📄 ttgload.c
字号:
if ( ( *flag & 32 ) == 0 ) y = -y; } else if ( ( *flag & 32 ) == 0 ) y = (FT_Pos)FT_GET_SHORT(); x += y; vec->y = x; } /* clear the touch tags */ for ( n = 0; n < n_points; n++ ) outline->tags[n] &= FT_CURVE_TAG_ON; outline->n_points = (FT_UShort)n_points; outline->n_contours = (FT_Short) n_contours; load->byte_len = byte_len; Fail: return error; Invalid_Outline: error = TT_Err_Invalid_Outline; goto Fail; } FT_CALLBACK_DEF( FT_Error ) TT_Load_Composite_Glyph( TT_Loader loader ) { FT_Error error; FT_Stream stream = loader->stream; FT_GlyphLoader gloader = loader->gloader; FT_SubGlyph subglyph; FT_UInt num_subglyphs; FT_Int byte_len = loader->byte_len; num_subglyphs = 0; do { FT_Fixed xx, xy, yy, yx; /* check that we can load a new subglyph */ error = FT_GlyphLoader_CheckSubGlyphs( gloader, num_subglyphs + 1 ); if ( error ) goto Fail; /* check space */ byte_len -= 4; if ( byte_len < 0 ) goto Invalid_Composite; subglyph = gloader->current.subglyphs + num_subglyphs; subglyph->arg1 = subglyph->arg2 = 0; subglyph->flags = FT_GET_USHORT(); subglyph->index = FT_GET_USHORT(); /* check space */ byte_len -= 2; if ( subglyph->flags & ARGS_ARE_WORDS ) byte_len -= 2; if ( subglyph->flags & WE_HAVE_A_SCALE ) byte_len -= 2; else if ( subglyph->flags & WE_HAVE_AN_XY_SCALE ) byte_len -= 4; else if ( subglyph->flags & WE_HAVE_A_2X2 ) byte_len -= 8; if ( byte_len < 0 ) goto Invalid_Composite; /* read arguments */ if ( subglyph->flags & ARGS_ARE_WORDS ) { subglyph->arg1 = FT_GET_SHORT(); subglyph->arg2 = FT_GET_SHORT(); } else { subglyph->arg1 = FT_GET_CHAR(); subglyph->arg2 = FT_GET_CHAR(); } /* read transform */ xx = yy = 0x10000L; xy = yx = 0; if ( subglyph->flags & WE_HAVE_A_SCALE ) { xx = (FT_Fixed)FT_GET_SHORT() << 2; yy = xx; } else if ( subglyph->flags & WE_HAVE_AN_XY_SCALE ) { xx = (FT_Fixed)FT_GET_SHORT() << 2; yy = (FT_Fixed)FT_GET_SHORT() << 2; } else if ( subglyph->flags & WE_HAVE_A_2X2 ) { xx = (FT_Fixed)FT_GET_SHORT() << 2; yx = (FT_Fixed)FT_GET_SHORT() << 2; xy = (FT_Fixed)FT_GET_SHORT() << 2; yy = (FT_Fixed)FT_GET_SHORT() << 2; } subglyph->transform.xx = xx; subglyph->transform.xy = xy; subglyph->transform.yx = yx; subglyph->transform.yy = yy; num_subglyphs++; } while ( subglyph->flags & MORE_COMPONENTS ); gloader->current.num_subglyphs = num_subglyphs;#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER { /* we must undo the FT_FRAME_ENTER in order to point to the */ /* composite instructions, if we find some. */ /* we will process them later... */ /* */ loader->ins_pos = (FT_ULong)( FT_STREAM_POS() + stream->cursor - stream->limit ); }#endif loader->byte_len = byte_len; Fail: return error; Invalid_Composite: error = TT_Err_Invalid_Composite; goto Fail; } FT_LOCAL_DEF( void ) TT_Init_Glyph_Loading( TT_Face face ) { face->access_glyph_frame = TT_Access_Glyph_Frame; face->read_glyph_header = TT_Load_Glyph_Header; face->read_simple_glyph = TT_Load_Simple_Glyph; face->read_composite_glyph = TT_Load_Composite_Glyph; face->forget_glyph_frame = TT_Forget_Glyph_Frame; } /*************************************************************************/ /* */ /* <Function> */ /* TT_Process_Simple_Glyph */ /* */ /* <Description> */ /* Once a simple glyph has been loaded, it needs to be processed. */ /* Usually, this means scaling and hinting through bytecode */ /* interpretation. */ /* */ static FT_Error TT_Process_Simple_Glyph( TT_Loader load, FT_Bool debug ) { FT_GlyphLoader gloader = load->gloader; FT_Outline* outline = &gloader->current.outline; FT_UInt n_points = outline->n_points;#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER FT_UInt n_ins;#endif TT_GlyphZone zone = &load->zone; FT_Error error = TT_Err_Ok; FT_UNUSED( debug ); /* used by truetype interpreter only */#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER n_ins = load->glyph->control_len;#endif /* add shadow points */ /* Now add the two shadow points at n and n + 1. */ /* We need the left side bearing and advance width. */ { FT_Vector* pp1; FT_Vector* pp2; /* pp1 = xMin - lsb */ pp1 = outline->points + n_points; pp1->x = load->bbox.xMin - load->left_bearing; pp1->y = 0; /* pp2 = pp1 + aw */ pp2 = pp1 + 1; pp2->x = pp1->x + load->advance; pp2->y = 0; outline->tags[n_points ] = 0; outline->tags[n_points + 1] = 0; } /* Note that we return two more points that are not */ /* part of the glyph outline. */ n_points += 2; /* set up zone for hinting */ tt_prepare_zone( zone, &gloader->current, 0, 0 ); /* eventually scale the glyph */ if ( !( load->load_flags & FT_LOAD_NO_SCALE ) ) { FT_Vector* vec = zone->cur; FT_Vector* limit = vec + n_points; FT_Fixed x_scale = load->size->metrics.x_scale; FT_Fixed y_scale = load->size->metrics.y_scale; /* first scale the glyph points */ for ( ; vec < limit; vec++ ) { vec->x = FT_MulFix( vec->x, x_scale ); vec->y = FT_MulFix( vec->y, y_scale ); } } cur_to_org( n_points, zone ); /* eventually hint the glyph */ if ( IS_HINTED( load->load_flags ) ) { FT_Pos x = zone->org[n_points-2].x; x = ( ( x + 32 ) & -64 ) - x; translate_array( n_points, zone->org, x, 0 ); org_to_cur( n_points, zone ); zone->cur[n_points - 1].x = ( zone->cur[n_points - 1].x + 32 ) & -64;#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER /* now consider hinting */ if ( n_ins > 0 ) { error = TT_Set_CodeRange( load->exec, tt_coderange_glyph, load->exec->glyphIns, n_ins ); if ( error ) goto Exit; load->exec->is_composite = FALSE; load->exec->pedantic_hinting = (FT_Bool)( load->load_flags & FT_LOAD_PEDANTIC ); load->exec->pts = *zone; load->exec->pts.n_points += 2; error = TT_Run_Context( load->exec, debug ); if ( error && load->exec->pedantic_hinting ) goto Exit; error = TT_Err_Ok; /* ignore bytecode errors in non-pedantic mode */ }#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */ } /* save glyph phantom points */ if ( !load->preserve_pps ) { load->pp1 = zone->cur[n_points - 2]; load->pp2 = zone->cur[n_points - 1]; }#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER Exit:#endif return error; } /*************************************************************************/ /* */ /* <Function> */ /* load_truetype_glyph */ /* */ /* <Description> */ /* Loads a given truetype glyph. Handles composites and uses a */ /* TT_Loader object. */ /* */ static FT_Error load_truetype_glyph( TT_Loader loader, FT_UInt glyph_index, FT_UInt recurse_count ) {#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER FT_Stream stream = loader->stream;#endif FT_Error error; TT_Face face = (TT_Face)loader->face; FT_ULong offset; FT_Int contours_count; FT_UInt num_points, count; FT_Fixed x_scale, y_scale; FT_GlyphLoader gloader = loader->gloader; FT_Bool opened_frame = 0;#ifdef FT_CONFIG_OPTION_INCREMENTAL struct FT_StreamRec_ inc_stream; FT_Data glyph_data; FT_Bool glyph_data_loaded = 0;#endif if ( recurse_count >= TT_MAX_COMPOSITE_RECURSE ) { error = TT_Err_Invalid_Composite; goto Exit; } /* check glyph index */ if ( glyph_index >= (FT_UInt)face->root.num_glyphs ) { error = TT_Err_Invalid_Glyph_Index; goto Exit; } loader->glyph_index = glyph_index; num_points = 0; x_scale = 0x10000L; y_scale = 0x10000L; if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 ) { x_scale = loader->size->metrics.x_scale; y_scale = loader->size->metrics.y_scale; } /* get horizontal metrics */ { FT_Short left_bearing = 0; FT_UShort advance_width = 0; Get_HMetrics( face, glyph_index, (FT_Bool)!( loader->load_flags & FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH ), &left_bearing, &advance_width );#ifdef FT_CONFIG_OPTION_INCREMENTAL /* If this is an incrementally loaded font see if there are */ /* overriding metrics for this glyph. */ if ( face->root.internal->incremental_interface && face->root.internal->incremental_interface->funcs->get_glyph_metrics ) { FT_Incremental_MetricsRec metrics; metrics.bearing_x = left_bearing; metrics.bearing_y = 0; metrics.advance = advance_width; error = face->root.internal->incremental_interface->funcs->get_glyph_metrics( face->root.internal->incremental_interface->object, glyph_index, FALSE, &metrics ); if ( error ) goto Exit; left_bearing = (FT_Short)metrics.bearing_x; advance_width = (FT_UShort)metrics.advance; }#endif /* FT_CONFIG_OPTION_INCREMENTAL */ loader->left_bearing = left_bearing; loader->advance = advance_width; if ( !loader->linear_def ) { loader->linear_def = 1; loader->linear = advance_width; } }#ifdef FT_CONFIG_OPTION_INCREMENTAL /* Set `offset' to the start of the glyph program relative to the */ /* start of the 'glyf' table, and `count' to the length of the */ /* glyph program in bytes. */ /* */ /* If we are loading glyph data via the incremental interface, set */ /* the loader stream to a memory stream reading the data returned */ /* by the interface. */ if ( face->root.internal->incremental_interface ) { error = face->root.internal->incremental_interface->funcs->get_glyph_data( face->root.internal->incremental_interface->object, glyph_index, &glyph_data ); if ( error ) goto Exit; glyph_data_loaded = 1; offset = 0; count = glyph_data.length; FT_MEM_ZERO( &inc_stream, sizeof ( inc_stream ) ); FT_Stream_OpenMemory( &inc_stream, glyph_data.pointer, glyph_data.length ); loader->stream = &inc_stream; } else#endif /* FT_CONFIG_OPTION_INCREMENTAL */ { offset = face->glyph_locations[glyph_index]; count = 0; if ( glyph_index < (FT_UInt)face->num_locations - 1 ) count = (FT_UInt)( face->glyph_locations[glyph_index + 1] - offset ); } if ( count == 0 ) { /* as described by Frederic Loyer, these are spaces, and */ /* not the unknown glyph. */ loader->bbox.xMin = 0; loader->bbox.xMax = 0; loader->bbox.yMin = 0; loader->bbox.yMax = 0; loader->pp1.x = 0; loader->pp2.x = loader->advance; if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 ) loader->pp2.x = FT_MulFix( loader->pp2.x, x_scale );#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -