From ae6699f86c42d3f81626eca1833d0537356f196a Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 14 Jan 2015 18:55:39 +0100 Subject: [PATCH] [autofit] Remove (unused) support for composite glyphs. We never have to deal with composite glyphs in the autohinter, as those will be loaded into FORMAT_OUTLINE by the recursed `FT_Load_Glyph' function. In the rare cases that FT_LOAD_NO_RECURSE is set, it will imply FT_LOAD_NO_SCALE as per `FT_Load_Glyph', which then implies FT_LOAD_NO_HINTING: /* resolve load flags dependencies */ if ( load_flags & FT_LOAD_NO_RECURSE ) load_flags |= FT_LOAD_NO_SCALE | FT_LOAD_IGNORE_TRANSFORM; if ( load_flags & FT_LOAD_NO_SCALE ) { load_flags |= FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP; load_flags &= ~FT_LOAD_RENDER; } and as such the auto-hinter is never called. Thus, the recursion in `af_loader_load_g' never actually happens. So remove the depth counter as well. * src/autofit/afloader.c (af_loader_load_g): Remove `depth' parameter. : Remove associated code. (af_loader_load_glyph): Updated. --- ChangeLog | 35 +++++++++++ src/autofit/afloader.c | 134 +++-------------------------------------- 2 files changed, 42 insertions(+), 127 deletions(-) diff --git a/ChangeLog b/ChangeLog index 72e4a7c2c..ba8c3ee66 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,38 @@ +2015-01-14 Behdad Esfahbod + + [autofit] Remove (unused) support for composite glyphs. + + We never have to deal with composite glyphs in the autohinter, as + those will be loaded into FORMAT_OUTLINE by the recursed + `FT_Load_Glyph' function. + + In the rare cases that FT_LOAD_NO_RECURSE is set, it will imply + FT_LOAD_NO_SCALE as per `FT_Load_Glyph', which then implies + FT_LOAD_NO_HINTING: + + /* resolve load flags dependencies */ + + if ( load_flags & FT_LOAD_NO_RECURSE ) + load_flags |= FT_LOAD_NO_SCALE | + FT_LOAD_IGNORE_TRANSFORM; + + if ( load_flags & FT_LOAD_NO_SCALE ) + { + load_flags |= FT_LOAD_NO_HINTING | + FT_LOAD_NO_BITMAP; + + load_flags &= ~FT_LOAD_RENDER; + } + + and as such the auto-hinter is never called. Thus, the recursion in + `af_loader_load_g' never actually happens. So remove the depth + counter as well. + + * src/autofit/afloader.c (af_loader_load_g): Remove `depth' + parameter. + : Remove associated code. + (af_loader_load_glyph): Updated. + 2015-01-14 Behdad Esfahbod [raster] Fix uninitialized memory access. diff --git a/src/autofit/afloader.c b/src/autofit/afloader.c index 612103cdb..a4c4968ef 100644 --- a/src/autofit/afloader.c +++ b/src/autofit/afloader.c @@ -89,16 +89,17 @@ } - /* Load a single glyph component. This routine calls itself */ - /* recursively, if necessary, and does the main work of */ - /* `af_loader_load_glyph.' */ + /* Do the main work of `af_loader_load_glyph'. Note that we never */ + /* have to deal with composite glyphs as those get loaded into */ + /* FT_GLYPH_FORMAT_OUTLINE by the recursed `FT_Load_Glyph' function. */ + /* In the rare cases where FT_LOAD_NO_RECURSE is set, it implies */ + /* FT_LOAD_NO_SCALE and as such the auto-hinter is never called. */ static FT_Error af_loader_load_g( AF_Loader loader, AF_Scaler scaler, FT_UInt glyph_index, - FT_Int32 load_flags, - FT_UInt depth ) + FT_Int32 load_flags ) { FT_Error error; FT_Face face = loader->face; @@ -265,133 +266,12 @@ FT_GlyphLoader_Add( gloader ); break; - case FT_GLYPH_FORMAT_COMPOSITE: - { - FT_UInt nn, num_subglyphs = slot->num_subglyphs; - FT_UInt num_base_subgs, start_point; - FT_SubGlyph subglyph; - - - start_point = gloader->base.outline.n_points; - - /* first of all, copy the subglyph descriptors in the glyph loader */ - error = FT_GlyphLoader_CheckSubGlyphs( gloader, num_subglyphs ); - if ( error ) - goto Exit; - - FT_ARRAY_COPY( gloader->current.subglyphs, - slot->subglyphs, - num_subglyphs ); - - gloader->current.num_subglyphs = num_subglyphs; - num_base_subgs = gloader->base.num_subglyphs; - - /* now read each subglyph independently */ - for ( nn = 0; nn < num_subglyphs; nn++ ) - { - FT_Vector pp1, pp2; - FT_Pos x, y; - FT_UInt num_points, num_new_points, num_base_points; - - - /* gloader.current.subglyphs can change during glyph loading due */ - /* to re-allocation -- we must recompute the current subglyph on */ - /* each iteration */ - subglyph = gloader->base.subglyphs + num_base_subgs + nn; - - pp1 = loader->pp1; - pp2 = loader->pp2; - - num_base_points = gloader->base.outline.n_points; - - error = af_loader_load_g( loader, scaler, subglyph->index, - load_flags, depth + 1 ); - if ( error ) - goto Exit; - - /* recompute subglyph pointer */ - subglyph = gloader->base.subglyphs + num_base_subgs + nn; - - if ( !( subglyph->flags & FT_SUBGLYPH_FLAG_USE_MY_METRICS ) ) - { - loader->pp1 = pp1; - loader->pp2 = pp2; - } - - num_points = gloader->base.outline.n_points; - num_new_points = num_points - num_base_points; - - /* now perform the transformation required for this subglyph */ - - if ( subglyph->flags & ( FT_SUBGLYPH_FLAG_SCALE | - FT_SUBGLYPH_FLAG_XY_SCALE | - FT_SUBGLYPH_FLAG_2X2 ) ) - { - FT_Vector* cur = gloader->base.outline.points + - num_base_points; - FT_Vector* limit = cur + num_new_points; - - - for ( ; cur < limit; cur++ ) - FT_Vector_Transform( cur, &subglyph->transform ); - } - - /* apply offset */ - - if ( !( subglyph->flags & FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES ) ) - { - FT_Int k = subglyph->arg1; - FT_UInt l = subglyph->arg2; - FT_Vector* p1; - FT_Vector* p2; - - - if ( start_point + k >= num_base_points || - l >= (FT_UInt)num_new_points ) - { - error = FT_THROW( Invalid_Composite ); - goto Exit; - } - - l += num_base_points; - - /* for now, only use the current point coordinates; */ - /* we eventually may consider another approach */ - p1 = gloader->base.outline.points + start_point + k; - p2 = gloader->base.outline.points + start_point + l; - - x = p1->x - p2->x; - y = p1->y - p2->y; - } - else - { - x = FT_MulFix( subglyph->arg1, hints->x_scale ) + hints->x_delta; - y = FT_MulFix( subglyph->arg2, hints->y_scale ) + hints->y_delta; - - x = FT_PIX_ROUND( x ); - y = FT_PIX_ROUND( y ); - } - - { - FT_Outline dummy = gloader->base.outline; - - - dummy.points += num_base_points; - dummy.n_points = (short)num_new_points; - - FT_Outline_Translate( &dummy, x, y ); - } - } - } - break; - default: /* we don't support other formats (yet?) */ error = FT_THROW( Unimplemented_Feature ); } Hint_Metrics: - if ( depth == 0 ) { FT_BBox bbox; FT_Vector vvector; @@ -558,7 +438,7 @@ goto Exit; } - error = af_loader_load_g( loader, &scaler, gindex, load_flags, 0 ); + error = af_loader_load_g( loader, &scaler, gindex, load_flags ); } } Exit: