From f3e71bab9ed0caefda8bddec8af36c0485870c08 Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Fri, 26 Aug 2016 10:31:30 +0200 Subject: [PATCH] [sfnt] Cache offset and size to bitmap data table. This commit avoids `EBDT' and friends being looked up again and again while loading a single embedded bitmap. * include/freetype/internal/tttypes.h (TT_FaceRec) [TT_CONFIG_OPTION_EMBEDDED_BITMAPS]: New fields `ebdt_start' and `ebdt_size'. * src/sfnt/ttsbit.c (tt_sbit_decoder_init): Move table lookup to ... (tt_face_load_sbit): ... this function; also store the table size and offset. --- ChangeLog | 15 ++++++++++++ include/freetype/internal/tttypes.h | 6 +++++ src/sfnt/ttsbit.c | 37 +++++++++++++++++++++-------- 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8b1e97a19..3ee8b5818 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2016-08-26 Werner Lemberg + + [sfnt] Cache offset and size to bitmap data table. + + This commit avoids `EBDT' and friends being looked up again and + again while loading a single embedded bitmap. + + * include/freetype/internal/tttypes.h (TT_FaceRec) + [TT_CONFIG_OPTION_EMBEDDED_BITMAPS]: New fields `ebdt_start' and + `ebdt_size'. + + * src/sfnt/ttsbit.c (tt_sbit_decoder_init): Move table lookup to ... + (tt_face_load_sbit): ... this function; also store the table size + and offset. + 2016-08-26 Alexei Podtelezhnikov * src/smooth/ftgrays.c (gray_raster_render): Minor tweaks. diff --git a/include/freetype/internal/tttypes.h b/include/freetype/internal/tttypes.h index 4110d5028..4ed980be8 100644 --- a/include/freetype/internal/tttypes.h +++ b/include/freetype/internal/tttypes.h @@ -1393,6 +1393,12 @@ FT_BEGIN_HEADER FT_Bool sph_compatibility_mode; #endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ +#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS + /* since 2.7 */ + FT_ULong ebdt_start; /* either `CBDT', `EBDT', or `bdat' */ + FT_ULong ebdt_size; +#endif + } TT_FaceRec; diff --git a/src/sfnt/ttsbit.c b/src/sfnt/ttsbit.c index 82c85446b..5b7a12351 100644 --- a/src/sfnt/ttsbit.c +++ b/src/sfnt/ttsbit.c @@ -197,6 +197,27 @@ if ( !error ) FT_TRACE3(( "sbit_num_strikes: %u\n", face->sbit_num_strikes )); + face->ebdt_start = 0; + face->ebdt_size = 0; + + if ( face->sbit_table_type != TT_SBIT_TABLE_TYPE_NONE ) + { + FT_ULong ebdt_size; + + + error = face->goto_table( face, TTAG_CBDT, stream, &ebdt_size ); + if ( error ) + error = face->goto_table( face, TTAG_EBDT, stream, &ebdt_size ); + if ( error ) + error = face->goto_table( face, TTAG_bdat, stream, &ebdt_size ); + + if ( !error ) + { + face->ebdt_start = FT_STREAM_POS(); + face->ebdt_size = ebdt_size; + } + } + return FT_Err_Ok; Exit: @@ -424,17 +445,13 @@ FT_ULong strike_index, TT_SBit_MetricsRec* metrics ) { - FT_Error error; + FT_Error error = FT_ERR( Table_Missing ); FT_Stream stream = face->root.stream; - FT_ULong ebdt_size; - error = face->goto_table( face, TTAG_CBDT, stream, &ebdt_size ); - if ( error ) - error = face->goto_table( face, TTAG_EBDT, stream, &ebdt_size ); - if ( error ) - error = face->goto_table( face, TTAG_bdat, stream, &ebdt_size ); - if ( error ) + if ( !face->ebdt_size ) + goto Exit; + if ( FT_STREAM_SEEK( face->ebdt_start ) ) goto Exit; decoder->face = face; @@ -445,8 +462,8 @@ decoder->metrics_loaded = 0; decoder->bitmap_allocated = 0; - decoder->ebdt_start = FT_STREAM_POS(); - decoder->ebdt_size = ebdt_size; + decoder->ebdt_start = face->ebdt_start; + decoder->ebdt_size = face->ebdt_size; decoder->eblc_base = face->sbit_table; decoder->eblc_limit = face->sbit_table + face->sbit_table_size;