freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freetype2] master 86d0ca245: [sdf] Correct handling of empty glyphs.


From: Werner Lemberg
Subject: [freetype2] master 86d0ca245: [sdf] Correct handling of empty glyphs.
Date: Thu, 8 Jun 2023 23:42:44 -0400 (EDT)

branch: master
commit 86d0ca245ac68b633a98c31023cf307d771c3f40
Author: Werner Lemberg <wl@gnu.org>
Commit: Werner Lemberg <wl@gnu.org>

    [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.
---
 src/sdf/ftsdfrend.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/src/sdf/ftsdfrend.c b/src/sdf/ftsdfrend.c
index c4d1a8cba..5610c119f 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 );



reply via email to

[Prev in Thread] Current Thread [Next in Thread]