ttgload.c revision 24e256ab005c68a3894845ef3b7764338f9442a4
1/***************************************************************************/ 2/* */ 3/* ttgload.c */ 4/* */ 5/* TrueType Glyph Loader (body). */ 6/* */ 7/* Copyright 1996-2017 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_CONFIG_CONFIG_H 22#include FT_INTERNAL_CALC_H 23#include FT_INTERNAL_STREAM_H 24#include FT_INTERNAL_SFNT_H 25#include FT_TRUETYPE_TAGS_H 26#include FT_OUTLINE_H 27#include FT_TRUETYPE_DRIVER_H 28#include FT_LIST_H 29 30#include "ttgload.h" 31#include "ttpload.h" 32 33#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT 34#include "ttgxvar.h" 35#endif 36 37#include "tterrors.h" 38#include "ttsubpix.h" 39 40 41 /*************************************************************************/ 42 /* */ 43 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ 44 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ 45 /* messages during execution. */ 46 /* */ 47#undef FT_COMPONENT 48#define FT_COMPONENT trace_ttgload 49 50 51 /*************************************************************************/ 52 /* */ 53 /* Composite glyph flags. */ 54 /* */ 55#define ARGS_ARE_WORDS 0x0001 56#define ARGS_ARE_XY_VALUES 0x0002 57#define ROUND_XY_TO_GRID 0x0004 58#define WE_HAVE_A_SCALE 0x0008 59/* reserved 0x0010 */ 60#define MORE_COMPONENTS 0x0020 61#define WE_HAVE_AN_XY_SCALE 0x0040 62#define WE_HAVE_A_2X2 0x0080 63#define WE_HAVE_INSTR 0x0100 64#define USE_MY_METRICS 0x0200 65#define OVERLAP_COMPOUND 0x0400 66#define SCALED_COMPONENT_OFFSET 0x0800 67#define UNSCALED_COMPONENT_OFFSET 0x1000 68 69 70 /*************************************************************************/ 71 /* */ 72 /* Return the horizontal metrics in font units for a given glyph. */ 73 /* */ 74 FT_LOCAL_DEF( void ) 75 TT_Get_HMetrics( TT_Face face, 76 FT_UInt idx, 77 FT_Short* lsb, 78 FT_UShort* aw ) 79 { 80 ( (SFNT_Service)face->sfnt )->get_metrics( face, 0, idx, lsb, aw ); 81 82 FT_TRACE5(( " advance width (font units): %d\n", *aw )); 83 FT_TRACE5(( " left side bearing (font units): %d\n", *lsb )); 84 } 85 86 87 /*************************************************************************/ 88 /* */ 89 /* Return the vertical metrics in font units for a given glyph. */ 90 /* See macro `TT_LOADER_SET_PP' below for explanations. */ 91 /* */ 92 FT_LOCAL_DEF( void ) 93 TT_Get_VMetrics( TT_Face face, 94 FT_UInt idx, 95 FT_Pos yMax, 96 FT_Short* tsb, 97 FT_UShort* ah ) 98 { 99 if ( face->vertical_info ) 100 ( (SFNT_Service)face->sfnt )->get_metrics( face, 1, idx, tsb, ah ); 101 102 else if ( face->os2.version != 0xFFFFU ) 103 { 104 *tsb = (FT_Short)( face->os2.sTypoAscender - yMax ); 105 *ah = (FT_UShort)FT_ABS( face->os2.sTypoAscender - 106 face->os2.sTypoDescender ); 107 } 108 109 else 110 { 111 *tsb = (FT_Short)( face->horizontal.Ascender - yMax ); 112 *ah = (FT_UShort)FT_ABS( face->horizontal.Ascender - 113 face->horizontal.Descender ); 114 } 115 116 FT_TRACE5(( " advance height (font units): %d\n", *ah )); 117 FT_TRACE5(( " top side bearing (font units): %d\n", *tsb )); 118 } 119 120 121 static FT_Error 122 tt_get_metrics( TT_Loader loader, 123 FT_UInt glyph_index ) 124 { 125 TT_Face face = loader->face; 126#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY 127 TT_Driver driver = (TT_Driver)FT_FACE_DRIVER( face ); 128#endif 129 130 FT_Error error; 131 FT_Stream stream = loader->stream; 132 133 FT_Short left_bearing = 0, top_bearing = 0; 134 FT_UShort advance_width = 0, advance_height = 0; 135 136 /* we must preserve the stream position */ 137 /* (which gets altered by the metrics functions) */ 138 FT_ULong pos = FT_STREAM_POS(); 139 140 141 TT_Get_HMetrics( face, glyph_index, 142 &left_bearing, 143 &advance_width ); 144 TT_Get_VMetrics( face, glyph_index, 145 loader->bbox.yMax, 146 &top_bearing, 147 &advance_height ); 148 149 if ( FT_STREAM_SEEK( pos ) ) 150 return error; 151 152 loader->left_bearing = left_bearing; 153 loader->advance = advance_width; 154 loader->top_bearing = top_bearing; 155 loader->vadvance = advance_height; 156 157#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY 158 if ( driver->interpreter_version == TT_INTERPRETER_VERSION_38 && 159 loader->exec ) 160 { 161 loader->exec->sph_tweak_flags = 0; 162 163 /* This may not be the right place for this, but it works... */ 164 /* Note that we have to unconditionally load the tweaks since */ 165 /* it is possible that glyphs individually switch ClearType's */ 166 /* backward compatibility mode on and off. */ 167 sph_set_tweaks( loader, glyph_index ); 168 } 169#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ 170 171 if ( !loader->linear_def ) 172 { 173 loader->linear_def = 1; 174 loader->linear = advance_width; 175 } 176 177 return FT_Err_Ok; 178 } 179 180 181#ifdef FT_CONFIG_OPTION_INCREMENTAL 182 183 static void 184 tt_get_metrics_incr_overrides( TT_Loader loader, 185 FT_UInt glyph_index ) 186 { 187 TT_Face face = loader->face; 188 189 FT_Short left_bearing = 0, top_bearing = 0; 190 FT_UShort advance_width = 0, advance_height = 0; 191 192 193 /* If this is an incrementally loaded font check whether there are */ 194 /* overriding metrics for this glyph. */ 195 if ( face->root.internal->incremental_interface && 196 face->root.internal->incremental_interface->funcs->get_glyph_metrics ) 197 { 198 FT_Incremental_MetricsRec incr_metrics; 199 FT_Error error; 200 201 202 incr_metrics.bearing_x = loader->left_bearing; 203 incr_metrics.bearing_y = 0; 204 incr_metrics.advance = loader->advance; 205 incr_metrics.advance_v = 0; 206 207 error = face->root.internal->incremental_interface->funcs->get_glyph_metrics( 208 face->root.internal->incremental_interface->object, 209 glyph_index, FALSE, &incr_metrics ); 210 if ( error ) 211 goto Exit; 212 213 left_bearing = (FT_Short)incr_metrics.bearing_x; 214 advance_width = (FT_UShort)incr_metrics.advance; 215 216#if 0 217 218 /* GWW: Do I do the same for vertical metrics? */ 219 incr_metrics.bearing_x = 0; 220 incr_metrics.bearing_y = loader->top_bearing; 221 incr_metrics.advance = loader->vadvance; 222 223 error = face->root.internal->incremental_interface->funcs->get_glyph_metrics( 224 face->root.internal->incremental_interface->object, 225 glyph_index, TRUE, &incr_metrics ); 226 if ( error ) 227 goto Exit; 228 229 top_bearing = (FT_Short)incr_metrics.bearing_y; 230 advance_height = (FT_UShort)incr_metrics.advance; 231 232#endif /* 0 */ 233 234 loader->left_bearing = left_bearing; 235 loader->advance = advance_width; 236 loader->top_bearing = top_bearing; 237 loader->vadvance = advance_height; 238 239 if ( !loader->linear_def ) 240 { 241 loader->linear_def = 1; 242 loader->linear = advance_width; 243 } 244 } 245 246 Exit: 247 return; 248 } 249 250#endif /* FT_CONFIG_OPTION_INCREMENTAL */ 251 252 253 /*************************************************************************/ 254 /* */ 255 /* The following functions are used by default with TrueType fonts. */ 256 /* However, they can be replaced by alternatives if we need to support */ 257 /* TrueType-compressed formats (like MicroType) in the future. */ 258 /* */ 259 /*************************************************************************/ 260 261 FT_CALLBACK_DEF( FT_Error ) 262 TT_Access_Glyph_Frame( TT_Loader loader, 263 FT_UInt glyph_index, 264 FT_ULong offset, 265 FT_UInt byte_count ) 266 { 267 FT_Error error; 268 FT_Stream stream = loader->stream; 269 270 /* for non-debug mode */ 271 FT_UNUSED( glyph_index ); 272 273 274 FT_TRACE4(( "Glyph %ld\n", glyph_index )); 275 276 /* the following line sets the `error' variable through macros! */ 277 if ( FT_STREAM_SEEK( offset ) || FT_FRAME_ENTER( byte_count ) ) 278 return error; 279 280 loader->cursor = stream->cursor; 281 loader->limit = stream->limit; 282 283 return FT_Err_Ok; 284 } 285 286 287 FT_CALLBACK_DEF( void ) 288 TT_Forget_Glyph_Frame( TT_Loader loader ) 289 { 290 FT_Stream stream = loader->stream; 291 292 293 FT_FRAME_EXIT(); 294 } 295 296 297 FT_CALLBACK_DEF( FT_Error ) 298 TT_Load_Glyph_Header( TT_Loader loader ) 299 { 300 FT_Byte* p = loader->cursor; 301 FT_Byte* limit = loader->limit; 302 303 304 if ( p + 10 > limit ) 305 return FT_THROW( Invalid_Outline ); 306 307 loader->n_contours = FT_NEXT_SHORT( p ); 308 309 loader->bbox.xMin = FT_NEXT_SHORT( p ); 310 loader->bbox.yMin = FT_NEXT_SHORT( p ); 311 loader->bbox.xMax = FT_NEXT_SHORT( p ); 312 loader->bbox.yMax = FT_NEXT_SHORT( p ); 313 314 FT_TRACE5(( " # of contours: %d\n", loader->n_contours )); 315 FT_TRACE5(( " xMin: %4d xMax: %4d\n", loader->bbox.xMin, 316 loader->bbox.xMax )); 317 FT_TRACE5(( " yMin: %4d yMax: %4d\n", loader->bbox.yMin, 318 loader->bbox.yMax )); 319 loader->cursor = p; 320 321 return FT_Err_Ok; 322 } 323 324 325 FT_CALLBACK_DEF( FT_Error ) 326 TT_Load_Simple_Glyph( TT_Loader load ) 327 { 328 FT_Error error; 329 FT_Byte* p = load->cursor; 330 FT_Byte* limit = load->limit; 331 FT_GlyphLoader gloader = load->gloader; 332 FT_Int n_contours = load->n_contours; 333 FT_Outline* outline; 334 FT_UShort n_ins; 335 FT_Int n_points; 336 337 FT_Byte *flag, *flag_limit; 338 FT_Byte c, count; 339 FT_Vector *vec, *vec_limit; 340 FT_Pos x; 341 FT_Short *cont, *cont_limit, prev_cont; 342 FT_Int xy_size = 0; 343 344 345 /* check that we can add the contours to the glyph */ 346 error = FT_GLYPHLOADER_CHECK_POINTS( gloader, 0, n_contours ); 347 if ( error ) 348 goto Fail; 349 350 /* reading the contours' endpoints & number of points */ 351 cont = gloader->current.outline.contours; 352 cont_limit = cont + n_contours; 353 354 /* check space for contours array + instructions count */ 355 if ( n_contours >= 0xFFF || p + ( n_contours + 1 ) * 2 > limit ) 356 goto Invalid_Outline; 357 358 prev_cont = FT_NEXT_SHORT( p ); 359 360 if ( n_contours > 0 ) 361 cont[0] = prev_cont; 362 363 if ( prev_cont < 0 ) 364 goto Invalid_Outline; 365 366 for ( cont++; cont < cont_limit; cont++ ) 367 { 368 cont[0] = FT_NEXT_SHORT( p ); 369 if ( cont[0] <= prev_cont ) 370 { 371 /* unordered contours: this is invalid */ 372 goto Invalid_Outline; 373 } 374 prev_cont = cont[0]; 375 } 376 377 n_points = 0; 378 if ( n_contours > 0 ) 379 { 380 n_points = cont[-1] + 1; 381 if ( n_points < 0 ) 382 goto Invalid_Outline; 383 } 384 385 /* note that we will add four phantom points later */ 386 error = FT_GLYPHLOADER_CHECK_POINTS( gloader, n_points + 4, 0 ); 387 if ( error ) 388 goto Fail; 389 390 /* reading the bytecode instructions */ 391 load->glyph->control_len = 0; 392 load->glyph->control_data = NULL; 393 394 if ( p + 2 > limit ) 395 goto Invalid_Outline; 396 397 n_ins = FT_NEXT_USHORT( p ); 398 399 FT_TRACE5(( " Instructions size: %u\n", n_ins )); 400 401#ifdef TT_USE_BYTECODE_INTERPRETER 402 403 if ( IS_HINTED( load->load_flags ) ) 404 { 405 FT_ULong tmp; 406 407 408 /* check instructions size */ 409 if ( ( limit - p ) < n_ins ) 410 { 411 FT_TRACE1(( "TT_Load_Simple_Glyph: instruction count mismatch\n" )); 412 error = FT_THROW( Too_Many_Hints ); 413 goto Fail; 414 } 415 416 /* we don't trust `maxSizeOfInstructions' in the `maxp' table */ 417 /* and thus update the bytecode array size by ourselves */ 418 419 tmp = load->exec->glyphSize; 420 error = Update_Max( load->exec->memory, 421 &tmp, 422 sizeof ( FT_Byte ), 423 (void*)&load->exec->glyphIns, 424 n_ins ); 425 426 load->exec->glyphSize = (FT_UShort)tmp; 427 if ( error ) 428 return error; 429 430 load->glyph->control_len = n_ins; 431 load->glyph->control_data = load->exec->glyphIns; 432 433 if ( n_ins ) 434 FT_MEM_COPY( load->exec->glyphIns, p, (FT_Long)n_ins ); 435 } 436 437#endif /* TT_USE_BYTECODE_INTERPRETER */ 438 439 p += n_ins; 440 441 outline = &gloader->current.outline; 442 443 /* reading the point tags */ 444 flag = (FT_Byte*)outline->tags; 445 flag_limit = flag + n_points; 446 447 FT_ASSERT( flag ); 448 449 while ( flag < flag_limit ) 450 { 451 if ( p + 1 > limit ) 452 goto Invalid_Outline; 453 454 *flag++ = c = FT_NEXT_BYTE( p ); 455 if ( c & 8 ) 456 { 457 if ( p + 1 > limit ) 458 goto Invalid_Outline; 459 460 count = FT_NEXT_BYTE( p ); 461 if ( flag + (FT_Int)count > flag_limit ) 462 goto Invalid_Outline; 463 464 for ( ; count > 0; count-- ) 465 *flag++ = c; 466 } 467 } 468 469 /* reading the X coordinates */ 470 471 vec = outline->points; 472 vec_limit = vec + n_points; 473 flag = (FT_Byte*)outline->tags; 474 x = 0; 475 476 if ( p + xy_size > limit ) 477 goto Invalid_Outline; 478 479 for ( ; vec < vec_limit; vec++, flag++ ) 480 { 481 FT_Pos y = 0; 482 FT_Byte f = *flag; 483 484 485 if ( f & 2 ) 486 { 487 if ( p + 1 > limit ) 488 goto Invalid_Outline; 489 490 y = (FT_Pos)FT_NEXT_BYTE( p ); 491 if ( ( f & 16 ) == 0 ) 492 y = -y; 493 } 494 else if ( ( f & 16 ) == 0 ) 495 { 496 if ( p + 2 > limit ) 497 goto Invalid_Outline; 498 499 y = (FT_Pos)FT_NEXT_SHORT( p ); 500 } 501 502 x += y; 503 vec->x = x; 504 /* the cast is for stupid compilers */ 505 *flag = (FT_Byte)( f & ~( 2 | 16 ) ); 506 } 507 508 /* reading the Y coordinates */ 509 510 vec = gloader->current.outline.points; 511 vec_limit = vec + n_points; 512 flag = (FT_Byte*)outline->tags; 513 x = 0; 514 515 for ( ; vec < vec_limit; vec++, flag++ ) 516 { 517 FT_Pos y = 0; 518 FT_Byte f = *flag; 519 520 521 if ( f & 4 ) 522 { 523 if ( p + 1 > limit ) 524 goto Invalid_Outline; 525 526 y = (FT_Pos)FT_NEXT_BYTE( p ); 527 if ( ( f & 32 ) == 0 ) 528 y = -y; 529 } 530 else if ( ( f & 32 ) == 0 ) 531 { 532 if ( p + 2 > limit ) 533 goto Invalid_Outline; 534 535 y = (FT_Pos)FT_NEXT_SHORT( p ); 536 } 537 538 x += y; 539 vec->y = x; 540 /* the cast is for stupid compilers */ 541 *flag = (FT_Byte)( f & FT_CURVE_TAG_ON ); 542 } 543 544 outline->n_points = (FT_Short)n_points; 545 outline->n_contours = (FT_Short)n_contours; 546 547 load->cursor = p; 548 549 Fail: 550 return error; 551 552 Invalid_Outline: 553 error = FT_THROW( Invalid_Outline ); 554 goto Fail; 555 } 556 557 558 FT_CALLBACK_DEF( FT_Error ) 559 TT_Load_Composite_Glyph( TT_Loader loader ) 560 { 561 FT_Error error; 562 FT_Byte* p = loader->cursor; 563 FT_Byte* limit = loader->limit; 564 FT_GlyphLoader gloader = loader->gloader; 565 FT_SubGlyph subglyph; 566 FT_UInt num_subglyphs; 567 568 569 num_subglyphs = 0; 570 571 do 572 { 573 FT_Fixed xx, xy, yy, yx; 574 FT_UInt count; 575 576 577 /* check that we can load a new subglyph */ 578 error = FT_GlyphLoader_CheckSubGlyphs( gloader, num_subglyphs + 1 ); 579 if ( error ) 580 goto Fail; 581 582 /* check space */ 583 if ( p + 4 > limit ) 584 goto Invalid_Composite; 585 586 subglyph = gloader->current.subglyphs + num_subglyphs; 587 588 subglyph->arg1 = subglyph->arg2 = 0; 589 590 subglyph->flags = FT_NEXT_USHORT( p ); 591 subglyph->index = FT_NEXT_USHORT( p ); 592 593 /* check space */ 594 count = 2; 595 if ( subglyph->flags & ARGS_ARE_WORDS ) 596 count += 2; 597 if ( subglyph->flags & WE_HAVE_A_SCALE ) 598 count += 2; 599 else if ( subglyph->flags & WE_HAVE_AN_XY_SCALE ) 600 count += 4; 601 else if ( subglyph->flags & WE_HAVE_A_2X2 ) 602 count += 8; 603 604 if ( p + count > limit ) 605 goto Invalid_Composite; 606 607 /* read arguments */ 608 if ( subglyph->flags & ARGS_ARE_XY_VALUES ) 609 { 610 if ( subglyph->flags & ARGS_ARE_WORDS ) 611 { 612 subglyph->arg1 = FT_NEXT_SHORT( p ); 613 subglyph->arg2 = FT_NEXT_SHORT( p ); 614 } 615 else 616 { 617 subglyph->arg1 = FT_NEXT_CHAR( p ); 618 subglyph->arg2 = FT_NEXT_CHAR( p ); 619 } 620 } 621 else 622 { 623 if ( subglyph->flags & ARGS_ARE_WORDS ) 624 { 625 subglyph->arg1 = (FT_Int)FT_NEXT_USHORT( p ); 626 subglyph->arg2 = (FT_Int)FT_NEXT_USHORT( p ); 627 } 628 else 629 { 630 subglyph->arg1 = (FT_Int)FT_NEXT_BYTE( p ); 631 subglyph->arg2 = (FT_Int)FT_NEXT_BYTE( p ); 632 } 633 } 634 635 /* read transform */ 636 xx = yy = 0x10000L; 637 xy = yx = 0; 638 639 if ( subglyph->flags & WE_HAVE_A_SCALE ) 640 { 641 xx = (FT_Fixed)FT_NEXT_SHORT( p ) * 4; 642 yy = xx; 643 } 644 else if ( subglyph->flags & WE_HAVE_AN_XY_SCALE ) 645 { 646 xx = (FT_Fixed)FT_NEXT_SHORT( p ) * 4; 647 yy = (FT_Fixed)FT_NEXT_SHORT( p ) * 4; 648 } 649 else if ( subglyph->flags & WE_HAVE_A_2X2 ) 650 { 651 xx = (FT_Fixed)FT_NEXT_SHORT( p ) * 4; 652 yx = (FT_Fixed)FT_NEXT_SHORT( p ) * 4; 653 xy = (FT_Fixed)FT_NEXT_SHORT( p ) * 4; 654 yy = (FT_Fixed)FT_NEXT_SHORT( p ) * 4; 655 } 656 657 subglyph->transform.xx = xx; 658 subglyph->transform.xy = xy; 659 subglyph->transform.yx = yx; 660 subglyph->transform.yy = yy; 661 662 num_subglyphs++; 663 664 } while ( subglyph->flags & MORE_COMPONENTS ); 665 666 gloader->current.num_subglyphs = num_subglyphs; 667 FT_TRACE5(( " %d components\n", num_subglyphs )); 668 669#ifdef TT_USE_BYTECODE_INTERPRETER 670 671 { 672 FT_Stream stream = loader->stream; 673 674 675 /* we must undo the FT_FRAME_ENTER in order to point */ 676 /* to the composite instructions, if we find some. */ 677 /* We will process them later. */ 678 /* */ 679 loader->ins_pos = (FT_ULong)( FT_STREAM_POS() + 680 p - limit ); 681 } 682 683#endif 684 685 loader->cursor = p; 686 687 Fail: 688 return error; 689 690 Invalid_Composite: 691 error = FT_THROW( Invalid_Composite ); 692 goto Fail; 693 } 694 695 696 FT_LOCAL_DEF( void ) 697 TT_Init_Glyph_Loading( TT_Face face ) 698 { 699 face->access_glyph_frame = TT_Access_Glyph_Frame; 700 face->read_glyph_header = TT_Load_Glyph_Header; 701 face->read_simple_glyph = TT_Load_Simple_Glyph; 702 face->read_composite_glyph = TT_Load_Composite_Glyph; 703 face->forget_glyph_frame = TT_Forget_Glyph_Frame; 704 } 705 706 707 static void 708 tt_prepare_zone( TT_GlyphZone zone, 709 FT_GlyphLoad load, 710 FT_UInt start_point, 711 FT_UInt start_contour ) 712 { 713 zone->n_points = (FT_UShort)load->outline.n_points - 714 (FT_UShort)start_point; 715 zone->n_contours = load->outline.n_contours - 716 (FT_Short)start_contour; 717 zone->org = load->extra_points + start_point; 718 zone->cur = load->outline.points + start_point; 719 zone->orus = load->extra_points2 + start_point; 720 zone->tags = (FT_Byte*)load->outline.tags + start_point; 721 zone->contours = (FT_UShort*)load->outline.contours + start_contour; 722 zone->first_point = (FT_UShort)start_point; 723 } 724 725 726 /*************************************************************************/ 727 /* */ 728 /* <Function> */ 729 /* TT_Hint_Glyph */ 730 /* */ 731 /* <Description> */ 732 /* Hint the glyph using the zone prepared by the caller. Note that */ 733 /* the zone is supposed to include four phantom points. */ 734 /* */ 735 static FT_Error 736 TT_Hint_Glyph( TT_Loader loader, 737 FT_Bool is_composite ) 738 { 739#if defined TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY || \ 740 defined TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL 741 TT_Face face = loader->face; 742 TT_Driver driver = (TT_Driver)FT_FACE_DRIVER( face ); 743#endif 744 745 TT_GlyphZone zone = &loader->zone; 746 747#ifdef TT_USE_BYTECODE_INTERPRETER 748 FT_Long n_ins; 749#else 750 FT_UNUSED( is_composite ); 751#endif 752 753 754#ifdef TT_USE_BYTECODE_INTERPRETER 755 if ( loader->glyph->control_len > 0xFFFFL ) 756 { 757 FT_TRACE1(( "TT_Hint_Glyph: too long instructions" )); 758 FT_TRACE1(( " (0x%lx byte) is truncated\n", 759 loader->glyph->control_len )); 760 } 761 n_ins = loader->glyph->control_len; 762 763 /* save original point position in org */ 764 if ( n_ins > 0 ) 765 FT_ARRAY_COPY( zone->org, zone->cur, zone->n_points ); 766 767 /* Reset graphics state. */ 768 loader->exec->GS = loader->size->GS; 769 770 /* XXX: UNDOCUMENTED! Hinting instructions of a composite glyph */ 771 /* completely refer to the (already) hinted subglyphs. */ 772 if ( is_composite ) 773 { 774 loader->exec->metrics.x_scale = 1 << 16; 775 loader->exec->metrics.y_scale = 1 << 16; 776 777 FT_ARRAY_COPY( zone->orus, zone->cur, zone->n_points ); 778 } 779 else 780 { 781 loader->exec->metrics.x_scale = loader->size->metrics->x_scale; 782 loader->exec->metrics.y_scale = loader->size->metrics->y_scale; 783 } 784#endif 785 786 /* round phantom points */ 787 zone->cur[zone->n_points - 4].x = 788 FT_PIX_ROUND( zone->cur[zone->n_points - 4].x ); 789 zone->cur[zone->n_points - 3].x = 790 FT_PIX_ROUND( zone->cur[zone->n_points - 3].x ); 791 zone->cur[zone->n_points - 2].y = 792 FT_PIX_ROUND( zone->cur[zone->n_points - 2].y ); 793 zone->cur[zone->n_points - 1].y = 794 FT_PIX_ROUND( zone->cur[zone->n_points - 1].y ); 795 796#ifdef TT_USE_BYTECODE_INTERPRETER 797 798 if ( n_ins > 0 ) 799 { 800 FT_Error error; 801 802 FT_GlyphLoader gloader = loader->gloader; 803 FT_Outline current_outline = gloader->current.outline; 804 805 806 TT_Set_CodeRange( loader->exec, tt_coderange_glyph, 807 loader->exec->glyphIns, n_ins ); 808 809 loader->exec->is_composite = is_composite; 810 loader->exec->pts = *zone; 811 812 error = TT_Run_Context( loader->exec ); 813 if ( error && loader->exec->pedantic_hinting ) 814 return error; 815 816 /* store drop-out mode in bits 5-7; set bit 2 also as a marker */ 817 current_outline.tags[0] |= 818 ( loader->exec->GS.scan_type << 5 ) | FT_CURVE_TAG_HAS_SCANMODE; 819 } 820 821#endif 822 823#ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL 824 /* Save possibly modified glyph phantom points unless in v40 backward */ 825 /* compatibility mode, where no movement on the x axis means no reason */ 826 /* to change bearings or advance widths. */ 827 if ( !( driver->interpreter_version == TT_INTERPRETER_VERSION_40 && 828 loader->exec->backward_compatibility ) ) 829 { 830#endif 831 loader->pp1 = zone->cur[zone->n_points - 4]; 832 loader->pp2 = zone->cur[zone->n_points - 3]; 833 loader->pp3 = zone->cur[zone->n_points - 2]; 834 loader->pp4 = zone->cur[zone->n_points - 1]; 835#ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL 836 } 837#endif 838 839#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY 840 if ( driver->interpreter_version == TT_INTERPRETER_VERSION_38 ) 841 { 842 if ( loader->exec->sph_tweak_flags & SPH_TWEAK_DEEMBOLDEN ) 843 FT_Outline_EmboldenXY( &loader->gloader->current.outline, -24, 0 ); 844 845 else if ( loader->exec->sph_tweak_flags & SPH_TWEAK_EMBOLDEN ) 846 FT_Outline_EmboldenXY( &loader->gloader->current.outline, 24, 0 ); 847 } 848#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ 849 850 return FT_Err_Ok; 851 } 852 853 854 /*************************************************************************/ 855 /* */ 856 /* <Function> */ 857 /* TT_Process_Simple_Glyph */ 858 /* */ 859 /* <Description> */ 860 /* Once a simple glyph has been loaded, it needs to be processed. */ 861 /* Usually, this means scaling and hinting through bytecode */ 862 /* interpretation. */ 863 /* */ 864 static FT_Error 865 TT_Process_Simple_Glyph( TT_Loader loader ) 866 { 867 FT_GlyphLoader gloader = loader->gloader; 868 FT_Error error = FT_Err_Ok; 869 FT_Outline* outline; 870 FT_Int n_points; 871 872 873 outline = &gloader->current.outline; 874 n_points = outline->n_points; 875 876 /* set phantom points */ 877 878 outline->points[n_points ] = loader->pp1; 879 outline->points[n_points + 1] = loader->pp2; 880 outline->points[n_points + 2] = loader->pp3; 881 outline->points[n_points + 3] = loader->pp4; 882 883 outline->tags[n_points ] = 0; 884 outline->tags[n_points + 1] = 0; 885 outline->tags[n_points + 2] = 0; 886 outline->tags[n_points + 3] = 0; 887 888 n_points += 4; 889 890#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT 891 892 if ( !loader->face->is_default_instance ) 893 { 894 /* Deltas apply to the unscaled data. */ 895 error = TT_Vary_Apply_Glyph_Deltas( loader->face, 896 loader->glyph_index, 897 outline, 898 (FT_UInt)n_points ); 899 900 /* recalculate linear horizontal and vertical advances */ 901 /* if we don't have HVAR and VVAR, respectively */ 902 if ( !( loader->face->variation_support & TT_FACE_FLAG_VAR_HADVANCE ) ) 903 loader->linear = outline->points[n_points - 3].x - 904 outline->points[n_points - 4].x; 905 if ( !( loader->face->variation_support & TT_FACE_FLAG_VAR_VADVANCE ) ) 906 loader->vadvance = outline->points[n_points - 1].x - 907 outline->points[n_points - 2].x; 908 909 if ( error ) 910 return error; 911 } 912 913#endif /* TT_CONFIG_OPTION_GX_VAR_SUPPORT */ 914 915 if ( IS_HINTED( loader->load_flags ) ) 916 { 917 tt_prepare_zone( &loader->zone, &gloader->current, 0, 0 ); 918 919 FT_ARRAY_COPY( loader->zone.orus, loader->zone.cur, 920 loader->zone.n_points + 4 ); 921 } 922 923 { 924#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY 925 TT_Face face = loader->face; 926 TT_Driver driver = (TT_Driver)FT_FACE_DRIVER( face ); 927 928 FT_String* family = face->root.family_name; 929 FT_UInt ppem = loader->size->metrics->x_ppem; 930 FT_String* style = face->root.style_name; 931 FT_UInt x_scale_factor = 1000; 932#endif 933 934 FT_Vector* vec = outline->points; 935 FT_Vector* limit = outline->points + n_points; 936 937 FT_Fixed x_scale = 0; /* pacify compiler */ 938 FT_Fixed y_scale = 0; 939 940 FT_Bool do_scale = FALSE; 941 942 943#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY 944 945 if ( driver->interpreter_version == TT_INTERPRETER_VERSION_38 ) 946 { 947 /* scale, but only if enabled and only if TT hinting is being used */ 948 if ( IS_HINTED( loader->load_flags ) ) 949 x_scale_factor = sph_test_tweak_x_scaling( face, 950 family, 951 ppem, 952 style, 953 loader->glyph_index ); 954 /* scale the glyph */ 955 if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 || 956 x_scale_factor != 1000 ) 957 { 958 x_scale = FT_MulDiv( loader->size->metrics->x_scale, 959 (FT_Long)x_scale_factor, 1000 ); 960 y_scale = loader->size->metrics->y_scale; 961 962 /* compensate for any scaling by de/emboldening; */ 963 /* the amount was determined via experimentation */ 964 if ( x_scale_factor != 1000 && ppem > 11 ) 965 FT_Outline_EmboldenXY( outline, 966 FT_MulFix( 1280 * ppem, 967 1000 - x_scale_factor ), 968 0 ); 969 do_scale = TRUE; 970 } 971 } 972 else 973 974#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ 975 976 { 977 /* scale the glyph */ 978 if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 ) 979 { 980 x_scale = loader->size->metrics->x_scale; 981 y_scale = loader->size->metrics->y_scale; 982 983 do_scale = TRUE; 984 } 985 } 986 987 if ( do_scale ) 988 { 989 for ( ; vec < limit; vec++ ) 990 { 991 vec->x = FT_MulFix( vec->x, x_scale ); 992 vec->y = FT_MulFix( vec->y, y_scale ); 993 } 994 995 loader->pp1 = outline->points[n_points - 4]; 996 loader->pp2 = outline->points[n_points - 3]; 997 loader->pp3 = outline->points[n_points - 2]; 998 loader->pp4 = outline->points[n_points - 1]; 999 } 1000 } 1001 1002 if ( IS_HINTED( loader->load_flags ) ) 1003 { 1004 loader->zone.n_points += 4; 1005 1006 error = TT_Hint_Glyph( loader, 0 ); 1007 } 1008 1009 return error; 1010 } 1011 1012 1013 /*************************************************************************/ 1014 /* */ 1015 /* <Function> */ 1016 /* TT_Process_Composite_Component */ 1017 /* */ 1018 /* <Description> */ 1019 /* Once a composite component has been loaded, it needs to be */ 1020 /* processed. Usually, this means transforming and translating. */ 1021 /* */ 1022 static FT_Error 1023 TT_Process_Composite_Component( TT_Loader loader, 1024 FT_SubGlyph subglyph, 1025 FT_UInt start_point, 1026 FT_UInt num_base_points ) 1027 { 1028 FT_GlyphLoader gloader = loader->gloader; 1029 FT_Outline current; 1030 FT_Bool have_scale; 1031 FT_Pos x, y; 1032 1033 1034 current.points = gloader->base.outline.points + 1035 num_base_points; 1036 current.n_points = gloader->base.outline.n_points - 1037 (short)num_base_points; 1038 1039 have_scale = FT_BOOL( subglyph->flags & ( WE_HAVE_A_SCALE | 1040 WE_HAVE_AN_XY_SCALE | 1041 WE_HAVE_A_2X2 ) ); 1042 1043 /* perform the transform required for this subglyph */ 1044 if ( have_scale ) 1045 FT_Outline_Transform( ¤t, &subglyph->transform ); 1046 1047 /* get offset */ 1048 if ( !( subglyph->flags & ARGS_ARE_XY_VALUES ) ) 1049 { 1050 FT_UInt num_points = (FT_UInt)gloader->base.outline.n_points; 1051 FT_UInt k = (FT_UInt)subglyph->arg1; 1052 FT_UInt l = (FT_UInt)subglyph->arg2; 1053 FT_Vector* p1; 1054 FT_Vector* p2; 1055 1056 1057 /* match l-th point of the newly loaded component to the k-th point */ 1058 /* of the previously loaded components. */ 1059 1060 /* change to the point numbers used by our outline */ 1061 k += start_point; 1062 l += num_base_points; 1063 if ( k >= num_base_points || 1064 l >= num_points ) 1065 return FT_THROW( Invalid_Composite ); 1066 1067 p1 = gloader->base.outline.points + k; 1068 p2 = gloader->base.outline.points + l; 1069 1070 x = p1->x - p2->x; 1071 y = p1->y - p2->y; 1072 } 1073 else 1074 { 1075 x = subglyph->arg1; 1076 y = subglyph->arg2; 1077 1078 if ( !x && !y ) 1079 return FT_Err_Ok; 1080 1081 /* Use a default value dependent on */ 1082 /* TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED. This is useful for old */ 1083 /* TT fonts which don't set the xxx_COMPONENT_OFFSET bit. */ 1084 1085 if ( have_scale && 1086#ifdef TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED 1087 !( subglyph->flags & UNSCALED_COMPONENT_OFFSET ) ) 1088#else 1089 ( subglyph->flags & SCALED_COMPONENT_OFFSET ) ) 1090#endif 1091 { 1092 1093#if 0 1094 1095 /*******************************************************************/ 1096 /* */ 1097 /* This algorithm is what Apple documents. But it doesn't work. */ 1098 /* */ 1099 int a = subglyph->transform.xx > 0 ? subglyph->transform.xx 1100 : -subglyph->transform.xx; 1101 int b = subglyph->transform.yx > 0 ? subglyph->transform.yx 1102 : -subglyph->transform.yx; 1103 int c = subglyph->transform.xy > 0 ? subglyph->transform.xy 1104 : -subglyph->transform.xy; 1105 int d = subglyph->transform.yy > 0 ? subglyph->transform.yy 1106 : -subglyph->transform.yy; 1107 int m = a > b ? a : b; 1108 int n = c > d ? c : d; 1109 1110 1111 if ( a - b <= 33 && a - b >= -33 ) 1112 m *= 2; 1113 if ( c - d <= 33 && c - d >= -33 ) 1114 n *= 2; 1115 x = FT_MulFix( x, m ); 1116 y = FT_MulFix( y, n ); 1117 1118#else /* 1 */ 1119 1120 /*******************************************************************/ 1121 /* */ 1122 /* This algorithm is a guess and works much better than the above. */ 1123 /* */ 1124 FT_Fixed mac_xscale = FT_Hypot( subglyph->transform.xx, 1125 subglyph->transform.xy ); 1126 FT_Fixed mac_yscale = FT_Hypot( subglyph->transform.yy, 1127 subglyph->transform.yx ); 1128 1129 1130 x = FT_MulFix( x, mac_xscale ); 1131 y = FT_MulFix( y, mac_yscale ); 1132 1133#endif /* 1 */ 1134 1135 } 1136 1137 if ( !( loader->load_flags & FT_LOAD_NO_SCALE ) ) 1138 { 1139 FT_Fixed x_scale = loader->size->metrics->x_scale; 1140 FT_Fixed y_scale = loader->size->metrics->y_scale; 1141 1142 1143 x = FT_MulFix( x, x_scale ); 1144 y = FT_MulFix( y, y_scale ); 1145 1146 if ( subglyph->flags & ROUND_XY_TO_GRID ) 1147 { 1148 x = FT_PIX_ROUND( x ); 1149 y = FT_PIX_ROUND( y ); 1150 } 1151 } 1152 } 1153 1154 if ( x || y ) 1155 FT_Outline_Translate( ¤t, x, y ); 1156 1157 return FT_Err_Ok; 1158 } 1159 1160 1161 /*************************************************************************/ 1162 /* */ 1163 /* <Function> */ 1164 /* TT_Process_Composite_Glyph */ 1165 /* */ 1166 /* <Description> */ 1167 /* This is slightly different from TT_Process_Simple_Glyph, in that */ 1168 /* its sole purpose is to hint the glyph. Thus this function is */ 1169 /* only available when bytecode interpreter is enabled. */ 1170 /* */ 1171 static FT_Error 1172 TT_Process_Composite_Glyph( TT_Loader loader, 1173 FT_UInt start_point, 1174 FT_UInt start_contour ) 1175 { 1176 FT_Error error; 1177 FT_Outline* outline; 1178 FT_UInt i; 1179 1180 1181 outline = &loader->gloader->base.outline; 1182 1183 /* make room for phantom points */ 1184 error = FT_GLYPHLOADER_CHECK_POINTS( loader->gloader, 1185 outline->n_points + 4, 1186 0 ); 1187 if ( error ) 1188 return error; 1189 1190 outline->points[outline->n_points ] = loader->pp1; 1191 outline->points[outline->n_points + 1] = loader->pp2; 1192 outline->points[outline->n_points + 2] = loader->pp3; 1193 outline->points[outline->n_points + 3] = loader->pp4; 1194 1195 outline->tags[outline->n_points ] = 0; 1196 outline->tags[outline->n_points + 1] = 0; 1197 outline->tags[outline->n_points + 2] = 0; 1198 outline->tags[outline->n_points + 3] = 0; 1199 1200#ifdef TT_USE_BYTECODE_INTERPRETER 1201 1202 { 1203 FT_Stream stream = loader->stream; 1204 FT_UShort n_ins, max_ins; 1205 FT_ULong tmp; 1206 1207 1208 /* TT_Load_Composite_Glyph only gives us the offset of instructions */ 1209 /* so we read them here */ 1210 if ( FT_STREAM_SEEK( loader->ins_pos ) || 1211 FT_READ_USHORT( n_ins ) ) 1212 return error; 1213 1214 FT_TRACE5(( " Instructions size = %d\n", n_ins )); 1215 1216 /* check it */ 1217 max_ins = loader->face->max_profile.maxSizeOfInstructions; 1218 if ( n_ins > max_ins ) 1219 { 1220 /* don't trust `maxSizeOfInstructions'; */ 1221 /* only do a rough safety check */ 1222 if ( (FT_Int)n_ins > loader->byte_len ) 1223 { 1224 FT_TRACE1(( "TT_Process_Composite_Glyph:" 1225 " too many instructions (%d) for glyph with length %d\n", 1226 n_ins, loader->byte_len )); 1227 return FT_THROW( Too_Many_Hints ); 1228 } 1229 1230 tmp = loader->exec->glyphSize; 1231 error = Update_Max( loader->exec->memory, 1232 &tmp, 1233 sizeof ( FT_Byte ), 1234 (void*)&loader->exec->glyphIns, 1235 n_ins ); 1236 1237 loader->exec->glyphSize = (FT_UShort)tmp; 1238 if ( error ) 1239 return error; 1240 } 1241 else if ( n_ins == 0 ) 1242 return FT_Err_Ok; 1243 1244 if ( FT_STREAM_READ( loader->exec->glyphIns, n_ins ) ) 1245 return error; 1246 1247 loader->glyph->control_data = loader->exec->glyphIns; 1248 loader->glyph->control_len = n_ins; 1249 } 1250 1251#endif 1252 1253 tt_prepare_zone( &loader->zone, &loader->gloader->base, 1254 start_point, start_contour ); 1255 1256 /* Some points are likely touched during execution of */ 1257 /* instructions on components. So let's untouch them. */ 1258 for ( i = 0; i < loader->zone.n_points; i++ ) 1259 loader->zone.tags[i] &= ~FT_CURVE_TAG_TOUCH_BOTH; 1260 1261 loader->zone.n_points += 4; 1262 1263 return TT_Hint_Glyph( loader, 1 ); 1264 } 1265 1266 1267 /* 1268 * Calculate the phantom points 1269 * 1270 * Defining the right side bearing (rsb) as 1271 * 1272 * rsb = aw - (lsb + xmax - xmin) 1273 * 1274 * (with `aw' the advance width, `lsb' the left side bearing, and `xmin' 1275 * and `xmax' the glyph's minimum and maximum x value), the OpenType 1276 * specification defines the initial position of horizontal phantom points 1277 * as 1278 * 1279 * pp1 = (round(xmin - lsb), 0) , 1280 * pp2 = (round(pp1 + aw), 0) . 1281 * 1282 * Note that the rounding to the grid (in the device space) is not 1283 * documented currently in the specification. 1284 * 1285 * However, the specification lacks the precise definition of vertical 1286 * phantom points. Greg Hitchcock provided the following explanation. 1287 * 1288 * - a `vmtx' table is present 1289 * 1290 * For any glyph, the minimum and maximum y values (`ymin' and `ymax') 1291 * are given in the `glyf' table, the top side bearing (tsb) and advance 1292 * height (ah) are given in the `vmtx' table. The bottom side bearing 1293 * (bsb) is then calculated as 1294 * 1295 * bsb = ah - (tsb + ymax - ymin) , 1296 * 1297 * and the initial position of vertical phantom points is 1298 * 1299 * pp3 = (x, round(ymax + tsb)) , 1300 * pp4 = (x, round(pp3 - ah)) . 1301 * 1302 * See below for value `x'. 1303 * 1304 * - no `vmtx' table in the font 1305 * 1306 * If there is an `OS/2' table, we set 1307 * 1308 * DefaultAscender = sTypoAscender , 1309 * DefaultDescender = sTypoDescender , 1310 * 1311 * otherwise we use data from the `hhea' table: 1312 * 1313 * DefaultAscender = Ascender , 1314 * DefaultDescender = Descender . 1315 * 1316 * With these two variables we can now set 1317 * 1318 * ah = DefaultAscender - sDefaultDescender , 1319 * tsb = DefaultAscender - yMax , 1320 * 1321 * and proceed as if a `vmtx' table was present. 1322 * 1323 * Usually we have 1324 * 1325 * x = aw / 2 , (1) 1326 * 1327 * but there is one compatibility case where it can be set to 1328 * 1329 * x = -DefaultDescender - 1330 * ((DefaultAscender - DefaultDescender - aw) / 2) . (2) 1331 * 1332 * and another one with 1333 * 1334 * x = 0 . (3) 1335 * 1336 * In Windows, the history of those values is quite complicated, 1337 * depending on the hinting engine (that is, the graphics framework). 1338 * 1339 * framework from to formula 1340 * ---------------------------------------------------------- 1341 * GDI Windows 98 current (1) 1342 * (Windows 2000 for NT) 1343 * GDI+ Windows XP Windows 7 (2) 1344 * GDI+ Windows 8 current (3) 1345 * DWrite Windows 7 current (3) 1346 * 1347 * For simplicity, FreeType uses (1) for grayscale subpixel hinting and 1348 * (3) for everything else. 1349 * 1350 */ 1351 static void 1352 tt_loader_set_pp( TT_Loader loader ) 1353 { 1354 FT_Bool subpixel_hinting = 0; 1355 FT_Bool grayscale = 0; 1356 FT_Bool use_aw_2 = 0; 1357 1358#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING 1359 TT_Driver driver = (TT_Driver)FT_FACE_DRIVER( loader->face ); 1360#endif 1361 1362#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY 1363 if ( driver->interpreter_version == TT_INTERPRETER_VERSION_38 ) 1364 { 1365 subpixel_hinting = loader->exec ? loader->exec->subpixel_hinting 1366 : 0; 1367 grayscale = loader->exec ? loader->exec->grayscale 1368 : 0; 1369 } 1370#endif 1371#ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL 1372 if ( driver->interpreter_version == TT_INTERPRETER_VERSION_40 ) 1373 { 1374 subpixel_hinting = loader->exec ? loader->exec->subpixel_hinting_lean 1375 : 0; 1376 grayscale = loader->exec ? loader->exec->grayscale_cleartype 1377 : 0; 1378 } 1379#endif 1380 1381 use_aw_2 = (FT_Bool)( subpixel_hinting && grayscale ); 1382 1383 loader->pp1.x = loader->bbox.xMin - loader->left_bearing; 1384 loader->pp1.y = 0; 1385 loader->pp2.x = loader->pp1.x + loader->advance; 1386 loader->pp2.y = 0; 1387 1388 loader->pp3.x = use_aw_2 ? loader->advance / 2 : 0; 1389 loader->pp3.y = loader->bbox.yMax + loader->top_bearing; 1390 loader->pp4.x = use_aw_2 ? loader->advance / 2 : 0; 1391 loader->pp4.y = loader->pp3.y - loader->vadvance; 1392 } 1393 1394 1395 /* a utility function to retrieve i-th node from given FT_List */ 1396 static FT_ListNode 1397 ft_list_get_node_at( FT_List list, 1398 FT_UInt idx ) 1399 { 1400 FT_ListNode cur; 1401 1402 1403 if ( !list ) 1404 return NULL; 1405 1406 for ( cur = list->head; cur; cur = cur->next ) 1407 { 1408 if ( !idx ) 1409 return cur; 1410 1411 idx--; 1412 } 1413 1414 return NULL; 1415 } 1416 1417 1418 /*************************************************************************/ 1419 /* */ 1420 /* <Function> */ 1421 /* load_truetype_glyph */ 1422 /* */ 1423 /* <Description> */ 1424 /* Loads a given truetype glyph. Handles composites and uses a */ 1425 /* TT_Loader object. */ 1426 /* */ 1427 static FT_Error 1428 load_truetype_glyph( TT_Loader loader, 1429 FT_UInt glyph_index, 1430 FT_UInt recurse_count, 1431 FT_Bool header_only ) 1432 { 1433 FT_Error error = FT_Err_Ok; 1434 FT_Fixed x_scale, y_scale; 1435 FT_ULong offset; 1436 TT_Face face = loader->face; 1437 FT_GlyphLoader gloader = loader->gloader; 1438 FT_Bool opened_frame = 0; 1439 1440#ifdef FT_CONFIG_OPTION_INCREMENTAL 1441 FT_StreamRec inc_stream; 1442 FT_Data glyph_data; 1443 FT_Bool glyph_data_loaded = 0; 1444#endif 1445 1446 1447#ifdef FT_DEBUG_LEVEL_TRACE 1448 if ( recurse_count ) 1449 FT_TRACE5(( " nesting level: %d\n", recurse_count )); 1450#endif 1451 1452 /* some fonts have an incorrect value of `maxComponentDepth' */ 1453 if ( recurse_count > face->max_profile.maxComponentDepth ) 1454 { 1455 FT_TRACE1(( "load_truetype_glyph: maxComponentDepth set to %d\n", 1456 recurse_count )); 1457 face->max_profile.maxComponentDepth = (FT_UShort)recurse_count; 1458 } 1459 1460#ifndef FT_CONFIG_OPTION_INCREMENTAL 1461 /* check glyph index */ 1462 if ( glyph_index >= (FT_UInt)face->root.num_glyphs ) 1463 { 1464 error = FT_THROW( Invalid_Glyph_Index ); 1465 goto Exit; 1466 } 1467#endif 1468 1469 loader->glyph_index = glyph_index; 1470 1471 if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 ) 1472 { 1473 x_scale = loader->size->metrics->x_scale; 1474 y_scale = loader->size->metrics->y_scale; 1475 } 1476 else 1477 { 1478 x_scale = 0x10000L; 1479 y_scale = 0x10000L; 1480 } 1481 1482 /* Set `offset' to the start of the glyph relative to the start of */ 1483 /* the `glyf' table, and `byte_len' to the length of the glyph in */ 1484 /* bytes. */ 1485 1486#ifdef FT_CONFIG_OPTION_INCREMENTAL 1487 1488 /* If we are loading glyph data via the incremental interface, set */ 1489 /* the loader stream to a memory stream reading the data returned */ 1490 /* by the interface. */ 1491 if ( face->root.internal->incremental_interface ) 1492 { 1493 error = face->root.internal->incremental_interface->funcs->get_glyph_data( 1494 face->root.internal->incremental_interface->object, 1495 glyph_index, &glyph_data ); 1496 if ( error ) 1497 goto Exit; 1498 1499 glyph_data_loaded = 1; 1500 offset = 0; 1501 loader->byte_len = glyph_data.length; 1502 1503 FT_ZERO( &inc_stream ); 1504 FT_Stream_OpenMemory( &inc_stream, 1505 glyph_data.pointer, 1506 (FT_ULong)glyph_data.length ); 1507 1508 loader->stream = &inc_stream; 1509 } 1510 else 1511 1512#endif /* FT_CONFIG_OPTION_INCREMENTAL */ 1513 1514 offset = tt_face_get_location( face, glyph_index, 1515 (FT_UInt*)&loader->byte_len ); 1516 1517 if ( loader->byte_len > 0 ) 1518 { 1519#ifdef FT_CONFIG_OPTION_INCREMENTAL 1520 /* for the incremental interface, `glyf_offset' is always zero */ 1521 if ( !face->glyf_offset && 1522 !face->root.internal->incremental_interface ) 1523#else 1524 if ( !face->glyf_offset ) 1525#endif /* FT_CONFIG_OPTION_INCREMENTAL */ 1526 { 1527 FT_TRACE2(( "no `glyf' table but non-zero `loca' entry\n" )); 1528 error = FT_THROW( Invalid_Table ); 1529 goto Exit; 1530 } 1531 1532 error = face->access_glyph_frame( loader, glyph_index, 1533 face->glyf_offset + offset, 1534 (FT_UInt)loader->byte_len ); 1535 if ( error ) 1536 goto Exit; 1537 1538 opened_frame = 1; 1539 1540 /* read glyph header first */ 1541 error = face->read_glyph_header( loader ); 1542 if ( error ) 1543 goto Exit; 1544 1545 /* the metrics must be computed after loading the glyph header */ 1546 /* since we need the glyph's `yMax' value in case the vertical */ 1547 /* metrics must be emulated */ 1548 error = tt_get_metrics( loader, glyph_index ); 1549 if ( error ) 1550 goto Exit; 1551 1552 if ( header_only ) 1553 goto Exit; 1554 } 1555 1556 if ( loader->byte_len == 0 || loader->n_contours == 0 ) 1557 { 1558 loader->bbox.xMin = 0; 1559 loader->bbox.xMax = 0; 1560 loader->bbox.yMin = 0; 1561 loader->bbox.yMax = 0; 1562 1563 error = tt_get_metrics( loader, glyph_index ); 1564 if ( error ) 1565 goto Exit; 1566 1567 if ( header_only ) 1568 goto Exit; 1569 1570 /* must initialize points before (possibly) overriding */ 1571 /* glyph metrics from the incremental interface */ 1572 tt_loader_set_pp( loader ); 1573 1574#ifdef FT_CONFIG_OPTION_INCREMENTAL 1575 tt_get_metrics_incr_overrides( loader, glyph_index ); 1576#endif 1577 1578#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT 1579 1580 if ( !loader->face->is_default_instance ) 1581 { 1582 /* a small outline structure with four elements for */ 1583 /* communication with `TT_Vary_Apply_Glyph_Deltas' */ 1584 FT_Vector points[4]; 1585 char tags[4] = { 1, 1, 1, 1 }; 1586 short contours[4] = { 0, 1, 2, 3 }; 1587 FT_Outline outline; 1588 1589 1590 points[0].x = loader->pp1.x; 1591 points[0].y = loader->pp1.y; 1592 points[1].x = loader->pp2.x; 1593 points[1].y = loader->pp2.y; 1594 1595 points[2].x = loader->pp3.x; 1596 points[2].y = loader->pp3.y; 1597 points[3].x = loader->pp4.x; 1598 points[3].y = loader->pp4.y; 1599 1600 outline.n_points = 4; 1601 outline.n_contours = 4; 1602 outline.points = points; 1603 outline.tags = tags; 1604 outline.contours = contours; 1605 1606 /* this must be done before scaling */ 1607 error = TT_Vary_Apply_Glyph_Deltas( loader->face, 1608 glyph_index, 1609 &outline, 1610 (FT_UInt)outline.n_points ); 1611 if ( error ) 1612 goto Exit; 1613 1614 loader->pp1.x = points[0].x; 1615 loader->pp1.y = points[0].y; 1616 loader->pp2.x = points[1].x; 1617 loader->pp2.y = points[1].y; 1618 1619 loader->pp3.x = points[2].x; 1620 loader->pp3.y = points[2].y; 1621 loader->pp4.x = points[3].x; 1622 loader->pp4.y = points[3].y; 1623 1624 1625 /* recalculate linear horizontal and vertical advances */ 1626 /* if we don't have HVAR and VVAR, respectively */ 1627 if ( !( loader->face->variation_support & TT_FACE_FLAG_VAR_HADVANCE ) ) 1628 loader->linear = loader->pp2.x - loader->pp1.x; 1629 if ( !( loader->face->variation_support & TT_FACE_FLAG_VAR_VADVANCE ) ) 1630 loader->vadvance = loader->pp4.x - loader->pp3.x; 1631 } 1632 1633#endif /* TT_CONFIG_OPTION_GX_VAR_SUPPORT */ 1634 1635 /* scale phantom points, if necessary; */ 1636 /* they get rounded in `TT_Hint_Glyph' */ 1637 if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 ) 1638 { 1639 loader->pp1.x = FT_MulFix( loader->pp1.x, x_scale ); 1640 loader->pp2.x = FT_MulFix( loader->pp2.x, x_scale ); 1641 /* pp1.y and pp2.y are always zero */ 1642 1643 loader->pp3.x = FT_MulFix( loader->pp3.x, x_scale ); 1644 loader->pp3.y = FT_MulFix( loader->pp3.y, y_scale ); 1645 loader->pp4.x = FT_MulFix( loader->pp4.x, x_scale ); 1646 loader->pp4.y = FT_MulFix( loader->pp4.y, y_scale ); 1647 } 1648 1649 error = FT_Err_Ok; 1650 goto Exit; 1651 } 1652 1653 /* must initialize phantom points before (possibly) overriding */ 1654 /* glyph metrics from the incremental interface */ 1655 tt_loader_set_pp( loader ); 1656 1657#ifdef FT_CONFIG_OPTION_INCREMENTAL 1658 tt_get_metrics_incr_overrides( loader, glyph_index ); 1659#endif 1660 1661 /***********************************************************************/ 1662 /***********************************************************************/ 1663 /***********************************************************************/ 1664 1665 /* if it is a simple glyph, load it */ 1666 1667 if ( loader->n_contours > 0 ) 1668 { 1669 error = face->read_simple_glyph( loader ); 1670 if ( error ) 1671 goto Exit; 1672 1673 /* all data have been read */ 1674 face->forget_glyph_frame( loader ); 1675 opened_frame = 0; 1676 1677 error = TT_Process_Simple_Glyph( loader ); 1678 if ( error ) 1679 goto Exit; 1680 1681 FT_GlyphLoader_Add( gloader ); 1682 } 1683 1684 /***********************************************************************/ 1685 /***********************************************************************/ 1686 /***********************************************************************/ 1687 1688 /* otherwise, load a composite! */ 1689 else if ( loader->n_contours < 0 ) 1690 { 1691 FT_Memory memory = face->root.memory; 1692 1693 FT_UInt start_point; 1694 FT_UInt start_contour; 1695 FT_ULong ins_pos; /* position of composite instructions, if any */ 1696 1697 FT_ListNode node, node2; 1698 1699 1700 /* normalize the `n_contours' value */ 1701 loader->n_contours = -1; 1702 1703 /* 1704 * We store the glyph index directly in the `node->data' pointer, 1705 * following the glib solution (cf. macro `GUINT_TO_POINTER') with a 1706 * double cast to make this portable. Note, however, that this needs 1707 * pointers with a width of at least 32 bits. 1708 */ 1709 1710 1711 /* clear the nodes filled by sibling chains */ 1712 node = ft_list_get_node_at( &loader->composites, recurse_count ); 1713 for ( node2 = node; node2; node2 = node2->next ) 1714 node2->data = (void*)ULONG_MAX; 1715 1716 /* check whether we already have a composite glyph with this index */ 1717 if ( FT_List_Find( &loader->composites, 1718 FT_UINT_TO_POINTER( glyph_index ) ) ) 1719 { 1720 FT_TRACE1(( "TT_Load_Composite_Glyph:" 1721 " infinite recursion detected\n" )); 1722 error = FT_THROW( Invalid_Composite ); 1723 goto Exit; 1724 } 1725 1726 else if ( node ) 1727 node->data = FT_UINT_TO_POINTER( glyph_index ); 1728 1729 else 1730 { 1731 if ( FT_NEW( node ) ) 1732 goto Exit; 1733 node->data = FT_UINT_TO_POINTER( glyph_index ); 1734 FT_List_Add( &loader->composites, node ); 1735 } 1736 1737 start_point = (FT_UInt)gloader->base.outline.n_points; 1738 start_contour = (FT_UInt)gloader->base.outline.n_contours; 1739 1740 /* for each subglyph, read composite header */ 1741 error = face->read_composite_glyph( loader ); 1742 if ( error ) 1743 goto Exit; 1744 1745 /* store the offset of instructions */ 1746 ins_pos = loader->ins_pos; 1747 1748 /* all data we need are read */ 1749 face->forget_glyph_frame( loader ); 1750 opened_frame = 0; 1751 1752#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT 1753 1754 if ( !face->is_default_instance ) 1755 { 1756 short i, limit; 1757 FT_SubGlyph subglyph; 1758 1759 FT_Outline outline; 1760 FT_Vector* points = NULL; 1761 char* tags = NULL; 1762 short* contours = NULL; 1763 1764 1765 limit = (short)gloader->current.num_subglyphs; 1766 1767 /* construct an outline structure for */ 1768 /* communication with `TT_Vary_Apply_Glyph_Deltas' */ 1769 outline.n_points = (short)( gloader->current.num_subglyphs + 4 ); 1770 outline.n_contours = outline.n_points; 1771 1772 outline.points = NULL; 1773 outline.tags = NULL; 1774 outline.contours = NULL; 1775 1776 if ( FT_NEW_ARRAY( points, outline.n_points ) || 1777 FT_NEW_ARRAY( tags, outline.n_points ) || 1778 FT_NEW_ARRAY( contours, outline.n_points ) ) 1779 goto Exit1; 1780 1781 subglyph = gloader->current.subglyphs; 1782 1783 for ( i = 0; i < limit; i++, subglyph++ ) 1784 { 1785 /* applying deltas for anchor points doesn't make sense, */ 1786 /* but we don't have to specially check this since */ 1787 /* unused delta values are zero anyways */ 1788 points[i].x = subglyph->arg1; 1789 points[i].y = subglyph->arg2; 1790 tags[i] = 1; 1791 contours[i] = i; 1792 } 1793 1794 points[i].x = loader->pp1.x; 1795 points[i].y = loader->pp1.y; 1796 tags[i] = 1; 1797 contours[i] = i; 1798 1799 i++; 1800 points[i].x = loader->pp2.x; 1801 points[i].y = loader->pp2.y; 1802 tags[i] = 1; 1803 contours[i] = i; 1804 1805 i++; 1806 points[i].x = loader->pp3.x; 1807 points[i].y = loader->pp3.y; 1808 tags[i] = 1; 1809 contours[i] = i; 1810 1811 i++; 1812 points[i].x = loader->pp4.x; 1813 points[i].y = loader->pp4.y; 1814 tags[i] = 1; 1815 contours[i] = i; 1816 1817 outline.points = points; 1818 outline.tags = tags; 1819 outline.contours = contours; 1820 1821 /* this call provides additional offsets */ 1822 /* for each component's translation */ 1823 if ( FT_SET_ERROR( TT_Vary_Apply_Glyph_Deltas( 1824 face, 1825 glyph_index, 1826 &outline, 1827 (FT_UInt)outline.n_points ) ) ) 1828 goto Exit1; 1829 1830 subglyph = gloader->current.subglyphs; 1831 1832 for ( i = 0; i < limit; i++, subglyph++ ) 1833 { 1834 if ( subglyph->flags & ARGS_ARE_XY_VALUES ) 1835 { 1836 subglyph->arg1 = (FT_Int16)points[i].x; 1837 subglyph->arg2 = (FT_Int16)points[i].y; 1838 } 1839 } 1840 1841 loader->pp1.x = points[i + 0].x; 1842 loader->pp1.y = points[i + 0].y; 1843 loader->pp2.x = points[i + 1].x; 1844 loader->pp2.y = points[i + 1].y; 1845 1846 loader->pp3.x = points[i + 2].x; 1847 loader->pp3.y = points[i + 2].y; 1848 loader->pp4.x = points[i + 3].x; 1849 loader->pp4.y = points[i + 3].y; 1850 1851 /* recalculate linear horizontal and vertical advances */ 1852 /* if we don't have HVAR and VVAR, respectively */ 1853 if ( !( face->variation_support & TT_FACE_FLAG_VAR_HADVANCE ) ) 1854 loader->linear = loader->pp2.x - loader->pp1.x; 1855 if ( !( face->variation_support & TT_FACE_FLAG_VAR_VADVANCE ) ) 1856 loader->vadvance = loader->pp4.x - loader->pp3.x; 1857 1858 Exit1: 1859 FT_FREE( outline.points ); 1860 FT_FREE( outline.tags ); 1861 FT_FREE( outline.contours ); 1862 1863 if ( error ) 1864 goto Exit; 1865 } 1866 1867#endif /* TT_CONFIG_OPTION_GX_VAR_SUPPORT */ 1868 1869 /* scale phantom points, if necessary; */ 1870 /* they get rounded in `TT_Hint_Glyph' */ 1871 if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 ) 1872 { 1873 loader->pp1.x = FT_MulFix( loader->pp1.x, x_scale ); 1874 loader->pp2.x = FT_MulFix( loader->pp2.x, x_scale ); 1875 /* pp1.y and pp2.y are always zero */ 1876 1877 loader->pp3.x = FT_MulFix( loader->pp3.x, x_scale ); 1878 loader->pp3.y = FT_MulFix( loader->pp3.y, y_scale ); 1879 loader->pp4.x = FT_MulFix( loader->pp4.x, x_scale ); 1880 loader->pp4.y = FT_MulFix( loader->pp4.y, y_scale ); 1881 } 1882 1883 /* if the flag FT_LOAD_NO_RECURSE is set, we return the subglyph */ 1884 /* `as is' in the glyph slot (the client application will be */ 1885 /* responsible for interpreting these data)... */ 1886 if ( loader->load_flags & FT_LOAD_NO_RECURSE ) 1887 { 1888 FT_GlyphLoader_Add( gloader ); 1889 loader->glyph->format = FT_GLYPH_FORMAT_COMPOSITE; 1890 1891 goto Exit; 1892 } 1893 1894 /*********************************************************************/ 1895 /*********************************************************************/ 1896 /*********************************************************************/ 1897 1898 { 1899 FT_UInt n, num_base_points; 1900 FT_SubGlyph subglyph = NULL; 1901 1902 FT_UInt num_points = start_point; 1903 FT_UInt num_subglyphs = gloader->current.num_subglyphs; 1904 FT_UInt num_base_subgs = gloader->base.num_subglyphs; 1905 1906 FT_Stream old_stream = loader->stream; 1907 FT_Int old_byte_len = loader->byte_len; 1908 1909 1910 FT_GlyphLoader_Add( gloader ); 1911 1912 /* read each subglyph independently */ 1913 for ( n = 0; n < num_subglyphs; n++ ) 1914 { 1915 FT_Vector pp[4]; 1916 1917 FT_Int linear_hadvance; 1918 FT_Int linear_vadvance; 1919 1920 1921 /* Each time we call load_truetype_glyph in this loop, the */ 1922 /* value of `gloader.base.subglyphs' can change due to table */ 1923 /* reallocations. We thus need to recompute the subglyph */ 1924 /* pointer on each iteration. */ 1925 subglyph = gloader->base.subglyphs + num_base_subgs + n; 1926 1927 pp[0] = loader->pp1; 1928 pp[1] = loader->pp2; 1929 pp[2] = loader->pp3; 1930 pp[3] = loader->pp4; 1931 1932 linear_hadvance = loader->linear; 1933 linear_vadvance = loader->vadvance; 1934 1935 num_base_points = (FT_UInt)gloader->base.outline.n_points; 1936 1937 error = load_truetype_glyph( loader, 1938 (FT_UInt)subglyph->index, 1939 recurse_count + 1, 1940 FALSE ); 1941 if ( error ) 1942 goto Exit; 1943 1944 /* restore subglyph pointer */ 1945 subglyph = gloader->base.subglyphs + num_base_subgs + n; 1946 1947 /* restore phantom points if necessary */ 1948 if ( !( subglyph->flags & USE_MY_METRICS ) ) 1949 { 1950 loader->pp1 = pp[0]; 1951 loader->pp2 = pp[1]; 1952 loader->pp3 = pp[2]; 1953 loader->pp4 = pp[3]; 1954 1955 loader->linear = linear_hadvance; 1956 loader->vadvance = linear_vadvance; 1957 } 1958 1959 num_points = (FT_UInt)gloader->base.outline.n_points; 1960 1961 if ( num_points == num_base_points ) 1962 continue; 1963 1964 /* gloader->base.outline consists of three parts: */ 1965 /* 0 -(1)-> start_point -(2)-> num_base_points -(3)-> n_points. */ 1966 /* */ 1967 /* (1): exists from the beginning */ 1968 /* (2): components that have been loaded so far */ 1969 /* (3): the newly loaded component */ 1970 error = TT_Process_Composite_Component( loader, 1971 subglyph, 1972 start_point, 1973 num_base_points ); 1974 if ( error ) 1975 goto Exit; 1976 } 1977 1978 loader->stream = old_stream; 1979 loader->byte_len = old_byte_len; 1980 1981 /* process the glyph */ 1982 loader->ins_pos = ins_pos; 1983 if ( IS_HINTED( loader->load_flags ) && 1984#ifdef TT_USE_BYTECODE_INTERPRETER 1985 subglyph->flags & WE_HAVE_INSTR && 1986#endif 1987 num_points > start_point ) 1988 { 1989 error = TT_Process_Composite_Glyph( loader, 1990 start_point, 1991 start_contour ); 1992 if ( error ) 1993 goto Exit; 1994 } 1995 } 1996 } 1997 1998 /***********************************************************************/ 1999 /***********************************************************************/ 2000 /***********************************************************************/ 2001 2002 Exit: 2003 2004 if ( opened_frame ) 2005 face->forget_glyph_frame( loader ); 2006 2007#ifdef FT_CONFIG_OPTION_INCREMENTAL 2008 2009 if ( glyph_data_loaded ) 2010 face->root.internal->incremental_interface->funcs->free_glyph_data( 2011 face->root.internal->incremental_interface->object, 2012 &glyph_data ); 2013 2014#endif 2015 2016 return error; 2017 } 2018 2019 2020 static FT_Error 2021 compute_glyph_metrics( TT_Loader loader, 2022 FT_UInt glyph_index ) 2023 { 2024 TT_Face face = loader->face; 2025#if defined TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY || \ 2026 defined TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL 2027 TT_Driver driver = (TT_Driver)FT_FACE_DRIVER( face ); 2028#endif 2029 2030 FT_BBox bbox; 2031 FT_Fixed y_scale; 2032 TT_GlyphSlot glyph = loader->glyph; 2033 TT_Size size = loader->size; 2034 2035 2036 y_scale = 0x10000L; 2037 if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 ) 2038 y_scale = size->metrics->y_scale; 2039 2040 if ( glyph->format != FT_GLYPH_FORMAT_COMPOSITE ) 2041 FT_Outline_Get_CBox( &glyph->outline, &bbox ); 2042 else 2043 bbox = loader->bbox; 2044 2045 /* get the device-independent horizontal advance; it is scaled later */ 2046 /* by the base layer. */ 2047 glyph->linearHoriAdvance = loader->linear; 2048 2049 glyph->metrics.horiBearingX = bbox.xMin; 2050 glyph->metrics.horiBearingY = bbox.yMax; 2051 glyph->metrics.horiAdvance = loader->pp2.x - loader->pp1.x; 2052 2053 /* Adjust advance width to the value contained in the hdmx table */ 2054 /* unless FT_LOAD_COMPUTE_METRICS is set or backward compatibility */ 2055 /* mode of the v40 interpreter is active. See `ttinterp.h' for */ 2056 /* details on backward compatibility mode. */ 2057 if ( 2058#ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL 2059 !( driver->interpreter_version == TT_INTERPRETER_VERSION_40 && 2060 ( loader->exec && loader->exec->backward_compatibility ) ) && 2061#endif 2062 !face->postscript.isFixedPitch && 2063 IS_HINTED( loader->load_flags ) && 2064 !( loader->load_flags & FT_LOAD_COMPUTE_METRICS ) ) 2065 { 2066 FT_Byte* widthp; 2067 2068 2069 widthp = tt_face_get_device_metrics( face, 2070 size->metrics->x_ppem, 2071 glyph_index ); 2072 2073#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY 2074 2075 if ( driver->interpreter_version == TT_INTERPRETER_VERSION_38 ) 2076 { 2077 FT_Bool ignore_x_mode; 2078 2079 2080 ignore_x_mode = FT_BOOL( FT_LOAD_TARGET_MODE( loader->load_flags ) != 2081 FT_RENDER_MODE_MONO ); 2082 2083 if ( widthp && 2084 ( ( ignore_x_mode && loader->exec->compatible_widths ) || 2085 !ignore_x_mode || 2086 SPH_OPTION_BITMAP_WIDTHS ) ) 2087 glyph->metrics.horiAdvance = *widthp * 64; 2088 } 2089 else 2090 2091#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ 2092 2093 { 2094 if ( widthp ) 2095 glyph->metrics.horiAdvance = *widthp * 64; 2096 } 2097 } 2098 2099 /* set glyph dimensions */ 2100 glyph->metrics.width = SUB_LONG( bbox.xMax, bbox.xMin ); 2101 glyph->metrics.height = SUB_LONG( bbox.yMax, bbox.yMin ); 2102 2103 /* Now take care of vertical metrics. In the case where there is */ 2104 /* no vertical information within the font (relatively common), */ 2105 /* create some metrics manually */ 2106 { 2107 FT_Pos top; /* scaled vertical top side bearing */ 2108 FT_Pos advance; /* scaled vertical advance height */ 2109 2110 2111 /* Get the unscaled top bearing and advance height. */ 2112 if ( face->vertical_info && 2113 face->vertical.number_Of_VMetrics > 0 ) 2114 { 2115 top = (FT_Short)FT_DivFix( loader->pp3.y - bbox.yMax, 2116 y_scale ); 2117 2118 if ( loader->pp3.y <= loader->pp4.y ) 2119 advance = 0; 2120 else 2121 advance = (FT_UShort)FT_DivFix( loader->pp3.y - loader->pp4.y, 2122 y_scale ); 2123 } 2124 else 2125 { 2126 FT_Pos height; 2127 2128 2129 /* XXX Compute top side bearing and advance height in */ 2130 /* Get_VMetrics instead of here. */ 2131 2132 /* NOTE: The OS/2 values are the only `portable' ones, */ 2133 /* which is why we use them, if there is an OS/2 */ 2134 /* table in the font. Otherwise, we use the */ 2135 /* values defined in the horizontal header. */ 2136 2137 height = (FT_Short)FT_DivFix( SUB_LONG( bbox.yMax, 2138 bbox.yMin ), 2139 y_scale ); 2140 if ( face->os2.version != 0xFFFFU ) 2141 advance = (FT_Pos)( face->os2.sTypoAscender - 2142 face->os2.sTypoDescender ); 2143 else 2144 advance = (FT_Pos)( face->horizontal.Ascender - 2145 face->horizontal.Descender ); 2146 2147 top = ( advance - height ) / 2; 2148 } 2149 2150#ifdef FT_CONFIG_OPTION_INCREMENTAL 2151 { 2152 FT_Incremental_InterfaceRec* incr; 2153 FT_Incremental_MetricsRec incr_metrics; 2154 FT_Error error; 2155 2156 2157 incr = face->root.internal->incremental_interface; 2158 2159 /* If this is an incrementally loaded font see if there are */ 2160 /* overriding metrics for this glyph. */ 2161 if ( incr && incr->funcs->get_glyph_metrics ) 2162 { 2163 incr_metrics.bearing_x = 0; 2164 incr_metrics.bearing_y = top; 2165 incr_metrics.advance = advance; 2166 2167 error = incr->funcs->get_glyph_metrics( incr->object, 2168 glyph_index, 2169 TRUE, 2170 &incr_metrics ); 2171 if ( error ) 2172 return error; 2173 2174 top = incr_metrics.bearing_y; 2175 advance = incr_metrics.advance; 2176 } 2177 } 2178 2179 /* GWW: Do vertical metrics get loaded incrementally too? */ 2180 2181#endif /* FT_CONFIG_OPTION_INCREMENTAL */ 2182 2183 glyph->linearVertAdvance = advance; 2184 2185 /* scale the metrics */ 2186 if ( !( loader->load_flags & FT_LOAD_NO_SCALE ) ) 2187 { 2188 top = FT_MulFix( top, y_scale ); 2189 advance = FT_MulFix( advance, y_scale ); 2190 } 2191 2192 /* XXX: for now, we have no better algorithm for the lsb, but it */ 2193 /* should work fine. */ 2194 /* */ 2195 glyph->metrics.vertBearingX = glyph->metrics.horiBearingX - 2196 glyph->metrics.horiAdvance / 2; 2197 glyph->metrics.vertBearingY = top; 2198 glyph->metrics.vertAdvance = advance; 2199 } 2200 2201 return 0; 2202 } 2203 2204 2205#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS 2206 2207 static FT_Error 2208 load_sbit_image( TT_Size size, 2209 TT_GlyphSlot glyph, 2210 FT_UInt glyph_index, 2211 FT_Int32 load_flags ) 2212 { 2213 TT_Face face; 2214 SFNT_Service sfnt; 2215 FT_Stream stream; 2216 FT_Error error; 2217 TT_SBit_MetricsRec sbit_metrics; 2218 2219 2220 face = (TT_Face)glyph->face; 2221 sfnt = (SFNT_Service)face->sfnt; 2222 stream = face->root.stream; 2223 2224 error = sfnt->load_sbit_image( face, 2225 size->strike_index, 2226 glyph_index, 2227 (FT_UInt)load_flags, 2228 stream, 2229 &glyph->bitmap, 2230 &sbit_metrics ); 2231 if ( !error ) 2232 { 2233 glyph->outline.n_points = 0; 2234 glyph->outline.n_contours = 0; 2235 2236 glyph->metrics.width = (FT_Pos)sbit_metrics.width * 64; 2237 glyph->metrics.height = (FT_Pos)sbit_metrics.height * 64; 2238 2239 glyph->metrics.horiBearingX = (FT_Pos)sbit_metrics.horiBearingX * 64; 2240 glyph->metrics.horiBearingY = (FT_Pos)sbit_metrics.horiBearingY * 64; 2241 glyph->metrics.horiAdvance = (FT_Pos)sbit_metrics.horiAdvance * 64; 2242 2243 glyph->metrics.vertBearingX = (FT_Pos)sbit_metrics.vertBearingX * 64; 2244 glyph->metrics.vertBearingY = (FT_Pos)sbit_metrics.vertBearingY * 64; 2245 glyph->metrics.vertAdvance = (FT_Pos)sbit_metrics.vertAdvance * 64; 2246 2247 glyph->format = FT_GLYPH_FORMAT_BITMAP; 2248 2249 if ( load_flags & FT_LOAD_VERTICAL_LAYOUT ) 2250 { 2251 glyph->bitmap_left = sbit_metrics.vertBearingX; 2252 glyph->bitmap_top = sbit_metrics.vertBearingY; 2253 } 2254 else 2255 { 2256 glyph->bitmap_left = sbit_metrics.horiBearingX; 2257 glyph->bitmap_top = sbit_metrics.horiBearingY; 2258 } 2259 } 2260 2261 return error; 2262 } 2263 2264#endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */ 2265 2266 2267 static FT_Error 2268 tt_loader_init( TT_Loader loader, 2269 TT_Size size, 2270 TT_GlyphSlot glyph, 2271 FT_Int32 load_flags, 2272 FT_Bool glyf_table_only ) 2273 { 2274 TT_Face face; 2275 FT_Stream stream; 2276 2277#ifdef TT_USE_BYTECODE_INTERPRETER 2278 FT_Error error; 2279 FT_Bool pedantic = FT_BOOL( load_flags & FT_LOAD_PEDANTIC ); 2280#if defined TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY || \ 2281 defined TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL 2282 TT_Driver driver = (TT_Driver)FT_FACE_DRIVER( (TT_Face)glyph->face ); 2283#endif 2284#endif 2285 2286 2287 face = (TT_Face)glyph->face; 2288 stream = face->root.stream; 2289 2290 FT_ZERO( loader ); 2291 2292#ifdef TT_USE_BYTECODE_INTERPRETER 2293 2294 /* load execution context */ 2295 if ( IS_HINTED( load_flags ) && !glyf_table_only ) 2296 { 2297 TT_ExecContext exec; 2298 FT_Bool grayscale = TRUE; 2299#ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL 2300 FT_Bool subpixel_hinting_lean; 2301 FT_Bool grayscale_cleartype; 2302#endif 2303 2304#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY 2305 FT_Bool subpixel_hinting = FALSE; 2306 2307#if 0 2308 /* not used yet */ 2309 FT_Bool compatible_widths; 2310 FT_Bool symmetrical_smoothing; 2311 FT_Bool bgr; 2312 FT_Bool vertical_lcd; 2313 FT_Bool subpixel_positioned; 2314 FT_Bool gray_cleartype; 2315#endif 2316#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ 2317 2318 FT_Bool reexecute = FALSE; 2319 2320 2321 if ( size->bytecode_ready < 0 || size->cvt_ready < 0 ) 2322 { 2323 error = tt_size_ready_bytecode( size, pedantic ); 2324 if ( error ) 2325 return error; 2326 } 2327 else if ( size->bytecode_ready ) 2328 return size->bytecode_ready; 2329 else if ( size->cvt_ready ) 2330 return size->cvt_ready; 2331 2332 /* query new execution context */ 2333 exec = size->context; 2334 if ( !exec ) 2335 return FT_THROW( Could_Not_Find_Context ); 2336 2337#ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL 2338 if ( driver->interpreter_version == TT_INTERPRETER_VERSION_40 ) 2339 { 2340 subpixel_hinting_lean = 2341 FT_BOOL( FT_LOAD_TARGET_MODE( load_flags ) != 2342 FT_RENDER_MODE_MONO ); 2343 grayscale_cleartype = 2344 FT_BOOL( subpixel_hinting_lean && 2345 !( ( load_flags & 2346 FT_LOAD_TARGET_LCD ) || 2347 ( load_flags & 2348 FT_LOAD_TARGET_LCD_V ) ) ); 2349 exec->vertical_lcd_lean = 2350 FT_BOOL( subpixel_hinting_lean && 2351 ( load_flags & 2352 FT_LOAD_TARGET_LCD_V ) ); 2353 } 2354 else 2355 { 2356 subpixel_hinting_lean = FALSE; 2357 grayscale_cleartype = FALSE; 2358 exec->vertical_lcd_lean = FALSE; 2359 } 2360#endif 2361 2362#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY 2363 2364 if ( driver->interpreter_version == TT_INTERPRETER_VERSION_38 ) 2365 { 2366 subpixel_hinting = FT_BOOL( ( FT_LOAD_TARGET_MODE( load_flags ) != 2367 FT_RENDER_MODE_MONO ) && 2368 SPH_OPTION_SET_SUBPIXEL ); 2369 2370 if ( subpixel_hinting ) 2371 grayscale = FALSE; 2372 else if ( SPH_OPTION_SET_GRAYSCALE ) 2373 { 2374 grayscale = TRUE; 2375 subpixel_hinting = FALSE; 2376 } 2377 else 2378 grayscale = FALSE; 2379 2380 if ( FT_IS_TRICKY( glyph->face ) ) 2381 subpixel_hinting = FALSE; 2382 2383 exec->ignore_x_mode = subpixel_hinting || grayscale; 2384 exec->rasterizer_version = SPH_OPTION_SET_RASTERIZER_VERSION; 2385 if ( exec->sph_tweak_flags & SPH_TWEAK_RASTERIZER_35 ) 2386 exec->rasterizer_version = TT_INTERPRETER_VERSION_35; 2387 2388#if 1 2389 exec->compatible_widths = SPH_OPTION_SET_COMPATIBLE_WIDTHS; 2390 exec->symmetrical_smoothing = TRUE; 2391 exec->bgr = FALSE; 2392 exec->vertical_lcd = FALSE; 2393 exec->subpixel_positioned = TRUE; 2394 exec->gray_cleartype = FALSE; 2395#else /* 0 */ 2396 exec->compatible_widths = 2397 FT_BOOL( FT_LOAD_TARGET_MODE( load_flags ) != 2398 TT_LOAD_COMPATIBLE_WIDTHS ); 2399 exec->symmetrical_smoothing = 2400 FT_BOOL( FT_LOAD_TARGET_MODE( load_flags ) != 2401 TT_LOAD_SYMMETRICAL_SMOOTHING ); 2402 exec->bgr = 2403 FT_BOOL( FT_LOAD_TARGET_MODE( load_flags ) != 2404 TT_LOAD_BGR ); 2405 exec->vertical_lcd = 2406 FT_BOOL( FT_LOAD_TARGET_MODE( load_flags ) != 2407 TT_LOAD_VERTICAL_LCD ); 2408 exec->subpixel_positioned = 2409 FT_BOOL( FT_LOAD_TARGET_MODE( load_flags ) != 2410 TT_LOAD_SUBPIXEL_POSITIONED ); 2411 exec->gray_cleartype = 2412 FT_BOOL( FT_LOAD_TARGET_MODE( load_flags ) != 2413 TT_LOAD_GRAY_CLEARTYPE ); 2414#endif /* 0 */ 2415 2416 } 2417 else 2418 2419#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ 2420 2421#ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL 2422 if ( driver->interpreter_version == TT_INTERPRETER_VERSION_40 ) 2423 grayscale = FT_BOOL( !subpixel_hinting_lean && 2424 FT_LOAD_TARGET_MODE( load_flags ) != 2425 FT_RENDER_MODE_MONO ); 2426 else 2427#endif 2428 grayscale = FT_BOOL( FT_LOAD_TARGET_MODE( load_flags ) != 2429 FT_RENDER_MODE_MONO ); 2430 2431 error = TT_Load_Context( exec, face, size ); 2432 if ( error ) 2433 return error; 2434 2435#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY 2436 2437 if ( driver->interpreter_version == TT_INTERPRETER_VERSION_38 ) 2438 { 2439 /* a change from mono to subpixel rendering (and vice versa) */ 2440 /* requires a re-execution of the CVT program */ 2441 if ( subpixel_hinting != exec->subpixel_hinting ) 2442 { 2443 FT_TRACE4(( "tt_loader_init: subpixel hinting change," 2444 " re-executing `prep' table\n" )); 2445 2446 exec->subpixel_hinting = subpixel_hinting; 2447 reexecute = TRUE; 2448 } 2449 2450 /* a change from mono to grayscale rendering (and vice versa) */ 2451 /* requires a re-execution of the CVT program */ 2452 if ( grayscale != exec->grayscale ) 2453 { 2454 FT_TRACE4(( "tt_loader_init: grayscale hinting change," 2455 " re-executing `prep' table\n" )); 2456 2457 exec->grayscale = grayscale; 2458 reexecute = TRUE; 2459 } 2460 } 2461 else 2462 2463#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ 2464 2465 { 2466 2467#ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL 2468 if ( driver->interpreter_version == TT_INTERPRETER_VERSION_40 ) 2469 { 2470 /* a change from mono to subpixel rendering (and vice versa) */ 2471 /* requires a re-execution of the CVT program */ 2472 if ( subpixel_hinting_lean != exec->subpixel_hinting_lean ) 2473 { 2474 FT_TRACE4(( "tt_loader_init: subpixel hinting change," 2475 " re-executing `prep' table\n" )); 2476 2477 exec->subpixel_hinting_lean = subpixel_hinting_lean; 2478 reexecute = TRUE; 2479 } 2480 2481 /* a change from colored to grayscale subpixel rendering (and */ 2482 /* vice versa) requires a re-execution of the CVT program */ 2483 if ( grayscale_cleartype != exec->grayscale_cleartype ) 2484 { 2485 FT_TRACE4(( "tt_loader_init: grayscale subpixel hinting change," 2486 " re-executing `prep' table\n" )); 2487 2488 exec->grayscale_cleartype = grayscale_cleartype; 2489 reexecute = TRUE; 2490 } 2491 } 2492#endif 2493 2494 /* a change from mono to grayscale rendering (and vice versa) */ 2495 /* requires a re-execution of the CVT program */ 2496 if ( grayscale != exec->grayscale ) 2497 { 2498 FT_TRACE4(( "tt_loader_init: grayscale hinting change," 2499 " re-executing `prep' table\n" )); 2500 2501 exec->grayscale = grayscale; 2502 reexecute = TRUE; 2503 } 2504 } 2505 2506 if ( reexecute ) 2507 { 2508 FT_UInt i; 2509 2510 2511 for ( i = 0; i < size->cvt_size; i++ ) 2512 size->cvt[i] = FT_MulFix( face->cvt[i], size->ttmetrics.scale ); 2513 error = tt_size_run_prep( size, pedantic ); 2514 if ( error ) 2515 return error; 2516 } 2517 2518 /* check whether the cvt program has disabled hinting */ 2519 if ( exec->GS.instruct_control & 1 ) 2520 load_flags |= FT_LOAD_NO_HINTING; 2521 2522 /* load default graphics state -- if needed */ 2523 if ( exec->GS.instruct_control & 2 ) 2524 exec->GS = tt_default_graphics_state; 2525 2526#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY 2527 /* check whether we have a font hinted for ClearType -- */ 2528 /* note that this flag can also be modified in a glyph's bytecode */ 2529 if ( driver->interpreter_version == TT_INTERPRETER_VERSION_38 && 2530 exec->GS.instruct_control & 4 ) 2531 exec->ignore_x_mode = 0; 2532#endif 2533 2534 exec->pedantic_hinting = FT_BOOL( load_flags & FT_LOAD_PEDANTIC ); 2535 loader->exec = exec; 2536 loader->instructions = exec->glyphIns; 2537 } 2538 2539#endif /* TT_USE_BYTECODE_INTERPRETER */ 2540 2541 /* get face's glyph loader */ 2542 if ( !glyf_table_only ) 2543 { 2544 FT_GlyphLoader gloader = glyph->internal->loader; 2545 2546 2547 FT_GlyphLoader_Rewind( gloader ); 2548 loader->gloader = gloader; 2549 } 2550 2551 loader->load_flags = (FT_ULong)load_flags; 2552 2553 loader->face = face; 2554 loader->size = size; 2555 loader->glyph = (FT_GlyphSlot)glyph; 2556 loader->stream = stream; 2557 2558 loader->composites.head = NULL; 2559 loader->composites.tail = NULL; 2560 2561 return FT_Err_Ok; 2562 } 2563 2564 2565 static void 2566 tt_loader_done( TT_Loader loader ) 2567 { 2568 FT_List_Finalize( &loader->composites, 2569 NULL, 2570 loader->face->root.memory, 2571 NULL ); 2572 } 2573 2574 2575 /*************************************************************************/ 2576 /* */ 2577 /* <Function> */ 2578 /* TT_Load_Glyph */ 2579 /* */ 2580 /* <Description> */ 2581 /* A function used to load a single glyph within a given glyph slot, */ 2582 /* for a given size. */ 2583 /* */ 2584 /* <Input> */ 2585 /* glyph :: A handle to a target slot object where the glyph */ 2586 /* will be loaded. */ 2587 /* */ 2588 /* size :: A handle to the source face size at which the glyph */ 2589 /* must be scaled/loaded. */ 2590 /* */ 2591 /* glyph_index :: The index of the glyph in the font file. */ 2592 /* */ 2593 /* load_flags :: A flag indicating what to load for this glyph. The */ 2594 /* FT_LOAD_XXX constants can be used to control the */ 2595 /* glyph loading process (e.g., whether the outline */ 2596 /* should be scaled, whether to load bitmaps or not, */ 2597 /* whether to hint the outline, etc). */ 2598 /* */ 2599 /* <Return> */ 2600 /* FreeType error code. 0 means success. */ 2601 /* */ 2602 FT_LOCAL_DEF( FT_Error ) 2603 TT_Load_Glyph( TT_Size size, 2604 TT_GlyphSlot glyph, 2605 FT_UInt glyph_index, 2606 FT_Int32 load_flags ) 2607 { 2608 FT_Error error; 2609 TT_LoaderRec loader; 2610 2611#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT 2612#define IS_DEFAULT_INSTANCE ( ( (TT_Face)glyph->face )->is_default_instance ) 2613#else 2614#define IS_DEFAULT_INSTANCE 1 2615#endif 2616 2617 2618 FT_TRACE1(( "TT_Load_Glyph: glyph index %d\n", glyph_index )); 2619 2620#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS 2621 2622 /* try to load embedded bitmap (if any) */ 2623 if ( size->strike_index != 0xFFFFFFFFUL && 2624 ( load_flags & FT_LOAD_NO_BITMAP ) == 0 && 2625 IS_DEFAULT_INSTANCE ) 2626 { 2627 error = load_sbit_image( size, glyph, glyph_index, load_flags ); 2628 if ( error ) 2629 { 2630 /* return error if font is not scalable */ 2631 if ( !FT_IS_SCALABLE( glyph->face ) ) 2632 return error; 2633 } 2634 else 2635 { 2636 if ( FT_IS_SCALABLE( glyph->face ) ) 2637 { 2638 /* for the bbox we need the header only */ 2639 (void)tt_loader_init( &loader, size, glyph, load_flags, TRUE ); 2640 (void)load_truetype_glyph( &loader, glyph_index, 0, TRUE ); 2641 tt_loader_done( &loader ); 2642 glyph->linearHoriAdvance = loader.linear; 2643 glyph->linearVertAdvance = loader.vadvance; 2644 2645 /* sanity checks: if `xxxAdvance' in the sbit metric */ 2646 /* structure isn't set, use `linearXXXAdvance' */ 2647 if ( !glyph->metrics.horiAdvance && glyph->linearHoriAdvance ) 2648 glyph->metrics.horiAdvance = 2649 FT_MulFix( glyph->linearHoriAdvance, 2650 size->metrics->x_scale ); 2651 if ( !glyph->metrics.vertAdvance && glyph->linearVertAdvance ) 2652 glyph->metrics.vertAdvance = 2653 FT_MulFix( glyph->linearVertAdvance, 2654 size->metrics->y_scale ); 2655 } 2656 2657 return FT_Err_Ok; 2658 } 2659 } 2660 2661#endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */ 2662 2663 /* if FT_LOAD_NO_SCALE is not set, `ttmetrics' must be valid */ 2664 if ( !( load_flags & FT_LOAD_NO_SCALE ) && !size->ttmetrics.valid ) 2665 { 2666 error = FT_THROW( Invalid_Size_Handle ); 2667 goto Exit; 2668 } 2669 2670 if ( load_flags & FT_LOAD_SBITS_ONLY ) 2671 { 2672 error = FT_THROW( Invalid_Argument ); 2673 goto Exit; 2674 } 2675 2676 error = tt_loader_init( &loader, size, glyph, load_flags, FALSE ); 2677 if ( error ) 2678 goto Exit; 2679 2680 glyph->format = FT_GLYPH_FORMAT_OUTLINE; 2681 glyph->num_subglyphs = 0; 2682 glyph->outline.flags = 0; 2683 2684 /* main loading loop */ 2685 error = load_truetype_glyph( &loader, glyph_index, 0, FALSE ); 2686 if ( !error ) 2687 { 2688 if ( glyph->format == FT_GLYPH_FORMAT_COMPOSITE ) 2689 { 2690 glyph->num_subglyphs = loader.gloader->base.num_subglyphs; 2691 glyph->subglyphs = loader.gloader->base.subglyphs; 2692 } 2693 else 2694 { 2695 glyph->outline = loader.gloader->base.outline; 2696 glyph->outline.flags &= ~FT_OUTLINE_SINGLE_PASS; 2697 2698 /* Translate array so that (0,0) is the glyph's origin. Note */ 2699 /* that this behaviour is independent on the value of bit 1 of */ 2700 /* the `flags' field in the `head' table -- at least major */ 2701 /* applications like Acroread indicate that. */ 2702 if ( loader.pp1.x ) 2703 FT_Outline_Translate( &glyph->outline, -loader.pp1.x, 0 ); 2704 } 2705 2706#ifdef TT_USE_BYTECODE_INTERPRETER 2707 2708 if ( IS_HINTED( load_flags ) ) 2709 { 2710 if ( loader.exec->GS.scan_control ) 2711 { 2712 /* convert scan conversion mode to FT_OUTLINE_XXX flags */ 2713 switch ( loader.exec->GS.scan_type ) 2714 { 2715 case 0: /* simple drop-outs including stubs */ 2716 glyph->outline.flags |= FT_OUTLINE_INCLUDE_STUBS; 2717 break; 2718 case 1: /* simple drop-outs excluding stubs */ 2719 /* nothing; it's the default rendering mode */ 2720 break; 2721 case 4: /* smart drop-outs including stubs */ 2722 glyph->outline.flags |= FT_OUTLINE_SMART_DROPOUTS | 2723 FT_OUTLINE_INCLUDE_STUBS; 2724 break; 2725 case 5: /* smart drop-outs excluding stubs */ 2726 glyph->outline.flags |= FT_OUTLINE_SMART_DROPOUTS; 2727 break; 2728 2729 default: /* no drop-out control */ 2730 glyph->outline.flags |= FT_OUTLINE_IGNORE_DROPOUTS; 2731 break; 2732 } 2733 } 2734 else 2735 glyph->outline.flags |= FT_OUTLINE_IGNORE_DROPOUTS; 2736 } 2737 2738#endif /* TT_USE_BYTECODE_INTERPRETER */ 2739 2740 error = compute_glyph_metrics( &loader, glyph_index ); 2741 } 2742 2743 tt_loader_done( &loader ); 2744 2745 /* Set the `high precision' bit flag. */ 2746 /* This is _critical_ to get correct output for monochrome */ 2747 /* TrueType glyphs at all sizes using the bytecode interpreter. */ 2748 /* */ 2749 if ( !( load_flags & FT_LOAD_NO_SCALE ) && 2750 size->metrics->y_ppem < 24 ) 2751 glyph->outline.flags |= FT_OUTLINE_HIGH_PRECISION; 2752 2753 Exit: 2754#ifdef FT_DEBUG_LEVEL_TRACE 2755 if ( error ) 2756 FT_TRACE1(( " failed (error code 0x%x)\n", 2757 error )); 2758#endif 2759 2760 return error; 2761 } 2762 2763 2764/* END */ 2765