diff --git a/src/sfnt/ttsbit.c b/src/sfnt/ttsbit.c index cb3a8abf1..9738d464f 100644 --- a/src/sfnt/ttsbit.c +++ b/src/sfnt/ttsbit.c @@ -1462,6 +1462,7 @@ FT_Int originOffsetX, originOffsetY; FT_Tag graphicType; FT_Int recurse_depth = 0; + FT_Bool flipped = FALSE; FT_Error error; FT_Byte* p; @@ -1517,12 +1518,17 @@ switch ( graphicType ) { + case FT_MAKE_TAG( 'f', 'l', 'i', 'p' ): case FT_MAKE_TAG( 'd', 'u', 'p', 'e' ): if ( recurse_depth < 4 ) { glyph_index = FT_GET_USHORT(); FT_FRAME_EXIT(); recurse_depth++; + + if ( graphicType == FT_MAKE_TAG( 'f', 'l', 'i', 'p' ) ) + flipped = TRUE; + goto retry; } error = FT_THROW( Invalid_File_Format ); @@ -1540,6 +1546,42 @@ glyph_end - glyph_start - 8, TRUE, metrics_only ); + if ( !error && flipped ) + { + FT_UInt32* curr_pos = (FT_UInt32*)map->buffer; + + /* `Load_SBit_Png` always returns a pixmap with 32 bits per pixel */ + /* and no extra pitch bytes. */ + FT_UInt32 width = (FT_UInt32)( map->width ); + FT_UInt32 half_width = (FT_UInt32)( map->width / 2 ); + + FT_UInt y; + + + for ( y = 0; y < map->rows; y++ ) + { + FT_UInt32* left = curr_pos; + FT_UInt32* right = curr_pos + width - 1; + + FT_UInt32 x; + + + for ( x = 0; x < half_width; x++ ) + { + FT_UInt32 value; + + + value = *right; + *right = *left; + *left = value; + + left++; + right--; + } + + curr_pos += width; + } + } #else error = FT_THROW( Unimplemented_Feature ); #endif