OLD | NEW |
1 /***************************************************************************/ | 1 /***************************************************************************/ |
2 /* */ | 2 /* */ |
3 /* ttgload.c */ | 3 /* ttgload.c */ |
4 /* */ | 4 /* */ |
5 /* TrueType Glyph Loader (body). */ | 5 /* TrueType Glyph Loader (body). */ |
6 /* */ | 6 /* */ |
7 /* Copyright 1996-2013 */ | 7 /* Copyright 1996-2014 */ |
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ | 8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ |
9 /* */ | 9 /* */ |
10 /* This file is part of the FreeType project, and may only be used, */ | 10 /* This file is part of the FreeType project, and may only be used, */ |
11 /* modified, and distributed under the terms of the FreeType project */ | 11 /* modified, and distributed under the terms of the FreeType project */ |
12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ | 12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ |
13 /* this file you indicate that you have read the license and */ | 13 /* this file you indicate that you have read the license and */ |
14 /* understand and accept it fully. */ | 14 /* understand and accept it fully. */ |
15 /* */ | 15 /* */ |
16 /***************************************************************************/ | 16 /***************************************************************************/ |
17 | 17 |
18 | 18 |
19 #include "../../include/ft2build.h" | 19 #include <ft2build.h> |
20 #include "../../include/freetype/internal/ftdebug.h" | 20 #include FT_INTERNAL_DEBUG_H |
21 #include "../../include/freetype/internal/ftcalc.h" | 21 #include FT_INTERNAL_CALC_H |
22 #include "../../include/freetype/internal/ftstream.h" | 22 #include FT_INTERNAL_STREAM_H |
23 #include "../../include/freetype/internal/sfnt.h" | 23 #include FT_INTERNAL_SFNT_H |
24 #include "../../include/freetype/tttags.h" | 24 #include FT_TRUETYPE_TAGS_H |
25 #include "../../include/freetype/ftoutln.h" | 25 #include FT_OUTLINE_H |
26 #include "../../include/freetype/ftttdrv.h" | 26 #include FT_TRUETYPE_DRIVER_H |
27 | |
28 | 27 |
29 #include "ttgload.h" | 28 #include "ttgload.h" |
30 #include "ttpload.h" | 29 #include "ttpload.h" |
31 | 30 |
32 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT | 31 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT |
33 #include "ttgxvar.h" | 32 #include "ttgxvar.h" |
34 #endif | 33 #endif |
35 | 34 |
36 #include "tterrors.h" | 35 #include "tterrors.h" |
37 #include "ttsubpix.h" | 36 #include "ttsubpix.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 ( (SFNT_Service)face->sfnt )->get_metrics( face, 0, idx, lsb, aw ); | 78 ( (SFNT_Service)face->sfnt )->get_metrics( face, 0, idx, lsb, aw ); |
80 | 79 |
81 FT_TRACE5(( " advance width (font units): %d\n", *aw )); | 80 FT_TRACE5(( " advance width (font units): %d\n", *aw )); |
82 FT_TRACE5(( " left side bearing (font units): %d\n", *lsb )); | 81 FT_TRACE5(( " left side bearing (font units): %d\n", *lsb )); |
83 } | 82 } |
84 | 83 |
85 | 84 |
86 /*************************************************************************/ | 85 /*************************************************************************/ |
87 /* */ | 86 /* */ |
88 /* Return the vertical metrics in font units for a given glyph. */ | 87 /* Return the vertical metrics in font units for a given glyph. */ |
89 /* Greg Hitchcock from Microsoft told us that if there were no `vmtx' */ | 88 /* See macro `TT_LOADER_SET_PP' below for explanations. */ |
90 /* table, typoAscender/Descender from the `OS/2' table would be used */ | |
91 /* instead, and if there were no `OS/2' table, use ascender/descender */ | |
92 /* from the `hhea' table. But that is not what Microsoft's rasterizer */ | |
93 /* apparently does: It uses the ppem value as the advance height, and */ | |
94 /* sets the top side bearing to be zero. */ | |
95 /* */ | 89 /* */ |
96 FT_LOCAL_DEF( void ) | 90 FT_LOCAL_DEF( void ) |
97 TT_Get_VMetrics( TT_Face face, | 91 TT_Get_VMetrics( TT_Face face, |
98 FT_UInt idx, | 92 FT_UInt idx, |
| 93 FT_Pos yMax, |
99 FT_Short* tsb, | 94 FT_Short* tsb, |
100 FT_UShort* ah ) | 95 FT_UShort* ah ) |
101 { | 96 { |
102 if ( face->vertical_info ) | 97 if ( face->vertical_info ) |
103 ( (SFNT_Service)face->sfnt )->get_metrics( face, 1, idx, tsb, ah ); | 98 ( (SFNT_Service)face->sfnt )->get_metrics( face, 1, idx, tsb, ah ); |
104 | 99 |
105 #if 1 /* Empirically determined, at variance with what MS said */ | 100 else if ( face->os2.version != 0xFFFFU ) |
| 101 { |
| 102 *tsb = (FT_Short)( face->os2.sTypoAscender - yMax ); |
| 103 *ah = face->os2.sTypoAscender - face->os2.sTypoDescender; |
| 104 } |
106 | 105 |
107 else | 106 else |
108 { | 107 { |
109 *tsb = 0; | 108 *tsb = (FT_Short)( face->horizontal.Ascender - yMax ); |
110 *ah = face->root.units_per_EM; | |
111 } | |
112 | |
113 #else /* This is what MS said to do. It isn't what they do, however. */ | |
114 | |
115 else if ( face->os2.version != 0xFFFFU ) | |
116 { | |
117 *tsb = face->os2.sTypoAscender; | |
118 *ah = face->os2.sTypoAscender - face->os2.sTypoDescender; | |
119 } | |
120 else | |
121 { | |
122 *tsb = face->horizontal.Ascender; | |
123 *ah = face->horizontal.Ascender - face->horizontal.Descender; | 109 *ah = face->horizontal.Ascender - face->horizontal.Descender; |
124 } | 110 } |
125 | 111 |
126 #endif | |
127 | |
128 FT_TRACE5(( " advance height (font units): %d\n", *ah )); | 112 FT_TRACE5(( " advance height (font units): %d\n", *ah )); |
129 FT_TRACE5(( " top side bearing (font units): %d\n", *tsb )); | 113 FT_TRACE5(( " top side bearing (font units): %d\n", *tsb )); |
130 } | 114 } |
131 | 115 |
132 | 116 |
133 static void | 117 static FT_Error |
134 tt_get_metrics( TT_Loader loader, | 118 tt_get_metrics( TT_Loader loader, |
135 FT_UInt glyph_index ) | 119 FT_UInt glyph_index ) |
136 { | 120 { |
137 TT_Face face = (TT_Face)loader->face; | 121 TT_Face face = (TT_Face)loader->face; |
138 #ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING | 122 #ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING |
139 TT_Driver driver = (TT_Driver)FT_FACE_DRIVER( face ); | 123 TT_Driver driver = (TT_Driver)FT_FACE_DRIVER( face ); |
140 #endif | 124 #endif |
141 | 125 |
| 126 FT_Error error; |
| 127 FT_Stream stream = loader->stream; |
| 128 |
142 FT_Short left_bearing = 0, top_bearing = 0; | 129 FT_Short left_bearing = 0, top_bearing = 0; |
143 FT_UShort advance_width = 0, advance_height = 0; | 130 FT_UShort advance_width = 0, advance_height = 0; |
144 | 131 |
| 132 /* we must preserve the stream position */ |
| 133 /* (which gets altered by the metrics functions) */ |
| 134 FT_ULong pos = FT_STREAM_POS(); |
| 135 |
145 | 136 |
146 TT_Get_HMetrics( face, glyph_index, | 137 TT_Get_HMetrics( face, glyph_index, |
147 &left_bearing, | 138 &left_bearing, |
148 &advance_width ); | 139 &advance_width ); |
149 TT_Get_VMetrics( face, glyph_index, | 140 TT_Get_VMetrics( face, glyph_index, |
| 141 loader->bbox.yMax, |
150 &top_bearing, | 142 &top_bearing, |
151 &advance_height ); | 143 &advance_height ); |
152 | 144 |
| 145 if ( FT_STREAM_SEEK( pos ) ) |
| 146 return error; |
| 147 |
153 loader->left_bearing = left_bearing; | 148 loader->left_bearing = left_bearing; |
154 loader->advance = advance_width; | 149 loader->advance = advance_width; |
155 loader->top_bearing = top_bearing; | 150 loader->top_bearing = top_bearing; |
156 loader->vadvance = advance_height; | 151 loader->vadvance = advance_height; |
157 | 152 |
158 #ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING | 153 #ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING |
159 if ( driver->interpreter_version == TT_INTERPRETER_VERSION_38 ) | 154 if ( driver->interpreter_version == TT_INTERPRETER_VERSION_38 ) |
160 { | 155 { |
161 if ( loader->exec ) | 156 if ( loader->exec ) |
162 loader->exec->sph_tweak_flags = 0; | 157 loader->exec->sph_tweak_flags = 0; |
163 | 158 |
164 /* this may not be the right place for this, but it works */ | 159 /* this may not be the right place for this, but it works */ |
165 if ( loader->exec && loader->exec->ignore_x_mode ) | 160 if ( loader->exec && loader->exec->ignore_x_mode ) |
166 sph_set_tweaks( loader, glyph_index ); | 161 sph_set_tweaks( loader, glyph_index ); |
167 } | 162 } |
168 #endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ | 163 #endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ |
169 | 164 |
170 if ( !loader->linear_def ) | 165 if ( !loader->linear_def ) |
171 { | 166 { |
172 loader->linear_def = 1; | 167 loader->linear_def = 1; |
173 loader->linear = advance_width; | 168 loader->linear = advance_width; |
174 } | 169 } |
| 170 |
| 171 return FT_Err_Ok; |
175 } | 172 } |
176 | 173 |
177 | 174 |
178 #ifdef FT_CONFIG_OPTION_INCREMENTAL | 175 #ifdef FT_CONFIG_OPTION_INCREMENTAL |
179 | 176 |
180 static void | 177 static void |
181 tt_get_metrics_incr_overrides( TT_Loader loader, | 178 tt_get_metrics_incr_overrides( TT_Loader loader, |
182 FT_UInt glyph_index ) | 179 FT_UInt glyph_index ) |
183 { | 180 { |
184 TT_Face face = (TT_Face)loader->face; | 181 TT_Face face = (TT_Face)loader->face; |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 | 341 |
345 FT_CALLBACK_DEF( FT_Error ) | 342 FT_CALLBACK_DEF( FT_Error ) |
346 TT_Load_Simple_Glyph( TT_Loader load ) | 343 TT_Load_Simple_Glyph( TT_Loader load ) |
347 { | 344 { |
348 FT_Error error; | 345 FT_Error error; |
349 FT_Byte* p = load->cursor; | 346 FT_Byte* p = load->cursor; |
350 FT_Byte* limit = load->limit; | 347 FT_Byte* limit = load->limit; |
351 FT_GlyphLoader gloader = load->gloader; | 348 FT_GlyphLoader gloader = load->gloader; |
352 FT_Int n_contours = load->n_contours; | 349 FT_Int n_contours = load->n_contours; |
353 FT_Outline* outline; | 350 FT_Outline* outline; |
354 TT_Face face = (TT_Face)load->face; | |
355 FT_UShort n_ins; | 351 FT_UShort n_ins; |
356 FT_Int n_points; | 352 FT_Int n_points; |
| 353 FT_ULong tmp; |
357 | 354 |
358 FT_Byte *flag, *flag_limit; | 355 FT_Byte *flag, *flag_limit; |
359 FT_Byte c, count; | 356 FT_Byte c, count; |
360 FT_Vector *vec, *vec_limit; | 357 FT_Vector *vec, *vec_limit; |
361 FT_Pos x; | 358 FT_Pos x; |
362 FT_Short *cont, *cont_limit, prev_cont; | 359 FT_Short *cont, *cont_limit, prev_cont; |
363 FT_Int xy_size = 0; | 360 FT_Int xy_size = 0; |
364 | 361 |
365 | 362 |
366 /* check that we can add the contours to the glyph */ | 363 /* check that we can add the contours to the glyph */ |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 load->glyph->control_len = 0; | 409 load->glyph->control_len = 0; |
413 load->glyph->control_data = 0; | 410 load->glyph->control_data = 0; |
414 | 411 |
415 if ( p + 2 > limit ) | 412 if ( p + 2 > limit ) |
416 goto Invalid_Outline; | 413 goto Invalid_Outline; |
417 | 414 |
418 n_ins = FT_NEXT_USHORT( p ); | 415 n_ins = FT_NEXT_USHORT( p ); |
419 | 416 |
420 FT_TRACE5(( " Instructions size: %u\n", n_ins )); | 417 FT_TRACE5(( " Instructions size: %u\n", n_ins )); |
421 | 418 |
422 if ( n_ins > face->max_profile.maxSizeOfInstructions ) | 419 /* check it */ |
423 { | |
424 FT_TRACE0(( "TT_Load_Simple_Glyph: too many instructions (%d)\n", | |
425 n_ins )); | |
426 error = FT_THROW( Too_Many_Hints ); | |
427 goto Fail; | |
428 } | |
429 | |
430 if ( ( limit - p ) < n_ins ) | 420 if ( ( limit - p ) < n_ins ) |
431 { | 421 { |
432 FT_TRACE0(( "TT_Load_Simple_Glyph: instruction count mismatch\n" )); | 422 FT_TRACE0(( "TT_Load_Simple_Glyph: instruction count mismatch\n" )); |
433 error = FT_THROW( Too_Many_Hints ); | 423 error = FT_THROW( Too_Many_Hints ); |
434 goto Fail; | 424 goto Fail; |
435 } | 425 } |
436 | 426 |
437 #ifdef TT_USE_BYTECODE_INTERPRETER | 427 #ifdef TT_USE_BYTECODE_INTERPRETER |
438 | 428 |
439 if ( IS_HINTED( load->load_flags ) ) | 429 if ( IS_HINTED( load->load_flags ) ) |
440 { | 430 { |
| 431 /* we don't trust `maxSizeOfInstructions' in the `maxp' table */ |
| 432 /* and thus update the bytecode array size by ourselves */ |
| 433 |
| 434 tmp = load->exec->glyphSize; |
| 435 error = Update_Max( load->exec->memory, |
| 436 &tmp, |
| 437 sizeof ( FT_Byte ), |
| 438 (void*)&load->exec->glyphIns, |
| 439 n_ins ); |
| 440 |
| 441 load->exec->glyphSize = (FT_UShort)tmp; |
| 442 if ( error ) |
| 443 return error; |
| 444 |
441 load->glyph->control_len = n_ins; | 445 load->glyph->control_len = n_ins; |
442 load->glyph->control_data = load->exec->glyphIns; | 446 load->glyph->control_data = load->exec->glyphIns; |
443 | 447 |
444 FT_MEM_COPY( load->exec->glyphIns, p, (FT_Long)n_ins ); | 448 FT_MEM_COPY( load->exec->glyphIns, p, (FT_Long)n_ins ); |
445 } | 449 } |
446 | 450 |
447 #endif /* TT_USE_BYTECODE_INTERPRETER */ | 451 #endif /* TT_USE_BYTECODE_INTERPRETER */ |
448 | 452 |
449 p += n_ins; | 453 p += n_ins; |
450 | 454 |
451 outline = &gloader->current.outline; | 455 outline = &gloader->current.outline; |
452 if (outline->tags == NULL) { | |
453 FT_TRACE0(( "TT_Load_Simple_Glyph: Outline->tags = NULL!\n" )); | |
454 goto Invalid_Outline; | |
455 } | |
456 | 456 |
457 /* reading the point tags */ | 457 /* reading the point tags */ |
458 flag = (FT_Byte*)outline->tags; | 458 flag = (FT_Byte*)outline->tags; |
459 flag_limit = flag + n_points; | 459 flag_limit = flag + n_points; |
460 | 460 |
461 //FT_ASSERT( flag != NULL ); | 461 FT_ASSERT( flag != NULL ); |
462 | 462 |
463 while ( flag < flag_limit ) | 463 while ( flag < flag_limit ) |
464 { | 464 { |
465 if ( p + 1 > limit ) | 465 if ( p + 1 > limit ) |
466 goto Invalid_Outline; | 466 goto Invalid_Outline; |
467 | 467 |
468 *flag++ = c = FT_NEXT_BYTE( p ); | 468 *flag++ = c = FT_NEXT_BYTE( p ); |
469 if ( c & 8 ) | 469 if ( c & 8 ) |
470 { | 470 { |
471 if ( p + 1 > limit ) | 471 if ( p + 1 > limit ) |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 static FT_Error | 731 static FT_Error |
732 TT_Hint_Glyph( TT_Loader loader, | 732 TT_Hint_Glyph( TT_Loader loader, |
733 FT_Bool is_composite ) | 733 FT_Bool is_composite ) |
734 { | 734 { |
735 #ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING | 735 #ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING |
736 TT_Face face = (TT_Face)loader->face; | 736 TT_Face face = (TT_Face)loader->face; |
737 TT_Driver driver = (TT_Driver)FT_FACE_DRIVER( face ); | 737 TT_Driver driver = (TT_Driver)FT_FACE_DRIVER( face ); |
738 #endif | 738 #endif |
739 | 739 |
740 TT_GlyphZone zone = &loader->zone; | 740 TT_GlyphZone zone = &loader->zone; |
741 FT_Pos origin; | |
742 | 741 |
743 #ifdef TT_USE_BYTECODE_INTERPRETER | 742 #ifdef TT_USE_BYTECODE_INTERPRETER |
744 FT_UInt n_ins; | 743 FT_UInt n_ins; |
745 #else | 744 #else |
746 FT_UNUSED( is_composite ); | 745 FT_UNUSED( is_composite ); |
747 #endif | 746 #endif |
748 | 747 |
749 | 748 |
750 #ifdef TT_USE_BYTECODE_INTERPRETER | 749 #ifdef TT_USE_BYTECODE_INTERPRETER |
751 if ( loader->glyph->control_len > 0xFFFFL ) | 750 if ( loader->glyph->control_len > 0xFFFFL ) |
752 { | 751 { |
753 FT_TRACE1(( "TT_Hint_Glyph: too long instructions " )); | 752 FT_TRACE1(( "TT_Hint_Glyph: too long instructions" )); |
754 FT_TRACE1(( "(0x%lx byte) is truncated\n", | 753 FT_TRACE1(( " (0x%lx byte) is truncated\n", |
755 loader->glyph->control_len )); | 754 loader->glyph->control_len )); |
756 } | 755 } |
757 n_ins = (FT_UInt)( loader->glyph->control_len ); | 756 n_ins = (FT_UInt)( loader->glyph->control_len ); |
758 #endif | |
759 | 757 |
760 origin = zone->cur[zone->n_points - 4].x; | |
761 origin = FT_PIX_ROUND( origin ) - origin; | |
762 if ( origin ) | |
763 translate_array( zone->n_points, zone->cur, origin, 0 ); | |
764 | |
765 #ifdef TT_USE_BYTECODE_INTERPRETER | |
766 /* save original point position in org */ | 758 /* save original point position in org */ |
767 if ( n_ins > 0 ) | 759 if ( n_ins > 0 ) |
768 FT_ARRAY_COPY( zone->org, zone->cur, zone->n_points ); | 760 FT_ARRAY_COPY( zone->org, zone->cur, zone->n_points ); |
769 | 761 |
770 /* Reset graphics state. */ | 762 /* Reset graphics state. */ |
771 loader->exec->GS = ((TT_Size)loader->size)->GS; | 763 loader->exec->GS = ((TT_Size)loader->size)->GS; |
772 | 764 |
773 /* XXX: UNDOCUMENTED! Hinting instructions of a composite glyph */ | 765 /* XXX: UNDOCUMENTED! Hinting instructions of a composite glyph */ |
774 /* completely refer to the (already) hinted subglyphs. */ | 766 /* completely refer to the (already) hinted subglyphs. */ |
775 if ( is_composite ) | 767 if ( is_composite ) |
776 { | 768 { |
777 loader->exec->metrics.x_scale = 1 << 16; | 769 loader->exec->metrics.x_scale = 1 << 16; |
778 loader->exec->metrics.y_scale = 1 << 16; | 770 loader->exec->metrics.y_scale = 1 << 16; |
779 | 771 |
780 FT_ARRAY_COPY( zone->orus, zone->cur, zone->n_points ); | 772 FT_ARRAY_COPY( zone->orus, zone->cur, zone->n_points ); |
781 } | 773 } |
782 else | 774 else |
783 { | 775 { |
784 loader->exec->metrics.x_scale = | 776 loader->exec->metrics.x_scale = |
785 ((TT_Size)loader->size)->metrics.x_scale; | 777 ((TT_Size)loader->size)->metrics.x_scale; |
786 loader->exec->metrics.y_scale = | 778 loader->exec->metrics.y_scale = |
787 ((TT_Size)loader->size)->metrics.y_scale; | 779 ((TT_Size)loader->size)->metrics.y_scale; |
788 } | 780 } |
789 #endif | 781 #endif |
790 | 782 |
791 /* round pp2 and pp4 */ | 783 /* round phantom points */ |
| 784 zone->cur[zone->n_points - 4].x = |
| 785 FT_PIX_ROUND( zone->cur[zone->n_points - 4].x ); |
792 zone->cur[zone->n_points - 3].x = | 786 zone->cur[zone->n_points - 3].x = |
793 FT_PIX_ROUND( zone->cur[zone->n_points - 3].x ); | 787 FT_PIX_ROUND( zone->cur[zone->n_points - 3].x ); |
| 788 zone->cur[zone->n_points - 2].y = |
| 789 FT_PIX_ROUND( zone->cur[zone->n_points - 2].y ); |
794 zone->cur[zone->n_points - 1].y = | 790 zone->cur[zone->n_points - 1].y = |
795 FT_PIX_ROUND( zone->cur[zone->n_points - 1].y ); | 791 FT_PIX_ROUND( zone->cur[zone->n_points - 1].y ); |
796 | 792 |
797 #ifdef TT_USE_BYTECODE_INTERPRETER | 793 #ifdef TT_USE_BYTECODE_INTERPRETER |
798 | 794 |
799 if ( n_ins > 0 ) | 795 if ( n_ins > 0 ) |
800 { | 796 { |
801 FT_Bool debug; | 797 FT_Bool debug; |
802 FT_Error error; | 798 FT_Error error; |
803 | 799 |
804 FT_GlyphLoader gloader = loader->gloader; | 800 FT_GlyphLoader gloader = loader->gloader; |
805 FT_Outline current_outline = gloader->current.outline; | 801 FT_Outline current_outline = gloader->current.outline; |
806 | 802 |
807 | 803 |
808 error = TT_Set_CodeRange( loader->exec, tt_coderange_glyph, | 804 TT_Set_CodeRange( loader->exec, tt_coderange_glyph, |
809 loader->exec->glyphIns, n_ins ); | 805 loader->exec->glyphIns, n_ins ); |
810 if ( error ) | |
811 return error; | |
812 | 806 |
813 loader->exec->is_composite = is_composite; | 807 loader->exec->is_composite = is_composite; |
814 loader->exec->pts = *zone; | 808 loader->exec->pts = *zone; |
815 | 809 |
816 debug = FT_BOOL( !( loader->load_flags & FT_LOAD_NO_SCALE ) && | 810 debug = FT_BOOL( !( loader->load_flags & FT_LOAD_NO_SCALE ) && |
817 ((TT_Size)loader->size)->debug ); | 811 ((TT_Size)loader->size)->debug ); |
818 | 812 |
819 error = TT_Run_Context( loader->exec, debug ); | 813 error = TT_Run_Context( loader->exec, debug ); |
820 if ( error && loader->exec->pedantic_hinting ) | 814 if ( error && loader->exec->pedantic_hinting ) |
821 return error; | 815 return error; |
822 | 816 |
823 /* store drop-out mode in bits 5-7; set bit 2 also as a marker */ | 817 /* store drop-out mode in bits 5-7; set bit 2 also as a marker */ |
824 current_outline.tags[0] |= | 818 current_outline.tags[0] |= |
825 ( loader->exec->GS.scan_type << 5 ) | FT_CURVE_TAG_HAS_SCANMODE; | 819 ( loader->exec->GS.scan_type << 5 ) | FT_CURVE_TAG_HAS_SCANMODE; |
826 } | 820 } |
827 | 821 |
828 #endif | 822 #endif |
829 | 823 |
830 /* save glyph phantom points */ | 824 /* save glyph phantom points */ |
831 if ( !loader->preserve_pps ) | 825 loader->pp1 = zone->cur[zone->n_points - 4]; |
832 { | 826 loader->pp2 = zone->cur[zone->n_points - 3]; |
833 loader->pp1 = zone->cur[zone->n_points - 4]; | 827 loader->pp3 = zone->cur[zone->n_points - 2]; |
834 loader->pp2 = zone->cur[zone->n_points - 3]; | 828 loader->pp4 = zone->cur[zone->n_points - 1]; |
835 loader->pp3 = zone->cur[zone->n_points - 2]; | |
836 loader->pp4 = zone->cur[zone->n_points - 1]; | |
837 } | |
838 | 829 |
839 #ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING | 830 #ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING |
840 if ( driver->interpreter_version == TT_INTERPRETER_VERSION_38 ) | 831 if ( driver->interpreter_version == TT_INTERPRETER_VERSION_38 ) |
841 { | 832 { |
842 if ( loader->exec->sph_tweak_flags & SPH_TWEAK_DEEMBOLDEN ) | 833 if ( loader->exec->sph_tweak_flags & SPH_TWEAK_DEEMBOLDEN ) |
843 FT_Outline_EmboldenXY( &loader->gloader->current.outline, -24, 0 ); | 834 FT_Outline_EmboldenXY( &loader->gloader->current.outline, -24, 0 ); |
844 | 835 |
845 else if ( loader->exec->sph_tweak_flags & SPH_TWEAK_EMBOLDEN ) | 836 else if ( loader->exec->sph_tweak_flags & SPH_TWEAK_EMBOLDEN ) |
846 FT_Outline_EmboldenXY( &loader->gloader->current.outline, 24, 0 ); | 837 FT_Outline_EmboldenXY( &loader->gloader->current.outline, 24, 0 ); |
847 } | 838 } |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
995 vec->y = FT_MulFix( vec->y, y_scale ); | 986 vec->y = FT_MulFix( vec->y, y_scale ); |
996 } | 987 } |
997 | 988 |
998 loader->pp1 = outline->points[n_points - 4]; | 989 loader->pp1 = outline->points[n_points - 4]; |
999 loader->pp2 = outline->points[n_points - 3]; | 990 loader->pp2 = outline->points[n_points - 3]; |
1000 loader->pp3 = outline->points[n_points - 2]; | 991 loader->pp3 = outline->points[n_points - 2]; |
1001 loader->pp4 = outline->points[n_points - 1]; | 992 loader->pp4 = outline->points[n_points - 1]; |
1002 } | 993 } |
1003 } | 994 } |
1004 | 995 |
1005 /**We Disable HINT except tricky font, seem it looks better, #Testdoc:000058
4_Open_CAC5U7WH.pdf, | 996 if ( IS_HINTED( loader->load_flags ) ) |
1006 » 0000879_Image_MSFNUnattendedPDF.pdf,0005480_sample-barcodes print.pdf. | |
1007 » */ | |
1008 » | |
1009 if ( IS_HINTED( loader->load_flags ) && (loader->face->face_flags&FT_FACE_FL
AG_TRICKY)) | |
1010 { | 997 { |
1011 loader->zone.n_points += 4; | 998 loader->zone.n_points += 4; |
1012 | 999 |
1013 error = TT_Hint_Glyph( loader, 0 ); | 1000 error = TT_Hint_Glyph( loader, 0 ); |
1014 } | 1001 } |
1015 | 1002 |
1016 return error; | 1003 return error; |
1017 } | 1004 } |
1018 | 1005 |
1019 | 1006 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1079 y = p1->y - p2->y; | 1066 y = p1->y - p2->y; |
1080 } | 1067 } |
1081 else | 1068 else |
1082 { | 1069 { |
1083 x = subglyph->arg1; | 1070 x = subglyph->arg1; |
1084 y = subglyph->arg2; | 1071 y = subglyph->arg2; |
1085 | 1072 |
1086 if ( !x && !y ) | 1073 if ( !x && !y ) |
1087 return FT_Err_Ok; | 1074 return FT_Err_Ok; |
1088 | 1075 |
1089 /* Use a default value dependent on */ | 1076 /* Use a default value dependent on */ |
1090 /* TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED. This is useful for old TT */ | 1077 /* TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED. This is useful for old */ |
1091 /* fonts which don't set the xxx_COMPONENT_OFFSET bit. */ | 1078 /* TT fonts which don't set the xxx_COMPONENT_OFFSET bit. */ |
1092 | 1079 |
1093 if ( have_scale && | 1080 if ( have_scale && |
1094 #ifdef TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED | 1081 #ifdef TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED |
1095 !( subglyph->flags & UNSCALED_COMPONENT_OFFSET ) ) | 1082 !( subglyph->flags & UNSCALED_COMPONENT_OFFSET ) ) |
1096 #else | 1083 #else |
1097 ( subglyph->flags & SCALED_COMPONENT_OFFSET ) ) | 1084 ( subglyph->flags & SCALED_COMPONENT_OFFSET ) ) |
1098 #endif | 1085 #endif |
1099 { | 1086 { |
1100 | 1087 |
1101 #if 0 | 1088 #if 0 |
1102 | 1089 |
1103 /*************************************************************************/ | 1090 /*******************************************************************/ |
1104 /* */ | 1091 /* */ |
1105 /* This algorithm is what Apple documents. But it doesn't work. */ | 1092 /* This algorithm is what Apple documents. But it doesn't work. */ |
1106 /* */ | 1093 /* */ |
1107 int a = subglyph->transform.xx > 0 ? subglyph->transform.xx | 1094 int a = subglyph->transform.xx > 0 ? subglyph->transform.xx |
1108 : -subglyph->transform.xx; | 1095 : -subglyph->transform.xx; |
1109 int b = subglyph->transform.yx > 0 ? subglyph->transform.yx | 1096 int b = subglyph->transform.yx > 0 ? subglyph->transform.yx |
1110 : -subglyph->transform.yx; | 1097 : -subglyph->transform.yx; |
1111 int c = subglyph->transform.xy > 0 ? subglyph->transform.xy | 1098 int c = subglyph->transform.xy > 0 ? subglyph->transform.xy |
1112 : -subglyph->transform.xy; | 1099 : -subglyph->transform.xy; |
1113 int d = subglyph->transform.yy > 0 ? subglyph->transform.yy | 1100 int d = subglyph->transform.yy > 0 ? subglyph->transform.yy |
1114 : -subglyph->transform.yy; | 1101 : -subglyph->transform.yy; |
1115 int m = a > b ? a : b; | 1102 int m = a > b ? a : b; |
1116 int n = c > d ? c : d; | 1103 int n = c > d ? c : d; |
1117 | 1104 |
1118 | 1105 |
1119 if ( a - b <= 33 && a - b >= -33 ) | 1106 if ( a - b <= 33 && a - b >= -33 ) |
1120 m *= 2; | 1107 m *= 2; |
1121 if ( c - d <= 33 && c - d >= -33 ) | 1108 if ( c - d <= 33 && c - d >= -33 ) |
1122 n *= 2; | 1109 n *= 2; |
1123 x = FT_MulFix( x, m ); | 1110 x = FT_MulFix( x, m ); |
1124 y = FT_MulFix( y, n ); | 1111 y = FT_MulFix( y, n ); |
1125 | 1112 |
1126 #else /* 0 */ | 1113 #else /* 1 */ |
1127 | 1114 |
1128 /*************************************************************************/ | 1115 /*******************************************************************/ |
1129 /* */ | 1116 /* */ |
1130 /* This algorithm is a guess and works much better than the above. */ | 1117 /* This algorithm is a guess and works much better than the above. */ |
1131 /* */ | 1118 /* */ |
1132 FT_Fixed mac_xscale = FT_Hypot( subglyph->transform.xx, | 1119 FT_Fixed mac_xscale = FT_Hypot( subglyph->transform.xx, |
1133 subglyph->transform.xy ); | 1120 subglyph->transform.xy ); |
1134 FT_Fixed mac_yscale = FT_Hypot( subglyph->transform.yy, | 1121 FT_Fixed mac_yscale = FT_Hypot( subglyph->transform.yy, |
1135 subglyph->transform.yx ); | 1122 subglyph->transform.yx ); |
1136 | 1123 |
1137 | 1124 |
1138 x = FT_MulFix( x, mac_xscale ); | 1125 x = FT_MulFix( x, mac_xscale ); |
1139 y = FT_MulFix( y, mac_yscale ); | 1126 y = FT_MulFix( y, mac_yscale ); |
1140 | 1127 |
1141 #endif /* 0 */ | 1128 #endif /* 1 */ |
1142 | 1129 |
1143 } | 1130 } |
1144 | 1131 |
1145 if ( !( loader->load_flags & FT_LOAD_NO_SCALE ) ) | 1132 if ( !( loader->load_flags & FT_LOAD_NO_SCALE ) ) |
1146 { | 1133 { |
1147 FT_Fixed x_scale = ((TT_Size)loader->size)->metrics.x_scale; | 1134 FT_Fixed x_scale = ((TT_Size)loader->size)->metrics.x_scale; |
1148 FT_Fixed y_scale = ((TT_Size)loader->size)->metrics.y_scale; | 1135 FT_Fixed y_scale = ((TT_Size)loader->size)->metrics.y_scale; |
1149 | 1136 |
1150 | 1137 |
1151 x = FT_MulFix( x, x_scale ); | 1138 x = FT_MulFix( x, x_scale ); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1220 if ( FT_STREAM_SEEK( loader->ins_pos ) || | 1207 if ( FT_STREAM_SEEK( loader->ins_pos ) || |
1221 FT_READ_USHORT( n_ins ) ) | 1208 FT_READ_USHORT( n_ins ) ) |
1222 return error; | 1209 return error; |
1223 | 1210 |
1224 FT_TRACE5(( " Instructions size = %d\n", n_ins )); | 1211 FT_TRACE5(( " Instructions size = %d\n", n_ins )); |
1225 | 1212 |
1226 /* check it */ | 1213 /* check it */ |
1227 max_ins = ((TT_Face)loader->face)->max_profile.maxSizeOfInstructions; | 1214 max_ins = ((TT_Face)loader->face)->max_profile.maxSizeOfInstructions; |
1228 if ( n_ins > max_ins ) | 1215 if ( n_ins > max_ins ) |
1229 { | 1216 { |
1230 /* acroread ignores this field, so we only do a rough safety check */ | 1217 /* don't trust `maxSizeOfInstructions'; */ |
| 1218 /* only do a rough safety check */ |
1231 if ( (FT_Int)n_ins > loader->byte_len ) | 1219 if ( (FT_Int)n_ins > loader->byte_len ) |
1232 { | 1220 { |
1233 FT_TRACE1(( "TT_Process_Composite_Glyph: " | 1221 FT_TRACE1(( "TT_Process_Composite_Glyph:" |
1234 "too many instructions (%d) for glyph with length %d\n", | 1222 " too many instructions (%d) for glyph with length %d\n", |
1235 n_ins, loader->byte_len )); | 1223 n_ins, loader->byte_len )); |
1236 return FT_THROW( Too_Many_Hints ); | 1224 return FT_THROW( Too_Many_Hints ); |
1237 } | 1225 } |
1238 | 1226 |
1239 tmp = loader->exec->glyphSize; | 1227 tmp = loader->exec->glyphSize; |
1240 error = Update_Max( loader->exec->memory, | 1228 error = Update_Max( loader->exec->memory, |
1241 &tmp, | 1229 &tmp, |
1242 sizeof ( FT_Byte ), | 1230 sizeof ( FT_Byte ), |
1243 (void*)&loader->exec->glyphIns, | 1231 (void*)&loader->exec->glyphIns, |
1244 n_ins ); | 1232 n_ins ); |
| 1233 |
1245 loader->exec->glyphSize = (FT_UShort)tmp; | 1234 loader->exec->glyphSize = (FT_UShort)tmp; |
1246 if ( error ) | 1235 if ( error ) |
1247 return error; | 1236 return error; |
1248 } | 1237 } |
1249 else if ( n_ins == 0 ) | 1238 else if ( n_ins == 0 ) |
1250 return FT_Err_Ok; | 1239 return FT_Err_Ok; |
1251 | 1240 |
1252 if ( FT_STREAM_READ( loader->exec->glyphIns, n_ins ) ) | 1241 if ( FT_STREAM_READ( loader->exec->glyphIns, n_ins ) ) |
1253 return error; | 1242 return error; |
1254 | 1243 |
1255 loader->glyph->control_data = loader->exec->glyphIns; | 1244 loader->glyph->control_data = loader->exec->glyphIns; |
1256 loader->glyph->control_len = n_ins; | 1245 loader->glyph->control_len = n_ins; |
1257 } | 1246 } |
1258 | 1247 |
1259 #endif | 1248 #endif |
1260 | 1249 |
1261 tt_prepare_zone( &loader->zone, &loader->gloader->base, | 1250 tt_prepare_zone( &loader->zone, &loader->gloader->base, |
1262 start_point, start_contour ); | 1251 start_point, start_contour ); |
1263 | 1252 |
1264 /* Some points are likely touched during execution of */ | 1253 /* Some points are likely touched during execution of */ |
1265 /* instructions on components. So let's untouch them. */ | 1254 /* instructions on components. So let's untouch them. */ |
1266 for ( i = start_point; i < loader->zone.n_points; i++ ) | 1255 for ( i = 0; i < loader->zone.n_points; i++ ) |
1267 loader->zone.tags[i] &= ~FT_CURVE_TAG_TOUCH_BOTH; | 1256 loader->zone.tags[i] &= ~FT_CURVE_TAG_TOUCH_BOTH; |
1268 | 1257 |
1269 loader->zone.n_points += 4; | 1258 loader->zone.n_points += 4; |
1270 | 1259 |
1271 return TT_Hint_Glyph( loader, 1 ); | 1260 return TT_Hint_Glyph( loader, 1 ); |
1272 } | 1261 } |
1273 | 1262 |
1274 | 1263 |
1275 /* Calculate the four phantom points. */ | 1264 /* |
1276 /* The first two stand for horizontal origin and advance. */ | 1265 * Calculate the phantom points |
1277 /* The last two stand for vertical origin and advance. */ | 1266 * |
| 1267 * Defining the right side bearing (rsb) as |
| 1268 * |
| 1269 * rsb = aw - (lsb + xmax - xmin) |
| 1270 * |
| 1271 * (with `aw' the advance width, `lsb' the left side bearing, and `xmin' |
| 1272 * and `xmax' the glyph's minimum and maximum x value), the OpenType |
| 1273 * specification defines the initial position of horizontal phantom points |
| 1274 * as |
| 1275 * |
| 1276 * pp1 = (round(xmin - lsb), 0) , |
| 1277 * pp2 = (round(pp1 + aw), 0) . |
| 1278 * |
| 1279 * Note that the rounding to the grid (in the device space) is not |
| 1280 * documented currently in the specification. |
| 1281 * |
| 1282 * However, the specification lacks the precise definition of vertical |
| 1283 * phantom points. Greg Hitchcock provided the following explanation. |
| 1284 * |
| 1285 * - a `vmtx' table is present |
| 1286 * |
| 1287 * For any glyph, the minimum and maximum y values (`ymin' and `ymax') |
| 1288 * are given in the `glyf' table, the top side bearing (tsb) and advance |
| 1289 * height (ah) are given in the `vmtx' table. The bottom side bearing |
| 1290 * (bsb) is then calculated as |
| 1291 * |
| 1292 * bsb = ah - (tsb + ymax - ymin) , |
| 1293 * |
| 1294 * and the initial position of vertical phantom points is |
| 1295 * |
| 1296 * pp3 = (x, round(ymax + tsb)) , |
| 1297 * pp4 = (x, round(pp3 - ah)) . |
| 1298 * |
| 1299 * See below for value `x'. |
| 1300 * |
| 1301 * - no `vmtx' table in the font |
| 1302 * |
| 1303 * If there is an `OS/2' table, we set |
| 1304 * |
| 1305 * DefaultAscender = sTypoAscender , |
| 1306 * DefaultDescender = sTypoDescender , |
| 1307 * |
| 1308 * otherwise we use data from the `hhea' table: |
| 1309 * |
| 1310 * DefaultAscender = Ascender , |
| 1311 * DefaultDescender = Descender . |
| 1312 * |
| 1313 * With these two variables we can now set |
| 1314 * |
| 1315 * ah = DefaultAscender - sDefaultDescender , |
| 1316 * tsb = DefaultAscender - yMax , |
| 1317 * |
| 1318 * and proceed as if a `vmtx' table was present. |
| 1319 * |
| 1320 * Usually we have |
| 1321 * |
| 1322 * x = aw / 2 , (1) |
| 1323 * |
| 1324 * but there is one compatibility case where it can be set to |
| 1325 * |
| 1326 * x = -DefaultDescender - |
| 1327 * ((DefaultAscender - DefaultDescender - aw) / 2) . (2) |
| 1328 * |
| 1329 * and another one with |
| 1330 * |
| 1331 * x = 0 . (3) |
| 1332 * |
| 1333 * In Windows, the history of those values is quite complicated, |
| 1334 * depending on the hinting engine (that is, the graphics framework). |
| 1335 * |
| 1336 * framework from to formula |
| 1337 * ---------------------------------------------------------- |
| 1338 * GDI Windows 98 current (1) |
| 1339 * (Windows 2000 for NT) |
| 1340 * GDI+ Windows XP Windows 7 (2) |
| 1341 * GDI+ Windows 8 current (3) |
| 1342 * DWrite Windows 7 current (3) |
| 1343 * |
| 1344 * For simplicity, FreeType uses (1) for grayscale subpixel hinting and |
| 1345 * (3) for everything else. |
| 1346 * |
| 1347 */ |
| 1348 #ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING |
| 1349 |
1278 #define TT_LOADER_SET_PP( loader ) \ | 1350 #define TT_LOADER_SET_PP( loader ) \ |
1279 do { \ | 1351 do \ |
| 1352 { \ |
| 1353 FT_Bool subpixel_ = loader->exec ? loader->exec->subpixel \ |
| 1354 : 0; \ |
| 1355 FT_Bool grayscale_ = loader->exec ? loader->exec->grayscale \ |
| 1356 : 0; \ |
| 1357 FT_Bool use_aw_2_ = (FT_Bool)( subpixel_ && grayscale_ ); \ |
| 1358 \ |
| 1359 \ |
1280 (loader)->pp1.x = (loader)->bbox.xMin - (loader)->left_bearing; \ | 1360 (loader)->pp1.x = (loader)->bbox.xMin - (loader)->left_bearing; \ |
1281 (loader)->pp1.y = 0; \ | 1361 (loader)->pp1.y = 0; \ |
1282 (loader)->pp2.x = (loader)->pp1.x + (loader)->advance; \ | 1362 (loader)->pp2.x = (loader)->pp1.x + (loader)->advance; \ |
1283 (loader)->pp2.y = 0; \ | 1363 (loader)->pp2.y = 0; \ |
| 1364 \ |
| 1365 (loader)->pp3.x = use_aw_2_ ? (loader)->advance / 2 : 0; \ |
| 1366 (loader)->pp3.y = (loader)->bbox.yMax + (loader)->top_bearing; \ |
| 1367 (loader)->pp4.x = use_aw_2_ ? (loader)->advance / 2 : 0; \ |
| 1368 (loader)->pp4.y = (loader)->pp3.y - (loader)->vadvance; \ |
| 1369 } while ( 0 ) |
| 1370 |
| 1371 #else /* !TT_CONFIG_OPTION_SUBPIXEL_HINTING */ |
| 1372 |
| 1373 #define TT_LOADER_SET_PP( loader ) \ |
| 1374 do \ |
| 1375 { \ |
| 1376 (loader)->pp1.x = (loader)->bbox.xMin - (loader)->left_bearing; \ |
| 1377 (loader)->pp1.y = 0; \ |
| 1378 (loader)->pp2.x = (loader)->pp1.x + (loader)->advance; \ |
| 1379 (loader)->pp2.y = 0; \ |
| 1380 \ |
1284 (loader)->pp3.x = 0; \ | 1381 (loader)->pp3.x = 0; \ |
1285 (loader)->pp3.y = (loader)->top_bearing + (loader)->bbox.yMax; \ | 1382 (loader)->pp3.y = (loader)->bbox.yMax + (loader)->top_bearing; \ |
1286 (loader)->pp4.x = 0; \ | 1383 (loader)->pp4.x = 0; \ |
1287 (loader)->pp4.y = (loader)->pp3.y - (loader)->vadvance; \ | 1384 (loader)->pp4.y = (loader)->pp3.y - (loader)->vadvance; \ |
1288 } while ( 0 ) | 1385 } while ( 0 ) |
1289 | 1386 |
| 1387 #endif /* !TT_CONFIG_OPTION_SUBPIXEL_HINTING */ |
| 1388 |
1290 | 1389 |
1291 /*************************************************************************/ | 1390 /*************************************************************************/ |
1292 /* */ | 1391 /* */ |
1293 /* <Function> */ | 1392 /* <Function> */ |
1294 /* load_truetype_glyph */ | 1393 /* load_truetype_glyph */ |
1295 /* */ | 1394 /* */ |
1296 /* <Description> */ | 1395 /* <Description> */ |
1297 /* Loads a given truetype glyph. Handles composites and uses a */ | 1396 /* Loads a given truetype glyph. Handles composites and uses a */ |
1298 /* TT_Loader object. */ | 1397 /* TT_Loader object. */ |
1299 /* */ | 1398 /* */ |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1343 { | 1442 { |
1344 x_scale = ((TT_Size)loader->size)->metrics.x_scale; | 1443 x_scale = ((TT_Size)loader->size)->metrics.x_scale; |
1345 y_scale = ((TT_Size)loader->size)->metrics.y_scale; | 1444 y_scale = ((TT_Size)loader->size)->metrics.y_scale; |
1346 } | 1445 } |
1347 else | 1446 else |
1348 { | 1447 { |
1349 x_scale = 0x10000L; | 1448 x_scale = 0x10000L; |
1350 y_scale = 0x10000L; | 1449 y_scale = 0x10000L; |
1351 } | 1450 } |
1352 | 1451 |
1353 tt_get_metrics( loader, glyph_index ); | |
1354 | |
1355 /* Set `offset' to the start of the glyph relative to the start of */ | 1452 /* Set `offset' to the start of the glyph relative to the start of */ |
1356 /* the `glyf' table, and `byte_len' to the length of the glyph in */ | 1453 /* the `glyf' table, and `byte_len' to the length of the glyph in */ |
1357 /* bytes. */ | 1454 /* bytes. */ |
1358 | 1455 |
1359 #ifdef FT_CONFIG_OPTION_INCREMENTAL | 1456 #ifdef FT_CONFIG_OPTION_INCREMENTAL |
1360 | 1457 |
1361 /* If we are loading glyph data via the incremental interface, set */ | 1458 /* If we are loading glyph data via the incremental interface, set */ |
1362 /* the loader stream to a memory stream reading the data returned */ | 1459 /* the loader stream to a memory stream reading the data returned */ |
1363 /* by the interface. */ | 1460 /* by the interface. */ |
1364 if ( face->root.internal->incremental_interface ) | 1461 if ( face->root.internal->incremental_interface ) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1404 error = face->access_glyph_frame( loader, glyph_index, | 1501 error = face->access_glyph_frame( loader, glyph_index, |
1405 loader->glyf_offset + offset, | 1502 loader->glyf_offset + offset, |
1406 loader->byte_len ); | 1503 loader->byte_len ); |
1407 if ( error ) | 1504 if ( error ) |
1408 goto Exit; | 1505 goto Exit; |
1409 | 1506 |
1410 opened_frame = 1; | 1507 opened_frame = 1; |
1411 | 1508 |
1412 /* read glyph header first */ | 1509 /* read glyph header first */ |
1413 error = face->read_glyph_header( loader ); | 1510 error = face->read_glyph_header( loader ); |
1414 if ( error || header_only ) | 1511 if ( error ) |
| 1512 goto Exit; |
| 1513 |
| 1514 /* the metrics must be computed after loading the glyph header */ |
| 1515 /* since we need the glyph's `yMax' value in case the vertical */ |
| 1516 /* metrics must be emulated */ |
| 1517 error = tt_get_metrics( loader, glyph_index ); |
| 1518 if ( error ) |
| 1519 goto Exit; |
| 1520 |
| 1521 if ( header_only ) |
1415 goto Exit; | 1522 goto Exit; |
1416 } | 1523 } |
1417 | 1524 |
1418 if ( loader->byte_len == 0 || loader->n_contours == 0 ) | 1525 if ( loader->byte_len == 0 || loader->n_contours == 0 ) |
1419 { | 1526 { |
1420 loader->bbox.xMin = 0; | 1527 loader->bbox.xMin = 0; |
1421 loader->bbox.xMax = 0; | 1528 loader->bbox.xMax = 0; |
1422 loader->bbox.yMin = 0; | 1529 loader->bbox.yMin = 0; |
1423 loader->bbox.yMax = 0; | 1530 loader->bbox.yMax = 0; |
1424 | 1531 |
| 1532 error = tt_get_metrics( loader, glyph_index ); |
| 1533 if ( error ) |
| 1534 goto Exit; |
| 1535 |
1425 if ( header_only ) | 1536 if ( header_only ) |
1426 goto Exit; | 1537 goto Exit; |
1427 | 1538 |
1428 /* must initialize points before (possibly) overriding */ | 1539 /* must initialize points before (possibly) overriding */ |
1429 /* glyph metrics from the incremental interface */ | 1540 /* glyph metrics from the incremental interface */ |
1430 TT_LOADER_SET_PP( loader ); | 1541 TT_LOADER_SET_PP( loader ); |
1431 | 1542 |
1432 #ifdef FT_CONFIG_OPTION_INCREMENTAL | 1543 #ifdef FT_CONFIG_OPTION_INCREMENTAL |
1433 tt_get_metrics_incr_overrides( loader, glyph_index ); | 1544 tt_get_metrics_incr_overrides( loader, glyph_index ); |
1434 #endif | 1545 #endif |
1435 | 1546 |
1436 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT | 1547 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT |
1437 | 1548 |
1438 if ( ((TT_Face)(loader->face))->doblend ) | 1549 if ( ((TT_Face)(loader->face))->doblend ) |
1439 { | 1550 { |
1440 /* this must be done before scaling */ | 1551 /* this must be done before scaling */ |
1441 FT_Memory memory = loader->face->memory; | 1552 FT_Memory memory = loader->face->memory; |
1442 | 1553 |
1443 | 1554 |
1444 error = TT_Vary_Get_Glyph_Deltas( (TT_Face)(loader->face), | 1555 error = TT_Vary_Get_Glyph_Deltas( (TT_Face)(loader->face), |
1445 glyph_index, &deltas, 4 ); | 1556 glyph_index, &deltas, 4 ); |
1446 if ( error ) | 1557 if ( error ) |
1447 goto Exit; | 1558 goto Exit; |
1448 | 1559 |
1449 loader->pp1.x += deltas[0].x; loader->pp1.y += deltas[0].y; | 1560 loader->pp1.x += deltas[0].x; |
1450 loader->pp2.x += deltas[1].x; loader->pp2.y += deltas[1].y; | 1561 loader->pp1.y += deltas[0].y; |
1451 loader->pp3.x += deltas[2].x; loader->pp3.y += deltas[2].y; | 1562 loader->pp2.x += deltas[1].x; |
1452 loader->pp4.x += deltas[3].x; loader->pp4.y += deltas[3].y; | 1563 loader->pp2.y += deltas[1].y; |
| 1564 |
| 1565 loader->pp3.x += deltas[2].x; |
| 1566 loader->pp3.y += deltas[2].y; |
| 1567 loader->pp4.x += deltas[3].x; |
| 1568 loader->pp4.y += deltas[3].y; |
1453 | 1569 |
1454 FT_FREE( deltas ); | 1570 FT_FREE( deltas ); |
1455 } | 1571 } |
1456 | 1572 |
1457 #endif | 1573 #endif /* TT_CONFIG_OPTION_GX_VAR_SUPPORT */ |
1458 | 1574 |
| 1575 /* scale phantom points, if necessary; */ |
| 1576 /* they get rounded in `TT_Hint_Glyph' */ |
1459 if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 ) | 1577 if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 ) |
1460 { | 1578 { |
1461 loader->pp1.x = FT_MulFix( loader->pp1.x, x_scale ); | 1579 loader->pp1.x = FT_MulFix( loader->pp1.x, x_scale ); |
1462 loader->pp2.x = FT_MulFix( loader->pp2.x, x_scale ); | 1580 loader->pp2.x = FT_MulFix( loader->pp2.x, x_scale ); |
| 1581 /* pp1.y and pp2.y are always zero */ |
| 1582 |
| 1583 loader->pp3.x = FT_MulFix( loader->pp3.x, x_scale ); |
1463 loader->pp3.y = FT_MulFix( loader->pp3.y, y_scale ); | 1584 loader->pp3.y = FT_MulFix( loader->pp3.y, y_scale ); |
| 1585 loader->pp4.x = FT_MulFix( loader->pp4.x, x_scale ); |
1464 loader->pp4.y = FT_MulFix( loader->pp4.y, y_scale ); | 1586 loader->pp4.y = FT_MulFix( loader->pp4.y, y_scale ); |
1465 } | 1587 } |
1466 | 1588 |
1467 error = FT_Err_Ok; | 1589 error = FT_Err_Ok; |
1468 goto Exit; | 1590 goto Exit; |
1469 } | 1591 } |
1470 | 1592 |
1471 /* must initialize points before (possibly) overriding */ | 1593 /* must initialize phantom points before (possibly) overriding */ |
1472 /* glyph metrics from the incremental interface */ | 1594 /* glyph metrics from the incremental interface */ |
1473 TT_LOADER_SET_PP( loader ); | 1595 TT_LOADER_SET_PP( loader ); |
1474 | 1596 |
1475 #ifdef FT_CONFIG_OPTION_INCREMENTAL | 1597 #ifdef FT_CONFIG_OPTION_INCREMENTAL |
1476 tt_get_metrics_incr_overrides( loader, glyph_index ); | 1598 tt_get_metrics_incr_overrides( loader, glyph_index ); |
1477 #endif | 1599 #endif |
1478 | 1600 |
1479 /***********************************************************************/ | 1601 /***********************************************************************/ |
1480 /***********************************************************************/ | 1602 /***********************************************************************/ |
1481 /***********************************************************************/ | 1603 /***********************************************************************/ |
1482 | 1604 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1535 FT_Memory memory = face->root.memory; | 1657 FT_Memory memory = face->root.memory; |
1536 | 1658 |
1537 | 1659 |
1538 /* this provides additional offsets */ | 1660 /* this provides additional offsets */ |
1539 /* for each component's translation */ | 1661 /* for each component's translation */ |
1540 | 1662 |
1541 if ( ( error = TT_Vary_Get_Glyph_Deltas( | 1663 if ( ( error = TT_Vary_Get_Glyph_Deltas( |
1542 face, | 1664 face, |
1543 glyph_index, | 1665 glyph_index, |
1544 &deltas, | 1666 &deltas, |
1545 gloader->current.num_subglyphs + 4 )) != 0 ) | 1667 gloader->current.num_subglyphs + 4 ) ) != 0 ) |
1546 goto Exit; | 1668 goto Exit; |
1547 | 1669 |
1548 subglyph = gloader->current.subglyphs + gloader->base.num_subglyphs; | 1670 subglyph = gloader->current.subglyphs + gloader->base.num_subglyphs; |
1549 limit = gloader->current.num_subglyphs; | 1671 limit = gloader->current.num_subglyphs; |
1550 | 1672 |
1551 for ( i = 0; i < limit; ++i, ++subglyph ) | 1673 for ( i = 0; i < limit; ++i, ++subglyph ) |
1552 { | 1674 { |
1553 if ( subglyph->flags & ARGS_ARE_XY_VALUES ) | 1675 if ( subglyph->flags & ARGS_ARE_XY_VALUES ) |
1554 { | 1676 { |
1555 /* XXX: overflow check for subglyph->{arg1,arg2}. */ | 1677 /* XXX: overflow check for subglyph->{arg1,arg2}. */ |
1556 /* deltas[i].{x,y} must be within signed 16-bit, */ | 1678 /* deltas[i].{x,y} must be within signed 16-bit, */ |
1557 /* but the restriction of summed delta is not clear */ | 1679 /* but the restriction of summed delta is not clear */ |
1558 subglyph->arg1 += (FT_Int16)deltas[i].x; | 1680 subglyph->arg1 += (FT_Int16)deltas[i].x; |
1559 subglyph->arg2 += (FT_Int16)deltas[i].y; | 1681 subglyph->arg2 += (FT_Int16)deltas[i].y; |
1560 } | 1682 } |
1561 } | 1683 } |
1562 | 1684 |
1563 loader->pp1.x += deltas[i + 0].x; loader->pp1.y += deltas[i + 0].y; | 1685 loader->pp1.x += deltas[i + 0].x; |
1564 loader->pp2.x += deltas[i + 1].x; loader->pp2.y += deltas[i + 1].y; | 1686 loader->pp1.y += deltas[i + 0].y; |
1565 loader->pp3.x += deltas[i + 2].x; loader->pp3.y += deltas[i + 2].y; | 1687 loader->pp2.x += deltas[i + 1].x; |
1566 loader->pp4.x += deltas[i + 3].x; loader->pp4.y += deltas[i + 3].y; | 1688 loader->pp2.y += deltas[i + 1].y; |
| 1689 |
| 1690 loader->pp3.x += deltas[i + 2].x; |
| 1691 loader->pp3.y += deltas[i + 2].y; |
| 1692 loader->pp4.x += deltas[i + 3].x; |
| 1693 loader->pp4.y += deltas[i + 3].y; |
1567 | 1694 |
1568 FT_FREE( deltas ); | 1695 FT_FREE( deltas ); |
1569 } | 1696 } |
1570 | 1697 |
1571 #endif /* TT_CONFIG_OPTION_GX_VAR_SUPPORT */ | 1698 #endif /* TT_CONFIG_OPTION_GX_VAR_SUPPORT */ |
1572 | 1699 |
| 1700 /* scale phantom points, if necessary; */ |
| 1701 /* they get rounded in `TT_Hint_Glyph' */ |
1573 if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 ) | 1702 if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 ) |
1574 { | 1703 { |
1575 loader->pp1.x = FT_MulFix( loader->pp1.x, x_scale ); | 1704 loader->pp1.x = FT_MulFix( loader->pp1.x, x_scale ); |
1576 loader->pp2.x = FT_MulFix( loader->pp2.x, x_scale ); | 1705 loader->pp2.x = FT_MulFix( loader->pp2.x, x_scale ); |
| 1706 /* pp1.y and pp2.y are always zero */ |
| 1707 |
| 1708 loader->pp3.x = FT_MulFix( loader->pp3.x, x_scale ); |
1577 loader->pp3.y = FT_MulFix( loader->pp3.y, y_scale ); | 1709 loader->pp3.y = FT_MulFix( loader->pp3.y, y_scale ); |
| 1710 loader->pp4.x = FT_MulFix( loader->pp4.x, x_scale ); |
1578 loader->pp4.y = FT_MulFix( loader->pp4.y, y_scale ); | 1711 loader->pp4.y = FT_MulFix( loader->pp4.y, y_scale ); |
1579 } | 1712 } |
1580 | 1713 |
1581 /* if the flag FT_LOAD_NO_RECURSE is set, we return the subglyph */ | 1714 /* if the flag FT_LOAD_NO_RECURSE is set, we return the subglyph */ |
1582 /* `as is' in the glyph slot (the client application will be */ | 1715 /* `as is' in the glyph slot (the client application will be */ |
1583 /* responsible for interpreting these data)... */ | 1716 /* responsible for interpreting these data)... */ |
1584 if ( loader->load_flags & FT_LOAD_NO_RECURSE ) | 1717 if ( loader->load_flags & FT_LOAD_NO_RECURSE ) |
1585 { | 1718 { |
1586 FT_GlyphLoader_Add( gloader ); | 1719 FT_GlyphLoader_Add( gloader ); |
1587 loader->glyph->format = FT_GLYPH_FORMAT_COMPOSITE; | 1720 loader->glyph->format = FT_GLYPH_FORMAT_COMPOSITE; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1627 num_base_points = gloader->base.outline.n_points; | 1760 num_base_points = gloader->base.outline.n_points; |
1628 | 1761 |
1629 error = load_truetype_glyph( loader, subglyph->index, | 1762 error = load_truetype_glyph( loader, subglyph->index, |
1630 recurse_count + 1, FALSE ); | 1763 recurse_count + 1, FALSE ); |
1631 if ( error ) | 1764 if ( error ) |
1632 goto Exit; | 1765 goto Exit; |
1633 | 1766 |
1634 /* restore subglyph pointer */ | 1767 /* restore subglyph pointer */ |
1635 subglyph = gloader->base.subglyphs + num_base_subgs + n; | 1768 subglyph = gloader->base.subglyphs + num_base_subgs + n; |
1636 | 1769 |
| 1770 /* restore phantom points if necessary */ |
1637 if ( !( subglyph->flags & USE_MY_METRICS ) ) | 1771 if ( !( subglyph->flags & USE_MY_METRICS ) ) |
1638 { | 1772 { |
1639 loader->pp1 = pp[0]; | 1773 loader->pp1 = pp[0]; |
1640 loader->pp2 = pp[1]; | 1774 loader->pp2 = pp[1]; |
1641 loader->pp3 = pp[2]; | 1775 loader->pp3 = pp[2]; |
1642 loader->pp4 = pp[3]; | 1776 loader->pp4 = pp[3]; |
1643 } | 1777 } |
1644 | 1778 |
1645 num_points = gloader->base.outline.n_points; | 1779 num_points = gloader->base.outline.n_points; |
1646 | 1780 |
1647 if ( num_points == num_base_points ) | 1781 if ( num_points == num_base_points ) |
1648 continue; | 1782 continue; |
1649 | 1783 |
1650 /* gloader->base.outline consists of three parts: */ | 1784 /* gloader->base.outline consists of three parts: */ |
1651 /* 0 -(1)-> start_point -(2)-> num_base_points -(3)-> n_points. */ | 1785 /* 0 -(1)-> start_point -(2)-> num_base_points -(3)-> n_points. */ |
1652 /* */ | 1786 /* */ |
1653 /* (1): exists from the beginning */ | 1787 /* (1): exists from the beginning */ |
1654 /* (2): components that have been loaded so far */ | 1788 /* (2): components that have been loaded so far */ |
1655 /* (3): the newly loaded component */ | 1789 /* (3): the newly loaded component */ |
1656 TT_Process_Composite_Component( loader, subglyph, start_point, | 1790 error = TT_Process_Composite_Component( loader, |
1657 num_base_points ); | 1791 subglyph, |
| 1792 start_point, |
| 1793 num_base_points ); |
| 1794 if ( error ) |
| 1795 goto Exit; |
1658 } | 1796 } |
1659 | 1797 |
1660 loader->stream = old_stream; | 1798 loader->stream = old_stream; |
1661 loader->byte_len = old_byte_len; | 1799 loader->byte_len = old_byte_len; |
1662 | 1800 |
1663 /* process the glyph */ | 1801 /* process the glyph */ |
1664 loader->ins_pos = ins_pos; | 1802 loader->ins_pos = ins_pos; |
1665 if ( IS_HINTED( loader->load_flags ) && | 1803 if ( IS_HINTED( loader->load_flags ) && |
1666 | |
1667 #ifdef TT_USE_BYTECODE_INTERPRETER | 1804 #ifdef TT_USE_BYTECODE_INTERPRETER |
1668 | |
1669 subglyph->flags & WE_HAVE_INSTR && | 1805 subglyph->flags & WE_HAVE_INSTR && |
1670 | |
1671 #endif | 1806 #endif |
1672 | |
1673 num_points > start_point ) | 1807 num_points > start_point ) |
1674 TT_Process_Composite_Glyph( loader, start_point, start_contour ); | 1808 { |
1675 | 1809 error = TT_Process_Composite_Glyph( loader, |
| 1810 start_point, |
| 1811 start_contour ); |
| 1812 if ( error ) |
| 1813 goto Exit; |
| 1814 } |
1676 } | 1815 } |
1677 } | 1816 } |
1678 else | 1817 else |
1679 { | 1818 { |
1680 /* invalid composite count (negative but not -1) */ | 1819 /* invalid composite count (negative but not -1) */ |
1681 error = FT_THROW( Invalid_Outline ); | 1820 error = FT_THROW( Invalid_Outline ); |
1682 goto Exit; | 1821 goto Exit; |
1683 } | 1822 } |
1684 | 1823 |
1685 /***********************************************************************/ | 1824 /***********************************************************************/ |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1940 #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */ | 2079 #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */ |
1941 | 2080 |
1942 | 2081 |
1943 static FT_Error | 2082 static FT_Error |
1944 tt_loader_init( TT_Loader loader, | 2083 tt_loader_init( TT_Loader loader, |
1945 TT_Size size, | 2084 TT_Size size, |
1946 TT_GlyphSlot glyph, | 2085 TT_GlyphSlot glyph, |
1947 FT_Int32 load_flags, | 2086 FT_Int32 load_flags, |
1948 FT_Bool glyf_table_only ) | 2087 FT_Bool glyf_table_only ) |
1949 { | 2088 { |
| 2089 FT_Error error; |
| 2090 |
1950 TT_Face face; | 2091 TT_Face face; |
1951 FT_Stream stream; | 2092 FT_Stream stream; |
1952 #ifdef TT_USE_BYTECODE_INTERPRETER | 2093 #ifdef TT_USE_BYTECODE_INTERPRETER |
1953 FT_Bool pedantic = FT_BOOL( load_flags & FT_LOAD_PEDANTIC ); | 2094 FT_Bool pedantic = FT_BOOL( load_flags & FT_LOAD_PEDANTIC ); |
1954 #endif | 2095 #endif |
1955 | 2096 |
1956 | 2097 |
1957 face = (TT_Face)glyph->face; | 2098 face = (TT_Face)glyph->face; |
1958 stream = face->root.stream; | 2099 stream = face->root.stream; |
1959 | 2100 |
1960 FT_MEM_ZERO( loader, sizeof ( TT_LoaderRec ) ); | 2101 FT_MEM_ZERO( loader, sizeof ( TT_LoaderRec ) ); |
1961 | 2102 |
1962 #ifdef TT_USE_BYTECODE_INTERPRETER | 2103 #ifdef TT_USE_BYTECODE_INTERPRETER |
1963 | 2104 |
1964 /* load execution context */ | 2105 /* load execution context */ |
1965 if ( IS_HINTED( load_flags ) && !glyf_table_only ) | 2106 if ( IS_HINTED( load_flags ) && !glyf_table_only ) |
1966 { | 2107 { |
1967 TT_ExecContext exec; | 2108 TT_ExecContext exec; |
1968 FT_Bool grayscale; | 2109 FT_Bool grayscale; |
1969 | 2110 |
1970 #ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING | 2111 #ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING |
1971 TT_Driver driver = (TT_Driver)FT_FACE_DRIVER( face ); | 2112 TT_Driver driver = (TT_Driver)FT_FACE_DRIVER( face ); |
1972 | 2113 |
1973 FT_Bool subpixel_hinting = FALSE; | 2114 FT_Bool subpixel = FALSE; |
1974 FT_Bool grayscale_hinting = TRUE; | |
1975 | 2115 |
1976 #if 0 | 2116 #if 0 |
1977 /* not used yet */ | 2117 /* not used yet */ |
1978 FT_Bool compatible_widths; | 2118 FT_Bool compatible_widths; |
1979 FT_Bool symmetrical_smoothing; | 2119 FT_Bool symmetrical_smoothing; |
1980 FT_Bool bgr; | 2120 FT_Bool bgr; |
1981 FT_Bool subpixel_positioned; | 2121 FT_Bool subpixel_positioned; |
1982 #endif | 2122 #endif |
1983 #endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ | 2123 #endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ |
1984 | 2124 |
1985 FT_Bool reexecute = FALSE; | 2125 FT_Bool reexecute = FALSE; |
1986 | 2126 |
1987 | 2127 |
1988 if ( !size->cvt_ready ) | 2128 if ( size->bytecode_ready < 0 || size->cvt_ready < 0 ) |
1989 { | 2129 { |
1990 FT_Error error = tt_size_ready_bytecode( size, pedantic ); | 2130 error = tt_size_ready_bytecode( size, pedantic ); |
1991 | |
1992 | |
1993 if ( error ) | 2131 if ( error ) |
1994 return error; | 2132 return error; |
1995 } | 2133 } |
| 2134 else if ( size->bytecode_ready ) |
| 2135 return size->bytecode_ready; |
| 2136 else if ( size->cvt_ready ) |
| 2137 return size->cvt_ready; |
1996 | 2138 |
1997 /* query new execution context */ | 2139 /* query new execution context */ |
1998 exec = size->debug ? size->context | 2140 exec = size->debug ? size->context |
1999 : ( (TT_Driver)FT_FACE_DRIVER( face ) )->context; | 2141 : ( (TT_Driver)FT_FACE_DRIVER( face ) )->context; |
2000 if ( !exec ) | 2142 if ( !exec ) |
2001 return FT_THROW( Could_Not_Find_Context ); | 2143 return FT_THROW( Could_Not_Find_Context ); |
2002 | 2144 |
2003 #ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING | 2145 #ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING |
2004 | 2146 |
2005 if ( driver->interpreter_version == TT_INTERPRETER_VERSION_38 ) | 2147 if ( driver->interpreter_version == TT_INTERPRETER_VERSION_38 ) |
2006 { | 2148 { |
2007 subpixel_hinting = FT_BOOL( ( FT_LOAD_TARGET_MODE( load_flags ) | 2149 subpixel = FT_BOOL( ( FT_LOAD_TARGET_MODE( load_flags ) != |
2008 != FT_RENDER_MODE_MONO ) && | 2150 FT_RENDER_MODE_MONO ) && |
2009 SPH_OPTION_SET_SUBPIXEL ); | 2151 SPH_OPTION_SET_SUBPIXEL ); |
2010 | 2152 |
2011 if ( subpixel_hinting ) | 2153 if ( subpixel ) |
2012 grayscale = grayscale_hinting = FALSE; | 2154 grayscale = FALSE; |
2013 else if ( SPH_OPTION_SET_GRAYSCALE ) | 2155 else if ( SPH_OPTION_SET_GRAYSCALE ) |
2014 { | 2156 { |
2015 grayscale = grayscale_hinting = TRUE; | 2157 grayscale = TRUE; |
2016 subpixel_hinting = FALSE; | 2158 subpixel = FALSE; |
2017 } | 2159 } |
2018 else | 2160 else |
2019 grayscale = grayscale_hinting = FALSE; | 2161 grayscale = FALSE; |
2020 | 2162 |
2021 if ( FT_IS_TRICKY( glyph->face ) ) | 2163 if ( FT_IS_TRICKY( glyph->face ) ) |
2022 subpixel_hinting = grayscale_hinting = FALSE; | 2164 subpixel = FALSE; |
2023 | 2165 |
2024 exec->ignore_x_mode = subpixel_hinting || grayscale_hinting; | 2166 exec->ignore_x_mode = subpixel || grayscale; |
2025 exec->rasterizer_version = SPH_OPTION_SET_RASTERIZER_VERSION; | 2167 exec->rasterizer_version = SPH_OPTION_SET_RASTERIZER_VERSION; |
2026 if ( exec->sph_tweak_flags & SPH_TWEAK_RASTERIZER_35 ) | 2168 if ( exec->sph_tweak_flags & SPH_TWEAK_RASTERIZER_35 ) |
2027 exec->rasterizer_version = TT_INTERPRETER_VERSION_35; | 2169 exec->rasterizer_version = TT_INTERPRETER_VERSION_35; |
2028 | 2170 |
2029 #if 1 | 2171 #if 1 |
2030 exec->compatible_widths = SPH_OPTION_SET_COMPATIBLE_WIDTHS; | 2172 exec->compatible_widths = SPH_OPTION_SET_COMPATIBLE_WIDTHS; |
2031 exec->symmetrical_smoothing = FALSE; | 2173 exec->symmetrical_smoothing = FALSE; |
2032 exec->bgr = FALSE; | 2174 exec->bgr = FALSE; |
2033 exec->subpixel_positioned = TRUE; | 2175 exec->subpixel_positioned = TRUE; |
2034 #else /* 0 */ | 2176 #else /* 0 */ |
(...skipping 14 matching lines...) Expand all Loading... |
2049 } | 2191 } |
2050 else | 2192 else |
2051 | 2193 |
2052 #endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ | 2194 #endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ |
2053 | 2195 |
2054 { | 2196 { |
2055 grayscale = FT_BOOL( FT_LOAD_TARGET_MODE( load_flags ) != | 2197 grayscale = FT_BOOL( FT_LOAD_TARGET_MODE( load_flags ) != |
2056 FT_RENDER_MODE_MONO ); | 2198 FT_RENDER_MODE_MONO ); |
2057 } | 2199 } |
2058 | 2200 |
2059 TT_Load_Context( exec, face, size ); | 2201 error = TT_Load_Context( exec, face, size ); |
| 2202 if ( error ) |
| 2203 return error; |
2060 | 2204 |
2061 #ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING | 2205 #ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING |
2062 | 2206 |
2063 if ( driver->interpreter_version == TT_INTERPRETER_VERSION_38 ) | 2207 if ( driver->interpreter_version == TT_INTERPRETER_VERSION_38 ) |
2064 { | 2208 { |
2065 /* a change from mono to subpixel rendering (and vice versa) */ | 2209 /* a change from mono to subpixel rendering (and vice versa) */ |
2066 /* requires a re-execution of the CVT program */ | 2210 /* requires a re-execution of the CVT program */ |
2067 if ( subpixel_hinting != exec->subpixel_hinting ) | 2211 if ( subpixel != exec->subpixel ) |
2068 { | 2212 { |
2069 FT_TRACE4(( "tt_loader_init: subpixel hinting change," | 2213 FT_TRACE4(( "tt_loader_init: subpixel hinting change," |
2070 " re-executing `prep' table\n" )); | 2214 " re-executing `prep' table\n" )); |
2071 | 2215 |
2072 exec->subpixel_hinting = subpixel_hinting; | 2216 exec->subpixel = subpixel; |
2073 reexecute = TRUE; | 2217 reexecute = TRUE; |
2074 } | 2218 } |
2075 | 2219 |
2076 /* a change from mono to grayscale rendering (and vice versa) */ | 2220 /* a change from mono to grayscale rendering (and vice versa) */ |
2077 /* requires a re-execution of the CVT program */ | 2221 /* requires a re-execution of the CVT program */ |
2078 if ( grayscale != exec->grayscale_hinting ) | 2222 if ( grayscale != exec->grayscale ) |
2079 { | 2223 { |
2080 FT_TRACE4(( "tt_loader_init: grayscale hinting change," | 2224 FT_TRACE4(( "tt_loader_init: grayscale hinting change," |
2081 " re-executing `prep' table\n" )); | 2225 " re-executing `prep' table\n" )); |
2082 | 2226 |
2083 exec->grayscale_hinting = grayscale_hinting; | 2227 exec->grayscale = grayscale; |
2084 reexecute = TRUE; | 2228 reexecute = TRUE; |
2085 } | 2229 } |
2086 } | 2230 } |
2087 else | 2231 else |
2088 | 2232 |
2089 #endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ | 2233 #endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */ |
2090 | 2234 |
2091 { | 2235 { |
2092 /* a change from mono to grayscale rendering (and vice versa) */ | 2236 /* a change from mono to grayscale rendering (and vice versa) */ |
2093 /* requires a re-execution of the CVT program */ | 2237 /* requires a re-execution of the CVT program */ |
2094 if ( grayscale != exec->grayscale ) | 2238 if ( grayscale != exec->grayscale ) |
2095 { | 2239 { |
2096 FT_TRACE4(( "tt_loader_init: grayscale change," | 2240 FT_TRACE4(( "tt_loader_init: grayscale change," |
2097 " re-executing `prep' table\n" )); | 2241 " re-executing `prep' table\n" )); |
2098 | 2242 |
2099 exec->grayscale = grayscale; | 2243 exec->grayscale = grayscale; |
2100 reexecute = TRUE; | 2244 reexecute = TRUE; |
2101 } | 2245 } |
2102 } | 2246 } |
2103 | 2247 |
2104 if ( reexecute ) | 2248 if ( reexecute ) |
2105 { | 2249 { |
2106 FT_UInt i; | 2250 FT_UInt i; |
2107 | 2251 |
2108 | 2252 |
2109 for ( i = 0; i < size->cvt_size; i++ ) | 2253 for ( i = 0; i < size->cvt_size; i++ ) |
2110 size->cvt[i] = FT_MulFix( face->cvt[i], size->ttmetrics.scale ); | 2254 size->cvt[i] = FT_MulFix( face->cvt[i], size->ttmetrics.scale ); |
2111 tt_size_run_prep( size, pedantic ); | 2255 error = tt_size_run_prep( size, pedantic ); |
| 2256 if ( error ) |
| 2257 return error; |
2112 } | 2258 } |
2113 | 2259 |
2114 /* see whether the cvt program has disabled hinting */ | 2260 /* see whether the cvt program has disabled hinting */ |
2115 if ( exec->GS.instruct_control & 1 ) | 2261 if ( exec->GS.instruct_control & 1 ) |
2116 load_flags |= FT_LOAD_NO_HINTING; | 2262 load_flags |= FT_LOAD_NO_HINTING; |
2117 | 2263 |
2118 /* load default graphics state -- if needed */ | 2264 /* load default graphics state -- if needed */ |
2119 if ( exec->GS.instruct_control & 2 ) | 2265 if ( exec->GS.instruct_control & 2 ) |
2120 exec->GS = tt_default_graphics_state; | 2266 exec->GS = tt_default_graphics_state; |
2121 | 2267 |
(...skipping 10 matching lines...) Expand all Loading... |
2132 | 2278 |
2133 #ifdef FT_CONFIG_OPTION_INCREMENTAL | 2279 #ifdef FT_CONFIG_OPTION_INCREMENTAL |
2134 | 2280 |
2135 if ( face->root.internal->incremental_interface ) | 2281 if ( face->root.internal->incremental_interface ) |
2136 loader->glyf_offset = 0; | 2282 loader->glyf_offset = 0; |
2137 else | 2283 else |
2138 | 2284 |
2139 #endif | 2285 #endif |
2140 | 2286 |
2141 { | 2287 { |
2142 FT_Error error = face->goto_table( face, TTAG_glyf, stream, 0 ); | 2288 error = face->goto_table( face, TTAG_glyf, stream, 0 ); |
2143 | |
2144 | 2289 |
2145 if ( FT_ERR_EQ( error, Table_Missing ) ) | 2290 if ( FT_ERR_EQ( error, Table_Missing ) ) |
2146 loader->glyf_offset = 0; | 2291 loader->glyf_offset = 0; |
2147 else if ( error ) | 2292 else if ( error ) |
2148 { | 2293 { |
2149 FT_ERROR(( "tt_loader_init: could not access glyph table\n" )); | 2294 FT_ERROR(( "tt_loader_init: could not access glyph table\n" )); |
2150 return error; | 2295 return error; |
2151 } | 2296 } |
2152 else | 2297 else |
2153 loader->glyf_offset = FT_STREAM_POS(); | 2298 loader->glyf_offset = FT_STREAM_POS(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2204 FT_LOCAL_DEF( FT_Error ) | 2349 FT_LOCAL_DEF( FT_Error ) |
2205 TT_Load_Glyph( TT_Size size, | 2350 TT_Load_Glyph( TT_Size size, |
2206 TT_GlyphSlot glyph, | 2351 TT_GlyphSlot glyph, |
2207 FT_UInt glyph_index, | 2352 FT_UInt glyph_index, |
2208 FT_Int32 load_flags ) | 2353 FT_Int32 load_flags ) |
2209 { | 2354 { |
2210 FT_Error error; | 2355 FT_Error error; |
2211 TT_LoaderRec loader; | 2356 TT_LoaderRec loader; |
2212 | 2357 |
2213 | 2358 |
2214 error = FT_Err_Ok; | 2359 FT_TRACE1(( "TT_Load_Glyph: glyph index %d\n", glyph_index )); |
2215 | 2360 |
2216 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS | 2361 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS |
2217 | 2362 |
2218 /* try to load embedded bitmap if any */ | 2363 /* try to load embedded bitmap if any */ |
2219 /* */ | 2364 /* */ |
2220 /* XXX: The convention should be emphasized in */ | 2365 /* XXX: The convention should be emphasized in */ |
2221 /* the documents because it can be confusing. */ | 2366 /* the documents because it can be confusing. */ |
2222 if ( size->strike_index != 0xFFFFFFFFUL && | 2367 if ( size->strike_index != 0xFFFFFFFFUL && |
2223 ( load_flags & FT_LOAD_NO_BITMAP ) == 0 ) | 2368 ( load_flags & FT_LOAD_NO_BITMAP ) == 0 ) |
2224 { | 2369 { |
2225 error = load_sbit_image( size, glyph, glyph_index, load_flags ); | 2370 error = load_sbit_image( size, glyph, glyph_index, load_flags ); |
2226 if ( !error ) | 2371 if ( !error ) |
2227 { | 2372 { |
2228 if ( FT_IS_SCALABLE( glyph->face ) ) | 2373 if ( FT_IS_SCALABLE( glyph->face ) ) |
2229 { | 2374 { |
2230 /* for the bbox we need the header only */ | 2375 /* for the bbox we need the header only */ |
2231 (void)tt_loader_init( &loader, size, glyph, load_flags, TRUE ); | 2376 (void)tt_loader_init( &loader, size, glyph, load_flags, TRUE ); |
2232 (void)load_truetype_glyph( &loader, glyph_index, 0, TRUE ); | 2377 (void)load_truetype_glyph( &loader, glyph_index, 0, TRUE ); |
2233 glyph->linearHoriAdvance = loader.linear; | 2378 glyph->linearHoriAdvance = loader.linear; |
2234 glyph->linearVertAdvance = loader.top_bearing + loader.bbox.yMax - | 2379 glyph->linearVertAdvance = loader.vadvance; |
2235 loader.vadvance; | |
2236 | 2380 |
2237 /* sanity check: if `horiAdvance' in the sbit metric */ | 2381 /* sanity checks: if `xxxAdvance' in the sbit metric */ |
2238 /* structure isn't set, use `linearHoriAdvance' */ | 2382 /* structure isn't set, use `linearXXXAdvance' */ |
2239 if ( !glyph->metrics.horiAdvance && glyph->linearHoriAdvance ) | 2383 if ( !glyph->metrics.horiAdvance && glyph->linearHoriAdvance ) |
2240 glyph->metrics.horiAdvance = | 2384 glyph->metrics.horiAdvance = |
2241 FT_MulFix( glyph->linearHoriAdvance, | 2385 FT_MulFix( glyph->linearHoriAdvance, |
2242 size->root.metrics.x_scale ); | 2386 size->root.metrics.x_scale ); |
| 2387 if ( !glyph->metrics.vertAdvance && glyph->linearVertAdvance ) |
| 2388 glyph->metrics.vertAdvance = |
| 2389 FT_MulFix( glyph->linearVertAdvance, |
| 2390 size->root.metrics.y_scale ); |
2243 } | 2391 } |
2244 | 2392 |
2245 return FT_Err_Ok; | 2393 return FT_Err_Ok; |
2246 } | 2394 } |
2247 } | 2395 } |
2248 | 2396 |
2249 #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */ | 2397 #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */ |
2250 | 2398 |
2251 /* if FT_LOAD_NO_SCALE is not set, `ttmetrics' must be valid */ | 2399 /* if FT_LOAD_NO_SCALE is not set, `ttmetrics' must be valid */ |
2252 if ( !( load_flags & FT_LOAD_NO_SCALE ) && !size->ttmetrics.valid ) | 2400 if ( !( load_flags & FT_LOAD_NO_SCALE ) && !size->ttmetrics.valid ) |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2312 glyph->outline.flags |= FT_OUTLINE_IGNORE_DROPOUTS; | 2460 glyph->outline.flags |= FT_OUTLINE_IGNORE_DROPOUTS; |
2313 break; | 2461 break; |
2314 } | 2462 } |
2315 } | 2463 } |
2316 else | 2464 else |
2317 glyph->outline.flags |= FT_OUTLINE_IGNORE_DROPOUTS; | 2465 glyph->outline.flags |= FT_OUTLINE_IGNORE_DROPOUTS; |
2318 } | 2466 } |
2319 | 2467 |
2320 #endif /* TT_USE_BYTECODE_INTERPRETER */ | 2468 #endif /* TT_USE_BYTECODE_INTERPRETER */ |
2321 | 2469 |
2322 compute_glyph_metrics( &loader, glyph_index ); | 2470 error = compute_glyph_metrics( &loader, glyph_index ); |
2323 } | 2471 } |
2324 | 2472 |
2325 /* Set the `high precision' bit flag. */ | 2473 /* Set the `high precision' bit flag. */ |
2326 /* This is _critical_ to get correct output for monochrome */ | 2474 /* This is _critical_ to get correct output for monochrome */ |
2327 /* TrueType glyphs at all sizes using the bytecode interpreter. */ | 2475 /* TrueType glyphs at all sizes using the bytecode interpreter. */ |
2328 /* */ | 2476 /* */ |
2329 if ( !( load_flags & FT_LOAD_NO_SCALE ) && | 2477 if ( !( load_flags & FT_LOAD_NO_SCALE ) && |
2330 size->root.metrics.y_ppem < 24 ) | 2478 size->root.metrics.y_ppem < 24 ) |
2331 glyph->outline.flags |= FT_OUTLINE_HIGH_PRECISION; | 2479 glyph->outline.flags |= FT_OUTLINE_HIGH_PRECISION; |
2332 | 2480 |
2333 return error; | 2481 return error; |
2334 } | 2482 } |
2335 | 2483 |
2336 | 2484 |
2337 /* END */ | 2485 /* END */ |
OLD | NEW |