ttgload.c revision e793092d0a9f4d4d383315bcefd485dcbe4804b3
1/***************************************************************************/ 2/* */ 3/* ttgload.c */ 4/* */ 5/* TrueType Glyph Loader (body). */ 6/* */ 7/* Copyright 1996-2001, 2002, 2003, 2004, 2005 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 FT_INTERNAL_DEBUG_H 21#include FT_INTERNAL_CALC_H 22#include FT_INTERNAL_STREAM_H 23#include FT_INTERNAL_SFNT_H 24#include FT_TRUETYPE_TAGS_H 25#include FT_OUTLINE_H 26 27#include "ttgload.h" 28 29#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT 30#include "ttgxvar.h" 31#endif 32 33#include "tterrors.h" 34 35 36 /*************************************************************************/ 37 /* */ 38 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ 39 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ 40 /* messages during execution. */ 41 /* */ 42#undef FT_COMPONENT 43#define FT_COMPONENT trace_ttgload 44 45 46 /*************************************************************************/ 47 /* */ 48 /* Composite font flags. */ 49 /* */ 50#define ARGS_ARE_WORDS 0x0001 51#define ARGS_ARE_XY_VALUES 0x0002 52#define ROUND_XY_TO_GRID 0x0004 53#define WE_HAVE_A_SCALE 0x0008 54/* reserved 0x0010 */ 55#define MORE_COMPONENTS 0x0020 56#define WE_HAVE_AN_XY_SCALE 0x0040 57#define WE_HAVE_A_2X2 0x0080 58#define WE_HAVE_INSTR 0x0100 59#define USE_MY_METRICS 0x0200 60#define OVERLAP_COMPOUND 0x0400 61#define SCALED_COMPONENT_OFFSET 0x0800 62#define UNSCALED_COMPONENT_OFFSET 0x1000 63 64 65/* Maximum recursion depth we allow for composite glyphs. 66 * The TrueType spec doesn't say anything about recursion, 67 * so it isn't clear that recursion is allowed at all. But 68 * we'll be generous. 69 */ 70#define TT_MAX_COMPOSITE_RECURSE 5 71 72 73 74 /*************************************************************************/ 75 /* */ 76 /* <Function> */ 77 /* TT_Get_Metrics */ 78 /* */ 79 /* <Description> */ 80 /* Returns the horizontal or vertical metrics in font units for a */ 81 /* given glyph. The metrics are the left side bearing (resp. top */ 82 /* side bearing) and advance width (resp. advance height). */ 83 /* */ 84 /* <Input> */ 85 /* header :: A pointer to either the horizontal or vertical metrics */ 86 /* structure. */ 87 /* */ 88 /* idx :: The glyph index. */ 89 /* */ 90 /* <Output> */ 91 /* bearing :: The bearing, either left side or top side. */ 92 /* */ 93 /* advance :: The advance width resp. advance height. */ 94 /* */ 95 /* <Note> */ 96 /* This function will much probably move to another component in the */ 97 /* near future, but I haven't decided which yet. */ 98 /* */ 99#ifdef FT_OPTIMIZE_MEMORY 100 101 static void 102 tt_face_get_metrics( TT_Face face, 103 FT_Bool vertical, 104 FT_UInt idx, 105 FT_Short *abearing, 106 FT_UShort *aadvance ) 107 { 108 TT_HoriHeader* header; 109 FT_Byte* p; 110 FT_Byte* limit; 111 FT_UShort k; 112 113 114 if ( vertical ) 115 { 116 header = (TT_HoriHeader*)&face->vertical; 117 p = face->vert_metrics; 118 limit = p + face->vert_metrics_size; 119 } 120 else 121 { 122 header = &face->horizontal; 123 p = face->horz_metrics; 124 limit = p + face->horz_metrics_size; 125 } 126 127 k = header->number_Of_HMetrics; 128 129 if ( k > 0 ) 130 { 131 if ( idx < (FT_UInt)k ) 132 { 133 p += 4 * idx; 134 if ( p + 4 >= limit ) 135 goto NoData; 136 137 *aadvance = FT_NEXT_USHORT( p ); 138 *abearing = FT_NEXT_SHORT( p ); 139 } 140 else 141 { 142 p += 4 * ( k - 1 ); 143 if ( p + 4 > limit ) 144 goto NoData; 145 146 *aadvance = FT_NEXT_USHORT( p ); 147 p += 2 + 2 * ( idx - k ); 148 if ( p + 2 > limit ) 149 *abearing = 0; 150 else 151 *abearing = FT_PEEK_SHORT( p ); 152 } 153 } 154 else 155 { 156 NoData: 157 *abearing = 0; 158 *aadvance = 0; 159 } 160 } 161 162#else /* !FT_OPTIMIZE_MEMORY */ 163 164 static void 165 tt_face_get_metrics( TT_Face face, 166 FT_Bool vertical, 167 FT_UInt idx, 168 FT_Short *abearing, 169 FT_UShort *aadvance ) 170 { 171 TT_HoriHeader* header = vertical ? (TT_HoriHeader*)&face->vertical 172 : &face->horizontal; 173 TT_LongMetrics longs_m; 174 FT_UShort k = header->number_Of_HMetrics; 175 176 177 if ( k == 0 ) 178 { 179 *abearing = *aadvance = 0; 180 return; 181 } 182 183 if ( idx < (FT_UInt)k ) 184 { 185 longs_m = (TT_LongMetrics)header->long_metrics + idx; 186 *abearing = longs_m->bearing; 187 *aadvance = longs_m->advance; 188 } 189 else 190 { 191 *abearing = ((TT_ShortMetrics*)header->short_metrics)[idx - k]; 192 *aadvance = ((TT_LongMetrics)header->long_metrics)[k - 1].advance; 193 } 194 } 195 196#endif /* !FT_OPTIMIZE_MEMORY */ 197 198 199 /*************************************************************************/ 200 /* */ 201 /* Returns the horizontal metrics in font units for a given glyph. If */ 202 /* `check' is true, take care of monospaced fonts by returning the */ 203 /* advance width maximum. */ 204 /* */ 205 static void 206 Get_HMetrics( TT_Face face, 207 FT_UInt idx, 208 FT_Bool check, 209 FT_Short* lsb, 210 FT_UShort* aw ) 211 { 212 tt_face_get_metrics( face, 0, idx, lsb, aw ); 213 214 if ( check && face->postscript.isFixedPitch ) 215 *aw = face->horizontal.advance_Width_Max; 216 } 217 218 219 /*************************************************************************/ 220 /* */ 221 /* Returns the advance width table for a given pixel size if it is found */ 222 /* in the font's `hdmx' table (if any). */ 223 /* */ 224 static FT_Byte* 225 Get_Advance_WidthPtr( TT_Face face, 226 FT_Int ppem, 227 FT_UInt gindex ) 228 { 229#ifdef FT_OPTIMIZE_MEMORY 230 231 FT_UInt nn; 232 FT_Byte* result = NULL; 233 FT_ULong record_size = face->hdmx_record_size; 234 FT_Byte* record = face->hdmx_table + 8; 235 236 237 for ( nn = 0; nn < face->hdmx_record_count; nn++ ) 238 if ( face->hdmx_record_sizes[nn] == ppem ) 239 { 240 gindex += 2; 241 if ( gindex < record_size ) 242 result = record + gindex; 243 break; 244 } 245 246 return result; 247 248#else 249 250 FT_UShort n; 251 252 253 for ( n = 0; n < face->hdmx.num_records; n++ ) 254 if ( face->hdmx.records[n].ppem == ppem ) 255 return &face->hdmx.records[n].widths[gindex]; 256 257 return NULL; 258 259#endif 260 } 261 262 263 /*************************************************************************/ 264 /* */ 265 /* Returns the vertical metrics in font units for a given glyph. */ 266 /* Greg Hitchcock from Microsoft told us that if there were no `vmtx' */ 267 /* table, typoAscender/Descender from the `OS/2' table would be used */ 268 /* instead, and if there were no `OS/2' table, use ascender/descender */ 269 /* from the `hhea' table. But that is not what Microsoft's rasterizer */ 270 /* apparently does: It uses the ppem value as the advance height, and */ 271 /* sets the top side bearing to be zero. */ 272 /* */ 273 /* The monospace `check' is probably not meaningful here, but we leave */ 274 /* it in for a consistent interface. */ 275 /* */ 276 static void 277 Get_VMetrics( TT_Face face, 278 FT_UInt idx, 279 FT_Bool check, 280 FT_Short* tsb, 281 FT_UShort* ah ) 282 { 283 FT_UNUSED( check ); 284 285 if ( face->vertical_info ) 286 tt_face_get_metrics( face, 1, idx, tsb, ah ); 287 288#if 1 /* Emperically determined, at variance with what MS said */ 289 290 else 291 { 292 *tsb = 0; 293 *ah = face->root.units_per_EM; 294 } 295 296#else /* This is what MS said to do. It isn't what they do, however. */ 297 298 else if ( face->os2.version != 0xFFFFU ) 299 { 300 *tsb = face->os2.sTypoAscender; 301 *ah = face->os2.sTypoAscender - face->os2.sTypoDescender; 302 } 303 else 304 { 305 *tsb = face->horizontal.Ascender; 306 *ah = face->horizontal.Ascender - face->horizontal.Descender; 307 } 308 309#endif 310 311 } 312 313 314#define cur_to_org( n, zone ) \ 315 FT_ARRAY_COPY( (zone)->org, (zone)->cur, (n) ) 316 317#define org_to_cur( n, zone ) \ 318 FT_ARRAY_COPY( (zone)->cur, (zone)->org, (n) ) 319 320 321 /*************************************************************************/ 322 /* */ 323 /* Translates an array of coordinates. */ 324 /* */ 325 static void 326 translate_array( FT_UInt n, 327 FT_Vector* coords, 328 FT_Pos delta_x, 329 FT_Pos delta_y ) 330 { 331 FT_UInt k; 332 333 334 if ( delta_x ) 335 for ( k = 0; k < n; k++ ) 336 coords[k].x += delta_x; 337 338 if ( delta_y ) 339 for ( k = 0; k < n; k++ ) 340 coords[k].y += delta_y; 341 } 342 343 344 static void 345 tt_prepare_zone( TT_GlyphZone zone, 346 FT_GlyphLoad load, 347 FT_UInt start_point, 348 FT_UInt start_contour ) 349 { 350 zone->n_points = (FT_UShort)( load->outline.n_points - start_point ); 351 zone->n_contours = (FT_Short) ( load->outline.n_contours - start_contour ); 352 zone->org = load->extra_points + start_point; 353 zone->cur = load->outline.points + start_point; 354 zone->tags = (FT_Byte*)load->outline.tags + start_point; 355 zone->contours = (FT_UShort*)load->outline.contours + start_contour; 356 } 357 358 359#undef IS_HINTED 360#define IS_HINTED( flags ) ( ( flags & FT_LOAD_NO_HINTING ) == 0 ) 361 362 363 /*************************************************************************/ 364 /* */ 365 /* The following functions are used by default with TrueType fonts. */ 366 /* However, they can be replaced by alternatives if we need to support */ 367 /* TrueType-compressed formats (like MicroType) in the future. */ 368 /* */ 369 /*************************************************************************/ 370 371 FT_CALLBACK_DEF( FT_Error ) 372 TT_Access_Glyph_Frame( TT_Loader loader, 373 FT_UInt glyph_index, 374 FT_ULong offset, 375 FT_UInt byte_count ) 376 { 377 FT_Error error; 378 FT_Stream stream = loader->stream; 379 380 /* for non-debug mode */ 381 FT_UNUSED( glyph_index ); 382 383 384 FT_TRACE5(( "Glyph %ld\n", glyph_index )); 385 386 /* the following line sets the `error' variable through macros! */ 387 if ( FT_STREAM_SEEK( offset ) || FT_FRAME_ENTER( byte_count ) ) 388 return error; 389 390 return TT_Err_Ok; 391 } 392 393 394 FT_CALLBACK_DEF( void ) 395 TT_Forget_Glyph_Frame( TT_Loader loader ) 396 { 397 FT_Stream stream = loader->stream; 398 399 400 FT_FRAME_EXIT(); 401 } 402 403 404 FT_CALLBACK_DEF( FT_Error ) 405 TT_Load_Glyph_Header( TT_Loader loader ) 406 { 407 FT_Stream stream = loader->stream; 408 FT_Int byte_len = loader->byte_len - 10; 409 410 411 if ( byte_len < 0 ) 412 return TT_Err_Invalid_Outline; 413 414 loader->n_contours = FT_GET_SHORT(); 415 416 loader->bbox.xMin = FT_GET_SHORT(); 417 loader->bbox.yMin = FT_GET_SHORT(); 418 loader->bbox.xMax = FT_GET_SHORT(); 419 loader->bbox.yMax = FT_GET_SHORT(); 420 421 FT_TRACE5(( " # of contours: %d\n", loader->n_contours )); 422 FT_TRACE5(( " xMin: %4d xMax: %4d\n", loader->bbox.xMin, 423 loader->bbox.xMax )); 424 FT_TRACE5(( " yMin: %4d yMax: %4d\n", loader->bbox.yMin, 425 loader->bbox.yMax )); 426 loader->byte_len = byte_len; 427 428 return TT_Err_Ok; 429 } 430 431 432 FT_CALLBACK_DEF( FT_Error ) 433 TT_Load_Simple_Glyph( TT_Loader load ) 434 { 435 FT_Error error; 436 FT_Stream stream = load->stream; 437 FT_GlyphLoader gloader = load->gloader; 438 FT_Int n_contours = load->n_contours; 439 FT_Outline* outline; 440 TT_Face face = (TT_Face)load->face; 441 TT_GlyphSlot slot = (TT_GlyphSlot)load->glyph; 442 FT_UShort n_ins; 443 FT_Int n, n_points; 444 FT_Int byte_len = load->byte_len; 445 446 FT_Byte *flag, *flag_limit; 447 FT_Byte c, count; 448 FT_Vector *vec, *vec_limit; 449 FT_Pos x; 450 FT_Short *cont, *cont_limit; 451 452 453 /* reading the contours' endpoints & number of points */ 454 cont = gloader->current.outline.contours; 455 cont_limit = cont + n_contours; 456 457 /* check space for contours array + instructions count */ 458 byte_len -= 2 * ( n_contours + 1 ); 459 if ( byte_len < 0 ) 460 goto Invalid_Outline; 461 462 for ( ; cont < cont_limit; cont++ ) 463 cont[0] = FT_GET_USHORT(); 464 465 n_points = 0; 466 if ( n_contours > 0 ) 467 n_points = cont[-1] + 1; 468 469 error = FT_GlyphLoader_CheckPoints( gloader, n_points + 4, 0 ); 470 if ( error ) 471 goto Fail; 472 473 /* we'd better check the contours table right now */ 474 outline = &gloader->current.outline; 475 476 for ( cont = outline->contours + 1; cont < cont_limit; cont++ ) 477 if ( cont[-1] >= cont[0] ) 478 goto Invalid_Outline; 479 480 /* reading the bytecode instructions */ 481 slot->control_len = 0; 482 slot->control_data = 0; 483 484 n_ins = FT_GET_USHORT(); 485 486 FT_TRACE5(( " Instructions size: %u\n", n_ins )); 487 488 if ( n_ins > face->max_profile.maxSizeOfInstructions ) 489 { 490 FT_TRACE0(( "TT_Load_Simple_Glyph: Too many instructions!\n" )); 491 error = TT_Err_Too_Many_Hints; 492 goto Fail; 493 } 494 495 byte_len -= (FT_Int)n_ins; 496 if ( byte_len < 0 ) 497 { 498 FT_TRACE0(( "TT_Load_Simple_Glyph: Instruction count mismatch!\n" )); 499 error = TT_Err_Too_Many_Hints; 500 goto Fail; 501 } 502 503#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER 504 505 if ( ( load->load_flags & 506 ( FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING ) ) == 0 && 507 load->instructions ) 508 { 509 slot->control_len = n_ins; 510 slot->control_data = load->instructions; 511 512 FT_MEM_COPY( load->instructions, stream->cursor, (FT_Long)n_ins ); 513 } 514 515#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */ 516 517 stream->cursor += (FT_Int)n_ins; 518 519 /* reading the point tags */ 520 flag = (FT_Byte*)outline->tags; 521 flag_limit = flag + n_points; 522 523 FT_ASSERT( flag != NULL ); 524 525 while ( flag < flag_limit ) 526 { 527 if ( --byte_len < 0 ) 528 goto Invalid_Outline; 529 530 *flag++ = c = FT_GET_BYTE(); 531 if ( c & 8 ) 532 { 533 if ( --byte_len < 0 ) 534 goto Invalid_Outline; 535 536 count = FT_GET_BYTE(); 537 if ( flag + (FT_Int)count > flag_limit ) 538 goto Invalid_Outline; 539 540 for ( ; count > 0; count-- ) 541 *flag++ = c; 542 } 543 } 544 545 /* check that there is enough room to load the coordinates */ 546 for ( flag = (FT_Byte*)outline->tags; flag < flag_limit; flag++ ) 547 { 548 if ( *flag & 2 ) 549 byte_len -= 1; 550 else if ( ( *flag & 16 ) == 0 ) 551 byte_len -= 2; 552 553 if ( *flag & 4 ) 554 byte_len -= 1; 555 else if ( ( *flag & 32 ) == 0 ) 556 byte_len -= 2; 557 } 558 559 if ( byte_len < 0 ) 560 goto Invalid_Outline; 561 562 /* reading the X coordinates */ 563 564 vec = outline->points; 565 vec_limit = vec + n_points; 566 flag = (FT_Byte*)outline->tags; 567 x = 0; 568 569 for ( ; vec < vec_limit; vec++, flag++ ) 570 { 571 FT_Pos y = 0; 572 573 574 if ( *flag & 2 ) 575 { 576 y = (FT_Pos)FT_GET_BYTE(); 577 if ( ( *flag & 16 ) == 0 ) 578 y = -y; 579 } 580 else if ( ( *flag & 16 ) == 0 ) 581 y = (FT_Pos)FT_GET_SHORT(); 582 583 x += y; 584 vec->x = x; 585 } 586 587 /* reading the Y coordinates */ 588 589 vec = gloader->current.outline.points; 590 vec_limit = vec + n_points; 591 flag = (FT_Byte*)outline->tags; 592 x = 0; 593 594 for ( ; vec < vec_limit; vec++, flag++ ) 595 { 596 FT_Pos y = 0; 597 598 599 if ( *flag & 4 ) 600 { 601 y = (FT_Pos)FT_GET_BYTE(); 602 if ( ( *flag & 32 ) == 0 ) 603 y = -y; 604 } 605 else if ( ( *flag & 32 ) == 0 ) 606 y = (FT_Pos)FT_GET_SHORT(); 607 608 x += y; 609 vec->y = x; 610 } 611 612 /* clear the touch tags */ 613 for ( n = 0; n < n_points; n++ ) 614 outline->tags[n] &= FT_CURVE_TAG_ON; 615 616 outline->n_points = (FT_UShort)n_points; 617 outline->n_contours = (FT_Short) n_contours; 618 619 load->byte_len = byte_len; 620 621 Fail: 622 return error; 623 624 Invalid_Outline: 625 error = TT_Err_Invalid_Outline; 626 goto Fail; 627 } 628 629 630 FT_CALLBACK_DEF( FT_Error ) 631 TT_Load_Composite_Glyph( TT_Loader loader ) 632 { 633 FT_Error error; 634 FT_Stream stream = loader->stream; 635 FT_GlyphLoader gloader = loader->gloader; 636 FT_SubGlyph subglyph; 637 FT_UInt num_subglyphs; 638 FT_Int byte_len = loader->byte_len; 639 640 641 num_subglyphs = 0; 642 643 do 644 { 645 FT_Fixed xx, xy, yy, yx; 646 647 648 /* check that we can load a new subglyph */ 649 error = FT_GlyphLoader_CheckSubGlyphs( gloader, num_subglyphs + 1 ); 650 if ( error ) 651 goto Fail; 652 653 /* check space */ 654 byte_len -= 4; 655 if ( byte_len < 0 ) 656 goto Invalid_Composite; 657 658 subglyph = gloader->current.subglyphs + num_subglyphs; 659 660 subglyph->arg1 = subglyph->arg2 = 0; 661 662 subglyph->flags = FT_GET_USHORT(); 663 subglyph->index = FT_GET_USHORT(); 664 665 /* check space */ 666 byte_len -= 2; 667 if ( subglyph->flags & ARGS_ARE_WORDS ) 668 byte_len -= 2; 669 if ( subglyph->flags & WE_HAVE_A_SCALE ) 670 byte_len -= 2; 671 else if ( subglyph->flags & WE_HAVE_AN_XY_SCALE ) 672 byte_len -= 4; 673 else if ( subglyph->flags & WE_HAVE_A_2X2 ) 674 byte_len -= 8; 675 676 if ( byte_len < 0 ) 677 goto Invalid_Composite; 678 679 /* read arguments */ 680 if ( subglyph->flags & ARGS_ARE_WORDS ) 681 { 682 subglyph->arg1 = FT_GET_SHORT(); 683 subglyph->arg2 = FT_GET_SHORT(); 684 } 685 else 686 { 687 subglyph->arg1 = FT_GET_CHAR(); 688 subglyph->arg2 = FT_GET_CHAR(); 689 } 690 691 /* read transform */ 692 xx = yy = 0x10000L; 693 xy = yx = 0; 694 695 if ( subglyph->flags & WE_HAVE_A_SCALE ) 696 { 697 xx = (FT_Fixed)FT_GET_SHORT() << 2; 698 yy = xx; 699 } 700 else if ( subglyph->flags & WE_HAVE_AN_XY_SCALE ) 701 { 702 xx = (FT_Fixed)FT_GET_SHORT() << 2; 703 yy = (FT_Fixed)FT_GET_SHORT() << 2; 704 } 705 else if ( subglyph->flags & WE_HAVE_A_2X2 ) 706 { 707 xx = (FT_Fixed)FT_GET_SHORT() << 2; 708 yx = (FT_Fixed)FT_GET_SHORT() << 2; 709 xy = (FT_Fixed)FT_GET_SHORT() << 2; 710 yy = (FT_Fixed)FT_GET_SHORT() << 2; 711 } 712 713 subglyph->transform.xx = xx; 714 subglyph->transform.xy = xy; 715 subglyph->transform.yx = yx; 716 subglyph->transform.yy = yy; 717 718 num_subglyphs++; 719 720 } while ( subglyph->flags & MORE_COMPONENTS ); 721 722 gloader->current.num_subglyphs = num_subglyphs; 723 724#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER 725 { 726 /* we must undo the FT_FRAME_ENTER in order to point to the */ 727 /* composite instructions, if we find some. */ 728 /* we will process them later... */ 729 /* */ 730 loader->ins_pos = (FT_ULong)( FT_STREAM_POS() + 731 stream->cursor - stream->limit ); 732 } 733#endif 734 735 loader->byte_len = byte_len; 736 737 Fail: 738 return error; 739 740 Invalid_Composite: 741 error = TT_Err_Invalid_Composite; 742 goto Fail; 743 } 744 745 746 FT_LOCAL_DEF( void ) 747 TT_Init_Glyph_Loading( TT_Face face ) 748 { 749 face->access_glyph_frame = TT_Access_Glyph_Frame; 750 face->read_glyph_header = TT_Load_Glyph_Header; 751 face->read_simple_glyph = TT_Load_Simple_Glyph; 752 face->read_composite_glyph = TT_Load_Composite_Glyph; 753 face->forget_glyph_frame = TT_Forget_Glyph_Frame; 754 } 755 756 757 /*************************************************************************/ 758 /* */ 759 /* <Function> */ 760 /* TT_Process_Simple_Glyph */ 761 /* */ 762 /* <Description> */ 763 /* Once a simple glyph has been loaded, it needs to be processed. */ 764 /* Usually, this means scaling and hinting through bytecode */ 765 /* interpretation. */ 766 /* */ 767 static FT_Error 768 TT_Process_Simple_Glyph( TT_Loader load, 769 FT_Bool debug ) 770 { 771 FT_GlyphLoader gloader = load->gloader; 772 FT_Outline* outline = &gloader->current.outline; 773 FT_UInt n_points = outline->n_points; 774#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER 775 FT_UInt n_ins; 776#endif 777 TT_GlyphZone zone = &load->zone; 778 FT_Error error = TT_Err_Ok; 779 780 FT_UNUSED( debug ); /* used by truetype interpreter only */ 781 782 783#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER 784 n_ins = load->glyph->control_len; 785#endif 786 787 /* add shadow points */ 788 789 /* Add two horizontal shadow points at n and n+1. */ 790 /* We need the left side bearing and advance width. */ 791 /* Add two vertical shadow points at n+2 and n+3. */ 792 /* We need the top side bearing and advance height. */ 793 794 { 795 FT_Vector* pp1; 796 FT_Vector* pp2; 797 FT_Vector* pp3; 798 FT_Vector* pp4; 799 800 801 /* pp1 = xMin - lsb */ 802 pp1 = outline->points + n_points; 803 pp1->x = load->bbox.xMin - load->left_bearing; 804 pp1->y = 0; 805 806 /* pp2 = pp1 + aw */ 807 pp2 = pp1 + 1; 808 pp2->x = pp1->x + load->advance; 809 pp2->y = 0; 810 811 /* pp3 = top side bearing */ 812 pp3 = pp1 + 2; 813 pp3->x = 0; 814 pp3->y = load->top_bearing + load->bbox.yMax; 815 816 /* pp4 = pp3 - ah */ 817 pp4 = pp1 + 3; 818 pp4->x = 0; 819 pp4->y = pp3->y - load->vadvance; 820 821 outline->tags[n_points ] = 0; 822 outline->tags[n_points + 1] = 0; 823 outline->tags[n_points + 2] = 0; 824 outline->tags[n_points + 3] = 0; 825 } 826 827 /* Note that we return four more points that are not */ 828 /* part of the glyph outline. */ 829 830 n_points += 4; 831 832#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT 833 834 if ( ((TT_Face)load->face)->doblend ) 835 { 836 /* Deltas apply to the unscaled data. */ 837 FT_Vector* deltas; 838 FT_Memory memory = load->face->memory; 839 FT_StreamRec saved_stream = *(load->stream); 840 FT_UInt i; 841 842 843 /* TT_Vary_Get_Glyph_Deltas uses a frame, thus we have to save */ 844 /* (and restore) the current one */ 845 load->stream->cursor = 0; 846 load->stream->limit = 0; 847 848 error = TT_Vary_Get_Glyph_Deltas( (TT_Face)(load->face), 849 load->glyph_index, 850 &deltas, 851 n_points ); 852 853 *(load->stream) = saved_stream; 854 855 if ( error ) 856 goto Exit; 857 858 for ( i = 0; i < n_points; ++i ) 859 { 860 outline->points[i].x += deltas[i].x; 861 outline->points[i].y += deltas[i].y; 862 } 863 864 FT_FREE( deltas ); 865 } 866 867#endif /* TT_CONFIG_OPTION_GX_VAR_SUPPORT */ 868 869 /* set up zone for hinting */ 870 tt_prepare_zone( zone, &gloader->current, 0, 0 ); 871 872 /* eventually scale the glyph */ 873 if ( !( load->load_flags & FT_LOAD_NO_SCALE ) ) 874 { 875 FT_Vector* vec = zone->cur; 876 FT_Vector* limit = vec + n_points; 877 FT_Fixed x_scale = ((TT_Size)load->size)->metrics.x_scale; 878 FT_Fixed y_scale = ((TT_Size)load->size)->metrics.y_scale; 879 880 /* first scale the glyph points */ 881 for ( ; vec < limit; vec++ ) 882 { 883 vec->x = FT_MulFix( vec->x, x_scale ); 884 vec->y = FT_MulFix( vec->y, y_scale ); 885 } 886 } 887 888 cur_to_org( n_points, zone ); 889 890 /* eventually hint the glyph */ 891 if ( IS_HINTED( load->load_flags ) ) 892 { 893 FT_Pos x = zone->org[n_points-4].x; 894 895 896 x = FT_PIX_ROUND( x ) - x; 897 translate_array( n_points, zone->org, x, 0 ); 898 899 org_to_cur( n_points, zone ); 900 901 zone->cur[n_points - 3].x = FT_PIX_ROUND( zone->cur[n_points - 3].x ); 902 zone->cur[n_points - 1].y = FT_PIX_ROUND( zone->cur[n_points - 1].y ); 903 904#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER 905 906 /* now consider hinting */ 907 if ( n_ins > 0 ) 908 { 909 error = TT_Set_CodeRange( load->exec, tt_coderange_glyph, 910 load->exec->glyphIns, n_ins ); 911 if ( error ) 912 goto Exit; 913 914 load->exec->is_composite = FALSE; 915 load->exec->pts = *zone; 916 load->exec->pts.n_points += 4; 917 918 error = TT_Run_Context( load->exec, debug ); 919 if ( error && load->exec->pedantic_hinting ) 920 goto Exit; 921 922 error = TT_Err_Ok; /* ignore bytecode errors in non-pedantic mode */ 923 } 924 925#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */ 926 927 } 928 929 /* save glyph phantom points */ 930 if ( !load->preserve_pps ) 931 { 932 load->pp1 = zone->cur[n_points - 4]; 933 load->pp2 = zone->cur[n_points - 3]; 934 load->pp3 = zone->cur[n_points - 2]; 935 load->pp4 = zone->cur[n_points - 1]; 936 } 937 938#if defined( TT_CONFIG_OPTION_BYTECODE_INTERPRETER ) || \ 939 defined( TT_CONFIG_OPTION_GX_VAR_SUPPORT ) 940 Exit: 941#endif 942 943 return error; 944 } 945 946 947 /*************************************************************************/ 948 /* */ 949 /* <Function> */ 950 /* load_truetype_glyph */ 951 /* */ 952 /* <Description> */ 953 /* Loads a given truetype glyph. Handles composites and uses a */ 954 /* TT_Loader object. */ 955 /* */ 956 static FT_Error 957 load_truetype_glyph( TT_Loader loader, 958 FT_UInt glyph_index, 959 FT_UInt recurse_count ) 960 { 961 962#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER 963 FT_Stream stream = loader->stream; 964#endif 965 966 FT_Error error; 967 TT_Face face = (TT_Face)loader->face; 968 FT_ULong offset; 969 FT_Int contours_count; 970 FT_UInt num_points, count; 971 FT_Fixed x_scale, y_scale; 972 FT_GlyphLoader gloader = loader->gloader; 973 FT_Bool opened_frame = 0; 974 975#ifdef FT_CONFIG_OPTION_INCREMENTAL 976 FT_StreamRec inc_stream; 977 FT_Data glyph_data; 978 FT_Bool glyph_data_loaded = 0; 979#endif 980 981#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT 982 FT_Vector *deltas; 983#endif 984 985 986 if ( recurse_count >= TT_MAX_COMPOSITE_RECURSE ) 987 { 988 error = TT_Err_Invalid_Composite; 989 goto Exit; 990 } 991 992 /* check glyph index */ 993 if ( glyph_index >= (FT_UInt)face->root.num_glyphs ) 994 { 995 error = TT_Err_Invalid_Glyph_Index; 996 goto Exit; 997 } 998 999 loader->glyph_index = glyph_index; 1000 num_points = 0; 1001 1002 x_scale = 0x10000L; 1003 y_scale = 0x10000L; 1004 if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 ) 1005 { 1006 x_scale = ((TT_Size)loader->size)->metrics.x_scale; 1007 y_scale = ((TT_Size)loader->size)->metrics.y_scale; 1008 } 1009 1010 /* get metrics, horizontal and vertical */ 1011 { 1012 FT_Short left_bearing = 0, top_bearing = 0; 1013 FT_UShort advance_width = 0, advance_height = 0; 1014 1015 1016 Get_HMetrics( face, glyph_index, 1017 (FT_Bool)!( loader->load_flags & 1018 FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH ), 1019 &left_bearing, 1020 &advance_width ); 1021 Get_VMetrics( face, glyph_index, 1022 (FT_Bool)!( loader->load_flags & 1023 FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH ), 1024 &top_bearing, 1025 &advance_height ); 1026 1027#ifdef FT_CONFIG_OPTION_INCREMENTAL 1028 1029 /* If this is an incrementally loaded font see if there are */ 1030 /* overriding metrics for this glyph. */ 1031 if ( face->root.internal->incremental_interface && 1032 face->root.internal->incremental_interface->funcs->get_glyph_metrics ) 1033 { 1034 FT_Incremental_MetricsRec metrics; 1035 1036 1037 metrics.bearing_x = left_bearing; 1038 metrics.bearing_y = 0; 1039 metrics.advance = advance_width; 1040 error = face->root.internal->incremental_interface->funcs->get_glyph_metrics( 1041 face->root.internal->incremental_interface->object, 1042 glyph_index, FALSE, &metrics ); 1043 if ( error ) 1044 goto Exit; 1045 left_bearing = (FT_Short)metrics.bearing_x; 1046 advance_width = (FT_UShort)metrics.advance; 1047 } 1048 1049# if 0 1050 /* GWW: Do I do the same for vertical metrics ??? */ 1051 if ( face->root.internal->incremental_interface && 1052 face->root.internal->incremental_interface->funcs->get_glyph_metrics ) 1053 { 1054 FT_Incremental_MetricsRec metrics; 1055 1056 1057 metrics.bearing_x = 0; 1058 metrics.bearing_y = top_bearing; 1059 metrics.advance = advance_height; 1060 error = face->root.internal->incremental_interface->funcs->get_glyph_metrics( 1061 face->root.internal->incremental_interface->object, 1062 glyph_index, TRUE, &metrics ); 1063 if ( error ) 1064 goto Exit; 1065 top_bearing = (FT_Short)metrics.bearing_y; 1066 advance_height = (FT_UShort)metrics.advance; 1067 } 1068# endif 1069 1070#endif /* FT_CONFIG_OPTION_INCREMENTAL */ 1071 1072 loader->left_bearing = left_bearing; 1073 loader->advance = advance_width; 1074 loader->top_bearing = top_bearing; 1075 loader->vadvance = advance_height; 1076 1077 if ( !loader->linear_def ) 1078 { 1079 loader->linear_def = 1; 1080 loader->linear = advance_width; 1081 } 1082 } 1083 1084#ifdef FT_CONFIG_OPTION_INCREMENTAL 1085 1086 /* Set `offset' to the start of the glyph program relative to the */ 1087 /* start of the 'glyf' table, and `count' to the length of the */ 1088 /* glyph program in bytes. */ 1089 /* */ 1090 /* If we are loading glyph data via the incremental interface, set */ 1091 /* the loader stream to a memory stream reading the data returned */ 1092 /* by the interface. */ 1093 1094 if ( face->root.internal->incremental_interface ) 1095 { 1096 error = face->root.internal->incremental_interface->funcs->get_glyph_data( 1097 face->root.internal->incremental_interface->object, 1098 glyph_index, &glyph_data ); 1099 if ( error ) 1100 goto Exit; 1101 1102 glyph_data_loaded = 1; 1103 offset = 0; 1104 count = glyph_data.length; 1105 1106 FT_MEM_ZERO( &inc_stream, sizeof ( inc_stream ) ); 1107 FT_Stream_OpenMemory( &inc_stream, 1108 glyph_data.pointer, glyph_data.length ); 1109 1110 loader->stream = &inc_stream; 1111 } 1112 else 1113 1114#endif /* FT_CONFIG_OPTION_INCREMENTAL */ 1115 1116 offset = tt_face_get_location( face, glyph_index, &count ); 1117 1118 if ( count == 0 ) 1119 { 1120 /* as described by Frederic Loyer, these are spaces, and */ 1121 /* not the unknown glyph. */ 1122 loader->bbox.xMin = 0; 1123 loader->bbox.xMax = 0; 1124 loader->bbox.yMin = 0; 1125 loader->bbox.yMax = 0; 1126 1127 loader->pp1.x = 0; 1128 loader->pp2.x = loader->advance; 1129 loader->pp3.y = 0; 1130 loader->pp4.y = loader->pp3.y-loader->vadvance; 1131 1132#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT 1133 if ( ((TT_Face)(loader->face))->doblend ) 1134 { 1135 /* this must be done before scaling */ 1136 FT_Memory memory = loader->face->memory; 1137 1138 1139 error = TT_Vary_Get_Glyph_Deltas( (TT_Face)(loader->face), 1140 glyph_index, &deltas, 4 ); 1141 if ( error ) 1142 goto Exit; 1143 1144 loader->pp1.x += deltas[0].x; loader->pp1.y += deltas[0].y; 1145 loader->pp2.x += deltas[1].x; loader->pp2.y += deltas[1].y; 1146 loader->pp3.x += deltas[2].x; loader->pp3.y += deltas[2].y; 1147 loader->pp4.x += deltas[3].x; loader->pp4.y += deltas[3].y; 1148 1149 FT_FREE( deltas ); 1150 } 1151#endif 1152 1153 if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 ) 1154 { 1155 loader->pp2.x = FT_MulFix( loader->pp2.x, x_scale ); 1156 loader->pp4.y = FT_MulFix( loader->pp4.y, y_scale ); 1157 } 1158 1159#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER 1160 1161 if ( loader->exec ) 1162 loader->exec->glyphSize = 0; 1163 1164#endif 1165 1166 error = TT_Err_Ok; 1167 goto Exit; 1168 } 1169 1170 loader->byte_len = (FT_Int)count; 1171 1172 offset = loader->glyf_offset + offset; 1173 1174 /* access glyph frame */ 1175 error = face->access_glyph_frame( loader, glyph_index, offset, count ); 1176 if ( error ) 1177 goto Exit; 1178 1179 opened_frame = 1; 1180 1181 /* read first glyph header */ 1182 error = face->read_glyph_header( loader ); 1183 if ( error ) 1184 goto Fail; 1185 1186 contours_count = loader->n_contours; 1187 1188 count -= 10; 1189 1190 loader->pp1.x = loader->bbox.xMin - loader->left_bearing; 1191 loader->pp1.y = 0; 1192 loader->pp2.x = loader->pp1.x + loader->advance; 1193 loader->pp2.y = 0; 1194 1195 loader->pp3.x = 0; 1196 loader->pp3.y = loader->top_bearing + loader->bbox.yMax; 1197 loader->pp4.x = 0; 1198 loader->pp4.y = loader->pp3.y - loader->vadvance; 1199 1200 /***********************************************************************/ 1201 /***********************************************************************/ 1202 /***********************************************************************/ 1203 1204 /* if it is a simple glyph, load it */ 1205 1206 if ( contours_count >= 0 ) 1207 { 1208 /* check that we can add the contours to the glyph */ 1209 error = FT_GlyphLoader_CheckPoints( gloader, 0, contours_count ); 1210 if ( error ) 1211 goto Fail; 1212 1213 error = face->read_simple_glyph( loader ); 1214 if ( error ) 1215 goto Fail; 1216 1217#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER 1218 1219 { 1220 TT_Size size = (TT_Size)loader->size; 1221 1222 1223 error = TT_Process_Simple_Glyph( loader, 1224 (FT_Bool)( size && size->debug ) ); 1225 } 1226 1227#else 1228 1229 error = TT_Process_Simple_Glyph( loader, 0 ); 1230 1231#endif 1232 1233 if ( error ) 1234 goto Fail; 1235 1236 FT_GlyphLoader_Add( gloader ); 1237 1238 /* Note: We could have put the simple loader source there */ 1239 /* but the code is fat enough already :-) */ 1240 } 1241 1242 /***********************************************************************/ 1243 /***********************************************************************/ 1244 /***********************************************************************/ 1245 1246 /* otherwise, load a composite! */ 1247 else if ( contours_count == -1 ) 1248 { 1249 TT_GlyphSlot glyph = (TT_GlyphSlot)loader->glyph; 1250 FT_UInt start_point; 1251#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER 1252 FT_UInt start_contour; 1253 FT_ULong ins_pos; /* position of composite instructions, if any */ 1254#endif 1255 1256 1257 /* for each subglyph, read composite header */ 1258 start_point = gloader->base.outline.n_points; 1259#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER 1260 start_contour = gloader->base.outline.n_contours; 1261#endif 1262 1263 error = face->read_composite_glyph( loader ); 1264 if ( error ) 1265 goto Fail; 1266 1267#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER 1268 ins_pos = loader->ins_pos; 1269#endif 1270 face->forget_glyph_frame( loader ); 1271 opened_frame = 0; 1272 1273#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT 1274 1275 if ( face->doblend ) 1276 { 1277 FT_Int i, limit; 1278 FT_SubGlyph subglyph; 1279 FT_Memory memory = face->root.memory; 1280 1281 1282 /* this provides additional offsets */ 1283 /* for each component's translation */ 1284 1285 if ( (error = TT_Vary_Get_Glyph_Deltas( 1286 face, 1287 glyph_index, 1288 &deltas, 1289 gloader->current.num_subglyphs + 4 )) != 0 ) 1290 goto Exit; 1291 1292 /* Note: No subglyph reallocation here, our pointers are stable. */ 1293 subglyph = gloader->current.subglyphs + gloader->base.num_subglyphs; 1294 limit = gloader->current.num_subglyphs; 1295 1296 for ( i = 0; i < limit; ++i, ++subglyph ) 1297 { 1298 if ( subglyph->flags & ARGS_ARE_XY_VALUES ) 1299 { 1300 subglyph->arg1 += deltas[i].x; 1301 subglyph->arg2 += deltas[i].y; 1302 } 1303 } 1304 1305 loader->pp1.x += deltas[i + 0].x; loader->pp1.y += deltas[i + 0].y; 1306 loader->pp2.x += deltas[i + 1].x; loader->pp2.y += deltas[i + 1].y; 1307 loader->pp3.x += deltas[i + 2].x; loader->pp3.y += deltas[i + 2].y; 1308 loader->pp4.x += deltas[i + 3].x; loader->pp4.y += deltas[i + 3].y; 1309 1310 FT_FREE( deltas ); 1311 } 1312 1313#endif /* TT_CONFIG_OPTION_GX_VAR_SUPPORT */ 1314 1315 if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 ) 1316 { 1317 loader->pp1.x = FT_MulFix( loader->pp1.x, x_scale ); 1318 loader->pp2.x = FT_MulFix( loader->pp2.x, x_scale ); 1319 loader->pp3.y = FT_MulFix( loader->pp3.y, y_scale ); 1320 loader->pp4.y = FT_MulFix( loader->pp4.y, y_scale ); 1321 } 1322 1323 /* if the flag FT_LOAD_NO_RECURSE is set, we return the subglyph */ 1324 /* `as is' in the glyph slot (the client application will be */ 1325 /* responsible for interpreting these data)... */ 1326 /* */ 1327 if ( loader->load_flags & FT_LOAD_NO_RECURSE ) 1328 { 1329 /* set up remaining glyph fields */ 1330 FT_GlyphLoader_Add( gloader ); 1331 1332 glyph->num_subglyphs = gloader->base.num_subglyphs; 1333 glyph->format = FT_GLYPH_FORMAT_COMPOSITE; 1334 glyph->subglyphs = gloader->base.subglyphs; 1335 1336 goto Exit; 1337 } 1338 1339 /*********************************************************************/ 1340 /*********************************************************************/ 1341 /*********************************************************************/ 1342 1343 /* Now, read each subglyph independently. */ 1344 { 1345 FT_Int n, num_base_points, num_new_points; 1346 FT_SubGlyph subglyph = 0; 1347 1348 FT_UInt num_subglyphs = gloader->current.num_subglyphs; 1349 FT_UInt num_base_subgs = gloader->base.num_subglyphs; 1350 1351 1352 FT_GlyphLoader_Add( gloader ); 1353 1354 for ( n = 0; n < (FT_Int)num_subglyphs; n++ ) 1355 { 1356 FT_Vector pp1, pp2, pp3, pp4; 1357 FT_Pos x, y; 1358 1359 1360 /* Each time we call load_truetype_glyph in this loop, the */ 1361 /* value of `gloader.base.subglyphs' can change due to table */ 1362 /* reallocations. We thus need to recompute the subglyph */ 1363 /* pointer on each iteration. */ 1364 subglyph = gloader->base.subglyphs + num_base_subgs + n; 1365 1366 pp1 = loader->pp1; 1367 pp2 = loader->pp2; 1368 pp3 = loader->pp3; 1369 pp4 = loader->pp4; 1370 1371 num_base_points = gloader->base.outline.n_points; 1372 1373 error = load_truetype_glyph( loader, subglyph->index, 1374 recurse_count + 1 ); 1375 if ( error ) 1376 goto Fail; 1377 1378 /* restore subglyph pointer */ 1379 subglyph = gloader->base.subglyphs + num_base_subgs + n; 1380 1381 if ( subglyph->flags & USE_MY_METRICS ) 1382 { 1383 pp1 = loader->pp1; 1384 pp2 = loader->pp2; 1385 pp3 = loader->pp3; 1386 pp4 = loader->pp4; 1387 } 1388 else 1389 { 1390 loader->pp1 = pp1; 1391 loader->pp2 = pp2; 1392 loader->pp3 = pp3; 1393 loader->pp4 = pp4; 1394 } 1395 1396 num_points = gloader->base.outline.n_points; 1397 1398 num_new_points = num_points - num_base_points; 1399 1400 /* now perform the transform required for this subglyph */ 1401 1402 if ( subglyph->flags & ( WE_HAVE_A_SCALE | 1403 WE_HAVE_AN_XY_SCALE | 1404 WE_HAVE_A_2X2 ) ) 1405 { 1406 FT_Vector* cur = gloader->base.outline.points + 1407 num_base_points; 1408 FT_Vector* org = gloader->base.extra_points + 1409 num_base_points; 1410 FT_Vector* limit = cur + num_new_points; 1411 1412 1413 for ( ; cur < limit; cur++, org++ ) 1414 { 1415 FT_Vector_Transform( cur, &subglyph->transform ); 1416 FT_Vector_Transform( org, &subglyph->transform ); 1417 } 1418 } 1419 1420 /* apply offset */ 1421 1422 if ( !( subglyph->flags & ARGS_ARE_XY_VALUES ) ) 1423 { 1424 FT_UInt k = subglyph->arg1; 1425 FT_UInt l = subglyph->arg2; 1426 FT_Vector* p1; 1427 FT_Vector* p2; 1428 1429 1430 if ( start_point + k >= (FT_UInt)num_base_points || 1431 l >= (FT_UInt)num_new_points ) 1432 { 1433 error = TT_Err_Invalid_Composite; 1434 goto Fail; 1435 } 1436 1437 l += num_base_points; 1438 1439 p1 = gloader->base.outline.points + start_point + k; 1440 p2 = gloader->base.outline.points + start_point + l; 1441 1442 x = p1->x - p2->x; 1443 y = p1->y - p2->y; 1444 } 1445 else 1446 { 1447 x = subglyph->arg1; 1448 y = subglyph->arg2; 1449 1450 /* Use a default value dependent on */ 1451 /* TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED. This is useful for old TT */ 1452 /* fonts which don't set the xxx_COMPONENT_OFFSET bit. */ 1453 1454#ifdef TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED 1455 if ( !( subglyph->flags & UNSCALED_COMPONENT_OFFSET ) && 1456#else 1457 if ( ( subglyph->flags & SCALED_COMPONENT_OFFSET ) && 1458#endif 1459 ( subglyph->flags & ( WE_HAVE_A_SCALE | 1460 WE_HAVE_AN_XY_SCALE | 1461 WE_HAVE_A_2X2 )) ) 1462 { 1463#if 0 1464 1465 /*************************************************************************/ 1466 /* */ 1467 /* This algorithm is what Apple documents. But it doesn't work. */ 1468 /* */ 1469 int a = subglyph->transform.xx > 0 ? subglyph->transform.xx 1470 : -subglyph->transform.xx; 1471 int b = subglyph->transform.yx > 0 ? subglyph->transform.yx 1472 : -subglyph->transform.yx; 1473 int c = subglyph->transform.xy > 0 ? subglyph->transform.xy 1474 : -subglyph->transform.xy; 1475 int d = subglyph->transform.yy > 0 ? subglyph->transform.yy 1476 : -subglyph->transform.yy; 1477 int m = a > b ? a : b; 1478 int n = c > d ? c : d; 1479 1480 1481 if ( a - b <= 33 && a - b >= -33 ) 1482 m *= 2; 1483 if ( c - d <= 33 && c - d >= -33 ) 1484 n *= 2; 1485 x = FT_MulFix( x, m ); 1486 y = FT_MulFix( y, n ); 1487 1488#else /* 0 */ 1489 1490 /*************************************************************************/ 1491 /* */ 1492 /* This algorithm is a guess and works much better than the above. */ 1493 /* */ 1494 FT_Fixed mac_xscale = FT_SqrtFixed( 1495 FT_MulFix( subglyph->transform.xx, 1496 subglyph->transform.xx ) + 1497 FT_MulFix( subglyph->transform.xy, 1498 subglyph->transform.xy) ); 1499 FT_Fixed mac_yscale = FT_SqrtFixed( 1500 FT_MulFix( subglyph->transform.yy, 1501 subglyph->transform.yy ) + 1502 FT_MulFix( subglyph->transform.yx, 1503 subglyph->transform.yx ) ); 1504 1505 1506 x = FT_MulFix( x, mac_xscale ); 1507 y = FT_MulFix( y, mac_yscale ); 1508#endif /* 0 */ 1509 1510 } 1511 1512 if ( !( loader->load_flags & FT_LOAD_NO_SCALE ) ) 1513 { 1514 x = FT_MulFix( x, x_scale ); 1515 y = FT_MulFix( y, y_scale ); 1516 1517 if ( subglyph->flags & ROUND_XY_TO_GRID ) 1518 { 1519 x = FT_PIX_ROUND( x ); 1520 y = FT_PIX_ROUND( y ); 1521 } 1522 } 1523 } 1524 1525 if ( x || y ) 1526 { 1527 translate_array( num_new_points, 1528 gloader->base.outline.points + num_base_points, 1529 x, y ); 1530 1531 translate_array( num_new_points, 1532 gloader->base.extra_points + num_base_points, 1533 x, y ); 1534 } 1535 } 1536 1537 /*******************************************************************/ 1538 /*******************************************************************/ 1539 /*******************************************************************/ 1540 1541 /* we have finished loading all sub-glyphs; now, look for */ 1542 /* instructions for this composite! */ 1543 1544#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER 1545 1546 if ( num_subglyphs > 0 && 1547 loader->exec && 1548 ins_pos > 0 && 1549 subglyph->flags & WE_HAVE_INSTR ) 1550 { 1551 FT_UShort n_ins; 1552 TT_ExecContext exec = loader->exec; 1553 TT_GlyphZone pts; 1554 FT_Vector* pp1; 1555 1556 1557 /* read size of instructions */ 1558 if ( FT_STREAM_SEEK( ins_pos ) || 1559 FT_READ_USHORT( n_ins ) ) 1560 goto Fail; 1561 FT_TRACE5(( " Instructions size = %d\n", n_ins )); 1562 1563 /* in some fonts? */ 1564 if ( n_ins == 0xFFFFU ) 1565 n_ins = 0; 1566 1567 /* check it */ 1568 if ( n_ins > face->max_profile.maxSizeOfInstructions ) 1569 { 1570 FT_TRACE0(( "Too many instructions (%d) in composite glyph %ld\n", 1571 n_ins, subglyph->index )); 1572 error = TT_Err_Too_Many_Hints; 1573 goto Fail; 1574 } 1575 1576 /* read the instructions */ 1577 if ( FT_STREAM_READ( exec->glyphIns, n_ins ) ) 1578 goto Fail; 1579 1580 glyph->control_data = exec->glyphIns; 1581 glyph->control_len = n_ins; 1582 1583 error = TT_Set_CodeRange( exec, 1584 tt_coderange_glyph, 1585 exec->glyphIns, 1586 n_ins ); 1587 if ( error ) 1588 goto Fail; 1589 1590 error = FT_GlyphLoader_CheckPoints( gloader, num_points + 4, 0 ); 1591 if ( error ) 1592 goto Fail; 1593 1594 /* prepare the execution context */ 1595 tt_prepare_zone( &exec->pts, &gloader->base, 1596 start_point, start_contour ); 1597 pts = &exec->pts; 1598 1599 pts->n_points = (short)( num_points + 4 ); 1600 pts->n_contours = gloader->base.outline.n_contours; 1601 1602 /* add phantom points */ 1603 pp1 = pts->cur + num_points; 1604 pp1[0] = loader->pp1; 1605 pp1[1] = loader->pp2; 1606 pp1[2] = loader->pp3; 1607 pp1[3] = loader->pp4; 1608 1609 pts->tags[num_points ] = 0; 1610 pts->tags[num_points + 1] = 0; 1611 pts->tags[num_points + 2] = 0; 1612 pts->tags[num_points + 3] = 0; 1613 1614 /* if hinting, round the phantom points */ 1615 if ( IS_HINTED( loader->load_flags ) ) 1616 { 1617 pp1[0].x = FT_PIX_ROUND( loader->pp1.x ); 1618 pp1[1].x = FT_PIX_ROUND( loader->pp2.x ); 1619 pp1[2].y = FT_PIX_ROUND( loader->pp3.y ); 1620 pp1[3].y = FT_PIX_ROUND( loader->pp4.y ); 1621 } 1622 1623 { 1624 FT_UInt k; 1625 1626 1627 for ( k = 0; k < num_points; k++ ) 1628 pts->tags[k] &= FT_CURVE_TAG_ON; 1629 } 1630 1631 cur_to_org( num_points + 4, pts ); 1632 1633 /* now consider hinting */ 1634 if ( IS_HINTED( loader->load_flags ) && n_ins > 0 ) 1635 { 1636 exec->is_composite = TRUE; 1637 error = TT_Run_Context( exec, ((TT_Size)loader->size)->debug ); 1638 if ( error && exec->pedantic_hinting ) 1639 goto Fail; 1640 } 1641 1642 /* save glyph origin and advance points */ 1643 loader->pp1 = pp1[0]; 1644 loader->pp2 = pp1[1]; 1645 loader->pp3 = pp1[2]; 1646 loader->pp4 = pp1[3]; 1647 } 1648 1649#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */ 1650 1651 } 1652 /* end of composite loading */ 1653 } 1654 else 1655 { 1656 /* invalid composite count ( negative but not -1 ) */ 1657 error = TT_Err_Invalid_Outline; 1658 goto Fail; 1659 } 1660 1661 /***********************************************************************/ 1662 /***********************************************************************/ 1663 /***********************************************************************/ 1664 1665 Fail: 1666 if ( opened_frame ) 1667 face->forget_glyph_frame( loader ); 1668 1669 Exit: 1670 1671#ifdef FT_CONFIG_OPTION_INCREMENTAL 1672 if ( glyph_data_loaded ) 1673 face->root.internal->incremental_interface->funcs->free_glyph_data( 1674 face->root.internal->incremental_interface->object, 1675 &glyph_data ); 1676#endif 1677 1678 return error; 1679 } 1680 1681 1682 static FT_Error 1683 compute_glyph_metrics( TT_Loader loader, 1684 FT_UInt glyph_index ) 1685 { 1686 FT_BBox bbox; 1687 TT_Face face = (TT_Face)loader->face; 1688 FT_Fixed y_scale; 1689 TT_GlyphSlot glyph = loader->glyph; 1690 TT_Size size = (TT_Size)loader->size; 1691 1692 1693 y_scale = 0x10000L; 1694 if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 ) 1695 y_scale = size->root.metrics.y_scale; 1696 1697 if ( glyph->format != FT_GLYPH_FORMAT_COMPOSITE ) 1698 { 1699 glyph->outline.flags &= ~FT_OUTLINE_SINGLE_PASS; 1700 1701 /* copy outline to our glyph slot */ 1702 FT_GlyphLoader_CopyPoints( glyph->internal->loader, loader->gloader ); 1703 glyph->outline = glyph->internal->loader->base.outline; 1704 1705 /* translate array so that (0,0) is the glyph's origin */ 1706 FT_Outline_Translate( &glyph->outline, -loader->pp1.x, 0 ); 1707 1708 FT_Outline_Get_CBox( &glyph->outline, &bbox ); 1709 1710 if ( IS_HINTED( loader->load_flags ) ) 1711 { 1712 /* grid-fit the bounding box */ 1713 bbox.xMin = FT_PIX_FLOOR( bbox.xMin ); 1714 bbox.yMin = FT_PIX_FLOOR( bbox.yMin ); 1715 bbox.xMax = FT_PIX_CEIL( bbox.xMax ); 1716 bbox.yMax = FT_PIX_CEIL( bbox.yMax ); 1717 } 1718 } 1719 else 1720 bbox = loader->bbox; 1721 1722 /* get the device-independent horizontal advance. It is scaled later */ 1723 /* by the base layer. */ 1724 { 1725 FT_Pos advance = loader->linear; 1726 1727 1728 /* the flag FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH was introduced to */ 1729 /* correctly support DynaLab fonts, which have an incorrect */ 1730 /* `advance_Width_Max' field! It is used, to my knowledge, */ 1731 /* exclusively in the X-TrueType font server. */ 1732 /* */ 1733 if ( face->postscript.isFixedPitch && 1734 ( loader->load_flags & FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH ) == 0 ) 1735 advance = face->horizontal.advance_Width_Max; 1736 1737 /* we need to return the advance in font units in linearHoriAdvance, */ 1738 /* it will be scaled later by the base layer. */ 1739 glyph->linearHoriAdvance = advance; 1740 } 1741 1742 glyph->metrics.horiBearingX = bbox.xMin; 1743 glyph->metrics.horiBearingY = bbox.yMax; 1744 glyph->metrics.horiAdvance = loader->pp2.x - loader->pp1.x; 1745 1746 /* don't forget to hint the advance when we need to */ 1747 if ( IS_HINTED( loader->load_flags ) ) 1748 glyph->metrics.horiAdvance = FT_PIX_ROUND( glyph->metrics.horiAdvance ); 1749 1750 /* Now take care of vertical metrics. In the case where there is */ 1751 /* no vertical information within the font (relatively common), make */ 1752 /* up some metrics by `hand'... */ 1753 1754 { 1755 FT_Short top_bearing; /* vertical top side bearing (EM units) */ 1756 FT_UShort advance_height; /* vertical advance height (EM units) */ 1757 1758 FT_Pos left; /* scaled vertical left side bearing */ 1759 FT_Pos top; /* scaled vertical top side bearing */ 1760 FT_Pos advance; /* scaled vertical advance height */ 1761 1762 1763 /* Get the unscaled top bearing and advance height. */ 1764 if ( face->vertical_info && 1765 face->vertical.number_Of_VMetrics > 0 ) 1766 { 1767 advance_height = (FT_UShort)( loader->pp4.y - loader->pp3.y ); 1768 top_bearing = (FT_Short)( loader->pp3.y - bbox.yMax ); 1769 } 1770 else 1771 { 1772 /* Make up the distances from the horizontal header. */ 1773 1774 /* NOTE: The OS/2 values are the only `portable' ones, */ 1775 /* which is why we use them, if there is an OS/2 */ 1776 /* table in the font. Otherwise, we use the */ 1777 /* values defined in the horizontal header. */ 1778 /* */ 1779 /* NOTE2: The sTypoDescender is negative, which is why */ 1780 /* we compute the baseline-to-baseline distance */ 1781 /* here with: */ 1782 /* ascender - descender + linegap */ 1783 /* */ 1784 /* NOTE3: This is different from what MS's rasterizer */ 1785 /* appears to do when getting default values */ 1786 /* for the vertical phantom points. We leave */ 1787 /* the old code untouched, but relying on */ 1788 /* phantom points alone might be reasonable */ 1789 /* (i.e., removing the `if' above). */ 1790 if ( face->os2.version != 0xFFFFU ) 1791 { 1792 top_bearing = (FT_Short)( face->os2.sTypoLineGap / 2 ); 1793 advance_height = (FT_UShort)( face->os2.sTypoAscender - 1794 face->os2.sTypoDescender + 1795 face->os2.sTypoLineGap ); 1796 } 1797 else 1798 { 1799 top_bearing = (FT_Short)( face->horizontal.Line_Gap / 2 ); 1800 advance_height = (FT_UShort)( face->horizontal.Ascender + 1801 face->horizontal.Descender + 1802 face->horizontal.Line_Gap ); 1803 } 1804 } 1805 1806#ifdef FT_CONFIG_OPTION_INCREMENTAL 1807 1808 /* If this is an incrementally loaded font see if there are */ 1809 /* overriding metrics for this glyph. */ 1810 if ( face->root.internal->incremental_interface && 1811 face->root.internal->incremental_interface->funcs->get_glyph_metrics ) 1812 { 1813 FT_Incremental_MetricsRec metrics; 1814 FT_Error error = 0; 1815 1816 1817 metrics.bearing_x = 0; 1818 metrics.bearing_y = top_bearing; 1819 metrics.advance = advance_height; 1820 error = 1821 face->root.internal->incremental_interface->funcs->get_glyph_metrics( 1822 face->root.internal->incremental_interface->object, 1823 glyph_index, TRUE, &metrics ); 1824 1825 if ( error ) 1826 return error; 1827 1828 top_bearing = (FT_Short)metrics.bearing_y; 1829 advance_height = (FT_UShort)metrics.advance; 1830 } 1831 1832 /* GWW: Do vertical metrics get loaded incrementally too? */ 1833 1834#endif /* FT_CONFIG_OPTION_INCREMENTAL */ 1835 1836 /* We must adjust the top_bearing value from the bounding box given */ 1837 /* in the glyph header to the bounding box calculated with */ 1838 /* FT_Get_Outline_CBox(). */ 1839 1840 /* scale the metrics */ 1841 if ( !( loader->load_flags & FT_LOAD_NO_SCALE ) ) 1842 { 1843 top = FT_MulFix( top_bearing + loader->bbox.yMax, y_scale ) 1844 - bbox.yMax; 1845 advance = FT_MulFix( advance_height, y_scale ); 1846 } 1847 else 1848 { 1849 top = top_bearing + loader->bbox.yMax - bbox.yMax; 1850 advance = advance_height; 1851 } 1852 1853 /* set the advance height in design units. It is scaled later by */ 1854 /* the base layer. */ 1855 glyph->linearVertAdvance = advance_height; 1856 1857 /* XXX: for now, we have no better algorithm for the lsb, but it */ 1858 /* should work fine. */ 1859 /* */ 1860 left = ( bbox.xMin - bbox.xMax ) / 2; 1861 1862 /* grid-fit them if necessary */ 1863 if ( IS_HINTED( loader->load_flags ) ) 1864 { 1865 left = FT_PIX_FLOOR( left ); 1866 top = FT_PIX_CEIL( top ); 1867 advance = FT_PIX_ROUND( advance ); 1868 } 1869 1870 glyph->metrics.vertBearingX = left; 1871 glyph->metrics.vertBearingY = top; 1872 glyph->metrics.vertAdvance = advance; 1873 } 1874 1875 /* adjust advance width to the value contained in the hdmx table */ 1876 if ( !face->postscript.isFixedPitch && size && 1877 IS_HINTED( loader->load_flags ) ) 1878 { 1879 FT_Byte* widthp = Get_Advance_WidthPtr( face, 1880 size->root.metrics.x_ppem, 1881 glyph_index ); 1882 1883 1884 if ( widthp ) 1885 glyph->metrics.horiAdvance = *widthp << 6; 1886 } 1887 1888 /* set glyph dimensions */ 1889 glyph->metrics.width = bbox.xMax - bbox.xMin; 1890 glyph->metrics.height = bbox.yMax - bbox.yMin; 1891 1892 return 0; 1893 } 1894 1895 1896 /*************************************************************************/ 1897 /* */ 1898 /* <Function> */ 1899 /* TT_Load_Glyph */ 1900 /* */ 1901 /* <Description> */ 1902 /* A function used to load a single glyph within a given glyph slot, */ 1903 /* for a given size. */ 1904 /* */ 1905 /* <Input> */ 1906 /* glyph :: A handle to a target slot object where the glyph */ 1907 /* will be loaded. */ 1908 /* */ 1909 /* size :: A handle to the source face size at which the glyph */ 1910 /* must be scaled/loaded. */ 1911 /* */ 1912 /* glyph_index :: The index of the glyph in the font file. */ 1913 /* */ 1914 /* load_flags :: A flag indicating what to load for this glyph. The */ 1915 /* FT_LOAD_XXX constants can be used to control the */ 1916 /* glyph loading process (e.g., whether the outline */ 1917 /* should be scaled, whether to load bitmaps or not, */ 1918 /* whether to hint the outline, etc). */ 1919 /* */ 1920 /* <Return> */ 1921 /* FreeType error code. 0 means success. */ 1922 /* */ 1923 FT_LOCAL_DEF( FT_Error ) 1924 TT_Load_Glyph( TT_Size size, 1925 TT_GlyphSlot glyph, 1926 FT_UInt glyph_index, 1927 FT_Int32 load_flags ) 1928 { 1929 SFNT_Service sfnt; 1930 TT_Face face; 1931 FT_Stream stream; 1932 FT_Error error; 1933 TT_LoaderRec loader; 1934 1935 1936 face = (TT_Face)glyph->face; 1937 sfnt = (SFNT_Service)face->sfnt; 1938 stream = face->root.stream; 1939 error = 0; 1940 1941 if ( !size || ( load_flags & FT_LOAD_NO_SCALE ) || 1942 ( load_flags & FT_LOAD_NO_RECURSE ) ) 1943 { 1944 size = NULL; 1945 load_flags |= FT_LOAD_NO_SCALE | 1946 FT_LOAD_NO_HINTING | 1947 FT_LOAD_NO_BITMAP; 1948 } 1949 1950 glyph->num_subglyphs = 0; 1951 1952#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS 1953 1954 /* try to load embedded bitmap if any */ 1955 /* */ 1956 /* XXX: The convention should be emphasized in */ 1957 /* the documents because it can be confusing. */ 1958 if ( size && 1959 size->strike_index != 0xFFFFU && 1960 sfnt->load_sbits && 1961 ( load_flags & FT_LOAD_NO_BITMAP ) == 0 ) 1962 1963 { 1964 TT_SBit_MetricsRec metrics; 1965 1966 1967 error = sfnt->load_sbit_image( face, 1968 (FT_ULong)size->strike_index, 1969 glyph_index, 1970 (FT_Int)load_flags, 1971 stream, 1972 &glyph->bitmap, 1973 &metrics ); 1974 if ( !error ) 1975 { 1976 glyph->outline.n_points = 0; 1977 glyph->outline.n_contours = 0; 1978 1979 glyph->metrics.width = (FT_Pos)metrics.width << 6; 1980 glyph->metrics.height = (FT_Pos)metrics.height << 6; 1981 1982 glyph->metrics.horiBearingX = (FT_Pos)metrics.horiBearingX << 6; 1983 glyph->metrics.horiBearingY = (FT_Pos)metrics.horiBearingY << 6; 1984 glyph->metrics.horiAdvance = (FT_Pos)metrics.horiAdvance << 6; 1985 1986 glyph->metrics.vertBearingX = (FT_Pos)metrics.vertBearingX << 6; 1987 glyph->metrics.vertBearingY = (FT_Pos)metrics.vertBearingY << 6; 1988 glyph->metrics.vertAdvance = (FT_Pos)metrics.vertAdvance << 6; 1989 1990 glyph->format = FT_GLYPH_FORMAT_BITMAP; 1991 if ( load_flags & FT_LOAD_VERTICAL_LAYOUT ) 1992 { 1993 glyph->bitmap_left = metrics.vertBearingX; 1994 glyph->bitmap_top = metrics.vertBearingY; 1995 } 1996 else 1997 { 1998 glyph->bitmap_left = metrics.horiBearingX; 1999 glyph->bitmap_top = metrics.horiBearingY; 2000 } 2001 return error; 2002 } 2003 } 2004 2005#endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */ 2006 2007 /* return immediately if we only want the embedded bitmaps */ 2008 if ( load_flags & FT_LOAD_SBITS_ONLY ) 2009 return TT_Err_Invalid_Argument; 2010 2011 /* seek to the beginning of the glyph table. For Type 42 fonts */ 2012 /* the table might be accessed from a Postscript stream or something */ 2013 /* else... */ 2014 2015#ifdef FT_CONFIG_OPTION_INCREMENTAL 2016 2017 /* Don't look for the glyph table if this is an incremental font. */ 2018 if ( !face->root.internal->incremental_interface ) 2019 2020#endif 2021 2022 { 2023 error = face->goto_table( face, TTAG_glyf, stream, 0 ); 2024 if ( error ) 2025 { 2026 FT_ERROR(( "TT_Load_Glyph: could not access glyph table\n" )); 2027 goto Exit; 2028 } 2029 } 2030 2031 FT_MEM_ZERO( &loader, sizeof ( loader ) ); 2032 2033 /* update the glyph zone bounds */ 2034 { 2035 FT_GlyphLoader gloader = FT_FACE_DRIVER(face)->glyph_loader; 2036 2037 2038 loader.gloader = gloader; 2039 2040 FT_GlyphLoader_Rewind( gloader ); 2041 2042 tt_prepare_zone( &loader.zone, &gloader->base, 0, 0 ); 2043 tt_prepare_zone( &loader.base, &gloader->base, 0, 0 ); 2044 } 2045 2046#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER 2047 2048 if ( size ) 2049 { 2050 /* query new execution context */ 2051 loader.exec = size->debug ? size->context : TT_New_Context( face ); 2052 if ( !loader.exec ) 2053 return TT_Err_Could_Not_Find_Context; 2054 2055 TT_Load_Context( loader.exec, face, size ); 2056 loader.instructions = loader.exec->glyphIns; 2057 2058 /* load default graphics state - if needed */ 2059 if ( size->GS.instruct_control & 2 ) 2060 loader.exec->GS = tt_default_graphics_state; 2061 2062 loader.exec->pedantic_hinting = 2063 FT_BOOL( load_flags & FT_LOAD_PEDANTIC ); 2064 2065 loader.exec->grayscale = 2066 FT_BOOL( FT_LOAD_TARGET_MODE( load_flags ) != FT_LOAD_TARGET_MONO ); 2067 } 2068 2069#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */ 2070 2071 /* clear all outline flags, except the `owner' one */ 2072 glyph->outline.flags = 0; 2073 2074 /* let's initialize the rest of our loader now */ 2075 2076 loader.load_flags = load_flags; 2077 2078 loader.face = (FT_Face)face; 2079 loader.size = (FT_Size)size; 2080 loader.glyph = (FT_GlyphSlot)glyph; 2081 loader.stream = stream; 2082 2083#ifdef FT_CONFIG_OPTION_INCREMENTAL 2084 2085 if ( face->root.internal->incremental_interface ) 2086 loader.glyf_offset = 0; 2087 else 2088 2089#endif 2090 2091 loader.glyf_offset = FT_STREAM_POS(); 2092 2093#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER 2094 2095 /* if the cvt program has disabled hinting, the argument */ 2096 /* is ignored. */ 2097 if ( size && ( size->GS.instruct_control & 1 ) ) 2098 loader.load_flags |= FT_LOAD_NO_HINTING; 2099 2100#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */ 2101 2102 /* Main loading loop */ 2103 glyph->format = FT_GLYPH_FORMAT_OUTLINE; 2104 glyph->num_subglyphs = 0; 2105 2106 error = load_truetype_glyph( &loader, glyph_index, 0 ); 2107 if ( !error ) 2108 compute_glyph_metrics( &loader, glyph_index ); 2109 2110#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER 2111 2112 if ( !size || !size->debug ) 2113 TT_Done_Context( loader.exec ); 2114 2115#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */ 2116 2117 /* Set the `high precision' bit flag. */ 2118 /* This is _critical_ to get correct output for monochrome */ 2119 /* TrueType glyphs at all sizes using the bytecode interpreter. */ 2120 /* */ 2121 if ( size && size->root.metrics.y_ppem < 24 ) 2122 glyph->outline.flags |= FT_OUTLINE_HIGH_PRECISION; 2123 2124 Exit: 2125 return error; 2126 } 2127 2128 2129/* END */ 2130