[sfnt] Support sbix graphicType 'flip'.

* src/sfnt/ttsbit.c (tt_face_load_sbix_image): Currently undocumented by
Apple, this flips the bitmap data horizontally.  It is used on macOS in
Apple Color Emoji; 19.4d6e1; 2024-02-05 (file `Apple Color Emoji.ttc`).

Fixes issue #1282.
This commit is contained in:
Andrew Murray 2024-09-06 17:03:58 +10:00 committed by Werner Lemberg
parent aaa559eaca
commit 98283cb30f
1 changed files with 42 additions and 0 deletions

View File

@ -1462,6 +1462,7 @@
FT_Int originOffsetX, originOffsetY; FT_Int originOffsetX, originOffsetY;
FT_Tag graphicType; FT_Tag graphicType;
FT_Int recurse_depth = 0; FT_Int recurse_depth = 0;
FT_Bool flipped = FALSE;
FT_Error error; FT_Error error;
FT_Byte* p; FT_Byte* p;
@ -1517,12 +1518,17 @@
switch ( graphicType ) switch ( graphicType )
{ {
case FT_MAKE_TAG( 'f', 'l', 'i', 'p' ):
case FT_MAKE_TAG( 'd', 'u', 'p', 'e' ): case FT_MAKE_TAG( 'd', 'u', 'p', 'e' ):
if ( recurse_depth < 4 ) if ( recurse_depth < 4 )
{ {
glyph_index = FT_GET_USHORT(); glyph_index = FT_GET_USHORT();
FT_FRAME_EXIT(); FT_FRAME_EXIT();
recurse_depth++; recurse_depth++;
if ( graphicType == FT_MAKE_TAG( 'f', 'l', 'i', 'p' ) )
flipped = TRUE;
goto retry; goto retry;
} }
error = FT_THROW( Invalid_File_Format ); error = FT_THROW( Invalid_File_Format );
@ -1540,6 +1546,42 @@
glyph_end - glyph_start - 8, glyph_end - glyph_start - 8,
TRUE, TRUE,
metrics_only ); 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 #else
error = FT_THROW( Unimplemented_Feature ); error = FT_THROW( Unimplemented_Feature );
#endif #endif