Updated standard library
Diff: Fonts/FontMods.h
- Revision:
- 161:0215d0eec1a4
- Parent:
- 160:43f3d90fc491
- Child:
- 167:8aa3fb2a5a31
- Child:
- 173:ae8198c82b88
--- a/Fonts/FontMods.h Sat Jan 12 21:40:51 2019 +0000 +++ b/Fonts/FontMods.h Sun Jan 13 19:02:36 2019 +0000 @@ -25,16 +25,18 @@ "restriction. ", " ", "This script will read and then modify the file for a few specific purposes:", - " * <space> character is redefined to set the width to 1/2 the height. ", + " * <space> character is redefined to set the width to 1/4 the height. ", " * '0' - '9' characters are redefined to set the width equal to width('0')", + " or to the user override value. ", " ", "And just because it can, it then improves upon the documentation in the ", "resulting data structure. ", " ", "This script was created by Smartware Computing, and is provided 'as is' ", - "for anyone to use or modify subject to the agreement that: ", + "with no warranty or suitability of fitness for any purpose. Anyone may use ", + "or modify it subject to the agreement that: ", " * The Smartware copyright statement remains intact. ", - " * Modifications for derivative use are clearly stated in this header ", + " * Modifications for derivative use are clearly stated in this header. ", " ", "Modifications from the original: ", " * none. ", @@ -51,6 +53,11 @@ my $of = ""; # Output File - otherwise stdout my $OH; # Handle to the output file +my $prg = $0; +$prg =~ s/.*[\\\/]//; +$prg =~ s/\.pl//i; +my $args = join(" ", @ARGV); + if (!@ARGV) { ShowHelp(); exit; @@ -86,15 +93,10 @@ my @data = (); # Raw byte stream from the source file my @FileTop; -my $FontDec; +my $FontDeclaration; my @FileBot; my %charData; # charData{$char}{width}, {$char}{data} -# 0 = scanning -# 1 = after '{' -# 2 = found '}' -my $state = 0; - ImportFontFile(); DumpRawData() if ($Debug >= 2); @@ -106,7 +108,7 @@ my $fontHeight = GetValueAt_Size_(6,1); my $unk_2 = GetValueAt_Size_(7,1); -printf("Char Range [%4X - %4X]\n", $firstChar, $lastChar) if ($Debug); +printf("// Char Range [%4X - %4X]\n", $firstChar, $lastChar) if ($Debug); for (my $char = $firstChar; $char <= $lastChar; $char++) { my $offsetToChar = 8 + 4 * ($char - $firstChar); @@ -118,18 +120,28 @@ } ShowFonts() if ($Debug >= 2); # Before Modifications -#FixFonts() if ($FixFile); -if ($FixFile) { +FixChars() if ($FixFile); +ShowFonts() if ($Debug); # After Modifications +EmitFile(); +if ($of ne "") { + select(STDOUT); + close($OH); +} +exit; + +######################################################################### + +sub FixChars { my @newDat; my $char; my $charWidth; my $BytesWide; # - # Set <space> width to be 1/2 the Height + # * <space> character is redefined to set the width to 1/4 the height. # $char = 0x20; # Fix <space> - $charWidth = floor($fontHeight/2); + $charWidth = floor($fontHeight/4); $charData{$char}{width} = $charWidth; $BytesWide = floor($charWidth/8); for (my $i=0; $i<($BytesWide*$fontHeight); $i++) { @@ -137,12 +149,13 @@ } # - # Set '0' - '9' width to be equal to width('0'), or the user override value + # * '0' - '9' characters are redefined to set the width equal to width('0') + # or to the user override value. # if ($DigitWidth > 0) { $charWidth = $DigitWidth; # User override option } else { - $charWidth = $charData{0x30}{width}; # Set it to the width of the '0' + $charWidth = DigitMaxWidth(); # Set it to the width of the widest digit } $BytesWide = floor(($charWidth+7)/8); #printf("Set Width = $charWidth, BytesWide = $BytesWide, Height = $fontHeight\n"); @@ -166,75 +179,32 @@ #<stdin>; } } -ShowFonts() if ($Debug); # After Modifications -EmitFile(); -if ($of ne "") { - select(STDOUT); - close($OH); -} -exit; -######################################################################### - -sub FixFonts { - my @newDat; - my $char; - my $charWidth; - my $BytesWide; - - # - # Set <space> width to be 1/2 the Height - # - $char = 0x20; # Fix <space> - $charWidth = floor($fontHeight/2); - $charData{$char}{width} = $charWidth; - $BytesWide = floor($charWidth/8); - for (my $i=0; $i<($BytesWide*$fontHeight); $i++) { - $charData{$char}{data}[$i] = 0x00; +sub DigitMaxWidth { + my $max = 0; + for (my $char=0x30; $char <= 0x39; $char++) { + $max = $charData{$char}{width} if ($max < $charData{$char}{width}); } - - # - # Set '0' - '9' width to be equal to width('0'), or the user override value - # - if ($DigitWidth > 0) { - $charWidth = $DigitWidth; # User override option - } else { - $charWidth = $charData{0x30}{width}; # Set it to the width of the '0' - } - $BytesWide = floor(($charWidth+7)/8); - printf("Set Width = $charWidth, BytesWide = $BytesWide\n"); - for ($char = 0x30; $char <= 0x39; $char++) { - for (my $h=0; $h<$fontHeight; $h++) { - for (my $w=0; $w<$BytesWide; $w++) { - my $pDst = $h * $BytesWide + $w; - if ($w < ceil($charData{$char}{width}/8)) { - my $pSrc = $h * floor(($charData{$char}{width}+7)/8) + $w; - $newDat[$pDst] = $charData{$char}{data}[$pSrc]; - } else { - $newDat[$pDst] = 0x00; - } - } - } - $charData{$char}{width} = $charWidth; - for (my $i=0; $i<($fontHeight * $BytesWide); $i++) { - $charData{$char}{data}[$i] = $newDat[$i]; - } - } + return $max; } +sub ImportFontFile { + # 0 = scanning + # 1 = after '{' + # 2 = found '}' + my $state = 0; -sub ImportFontFile { open(FH, "<$ff") || die("Can't open $ff"); while (<FH>) { my $rec = $_; chomp $rec; if ($state == 0) { if ($rec =~ /^const .*{/) { - $FontDec = $rec; + $FontDeclaration = $rec; + $state = 1; } else { push @FileTop, $rec; } - $state = 1 if ($rec =~ /= \{/); } elsif ($state == 1) { if ($rec =~ /};/) { $rec =~ s/^ +(.*)$/$1/ if ($Details); @@ -258,9 +228,6 @@ sub ShowHelp { - my $prg = $0; - $prg =~ s/.*[\\\/]//; - $prg =~ s/\.pl//i; print "\n\n$prg\n\n"; foreach (@HelpInfo) { print " $_\n"; @@ -280,7 +247,7 @@ sub ShowFonts { for (my $char = $firstChar; $char <= $lastChar; $char++) { my $charWidth = $charData{$char}{width}; - printf("\n=== %d (0x%2X) === w:%d, h:%d\n", $char, $char, $charWidth, $fontHeight); + printf("\n// === %d (0x%2X) === w:%d, h:%d\n", $char, $char, $charWidth, $fontHeight); RenderChar($char); } } @@ -289,11 +256,14 @@ if ($Details) { foreach (@HelpInfo) { print "// $_\n"; - } + } + print "// Script Activation:\n"; + printf("// %s %s\n", $prg, $args); + print "\n"; } print join("\n", @FileTop) . "\n"; # Mikroe header - printf("%s\n", $FontDec); + printf("%s\n", $FontDeclaration); printf(" // Font Info\n") if ($Details); printf(" 0x%02X, // Unknown #1\n", $unk_0); printf(" 0x%02X, // Unknown #2\n", $unk_1); @@ -334,9 +304,10 @@ sub DumpRawData { my $i; + print "// "; for ($i=0; $i<=$#data; $i++) { printf("%02X ", hex($data[$i])); - print "\n" if ($i % 16 == 15); + print "\n// " if ($i % 16 == 15); } print "\n"; } @@ -363,7 +334,7 @@ sub PrintChar { my ($char,$w,$h,@datablock) = @_; - printf(" +%s+ \n", '-' x $w); + printf("// +%s+ \n// ", '-' x $w); my $row = 0; my $boolStream = 0; while ($h--) { @@ -384,7 +355,7 @@ } $pixels--; } - printf("| %s\n", $tail); + printf("| %s\n// ", $tail); $boolStream += ($rowStream - $boolStream + 1); } printf(" +%s+\n", '-' x $w);