Commit 7833e308efec8caf5ce62855e9b27041ad2155ad

Alexei Podtelezhnikov 2021-06-09T10:40:30

[sdf] Fix SDF positioning. * src/sdf/ftsdfrend.c (ft_sdf_render, ft_bsdf_render): Add padding to `bitmap_top' and `bitmap_left'. * sdf/sdf/ftsdf.c (sdf_generate_with_overlaps): Fix VC++ warning.

diff --git a/ChangeLog b/ChangeLog
index 01f696d..8afac74 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2021-06-09  Alexei Podtelezhnikov  <apodtele@gmail.com>
+
+	[sdf] Fix SDF positioning.
+
+	* src/sdf/ftsdfrend.c (ft_sdf_render, ft_bsdf_render): Add padding to
+	`bitmap_top' and `bitmap_left'.
+
+	* sdf/sdf/ftsdf.c (sdf_generate_with_overlaps): Fix VC++ warning.
+
 2021-06-08  Werner Lemberg  <wl@gnu.org>
 
 	Fix 'devel' build for COLR 'v1'.
diff --git a/src/sdf/ftsdf.c b/src/sdf/ftsdf.c
index b377bde..65a8f32 100644
--- a/src/sdf/ftsdf.c
+++ b/src/sdf/ftsdf.c
@@ -3520,6 +3520,11 @@
     if ( !shape || !bitmap || !shape->memory )
       return FT_THROW( Invalid_Argument );
 
+    /* Disable `flip_sign` to avoid extra complication */
+    /* during the combination phase.                   */
+    flip_sign                 = internal_params.flip_sign;
+    internal_params.flip_sign = 0;
+
     contour           = shape->contours;
     memory            = shape->memory;
     temp_shape.memory = memory;
@@ -3544,11 +3549,6 @@
                    (FT_UInt)num_contours * sizeof ( *orientations ) ) )
       goto Exit;
 
-    /* Disable `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 over all contours and generate SDF separately. */
diff --git a/src/sdf/ftsdfrend.c b/src/sdf/ftsdfrend.c
index aedc5bb..f8ffd19 100644
--- a/src/sdf/ftsdfrend.c
+++ b/src/sdf/ftsdfrend.c
@@ -323,8 +323,11 @@
 
     slot->internal->flags |= FT_GLYPH_OWN_BITMAP;
 
-    x_shift  = 64 * -( slot->bitmap_left - x_pad );
-    y_shift  = 64 * -( slot->bitmap_top + y_pad );
+    slot->bitmap_top  += y_pad;
+    slot->bitmap_left -= x_pad;
+
+    x_shift  = 64 * -slot->bitmap_left;
+    y_shift  = 64 * -slot->bitmap_top;
     y_shift += 64 * (FT_Int)bitmap->rows;
 
     if ( origin )
@@ -520,7 +523,7 @@
     y_pad = sdf_module->spread;
 
     /* apply padding, which extends to all directions */
-    target.rows  = bitmap->rows + y_pad * 2;
+    target.rows  = bitmap->rows  + y_pad * 2;
     target.width = bitmap->width + x_pad * 2;
 
     /* set up the target bitmap */
@@ -553,6 +556,8 @@
       }
 
       slot->bitmap           = target;
+      slot->bitmap_top      += y_pad;
+      slot->bitmap_left     -= x_pad;
       slot->internal->flags |= FT_GLYPH_OWN_BITMAP;
     }
     else if ( target.buffer )