Subversion Repositories HelenOS

Rev

Rev 4187 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #!/usr/bin/perl -w
  2.  
  3. #
  4. # Copyright (c) 2000 Dmitry Bolkhovityanov
  5. # Copyright (c) 2009 Martin Decky
  6. # All rights reserved.
  7. #
  8. # Redistribution and use in source and binary forms, with or without
  9. # modification, are permitted provided that the following conditions
  10. # are met:
  11. #
  12. # - Redistributions of source code must retain the above copyright
  13. #   notice, this list of conditions and the following disclaimer.
  14. # - Redistributions in binary form must reproduce the above copyright
  15. #   notice, this list of conditions and the following disclaimer in the
  16. #   documentation and/or other materials provided with the distribution.
  17. # - The name of the author may not be used to endorse or promote products
  18. #   derived from this software without specific prior written permission.
  19. #
  20. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  21. # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  22. # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  23. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  25. # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  29. # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. #
  31.  
  32. use strict;
  33.  
  34. my $skip;
  35.  
  36. my $width;
  37. my $height;
  38. my $offset_x;
  39. my $offset_y;
  40.  
  41. my $gwidth;
  42. my $gheight;
  43. my $goffset_x;
  44. my $goffset_y;
  45.  
  46. my $index;
  47. my @glyphs;
  48. my @chars;
  49.  
  50. open(BDF, "u_vga16.bdf") or die("Unable to open source font\n");
  51.  
  52. READHEADER: while (<BDF>) {
  53.     /^FONTBOUNDINGBOX\s/ and do {
  54.         ($skip, $width, $height, $offset_x, $offset_y) = (split);
  55.        
  56.         die("Font width is not 8px\n") if ($width != 8);
  57.         die("Font height is not 16px\n") if ($height != 16);
  58.     };
  59.     /^CHARS\s/ && last READHEADER;
  60. }
  61.  
  62. READCHARS: while (<BDF>) {
  63.     /^ENCODING\s+([0-9]+)\s*$/ && do {
  64.         $index = $1;
  65.     };
  66.     /^BBX\s/ && do {
  67.         ($skip, $gwidth, $gheight, $goffset_x, $goffset_y) = (split);
  68.     };
  69.     /^BITMAP/ && do {
  70.         my @glyph = ();
  71.         my $y;
  72.        
  73.         # Add empty lines at top
  74.         my $empties = $height + $offset_y - $goffset_y - $gheight;
  75.        
  76.         for ($y = 0; $y < $empties; $y++) {
  77.             $glyph[$y] = 0;
  78.         }
  79.        
  80.         # Scan the hex bitmap
  81.         for ($y = $empties; $y < $empties + $gheight; $y++) {
  82.             $_ = <BDF>;
  83.             $glyph[$y] = hex(substr($_, 0, 2)) >> $goffset_x;
  84.         }
  85.        
  86.         # Add empty lines at bottom
  87.         my $fill = $height - $gheight - $empties;
  88.         for ($y = $empties + $gheight; $y < $empties + $gheight + $fill; $y++) {
  89.             $glyph[$y] = 0;
  90.         }
  91.        
  92.         if ($index != 0) {
  93.             $glyphs[$index] = (\@glyph);
  94.             push(@chars, $index);
  95.         }
  96.     };
  97.     /^ENDFONT/ && last READCHARS;
  98. }
  99.  
  100. close(BDF);
  101.  
  102. @chars = sort { $a <=> $b } (@chars);
  103.  
  104. print "#define FONT_GLYPHS     " . @chars . "\n";
  105. print "#define FONT_SCANLINES  " . $height . "\n";
  106.  
  107. print "\n";
  108. print "index_t fb_font_glyph(const wchar_t ch)\n";
  109. print "{";
  110.  
  111. my $pos = 0;
  112. my $start = -1;
  113. my $start_pos = 0;
  114. my $prev = 0;
  115. for $index (@chars) {
  116.     if ($prev + 1 < $index) {
  117.         if ($start != -1) {
  118.             if ($start == $prev) {
  119.                 printf "\tif (ch == 0x%.4x)\n", $start;
  120.             } else {
  121.                 printf "\tif ((ch >= 0x%.4x) && (ch <= 0x%.4x))\n", $start, $prev;
  122.             }
  123.            
  124.             print "\t\treturn (ch - " . ($start - $start_pos) . ");\n";
  125.             print "\t\n";
  126.         }
  127.        
  128.         $start = $index;
  129.         $start_pos = $pos;
  130.     }
  131.     $pos++;
  132.     $prev = $index;
  133. }
  134.  
  135. print "\treturn 31;\n";
  136. print "}\n";
  137.  
  138. print "\n";
  139. print "uint8_t fb_font[FONT_GLYPHS][FONT_SCANLINES] = {";
  140.  
  141. my $f1 = 0;
  142. for $index (@chars) {
  143.     print "," if ($f1 > 0);
  144.     print "\n\t{";
  145.    
  146.     my $y;
  147.     for ($y = 0; $y < $height; $y++) {
  148.         print ", " if ($y > 0);
  149.         printf "0x%.2x", $glyphs[$index]->[$y];
  150.     }
  151.    
  152.     print "}";
  153.     $f1++;
  154. }
  155.  
  156. print "\n};\n";
  157.