1 /*****************************************************************************
2  * Copyright (C) The Apache Software Foundation. All rights reserved.        *
3  * ------------------------------------------------------------------------- *
4  * This software is published under the terms of the Apache Software License *
5  * version 1.1, a copy of which has been included with this distribution in  *
6  * the LICENSE file.                                                         *
7  *****************************************************************************/
8 
9 package jogamp.graph.font.typecast.ot.table;
10 
11 import java.io.DataInput;
12 import java.io.IOException;
13 
14 import jogamp.graph.font.typecast.ot.Fixed;
15 
16 /**
17  *
18  * @author <a href="mailto:davidsch@dev.java.net">David Schweinsberg</a>
19  * @version $Id: PostTable.java,v 1.1.1.1 2004-12-05 23:14:56 davidsch Exp $
20  */
21 public class PostTable implements Table {
22 
23     /**
24      * TODO: Mac Glyph names for 210 & 257
25      */
26     private static final String[] macGlyphName = {
27         ".notdef",      // 0
28         "null",         // 1
29         "CR",           // 2
30         "space",        // 3
31         "exclam",       // 4
32         "quotedbl",     // 5
33         "numbersign",   // 6
34         "dollar",       // 7
35         "percent",      // 8
36         "ampersand",    // 9
37         "quotesingle",  // 10
38         "parenleft",    // 11
39         "parenright",   // 12
40         "asterisk",     // 13
41         "plus",         // 14
42         "comma",        // 15
43         "hyphen",       // 16
44         "period",       // 17
45         "slash",        // 18
46         "zero",         // 19
47         "one",          // 20
48         "two",          // 21
49         "three",        // 22
50         "four",         // 23
51         "five",         // 24
52         "six",          // 25
53         "seven",        // 26
54         "eight",        // 27
55         "nine",         // 28
56         "colon",        // 29
57         "semicolon",    // 30
58         "less",         // 31
59         "equal",        // 32
60         "greater",      // 33
61         "question",     // 34
62         "at",           // 35
63         "A",            // 36
64         "B",            // 37
65         "C",            // 38
66         "D",            // 39
67         "E",            // 40
68         "F",            // 41
69         "G",            // 42
70         "H",            // 43
71         "I",            // 44
72         "J",            // 45
73         "K",            // 46
74         "L",            // 47
75         "M",            // 48
76         "N",            // 49
77         "O",            // 50
78         "P",            // 51
79         "Q",            // 52
80         "R",            // 53
81         "S",            // 54
82         "T",            // 55
83         "U",            // 56
84         "V",            // 57
85         "W",            // 58
86         "X",            // 59
87         "Y",            // 60
88         "Z",            // 61
89         "bracketleft",  // 62
90         "backslash",    // 63
91         "bracketright", // 64
92         "asciicircum",  // 65
93         "underscore",   // 66
94         "grave",        // 67
95         "a",            // 68
96         "b",            // 69
97         "c",            // 70
98         "d",            // 71
99         "e",            // 72
100         "f",            // 73
101         "g",            // 74
102         "h",            // 75
103         "i",            // 76
104         "j",            // 77
105         "k",            // 78
106         "l",            // 79
107         "m",            // 80
108         "n",            // 81
109         "o",            // 82
110         "p",            // 83
111         "q",            // 84
112         "r",            // 85
113         "s",            // 86
114         "t",            // 87
115         "u",            // 88
116         "v",            // 89
117         "w",            // 90
118         "x",            // 91
119         "y",            // 92
120         "z",            // 93
121         "braceleft",    // 94
122         "bar",          // 95
123         "braceright",   // 96
124         "asciitilde",   // 97
125         "Adieresis",    // 98
126         "Aring",        // 99
127         "Ccedilla",     // 100
128         "Eacute",       // 101
129         "Ntilde",       // 102
130         "Odieresis",    // 103
131         "Udieresis",    // 104
132         "aacute",       // 105
133         "agrave",       // 106
134         "acircumflex",  // 107
135         "adieresis",    // 108
136         "atilde",       // 109
137         "aring",        // 110
138         "ccedilla",     // 111
139         "eacute",       // 112
140         "egrave",       // 113
141         "ecircumflex",  // 114
142         "edieresis",    // 115
143         "iacute",       // 116
144         "igrave",       // 117
145         "icircumflex",  // 118
146         "idieresis",    // 119
147         "ntilde",       // 120
148         "oacute",       // 121
149         "ograve",       // 122
150         "ocircumflex",  // 123
151         "odieresis",    // 124
152         "otilde",       // 125
153         "uacute",       // 126
154         "ugrave",       // 127
155         "ucircumflex",  // 128
156         "udieresis",    // 129
157         "dagger",       // 130
158         "degree",       // 131
159         "cent",         // 132
160         "sterling",     // 133
161         "section",      // 134
162         "bullet",       // 135
163         "paragraph",    // 136
164         "germandbls",   // 137
165         "registered",   // 138
166         "copyright",    // 139
167         "trademark",    // 140
168         "acute",        // 141
169         "dieresis",     // 142
170         "notequal",     // 143
171         "AE",           // 144
172         "Oslash",       // 145
173         "infinity",     // 146
174         "plusminus",    // 147
175         "lessequal",    // 148
176         "greaterequal", // 149
177         "yen",          // 150
178     "mu",           // 151
179         "partialdiff",  // 152
180         "summation",    // 153
181         "product",      // 154
182     "pi",           // 155
183         "integral'",    // 156
184         "ordfeminine",  // 157
185         "ordmasculine", // 158
186     "Omega",        // 159
187         "ae",           // 160
188         "oslash",       // 161
189         "questiondown", // 162
190         "exclamdown",   // 163
191         "logicalnot",   // 164
192         "radical",      // 165
193         "florin",       // 166
194         "approxequal",  // 167
195         "increment",    // 168
196         "guillemotleft",// 169
197         "guillemotright",//170
198         "ellipsis",     // 171
199         "nbspace",      // 172
200         "Agrave",       // 173
201         "Atilde",       // 174
202         "Otilde",       // 175
203         "OE",           // 176
204         "oe",           // 177
205         "endash",       // 178
206         "emdash",       // 179
207         "quotedblleft", // 180
208         "quotedblright",// 181
209         "quoteleft",    // 182
210         "quoteright",   // 183
211         "divide",       // 184
212         "lozenge",      // 185
213         "ydieresis",    // 186
214         "Ydieresis",    // 187
215         "fraction",     // 188
216         "currency",     // 189
217         "guilsinglleft",// 190
218         "guilsinglright",//191
219         "fi",           // 192
220         "fl",           // 193
221         "daggerdbl",    // 194
222         "middot",       // 195
223         "quotesinglbase",//196
224         "quotedblbase", // 197
225         "perthousand",  // 198
226         "Acircumflex",  // 199
227         "Ecircumflex",  // 200
228         "Aacute",       // 201
229         "Edieresis",    // 202
230         "Egrave",       // 203
231         "Iacute",       // 204
232         "Icircumflex",  // 205
233         "Idieresis",    // 206
234         "Igrave",       // 207
235         "Oacute",       // 208
236         "Ocircumflex",  // 209
237         "",             // 210
238         "Ograve",       // 211
239         "Uacute",       // 212
240         "Ucircumflex",  // 213
241         "Ugrave",       // 214
242         "dotlessi",     // 215
243         "circumflex",   // 216
244         "tilde",        // 217
245         "overscore",    // 218
246         "breve",        // 219
247         "dotaccent",    // 220
248         "ring",         // 221
249         "cedilla",      // 222
250         "hungarumlaut", // 223
251         "ogonek",       // 224
252         "caron",        // 225
253         "Lslash",       // 226
254         "lslash",       // 227
255         "Scaron",       // 228
256         "scaron",       // 229
257         "Zcaron",       // 230
258         "zcaron",       // 231
259         "brokenbar",    // 232
260         "Eth",          // 233
261         "eth",          // 234
262         "Yacute",       // 235
263         "yacute",       // 236
264         "Thorn",        // 237
265         "thorn",        // 238
266         "minus",        // 239
267         "multiply",     // 240
268         "onesuperior",  // 241
269         "twosuperior",  // 242
270         "threesuperior",// 243
271         "onehalf",      // 244
272         "onequarter",   // 245
273         "threequarters",// 246
274         "franc",        // 247
275         "Gbreve",       // 248
276         "gbreve",       // 249
277         "Idot",         // 250
278         "Scedilla",     // 251
279         "scedilla",     // 252
280         "Cacute",       // 253
281         "cacute",       // 254
282         "Ccaron",       // 255
283         "ccaron",       // 256
284         ""              // 257
285     };
286 
287     private final DirectoryEntry de;
288     private final int version;
289     private final int italicAngle;
290     private final short underlinePosition;
291     private final short underlineThickness;
292     private final int isFixedPitch;
293     private final int minMemType42;
294     private final int maxMemType42;
295     private final int minMemType1;
296     private final int maxMemType1;
297 
298     // v2
299     private int numGlyphs;
300     private int[] glyphNameIndex;
301     private String[] psGlyphName;
302 
303     /** Creates new PostTable */
PostTable(final DirectoryEntry de, final DataInput di)304     protected PostTable(final DirectoryEntry de, final DataInput di) throws IOException {
305         this.de = (DirectoryEntry) de.clone();
306         version = di.readInt();
307         italicAngle = di.readInt();
308         underlinePosition = di.readShort();
309         underlineThickness = di.readShort();
310         isFixedPitch = di.readInt();
311         minMemType42 = di.readInt();
312         maxMemType42 = di.readInt();
313         minMemType1 = di.readInt();
314         maxMemType1 = di.readInt();
315 
316         if (version == 0x00020000) {
317             numGlyphs = di.readUnsignedShort();
318             glyphNameIndex = new int[numGlyphs];
319             for (int i = 0; i < numGlyphs; i++) {
320                 glyphNameIndex[i] = di.readUnsignedShort();
321             }
322             int h = highestGlyphNameIndex();
323             if (h > 257) {
324                 h -= 257;
325                 psGlyphName = new String[h];
326                 for (int i = 0; i < h; i++) {
327                     final int len = di.readUnsignedByte();
328                     final byte[] buf = new byte[len];
329                     di.readFully(buf);
330                     psGlyphName[i] = new String(buf);
331                 }
332             }
333         // } else if (version == 0x00025000) {
334         // } else if (version == 0x00030000) {
335         }
336     }
337 
getVersion()338     public int getVersion() {
339         return version;
340     }
341 
highestGlyphNameIndex()342     private int highestGlyphNameIndex() {
343         int high = 0;
344         for (int i = 0; i < numGlyphs; i++) {
345             if (high < glyphNameIndex[i]) {
346                 high = glyphNameIndex[i];
347             }
348         }
349         return high;
350     }
351 
getGlyphName(final int i)352     public String getGlyphName(final int i) {
353         if (version == 0x00020000) {
354             return (glyphNameIndex[i] > 257)
355                 ? psGlyphName[glyphNameIndex[i] - 258]
356                 : macGlyphName[glyphNameIndex[i]];
357         } else {
358             return null;
359         }
360     }
361 
isMacGlyphName(final int i)362     private boolean isMacGlyphName(final int i) {
363         if (version == 0x00020000) {
364             return glyphNameIndex[i] <= 257;
365         } else {
366             return false;
367         }
368     }
369 
370     /** Get the table type, as a table directory value.
371      * @return The table type
372      */
373     @Override
getType()374     public int getType() {
375         return post;
376     }
377 
378     @Override
toString()379     public String toString() {
380         final StringBuilder sb = new StringBuilder();
381         sb.append("'post' Table - PostScript Metrics\n---------------------------------\n")
382             .append("\n        'post' version:        ").append(Fixed.floatValue(version))
383             .append("\n        italicAngle:           ").append(Fixed.floatValue(italicAngle))
384             .append("\n        underlinePosition:     ").append(underlinePosition)
385             .append("\n        underlineThickness:    ").append(underlineThickness)
386             .append("\n        isFixedPitch:          ").append(isFixedPitch)
387             .append("\n        minMemType42:          ").append(minMemType42)
388             .append("\n        maxMemType42:          ").append(maxMemType42)
389             .append("\n        minMemType1:           ").append(minMemType1)
390             .append("\n        maxMemType1:           ").append(maxMemType1);
391 
392         if (version == 0x00020000) {
393             sb.append("\n\n        Format 2.0:  Non-Standard (for PostScript) TrueType Glyph Set.\n");
394             sb.append("        numGlyphs:      ").append(numGlyphs).append("\n");
395             for (int i = 0; i < numGlyphs; i++) {
396                 sb.append("        Glyf ").append(i).append(" -> ");
397                 if (isMacGlyphName(i)) {
398                     sb.append("Mac Glyph # ").append(glyphNameIndex[i])
399                         .append(", '").append(macGlyphName[glyphNameIndex[i]]).append("'\n");
400                 } else {
401                     sb.append("PSGlyf Name # ").append(glyphNameIndex[i] - 257)
402                         .append(", name= '").append(psGlyphName[glyphNameIndex[i] - 258]).append("'\n");
403                 }
404             }
405             sb.append("\n        Full List of PSGlyf Names\n        ------------------------\n");
406             for (int i = 0; i < psGlyphName.length; i++) {
407                 sb.append("        PSGlyf Name # ").append(i + 1)
408                     .append(": ").append(psGlyphName[i])
409                     .append("\n");
410             }
411         }
412         return sb.toString();
413     }
414 
415     /**
416      * Get a directory entry for this table.  This uniquely identifies the
417      * table in collections where there may be more than one instance of a
418      * particular table.
419      * @return A directory entry
420      */
421     @Override
getDirectoryEntry()422     public DirectoryEntry getDirectoryEntry() {
423         return de;
424     }
425 
426 }
427