From 1c6fd994376c182f07cd59558a2f9bdd082b9509 Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Sun, 6 Nov 2016 12:37:55 +0100 Subject: [PATCH] [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. --- ChangeLog | 13 +++++++++++++ src/sfnt/pngshim.c | 27 ++++++++++++++++----------- src/sfnt/pngshim.h | 3 ++- src/sfnt/ttsbit.c | 21 +++++++++++++-------- 4 files changed, 44 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 20c9f3e2b..e53fc937f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2016-11-06 Werner Lemberg + + [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 [sfnt] Speed up `sbix' lookup. diff --git a/src/sfnt/pngshim.c b/src/sfnt/pngshim.c index 2815759cc..ff6729273 100644 --- a/src/sfnt/pngshim.c +++ b/src/sfnt/pngshim.c @@ -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 ); diff --git a/src/sfnt/pngshim.h b/src/sfnt/pngshim.h index ff0587133..0af4bfc5b 100644 --- a/src/sfnt/pngshim.h +++ b/src/sfnt/pngshim.h @@ -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 diff --git a/src/sfnt/ttsbit.c b/src/sfnt/ttsbit.c index de59673e9..bc51304b6 100644 --- a/src/sfnt/ttsbit.c +++ b/src/sfnt/ttsbit.c @@ -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: