shithub: freetype+ttf2subf

Download patch

ref: 8a459e5172dbb54b42d7b8247c98627d5cefb98d
parent: 361465dec95a969bd351df8628d2346ffeb4ba5e
author: Alexei Podtelezhnikov <[email protected]>
date: Tue Apr 20 18:53:13 EDT 2021

[cache] Restore SBit copying for unowned (BDF) bitmaps.

* src/cache/ftcsbits.c (ftc_sbit_copy_bitmap): Restore.
(ftc_snode_load): Check ownership and copy unowned bitmaps.

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2021-04-20  Alexei Podtelezhnikov  <[email protected]>
+
+	[cache] Restore SBit copying for unowned (BDF) bitmaps.
+
+	* src/cache/ftcsbits.c (ftc_sbit_copy_bitmap): Restore.
+	(ftc_snode_load): Check ownership and copy unowned bitmaps.
+
 2021-04-19  Dominik Röttsches  <[email protected]>
 
 	[sfnt] Return in 'COLR' v1 when layer pointer outside table
--- a/src/cache/ftcsbits.c
+++ b/src/cache/ftcsbits.c
@@ -38,6 +38,30 @@
   /*************************************************************************/
 
 
+  static FT_Error
+  ftc_sbit_copy_bitmap( FTC_SBit    sbit,
+                        FT_Bitmap*  bitmap,
+                        FT_Memory   memory )
+  {
+    FT_Error  error;
+    FT_Int    pitch = bitmap->pitch;
+    FT_ULong  size;
+
+
+    if ( pitch < 0 )
+      pitch = -pitch;
+
+    size = (FT_ULong)pitch * bitmap->rows;
+    if ( !size )
+      return FT_Err_Ok;
+
+    if ( !FT_ALLOC( sbit->buffer, size ) )
+      FT_MEM_COPY( sbit->buffer, bitmap->buffer, size );
+
+    return error;
+  }
+
+
   FT_LOCAL_DEF( void )
   ftc_snode_free( FTC_Node   ftcsnode,
                   FTC_Cache  cache )
@@ -153,9 +177,17 @@
       sbit->format    = (FT_Byte)bitmap->pixel_mode;
       sbit->max_grays = (FT_Byte)(bitmap->num_grays - 1);
 
-      /* take the bitmap ownership */
-      sbit->buffer = bitmap->buffer;
-      slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
+      if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
+      {
+        /* take the bitmap ownership */
+        sbit->buffer = bitmap->buffer;
+        slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
+      }
+      else
+      {
+        /* copy the bitmap into a new buffer -- ignore error */
+        error = ftc_sbit_copy_bitmap( sbit, bitmap, manager->memory );
+      }
 
       /* now, compute size */
       if ( asize )