OLD | NEW |
1 /***************************************************************************/ | 1 /***************************************************************************/ |
2 /* */ | 2 /* */ |
3 /* cffgload.c */ | 3 /* cffgload.c */ |
4 /* */ | 4 /* */ |
5 /* OpenType Glyph Loader (body). */ | 5 /* OpenType Glyph Loader (body). */ |
6 /* */ | 6 /* */ |
7 /* Copyright 1996-2013 by */ | 7 /* Copyright 1996-2014 by */ |
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ | 8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ |
9 /* */ | 9 /* */ |
10 /* This file is part of the FreeType project, and may only be used, */ | 10 /* This file is part of the FreeType project, and may only be used, */ |
11 /* modified, and distributed under the terms of the FreeType project */ | 11 /* modified, and distributed under the terms of the FreeType project */ |
12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ | 12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ |
13 /* this file you indicate that you have read the license and */ | 13 /* this file you indicate that you have read the license and */ |
14 /* understand and accept it fully. */ | 14 /* understand and accept it fully. */ |
15 /* */ | 15 /* */ |
16 /***************************************************************************/ | 16 /***************************************************************************/ |
17 | 17 |
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/ftstream.h" | 21 #include FT_INTERNAL_STREAM_H |
22 #include "../../include/freetype/internal/sfnt.h" | 22 #include FT_INTERNAL_SFNT_H |
23 #include "../../include/freetype/ftoutln.h" | 23 #include FT_OUTLINE_H |
24 #include "../../include/freetype/ftcffdrv.h" | 24 #include FT_CFF_DRIVER_H |
25 | 25 |
26 #include "cffobjs.h" | 26 #include "cffobjs.h" |
27 #include "cffload.h" | 27 #include "cffload.h" |
28 #include "cffgload.h" | 28 #include "cffgload.h" |
29 #include "cf2ft.h" /* for cf2_decoder_parse_charstrings */ | 29 #include "cf2ft.h" /* for cf2_decoder_parse_charstrings */ |
30 | 30 |
31 #include "cfferrs.h" | 31 #include "cfferrs.h" |
32 | 32 |
33 | 33 |
34 /*************************************************************************/ | 34 /*************************************************************************/ |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 FT_Byte fd_index = cff_fd_select_get( &cff->fd_select, glyph_index ); | 427 FT_Byte fd_index = cff_fd_select_get( &cff->fd_select, glyph_index ); |
428 | 428 |
429 | 429 |
430 if ( fd_index >= cff->num_subfonts ) | 430 if ( fd_index >= cff->num_subfonts ) |
431 { | 431 { |
432 FT_TRACE4(( "cff_decoder_prepare: invalid CID subfont index\n" )); | 432 FT_TRACE4(( "cff_decoder_prepare: invalid CID subfont index\n" )); |
433 error = FT_THROW( Invalid_File_Format ); | 433 error = FT_THROW( Invalid_File_Format ); |
434 goto Exit; | 434 goto Exit; |
435 } | 435 } |
436 | 436 |
437 FT_TRACE3(( "glyph index %d (subfont %d):\n", glyph_index, fd_index )); | 437 FT_TRACE3(( " in subfont %d:\n", fd_index )); |
438 | 438 |
439 sub = cff->subfonts[fd_index]; | 439 sub = cff->subfonts[fd_index]; |
440 | 440 |
441 if ( builder->hints_funcs && size ) | 441 if ( builder->hints_funcs && size ) |
442 { | 442 { |
443 CFF_Internal internal = (CFF_Internal)size->root.internal; | 443 CFF_Internal internal = (CFF_Internal)size->root.internal; |
444 | 444 |
445 | 445 |
446 /* for CFFs without subfonts, this value has already been set */ | 446 /* for CFFs without subfonts, this value has already been set */ |
447 builder->hints_globals = (void *)internal->subfonts[fd_index]; | 447 builder->hints_globals = (void *)internal->subfonts[fd_index]; |
448 } | 448 } |
449 } | 449 } |
450 #ifdef FT_DEBUG_LEVEL_TRACE | |
451 else | |
452 FT_TRACE3(( "glyph index %d:\n", glyph_index )); | |
453 #endif | |
454 | 450 |
455 decoder->num_locals = sub->local_subrs_index.count; | 451 decoder->num_locals = sub->local_subrs_index.count; |
456 decoder->locals = sub->local_subrs; | 452 decoder->locals = sub->local_subrs; |
457 decoder->locals_bias = cff_compute_bias( | 453 decoder->locals_bias = cff_compute_bias( |
458 decoder->cff->top_font.font_dict.charstring_type, | 454 decoder->cff->top_font.font_dict.charstring_type, |
459 decoder->num_locals ); | 455 decoder->num_locals ); |
460 | 456 |
461 decoder->glyph_width = sub->private_dict.default_width; | 457 decoder->glyph_width = sub->private_dict.default_width; |
462 decoder->nominal_width = sub->private_dict.nominal_width; | 458 decoder->nominal_width = sub->private_dict.nominal_width; |
463 | 459 |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 { | 696 { |
701 #ifndef FT_CONFIG_OPTION_INCREMENTAL | 697 #ifndef FT_CONFIG_OPTION_INCREMENTAL |
702 FT_UNUSED( length ); | 698 FT_UNUSED( length ); |
703 #endif | 699 #endif |
704 | 700 |
705 #ifdef FT_CONFIG_OPTION_INCREMENTAL | 701 #ifdef FT_CONFIG_OPTION_INCREMENTAL |
706 /* For incremental fonts get the character data using the */ | 702 /* For incremental fonts get the character data using the */ |
707 /* callback function. */ | 703 /* callback function. */ |
708 if ( face->root.internal->incremental_interface ) | 704 if ( face->root.internal->incremental_interface ) |
709 { | 705 { |
710 FT_Data data; | 706 FT_Data data; |
711 | 707 |
712 | 708 |
713 data.pointer = *pointer; | 709 data.pointer = *pointer; |
714 data.length = length; | 710 data.length = length; |
715 | 711 |
716 face->root.internal->incremental_interface->funcs->free_glyph_data( | 712 face->root.internal->incremental_interface->funcs->free_glyph_data( |
717 face->root.internal->incremental_interface->object, &data ); | 713 face->root.internal->incremental_interface->object, &data ); |
718 } | 714 } |
719 else | 715 else |
720 #endif /* FT_CONFIG_OPTION_INCREMENTAL */ | 716 #endif /* FT_CONFIG_OPTION_INCREMENTAL */ |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1176 break; | 1172 break; |
1177 case 35: | 1173 case 35: |
1178 op = cff_op_flex; | 1174 op = cff_op_flex; |
1179 break; | 1175 break; |
1180 case 36: | 1176 case 36: |
1181 op = cff_op_hflex1; | 1177 op = cff_op_hflex1; |
1182 break; | 1178 break; |
1183 case 37: | 1179 case 37: |
1184 op = cff_op_flex1; | 1180 op = cff_op_flex1; |
1185 break; | 1181 break; |
1186 /*default: */ /* XYQ 2007-9-6: we can't just quit if we see some re
served op */ | 1182 default: |
1187 /* decrement ip for syntax error message */ | 1183 FT_TRACE4(( " unknown op (12, %d)\n", v )); |
1188 /* ip--;*/ | 1184 break; |
1189 } | 1185 } |
1190 } | 1186 } |
1191 break; | 1187 break; |
1192 case 13: | 1188 case 13: |
1193 op = cff_op_hsbw; | 1189 op = cff_op_hsbw; |
1194 break; | 1190 break; |
1195 case 14: | 1191 case 14: |
1196 op = cff_op_endchar; | 1192 op = cff_op_endchar; |
1197 break; | 1193 break; |
1198 case 16: | 1194 case 16: |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1309 decoder->read_width = 0; | 1305 decoder->read_width = 0; |
1310 req_args = 0; | 1306 req_args = 0; |
1311 } | 1307 } |
1312 | 1308 |
1313 req_args &= 0x000F; | 1309 req_args &= 0x000F; |
1314 if ( num_args < req_args ) | 1310 if ( num_args < req_args ) |
1315 goto Stack_Underflow; | 1311 goto Stack_Underflow; |
1316 args -= req_args; | 1312 args -= req_args; |
1317 num_args -= req_args; | 1313 num_args -= req_args; |
1318 | 1314 |
1319 /* Sunliang.Liu sync 221's revison. */ | |
1320 if (args > decoder->stack + CFF_MAX_OPERANDS) | |
1321 goto Stack_Overflow; | |
1322 | |
1323 /* At this point, `args' points to the first argument of the */ | 1315 /* At this point, `args' points to the first argument of the */ |
1324 /* operand in case `req_args' isn't zero. Otherwise, we have */ | 1316 /* operand in case `req_args' isn't zero. Otherwise, we have */ |
1325 /* to adjust `args' manually. */ | 1317 /* to adjust `args' manually. */ |
1326 | 1318 |
1327 /* Note that we only pop arguments from the stack which we */ | 1319 /* Note that we only pop arguments from the stack which we */ |
1328 /* really need and can digest so that we can continue in case */ | 1320 /* really need and can digest so that we can continue in case */ |
1329 /* of superfluous stack elements. */ | 1321 /* of superfluous stack elements. */ |
1330 | 1322 |
1331 switch ( op ) | 1323 switch ( op ) |
1332 { | 1324 { |
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1990 | 1982 |
1991 error = cff_operator_seac( decoder, | 1983 error = cff_operator_seac( decoder, |
1992 0L, args[-4], args[-3], | 1984 0L, args[-4], args[-3], |
1993 (FT_Int)( args[-2] >> 16 ), | 1985 (FT_Int)( args[-2] >> 16 ), |
1994 (FT_Int)( args[-1] >> 16 ) ); | 1986 (FT_Int)( args[-1] >> 16 ) ); |
1995 | 1987 |
1996 decoder->glyph_width = glyph_width; | 1988 decoder->glyph_width = glyph_width; |
1997 } | 1989 } |
1998 else | 1990 else |
1999 { | 1991 { |
2000 if ( !error ) | |
2001 error = FT_Err_Ok; | |
2002 | |
2003 cff_builder_close_contour( builder ); | 1992 cff_builder_close_contour( builder ); |
2004 | 1993 |
2005 /* close hints recording session */ | 1994 /* close hints recording session */ |
2006 if ( hinter ) | 1995 if ( hinter ) |
2007 { | 1996 { |
2008 if ( hinter->close( hinter->hints, | 1997 if ( hinter->close( hinter->hints, |
2009 builder->current->n_points ) ) | 1998 builder->current->n_points ) ) |
2010 goto Syntax_Error; | 1999 goto Syntax_Error; |
2011 | 2000 |
2012 /* apply hints to the loaded glyph outline now */ | 2001 /* apply hints to the loaded glyph outline now */ |
2013 hinter->apply( hinter->hints, | 2002 error = hinter->apply( hinter->hints, |
2014 builder->current, | 2003 builder->current, |
2015 (PSH_Globals)builder->hints_globals, | 2004 (PSH_Globals)builder->hints_globals, |
2016 decoder->hint_mode ); | 2005 decoder->hint_mode ); |
| 2006 if ( error ) |
| 2007 goto Fail; |
2017 } | 2008 } |
2018 | 2009 |
2019 /* add current outline to the glyph slot */ | 2010 /* add current outline to the glyph slot */ |
2020 FT_GlyphLoader_Add( builder->loader ); | 2011 FT_GlyphLoader_Add( builder->loader ); |
2021 } | 2012 } |
2022 | 2013 |
2023 /* return now! */ | 2014 /* return now! */ |
2024 FT_TRACE4(( "\n" )); | 2015 FT_TRACE4(( "\n" )); |
2025 return error; | 2016 return error; |
2026 | 2017 |
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2712 glyph->root.bitmap_top = metrics.vertBearingY; | 2703 glyph->root.bitmap_top = metrics.vertBearingY; |
2713 } | 2704 } |
2714 else | 2705 else |
2715 { | 2706 { |
2716 glyph->root.bitmap_left = metrics.horiBearingX; | 2707 glyph->root.bitmap_left = metrics.horiBearingX; |
2717 glyph->root.bitmap_top = metrics.horiBearingY; | 2708 glyph->root.bitmap_top = metrics.horiBearingY; |
2718 } | 2709 } |
2719 | 2710 |
2720 /* compute linear advance widths */ | 2711 /* compute linear advance widths */ |
2721 | 2712 |
2722 ( (SFNT_Service)face->sfnt )->get_metrics( face, 0, | 2713 (void)( (SFNT_Service)face->sfnt )->get_metrics( face, 0, |
2723 glyph_index, | 2714 glyph_index, |
2724 &dummy, | 2715 &dummy, |
2725 &advance ); | 2716 &advance ); |
2726 glyph->root.linearHoriAdvance = advance; | 2717 glyph->root.linearHoriAdvance = advance; |
2727 | 2718 |
2728 has_vertical_info = FT_BOOL( | 2719 has_vertical_info = FT_BOOL( |
2729 face->vertical_info && | 2720 face->vertical_info && |
2730 face->vertical.number_Of_VMetrics > 0 ); | 2721 face->vertical.number_Of_VMetrics > 0 ); |
2731 | 2722 |
2732 /* get the vertical metrics from the vtmx table if we have one */ | 2723 /* get the vertical metrics from the vtmx table if we have one */ |
2733 if ( has_vertical_info ) | 2724 if ( has_vertical_info ) |
2734 { | 2725 { |
2735 ( (SFNT_Service)face->sfnt )->get_metrics( face, 1, | 2726 (void)( (SFNT_Service)face->sfnt )->get_metrics( face, 1, |
2736 glyph_index, | 2727 glyph_index, |
2737 &dummy, | 2728 &dummy, |
2738 &advance ); | 2729 &advance ); |
2739 glyph->root.linearVertAdvance = advance; | 2730 glyph->root.linearVertAdvance = advance; |
2740 } | 2731 } |
2741 else | 2732 else |
2742 { | 2733 { |
2743 /* make up vertical ones */ | 2734 /* make up vertical ones */ |
2744 if ( face->os2.version != 0xFFFFU ) | 2735 if ( face->os2.version != 0xFFFFU ) |
2745 glyph->root.linearVertAdvance = (FT_Pos) | 2736 glyph->root.linearVertAdvance = (FT_Pos) |
2746 ( face->os2.sTypoAscender - face->os2.sTypoDescender ); | 2737 ( face->os2.sTypoAscender - face->os2.sTypoDescender ); |
2747 else | 2738 else |
2748 glyph->root.linearVertAdvance = (FT_Pos) | 2739 glyph->root.linearVertAdvance = (FT_Pos) |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2965 has_vertical_info = FT_BOOL( face->vertical_info && | 2956 has_vertical_info = FT_BOOL( face->vertical_info && |
2966 face->vertical.number_Of_VMetrics > 0 ); | 2957 face->vertical.number_Of_VMetrics > 0 ); |
2967 | 2958 |
2968 /* get the vertical metrics from the vtmx table if we have one */ | 2959 /* get the vertical metrics from the vtmx table if we have one */ |
2969 if ( has_vertical_info ) | 2960 if ( has_vertical_info ) |
2970 { | 2961 { |
2971 FT_Short vertBearingY = 0; | 2962 FT_Short vertBearingY = 0; |
2972 FT_UShort vertAdvance = 0; | 2963 FT_UShort vertAdvance = 0; |
2973 | 2964 |
2974 | 2965 |
2975 ( (SFNT_Service)face->sfnt )->get_metrics( face, 1, | 2966 (void)( (SFNT_Service)face->sfnt )->get_metrics( face, 1, |
2976 glyph_index, | 2967 glyph_index, |
2977 &vertBearingY, | 2968 &vertBearingY, |
2978 &vertAdvance ); | 2969 &vertAdvance ); |
2979 metrics->vertBearingY = vertBearingY; | 2970 metrics->vertBearingY = vertBearingY; |
2980 metrics->vertAdvance = vertAdvance; | 2971 metrics->vertAdvance = vertAdvance; |
2981 } | 2972 } |
2982 else | 2973 else |
2983 { | 2974 { |
2984 /* make up vertical ones */ | 2975 /* make up vertical ones */ |
2985 if ( face->os2.version != 0xFFFFU ) | 2976 if ( face->os2.version != 0xFFFFU ) |
2986 metrics->vertAdvance = (FT_Pos)( face->os2.sTypoAscender - | 2977 metrics->vertAdvance = (FT_Pos)( face->os2.sTypoAscender - |
2987 face->os2.sTypoDescender ); | 2978 face->os2.sTypoDescender ); |
2988 else | 2979 else |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3063 metrics->vertAdvance ); | 3054 metrics->vertAdvance ); |
3064 } | 3055 } |
3065 } | 3056 } |
3066 } | 3057 } |
3067 | 3058 |
3068 return error; | 3059 return error; |
3069 } | 3060 } |
3070 | 3061 |
3071 | 3062 |
3072 /* END */ | 3063 /* END */ |
OLD | NEW |