Commit 86d0ca245ac68b633a98c31023cf307d771c3f40

Werner Lemberg 2023-06-09T05:13:47

[sdf] Correct handling of empty glyphs. This is a refinement of commit 7b3ebb9. * src/sdf/ftsdfrend.c (ft_sdf_render): Goto 'Exit' instead of directly returning. (fd_bsdf_render): Ditto, also taking care of setting `FT_GLYPH_OWN_BITMAP` correctly.

diff --git a/src/sdf/ftsdfrend.c b/src/sdf/ftsdfrend.c
index c4d1a8c..5610c11 100644
--- a/src/sdf/ftsdfrend.c
+++ b/src/sdf/ftsdfrend.c
@@ -300,7 +300,7 @@
 
     /* nothing to render */
     if ( !bitmap->rows || !bitmap->pitch )
-      return FT_Err_Ok;
+      goto Exit;
 
     /* the padding will simply be equal to the `spread' */
     x_pad = sdf_module->spread;
@@ -508,6 +508,10 @@
       goto Exit;
     }
 
+    /* nothing to render */
+    if ( !bitmap->rows || !bitmap->pitch )
+      goto Exit;
+
     /* Do not generate SDF if the bitmap is not owned by the       */
     /* glyph: it might be that the source buffer is already freed. */
     if ( !( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) )
@@ -519,10 +523,6 @@
       goto Exit;
     }
 
-    /* nothing to render */
-    if ( !bitmap->rows || !bitmap->pitch )
-      return FT_Err_Ok;
-
     FT_Bitmap_New( &target );
 
     /* padding will simply be equal to `spread` */
@@ -557,15 +557,14 @@
     {
       /* the glyph is successfully converted to a SDF */
       if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
-      {
         FT_FREE( bitmap->buffer );
-        slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
-      }
 
-      slot->bitmap           = target;
-      slot->bitmap_top      += y_pad;
-      slot->bitmap_left     -= x_pad;
-      slot->internal->flags |= FT_GLYPH_OWN_BITMAP;
+      slot->bitmap       = target;
+      slot->bitmap_top  += y_pad;
+      slot->bitmap_left -= x_pad;
+
+      if ( target.buffer )
+        slot->internal->flags |= FT_GLYPH_OWN_BITMAP;
     }
     else if ( target.buffer )
       FT_FREE( target.buffer );