1 /***************************************************************************/ 2 /* */ 3 /* sfobjs.c */ 4 /* */ 5 /* SFNT object management (base). */ 6 /* */ 7 /* Copyright 1996-2001, 2002 by */ 8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ 9 /* */ 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 */ 12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 13 /* this file you indicate that you have read the license and */ 14 /* understand and accept it fully. */ 15 /* */ 16 /***************************************************************************/ 17 18 19 #include <ft2build.h> 20 #include "sfobjs.h" 21 #include "ttload.h" 22 #include "ttcmap0.h" 23 #include FT_INTERNAL_SFNT_H 24 #include FT_INTERNAL_POSTSCRIPT_NAMES_H 25 #include FT_TRUETYPE_IDS_H 26 #include FT_TRUETYPE_TAGS_H 27 28 #include "sferrors.h" 29 30 31 /*************************************************************************/ 32 /* */ 33 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ 34 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ 35 /* messages during execution. */ 36 /* */ 37 #undef FT_COMPONENT 38 #define FT_COMPONENT trace_sfobjs 39 40 41 42 /* convert a UTF-16 name entry to ASCII */ 43 static FT_String* tt_name_entry_ascii_from_utf16(TT_NameEntry entry,FT_Memory memory)44 tt_name_entry_ascii_from_utf16( TT_NameEntry entry, 45 FT_Memory memory ) 46 { 47 FT_String* string; 48 FT_UInt len, code, n; 49 FT_Byte* read = (FT_Byte*)entry->string; 50 51 52 len = (FT_UInt)entry->stringLength / 2; 53 54 if ( FT_MEM_NEW_ARRAY( string, len + 1 ) ) 55 return NULL; 56 57 for ( n = 0; n < len; n++ ) 58 { 59 code = FT_NEXT_USHORT( read ); 60 if ( code < 32 || code > 127 ) 61 code = '?'; 62 63 string[n] = (char)code; 64 } 65 66 string[len] = 0; 67 68 return string; 69 } 70 71 72 /* convert a UCS-4 name entry to ASCII */ 73 static FT_String* tt_name_entry_ascii_from_ucs4(TT_NameEntry entry,FT_Memory memory)74 tt_name_entry_ascii_from_ucs4( TT_NameEntry entry, 75 FT_Memory memory ) 76 { 77 FT_String* string; 78 FT_UInt len, code, n; 79 FT_Byte* read = (FT_Byte*)entry->string; 80 81 82 len = (FT_UInt)entry->stringLength / 4; 83 84 if ( FT_MEM_NEW_ARRAY( string, len + 1 ) ) 85 return NULL; 86 87 for ( n = 0; n < len; n++ ) 88 { 89 code = (FT_UInt)FT_NEXT_ULONG( read ); 90 if ( code < 32 || code > 127 ) 91 code = '?'; 92 93 string[n] = (char)code; 94 } 95 96 string[len] = 0; 97 98 return string; 99 } 100 101 102 /* convert an Apple Roman or symbol name entry to ASCII */ 103 static FT_String* tt_name_entry_ascii_from_other(TT_NameEntry entry,FT_Memory memory)104 tt_name_entry_ascii_from_other( TT_NameEntry entry, 105 FT_Memory memory ) 106 { 107 FT_String* string; 108 FT_UInt len, code, n; 109 FT_Byte* read = (FT_Byte*)entry->string; 110 111 112 len = (FT_UInt)entry->stringLength; 113 114 if ( FT_MEM_NEW_ARRAY( string, len + 1 ) ) 115 return NULL; 116 117 for ( n = 0; n < len; n++ ) 118 { 119 code = *read++; 120 if ( code < 32 || code > 127 ) 121 code = '?'; 122 123 string[n] = (char)code; 124 } 125 126 string[len] = 0; 127 128 return string; 129 } 130 131 132 typedef FT_String* (*TT_NameEntry_ConvertFunc)( TT_NameEntry entry, 133 FT_Memory memory ); 134 135 136 /*************************************************************************/ 137 /* */ 138 /* <Function> */ 139 /* tt_face_get_name */ 140 /* */ 141 /* <Description> */ 142 /* Returns a given ENGLISH name record in ASCII. */ 143 /* */ 144 /* <Input> */ 145 /* face :: A handle to the source face object. */ 146 /* */ 147 /* nameid :: The name id of the name record to return. */ 148 /* */ 149 /* <Return> */ 150 /* Character string. NULL if no name is present. */ 151 /* */ 152 static FT_String* tt_face_get_name(TT_Face face,FT_UShort nameid)153 tt_face_get_name( TT_Face face, 154 FT_UShort nameid ) 155 { 156 FT_Memory memory = face->root.memory; 157 FT_String* result = NULL; 158 FT_UShort n; 159 TT_NameEntryRec* rec; 160 FT_Int found_apple = -1; 161 FT_Int found_win = -1; 162 FT_Int found_unicode = -1; 163 164 TT_NameEntry_ConvertFunc convert; 165 166 167 rec = face->name_table.names; 168 for ( n = 0; n < face->num_names; n++, rec++ ) 169 { 170 /* According to the OpenType 1.3 specification, only Microsoft or */ 171 /* Apple platform IDs might be used in the `name' table. The */ 172 /* `Unicode' platform is reserved for the `cmap' table, and the */ 173 /* `Iso' one is deprecated. */ 174 /* */ 175 /* However, the Apple TrueType specification doesn't say the same */ 176 /* thing and goes to suggest that all Unicode `name' table entries */ 177 /* should be coded in UTF-16 (in big-endian format I suppose). */ 178 /* */ 179 if ( rec->nameID == nameid && rec->stringLength > 0 ) 180 { 181 switch ( rec->platformID ) 182 { 183 case TT_PLATFORM_APPLE_UNICODE: 184 case TT_PLATFORM_ISO: 185 /* there is `languageID' to check there. We should use this */ 186 /* field only as a last solution when nothing else is */ 187 /* available. */ 188 /* */ 189 found_unicode = n; 190 break; 191 192 case TT_PLATFORM_MACINTOSH: 193 if ( rec->languageID == TT_MAC_LANGID_ENGLISH ) 194 found_apple = n; 195 196 break; 197 198 case TT_PLATFORM_MICROSOFT: 199 /* we only take a non-English name when there is nothing */ 200 /* else available in the font */ 201 /* */ 202 if ( found_win == -1 || ( rec->languageID & 0x3FF ) == 0x009 ) 203 { 204 switch ( rec->encodingID ) 205 { 206 case TT_MS_ID_SYMBOL_CS: 207 case TT_MS_ID_UNICODE_CS: 208 case TT_MS_ID_UCS_4: 209 found_win = n; 210 break; 211 212 default: 213 ; 214 } 215 } 216 break; 217 218 default: 219 ; 220 } 221 } 222 } 223 224 /* some fonts contain invalid Unicode or Macintosh formatted entries; */ 225 /* we will thus favor names encoded in Windows formats if available */ 226 /* */ 227 convert = NULL; 228 if ( found_win >= 0 ) 229 { 230 rec = face->name_table.names + found_win; 231 switch ( rec->encodingID ) 232 { 233 case TT_MS_ID_UNICODE_CS: 234 case TT_MS_ID_SYMBOL_CS: 235 convert = tt_name_entry_ascii_from_utf16; 236 break; 237 238 case TT_MS_ID_UCS_4: 239 convert = tt_name_entry_ascii_from_ucs4; 240 break; 241 242 default: 243 ; 244 } 245 } 246 else if ( found_apple >= 0 ) 247 { 248 rec = face->name_table.names + found_apple; 249 convert = tt_name_entry_ascii_from_other; 250 } 251 else if ( found_unicode >= 0 ) 252 { 253 rec = face->name_table.names + found_unicode; 254 convert = tt_name_entry_ascii_from_utf16; 255 } 256 257 if ( rec && convert ) 258 { 259 if ( rec->string == NULL ) 260 { 261 FT_Error error; 262 FT_Stream stream = face->name_table.stream; 263 264 265 if ( FT_NEW_ARRAY ( rec->string, rec->stringLength ) || 266 FT_STREAM_SEEK( rec->stringOffset ) || 267 FT_STREAM_READ( rec->string, rec->stringLength ) ) 268 { 269 FT_FREE( rec->string ); 270 rec->stringLength = 0; 271 result = NULL; 272 goto Exit; 273 } 274 } 275 276 result = convert( rec, memory ); 277 } 278 279 Exit: 280 return result; 281 } 282 283 284 static FT_Encoding sfnt_find_encoding(int platform_id,int encoding_id)285 sfnt_find_encoding( int platform_id, 286 int encoding_id ) 287 { 288 typedef struct TEncoding 289 { 290 int platform_id; 291 int encoding_id; 292 FT_Encoding encoding; 293 294 } TEncoding; 295 296 static 297 const TEncoding tt_encodings[] = 298 { 299 { TT_PLATFORM_ISO, -1, FT_ENCODING_UNICODE }, 300 301 { TT_PLATFORM_APPLE_UNICODE, -1, FT_ENCODING_UNICODE }, 302 303 { TT_PLATFORM_MACINTOSH, TT_MAC_ID_ROMAN, FT_ENCODING_APPLE_ROMAN }, 304 305 { TT_PLATFORM_MICROSOFT, TT_MS_ID_SYMBOL_CS, FT_ENCODING_MS_SYMBOL }, 306 { TT_PLATFORM_MICROSOFT, TT_MS_ID_UCS_4, FT_ENCODING_UNICODE }, 307 { TT_PLATFORM_MICROSOFT, TT_MS_ID_UNICODE_CS, FT_ENCODING_UNICODE }, 308 { TT_PLATFORM_MICROSOFT, TT_MS_ID_SJIS, FT_ENCODING_MS_SJIS }, 309 { TT_PLATFORM_MICROSOFT, TT_MS_ID_GB2312, FT_ENCODING_MS_GB2312 }, 310 { TT_PLATFORM_MICROSOFT, TT_MS_ID_BIG_5, FT_ENCODING_MS_BIG5 }, 311 { TT_PLATFORM_MICROSOFT, TT_MS_ID_WANSUNG, FT_ENCODING_MS_WANSUNG }, 312 { TT_PLATFORM_MICROSOFT, TT_MS_ID_JOHAB, FT_ENCODING_MS_JOHAB } 313 }; 314 315 const TEncoding *cur, *limit; 316 317 318 cur = tt_encodings; 319 limit = cur + sizeof ( tt_encodings ) / sizeof ( tt_encodings[0] ); 320 321 for ( ; cur < limit; cur++ ) 322 { 323 if ( cur->platform_id == platform_id ) 324 { 325 if ( cur->encoding_id == encoding_id || 326 cur->encoding_id == -1 ) 327 return cur->encoding; 328 } 329 } 330 331 return FT_ENCODING_NONE; 332 } 333 334 335 FT_LOCAL_DEF( FT_Error ) sfnt_init_face(FT_Stream stream,TT_Face face,FT_Int face_index,FT_Int num_params,FT_Parameter * params)336 sfnt_init_face( FT_Stream stream, 337 TT_Face face, 338 FT_Int face_index, 339 FT_Int num_params, 340 FT_Parameter* params ) 341 { 342 FT_Error error; 343 FT_Library library = face->root.driver->root.library; 344 SFNT_Service sfnt; 345 SFNT_HeaderRec sfnt_header; 346 347 /* for now, parameters are unused */ 348 FT_UNUSED( num_params ); 349 FT_UNUSED( params ); 350 351 352 sfnt = (SFNT_Service)face->sfnt; 353 if ( !sfnt ) 354 { 355 sfnt = (SFNT_Service)FT_Get_Module_Interface( library, "sfnt" ); 356 if ( !sfnt ) 357 { 358 error = SFNT_Err_Invalid_File_Format; 359 goto Exit; 360 } 361 362 face->sfnt = sfnt; 363 face->goto_table = sfnt->goto_table; 364 } 365 366 if ( !face->psnames ) 367 { 368 face->psnames = (PSNames_Service) 369 FT_Get_Module_Interface( library, "psnames" ); 370 } 371 372 /* check that we have a valid TrueType file */ 373 error = sfnt->load_sfnt_header( face, stream, face_index, &sfnt_header ); 374 if ( error ) 375 goto Exit; 376 377 face->format_tag = sfnt_header.format_tag; 378 face->num_tables = sfnt_header.num_tables; 379 380 /* Load font directory */ 381 error = sfnt->load_directory( face, stream, &sfnt_header ); 382 if ( error ) 383 goto Exit; 384 385 face->root.num_faces = face->ttc_header.count; 386 if ( face->root.num_faces < 1 ) 387 face->root.num_faces = 1; 388 389 Exit: 390 return error; 391 } 392 393 394 #undef LOAD_ 395 #define LOAD_( x ) ( ( error = sfnt->load_##x( face, stream ) ) \ 396 != SFNT_Err_Ok ) 397 398 399 FT_LOCAL_DEF( FT_Error ) sfnt_load_face(FT_Stream stream,TT_Face face,FT_Int face_index,FT_Int num_params,FT_Parameter * params)400 sfnt_load_face( FT_Stream stream, 401 TT_Face face, 402 FT_Int face_index, 403 FT_Int num_params, 404 FT_Parameter* params ) 405 { 406 FT_Error error; 407 FT_Bool has_outline; 408 FT_Bool is_apple_sbit; 409 410 SFNT_Service sfnt = (SFNT_Service)face->sfnt; 411 412 FT_UNUSED( face_index ); 413 FT_UNUSED( num_params ); 414 FT_UNUSED( params ); 415 416 417 /* Load tables */ 418 419 /* We now support two SFNT-based bitmapped font formats. They */ 420 /* are recognized easily as they do not include a `glyf' */ 421 /* table. */ 422 /* */ 423 /* The first format comes from Apple, and uses a table named */ 424 /* `bhed' instead of `head' to store the font header (using */ 425 /* the same format). It also doesn't include horizontal and */ 426 /* vertical metrics tables (i.e. `hhea' and `vhea' tables are */ 427 /* missing). */ 428 /* */ 429 /* The other format comes from Microsoft, and is used with */ 430 /* WinCE/PocketPC. It looks like a standard TTF, except that */ 431 /* it doesn't contain outlines. */ 432 /* */ 433 434 /* do we have outlines in there? */ 435 #ifdef FT_CONFIG_OPTION_INCREMENTAL 436 has_outline = FT_BOOL( face->root.internal->incremental_interface != 0 || 437 tt_face_lookup_table( face, TTAG_glyf ) != 0 || 438 tt_face_lookup_table( face, TTAG_CFF ) != 0 ); 439 #else 440 has_outline = FT_BOOL( tt_face_lookup_table( face, TTAG_glyf ) != 0 || 441 tt_face_lookup_table( face, TTAG_CFF ) != 0 ); 442 #endif 443 444 is_apple_sbit = 0; 445 446 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS 447 448 /* if this font doesn't contain outlines, we try to load */ 449 /* a `bhed' table */ 450 if ( !has_outline ) 451 is_apple_sbit = FT_BOOL( !LOAD_( bitmap_header ) ); 452 453 #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */ 454 455 /* load the font header (`head' table) if this isn't an Apple */ 456 /* sbit font file */ 457 if ( !is_apple_sbit && LOAD_( header ) ) 458 goto Exit; 459 460 /* the following tables are often not present in embedded TrueType */ 461 /* fonts within PDF documents, so don't check for them. */ 462 (void)LOAD_( max_profile ); 463 (void)LOAD_( charmaps ); 464 465 /* the following tables are optional in PCL fonts -- */ 466 /* don't check for errors */ 467 (void)LOAD_( names ); 468 (void)LOAD_( psnames ); 469 470 /* do not load the metrics headers and tables if this is an Apple */ 471 /* sbit font file */ 472 if ( !is_apple_sbit ) 473 { 474 /* load the `hhea' and `hmtx' tables at once */ 475 error = sfnt->load_metrics( face, stream, 0 ); 476 if ( error ) 477 goto Exit; 478 479 /* try to load the `vhea' and `vmtx' tables at once */ 480 error = sfnt->load_metrics( face, stream, 1 ); 481 if ( error ) 482 goto Exit; 483 484 if ( LOAD_( os2 ) ) 485 goto Exit; 486 } 487 488 /* the optional tables */ 489 490 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS 491 492 /* embedded bitmap support. */ 493 if ( sfnt->load_sbits && LOAD_( sbits ) ) 494 { 495 /* return an error if this font file has no outlines */ 496 if ( error == SFNT_Err_Table_Missing && has_outline ) 497 error = SFNT_Err_Ok; 498 else 499 goto Exit; 500 } 501 502 #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */ 503 504 if ( LOAD_( hdmx ) || 505 LOAD_( gasp ) || 506 LOAD_( kerning ) || 507 LOAD_( pclt ) ) 508 goto Exit; 509 510 face->root.family_name = tt_face_get_name( face, 511 TT_NAME_ID_FONT_FAMILY ); 512 face->root.style_name = tt_face_get_name( face, 513 TT_NAME_ID_FONT_SUBFAMILY ); 514 515 /* now set up root fields */ 516 { 517 FT_Face root = &face->root; 518 FT_Int32 flags = 0; 519 FT_Memory memory; 520 521 522 memory = root->memory; 523 524 /*********************************************************************/ 525 /* */ 526 /* Compute face flags. */ 527 /* */ 528 if ( has_outline == TRUE ) 529 flags = FT_FACE_FLAG_SCALABLE; /* scalable outlines */ 530 531 flags |= FT_FACE_FLAG_SFNT | /* SFNT file format */ 532 FT_FACE_FLAG_HORIZONTAL; /* horizontal data */ 533 534 #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES 535 /* might need more polish to detect the presence of a Postscript */ 536 /* name table in the font */ 537 flags |= FT_FACE_FLAG_GLYPH_NAMES; 538 #endif 539 540 /* fixed width font? */ 541 if ( face->postscript.isFixedPitch ) 542 flags |= FT_FACE_FLAG_FIXED_WIDTH; 543 544 /* vertical information? */ 545 if ( face->vertical_info ) 546 flags |= FT_FACE_FLAG_VERTICAL; 547 548 /* kerning available ? */ 549 if ( face->kern_pairs ) 550 flags |= FT_FACE_FLAG_KERNING; 551 552 root->face_flags = flags; 553 554 /*********************************************************************/ 555 /* */ 556 /* Compute style flags. */ 557 /* */ 558 flags = 0; 559 if ( has_outline == TRUE && face->os2.version != 0xFFFF ) 560 { 561 /* we have an OS/2 table; use the `fsSelection' field */ 562 if ( face->os2.fsSelection & 1 ) 563 flags |= FT_STYLE_FLAG_ITALIC; 564 565 if ( face->os2.fsSelection & 32 ) 566 flags |= FT_STYLE_FLAG_BOLD; 567 } 568 else 569 { 570 /* this is an old Mac font, use the header field */ 571 if ( face->header.Mac_Style & 1 ) 572 flags |= FT_STYLE_FLAG_BOLD; 573 574 if ( face->header.Mac_Style & 2 ) 575 flags |= FT_STYLE_FLAG_ITALIC; 576 } 577 578 root->style_flags = flags; 579 580 /*********************************************************************/ 581 /* */ 582 /* Polish the charmaps. */ 583 /* */ 584 /* Try to set the charmap encoding according to the platform & */ 585 /* encoding ID of each charmap. */ 586 /* */ 587 588 tt_face_build_cmaps( face ); /* ignore errors */ 589 590 591 /* set the encoding fields */ 592 { 593 FT_Int m; 594 595 596 for ( m = 0; m < root->num_charmaps; m++ ) 597 { 598 FT_CharMap charmap = root->charmaps[m]; 599 600 601 charmap->encoding = sfnt_find_encoding( charmap->platform_id, 602 charmap->encoding_id ); 603 604 #if 0 605 if ( root->charmap == NULL && 606 charmap->encoding == FT_ENCODING_UNICODE ) 607 { 608 /* set 'root->charmap' to the first Unicode encoding we find */ 609 root->charmap = charmap; 610 } 611 #endif 612 } 613 } 614 615 616 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS 617 618 if ( face->num_sbit_strikes ) 619 { 620 FT_ULong n; 621 622 623 root->face_flags |= FT_FACE_FLAG_FIXED_SIZES; 624 625 #if 0 626 /* XXX: I don't know criteria whether layout is horizontal */ 627 /* or vertical. */ 628 if ( has_outline.... ) 629 { 630 ... 631 root->face_flags |= FT_FACE_FLAG_VERTICAL; 632 } 633 #endif 634 root->num_fixed_sizes = face->num_sbit_strikes; 635 636 if ( FT_NEW_ARRAY( root->available_sizes, face->num_sbit_strikes ) ) 637 goto Exit; 638 639 for ( n = 0 ; n < face->num_sbit_strikes ; n++ ) 640 { 641 root->available_sizes[n].width = 642 face->sbit_strikes[n].x_ppem; 643 644 root->available_sizes[n].height = 645 face->sbit_strikes[n].y_ppem; 646 } 647 } 648 else 649 650 #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */ 651 652 { 653 root->num_fixed_sizes = 0; 654 root->available_sizes = 0; 655 } 656 657 /*********************************************************************/ 658 /* */ 659 /* Set up metrics. */ 660 /* */ 661 if ( has_outline == TRUE ) 662 { 663 /* XXX What about if outline header is missing */ 664 /* (e.g. sfnt wrapped outline)? */ 665 root->bbox.xMin = face->header.xMin; 666 root->bbox.yMin = face->header.yMin; 667 root->bbox.xMax = face->header.xMax; 668 root->bbox.yMax = face->header.yMax; 669 root->units_per_EM = face->header.Units_Per_EM; 670 671 672 /* XXX: Computing the ascender/descender/height is very different */ 673 /* from what the specification tells you. Apparently, we */ 674 /* must be careful because */ 675 /* */ 676 /* - not all fonts have an OS/2 table; in this case, we take */ 677 /* the values in the horizontal header. However, these */ 678 /* values very often are not reliable. */ 679 /* */ 680 /* - otherwise, the correct typographic values are in the */ 681 /* sTypoAscender, sTypoDescender & sTypoLineGap fields. */ 682 /* */ 683 /* However, certains fonts have these fields set to 0. */ 684 /* Rather, they have usWinAscent & usWinDescent correctly */ 685 /* set (but with different values). */ 686 /* */ 687 /* As an example, Arial Narrow is implemented through four */ 688 /* files ARIALN.TTF, ARIALNI.TTF, ARIALNB.TTF & ARIALNBI.TTF */ 689 /* */ 690 /* Strangely, all fonts have the same values in their */ 691 /* sTypoXXX fields, except ARIALNB which sets them to 0. */ 692 /* */ 693 /* On the other hand, they all have different */ 694 /* usWinAscent/Descent values -- as a conclusion, the OS/2 */ 695 /* table cannot be used to compute the text height reliably! */ 696 /* */ 697 698 /* The ascender/descender/height are computed from the OS/2 table */ 699 /* when found. Otherwise, they're taken from the horizontal */ 700 /* header. */ 701 /* */ 702 703 root->ascender = face->horizontal.Ascender; 704 root->descender = face->horizontal.Descender; 705 706 root->height = (FT_Short)( root->ascender - root->descender + 707 face->horizontal.Line_Gap ); 708 709 /* if the line_gap is 0, we add an extra 15% to the text height -- */ 710 /* this computation is based on various versions of Times New Roman */ 711 if ( face->horizontal.Line_Gap == 0 ) 712 root->height = (FT_Short)( ( root->height * 115 + 50 ) / 100 ); 713 714 #if 0 715 716 /* some fonts have the OS/2 "sTypoAscender", "sTypoDescender" & */ 717 /* "sTypoLineGap" fields set to 0, like ARIALNB.TTF */ 718 if ( face->os2.version != 0xFFFF && root->ascender ) 719 { 720 FT_Int height; 721 722 723 root->ascender = face->os2.sTypoAscender; 724 root->descender = -face->os2.sTypoDescender; 725 726 height = root->ascender + root->descender + face->os2.sTypoLineGap; 727 if ( height > root->height ) 728 root->height = height; 729 } 730 731 #endif /* 0 */ 732 733 root->max_advance_width = face->horizontal.advance_Width_Max; 734 735 root->max_advance_height = (FT_Short)( face->vertical_info 736 ? face->vertical.advance_Height_Max 737 : root->height ); 738 739 root->underline_position = face->postscript.underlinePosition; 740 root->underline_thickness = face->postscript.underlineThickness; 741 742 /* root->max_points -- already set up */ 743 /* root->max_contours -- already set up */ 744 } 745 } 746 747 Exit: 748 return error; 749 } 750 751 752 #undef LOAD_ 753 754 755 FT_LOCAL_DEF( void ) sfnt_done_face(TT_Face face)756 sfnt_done_face( TT_Face face ) 757 { 758 FT_Memory memory = face->root.memory; 759 SFNT_Service sfnt = (SFNT_Service)face->sfnt; 760 761 762 if ( sfnt ) 763 { 764 /* destroy the postscript names table if it is loaded */ 765 if ( sfnt->free_psnames ) 766 sfnt->free_psnames( face ); 767 768 /* destroy the embedded bitmaps table if it is loaded */ 769 if ( sfnt->free_sbits ) 770 sfnt->free_sbits( face ); 771 } 772 773 /* freeing the kerning table */ 774 FT_FREE( face->kern_pairs ); 775 face->num_kern_pairs = 0; 776 777 /* freeing the collection table */ 778 FT_FREE( face->ttc_header.offsets ); 779 face->ttc_header.count = 0; 780 781 /* freeing table directory */ 782 FT_FREE( face->dir_tables ); 783 face->num_tables = 0; 784 785 { 786 FT_Stream stream = FT_FACE_STREAM( face ); 787 788 789 /* simply release the 'cmap' table frame */ 790 FT_FRAME_RELEASE( face->cmap_table ); 791 face->cmap_size = 0; 792 } 793 794 /* freeing the horizontal metrics */ 795 FT_FREE( face->horizontal.long_metrics ); 796 FT_FREE( face->horizontal.short_metrics ); 797 798 /* freeing the vertical ones, if any */ 799 if ( face->vertical_info ) 800 { 801 FT_FREE( face->vertical.long_metrics ); 802 FT_FREE( face->vertical.short_metrics ); 803 face->vertical_info = 0; 804 } 805 806 /* freeing the gasp table */ 807 FT_FREE( face->gasp.gaspRanges ); 808 face->gasp.numRanges = 0; 809 810 /* freeing the name table */ 811 sfnt->free_names( face ); 812 813 /* freeing the hdmx table */ 814 sfnt->free_hdmx( face ); 815 816 /* freeing family and style name */ 817 FT_FREE( face->root.family_name ); 818 FT_FREE( face->root.style_name ); 819 820 /* freeing sbit size table */ 821 face->root.num_fixed_sizes = 0; 822 if ( face->root.available_sizes ) 823 FT_FREE( face->root.available_sizes ); 824 825 face->sfnt = 0; 826 } 827 828 829 /* END */ 830