From b457aeee675f3dfa60a81159061566dc57ebfe52 Mon Sep 17 00:00:00 2001 From: Anuj Verma Date: Wed, 12 Aug 2020 11:52:16 +0530 Subject: [PATCH] [sdf] Handle Post-Script fonts for overlap. * src/sdf/ftsdf.c (sdf_generate_with_overlaps): Handle Handle Post-Script fonts for overlap support. Simply flip the orientation while combining all the separate SDF. Also, handle the `flip_sign' property separately so as to avoid handling extra cases. --- [GSoC]ChangeLog | 11 +++++++++++ src/sdf/ftsdf.c | 27 ++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/[GSoC]ChangeLog b/[GSoC]ChangeLog index fef32de43..c70040d31 100644 --- a/[GSoC]ChangeLog +++ b/[GSoC]ChangeLog @@ -1,3 +1,14 @@ +2020-08-12 Anuj Verma + + [sdf] Handle Post-Script fonts for overlap. + + * src/sdf/ftsdf.c (sdf_generate_with_overlaps): Handle + Handle Post-Script fonts for overlap support. Simply + flip the orientation while combining all the separate + SDF. + Also, handle the `flip_sign' property separately so as + to avoid handling extra cases. + 2020-08-12 Anuj Verma [sdf] Added overlap support (currently only for TrueType). diff --git a/src/sdf/ftsdf.c b/src/sdf/ftsdf.c index 98f4cfc64..0a9f98542 100644 --- a/src/sdf/ftsdf.c +++ b/src/sdf/ftsdf.c @@ -3207,6 +3207,7 @@ SDF_Contour* temp_contour; /* temporary contour */ FT_Memory memory; /* to allocate memory */ FT_6D10* t; /* target bitmap buffer */ + FT_Bool flip_sign; /* filp sign? */ /* orientation of all the seperate contours */ SDF_Contour_Orientation* orientations; @@ -3239,6 +3240,11 @@ if ( SDF_ALLOC( orientations, num_contours * sizeof( *orientations ) ) ) goto Exit; + /* Disable the flip_sign to avoid extra complication */ + /* during the combination phase. */ + flip_sign = internal_params.flip_sign; + internal_params.flip_sign = 0; + contour = shape->contours; /* Iterate through all the contours */ @@ -3281,8 +3287,12 @@ /* overload the default sign of the outside */ /* pixels. Which is necessary for counter clock */ /* wise contours. */ - if ( orientations[i] == SDF_ORIENTATION_ACW ) + if ( orientations[i] == SDF_ORIENTATION_ACW && + internal_params.orientation == FT_ORIENTATION_FILL_RIGHT ) internal_params.overload_sign = -1; + if ( orientations[i] == SDF_ORIENTATION_CW && + internal_params.orientation == FT_ORIENTATION_FILL_LEFT ) + internal_params.overload_sign = 1; else internal_params.overload_sign = 0; @@ -3292,6 +3302,16 @@ spread, &bitmaps[i] ) ); + /* Simply flip the orientation in case of post-scritp fonts, */ + /* so as to avoid modificatons in the combining phase. */ + if ( internal_params.orientation == FT_ORIENTATION_FILL_LEFT ) + { + if ( orientations[i] == SDF_ORIENTATION_CW ) + orientations[i] = SDF_ORIENTATION_ACW; + else if ( orientations[i] == SDF_ORIENTATION_ACW ) + orientations[i] = SDF_ORIENTATION_CW; + } + contour = contour->next; } @@ -3330,8 +3350,9 @@ val_ac = FT_MIN( val_ac, temp ); /* for anti-clockwise */ } - /* finally find the smaller of two and assign to output */ - t[id] = FT_MIN( val_c, val_ac ); + /* Finally find the smaller of two and assign to output. */ + /* Also apply the flip_sign if set. */ + t[id] = FT_MIN( val_c, val_ac ) * ( flip_sign ? -1 : 1 ); } }