From 213a435c5b196784a6a66834888ad276b02e6dbc Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Fri, 22 Jul 2011 22:32:01 +0200 Subject: [PATCH] Make makefont create binary files, too --- tools/font/makefont.pl | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/tools/font/makefont.pl b/tools/font/makefont.pl index a903f56..6a48f4d 100755 --- a/tools/font/makefont.pl +++ b/tools/font/makefont.pl @@ -33,7 +33,7 @@ push @charlist,map {ord $_} qw( ### Runtime Options ### -my ($verbose,$raw,$chars); +my ($verbose,$raw,$chars,$bin); my $size=18; my $font="ttf/Ubuntu-Regular.ttf"; @@ -42,6 +42,7 @@ GetOptions ("size=i" => \$size, # numeric "font=s" => \$font, # string "verbose" => \$verbose, # flag "raw" => \$raw, # flag + "bin" => \$bin, # flag "chars=s" => \$chars, # list of chars "help" => sub { print < Source .ttf file to use. [Default: $font] --chars Characters to encode. [Deflault: see source :-)] --size Pointsize the font should be rendered at. [Default: $size] @@ -123,6 +125,7 @@ EOF my $offset=0; my $maxsz=0; my @offsets; +my (@bindata,@binoffsets); for (0..$#charlist){ my $char=chr $charlist[$_]; print "### Start $char\n" if($verbose); @@ -186,6 +189,7 @@ for (0..$#charlist){ if(!$raw){ @enc=(255,$preblank,$postblank); @out=@enc; + push @bindata,@out; printf C " 0x%02x, %2d, %2d, /* rawmode, preblank, postblank */\n", (shift@out), (shift@out), (shift@out); }else{ @@ -194,6 +198,7 @@ for (0..$#charlist){ push @enc,@raw; $c2size+=scalar(@enc); @out=@enc; + push @bindata,@out; for (@char){ print C " "; printf C "0x%02x, ",shift@out for(1..$heightb); @@ -206,6 +211,7 @@ for (0..$#charlist){ print C " /* $_ */ \n"; }; my $pretty=0; + push @bindata,@enc; for(@enc){ print C " " if($pretty==0); printf C "0x%02x, ",$_; @@ -218,6 +224,7 @@ for (0..$#charlist){ print C "\n"; + push @binoffsets,scalar(@enc); push @offsets,sprintf " {%2d}, /* %s */\n",scalar(@enc),$char; print C "\n"; @@ -250,7 +257,8 @@ print C <",$file.".f0n")||die "Can't create $file.f0n: $!"; + binmode(B); # Just to be safe. + + print B +# uint8_t u8Width; /* Character width for storage */ + chr($raw?0:1), +# uint8_t u8Height; /* Character height for storage */ + chr($heightpx), +# uint8_t u8FirstChar; /* The first character available */ + chr($first), +# uint8_t u8LastChar; /* The last character available */ + chr($last); + + print B pack("S",scalar(@extras)); + print B map {pack "S",$_} @extras; + print B map {pack "C",$_} @binoffsets; + print B map {pack "C",$_} @bindata; + close(B); +}; + open (H,">",$file.".h")||die "Can't create $file.h: $!"; print H <