| OLD | NEW |
| 1 /***************************************************************************/ | 1 /***************************************************************************/ |
| 2 /* */ | 2 /* */ |
| 3 /* ttpload.c */ | 3 /* ttpload.c */ |
| 4 /* */ | 4 /* */ |
| 5 /* TrueType-specific tables loader (body). */ | 5 /* TrueType-specific tables loader (body). */ |
| 6 /* */ | 6 /* */ |
| 7 /* Copyright 1996-2002, 2004-2012 by */ | 7 /* Copyright 1996-2002, 2004-2013 by */ |
| 8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ | 8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ |
| 9 /* */ | 9 /* */ |
| 10 /* This file is part of the FreeType project, and may only be used, */ | 10 /* This file is part of the FreeType project, and may only be used, */ |
| 11 /* modified, and distributed under the terms of the FreeType project */ | 11 /* modified, and distributed under the terms of the FreeType project */ |
| 12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ | 12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ |
| 13 /* this file you indicate that you have read the license and */ | 13 /* this file you indicate that you have read the license and */ |
| 14 /* understand and accept it fully. */ | 14 /* understand and accept it fully. */ |
| 15 /* */ | 15 /* */ |
| 16 /***************************************************************************/ | 16 /***************************************************************************/ |
| 17 | 17 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 FT_Error error; | 65 FT_Error error; |
| 66 FT_ULong table_len; | 66 FT_ULong table_len; |
| 67 FT_Int shift; | 67 FT_Int shift; |
| 68 | 68 |
| 69 | 69 |
| 70 /* we need the size of the `glyf' table for malformed `loca' tables */ | 70 /* we need the size of the `glyf' table for malformed `loca' tables */ |
| 71 error = face->goto_table( face, TTAG_glyf, stream, &face->glyf_len ); | 71 error = face->goto_table( face, TTAG_glyf, stream, &face->glyf_len ); |
| 72 | 72 |
| 73 /* it is possible that a font doesn't have a glyf table at all */ | 73 /* it is possible that a font doesn't have a glyf table at all */ |
| 74 /* or its size is zero */ | 74 /* or its size is zero */ |
| 75 if ( error == TT_Err_Table_Missing ) | 75 if ( FT_ERR_EQ( error, Table_Missing ) ) |
| 76 face->glyf_len = 0; | 76 face->glyf_len = 0; |
| 77 else if ( error ) | 77 else if ( error ) |
| 78 goto Exit; | 78 goto Exit; |
| 79 | 79 |
| 80 FT_TRACE2(( "Locations " )); | 80 FT_TRACE2(( "Locations " )); |
| 81 error = face->goto_table( face, TTAG_loca, stream, &table_len ); | 81 error = face->goto_table( face, TTAG_loca, stream, &table_len ); |
| 82 if ( error ) | 82 if ( error ) |
| 83 { | 83 { |
| 84 error = TT_Err_Locations_Missing; | 84 error = FT_THROW( Locations_Missing ); |
| 85 goto Exit; | 85 goto Exit; |
| 86 } | 86 } |
| 87 | 87 |
| 88 if ( face->header.Index_To_Loc_Format != 0 ) | 88 if ( face->header.Index_To_Loc_Format != 0 ) |
| 89 { | 89 { |
| 90 shift = 2; | 90 shift = 2; |
| 91 | 91 |
| 92 if ( table_len >= 0x40000L ) | 92 if ( table_len >= 0x40000L ) |
| 93 { | 93 { |
| 94 FT_TRACE2(( "table too large\n" )); | 94 FT_TRACE2(( "table too large\n" )); |
| 95 error = TT_Err_Invalid_Table; | 95 error = FT_THROW( Invalid_Table ); |
| 96 goto Exit; | 96 goto Exit; |
| 97 } | 97 } |
| 98 face->num_locations = table_len >> shift; | 98 face->num_locations = table_len >> shift; |
| 99 } | 99 } |
| 100 else | 100 else |
| 101 { | 101 { |
| 102 shift = 1; | 102 shift = 1; |
| 103 | 103 |
| 104 if ( table_len >= 0x20000L ) | 104 if ( table_len >= 0x20000L ) |
| 105 { | 105 { |
| 106 FT_TRACE2(( "table too large\n" )); | 106 FT_TRACE2(( "table too large\n" )); |
| 107 error = TT_Err_Invalid_Table; | 107 error = FT_THROW( Invalid_Table ); |
| 108 goto Exit; | 108 goto Exit; |
| 109 } | 109 } |
| 110 face->num_locations = table_len >> shift; | 110 face->num_locations = table_len >> shift; |
| 111 } | 111 } |
| 112 | 112 |
| 113 if ( face->num_locations != (FT_ULong)face->root.num_glyphs + 1 ) | 113 if ( face->num_locations != (FT_ULong)face->root.num_glyphs + 1 ) |
| 114 { | 114 { |
| 115 FT_TRACE2(( "glyph count mismatch! loca: %d, maxp: %d\n", | 115 FT_TRACE2(( "glyph count mismatch! loca: %d, maxp: %d\n", |
| 116 face->num_locations - 1, face->root.num_glyphs )); | 116 face->num_locations - 1, face->root.num_glyphs )); |
| 117 | 117 |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 | 289 |
| 290 FT_TRACE2(( "CVT " )); | 290 FT_TRACE2(( "CVT " )); |
| 291 | 291 |
| 292 error = face->goto_table( face, TTAG_cvt, stream, &table_len ); | 292 error = face->goto_table( face, TTAG_cvt, stream, &table_len ); |
| 293 if ( error ) | 293 if ( error ) |
| 294 { | 294 { |
| 295 FT_TRACE2(( "is missing\n" )); | 295 FT_TRACE2(( "is missing\n" )); |
| 296 | 296 |
| 297 face->cvt_size = 0; | 297 face->cvt_size = 0; |
| 298 face->cvt = NULL; | 298 face->cvt = NULL; |
| 299 error = TT_Err_Ok; | 299 error = FT_Err_Ok; |
| 300 | 300 |
| 301 goto Exit; | 301 goto Exit; |
| 302 } | 302 } |
| 303 | 303 |
| 304 face->cvt_size = table_len / 2; | 304 face->cvt_size = table_len / 2; |
| 305 | 305 |
| 306 if ( FT_NEW_ARRAY( face->cvt, face->cvt_size ) ) | 306 if ( FT_NEW_ARRAY( face->cvt, face->cvt_size ) ) |
| 307 goto Exit; | 307 goto Exit; |
| 308 | 308 |
| 309 if ( FT_FRAME_ENTER( face->cvt_size * 2L ) ) | 309 if ( FT_FRAME_ENTER( face->cvt_size * 2L ) ) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 327 #endif | 327 #endif |
| 328 | 328 |
| 329 Exit: | 329 Exit: |
| 330 return error; | 330 return error; |
| 331 | 331 |
| 332 #else /* !TT_USE_BYTECODE_INTERPRETER */ | 332 #else /* !TT_USE_BYTECODE_INTERPRETER */ |
| 333 | 333 |
| 334 FT_UNUSED( face ); | 334 FT_UNUSED( face ); |
| 335 FT_UNUSED( stream ); | 335 FT_UNUSED( stream ); |
| 336 | 336 |
| 337 return TT_Err_Ok; | 337 return FT_Err_Ok; |
| 338 | 338 |
| 339 #endif | 339 #endif |
| 340 } | 340 } |
| 341 | 341 |
| 342 | 342 |
| 343 /*************************************************************************/ | 343 /*************************************************************************/ |
| 344 /* */ | 344 /* */ |
| 345 /* <Function> */ | 345 /* <Function> */ |
| 346 /* tt_face_load_fpgm */ | 346 /* tt_face_load_fpgm */ |
| 347 /* */ | 347 /* */ |
| (...skipping 20 matching lines...) Expand all Loading... |
| 368 | 368 |
| 369 | 369 |
| 370 FT_TRACE2(( "Font program " )); | 370 FT_TRACE2(( "Font program " )); |
| 371 | 371 |
| 372 /* The font program is optional */ | 372 /* The font program is optional */ |
| 373 error = face->goto_table( face, TTAG_fpgm, stream, &table_len ); | 373 error = face->goto_table( face, TTAG_fpgm, stream, &table_len ); |
| 374 if ( error ) | 374 if ( error ) |
| 375 { | 375 { |
| 376 face->font_program = NULL; | 376 face->font_program = NULL; |
| 377 face->font_program_size = 0; | 377 face->font_program_size = 0; |
| 378 error = TT_Err_Ok; | 378 error = FT_Err_Ok; |
| 379 | 379 |
| 380 FT_TRACE2(( "is missing\n" )); | 380 FT_TRACE2(( "is missing\n" )); |
| 381 } | 381 } |
| 382 else | 382 else |
| 383 { | 383 { |
| 384 face->font_program_size = table_len; | 384 face->font_program_size = table_len; |
| 385 if ( FT_FRAME_EXTRACT( table_len, face->font_program ) ) | 385 if ( FT_FRAME_EXTRACT( table_len, face->font_program ) ) |
| 386 goto Exit; | 386 goto Exit; |
| 387 | 387 |
| 388 FT_TRACE2(( "loaded, %12d bytes\n", face->font_program_size )); | 388 FT_TRACE2(( "loaded, %12d bytes\n", face->font_program_size )); |
| 389 } | 389 } |
| 390 | 390 |
| 391 Exit: | 391 Exit: |
| 392 return error; | 392 return error; |
| 393 | 393 |
| 394 #else /* !TT_USE_BYTECODE_INTERPRETER */ | 394 #else /* !TT_USE_BYTECODE_INTERPRETER */ |
| 395 | 395 |
| 396 FT_UNUSED( face ); | 396 FT_UNUSED( face ); |
| 397 FT_UNUSED( stream ); | 397 FT_UNUSED( stream ); |
| 398 | 398 |
| 399 return TT_Err_Ok; | 399 return FT_Err_Ok; |
| 400 | 400 |
| 401 #endif | 401 #endif |
| 402 } | 402 } |
| 403 | 403 |
| 404 | 404 |
| 405 /*************************************************************************/ | 405 /*************************************************************************/ |
| 406 /* */ | 406 /* */ |
| 407 /* <Function> */ | 407 /* <Function> */ |
| 408 /* tt_face_load_prep */ | 408 /* tt_face_load_prep */ |
| 409 /* */ | 409 /* */ |
| (...skipping 19 matching lines...) Expand all Loading... |
| 429 FT_ULong table_len; | 429 FT_ULong table_len; |
| 430 | 430 |
| 431 | 431 |
| 432 FT_TRACE2(( "Prep program " )); | 432 FT_TRACE2(( "Prep program " )); |
| 433 | 433 |
| 434 error = face->goto_table( face, TTAG_prep, stream, &table_len ); | 434 error = face->goto_table( face, TTAG_prep, stream, &table_len ); |
| 435 if ( error ) | 435 if ( error ) |
| 436 { | 436 { |
| 437 face->cvt_program = NULL; | 437 face->cvt_program = NULL; |
| 438 face->cvt_program_size = 0; | 438 face->cvt_program_size = 0; |
| 439 error = TT_Err_Ok; | 439 error = FT_Err_Ok; |
| 440 | 440 |
| 441 FT_TRACE2(( "is missing\n" )); | 441 FT_TRACE2(( "is missing\n" )); |
| 442 } | 442 } |
| 443 else | 443 else |
| 444 { | 444 { |
| 445 face->cvt_program_size = table_len; | 445 face->cvt_program_size = table_len; |
| 446 if ( FT_FRAME_EXTRACT( table_len, face->cvt_program ) ) | 446 if ( FT_FRAME_EXTRACT( table_len, face->cvt_program ) ) |
| 447 goto Exit; | 447 goto Exit; |
| 448 | 448 |
| 449 FT_TRACE2(( "loaded, %12d bytes\n", face->cvt_program_size )); | 449 FT_TRACE2(( "loaded, %12d bytes\n", face->cvt_program_size )); |
| 450 } | 450 } |
| 451 | 451 |
| 452 Exit: | 452 Exit: |
| 453 return error; | 453 return error; |
| 454 | 454 |
| 455 #else /* !TT_USE_BYTECODE_INTERPRETER */ | 455 #else /* !TT_USE_BYTECODE_INTERPRETER */ |
| 456 | 456 |
| 457 FT_UNUSED( face ); | 457 FT_UNUSED( face ); |
| 458 FT_UNUSED( stream ); | 458 FT_UNUSED( stream ); |
| 459 | 459 |
| 460 return TT_Err_Ok; | 460 return FT_Err_Ok; |
| 461 | 461 |
| 462 #endif | 462 #endif |
| 463 } | 463 } |
| 464 | 464 |
| 465 | 465 |
| 466 /*************************************************************************/ | 466 /*************************************************************************/ |
| 467 /* */ | 467 /* */ |
| 468 /* <Function> */ | 468 /* <Function> */ |
| 469 /* tt_face_load_hdmx */ | 469 /* tt_face_load_hdmx */ |
| 470 /* */ | 470 /* */ |
| (...skipping 17 matching lines...) Expand all Loading... |
| 488 FT_Memory memory = stream->memory; | 488 FT_Memory memory = stream->memory; |
| 489 FT_UInt version, nn, num_records; | 489 FT_UInt version, nn, num_records; |
| 490 FT_ULong table_size, record_size; | 490 FT_ULong table_size, record_size; |
| 491 FT_Byte* p; | 491 FT_Byte* p; |
| 492 FT_Byte* limit; | 492 FT_Byte* limit; |
| 493 | 493 |
| 494 | 494 |
| 495 /* this table is optional */ | 495 /* this table is optional */ |
| 496 error = face->goto_table( face, TTAG_hdmx, stream, &table_size ); | 496 error = face->goto_table( face, TTAG_hdmx, stream, &table_size ); |
| 497 if ( error || table_size < 8 ) | 497 if ( error || table_size < 8 ) |
| 498 return TT_Err_Ok; | 498 return FT_Err_Ok; |
| 499 | 499 |
| 500 if ( FT_FRAME_EXTRACT( table_size, face->hdmx_table ) ) | 500 if ( FT_FRAME_EXTRACT( table_size, face->hdmx_table ) ) |
| 501 goto Exit; | 501 goto Exit; |
| 502 | 502 |
| 503 p = face->hdmx_table; | 503 p = face->hdmx_table; |
| 504 limit = p + table_size; | 504 limit = p + table_size; |
| 505 | 505 |
| 506 version = FT_NEXT_USHORT( p ); | 506 version = FT_NEXT_USHORT( p ); |
| 507 num_records = FT_NEXT_USHORT( p ); | 507 num_records = FT_NEXT_USHORT( p ); |
| 508 record_size = FT_NEXT_ULONG( p ); | 508 record_size = FT_NEXT_ULONG( p ); |
| 509 | 509 |
| 510 /* The maximum number of bytes in an hdmx device record is the */ | 510 /* The maximum number of bytes in an hdmx device record is the */ |
| 511 /* maximum number of glyphs + 2; this is 0xFFFF + 2; this is */ | 511 /* maximum number of glyphs + 2; this is 0xFFFF + 2; this is */ |
| 512 /* the reason why `record_size' is a long (which we read as */ | 512 /* the reason why `record_size' is a long (which we read as */ |
| 513 /* unsigned long for convenience). In practice, two bytes */ | 513 /* unsigned long for convenience). In practice, two bytes */ |
| 514 /* sufficient to hold the size value. */ | 514 /* sufficient to hold the size value. */ |
| 515 /* */ | 515 /* */ |
| 516 /* There are at least two fonts, HANNOM-A and HANNOM-B version */ | 516 /* There are at least two fonts, HANNOM-A and HANNOM-B version */ |
| 517 /* 2.0 (2005), which get this wrong: The upper two bytes of */ | 517 /* 2.0 (2005), which get this wrong: The upper two bytes of */ |
| 518 /* the size value are set to 0xFF instead of 0x00. We catch */ | 518 /* the size value are set to 0xFF instead of 0x00. We catch */ |
| 519 /* and fix this. */ | 519 /* and fix this. */ |
| 520 | 520 |
| 521 if ( record_size >= 0xFFFF0000UL ) | 521 if ( record_size >= 0xFFFF0000UL ) |
| 522 record_size &= 0xFFFFU; | 522 record_size &= 0xFFFFU; |
| 523 | 523 |
| 524 /* The limit for `num_records' is a heuristic value. */ | 524 /* The limit for `num_records' is a heuristic value. */ |
| 525 | 525 |
| 526 if ( version != 0 || num_records > 255 || record_size > 0x10001L ) | 526 if ( version != 0 || num_records > 255 || record_size > 0x10001L ) |
| 527 { | 527 { |
| 528 error = TT_Err_Invalid_File_Format; | 528 error = FT_THROW( Invalid_File_Format ); |
| 529 goto Fail; | 529 goto Fail; |
| 530 } | 530 } |
| 531 | 531 |
| 532 if ( FT_NEW_ARRAY( face->hdmx_record_sizes, num_records ) ) | 532 if ( FT_NEW_ARRAY( face->hdmx_record_sizes, num_records ) ) |
| 533 goto Fail; | 533 goto Fail; |
| 534 | 534 |
| 535 for ( nn = 0; nn < num_records; nn++ ) | 535 for ( nn = 0; nn < num_records; nn++ ) |
| 536 { | 536 { |
| 537 if ( p + record_size > limit ) | 537 if ( p + record_size > limit ) |
| 538 break; | 538 break; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 if ( gindex < record_size ) | 590 if ( gindex < record_size ) |
| 591 result = record + nn * record_size + gindex; | 591 result = record + nn * record_size + gindex; |
| 592 break; | 592 break; |
| 593 } | 593 } |
| 594 | 594 |
| 595 return result; | 595 return result; |
| 596 } | 596 } |
| 597 | 597 |
| 598 | 598 |
| 599 /* END */ | 599 /* END */ |
| OLD | NEW |