File: | bitmap/pcfwrite.c |
Location: | line 344, column 5 |
Description: | Value stored to 'offset' is never read |
1 | /* |
2 | |
3 | Copyright 1990, 1994, 1998 The Open Group |
4 | |
5 | Permission to use, copy, modify, distribute, and sell this software and its |
6 | documentation for any purpose is hereby granted without fee, provided that |
7 | the above copyright notice appear in all copies and that both that |
8 | copyright notice and this permission notice appear in supporting |
9 | documentation. |
10 | |
11 | The above copyright notice and this permission notice shall be included |
12 | in all copies or substantial portions of the Software. |
13 | |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
15 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
17 | IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR |
18 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
19 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
20 | OTHER DEALINGS IN THE SOFTWARE. |
21 | |
22 | Except as contained in this notice, the name of The Open Group shall |
23 | not be used in advertising or otherwise to promote the sale, use or |
24 | other dealings in this Software without prior written authorization |
25 | from The Open Group. |
26 | |
27 | */ |
28 | |
29 | /* |
30 | * Author: Keith Packard, MIT X Consortium |
31 | */ |
32 | |
33 | #ifdef HAVE_CONFIG_H1 |
34 | #include <config.h> |
35 | #endif |
36 | #include "libxfontint.h" |
37 | |
38 | #include <X11/fonts/fntfilst.h> |
39 | #include <X11/fonts/bitmap.h> |
40 | #include <X11/fonts/pcf.h> |
41 | |
42 | /* Write PCF font files */ |
43 | |
44 | static CARD32 current_position; |
45 | |
46 | static int |
47 | pcfWrite(FontFilePtr file, const char *b, int c) |
48 | { |
49 | current_position += c; |
50 | return FontFileWrite(file, b, c)BufFileWrite(file,b,c); |
51 | } |
52 | |
53 | static int |
54 | pcfPutLSB32(FontFilePtr file, int c) |
55 | { |
56 | current_position += 4; |
57 | (void) FontFilePutc(c, file)(--(file)->left ? *(file)->bufp++ = ((unsigned char)(c) ) : (*(file)->output) ((unsigned char)(c),file)); |
58 | (void) FontFilePutc(c >> 8, file)(--(file)->left ? *(file)->bufp++ = ((unsigned char)(c >> 8)) : (*(file)->output) ((unsigned char)(c >> 8),file )); |
59 | (void) FontFilePutc(c >> 16, file)(--(file)->left ? *(file)->bufp++ = ((unsigned char)(c >> 16)) : (*(file)->output) ((unsigned char)(c >> 16), file)); |
60 | return FontFilePutc(c >> 24, file)(--(file)->left ? *(file)->bufp++ = ((unsigned char)(c >> 24)) : (*(file)->output) ((unsigned char)(c >> 24), file)); |
61 | } |
62 | |
63 | static int |
64 | pcfPutINT32(FontFilePtr file, CARD32 format, int c) |
65 | { |
66 | current_position += 4; |
67 | if (PCF_BYTE_ORDER(format)(((format) & (1<<2))?1:0) == MSBFirst1) { |
68 | (void) FontFilePutc(c >> 24, file)(--(file)->left ? *(file)->bufp++ = ((unsigned char)(c >> 24)) : (*(file)->output) ((unsigned char)(c >> 24), file)); |
69 | (void) FontFilePutc(c >> 16, file)(--(file)->left ? *(file)->bufp++ = ((unsigned char)(c >> 16)) : (*(file)->output) ((unsigned char)(c >> 16), file)); |
70 | (void) FontFilePutc(c >> 8, file)(--(file)->left ? *(file)->bufp++ = ((unsigned char)(c >> 8)) : (*(file)->output) ((unsigned char)(c >> 8),file )); |
71 | return FontFilePutc(c, file)(--(file)->left ? *(file)->bufp++ = ((unsigned char)(c) ) : (*(file)->output) ((unsigned char)(c),file)); |
72 | } else { |
73 | (void) FontFilePutc(c, file)(--(file)->left ? *(file)->bufp++ = ((unsigned char)(c) ) : (*(file)->output) ((unsigned char)(c),file)); |
74 | (void) FontFilePutc(c >> 8, file)(--(file)->left ? *(file)->bufp++ = ((unsigned char)(c >> 8)) : (*(file)->output) ((unsigned char)(c >> 8),file )); |
75 | (void) FontFilePutc(c >> 16, file)(--(file)->left ? *(file)->bufp++ = ((unsigned char)(c >> 16)) : (*(file)->output) ((unsigned char)(c >> 16), file)); |
76 | return FontFilePutc(c >> 24, file)(--(file)->left ? *(file)->bufp++ = ((unsigned char)(c >> 24)) : (*(file)->output) ((unsigned char)(c >> 24), file)); |
77 | } |
78 | } |
79 | |
80 | static int |
81 | pcfPutINT16(FontFilePtr file, CARD32 format, int c) |
82 | { |
83 | current_position += 2; |
84 | if (PCF_BYTE_ORDER(format)(((format) & (1<<2))?1:0) == MSBFirst1) { |
85 | (void) FontFilePutc(c >> 8, file)(--(file)->left ? *(file)->bufp++ = ((unsigned char)(c >> 8)) : (*(file)->output) ((unsigned char)(c >> 8),file )); |
86 | return FontFilePutc(c, file)(--(file)->left ? *(file)->bufp++ = ((unsigned char)(c) ) : (*(file)->output) ((unsigned char)(c),file)); |
87 | } else { |
88 | (void) FontFilePutc(c, file)(--(file)->left ? *(file)->bufp++ = ((unsigned char)(c) ) : (*(file)->output) ((unsigned char)(c),file)); |
89 | return FontFilePutc(c >> 8, file)(--(file)->left ? *(file)->bufp++ = ((unsigned char)(c >> 8)) : (*(file)->output) ((unsigned char)(c >> 8),file )); |
90 | } |
91 | } |
92 | |
93 | /*ARGSUSED*/ |
94 | static int |
95 | pcfPutINT8(FontFilePtr file, CARD32 format, int c) |
96 | { |
97 | current_position += 1; |
98 | return FontFilePutc(c, file)(--(file)->left ? *(file)->bufp++ = ((unsigned char)(c) ) : (*(file)->output) ((unsigned char)(c),file)); |
99 | } |
100 | |
101 | static void |
102 | pcfWriteTOC(FontFilePtr file, PCFTablePtr table, int count) |
103 | { |
104 | CARD32 version; |
105 | int i; |
106 | |
107 | version = PCF_FILE_VERSION(('p'<<24)|('c'<<16)|('f'<<8)|1); |
108 | pcfPutLSB32(file, version); |
109 | pcfPutLSB32(file, count); |
110 | for (i = 0; i < count; i++) { |
111 | pcfPutLSB32(file, table->type); |
112 | pcfPutLSB32(file, table->format); |
113 | pcfPutLSB32(file, table->size); |
114 | pcfPutLSB32(file, table->offset); |
115 | table++; |
116 | } |
117 | } |
118 | |
119 | static void |
120 | pcfPutCompressedMetric(FontFilePtr file, CARD32 format, xCharInfo *metric) |
121 | { |
122 | pcfPutINT8(file, format, metric->leftSideBearing + 0x80); |
123 | pcfPutINT8(file, format, metric->rightSideBearing + 0x80); |
124 | pcfPutINT8(file, format, metric->characterWidth + 0x80); |
125 | pcfPutINT8(file, format, metric->ascent + 0x80); |
126 | pcfPutINT8(file, format, metric->descent + 0x80); |
127 | } |
128 | |
129 | static void |
130 | pcfPutMetric(FontFilePtr file, CARD32 format, xCharInfo *metric) |
131 | { |
132 | pcfPutINT16(file, format, metric->leftSideBearing); |
133 | pcfPutINT16(file, format, metric->rightSideBearing); |
134 | pcfPutINT16(file, format, metric->characterWidth); |
135 | pcfPutINT16(file, format, metric->ascent); |
136 | pcfPutINT16(file, format, metric->descent); |
137 | pcfPutINT16(file, format, metric->attributes); |
138 | } |
139 | |
140 | static void |
141 | pcfPutBitmap(FontFilePtr file, CARD32 format, CharInfoPtr pCI) |
142 | { |
143 | int count; |
144 | unsigned char *bits; |
145 | |
146 | count = BYTES_FOR_GLYPH(pCI, PCF_GLYPH_PAD(format))(((pCI)->metrics.ascent + (pCI)->metrics.descent) * ((( 1<<((format) & (3<<0)))) == 1 ? (((((pCI)-> metrics.rightSideBearing - (pCI)->metrics.leftSideBearing) )+7)>>3) :((1<<((format) & (3<<0)))) == 2 ? ((((((pCI)->metrics.rightSideBearing - (pCI)->metrics .leftSideBearing))+15)>>3)&~1) :((1<<((format ) & (3<<0)))) == 4 ? ((((((pCI)->metrics.rightSideBearing - (pCI)->metrics.leftSideBearing))+31)>>3)&~3) : ((1<<((format) & (3<<0)))) == 8 ? ((((((pCI)-> metrics.rightSideBearing - (pCI)->metrics.leftSideBearing) )+63)>>3)&~7) : 0)); |
147 | bits = (unsigned char *) pCI->bits; |
148 | current_position += count; |
149 | while (count--) |
150 | FontFilePutc(*bits++, file)(--(file)->left ? *(file)->bufp++ = ((unsigned char)(*bits ++)) : (*(file)->output) ((unsigned char)(*bits++),file)); |
151 | } |
152 | |
153 | static void |
154 | pcfPutAccel(FontFilePtr file, CARD32 format, FontInfoPtr pFontInfo) |
155 | { |
156 | pcfPutINT8(file, format, pFontInfo->noOverlap); |
157 | pcfPutINT8(file, format, pFontInfo->constantMetrics); |
158 | pcfPutINT8(file, format, pFontInfo->terminalFont); |
159 | pcfPutINT8(file, format, pFontInfo->constantWidth); |
160 | pcfPutINT8(file, format, pFontInfo->inkInside); |
161 | pcfPutINT8(file, format, pFontInfo->inkMetrics); |
162 | pcfPutINT8(file, format, pFontInfo->drawDirection); |
163 | pcfPutINT8(file, format, 0); |
164 | pcfPutINT32(file, format, pFontInfo->fontAscent); |
165 | pcfPutINT32(file, format, pFontInfo->fontDescent); |
166 | pcfPutINT32(file, format, pFontInfo->maxOverlap); |
167 | pcfPutMetric(file, format, &pFontInfo->minbounds); |
168 | pcfPutMetric(file, format, &pFontInfo->maxbounds); |
169 | if (PCF_FORMAT_MATCH(format, PCF_ACCEL_W_INKBOUNDS)(((format)&0xffffff00) == ((0x00000100)&0xffffff00))) { |
170 | pcfPutMetric(file, format, &pFontInfo->ink_minbounds); |
171 | pcfPutMetric(file, format, &pFontInfo->ink_maxbounds); |
172 | } |
173 | } |
174 | |
175 | #define S324 4 |
176 | #define S162 2 |
177 | #define S81 1 |
178 | |
179 | #define Pad(s)((((s) + 3) & ~3) - (s)) (RoundUp(s)(((s) + 3) & ~3) - (s)) |
180 | #define RoundUp(s)(((s) + 3) & ~3) (((s) + 3) & ~3) |
181 | |
182 | #define Compressable(i)(-128 <= (i) && (i) <= 127) (-128 <= (i) && (i) <= 127) |
183 | |
184 | #define CanCompressMetric(m)((-128 <= ((m)->leftSideBearing) && ((m)->leftSideBearing ) <= 127) && (-128 <= ((m)->rightSideBearing ) && ((m)->rightSideBearing) <= 127) && (-128 <= ((m)->characterWidth) && ((m)->characterWidth ) <= 127) && (-128 <= ((m)->ascent) && ((m)->ascent) <= 127) && (-128 <= ((m)-> descent) && ((m)->descent) <= 127) && ( m)->attributes == 0) (Compressable((m)->leftSideBearing)(-128 <= ((m)->leftSideBearing) && ((m)->leftSideBearing ) <= 127) && \ |
185 | Compressable((m)->rightSideBearing)(-128 <= ((m)->rightSideBearing) && ((m)->rightSideBearing ) <= 127) && \ |
186 | Compressable((m)->characterWidth)(-128 <= ((m)->characterWidth) && ((m)->characterWidth ) <= 127) && \ |
187 | Compressable((m)->ascent)(-128 <= ((m)->ascent) && ((m)->ascent) <= 127) && \ |
188 | Compressable((m)->descent)(-128 <= ((m)->descent) && ((m)->descent) <= 127) && \ |
189 | (m)->attributes == 0) |
190 | |
191 | #define CanCompressMetrics(min,max)(((-128 <= ((min)->leftSideBearing) && ((min)-> leftSideBearing) <= 127) && (-128 <= ((min)-> rightSideBearing) && ((min)->rightSideBearing) <= 127) && (-128 <= ((min)->characterWidth) && ((min)->characterWidth) <= 127) && (-128 <= ((min)->ascent) && ((min)->ascent) <= 127) && (-128 <= ((min)->descent) && ((min)->descent ) <= 127) && (min)->attributes == 0) && ((-128 <= ((max)->leftSideBearing) && ((max)-> leftSideBearing) <= 127) && (-128 <= ((max)-> rightSideBearing) && ((max)->rightSideBearing) <= 127) && (-128 <= ((max)->characterWidth) && ((max)->characterWidth) <= 127) && (-128 <= ((max)->ascent) && ((max)->ascent) <= 127) && (-128 <= ((max)->descent) && ((max)->descent ) <= 127) && (max)->attributes == 0)) (CanCompressMetric(min)((-128 <= ((min)->leftSideBearing) && ((min)-> leftSideBearing) <= 127) && (-128 <= ((min)-> rightSideBearing) && ((min)->rightSideBearing) <= 127) && (-128 <= ((min)->characterWidth) && ((min)->characterWidth) <= 127) && (-128 <= ((min)->ascent) && ((min)->ascent) <= 127) && (-128 <= ((min)->descent) && ((min)->descent ) <= 127) && (min)->attributes == 0) && CanCompressMetric(max)((-128 <= ((max)->leftSideBearing) && ((max)-> leftSideBearing) <= 127) && (-128 <= ((max)-> rightSideBearing) && ((max)->rightSideBearing) <= 127) && (-128 <= ((max)->characterWidth) && ((max)->characterWidth) <= 127) && (-128 <= ((max)->ascent) && ((max)->ascent) <= 127) && (-128 <= ((max)->descent) && ((max)->descent ) <= 127) && (max)->attributes == 0)) |
192 | |
193 | static const char * |
194 | pcfNameForAtom(Atom a) |
195 | { |
196 | return NameForAtom__libxfont__NameForAtom(a); |
197 | } |
198 | |
199 | int |
200 | pcfWriteFont(FontPtr pFont, FontFilePtr file) |
201 | { |
202 | PCFTableRec tables[32], |
203 | *table; |
204 | CARD32 mask, |
205 | bit; |
206 | int ntables; |
207 | int size; |
208 | CARD32 format; |
209 | int i; |
210 | int cur_table; |
211 | int prop_string_size; |
212 | int glyph_string_size; |
213 | xCharInfo *minbounds, |
214 | *maxbounds; |
215 | xCharInfo *ink_minbounds, |
216 | *ink_maxbounds; |
217 | BitmapFontPtr bitmapFont; |
218 | int nencodings = 0; |
219 | int header_size; |
220 | FontPropPtr offsetProps; |
221 | int prop_pad = 0; |
222 | const char *atom_name; |
223 | int glyph; |
224 | CARD32 offset; |
225 | |
226 | bitmapFont = (BitmapFontPtr) pFont->fontPrivate; |
227 | if (bitmapFont->bitmapExtra) { |
228 | minbounds = &bitmapFont->bitmapExtra->info.minbounds; |
229 | maxbounds = &bitmapFont->bitmapExtra->info.maxbounds; |
230 | ink_minbounds = &bitmapFont->bitmapExtra->info.ink_minbounds; |
231 | ink_maxbounds = &bitmapFont->bitmapExtra->info.ink_maxbounds; |
232 | } else { |
233 | minbounds = &pFont->info.minbounds; |
234 | maxbounds = &pFont->info.maxbounds; |
235 | ink_minbounds = &pFont->info.ink_minbounds; |
236 | ink_maxbounds = &pFont->info.ink_maxbounds; |
237 | } |
238 | offsetProps = malloc(pFont->info.nprops * sizeof(FontPropRec)); |
239 | if (!offsetProps) { |
240 | pcfError("pcfWriteFont(): Couldn't allocate offsetProps (%d*%d)", |
241 | pFont->info.nprops, (int) sizeof(FontPropRec)); |
242 | return AllocError80; |
243 | } |
244 | prop_string_size = 0; |
245 | for (i = 0; i < pFont->info.nprops; i++) { |
246 | offsetProps[i].name = prop_string_size; |
247 | prop_string_size += strlen(pcfNameForAtom(pFont->info.props[i].name)) + 1; |
248 | if (pFont->info.isStringProp[i]) { |
249 | offsetProps[i].value = prop_string_size; |
250 | prop_string_size += strlen(pcfNameForAtom(pFont->info.props[i].value)) + 1; |
251 | } else |
252 | offsetProps[i].value = pFont->info.props[i].value; |
253 | } |
254 | format = PCF_FORMAT(pFont->bit, pFont->byte, pFont->glyph, pFont->scan)( (((pFont->scan) == 4 ? 2 : (pFont->scan) == 2 ? 1 : 0 ) << 4) | (((pFont->bit) == 1 ? 1 : 0) << 3) | (((pFont->byte) == 1 ? 1 : 0) << 2) | (((pFont-> glyph) == 4 ? 2 : (pFont->glyph) == 2 ? 1 : 0) << 0) ); |
255 | mask = 0xFFFFFFF; |
256 | ntables = 0; |
257 | table = tables; |
258 | while (mask) { |
259 | bit = lowbit(mask)((mask) & (~(mask) + 1)); |
260 | mask &= ~bit; |
261 | table->type = bit; |
262 | switch (bit) { |
263 | case PCF_PROPERTIES(1<<0): |
264 | table->format = PCF_DEFAULT_FORMAT0x00000000 | format; |
265 | size = S324 + S324 + (S324 + S81 + S324) * pFont->info.nprops; |
266 | prop_pad = Pad(size)((((size) + 3) & ~3) - (size)); |
267 | table->size = RoundUp(size)(((size) + 3) & ~3) + S324 + |
268 | RoundUp(prop_string_size)(((prop_string_size) + 3) & ~3); |
269 | table++; |
270 | break; |
271 | case PCF_ACCELERATORS(1<<1): |
272 | if (bitmapFont->bitmapExtra->info.inkMetrics) |
273 | table->format = PCF_ACCEL_W_INKBOUNDS0x00000100 | format; |
274 | else |
275 | table->format = PCF_DEFAULT_FORMAT0x00000000 | format; |
276 | table->size = 100; |
277 | table++; |
278 | break; |
279 | case PCF_METRICS(1<<2): |
280 | if (CanCompressMetrics(minbounds, maxbounds)(((-128 <= ((minbounds)->leftSideBearing) && (( minbounds)->leftSideBearing) <= 127) && (-128 <= ((minbounds)->rightSideBearing) && ((minbounds)-> rightSideBearing) <= 127) && (-128 <= ((minbounds )->characterWidth) && ((minbounds)->characterWidth ) <= 127) && (-128 <= ((minbounds)->ascent) && ((minbounds)->ascent) <= 127) && (-128 <= ( (minbounds)->descent) && ((minbounds)->descent) <= 127) && (minbounds)->attributes == 0) && ((-128 <= ((maxbounds)->leftSideBearing) && (( maxbounds)->leftSideBearing) <= 127) && (-128 <= ((maxbounds)->rightSideBearing) && ((maxbounds)-> rightSideBearing) <= 127) && (-128 <= ((maxbounds )->characterWidth) && ((maxbounds)->characterWidth ) <= 127) && (-128 <= ((maxbounds)->ascent) && ((maxbounds)->ascent) <= 127) && (-128 <= ( (maxbounds)->descent) && ((maxbounds)->descent) <= 127) && (maxbounds)->attributes == 0))) { |
281 | table->format = PCF_COMPRESSED_METRICS0x00000100 | format; |
282 | size = S324 + S162 + bitmapFont->num_chars * (5 * S81); |
283 | table->size = RoundUp(size)(((size) + 3) & ~3); |
284 | } else { |
285 | table->format = PCF_DEFAULT_FORMAT0x00000000 | format; |
286 | table->size = S324 + S324 + bitmapFont->num_chars * (6 * S162); |
287 | } |
288 | table++; |
289 | break; |
290 | case PCF_BITMAPS(1<<3): |
291 | table->format = PCF_DEFAULT_FORMAT0x00000000 | format; |
292 | size = S324 + S324 + bitmapFont->num_chars * S324 + |
293 | GLYPHPADOPTIONS4 * S324 + |
294 | bitmapFont->bitmapExtra->bitmapsSizes[PCF_GLYPH_PAD_INDEX(format)((format) & (3<<0))]; |
295 | table->size = RoundUp(size)(((size) + 3) & ~3); |
296 | table++; |
297 | break; |
298 | case PCF_INK_METRICS(1<<4): |
299 | if (bitmapFont->ink_metrics) { |
300 | if (CanCompressMetrics(ink_minbounds, ink_maxbounds)(((-128 <= ((ink_minbounds)->leftSideBearing) && ((ink_minbounds)->leftSideBearing) <= 127) && ( -128 <= ((ink_minbounds)->rightSideBearing) && ( (ink_minbounds)->rightSideBearing) <= 127) && ( -128 <= ((ink_minbounds)->characterWidth) && (( ink_minbounds)->characterWidth) <= 127) && (-128 <= ((ink_minbounds)->ascent) && ((ink_minbounds )->ascent) <= 127) && (-128 <= ((ink_minbounds )->descent) && ((ink_minbounds)->descent) <= 127) && (ink_minbounds)->attributes == 0) && ((-128 <= ((ink_maxbounds)->leftSideBearing) && ((ink_maxbounds)->leftSideBearing) <= 127) && ( -128 <= ((ink_maxbounds)->rightSideBearing) && ( (ink_maxbounds)->rightSideBearing) <= 127) && ( -128 <= ((ink_maxbounds)->characterWidth) && (( ink_maxbounds)->characterWidth) <= 127) && (-128 <= ((ink_maxbounds)->ascent) && ((ink_maxbounds )->ascent) <= 127) && (-128 <= ((ink_maxbounds )->descent) && ((ink_maxbounds)->descent) <= 127) && (ink_maxbounds)->attributes == 0))) { |
301 | table->format = PCF_COMPRESSED_METRICS0x00000100 | format; |
302 | size = S324 + S162 + bitmapFont->num_chars * (5 * S81); |
303 | table->size = RoundUp(size)(((size) + 3) & ~3); |
304 | } else { |
305 | table->format = PCF_DEFAULT_FORMAT0x00000000 | format; |
306 | table->size = S324 + S324 + bitmapFont->num_chars * (6 * S162); |
307 | } |
308 | table++; |
309 | } |
310 | break; |
311 | case PCF_BDF_ENCODINGS(1<<5): |
312 | table->format = PCF_DEFAULT_FORMAT0x00000000 | format; |
313 | nencodings = (pFont->info.lastRow - pFont->info.firstRow + 1) * |
314 | (pFont->info.lastCol - pFont->info.firstCol + 1); |
315 | size = S324 + 5 * S162 + nencodings * S162; |
316 | table->size = RoundUp(size)(((size) + 3) & ~3); |
317 | table++; |
318 | break; |
319 | case PCF_SWIDTHS(1<<6): |
320 | table->format = PCF_DEFAULT_FORMAT0x00000000 | format; |
321 | table->size = S324 + S324 + bitmapFont->num_chars * S324; |
322 | table++; |
323 | break; |
324 | case PCF_GLYPH_NAMES(1<<7): |
325 | table->format = PCF_DEFAULT_FORMAT0x00000000 | format; |
326 | glyph_string_size = 0; |
327 | for (i = 0; i < bitmapFont->num_chars; i++) |
328 | glyph_string_size += strlen(pcfNameForAtom(bitmapFont->bitmapExtra->glyphNames[i])) + 1; |
329 | table->size = S324 + S324 + bitmapFont->num_chars * S324 + |
330 | S324 + RoundUp(glyph_string_size)(((glyph_string_size) + 3) & ~3); |
331 | table++; |
332 | break; |
333 | case PCF_BDF_ACCELERATORS(1<<8): |
334 | if (pFont->info.inkMetrics) |
335 | table->format = PCF_ACCEL_W_INKBOUNDS0x00000100 | format; |
336 | else |
337 | table->format = PCF_DEFAULT_FORMAT0x00000000 | format; |
338 | table->size = 100; |
339 | table++; |
340 | break; |
341 | } |
342 | } |
343 | ntables = table - tables; |
344 | offset = 0; |
Value stored to 'offset' is never read | |
345 | header_size = S324 + S324 + ntables * (4 * S324); |
346 | offset = header_size; |
347 | for (cur_table = 0, table = tables; |
348 | cur_table < ntables; |
349 | cur_table++, table++) { |
350 | table->offset = offset; |
351 | offset += table->size; |
352 | } |
353 | current_position = 0; |
354 | pcfWriteTOC(file, tables, ntables); |
355 | for (cur_table = 0, table = tables; |
356 | cur_table < ntables; |
357 | cur_table++, table++) { |
358 | if (current_position > table->offset) { |
359 | printf("can't go backwards... %d > %d\n", |
360 | (int)current_position, (int)table->offset); |
361 | free(offsetProps); |
362 | return BadFontName83; |
363 | } |
364 | while (current_position < table->offset) |
365 | pcfPutINT8(file, format, '\0'); |
366 | pcfPutLSB32(file, table->format); |
367 | switch (table->type) { |
368 | case PCF_PROPERTIES(1<<0): |
369 | pcfPutINT32(file, format, pFont->info.nprops); |
370 | for (i = 0; i < pFont->info.nprops; i++) { |
371 | pcfPutINT32(file, format, offsetProps[i].name); |
372 | pcfPutINT8(file, format, pFont->info.isStringProp[i]); |
373 | pcfPutINT32(file, format, offsetProps[i].value); |
374 | } |
375 | for (i = 0; i < prop_pad; i++) |
376 | pcfPutINT8(file, format, 0); |
377 | pcfPutINT32(file, format, prop_string_size); |
378 | for (i = 0; i < pFont->info.nprops; i++) { |
379 | atom_name = pcfNameForAtom(pFont->info.props[i].name); |
380 | pcfWrite(file, atom_name, strlen(atom_name) + 1); |
381 | if (pFont->info.isStringProp[i]) { |
382 | atom_name = pcfNameForAtom(pFont->info.props[i].value); |
383 | pcfWrite(file, atom_name, strlen(atom_name) + 1); |
384 | } |
385 | } |
386 | break; |
387 | case PCF_ACCELERATORS(1<<1): |
388 | pcfPutAccel(file, table->format, &bitmapFont->bitmapExtra->info); |
389 | break; |
390 | case PCF_METRICS(1<<2): |
391 | if (PCF_FORMAT_MATCH(table->format, PCF_COMPRESSED_METRICS)(((table->format)&0xffffff00) == ((0x00000100)&0xffffff00 ))) { |
392 | pcfPutINT16(file, format, bitmapFont->num_chars); |
393 | for (i = 0; i < bitmapFont->num_chars; i++) |
394 | pcfPutCompressedMetric(file, format, &bitmapFont->metrics[i].metrics); |
395 | } else { |
396 | pcfPutINT32(file, format, bitmapFont->num_chars); |
397 | for (i = 0; i < bitmapFont->num_chars; i++) |
398 | pcfPutMetric(file, format, &bitmapFont->metrics[i].metrics); |
399 | } |
400 | break; |
401 | case PCF_BITMAPS(1<<3): |
402 | pcfPutINT32(file, format, bitmapFont->num_chars); |
403 | glyph = PCF_GLYPH_PAD(format)(1<<((format) & (3<<0))); |
404 | offset = 0; |
405 | for (i = 0; i < bitmapFont->num_chars; i++) { |
406 | pcfPutINT32(file, format, offset); |
407 | offset += BYTES_FOR_GLYPH(&bitmapFont->metrics[i], glyph)(((&bitmapFont->metrics[i])->metrics.ascent + (& bitmapFont->metrics[i])->metrics.descent) * ((glyph) == 1 ? (((((&bitmapFont->metrics[i])->metrics.rightSideBearing - (&bitmapFont->metrics[i])->metrics.leftSideBearing ))+7)>>3) :(glyph) == 2 ? ((((((&bitmapFont->metrics [i])->metrics.rightSideBearing - (&bitmapFont->metrics [i])->metrics.leftSideBearing))+15)>>3)&~1) :(glyph ) == 4 ? ((((((&bitmapFont->metrics[i])->metrics.rightSideBearing - (&bitmapFont->metrics[i])->metrics.leftSideBearing ))+31)>>3)&~3) :(glyph) == 8 ? ((((((&bitmapFont ->metrics[i])->metrics.rightSideBearing - (&bitmapFont ->metrics[i])->metrics.leftSideBearing))+63)>>3)& ~7) : 0)); |
408 | } |
409 | for (i = 0; i < GLYPHPADOPTIONS4; i++) { |
410 | pcfPutINT32(file, format, |
411 | bitmapFont->bitmapExtra->bitmapsSizes[i]); |
412 | } |
413 | for (i = 0; i < bitmapFont->num_chars; i++) |
414 | pcfPutBitmap(file, format, &bitmapFont->metrics[i]); |
415 | break; |
416 | case PCF_INK_METRICS(1<<4): |
417 | if (PCF_FORMAT_MATCH(table->format, PCF_COMPRESSED_METRICS)(((table->format)&0xffffff00) == ((0x00000100)&0xffffff00 ))) { |
418 | pcfPutINT16(file, format, bitmapFont->num_chars); |
419 | for (i = 0; i < bitmapFont->num_chars; i++) |
420 | pcfPutCompressedMetric(file, format, &bitmapFont->ink_metrics[i]); |
421 | } else { |
422 | pcfPutINT32(file, format, bitmapFont->num_chars); |
423 | for (i = 0; i < bitmapFont->num_chars; i++) |
424 | pcfPutMetric(file, format, &bitmapFont->ink_metrics[i]); |
425 | } |
426 | break; |
427 | case PCF_BDF_ENCODINGS(1<<5): |
428 | pcfPutINT16(file, format, pFont->info.firstCol); |
429 | pcfPutINT16(file, format, pFont->info.lastCol); |
430 | pcfPutINT16(file, format, pFont->info.firstRow); |
431 | pcfPutINT16(file, format, pFont->info.lastRow); |
432 | pcfPutINT16(file, format, pFont->info.defaultCh); |
433 | for (i = 0; i < nencodings; i++) { |
434 | if (ACCESSENCODING(bitmapFont->encoding,i)(bitmapFont->encoding[(i)/128]?(bitmapFont->encoding[(i )/128][(i)%128]):0)) |
435 | pcfPutINT16(file, format, |
436 | ACCESSENCODING(bitmapFont->encoding, i)(bitmapFont->encoding[(i)/128]?(bitmapFont->encoding[(i )/128][(i)%128]):0) - |
437 | bitmapFont->metrics); |
438 | else |
439 | pcfPutINT16(file, format, 0xFFFF); |
440 | } |
441 | break; |
442 | case PCF_SWIDTHS(1<<6): |
443 | pcfPutINT32(file, format, bitmapFont->num_chars); |
444 | for (i = 0; i < bitmapFont->num_chars; i++) |
445 | pcfPutINT32(file, format, bitmapFont->bitmapExtra->sWidths[i]); |
446 | break; |
447 | case PCF_GLYPH_NAMES(1<<7): |
448 | pcfPutINT32(file, format, bitmapFont->num_chars); |
449 | offset = 0; |
450 | for (i = 0; i < bitmapFont->num_chars; i++) { |
451 | pcfPutINT32(file, format, offset); |
452 | offset += strlen(pcfNameForAtom(bitmapFont->bitmapExtra->glyphNames[i])) + 1; |
453 | } |
454 | pcfPutINT32(file, format, offset); |
455 | for (i = 0; i < bitmapFont->num_chars; i++) { |
456 | atom_name = pcfNameForAtom(bitmapFont->bitmapExtra->glyphNames[i]); |
457 | pcfWrite(file, atom_name, strlen(atom_name) + 1); |
458 | } |
459 | break; |
460 | case PCF_BDF_ACCELERATORS(1<<8): |
461 | pcfPutAccel(file, table->format, &pFont->info); |
462 | break; |
463 | } |
464 | } |
465 | |
466 | free(offsetProps); |
467 | return Successful85; |
468 | } |