home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / anwor032.zip / antiword.0.32 / Unix-only / fontinfo.pl < prev   
Perl Script  |  2000-11-01  |  7KB  |  196 lines

  1. #! /usr/bin/perl -w
  2. #
  3. # Generate the fontinformation tables for the required fonts (Linux version)
  4. #
  5.  
  6. @charnames1 = (
  7. "space", "exclamdown", "cent", "sterling", "currency",
  8. "yen", "brokenbar", "section", "dieresis", "copyright",
  9. "ordfeminine", "guillemotleft", "logicalnot", "hyphen", "registered",
  10. "macron", "degree", "plusminus", "twosuperior", "threesuperior",
  11. "acute", "mu", "paragraph", "periodcentered", "cedilla",
  12. "onesuperior", "ordmasculine", "guillemotright", "onequarter",
  13. "onehalf", "threequarters", "questiondown", "Agrave", "Aacute",
  14. "Acircumflex", "Atilde", "Adieresis", "Aring", "AE", "Ccedilla",
  15. "Egrave", "Eacute", "Ecircumflex", "Edieresis", "Igrave", "Iacute",
  16. "Icircumflex", "Idieresis", "Eth", "Ntilde", "Ograve", "Oacute",
  17. "Ocircumflex", "Otilde", "Odieresis", "multiply", "Oslash",
  18. "Ugrave", "Uacute", "Ucircumflex", "Udieresis", "Yacute", "Thorn",
  19. "germandbls", "agrave", "aacute", "acircumflex", "atilde",
  20. "adieresis", "aring", "ae", "ccedilla", "egrave", "eacute",
  21. "ecircumflex", "edieresis", "igrave", "iacute", "icircumflex",
  22. "idieresis", "eth", "ntilde", "ograve", "oacute", "ocircumflex",
  23. "otilde", "odieresis", "divide", "oslash", "ugrave", "uacute",
  24. "ucircumflex", "udieresis", "yacute", "thorn", "ydieresis"
  25. );
  26.  
  27. @charnames2 = (
  28. "space", "Aogonek", "breve", "Lslash", "currency", "Lcaron",
  29. "Sacute", "section", "dieresis", "Scaron", "Scedilla",
  30. "Tcaron", "Zacute", "hyphen", "Zcaron", "Zdotaccent", "ring",
  31. "aogonek", "ogonek", "lslash", "acute", "lcaron", "sacute",
  32. "caron", "cedilla", "scaron", "scedilla", "tcaron",
  33. "zacute", "hungarumlaut", "zcaron", "zdotaccent", "Racute",
  34. "Aacute", "Acircumflex", "Abreve", "Adieresis", "Lacute",
  35. "Cacute", "Ccedilla", "Ccaron", "Eacute", "Eogonek",
  36. "Edieresis", "Ecaron", "Iacute", "Icircumflex", "Dcaron",
  37. "Dslash", "Nacute", "Ncaron", "Oacute", "Ocircumflex",
  38. "Ohungarumlaut", "Odieresis", "multiply", "Rcaron", "Uring",
  39. "Uacute", "Uhungarumlaut", "Udieresis", "Yacute", "Tcommaaccent",
  40. "germandbls", "racute", "aacute", "acircumflex", "abreve",
  41. "adieresis", "lacute", "cacute", "ccedilla", "ccaron", "eacute",
  42. "eogonek", "edieresis", "ecaron", "iacute", "icircumflex",
  43. "dcaron", "dmacron", "nacute", "ncaron", "oacute", "ocircumflex",
  44. "ohungarumlaut", "odieresis", "divide", "rcaron", "uring",
  45. "uacute", "uhungarumlaut", "udieresis", "yacute", "tcommaaccent",
  46. "dotaccent"
  47. );
  48.  
  49. $gs_dir1 = '/usr/share/ghostscript/fonts';
  50. $gs_dir2 = '/usr/share/ghostscript/fonts2';
  51.  
  52. @fontnames = (
  53. "Courier", "Courier-Bold", "Courier-Oblique", "Courier-BoldOblique",
  54. "Times-Roman", "Times-Bold", "Times-Italic", "Times-BoldItalic",
  55. "Helvetica", "Helvetica-Bold", "Helvetica-Oblique", "Helvetica-BoldOblique",
  56. "Palatino-Roman", "Palatino-Bold", "Palatino-Italic", "Palatino-BoldItalic",
  57. "Helvetica-Narrow", "Helvetica-Narrow-Bold", "Helvetica-Narrow-Oblique", "Helvetica-Narrow-BoldOblique",
  58. "Bookman-Light", "Bookman-Demi", "Bookman-LightItalic", "Bookman-DemiItalic",
  59. "AvantGarde-Book", "AvantGarde-Demi", "AvantGarde-BookOblique", "AvantGarde-DemiOblique",
  60. "NewCenturySchlbk-Roman", "NewCenturySchlbk-Bold", "NewCenturySchlbk-Italic", "NewCenturySchlbk-BoldItalic",
  61. );
  62.  
  63. @files = (
  64. "n022003l.afm", "n022004l.afm", "n022023l.afm", "n022024l.afm",
  65. "n021003l.afm", "n021004l.afm", "n021023l.afm", "n021024l.afm",
  66. "n019003l.afm", "n019004l.afm", "n019023l.afm", "n019024l.afm",
  67. "p052003l.afm", "p052004l.afm", "p052023l.afm", "p052024l.afm",
  68. "n019043l.afm", "n019044l.afm", "n019063l.afm", "n019064l.afm",
  69. "b018012l.afm", "b018015l.afm", "b018032l.afm", "b018035l.afm",
  70. "a010013l.afm", "a010015l.afm", "a010033l.afm", "a010035l.afm",
  71. "c059013l.afm", "c059016l.afm", "c059033l.afm", "c059036l.afm",
  72. );
  73.  
  74.  
  75. # Generate the array with the fontnames
  76. sub generate_fontnames
  77. {
  78.     printf STDOUT "static const char *szFontnames[%d] = {\n", $#fontnames + 1;
  79.     for ($n = 0; $n <= $#fontnames; $n++) {
  80.         printf STDOUT "\t\"%s\",\n", $fontnames[$n];
  81.     }
  82.     printf STDOUT "};\n";
  83. }
  84.  
  85. # Generate the array with the character widths
  86. sub generate_character_widths
  87. {
  88.     my ($char_set, $gs_dir, @charnames) = @_;
  89.     my ($n, $i, $file, $name);
  90.     my (@a, @charwidth);
  91.  
  92.     printf STDOUT "static unsigned short ausCharacterWidths%d[%d][256] = {\n", $char_set, $#files + 1;
  93.     for ($n = 0; $n <= $#files; $n++) {
  94.         $file = $files[$n];
  95.         $name = $fontnames[$n];
  96.         open(F_IN, "<$gs_dir/$file") || die "Cannot open $gs_dir/$file";
  97.         printf STDOUT "\t{\t/* %s */\n", $name;
  98.         while (<F_IN>) {
  99.             chop();
  100.             @a = split(/\s+/);
  101.             if ($a[0] eq 'UnderlinePosition') {
  102.                 $underlineposition[$n] = $a[1];
  103.             } elsif ($a[0] eq 'UnderlineThickness') {
  104.                 #printf STDERR "%d %d\n", $a[0], $a[1];
  105.                 $underlinethickness[$n] = $a[1];
  106.             } elsif ($a[0] eq 'C' && $a[2] eq ';' && $a[3] eq 'WX') {
  107.                 #printf STDERR "%d %d %s\n", $a[1], $a[4], $a[7];
  108.                 if (($a[1] < 0 || $a[1] >= 129) && defined($a[7])) {
  109.                     for ($i = 0; $i <= $#charnames; $i++) {
  110.                         if ($charnames[$i] eq $a[7]) {
  111.                             $charwidth[160 + $i] = $a[4];
  112.                             last;
  113.                         }
  114.                     }
  115.                 }
  116.                 if ($a[1] >= 0 && $a[1] <= 128 && !defined($charwidth[$a[1]])) {
  117.                     $charwidth[$a[1]] = $a[4];
  118.                 }
  119.             }
  120.             if (defined($a[7])) {
  121.                 for ($i = 0; $i <= $#charnames; $i++) {
  122.                     if ($charnames[$i] eq $a[7]) {
  123.                         $charwidth[160 + $i] = $a[4];
  124.                         last;
  125.                     }
  126.                 }
  127.             }
  128.         }
  129.         close(F_IN);
  130.  
  131.         # Set the width of the control characters zero
  132.         for ($i = 0; $i < 32; $i++) {
  133.             $charwidth[$i] = 0;
  134.         }
  135.         # Set the width of the unused characters to zero
  136.         for ($i = 127; $i < 160; $i++) {
  137.             $charwidth[$i] = 0;
  138.         }
  139.  
  140.         # Print the results
  141.         for ($i = 0; $i < 256; $i += 8) {
  142.             printf STDOUT "\t/* %3d */ ", $i;
  143.             for ($j = 0; $j < 8; $j++) {
  144.                 if (!defined($charwidth[$i + $j])) {
  145.                     printf STDERR "%d:%s: character %3d is undefined\n", $char_set, $name, $i + $j;
  146.                     $charwidth[$i + $j] = 0;
  147.                 }
  148.                 printf STDOUT "%5d,", $charwidth[$i + $j];
  149.             }
  150.             printf STDOUT "\n";
  151.         }
  152.         printf STDOUT "\t},\n";
  153.         undef @charwidth;
  154.     }
  155.     printf STDOUT "};\n";
  156. }
  157.  
  158. # Generate the array with the underline information
  159. sub generate_underline_information
  160. {
  161.     printf STDOUT "#if 0 /* Until this array is needed */\n";
  162.  
  163.     printf STDOUT "static int aiUnderlineInfo[%d][2] = {\n", $#fontnames + 1;
  164.     for ($n = 0; $n <= $#fontnames; $n++) {
  165.         if (!defined($underlineposition[$n])) {
  166.             $underlineposition[$n] = 0;
  167.         }
  168.         if (!defined($underlinethickness[$n])) {
  169.             $underlinethickness[$n] = 0;
  170.         }
  171.         printf STDOUT "\t{ %d, %d },\n", $underlineposition[$n], $underlinethickness[$n];
  172.     }
  173.     printf STDOUT "};\n";
  174.  
  175.     printf STDOUT "#endif /* 0 */\n";
  176. }
  177.  
  178.  
  179. # main()
  180.  
  181. if ($#fontnames != $#files) {
  182.     die "The fontnames-array and the files-array are of unequel length";
  183. }
  184. if ($#charnames1 != $#charnames2) {
  185.     die "The charname tables are of unequel length";
  186. }
  187.  
  188. printf STDOUT "/* THIS FILE IS AUTOMATICALLY GENERATED - DO NOT EDIT! */\n";
  189.  
  190. &generate_fontnames();
  191. &generate_character_widths(1, $gs_dir1, @charnames1);
  192. &generate_character_widths(2, $gs_dir2, @charnames2);
  193. &generate_underline_information();
  194.  
  195. exit 0;
  196.