Debian Codegraph @

texk/ttfdump/libttf/post.c

raw
1 #ifdef HAVE_CONFIG_H
2 #include <config.h>
3 #endif
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include "ttf.h"
8 #include "ttfutil.h"
9
10 /* $Id: post.c,v 1.3 1998/06/06 12:55:53 werner Exp $ */
11
12 static void ttfLoadPOST(FILE *fp, POSTPtr post, ULONG offset);
13
14 void ttfInitPOST(TTFontPtr font)
15 {
16 ULONG tag = FT_MAKE_TAG ('p', 'o', 's', 't');
17 TableDirPtr ptd;
18
19 if ((ptd = ttfLookUpTableDir(tag, font)) != NULL)
20 {
21 font->post = XCALLOC1 (POST);
22 ttfLoadPOST(font->fp, font->post, ptd->offset);
23 }
24 }
25
26 static void ttfLoadPOST(FILE *fp, POSTPtr post, ULONG offset)
27 {
28 USHORT i,numGlyphs;
29 xfseek(fp, offset, SEEK_SET, "ttfLoadPOST");
30
31 post->format = ttfGetFixed(fp);
32 post->italicAngle = ttfGetFixed(fp);
33 post->underlinePosition = ttfGetFWord(fp);
34 post->underlineThickness = ttfGetFWord(fp);
35 post->isFixedPitch = ttfGetULONG(fp);
36 post->minMemType42 = ttfGetULONG(fp);
37 post->maxMemType42 = ttfGetULONG(fp);
38 post->minMemType1 = ttfGetULONG(fp);
39 post->maxMemType1 = ttfGetULONG(fp);
40
41 switch (post->format)
42 {
43 case 0x00020000:
44 post->name.format20 = XCALLOC1 (Format20);
45 post->name.format20->numGlyphs = numGlyphs = ttfGetUSHORT(fp);
46 post->name.format20->glyphNameIndex = ttfMakeUSHORT (numGlyphs, fp);
47
48 post->name.format20->GlyphName = XCALLOC (numGlyphs, CHAR *);
49 for (i=0;i<numGlyphs;i++)
50 {
51 unsigned char len;
52 if (post->name.format20->glyphNameIndex[i] <= 257)
53 {
54 /* do nothing for standard Mac glyf name */
55 }
56 else if (post->name.format20->glyphNameIndex[i] <= 32767)
57 {
58 /* non-standard glyf name is stored as a Pascal
59 * string in the file i.e.
60 * the first byte is the length of the string
61 * but the string is not ended with a null
62 * character */
63 len = (unsigned char) ttfGetCHAR(fp);
64 post->name.format20->GlyphName[i] = XTALLOC (len+1, CHAR);
65 if (len)
66 fread(post->name.format20->GlyphName[i],
67 sizeof(CHAR), len, fp);
68 post->name.format20->GlyphName[i][len] = 0x0;
69 }
70 }
71 break;
72 case 0x00028000: /* 2.5 in 16.16 format */
73 /* not implemented yet */
74 break;
75 default:
76 /* do nothing */ ;
77 }
78 }
79
80 void ttfPrintPOST(FILE *fp,POSTPtr post)
81 {
82 int b[2],b1[2];
83 USHORT i,numGlyphs;
84
85 FixedSplit(post->format, b);
86 FixedSplit(post->italicAngle, b1);
87 fprintf(fp,"'post' Table - PostScript\n");
88 fprintf(fp,"-------------------------\n");
89 fprintf(fp,"\t 'post' format:\t\t %d.%d\n", b[1], b[0]);
90 fprintf(fp,"\t italicAngle:\t\t %d.%d\n", b1[1], b1[0]);
91 fprintf(fp,"\t underlinePosition:\t %d\n", post->underlinePosition);
92 fprintf(fp,"\t underlineThichness:\t %d\n", post->underlineThickness);
93 fprintf(fp,"\t isFixedPitch:\t\t %ud\n", post->isFixedPitch);
94 fprintf(fp,"\t minMemType42:\t\t %ud\n", post->minMemType42);
95 fprintf(fp,"\t maxMemType42:\t\t %ud\n", post->maxMemType42);
96 fprintf(fp,"\t minMemType1:\t\t %ud\n", post->minMemType1);
97 fprintf(fp,"\t maxMemType1:\t\t %ud\n", post->maxMemType1);
98
99 switch (post->format)
100 {
101 case 0x00020000:
102 numGlyphs = post->name.format20->numGlyphs;
103 fprintf(fp, "\t Format 2.0: Non-Standard (for PostScript) TrueType Glyph Set.\n");
104 fprintf(fp,"\t\t numGlyphs:\t %d\n",
105 post->name.format20->numGlyphs);
106 for (i=0;i<numGlyphs;i++)
107 {
108 if (post->name.format20->glyphNameIndex[i] < 257)
109 {
110 fprintf(fp,"\t\t Glyf %3d -> Mac Glyph # %3d\n", i,
111 post->name.format20->glyphNameIndex[i]);
112 }
113 else if (post->name.format20->glyphNameIndex[i] < 32767)
114 {
115 fprintf(fp,"\t\t Glyf %3d -> PSGlyf Name # %3d, '%s'\n",
116 i, post->name.format20->glyphNameIndex[i] - 257,
117 post->name.format20->GlyphName[i]);
118 }
119 }
120 break;
121 case 0x00020005:
122 /* not implemented yet */
123 break;
124 default:
125 /* do nothing */;
126 }
127 }
128
129 void ttfFreePOST(POSTPtr post)
130 {
131 USHORT i, numGlyphs;
132
133 if (!post)
134 return;
135
136 switch (post->format)
137 {
138 case 0x00020000:
139 numGlyphs = post->name.format20->numGlyphs;
140 for (i=0;i<numGlyphs;i++)
141 {
142 if (post->name.format20->glyphNameIndex[i] > 257)
143 free(post->name.format20->GlyphName[i]);
144 }
145 free(post->name.format20->glyphNameIndex);
146 free(post->name.format20->GlyphName);
147 free(post->name.format20);
148 break;
149 case 0x00020005:
150 /* not implemented yet */
151 break;
152 default:
153 /* do nothing */;
154 }
155 free(post);
156 }