From 8a459e5172dbb54b42d7b8247c98627d5cefb98d Mon Sep 17 00:00:00 2001 From: Alexei Podtelezhnikov Date: Tue, 20 Apr 2021 22:53:13 -0400 Subject: [PATCH] [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. --- ChangeLog | 7 +++++++ src/cache/ftcsbits.c | 38 +++++++++++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9bd955369..15ee63d8d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2021-04-20 Alexei Podtelezhnikov + + [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 [sfnt] Return in 'COLR' v1 when layer pointer outside table diff --git a/src/cache/ftcsbits.c b/src/cache/ftcsbits.c index 01d94ec9a..33c45386c 100644 --- 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 )