📄 cffgload.c
字号:
if ( index >= 0 ) { while ( index > 0 ) { FT_Fixed tmp = args[count - 1]; FT_Int i; for ( i = count - 2; i >= 0; i-- ) args[i + 1] = args[i]; args[0] = tmp; index--; } } else { while ( index < 0 ) { FT_Fixed tmp = args[0]; FT_Int i; for ( i = 0; i < count - 1; i++ ) args[i] = args[i + 1]; args[count - 1] = tmp; index++; } } args += count; } break; case cff_op_dup: FT_TRACE4(( " dup" )); args[1] = args[0]; args++; break; case cff_op_put: { FT_Fixed val = args[0]; FT_Int index = (FT_Int)( args[1] >> 16 ); FT_TRACE4(( " put" )); if ( index >= 0 && index < decoder->len_buildchar ) decoder->buildchar[index] = val; } break; case cff_op_get: { FT_Int index = (FT_Int)( args[0] >> 16 ); FT_Fixed val = 0; FT_TRACE4(( " get" )); if ( index >= 0 && index < decoder->len_buildchar ) val = decoder->buildchar[index]; args[0] = val; args++; } break; case cff_op_store: FT_TRACE4(( " store ")); goto Unimplemented; case cff_op_load: FT_TRACE4(( " load" )); goto Unimplemented; case cff_op_dotsection: /* this operator is deprecated and ignored by the parser */ FT_TRACE4(( " dotsection" )); break; case cff_op_and: { FT_Fixed cond = args[0] && args[1]; FT_TRACE4(( " and" )); args[0] = cond ? 0x10000L : 0; args++; } break; case cff_op_or: { FT_Fixed cond = args[0] || args[1]; FT_TRACE4(( " or" )); args[0] = cond ? 0x10000L : 0; args++; } break; case cff_op_eq: { FT_Fixed cond = !args[0]; FT_TRACE4(( " eq" )); args[0] = cond ? 0x10000L : 0; args++; } break; case cff_op_ifelse: { FT_Fixed cond = (args[2] <= args[3]); FT_TRACE4(( " ifelse" )); if ( !cond ) args[0] = args[1]; args++; } break; case cff_op_callsubr: { FT_UInt index = (FT_UInt)( ( args[0] >> 16 ) + decoder->locals_bias ); FT_TRACE4(( " callsubr(%d)", index )); if ( index >= decoder->num_locals ) { FT_ERROR(( "CFF_Parse_CharStrings:" )); FT_ERROR(( " invalid local subr index\n" )); goto Syntax_Error; } if ( zone - decoder->zones >= CFF_MAX_SUBRS_CALLS ) { FT_ERROR(( "CFF_Parse_CharStrings: too many nested subrs\n" )); goto Syntax_Error; } zone->cursor = ip; /* save current instruction pointer */ zone++; zone->base = decoder->locals[index]; zone->limit = decoder->locals[index + 1]; zone->cursor = zone->base; if ( !zone->base ) { FT_ERROR(( "CFF_Parse_CharStrings: invoking empty subrs!\n" )); goto Syntax_Error; } decoder->zone = zone; ip = zone->base; limit = zone->limit; } break; case cff_op_callgsubr: { FT_UInt index = (FT_UInt)( ( args[0] >> 16 ) + decoder->globals_bias ); FT_TRACE4(( " callgsubr(%d)", index )); if ( index >= decoder->num_globals ) { FT_ERROR(( "CFF_Parse_CharStrings:" )); FT_ERROR(( " invalid global subr index\n" )); goto Syntax_Error; } if ( zone - decoder->zones >= CFF_MAX_SUBRS_CALLS ) { FT_ERROR(( "CFF_Parse_CharStrings: too many nested subrs\n" )); goto Syntax_Error; } zone->cursor = ip; /* save current instruction pointer */ zone++; zone->base = decoder->globals[index]; zone->limit = decoder->globals[index+1]; zone->cursor = zone->base; if ( !zone->base ) { FT_ERROR(( "CFF_Parse_CharStrings: invoking empty subrs!\n" )); goto Syntax_Error; } decoder->zone = zone; ip = zone->base; limit = zone->limit; } break; case cff_op_return: FT_TRACE4(( " return" )); if ( decoder->zone <= decoder->zones ) { FT_ERROR(( "CFF_Parse_CharStrings: unexpected return\n" )); goto Syntax_Error; } decoder->zone--; zone = decoder->zone; ip = zone->cursor; limit = zone->limit; break; default: Unimplemented: FT_ERROR(( "Unimplemented opcode: %d", ip[-1] )); if ( ip[-1] == 12 ) FT_ERROR(( " %d", ip[0] )); FT_ERROR(( "\n" )); return CFF_Err_Unimplemented_Feature; } decoder->top = args; } /* general operator processing */ } /* while ip < limit */ FT_TRACE4(( "..end..\n\n" )); return error; Syntax_Error: FT_TRACE4(( "CFF_Parse_CharStrings: syntax error!" )); return CFF_Err_Invalid_File_Format; Stack_Underflow: FT_TRACE4(( "CFF_Parse_CharStrings: stack underflow!" )); return CFF_Err_Too_Few_Arguments; Stack_Overflow: FT_TRACE4(( "CFF_Parse_CharStrings: stack overflow!" )); return CFF_Err_Stack_Overflow; Memory_Error: return builder->error; } /*************************************************************************/ /*************************************************************************/ /*************************************************************************/ /********** *********/ /********** *********/ /********** COMPUTE THE MAXIMUM ADVANCE WIDTH *********/ /********** *********/ /********** The following code is in charge of computing *********/ /********** the maximum advance width of the font. It *********/ /********** quickly processes each glyph charstring to *********/ /********** extract the value from either a `sbw' or `seac' *********/ /********** operator. *********/ /********** *********/ /*************************************************************************/ /*************************************************************************/ /*************************************************************************/#if 0 /* unused until we support pure CFF fonts */ FT_LOCAL_DEF FT_Error CFF_Compute_Max_Advance( TT_Face face, FT_Int* max_advance ) { FT_Error error = 0; CFF_Decoder decoder; FT_Int glyph_index; CFF_Font* cff = (CFF_Font*)face->other; *max_advance = 0; /* Initialize load decoder */ CFF_Init_Decoder( &decoder, face, 0, 0, 0 ); decoder.builder.metrics_only = 1; decoder.builder.load_points = 0; /* For each glyph, parse the glyph charstring and extract */ /* the advance width. */ for ( glyph_index = 0; glyph_index < face->root.num_glyphs; glyph_index++ ) { FT_Byte* charstring; FT_ULong charstring_len; /* now get load the unscaled outline */ error = CFF_Access_Element( &cff->charstrings_index, glyph_index, &charstring, &charstring_len ); if ( !error ) { CFF_Prepare_Decoder( &decoder, glyph_index ); error = CFF_Parse_CharStrings( &decoder, charstring, charstring_len ); CFF_Forget_Element( &cff->charstrings_index, &charstring ); } /* ignore the error if one has occurred -- skip to next glyph */ error = 0; } *max_advance = decoder.builder.advance.x; return CFF_Err_Ok; }#endif /* 0 */ /*************************************************************************/ /*************************************************************************/ /*************************************************************************/ /********** *********/ /********** *********/ /********** UNHINTED GLYPH LOADER *********/ /********** *********/ /********** The following code is in charge of loading a *********/ /********** single outline. It completely ignores hinting *********/ /********** and is used when FT_LOAD_NO_HINTING is set. *********/ /********** *********/ /*************************************************************************/ /*************************************************************************/ /*************************************************************************/ FT_LOCAL_DEF FT_Error CFF_Load_Glyph( CFF_GlyphSlot glyph, CFF_Size size, FT_Int glyph_index, FT_Int load_flags ) { FT_Error error; CFF_Decoder decoder; TT_Face face = (TT_Face)glyph->root.face; FT_Bool hinting; CFF_Font* cff = (CFF_Font*)face->extra.data; FT_Matrix font_matrix; FT_Vector font_offset; if ( load_flags & FT_LOAD_NO_RECURSE ) load_flags |= FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING; glyph->x_scale = 0x10000L; glyph->y_scale = 0x10000L; if ( size ) { glyph->x_scale = size->metrics.x_scale; glyph->y_scale = size->metrics.y_scale; } glyph->root.outline.n_points = 0; glyph->root.outline.n_contours = 0; hinting = FT_BOOL( ( load_flags & FT_LOAD_NO_SCALE ) == 0 && ( load_flags & FT_LOAD_NO_HINTING ) == 0 ); glyph->root.format = ft_glyph_format_outline; /* by default */ { FT_Byte* charstring; FT_ULong charstring_len; CFF_Init_Decoder( &decoder, face, size, glyph, hinting ); decoder.builder.no_recurse = (FT_Bool)( ( load_flags & FT_LOAD_NO_RECURSE ) != 0 ); /* now load the unscaled outline */ error = CFF_Access_Element( &cff->charstrings_index, glyph_index, &charstring, &charstring_len ); if ( !error ) { CFF_Index csindex = cff->charstrings_index; CFF_Prepare_Decoder( &decoder, glyph_index ); error = CFF_Parse_CharStrings( &decoder, charstring, charstring_len ); CFF_Forget_Element( &cff->charstrings_index, &charstring ); /* We set control_data and control_len if charstrings is loaded. */ /* See how charstring loads at CFF_Access_Element() in cffload.c. */ glyph->root.control_data = csindex.bytes + csindex.offsets[glyph_index] - 1; glyph->root.control_len = charstring_len; } /* save new glyph tables */ CFF_Builder_Done( &decoder.builder ); } font_matrix = cff->top_font.font_dict.font_matrix; font_offset = cff->top_font.font_dict.font_offset; /* Now, set the metrics -- this is rather simple, as */ /* the left side bearing is the xMin, and the top side */ /* bearing the yMax. */ if ( !error ) { /* For composite glyphs, return only left side bearing and */ /* advance width. */ if ( load_flags & FT_LOAD_NO_RECURSE ) { FT_Slot_Internal internal = glyph->root.internal; glyph->root.metrics.horiBearingX = decoder.builder.left_bearing.x; glyph->root.metrics.horiAdvance = decoder.glyph_width; internal->glyph_matrix = font_matrix; internal->glyph_delta = font_offset; internal->glyph_transformed = 1; } else { FT_BBox cbox; FT_Glyph_Metrics* metrics = &glyph->root.metrics; /* copy the _unscaled_ advance width */ metrics->horiAdvance = decoder.glyph_width; glyph->root.linearHoriAdvance = decoder.glyph_width; glyph->root.internal->glyph_tra
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -