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