Correctly support raw font encoding
This commit is contained in:
parent
b2983a53a3
commit
da2e5cdf26
|
@ -51,6 +51,7 @@ Options:
|
||||||
--verbose Be verbose.
|
--verbose Be verbose.
|
||||||
--raw Create raw/uncompressed font.
|
--raw Create raw/uncompressed font.
|
||||||
--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 :-)]
|
||||||
--size <size> Pointsize the font should be rendered at. [Default: $size]
|
--size <size> Pointsize the font should be rendered at. [Default: $size]
|
||||||
HELP
|
HELP
|
||||||
exit(-1);}
|
exit(-1);}
|
||||||
|
@ -90,7 +91,7 @@ die "No font name?" if !defined $title;
|
||||||
my $file=$fonts;
|
my $file=$fonts;
|
||||||
$file=~s/pt$//;
|
$file=~s/pt$//;
|
||||||
$file=~y/A-Z/a-z/;
|
$file=~y/A-Z/a-z/;
|
||||||
$file.="-raw" if($raw);
|
#$file.="-raw" if($raw);
|
||||||
|
|
||||||
print "Writing $title to ${file}.c\n";
|
print "Writing $title to ${file}.c\n";
|
||||||
|
|
||||||
|
@ -174,18 +175,25 @@ for (0..$#charlist){
|
||||||
my $oneraw;
|
my $oneraw;
|
||||||
# If encoding is bigger, fall back to original char
|
# If encoding is bigger, fall back to original char
|
||||||
if($#enc>$#raw+3){
|
if($#enc>$#raw+3){
|
||||||
warn "Compression failure: Encoding char $char raw.\n";
|
warn "Compression failure: Encoding char $char raw.\n" unless $raw;
|
||||||
$oneraw=1;
|
$oneraw=1;
|
||||||
};
|
};
|
||||||
|
|
||||||
# Generate C source
|
# Generate C source
|
||||||
if($raw||$oneraw){
|
if($raw||$oneraw){
|
||||||
|
my @out;
|
||||||
$c2size-=scalar(@enc);
|
$c2size-=scalar(@enc);
|
||||||
@enc=(255,$preblank,$postblank,@raw);
|
if(!$raw){
|
||||||
$c2size+=scalar(@enc);
|
@enc=(255,$preblank,$postblank);
|
||||||
my @out=@enc;
|
@out=@enc;
|
||||||
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{
|
||||||
|
@enc=();
|
||||||
|
};
|
||||||
|
push @enc,@raw;
|
||||||
|
$c2size+=scalar(@enc);
|
||||||
|
@out=@enc;
|
||||||
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);
|
||||||
|
@ -249,21 +257,26 @@ printf C "
|
||||||
|
|
||||||
/* Font info */
|
/* Font info */
|
||||||
const struct FONT_DEF Font_$fonts = {
|
const struct FONT_DEF Font_$fonts = {
|
||||||
%3d, /* width (1 == comressed) */
|
%3d, /* width (1 == compressed) */
|
||||||
%3d, /* character height */
|
%3d, /* character height */
|
||||||
%3d, /* first char */
|
%3d, /* first char */
|
||||||
%3d, /* last char */
|
%3d, /* last char */
|
||||||
%s, %s, %s
|
%s, %s, %s
|
||||||
};
|
};
|
||||||
",1,$heightpx,$first,$last,"${fonts}Bitmaps","${fonts}Lengths","${fonts}Extra";
|
",($raw?0:1),$heightpx,$first,$last,"${fonts}Bitmaps","${fonts}Lengths","${fonts}Extra";
|
||||||
|
|
||||||
printf C "\n";
|
printf C "\n";
|
||||||
printf C "/* Font metadata: \n";
|
printf C "/* Font metadata: \n";
|
||||||
printf C " * Name: %s\n", $title;
|
printf C " * Name: %s\n", $title;
|
||||||
printf C " * Height: %d px (%d bytes)\n", $heightpx,$heightb;
|
printf C " * Height: %d px (%d bytes)\n", $heightpx,$heightb;
|
||||||
printf C " * Maximum width: %d px\n",$maxsz;
|
printf C " * Maximum width: %d px\n",$maxsz;
|
||||||
printf C " * Storage size: %d bytes (compressed by %2d%%)\n",
|
printf C " * Storage size: %d bytes ",$c2size;
|
||||||
$c2size,(1-$c2size/$origsize)*100;
|
if($raw){
|
||||||
|
printf C "(uncompressed)";
|
||||||
|
}else{
|
||||||
|
printf C "(compressed by %2d%%)", (1-$c2size/$origsize)*100;
|
||||||
|
};
|
||||||
|
printf C "\n";
|
||||||
printf C " */\n";
|
printf C " */\n";
|
||||||
|
|
||||||
close(C);
|
close(C);
|
||||||
|
|
Loading…
Reference in New Issue