From 47103b2f195e0f9664c9470182f063cb7d41dc9f Mon Sep 17 00:00:00 2001 From: Alexei Podtelezhnikov Date: Sat, 18 Jun 2022 23:09:17 -0400 Subject: [PATCH] [truetype] Clean up phantom point accounting. This formalizes that the phantom points appended in the outline do not increase its point count, nor are they tagged or included in any additional contours. Only their coordinates are stored. They are counted in the glyph zone, however. * src/truetype/ttgxvar.c (TT_Vary_Apply_Glyph_Deltas): Infer `n_points` from the outline size plus four phantom points. * src/truetype/ttgxvar.h (TT_Vary_Apply_Glyph_Deltas): Remove this argument. * src/truetype/ttgload.c (tt_prepare_zone): Add phantom four. (TT_Process_Simple_Glyph, load_truetype_glyph): Update all callers. --- src/truetype/ttgload.c | 96 +++++++++++------------------------------- src/truetype/ttgxvar.c | 9 +--- src/truetype/ttgxvar.h | 3 +- 3 files changed, 28 insertions(+), 80 deletions(-) diff --git a/src/truetype/ttgload.c b/src/truetype/ttgload.c index d2f7496a1..00b795cda 100644 --- a/src/truetype/ttgload.c +++ b/src/truetype/ttgload.c @@ -801,7 +801,7 @@ FT_UInt start_point, FT_UInt start_contour ) { - zone->n_points = (FT_UShort)load->outline.n_points - + zone->n_points = (FT_UShort)load->outline.n_points + 4 - (FT_UShort)start_point; zone->n_contours = load->outline.n_contours - (FT_Short)start_contour; @@ -970,11 +970,6 @@ outline->points[n_points + 2] = loader->pp3; outline->points[n_points + 3] = loader->pp4; - outline->tags[n_points ] = 0; - outline->tags[n_points + 1] = 0; - outline->tags[n_points + 2] = 0; - outline->tags[n_points + 3] = 0; - n_points += 4; #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT @@ -987,8 +982,7 @@ /* Deltas apply to the unscaled data. */ error = TT_Vary_Apply_Glyph_Deltas( loader, outline, - unrounded, - (FT_UInt)n_points ); + unrounded ); if ( error ) goto Exit; } @@ -1000,7 +994,7 @@ tt_prepare_zone( &loader->zone, &gloader->current, 0, 0 ); FT_ARRAY_COPY( loader->zone.orus, loader->zone.cur, - loader->zone.n_points + 4 ); + loader->zone.n_points ); } { @@ -1142,11 +1136,7 @@ } if ( IS_HINTED( loader->load_flags ) ) - { - loader->zone.n_points += 4; - error = TT_Hint_Glyph( loader, 0 ); - } #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT Exit: @@ -1359,11 +1349,6 @@ outline->points[outline->n_points + 2] = loader->pp3; outline->points[outline->n_points + 3] = loader->pp4; - outline->tags[outline->n_points ] = 0; - outline->tags[outline->n_points + 1] = 0; - outline->tags[outline->n_points + 2] = 0; - outline->tags[outline->n_points + 3] = 0; - #ifdef TT_USE_BYTECODE_INTERPRETER { @@ -1422,11 +1407,9 @@ /* Some points are likely touched during execution of */ /* instructions on components. So let's untouch them. */ - for ( i = 0; i < loader->zone.n_points; i++ ) + for ( i = 0; i < loader->zone.n_points - 4; i++ ) loader->zone.tags[i] &= ~FT_CURVE_TAG_TOUCH_BOTH; - loader->zone.n_points += 4; - return TT_Hint_Glyph( loader, 1 ); } @@ -1747,35 +1730,27 @@ /* a small outline structure with four elements for */ /* communication with `TT_Vary_Apply_Glyph_Deltas' */ FT_Vector points[4]; - char tags[4] = { 1, 1, 1, 1 }; - short contours[4] = { 0, 1, 2, 3 }; FT_Outline outline; /* unrounded values */ FT_Vector unrounded[4] = { {0, 0}, {0, 0}, {0, 0}, {0, 0} }; - points[0].x = loader->pp1.x; - points[0].y = loader->pp1.y; - points[1].x = loader->pp2.x; - points[1].y = loader->pp2.y; + points[0] = loader->pp1; + points[1] = loader->pp2; + points[2] = loader->pp3; + points[3] = loader->pp4; - points[2].x = loader->pp3.x; - points[2].y = loader->pp3.y; - points[3].x = loader->pp4.x; - points[3].y = loader->pp4.y; - - outline.n_points = 4; - outline.n_contours = 4; + outline.n_points = 0; + outline.n_contours = 0; outline.points = points; - outline.tags = tags; - outline.contours = contours; + outline.tags = NULL; + outline.contours = NULL; /* this must be done before scaling */ error = TT_Vary_Apply_Glyph_Deltas( loader, &outline, - unrounded, - (FT_UInt)outline.n_points ); + unrounded ); if ( error ) goto Exit; } @@ -1925,17 +1900,16 @@ /* construct an outline structure for */ /* communication with `TT_Vary_Apply_Glyph_Deltas' */ - outline.n_points = (short)( gloader->current.num_subglyphs + 4 ); - outline.n_contours = outline.n_points; + outline.n_contours = outline.n_points = limit; outline.points = NULL; outline.tags = NULL; outline.contours = NULL; - if ( FT_NEW_ARRAY( points, outline.n_points ) || - FT_NEW_ARRAY( tags, outline.n_points ) || - FT_NEW_ARRAY( contours, outline.n_points ) || - FT_NEW_ARRAY( unrounded, outline.n_points ) ) + if ( FT_NEW_ARRAY( points, limit + 4 ) || + FT_NEW_ARRAY( tags, limit + 4 ) || + FT_NEW_ARRAY( contours, limit + 4 ) || + FT_NEW_ARRAY( unrounded, limit + 4 ) ) goto Exit1; subglyph = gloader->current.subglyphs; @@ -1951,28 +1925,10 @@ contours[i] = i; } - points[i].x = loader->pp1.x; - points[i].y = loader->pp1.y; - tags[i] = 1; - contours[i] = i; - - i++; - points[i].x = loader->pp2.x; - points[i].y = loader->pp2.y; - tags[i] = 1; - contours[i] = i; - - i++; - points[i].x = loader->pp3.x; - points[i].y = loader->pp3.y; - tags[i] = 1; - contours[i] = i; - - i++; - points[i].x = loader->pp4.x; - points[i].y = loader->pp4.y; - tags[i] = 1; - contours[i] = i; + points[i++] = loader->pp1; + points[i++] = loader->pp2; + points[i++] = loader->pp3; + points[i ] = loader->pp4; outline.points = points; outline.tags = tags; @@ -1980,11 +1936,9 @@ /* this call provides additional offsets */ /* for each component's translation */ - if ( FT_SET_ERROR( TT_Vary_Apply_Glyph_Deltas( - loader, - &outline, - unrounded, - (FT_UInt)outline.n_points ) ) ) + if ( FT_SET_ERROR( TT_Vary_Apply_Glyph_Deltas( loader, + &outline, + unrounded ) ) ) goto Exit1; subglyph = gloader->current.subglyphs; diff --git a/src/truetype/ttgxvar.c b/src/truetype/ttgxvar.c index 476f6a2f9..1bf9debb0 100644 --- a/src/truetype/ttgxvar.c +++ b/src/truetype/ttgxvar.c @@ -3839,25 +3839,20 @@ * An array with `n_points' elements that is filled with unrounded * point coordinates (in 26.6 format). * - * @Input - * n_points :: - * The number of the points in the glyph, including - * phantom points. - * * @Return: * FreeType error code. 0 means success. */ FT_LOCAL_DEF( FT_Error ) TT_Vary_Apply_Glyph_Deltas( TT_Loader loader, FT_Outline* outline, - FT_Vector* unrounded, - FT_UInt n_points ) + FT_Vector* unrounded ) { FT_Error error; TT_Face face = loader->face; FT_Stream stream = face->root.stream; FT_Memory memory = stream->memory; FT_UInt glyph_index = loader->glyph_index; + FT_UInt n_points = (FT_UInt)outline->n_points + 4; FT_Vector* points_org = NULL; /* coordinates in 16.16 format */ FT_Vector* points_out = NULL; /* coordinates in 16.16 format */ diff --git a/src/truetype/ttgxvar.h b/src/truetype/ttgxvar.h index b3db2fcd3..15c26373d 100644 --- a/src/truetype/ttgxvar.h +++ b/src/truetype/ttgxvar.h @@ -363,8 +363,7 @@ FT_BEGIN_HEADER FT_LOCAL( FT_Error ) TT_Vary_Apply_Glyph_Deltas( TT_Loader loader, FT_Outline* outline, - FT_Vector* unrounded, - FT_UInt n_points ); + FT_Vector* unrounded ); FT_LOCAL( FT_Error ) tt_hadvance_adjust( TT_Face face,