From 9578e07a83a8cb12fba360948b264796ec607f83 Mon Sep 17 00:00:00 2001 From: Ewald Hew Date: Sun, 24 Sep 2017 22:05:32 +0200 Subject: [PATCH] Add callbacks for inter-module calls. NOTE: Does not compile! * include/freetype/internal/psaux.h: Add function pointer declarations. * src/psaux/cffdecode.c (cff_decoder_init): Update to take in callbacks. * src/psaux/cffdecode.h: Ditto. * src/cff/cffgload.c (cff_compute_max_advance, cff_slot_load): Update calls to pass in callbacks. * src/psaux/cf2ft.c, src/psaux/cffdecode.c: Use them. --- ChangeLog | 17 +++++++++++++++++ include/freetype/internal/psaux.h | 19 ++++++++++++++++++- src/cff/cffgload.c | 6 ++++-- src/psaux/cf2ft.c | 14 +++++++------- src/psaux/cffdecode.c | 19 ++++++++++++------- src/psaux/cffdecode.h | 4 +++- 6 files changed, 61 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 02e0611d1..0114f4843 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2017-09-24 Ewald Hew + + [psaux, cff] Add callbacks for inter-module calls. + + NOTE: Does not compile! + + * include/freetype/internal/psaux.h: Add function pointer + declarations. + + * src/psaux/cffdecode.c (cff_decoder_init): Update to take in + callbacks. + * src/psaux/cffdecode.h: Ditto. + + * src/cff/cffgload.c (cff_compute_max_advance, cff_slot_load): + Update calls to pass in callbacks. + * src/psaux/cf2ft.c, src/psaux/cffdecode.c: Use them. + 2017-09-24 Ewald Hew [psaux, cff] Create new `PSAux' service interface entries. diff --git a/include/freetype/internal/psaux.h b/include/freetype/internal/psaux.h index e29d45246..bcc84e38d 100644 --- a/include/freetype/internal/psaux.h +++ b/include/freetype/internal/psaux.h @@ -868,6 +868,18 @@ FT_BEGIN_HEADER } CFF_Decoder_Zone; + typedef FT_Error + (*CFF_Decoder_Get_Glyph_Callback)( TT_Face face, + FT_UInt glyph_index, + FT_Byte** pointer, + FT_ULong* length ); + + typedef void + (*CFF_Decoder_Free_Glyph_Callback)( TT_Face face, + FT_Byte** pointer, + FT_ULong length ); + + typedef struct CFF_Decoder_ { CFF_Builder builder; @@ -909,6 +921,9 @@ FT_BEGIN_HEADER CFF_SubFont current_subfont; /* for current glyph_index */ + CFF_Decoder_Get_Glyph_Callback get_glyph_callback; + CFF_Decoder_Free_Glyph_Callback free_glyph_callback; + } CFF_Decoder; typedef const struct CFF_Decoder_FuncsRec_* CFF_Decoder_Funcs; @@ -921,7 +936,9 @@ FT_BEGIN_HEADER CFF_Size size, CFF_GlyphSlot slot, FT_Bool hinting, - FT_Render_Mode hint_mode ); + FT_Render_Mode hint_mode, + CFF_Decoder_Get_Glyph_Callback get_callback, + CFF_Decoder_Free_Glyph_Callback free_callback ); FT_Error (*prepare)( CFF_Decoder* decoder, diff --git a/src/cff/cffgload.c b/src/cff/cffgload.c index a5fde87b5..18dbf6542 100644 --- a/src/cff/cffgload.c +++ b/src/cff/cffgload.c @@ -149,7 +149,7 @@ *max_advance = 0; /* Initialize load decoder */ - decoder_funcs->init( &decoder, face, 0, 0, 0, 0 ); + decoder_funcs->init( &decoder, face, 0, 0, 0, 0, 0, 0 ); decoder.builder.metrics_only = 1; decoder.builder.load_points = 0; @@ -404,7 +404,9 @@ decoder_funcs->init( &decoder, face, size, glyph, hinting, - FT_LOAD_TARGET_MODE( load_flags ) ); + FT_LOAD_TARGET_MODE( load_flags ), + cff_get_glyph_data, + cff_free_glyph_data ); /* this is for pure CFFs */ if ( load_flags & FT_LOAD_ADVANCE_ONLY ) diff --git a/src/psaux/cf2ft.c b/src/psaux/cf2ft.c index c6c00d162..169e1160b 100644 --- a/src/psaux/cf2ft.c +++ b/src/psaux/cf2ft.c @@ -647,10 +647,10 @@ return FT_THROW( Invalid_Glyph_Format ); } - error = cff_get_glyph_data( decoder->builder.face, - (CF2_UInt)gid, - &charstring, - &len ); + error = decoder->get_glyph_callback( decoder->builder.face, + (CF2_UInt)gid, + &charstring, + &len ); /* TODO: for now, just pass the FreeType error through */ if ( error ) return error; @@ -672,9 +672,9 @@ { FT_ASSERT( decoder ); - cff_free_glyph_data( decoder->builder.face, - (FT_Byte**)&buf->start, - (FT_ULong)( buf->end - buf->start ) ); + decoder->free_glyph_callback( decoder->builder.face, + (FT_Byte**)&buf->start, + (FT_ULong)( buf->end - buf->start ) ); } diff --git a/src/psaux/cffdecode.c b/src/psaux/cffdecode.c index e1af544f0..baa318bbe 100644 --- a/src/psaux/cffdecode.c +++ b/src/psaux/cffdecode.c @@ -272,8 +272,8 @@ FT_GlyphLoader_Prepare( builder->loader ); /* First load `bchar' in builder */ - error = cff_get_glyph_data( face, (FT_UInt)bchar_index, - &charstring, &charstring_len ); + error = decoder->get_glyph_callback( face, (FT_UInt)bchar_index, + &charstring, &charstring_len ); if ( !error ) { /* the seac operator must not be nested */ @@ -282,7 +282,7 @@ charstring_len, 0 ); decoder->seac = FALSE; - cff_free_glyph_data( face, &charstring, charstring_len ); + decoder->free_glyph_callback( face, &charstring, charstring_len ); if ( error ) goto Exit; @@ -302,8 +302,8 @@ builder->pos_y = ady; /* Now load `achar' on top of the base outline. */ - error = cff_get_glyph_data( face, (FT_UInt)achar_index, - &charstring, &charstring_len ); + error = decoder->get_glyph_callback( face, (FT_UInt)achar_index, + &charstring, &charstring_len ); if ( !error ) { /* the seac operator must not be nested */ @@ -312,7 +312,7 @@ charstring_len, 0 ); decoder->seac = FALSE; - cff_free_glyph_data( face, &charstring, charstring_len ); + decoder->free_glyph_callback( face, &charstring, charstring_len ); if ( error ) goto Exit; @@ -2231,7 +2231,9 @@ CFF_Size size, CFF_GlyphSlot slot, FT_Bool hinting, - FT_Render_Mode hint_mode ) + FT_Render_Mode hint_mode, + CFF_Decoder_Get_Glyph_Callback get_callback, + CFF_Decoder_Free_Glyph_Callback free_callback ) { CFF_Font cff = (CFF_Font)face->extra.data; @@ -2251,6 +2253,9 @@ decoder->num_globals ); decoder->hint_mode = hint_mode; + + decoder->get_glyph_callback = get_callback; + decoder->free_glyph_callback = free_callback; } diff --git a/src/psaux/cffdecode.h b/src/psaux/cffdecode.h index a890a505c..1b021b720 100644 --- a/src/psaux/cffdecode.h +++ b/src/psaux/cffdecode.h @@ -14,7 +14,9 @@ FT_BEGIN_HEADER CFF_Size size, CFF_GlyphSlot slot, FT_Bool hinting, - FT_Render_Mode hint_mode); + FT_Render_Mode hint_mode, + CFF_Decoder_Get_Glyph_Callback get_callback, + CFF_Decoder_Free_Glyph_Callback free_callback); FT_LOCAL( FT_Error ) cff_decoder_prepare( CFF_Decoder* decoder,