Merge branch 'master' of github.com:r0ket/r0ket

This commit is contained in:
kiu 2011-07-23 06:04:15 +02:00
commit 157b9ed0f0
1 changed files with 32 additions and 3 deletions

View File

@ -33,7 +33,7 @@ push @charlist,map {ord $_} qw(
### Runtime Options ### Runtime Options
### ###
my ($verbose,$raw,$chars); my ($verbose,$raw,$chars,$bin);
my $size=18; my $size=18;
my $font="ttf/Ubuntu-Regular.ttf"; my $font="ttf/Ubuntu-Regular.ttf";
@ -42,6 +42,7 @@ GetOptions ("size=i" => \$size, # numeric
"font=s" => \$font, # string "font=s" => \$font, # string
"verbose" => \$verbose, # flag "verbose" => \$verbose, # flag
"raw" => \$raw, # flag "raw" => \$raw, # flag
"bin" => \$bin, # flag
"chars=s" => \$chars, # list of chars "chars=s" => \$chars, # list of chars
"help" => sub { "help" => sub {
print <<HELP; print <<HELP;
@ -50,6 +51,7 @@ Uasge: makefont.pl [-r] [-v] [-f fontfile] [-s size]
Options: Options:
--verbose Be verbose. --verbose Be verbose.
--raw Create raw/uncompressed font. --raw Create raw/uncompressed font.
--bin Also create binary font file.
--font <filename> Source .ttf file to use. [Default: $font] --font <filename> Source .ttf file to use. [Default: $font]
--chars <chars> Characters to encode. [Deflault: see source :-)] --chars <chars> Characters to encode. [Deflault: see source :-)]
--size <size> Pointsize the font should be rendered at. [Default: $size] --size <size> Pointsize the font should be rendered at. [Default: $size]
@ -123,6 +125,7 @@ EOF
my $offset=0; my $offset=0;
my $maxsz=0; my $maxsz=0;
my @offsets; my @offsets;
my (@bindata,@binoffsets);
for (0..$#charlist){ for (0..$#charlist){
my $char=chr $charlist[$_]; my $char=chr $charlist[$_];
print "### Start $char\n" if($verbose); print "### Start $char\n" if($verbose);
@ -186,6 +189,7 @@ for (0..$#charlist){
if(!$raw){ if(!$raw){
@enc=(255,$preblank,$postblank); @enc=(255,$preblank,$postblank);
@out=@enc; @out=@enc;
push @bindata,@out;
printf C " 0x%02x, %2d, %2d, /* rawmode, preblank, postblank */\n", printf C " 0x%02x, %2d, %2d, /* rawmode, preblank, postblank */\n",
(shift@out), (shift@out), (shift@out); (shift@out), (shift@out), (shift@out);
}else{ }else{
@ -194,6 +198,7 @@ for (0..$#charlist){
push @enc,@raw; push @enc,@raw;
$c2size+=scalar(@enc); $c2size+=scalar(@enc);
@out=@enc; @out=@enc;
push @bindata,@out;
for (@char){ for (@char){
print C " "; print C " ";
printf C "0x%02x, ",shift@out for(1..$heightb); printf C "0x%02x, ",shift@out for(1..$heightb);
@ -206,6 +211,7 @@ for (0..$#charlist){
print C " /* $_ */ \n"; print C " /* $_ */ \n";
}; };
my $pretty=0; my $pretty=0;
push @bindata,@enc;
for(@enc){ for(@enc){
print C " " if($pretty==0); print C " " if($pretty==0);
printf C "0x%02x, ",$_; printf C "0x%02x, ",$_;
@ -218,6 +224,7 @@ for (0..$#charlist){
print C "\n"; print C "\n";
push @binoffsets,scalar(@enc);
push @offsets,sprintf " {%2d}, /* %s */\n",scalar(@enc),$char; push @offsets,sprintf " {%2d}, /* %s */\n",scalar(@enc),$char;
print C "\n"; print C "\n";
@ -250,7 +257,8 @@ print C <<EOF;
const uint16_t ${fonts}Extra[] = { const uint16_t ${fonts}Extra[] = {
EOF EOF
print C join(",",@charlist[($last-$first+1)..$#charlist],0xffff); my @extras=(@charlist[($last-$first+1)..$#charlist],0xffff);
print C join(",",@extras);
printf C " printf C "
}; };
@ -281,6 +289,27 @@ printf C " */\n";
close(C); close(C);
if($bin){
open (B,">",$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: $!"; open (H,">",$file.".h")||die "Can't create $file.h: $!";
print H <<EOF; print H <<EOF;
#include "lcd/fonts.h" #include "lcd/fonts.h"
@ -293,7 +322,7 @@ print "\ndone.\n" if($verbose);
print "\n"; print "\n";
print "Original size: $origsize\n"; print "Original size: $origsize\n";
print "Simple compression: $c1size\n"; print "Simple compression: $c1size\n";
print "PK compression: $c2size\n"; print( ($raw?"No":"PK")." compression: $c2size\n");
print "Maximum character size is: $heightb*$maxsz bytes\n"; print "Maximum character size is: $heightb*$maxsz bytes\n";