[sfnt] Improve FT_LOAD_BITMAP_METRICS_ONLY for `sbix' format.

It's unavoidable to call the PNG engine, but to get the metrics it
is sufficient to read the PNG image's header only.

* src/sfnt/pngshim.c (Load_SBit_Png): Add argument to control the
allocation of the glyph slot.
* src/sfnt/pngshim.h: Updated.
* src/sfnt/ttsbit.c (tt_sbit_decoder_load_png,
tt_face_load_sbix_image, tt_face_load_sbit_image): Updated.
This commit is contained in:
Werner Lemberg 2016-11-06 12:37:55 +01:00
parent 565db95b5c
commit 1c6fd99437
4 changed files with 44 additions and 20 deletions

View File

@ -1,3 +1,16 @@
2016-11-06 Werner Lemberg <wl@gnu.org>
[sfnt] Improve FT_LOAD_BITMAP_METRICS_ONLY for `sbix' format.
It's unavoidable to call the PNG engine, but to get the metrics it
is sufficient to read the PNG image's header only.
* src/sfnt/pngshim.c (Load_SBit_Png): Add argument to control the
allocation of the glyph slot.
* src/sfnt/pngshim.h: Updated.
* src/sfnt/ttsbit.c (tt_sbit_decoder_load_png,
tt_face_load_sbix_image, tt_face_load_sbit_image): Updated.
2016-11-06 Werner Lemberg <wl@gnu.org>
[sfnt] Speed up `sbix' lookup.

View File

@ -184,7 +184,8 @@
FT_Memory memory,
FT_Byte* data,
FT_UInt png_len,
FT_Bool populate_map_and_metrics )
FT_Bool populate_map_and_metrics,
FT_Bool metrics_only )
{
FT_Bitmap *map = &slot->bitmap;
FT_Error error = FT_Err_Ok;
@ -258,9 +259,6 @@
if ( populate_map_and_metrics )
{
FT_ULong size;
metrics->width = (FT_UShort)imgWidth;
metrics->height = (FT_UShort)imgHeight;
@ -276,13 +274,6 @@
error = FT_THROW( Array_Too_Large );
goto DestroyExit;
}
/* this doesn't overflow: 0x7FFF * 0x7FFF * 4 < 2^32 */
size = map->rows * (FT_ULong)map->pitch;
error = ft_glyphslot_alloc_bitmap( slot, size );
if ( error )
goto DestroyExit;
}
/* convert palette/gray image to rgb */
@ -334,6 +325,9 @@
goto DestroyExit;
}
if ( metrics_only )
goto DestroyExit;
switch ( color_type )
{
default:
@ -349,6 +343,17 @@
break;
}
if ( populate_map_and_metrics )
{
/* this doesn't overflow: 0x7FFF * 0x7FFF * 4 < 2^32 */
FT_ULong size = map->rows * (FT_ULong)map->pitch;
error = ft_glyphslot_alloc_bitmap( slot, size );
if ( error )
goto DestroyExit;
}
if ( FT_NEW_ARRAY( rows, imgHeight ) )
{
error = FT_THROW( Out_Of_Memory );

View File

@ -38,7 +38,8 @@ FT_BEGIN_HEADER
FT_Memory memory,
FT_Byte* data,
FT_UInt png_len,
FT_Bool populate_map_and_metrics );
FT_Bool populate_map_and_metrics,
FT_Bool metrics_only );
#endif

View File

@ -1071,6 +1071,7 @@
decoder->stream->memory,
p,
png_len,
FALSE,
FALSE );
Exit:
@ -1443,7 +1444,8 @@
FT_UInt glyph_index,
FT_Stream stream,
FT_Bitmap *map,
TT_SBit_MetricsRec *metrics )
TT_SBit_MetricsRec *metrics,
FT_Bool metrics_only )
{
FT_UInt strike_offset, glyph_start, glyph_end;
FT_Int originOffsetX, originOffsetY;
@ -1522,7 +1524,8 @@
stream->memory,
stream->cursor,
glyph_end - glyph_start - 8,
TRUE );
TRUE,
metrics_only );
#else
error = FT_THROW( Unimplemented_Feature );
#endif
@ -1595,12 +1598,14 @@
break;
case TT_SBIT_TABLE_TYPE_SBIX:
error = tt_face_load_sbix_image( face,
strike_index,
glyph_index,
stream,
map,
metrics );
error = tt_face_load_sbix_image(
face,
strike_index,
glyph_index,
stream,
map,
metrics,
( load_flags & FT_LOAD_BITMAP_METRICS_ONLY ) != 0 );
break;
default: