📄 t1gload.c
字号:
T1_Int achar ) { T1_Error error; T1_Face face = decoder->builder.face; T1_Int bchar_index, achar_index, n_base_points; FT_Outline* cur = &decoder->builder.current; FT_Outline* base = &decoder->builder.base; T1_Vector left_bearing, advance; T1_Font* type1 = &face->type1; bchar_index = lookup_glyph_by_stdcharcode( face, bchar ); achar_index = lookup_glyph_by_stdcharcode( face, achar ); if (bchar_index < 0 || achar_index < 0) { FT_ERROR(( "T1.Parse_Seac : invalid seac character code arguments\n" )); return T1_Err_Syntax_Error; } /* First load "bchar" in builder */ /* now load the unscaled outline */ cur->n_points = 0; cur->n_contours = 0; cur->points = base->points + base->n_points; cur->tags = base->tags + base->n_points; cur->contours = base->contours + base->n_contours; error = T1_Parse_CharStrings( decoder, type1->charstrings [bchar_index], type1->charstrings_len[bchar_index], type1->num_subrs, type1->subrs, type1->subrs_len ); if (error) return error; n_base_points = cur->n_points; /* save the left bearing and width of the base character */ /* as they will be erase by the next load.. */ left_bearing = decoder->builder.left_bearing; advance = decoder->builder.advance; decoder->builder.left_bearing.x = 0; decoder->builder.left_bearing.y = 0; /* Now load "achar" on top of */ /* the base outline */ /* */ cur->n_points = 0; cur->n_contours = 0; cur->points = base->points + base->n_points; cur->tags = base->tags + base->n_points; cur->contours = base->contours + base->n_contours; error = T1_Parse_CharStrings( decoder, type1->charstrings [achar_index], type1->charstrings_len[achar_index], type1->num_subrs, type1->subrs, type1->subrs_len ); if (error) return error; /* adjust contours in accented character outline */ if (decoder->builder.load_points) { T1_Int n; for ( n = 0; n < cur->n_contours; n++ ) cur->contours[n] += n_base_points; } /* restore the left side bearing and */ /* advance width of the base character */ decoder->builder.left_bearing = left_bearing; decoder->builder.advance = advance; /* Finally, move the accent */ if (decoder->builder.load_points) FT_Outline_Translate( cur, adx - asb, ady ); (void)asb; /* ignore this parameter */ return T1_Err_Ok; }/********************************************************************* * * <Function> * T1_Parse_CharStrings * * <Description> * Parses a given Type 1 charstrings program * * <Input> * decoder :: current Type 1 decoder * charstring_base :: base of the charstring stream * charstring_len :: length in bytes of the charstring stream * num_subrs :: number of sub-routines * subrs_base :: array of sub-routines addresses * subrs_len :: array of sub-routines lengths * * <Return> * Error code. 0 means success. * *********************************************************************/#define USE_ARGS(n) top -= n; if (top < decoder->stack) goto Stack_Underflow LOCAL_FUNC T1_Error T1_Parse_CharStrings( T1_Decoder* decoder, T1_Byte* charstring_base, T1_Int charstring_len, T1_Int num_subrs, T1_Byte** subrs_base, T1_Int* subrs_len ) { T1_Error error; T1_Decoder_Zone* zone; T1_Byte* ip; T1_Byte* limit; T1_Builder* builder = &decoder->builder; FT_Outline* outline; T1_Pos x, y; /* First of all, initialise the decoder */ decoder->top = decoder->stack; decoder->zone = decoder->zones; zone = decoder->zones; builder->path_begun = 0; zone->base = charstring_base; limit = zone->limit = charstring_base + charstring_len; ip = zone->cursor = zone->base; error = T1_Err_Ok; outline = &builder->current; x = builder->pos_x; y = builder->pos_y; /* now, execute loop */ while ( ip < limit ) { T1_Int* top = decoder->top; T1_Operator op = op_none; T1_Long value = 0; /********************************************************************/ /* */ /* Decode operator or operand */ /* */ /* */ /* First of all, decompress operator or value */ switch (*ip++) { case 1: op = op_hstem; break; case 3: op = op_vstem; break; case 4: op = op_vmoveto; break; case 5: op = op_rlineto; break; case 6: op = op_hlineto; break; case 7: op = op_vlineto; break; case 8: op = op_rrcurveto; break; case 9: op = op_closepath; break; case 10: op = op_callsubr; break; case 11: op = op_return; break; case 13: op = op_hsbw; break; case 14: op = op_endchar; break; case 21: op = op_rmoveto; break; case 22: op = op_hmoveto; break; case 30: op = op_vhcurveto; break; case 31: op = op_hvcurveto; break; case 12: { if (ip > limit) { FT_ERROR(( "T1.Parse_CharStrings : invalid escape (12+EOF)\n" )); goto Syntax_Error; } switch (*ip++) { case 0: op = op_dotsection; break; case 1: op = op_vstem3; break; case 2: op = op_hstem3; break; case 6: op = op_seac; break; case 7: op = op_sbw; break; case 12: op = op_div; break; case 16: op = op_callothersubr; break; case 17: op = op_pop; break; case 33: op = op_setcurrentpoint; break; default: FT_ERROR(( "T1.Parse_CharStrings : invalid escape (12+%d)\n", ip[-1] )); goto Syntax_Error; } } break; case 255: /* four bytes integer */ { if (ip+4 > limit) { FT_ERROR(( "T1.Parse_CharStrings : unexpected EOF in integer\n" )); goto Syntax_Error; } value = ((long)ip[0] << 24) | ((long)ip[1] << 16) | ((long)ip[2] << 8) | ip[3]; ip += 4; } break; default: if (ip[-1] >= 32) { if (ip[-1] < 247) value = (long)ip[-1] - 139; else { if (++ip > limit) { FT_ERROR(( "T1.Parse_CharStrings : unexpected EOF in integer\n" )); goto Syntax_Error; } if (ip[-2] < 251) value = ((long)(ip[-2]-247) << 8) + ip[-1] + 108; else value = -((((long)ip[-2]-251) << 8) + ip[-1] + 108 ); } } else { FT_ERROR(( "T1.Parse_CharStrings : invalid byte (%d)\n", ip[-1] )); goto Syntax_Error; } } /********************************************************************/ /* */ /* Push value on stack, or process operator */ /* */ /* */ if ( op == op_none ) { if ( top - decoder->stack >= T1_MAX_CHARSTRINGS_OPERANDS ) { FT_ERROR(( "T1.Parse_CharStrings : Stack overflow !!\n" )); goto Syntax_Error; } FT_TRACE4(( " %ld", value )); *top++ = value; decoder->top = top; } else if ( op == op_callothersubr ) /* callothersubr */ { FT_TRACE4(( " callothersubr" )); if ( top - decoder->stack < 2 ) goto Stack_Underflow; top -= 2; switch ( top[1] ) { case 1: /* start flex feature ---------------------- */ { if ( top[0] != 0 ) goto Unexpected_OtherSubr; decoder->flex_state = 1; decoder->num_flex_vectors = 0; if ( start_point(builder, x, y) || check_points(builder,6) ) goto Memory_Error; } break; case 2: /* add flex vectors ------------------------ */ { T1_Int index; if ( top[0] != 0 ) goto Unexpected_OtherSubr; /* note that we should not add a point for index 0 */ /* this will move our current position to the flex */ /* point without adding any point to the outline */ index = decoder->num_flex_vectors++; if (index > 0 && index < 7) add_point( builder, x, y, (T1_Byte)( index==3 || index==6 ) ); } break; case 0: /* end flex feature ------------------------- */ { if ( top[0] != 3 ) goto Unexpected_OtherSubr; if ( decoder->flex_state == 0 || decoder->num_flex_vectors != 7 ) { FT_ERROR(( "T1.Parse_CharStrings: unexpected flex end\n" )); goto Syntax_Error; } /* now consume the remaining "pop pop setcurpoint" */ if ( ip+6 > limit || ip[0] != 12 || ip[1] != 17 || /* pop */ ip[2] != 12 || ip[3] != 17 || /* pop */ ip[4] != 12 || ip[5] != 33 ) /* setcurpoint */ { FT_ERROR(( "T1.Parse_CharStrings: invalid flex charstring\n" )); goto Syntax_Error; } ip += 6; decoder->flex_state = 0; break; } case 3: /* change hints ---------------------------- */ { if ( top[0] != 1 ) goto Unexpected_OtherSubr; /* eat the following "pop" */ if (ip+2 > limit) { FT_ERROR(( "T1.Parse_CharStrings: invalid escape (12+%d)\n", ip[-1] )); goto Syntax_Error; } if (ip[0] != 12 || ip[1] != 17) { FT_ERROR(( "T1.Parse_CharStrings: 'pop' expected, found (%d %d)\n", ip[0], ip[1] )); goto Syntax_Error; } ip += 2; break;; } default: Unexpected_OtherSubr: FT_ERROR(( "T1.Parse_CharStrings: invalid othersubr [%d %d]!!\n", top[0], top[1] )); goto Syntax_Error; } decoder->top = top; } else /* general operator */ { T1_Int num_args = t1_args_count[op]; if ( top - decoder->stack < num_args ) goto Stack_Underflow; top -= num_args; switch (op) { case op_endchar: /*************************************************/ { FT_TRACE4(( " endchar" )); close_contour( builder ); /* add current outline to the glyph slot */ builder->base.n_points += builder->current.n_points; builder->base.n_contours += builder->current.n_contours; /* return now !! */ FT_TRACE4(( "\n\n" )); return T1_Err_Ok; } case op_hsbw: /****************************************************/ { FT_TRACE4(( " hsbw" )); builder->left_bearing.x += top[0]; builder->advance.x = top[1]; builder->advance.y = 0; builder->last.x = x = top[0]; builder->last.y = y = 0; /* the "metrics_only" indicates that we only want to compute */ /* the glyph's metrics (lsb + advance width), not load the */ /* rest of it.. so exit immediately */ if (builder->metrics_only) return T1_Err_Ok; break; } case op_seac: /****************************************************/ /* return immediately after the processing */ return t1operator_seac( decoder, top[0], top[1], top[2], top[3], top[4] ); case op_sbw: /****************************************************/ { FT_TRACE4(( " sbw" )); builder->left_bearing.x += top[0]; builder->left_bearing.y += top[1]; builder->advance.x = top[2]; builder->advance.y = top[3]; builder->last.x = x = top[0]; builder->last.y = y = top[1]; /* the "metrics_only" indicates that we only want to compute */ /* the glyph's metrics (lsb + advance width), not load the */ /* rest of it.. so exit immediately */ if (builder->metrics_only) return T1_Err_Ok; break; } case op_closepath: /**********************************************/ { FT_TRACE4(( " closepath" )); close_contour( builder ); builder->path_begun = 0; } break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -