... |
... |
@@ -156,64 +156,51 @@ |
156
|
156
|
|
157
|
157
|
|
158
|
158
|
static FT_Error
|
159
|
|
- load_format_20( TT_Face face,
|
160
|
|
- FT_Stream stream,
|
161
|
|
- FT_ULong post_len )
|
|
159
|
+ load_format_20( TT_Post_Names names,
|
|
160
|
+ FT_Stream stream,
|
|
161
|
+ FT_UShort num_glyphs,
|
|
162
|
+ FT_ULong post_len )
|
162
|
163
|
{
|
163
|
164
|
FT_Memory memory = stream->memory;
|
164
|
165
|
FT_Error error;
|
165
|
166
|
|
166
|
|
- FT_UShort num_glyphs;
|
|
167
|
+ FT_UShort n;
|
167
|
168
|
FT_UShort num_names = 0;
|
168
|
169
|
|
169
|
170
|
FT_UShort* glyph_indices = NULL;
|
170
|
171
|
FT_Byte** name_strings = NULL;
|
171
|
172
|
|
172
|
173
|
|
173
|
|
- if ( FT_READ_USHORT( num_glyphs ) )
|
174
|
|
- goto Exit;
|
175
|
|
-
|
176
|
|
- /* UNDOCUMENTED! The number of glyphs in this table can be smaller */
|
177
|
|
- /* than the value in the maxp table (cf. cyberbit.ttf). */
|
178
|
|
-
|
179
|
|
- /* There already exist fonts which have more than 32768 glyph names */
|
180
|
|
- /* in this table, so the test for this threshold has been dropped. */
|
181
|
|
-
|
182
|
|
- if ( num_glyphs > face->max_profile.numGlyphs ||
|
183
|
|
- (FT_ULong)num_glyphs * 2 > post_len )
|
|
174
|
+ if ( (FT_ULong)num_glyphs * 2 > post_len )
|
184
|
175
|
{
|
185
|
176
|
error = FT_THROW( Invalid_File_Format );
|
186
|
177
|
goto Exit;
|
187
|
178
|
}
|
188
|
179
|
|
189
|
180
|
/* load the indices and note their maximum */
|
190
|
|
- {
|
191
|
|
- FT_UShort n;
|
192
|
|
- FT_UShort idx;
|
193
|
|
-
|
|
181
|
+ if ( FT_QNEW_ARRAY( glyph_indices, num_glyphs ) ||
|
|
182
|
+ FT_FRAME_ENTER( num_glyphs * 2 ) )
|
|
183
|
+ goto Fail;
|
194
|
184
|
|
195
|
|
- if ( FT_QNEW_ARRAY( glyph_indices, num_glyphs ) ||
|
196
|
|
- FT_FRAME_ENTER( num_glyphs * 2 ) )
|
197
|
|
- goto Fail;
|
|
185
|
+ for ( n = 0; n < num_glyphs; n++ )
|
|
186
|
+ {
|
|
187
|
+ FT_UShort idx = FT_GET_USHORT();
|
198
|
188
|
|
199
|
|
- for ( n = 0; n < num_glyphs; n++ )
|
200
|
|
- {
|
201
|
|
- glyph_indices[n] = idx = FT_GET_USHORT();
|
202
|
189
|
|
203
|
|
- if ( idx > num_names )
|
204
|
|
- num_names = idx;
|
205
|
|
- }
|
|
190
|
+ if ( idx > num_names )
|
|
191
|
+ num_names = idx;
|
206
|
192
|
|
207
|
|
- FT_FRAME_EXIT();
|
|
193
|
+ glyph_indices[n] = idx;
|
208
|
194
|
}
|
209
|
195
|
|
|
196
|
+ FT_FRAME_EXIT();
|
|
197
|
+
|
210
|
198
|
/* compute number of names stored in table */
|
211
|
199
|
num_names = num_names > 257 ? num_names - 257 : 0;
|
212
|
200
|
|
213
|
201
|
/* now load the name strings */
|
214
|
202
|
if ( num_names )
|
215
|
203
|
{
|
216
|
|
- FT_UShort n;
|
217
|
204
|
FT_ULong p;
|
218
|
205
|
FT_Byte* strings;
|
219
|
206
|
|
... |
... |
@@ -258,15 +245,11 @@ |
258
|
245
|
}
|
259
|
246
|
|
260
|
247
|
/* all right, set table fields and exit successfully */
|
261
|
|
- {
|
262
|
|
- TT_Post_20 table = &face->postscript_names.names.format_20;
|
263
|
|
-
|
|
248
|
+ names->num_glyphs = num_glyphs;
|
|
249
|
+ names->num_names = num_names;
|
|
250
|
+ names->glyph_indices = glyph_indices;
|
|
251
|
+ names->glyph_names = name_strings;
|
264
|
252
|
|
265
|
|
- table->num_glyphs = num_glyphs;
|
266
|
|
- table->num_names = num_names;
|
267
|
|
- table->glyph_indices = glyph_indices;
|
268
|
|
- table->glyph_names = name_strings;
|
269
|
|
- }
|
270
|
253
|
return FT_Err_Ok;
|
271
|
254
|
|
272
|
255
|
Fail:
|
... |
... |
@@ -279,65 +262,55 @@ |
279
|
262
|
|
280
|
263
|
|
281
|
264
|
static FT_Error
|
282
|
|
- load_format_25( TT_Face face,
|
283
|
|
- FT_Stream stream,
|
284
|
|
- FT_ULong post_len )
|
|
265
|
+ load_format_25( TT_Post_Names names,
|
|
266
|
+ FT_Stream stream,
|
|
267
|
+ FT_UShort num_glyphs,
|
|
268
|
+ FT_ULong post_len )
|
285
|
269
|
{
|
286
|
270
|
FT_Memory memory = stream->memory;
|
287
|
271
|
FT_Error error;
|
288
|
272
|
|
289
|
|
- FT_UShort num_glyphs;
|
290
|
|
- FT_Char* offset_table = NULL;
|
291
|
|
-
|
|
273
|
+ FT_UShort n;
|
|
274
|
+ FT_UShort* glyph_indices = NULL;
|
292
|
275
|
|
293
|
|
- if ( FT_READ_USHORT( num_glyphs ) )
|
294
|
|
- goto Exit;
|
295
|
276
|
|
296
|
277
|
/* check the number of glyphs, including the theoretical limit */
|
297
|
|
- if ( num_glyphs > face->max_profile.numGlyphs ||
|
298
|
|
- num_glyphs > post_len ||
|
299
|
|
- num_glyphs > 257 + 128 )
|
|
278
|
+ if ( num_glyphs > post_len ||
|
|
279
|
+ num_glyphs > 258 + 128 )
|
300
|
280
|
{
|
301
|
281
|
error = FT_THROW( Invalid_File_Format );
|
302
|
282
|
goto Exit;
|
303
|
283
|
}
|
304
|
284
|
|
305
|
|
- if ( num_glyphs )
|
|
285
|
+ /* load the indices and note their maximum */
|
|
286
|
+ if ( FT_QNEW_ARRAY( glyph_indices, num_glyphs ) ||
|
|
287
|
+ FT_FRAME_ENTER( num_glyphs ) )
|
|
288
|
+ goto Fail;
|
|
289
|
+
|
|
290
|
+ for ( n = 0; n < num_glyphs; n++ )
|
306
|
291
|
{
|
307
|
|
- FT_UShort n;
|
|
292
|
+ FT_Int idx = n + FT_GET_CHAR();
|
308
|
293
|
|
309
|
294
|
|
310
|
|
- if ( FT_QNEW_ARRAY( offset_table, num_glyphs ) ||
|
311
|
|
- FT_STREAM_READ( offset_table, num_glyphs ) )
|
312
|
|
- goto Fail;
|
313
|
|
-
|
314
|
|
- /* now check the offset table for out-of-range values */
|
315
|
|
- for ( n = 0; n < num_glyphs; n++ )
|
|
295
|
+ if ( idx < 0 || idx > 257 )
|
316
|
296
|
{
|
317
|
|
- FT_Int idx = n + offset_table[n];
|
318
|
|
-
|
319
|
|
-
|
320
|
|
- if ( idx < 0 || idx > 257 )
|
321
|
|
- {
|
322
|
|
- error = FT_THROW( Invalid_File_Format );
|
323
|
|
- goto Fail;
|
324
|
|
- }
|
|
297
|
+ error = FT_THROW( Invalid_File_Format );
|
|
298
|
+ goto Fail;
|
325
|
299
|
}
|
326
|
|
- }
|
327
|
300
|
|
328
|
|
- /* OK, set table fields and exit successfully */
|
329
|
|
- {
|
330
|
|
- TT_Post_25 table = &face->postscript_names.names.format_25;
|
|
301
|
+ glyph_indices[n] = (FT_UShort)idx;
|
|
302
|
+ }
|
331
|
303
|
|
|
304
|
+ FT_FRAME_EXIT();
|
332
|
305
|
|
333
|
|
- table->num_glyphs = num_glyphs;
|
334
|
|
- table->offsets = offset_table;
|
335
|
|
- }
|
|
306
|
+ /* OK, set table fields and exit successfully */
|
|
307
|
+ names->num_glyphs = num_glyphs;
|
|
308
|
+ names->glyph_indices = glyph_indices;
|
336
|
309
|
|
337
|
310
|
return FT_Err_Ok;
|
338
|
311
|
|
339
|
312
|
Fail:
|
340
|
|
- FT_FREE( offset_table );
|
|
313
|
+ FT_FREE( glyph_indices );
|
341
|
314
|
|
342
|
315
|
Exit:
|
343
|
316
|
return error;
|
... |
... |
@@ -347,37 +320,37 @@ |
347
|
320
|
static FT_Error
|
348
|
321
|
load_post_names( TT_Face face )
|
349
|
322
|
{
|
350
|
|
- FT_Stream stream;
|
351
|
|
- FT_Error error;
|
352
|
|
- FT_Fixed format;
|
|
323
|
+ FT_Error error = FT_Err_Ok;
|
|
324
|
+ FT_Stream stream = face->root.stream;
|
|
325
|
+ FT_Fixed format = face->postscript.FormatType;
|
353
|
326
|
FT_ULong post_len;
|
|
327
|
+ FT_UShort num_glyphs;
|
354
|
328
|
|
355
|
329
|
|
356
|
|
- /* get a stream for the face's resource */
|
357
|
|
- stream = face->root.stream;
|
358
|
|
-
|
359
|
330
|
/* seek to the beginning of the PS names table */
|
360
|
331
|
error = face->goto_table( face, TTAG_post, stream, &post_len );
|
361
|
332
|
if ( error )
|
362
|
333
|
goto Exit;
|
363
|
334
|
|
364
|
|
- format = face->postscript.FormatType;
|
365
|
|
-
|
366
|
|
- /* go to beginning of subtable */
|
367
|
|
- if ( FT_STREAM_SKIP( 32 ) )
|
|
335
|
+ /* UNDOCUMENTED! The number of glyphs in this table can be smaller */
|
|
336
|
+ /* than the value in the maxp table (cf. cyberbit.ttf). */
|
|
337
|
+ if ( post_len < 34 ||
|
|
338
|
+ FT_STREAM_SKIP( 32 ) ||
|
|
339
|
+ FT_READ_USHORT( num_glyphs ) ||
|
|
340
|
+ num_glyphs > face->max_profile.numGlyphs ||
|
|
341
|
+ num_glyphs == 0 )
|
368
|
342
|
goto Exit;
|
369
|
343
|
|
370
|
|
- /* now read postscript table */
|
371
|
|
- if ( format == 0x00020000L && post_len >= 34 )
|
372
|
|
- error = load_format_20( face, stream, post_len - 34 );
|
373
|
|
- else if ( format == 0x00025000L && post_len >= 34 )
|
374
|
|
- error = load_format_25( face, stream, post_len - 34 );
|
375
|
|
- else
|
376
|
|
- error = FT_THROW( Invalid_File_Format );
|
377
|
|
-
|
378
|
|
- face->postscript_names.loaded = 1;
|
|
344
|
+ /* now read postscript names data */
|
|
345
|
+ if ( format == 0x00020000L )
|
|
346
|
+ error = load_format_20( &face->postscript_names, stream,
|
|
347
|
+ num_glyphs, post_len - 34 );
|
|
348
|
+ else if ( format == 0x00025000L )
|
|
349
|
+ error = load_format_25( &face->postscript_names, stream,
|
|
350
|
+ num_glyphs, post_len - 34 );
|
379
|
351
|
|
380
|
352
|
Exit:
|
|
353
|
+ face->postscript_names.loaded = 1; /* even if failed */
|
381
|
354
|
return error;
|
382
|
355
|
}
|
383
|
356
|
|
... |
... |
@@ -387,36 +360,20 @@ |
387
|
360
|
{
|
388
|
361
|
FT_Memory memory = face->root.memory;
|
389
|
362
|
TT_Post_Names names = &face->postscript_names;
|
390
|
|
- FT_Fixed format;
|
391
|
363
|
|
392
|
364
|
|
393
|
|
- if ( names->loaded )
|
|
365
|
+ if ( names->num_glyphs )
|
394
|
366
|
{
|
395
|
|
- format = face->postscript.FormatType;
|
396
|
|
-
|
397
|
|
- if ( format == 0x00020000L )
|
398
|
|
- {
|
399
|
|
- TT_Post_20 table = &names->names.format_20;
|
400
|
|
-
|
401
|
|
-
|
402
|
|
- FT_FREE( table->glyph_indices );
|
403
|
|
- table->num_glyphs = 0;
|
404
|
|
-
|
405
|
|
- if ( table->num_names )
|
406
|
|
- {
|
407
|
|
- FT_FREE( table->glyph_names );
|
408
|
|
- table->num_names = 0;
|
409
|
|
- }
|
410
|
|
- }
|
411
|
|
- else if ( format == 0x00025000L )
|
412
|
|
- {
|
413
|
|
- TT_Post_25 table = &names->names.format_25;
|
414
|
|
-
|
|
367
|
+ FT_FREE( names->glyph_indices );
|
|
368
|
+ names->num_glyphs = 0;
|
|
369
|
+ }
|
415
|
370
|
|
416
|
|
- FT_FREE( table->offsets );
|
417
|
|
- table->num_glyphs = 0;
|
418
|
|
- }
|
|
371
|
+ if ( names->num_names )
|
|
372
|
+ {
|
|
373
|
+ FT_FREE( names->glyph_names );
|
|
374
|
+ names->num_names = 0;
|
419
|
375
|
}
|
|
376
|
+
|
420
|
377
|
names->loaded = 0;
|
421
|
378
|
}
|
422
|
379
|
|
... |
... |
@@ -484,11 +441,9 @@ |
484
|
441
|
if ( idx < 258 ) /* paranoid checking */
|
485
|
442
|
*PSname = MAC_NAME( idx );
|
486
|
443
|
}
|
487
|
|
- else if ( format == 0x00020000L )
|
|
444
|
+ else if ( format == 0x00020000L ||
|
|
445
|
+ format == 0x00025000L )
|
488
|
446
|
{
|
489
|
|
- TT_Post_20 table = &names->names.format_20;
|
490
|
|
-
|
491
|
|
-
|
492
|
447
|
if ( !names->loaded )
|
493
|
448
|
{
|
494
|
449
|
error = load_post_names( face );
|
... |
... |
@@ -496,32 +451,17 @@ |
496
|
451
|
goto End;
|
497
|
452
|
}
|
498
|
453
|
|
499
|
|
- if ( idx < (FT_UInt)table->num_glyphs )
|
|
454
|
+ if ( idx < (FT_UInt)names->num_glyphs )
|
500
|
455
|
{
|
501
|
|
- FT_UShort name_index = table->glyph_indices[idx];
|
|
456
|
+ FT_UShort name_index = names->glyph_indices[idx];
|
502
|
457
|
|
503
|
458
|
|
504
|
459
|
if ( name_index < 258 )
|
505
|
460
|
*PSname = MAC_NAME( name_index );
|
506
|
|
- else
|
507
|
|
- *PSname = (FT_String*)table->glyph_names[name_index - 258];
|
|
461
|
+ else /* only for version 2.0 */
|
|
462
|
+ *PSname = (FT_String*)names->glyph_names[name_index - 258];
|
508
|
463
|
}
|
509
|
464
|
}
|
510
|
|
- else if ( format == 0x00025000L )
|
511
|
|
- {
|
512
|
|
- TT_Post_25 table = &names->names.format_25;
|
513
|
|
-
|
514
|
|
-
|
515
|
|
- if ( !names->loaded )
|
516
|
|
- {
|
517
|
|
- error = load_post_names( face );
|
518
|
|
- if ( error )
|
519
|
|
- goto End;
|
520
|
|
- }
|
521
|
|
-
|
522
|
|
- if ( idx < (FT_UInt)table->num_glyphs ) /* paranoid checking */
|
523
|
|
- *PSname = MAC_NAME( (FT_Int)idx + table->offsets[idx] );
|
524
|
|
- }
|
525
|
465
|
|
526
|
466
|
/* nothing to do for format == 0x00030000L */
|
527
|
467
|
|