20 #include FT_INTERNAL_DEBUG_H
21 #include FT_INTERNAL_STREAM_H
22 #include FT_INTERNAL_SFNT_H
39 #define FT_COMPONENT trace_cffgload
125 #define CFF_COUNT_CHECK_WIDTH 0x80
126 #define CFF_COUNT_EXACT 0x40
127 #define CFF_COUNT_CLEAR_STACK 0x20
257 builder->
glyph = glyph;
266 builder->
base = &loader->base.outline;
267 builder->
current = &loader->current.outline;
273 if ( hinting && size )
341 if ( in_charstring_type == 1 )
343 else if ( num_subrs < 1240 )
345 else if ( num_subrs < 33900U )
399 decoder->num_globals );
401 decoder->hint_mode = hint_mode;
426 FT_TRACE4((
"cff_decoder_prepare: invalid CID subfont index\n" ));
427 error = CFF_Err_Invalid_File_Format;
431 FT_TRACE3((
"glyph index %d (subfont %d):\n", glyph_index, fd_index ));
441 builder->
hints_globals = (
void *)
internal->subfonts[fd_index];
444 #ifdef FT_DEBUG_LEVEL_TRACE
446 FT_TRACE3((
"glyph index %d:\n", glyph_index ));
449 decoder->num_locals = sub->local_subrs_index.count;
450 decoder->locals = sub->local_subrs;
452 decoder->cff->top_font.font_dict.charstring_type,
453 decoder->num_locals );
455 decoder->glyph_width = sub->private_dict.default_width;
456 decoder->nominal_width = sub->private_dict.nominal_width;
589 if ( p1->
x == p2->
x && p1->
y == p2->
y )
598 if ( first == outline->
n_points - 1 )
623 if ( charcode < 0 || charcode > 255 )
645 #ifdef FT_CONFIG_OPTION_INCREMENTAL
652 face->
root.
internal->incremental_interface->funcs->get_glyph_data(
654 glyph_index, &data );
680 #ifndef FT_CONFIG_OPTION_INCREMENTAL
684 #ifdef FT_CONFIG_OPTION_INCREMENTAL
695 face->
root.
internal->incremental_interface->funcs->free_glyph_data(
696 face->
root.
internal->incremental_interface->object, &data );
720 FT_Int bchar_index, achar_index;
730 FT_ERROR((
"cff_operator_seac: invalid nested seac\n" ));
731 return CFF_Err_Syntax_Error;
737 #ifdef FT_CONFIG_OPTION_INCREMENTAL
755 if ( bchar_index < 0 || achar_index < 0 )
758 " invalid seac character code arguments\n" ));
759 return CFF_Err_Syntax_Error;
776 subg = loader->current.subglyphs;
779 subg->index = bchar_index;
787 subg->index = achar_index;
789 subg->arg1 = (
FT_Int)( adx >> 16 );
790 subg->arg2 = (
FT_Int)( ady >> 16 );
794 glyph->
subglyphs = loader->base.subglyphs;
795 glyph->
format = FT_GLYPH_FORMAT_COMPOSITE;
797 loader->current.num_subglyphs = 2;
804 &charstring, &charstring_len );
829 builder->
pos_x = adx - asb;
830 builder->
pos_y = ady;
834 &charstring, &charstring_len );
896 decoder->cff->top_font.font_dict.charstring_type;
902 decoder->num_hints = 0;
903 decoder->read_width = 1;
910 seed = ( seed ^ ( seed >> 10 ) ^ ( seed >> 20 ) ) & 0xFFFFL;
915 decoder->top = decoder->stack;
916 decoder->zone = decoder->zones;
917 zone = decoder->zones;
918 stack = decoder->top;
924 zone->
base = charstring_base;
925 limit = zone->
limit = charstring_base + charstring_len;
949 if ( v >= 32 || v == 28 )
958 if ( ip + 1 >= limit )
964 val = (FT_Int32)v - 139;
969 val = ( (FT_Int32)v - 247 ) * 256 + *ip++ + 108;
975 val = -( (FT_Int32)v - 251 ) * 256 - *ip++ - 108;
979 if ( ip + 3 >= limit )
981 val = ( (FT_Int32)ip[0] << 24 ) |
982 ( (FT_Int32)ip[1] << 16 ) |
983 ( (FT_Int32)ip[2] << 8 ) |
986 if ( charstring_type == 2 )
993 *decoder->top++ =
val;
995 #ifdef FT_DEBUG_LEVEL_TRACE
996 if ( !( val & 0xFFFFL ) )
997 FT_TRACE4((
" %ld", (FT_Int32)( val >> 16 ) ));
1161 FT_TRACE4((
" unknown op (12, %d)\n", v ));
1226 if ( num_args > 0 && decoder->read_width )
1243 set_width_ok = num_args & 2;
1253 set_width_ok = num_args & 1;
1259 set_width_ok = ( num_args == 5 ) || ( num_args == 1 );
1269 decoder->glyph_width = decoder->nominal_width +
1272 if ( decoder->width_only )
1283 decoder->read_width = 0;
1288 if ( num_args < req_args )
1289 goto Stack_Underflow;
1291 num_args -= req_args;
1317 args - ( num_args & ~1 ) );
1319 decoder->num_hints += num_args / 2;
1337 args - ( num_args & ~1 ) );
1339 decoder->num_hints += num_args / 2;
1347 if ( ( ip + ( ( decoder->num_hints + 7 ) >> 3 ) ) >= limit )
1363 #ifdef FT_DEBUG_LEVEL_TRACE
1371 maskbyte < (
FT_UInt)( ( decoder->num_hints + 7 ) >> 3 );
1378 ip += ( decoder->num_hints + 7 ) >> 3;
1419 goto Stack_Underflow;
1421 args -= num_args & ~1;
1422 while ( args < decoder->
top )
1442 goto Stack_Underflow;
1446 if ( num_args == 0 )
1454 while ( args < decoder->top )
1479 goto Stack_Underflow;
1481 nargs = num_args - num_args % 6;
1488 while ( args < decoder->top )
1513 goto Stack_Underflow;
1518 nargs = num_args & ~2;
1535 while ( args < decoder->top )
1558 goto Stack_Underflow;
1563 nargs = num_args & ~2;
1579 while ( args < decoder->top )
1602 :
" hvcurveto\n" ));
1608 goto Stack_Underflow;
1613 nargs = num_args & ~2;
1617 goto Stack_Underflow;
1621 while ( nargs >= 4 )
1664 goto Stack_Underflow;
1666 nargs = num_args & ~1;
1667 num_lines = ( nargs - 6 ) / 2;
1676 while ( num_lines > 0 )
1708 goto Stack_Underflow;
1710 nargs = num_args - 2;
1711 nargs = nargs - nargs % 6 + 2;
1712 num_curves = ( nargs - 2 ) / 6;
1721 while ( num_curves > 0 )
1870 for ( count = 5; count > 0; count-- )
1883 horizontal = ( dx > dy );
1885 for ( count = 5; count > 0; count-- )
1923 for ( count = 6; count > 0; count-- )
1928 (
FT_Bool)( count == 4 || count == 1 ) );
1940 args[0], args[1], args[2],
1941 (
FT_Int)( args[3] >> 16 ),
1942 (
FT_Int)( args[4] >> 16 ) );
1955 if ( num_args >= 4 )
1958 FT_Pos glyph_width = decoder->glyph_width;
1962 0L, args[-4], args[-3],
1963 (
FT_Int)( args[-2] >> 16 ),
1964 (
FT_Int)( args[-1] >> 16 ) );
1966 decoder->glyph_width = glyph_width;
1986 decoder->hint_mode );
2022 args[0] =
FT_DivFix( args[0], args[1] );
2041 if ( Rand >= 0x8000L )
2045 seed =
FT_MulFix( seed, 0x10000L - seed );
2055 args[0] =
FT_MulFix( args[0], args[1] );
2071 new_root = ( root +
FT_DivFix( args[0], root ) + 1 ) >> 1;
2072 if ( new_root == root || count <= 0 )
2112 else if ( idx > num_args - 2 )
2114 args[0] = args[-( idx + 1 )];
2132 goto Stack_Underflow;
2142 for ( i = count - 2; i >= 0; i-- )
2143 args[i + 1] = args[i];
2156 for ( i = 0; i < count - 1; i++ )
2157 args[i] = args[i + 1];
2158 args[count - 1] = tmp;
2182 decoder->buildchar[
idx] =
val;
2195 val = decoder->buildchar[
idx];
2222 FT_TRACE4((
" closepath (invalid op)\n" ));
2234 decoder->glyph_width = decoder->nominal_width + ( args[1] >> 16 );
2236 decoder->builder.left_bearing.x = args[0];
2237 decoder->builder.left_bearing.y = 0;
2239 x = decoder->builder.pos_x + args[0];
2240 y = decoder->builder.pos_y;
2251 decoder->glyph_width = decoder->nominal_width + ( args[2] >> 16 );
2253 decoder->builder.left_bearing.x = args[0];
2254 decoder->builder.left_bearing.y = args[1];
2256 x = decoder->builder.pos_x + args[0];
2257 y = decoder->builder.pos_y + args[1];
2266 FT_TRACE4((
" setcurrentpoint (invalid op)\n" ));
2268 x = decoder->builder.pos_x + args[0];
2269 y = decoder->builder.pos_y + args[1];
2278 FT_TRACE4((
" callothersubr (invalid op)\n" ));
2285 args -= 2 + ( args[-2] >> 16 );
2287 goto Stack_Underflow;
2318 FT_Fixed cond = args[0] && args[1];
2323 args[0] = cond ? 0x10000L : 0;
2330 FT_Fixed cond = args[0] || args[1];
2335 args[0] = cond ? 0x10000L : 0;
2347 args[0] = cond ? 0x10000L : 0;
2354 FT_Fixed cond = ( args[2] <= args[3] );
2368 decoder->locals_bias );
2373 if ( idx >= decoder->num_locals )
2375 FT_ERROR((
"cff_decoder_parse_charstrings:"
2376 " invalid local subr index\n" ));
2382 FT_ERROR((
"cff_decoder_parse_charstrings:"
2383 " too many nested subrs\n" ));
2390 zone->
base = decoder->locals[
idx];
2391 zone->
limit = decoder->locals[idx + 1];
2396 FT_ERROR((
"cff_decoder_parse_charstrings:"
2397 " invoking empty subrs\n" ));
2401 decoder->zone = zone;
2403 limit = zone->
limit;
2410 decoder->globals_bias );
2415 if ( idx >= decoder->num_globals )
2417 FT_ERROR((
"cff_decoder_parse_charstrings:"
2418 " invalid global subr index\n" ));
2424 FT_ERROR((
"cff_decoder_parse_charstrings:"
2425 " too many nested subrs\n" ));
2432 zone->
base = decoder->globals[
idx];
2433 zone->
limit = decoder->globals[idx + 1];
2438 FT_ERROR((
"cff_decoder_parse_charstrings:"
2439 " invoking empty subrs\n" ));
2443 decoder->zone = zone;
2445 limit = zone->
limit;
2452 if ( decoder->zone <= decoder->zones )
2454 FT_ERROR((
"cff_decoder_parse_charstrings:"
2455 " unexpected return\n" ));
2460 zone = decoder->zone;
2462 limit = zone->
limit;
2467 FT_ERROR((
"Unimplemented opcode: %d", ip[-1] ));
2473 return CFF_Err_Unimplemented_Feature;
2476 decoder->top = args;
2479 goto Stack_Overflow;
2491 FT_TRACE4((
"cff_decoder_parse_charstrings: syntax error\n" ));
2492 return CFF_Err_Invalid_File_Format;
2495 FT_TRACE4((
"cff_decoder_parse_charstrings: stack underflow\n" ));
2496 return CFF_Err_Too_Few_Arguments;
2499 FT_TRACE4((
"cff_decoder_parse_charstrings: stack overflow\n" ));
2500 return CFF_Err_Stack_Overflow;
2545 for ( glyph_index = 0; glyph_index < face->root.num_glyphs;
2554 &charstring, &charstring_len );
2583 FT_Int32 load_flags )
2588 FT_Bool hinting, force_scaling;
2595 force_scaling =
FALSE;
2604 if ( glyph_index != 0 )
2608 if ( glyph_index == 0 )
2609 return CFF_Err_Invalid_Argument;
2613 return CFF_Err_Invalid_Argument;
2618 glyph->x_scale = 0x10000L;
2619 glyph->y_scale = 0x10000L;
2622 glyph->x_scale = size->root.metrics.x_scale;
2623 glyph->y_scale = size->root.metrics.y_scale;
2626 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
2639 if ( size->strike_index != 0xFFFFFFFFUL &&
2646 error = sfnt->load_sbit_image( face,
2651 &glyph->root.bitmap,
2656 glyph->root.outline.n_points = 0;
2657 glyph->root.outline.n_contours = 0;
2659 glyph->root.metrics.width = (
FT_Pos)metrics.
width << 6;
2660 glyph->root.metrics.height = (
FT_Pos)metrics.
height << 6;
2670 glyph->root.format = FT_GLYPH_FORMAT_BITMAP;
2691 return CFF_Err_Invalid_Argument;
2713 if ( top_upm != sub_upm )
2715 glyph->x_scale =
FT_MulDiv( glyph->x_scale, top_upm, sub_upm );
2716 glyph->y_scale =
FT_MulDiv( glyph->y_scale, top_upm, sub_upm );
2718 force_scaling =
TRUE;
2727 glyph->root.outline.n_points = 0;
2728 glyph->root.outline.n_contours = 0;
2747 (
FT_Bool)( load_flags & FT_LOAD_NO_RECURSE );
2751 &charstring, &charstring_len );
2753 goto Glyph_Build_Finished;
2757 goto Glyph_Build_Finished;
2766 goto Glyph_Build_Finished;
2768 #ifdef FT_CONFIG_OPTION_INCREMENTAL
2773 glyph->root.control_data = 0;
2774 glyph->root.control_len = 0;
2786 if ( csindex->offsets )
2788 glyph->root.control_data = csindex->bytes +
2789 csindex->offsets[glyph_index] - 1;
2790 glyph->root.control_len = charstring_len;
2794 Glyph_Build_Finished:
2801 #ifdef FT_CONFIG_OPTION_INCREMENTAL
2806 face->
root.
internal->incremental_interface->funcs->get_glyph_metrics )
2816 error = face->
root.
internal->incremental_interface->funcs->get_glyph_metrics(
2818 glyph_index,
FALSE, &metrics );
2835 if ( load_flags & FT_LOAD_NO_RECURSE )
2841 glyph->root.metrics.horiAdvance = decoder.
glyph_width;
2842 internal->glyph_matrix = font_matrix;
2843 internal->glyph_delta = font_offset;
2844 internal->glyph_transformed = 1;
2856 glyph->root.linearHoriAdvance = decoder.
glyph_width;
2857 glyph->root.internal->glyph_transformed = 0;
2859 #ifdef FT_CONFIG_OPTION_OLD_INTERNALS
2869 if ( has_vertical_info )
2879 metrics->vertBearingY = vertBearingY;
2880 metrics->vertAdvance = vertAdvance;
2893 glyph->root.linearVertAdvance = metrics->vertAdvance;
2897 glyph->root.outline.flags = 0;
2898 if ( size && size->root.metrics.y_ppem < 24 )
2903 if ( !( font_matrix.
xx == 0x10000L &&
2904 font_matrix.
yy == 0x10000L &&
2905 font_matrix.
xy == 0 &&
2906 font_matrix.
yx == 0 ) )
2909 if ( !( font_offset.
x == 0 &&
2910 font_offset.
y == 0 ) )
2912 font_offset.
x, font_offset.
y );
2914 advance.
x = metrics->horiAdvance;
2917 metrics->horiAdvance = advance.
x + font_offset.
x;
2920 advance.
y = metrics->vertAdvance;
2922 metrics->vertAdvance = advance.
y + font_offset.
y;
2924 if ( ( load_flags & FT_LOAD_NO_SCALE ) == 0 || force_scaling )
2936 for ( n = cur->
n_points; n > 0; n--, vec++ )
2943 metrics->horiAdvance =
FT_MulFix( metrics->horiAdvance, x_scale );
2944 metrics->vertAdvance =
FT_MulFix( metrics->vertAdvance, y_scale );
2950 metrics->width = cbox.
xMax - cbox.
xMin;
2951 metrics->height = cbox.
yMax - cbox.
yMin;
2953 metrics->horiBearingX = cbox.
xMin;
2954 metrics->horiBearingY = cbox.
yMax;
2956 if ( has_vertical_info )
2957 metrics->vertBearingX = metrics->horiBearingX -
2958 metrics->horiAdvance / 2;
2963 metrics->vertAdvance );
typedefFT_BEGIN_HEADER struct PSH_GlobalsRec_ * PSH_Globals
cff_get_standard_encoding(FT_UInt charcode)
#define FT_LOAD_VERTICAL_LAYOUT
FT_DivFix(FT_Long a, FT_Long b)
GLuint const GLfloat * val
SFNT_Interface * SFNT_Service
static void cff_builder_close_contour(CFF_Builder *builder)
#define FT_LOAD_SBITS_ONLY
FT_BEGIN_HEADER typedef signed long FT_Pos
#define CFF_MAX_TRANS_ELEMENTS
ft_synthesize_vertical_metrics(FT_Glyph_Metrics *metrics, FT_Pos advance)
#define FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES
#define FT_MEM_ZERO(dest, count)
#define FT_SUBGLYPH_FLAG_USE_MY_METRICS
#define CFF_MAX_SUBRS_CALLS
#define FT_CURVE_TAG_CUBIC
static void cff_builder_init(CFF_Builder *builder, TT_Face face, CFF_Size size, CFF_GlyphSlot glyph, FT_Bool hinting)
enum FT_Render_Mode_ FT_Render_Mode
#define FT_LOAD_NO_HINTING
GLuint GLsizei GLsizei GLfloat * metrics
struct CFF_FontRec_ * CFF_Font
static FT_Error cff_operator_seac(CFF_Decoder *decoder, FT_Pos asb, FT_Pos adx, FT_Pos ady, FT_Int bchar, FT_Int achar)
#define FT_LOAD_NO_RECURSE
CFF_SubFont subfonts[CFF_MAX_CID_FONTS]
CFF_IndexRec global_subrs_index
static FT_Error cff_builder_start_point(CFF_Builder *builder, FT_Pos x, FT_Pos y)
#define FT_LOAD_ADVANCE_ONLY
cff_decoder_parse_charstrings(CFF_Decoder *decoder, FT_Byte *charstring_base, FT_ULong charstring_len)
FT_BEGIN_HEADER typedef unsigned char FT_Bool
FT_Face_Internal internal
static FT_Error cff_builder_add_contour(CFF_Builder *builder)
GLsizei const GLvoid * pointer
static const FT_Byte cff_argument_counts[]
typedefFT_BEGIN_HEADER struct FT_GlyphLoaderRec_ * FT_GlyphLoader
#define FT_ERROR(varformat)
cff_fd_select_get(CFF_FDSelect fdselect, FT_UInt glyph_index)
cff_index_access_element(CFF_Index idx, FT_UInt element, FT_Byte **pbytes, FT_ULong *pbyte_len)
struct CFF_InternalRec_ * CFF_Internal
FT_Size_Internal internal
#define FT_TRACE4(varformat)
FT_Outline_Get_CBox(const FT_Outline *outline, FT_BBox *acbox)
FT_GlyphLoader_Add(FT_GlyphLoader loader)
CFF_FontRecDictRec font_dict
cff_decoder_prepare(CFF_Decoder *decoder, CFF_Size size, FT_UInt glyph_index)
FT_Outline_Transform(const FT_Outline *outline, const FT_Matrix *matrix)
cff_decoder_init(CFF_Decoder *decoder, TT_Face face, CFF_Size size, CFF_GlyphSlot slot, FT_Bool hinting, FT_Render_Mode hint_mode)
struct TT_FaceRec_ * TT_Face
#define CFF_COUNT_CHECK_WIDTH
T2_Hints_CounterFunc counter
CFF_FDSelectRec fd_select
FT_GlyphLoader_CheckSubGlyphs(FT_GlyphLoader loader, FT_UInt n_subs)
FT_MulDiv(FT_Long a, FT_Long b, FT_Long c)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
#define FT_OUTLINE_HIGH_PRECISION
static FT_Error check_points(CFF_Builder *builder, FT_Int count)
GLfloat GLfloat GLfloat top
#define CFF_COUNT_CLEAR_STACK
cff_slot_load(CFF_GlyphSlot glyph, CFF_Size size, FT_UInt glyph_index, FT_Int32 load_flags)
static FT_Error cff_get_glyph_data(TT_Face face, FT_UInt glyph_index, FT_Byte **pointer, FT_ULong *length)
static void cff_free_glyph_data(TT_Face face, FT_Byte **pointer, FT_ULong length)
EGLSurface EGLint EGLint y
static void cff_builder_done(CFF_Builder *builder)
FT_MulFix(FT_Long a, FT_Long b)
static FT_Error cff_builder_add_point1(CFF_Builder *builder, FT_Pos x, FT_Pos y)
#define FT_TRACE3(varformat)
FT_Vector_Transform(FT_Vector *vec, const FT_Matrix *matrix)
FT_BEGIN_HEADER struct FT_Glyph_Metrics_ FT_Glyph_Metrics
struct T2_Hints_FuncsRec_ * T2_Hints_Funcs
static FT_Int cff_compute_bias(FT_Int in_charstring_type, FT_UInt num_subrs)
static void cff_builder_add_point(CFF_Builder *builder, FT_Pos x, FT_Pos y, FT_Byte flag)
struct FT_GlyphSlotRec_ * FT_GlyphSlot
FT_GlyphLoader_Rewind(FT_GlyphLoader loader)
static FT_Int cff_lookup_glyph_by_stdcharcode(CFF_Font cff, FT_Int charcode)
FT_Slot_Internal internal
cff_charset_cid_to_gindex(CFF_Charset charset, FT_UInt cid)
FT_Outline_Translate(const FT_Outline *outline, FT_Pos xOffset, FT_Pos yOffset)
FT_GlyphLoader_Prepare(FT_GlyphLoader loader)
CFF_IndexRec charstrings_index
#define FT_LOAD_NO_BITMAP
#define FT_GLYPHLOADER_CHECK_POINTS(_loader, _points, _contours)
enum CFF_Operator_ CFF_Operator
FT_Module_Constructor FT_GLYPH_FORMAT_OUTLINE
cff_index_forget_element(CFF_Index idx, FT_Byte **pbytes)
T2_Hints_MaskFunc hintmask
#define FT_OUTLINE_REVERSE_FILL
FT_BEGIN_HEADER struct CFF_IndexRec_ * CFF_Index
#define FT_LOAD_TARGET_MODE(x)