Just want to express that this is very, *very*, /very/, VERY, bad. The whole property API is a big anti-pattern that FreeType has adopted. Still, using it to set boolean, integer, or string values is justifiable.
Abusing it to set pointer to code, Just Unacceptable. b On Wed, Jul 17, 2019 at 11:32 AM Moazin Khatti <moa...@savannah.gnu.org> wrote: > branch: hooks-via-module-property > commit d94f52b0c698b7358210c13988ccaf6a8d25afc8 > Author: Moazin Khatti <moazinkha...@gmail.com> > Commit: Moazin Khatti <moazinkha...@gmail.com> > > Use `FT_Property_Set' to set the hooks. One less API function. > --- > include/freetype/svgrender.h | 72 ------------------------------ > src/base/ftobjs.c | 43 ------------------ > src/svg/ftsvg.c | 101 > ++++++++++++++++++++++++++++++++++--------- > 3 files changed, 81 insertions(+), 135 deletions(-) > > diff --git a/include/freetype/svgrender.h b/include/freetype/svgrender.h > index 181bfea..670e93f 100644 > --- a/include/freetype/svgrender.h > +++ b/include/freetype/svgrender.h > @@ -121,78 +121,6 @@ FT_BEGIN_HEADER > (*SVG_Lib_Get_Buffer_Size_Func)( FT_GlyphSlot slot, > FT_BBox bbox ); > > - > - > /************************************************************************** > - * > - * @functype: > - * SVG_Set_Hooks_Func > - * > - * @description: > - * A function that is used set SVG Hooks. Part of the SVG Renderer > - * Interface. > - * > - * @input: > - * module :: > - * `FT_Module` instance. > - * > - * init_svg :: > - * A function pointer of the type `SVG_Lib_Init_Func`. Read the > - * documentation of `SVG_Lib_Init_Func`. > - * > - * free_svg :: > - * A function pointer of the type `SVG_Lib_Free_Func`. Read the > - * documentation of `SVG_Lib_Free_Func`. > - * > - * render_svg :: > - * A function pointer of the type `SVG_Lib_Render_Func`. Read the > - * documentation of `SVG_Lib_Render_Func`. > - * > - * get_buffer_size :: > - * A function pointer of the type `SVG_Lib_Get_Buffer_Size_Func`. > - * Read the documentation of `SVG_Lib_Get_Buffer_Size_Func`. > - * > - * @return: > - * FreeType error code. 0 means success. > - */ > - > - typedef FT_Error > - (*SVG_Set_Hooks_Func)( FT_Module module, > - SVG_Lib_Init_Func init_svg, > - SVG_Lib_Free_Func free_svg, > - SVG_Lib_Render_Func render_svg, > - SVG_Lib_Get_Buffer_Size_Func get_buffer_size ); > - > - > /************************************************************************** > - * > - * @struct: > - * SVG_Renderer_Interface > - * > - * @description: > - * An interface structure that function needed to inject external SVG > - * rendering library hooks. > - * > - * @fields: > - * set_hooks :: > - * A function that can be called to set the hooks. > - * > - * @return: > - * FreeType error code. 0 means success. > - */ > - > - typedef struct SVG_Renderer_Interface_ > - { > - SVG_Set_Hooks_Func set_hooks; > - } SVG_Renderer_Interface; > - > - > - /* TODO: to document */ > - FT_EXPORT( FT_Error ) > - FT_Set_Svg_Hooks( FT_Library library, > - SVG_Lib_Init_Func init_svg, > - SVG_Lib_Free_Func free_svg, > - SVG_Lib_Render_Func render_svg, > - SVG_Lib_Get_Buffer_Size_Func get_buffer_size ); > - > > /************************************************************************** > * > * @struct: > diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c > index 5bf065f..dc71a98 100644 > --- a/src/base/ftobjs.c > +++ b/src/base/ftobjs.c > @@ -5603,47 +5603,4 @@ > return 0; > } > > -#ifdef FT_CONFIG_OPTION_SVG > - FT_EXPORT_DEF( FT_Error ) > - FT_Set_Svg_Hooks( FT_Library library, > - SVG_Lib_Init_Func init_svg, > - SVG_Lib_Free_Func free_svg, > - SVG_Lib_Render_Func render_svg, > - SVG_Lib_Get_Buffer_Size_Func get_buffer_size ) > - { > - FT_Module renderer; > - SVG_Renderer_Interface *svg; > - > - /* TODO: (OT-SVG) Handle the case if the module is not found */ > - renderer = FT_Get_Module( library, "ot-svg" ); > - > - /* If ot-svg module is not available return with error */ > - if ( renderer == 0 ) > - return FT_THROW( Missing_Module ); > - > - svg = (SVG_Renderer_Interface*)renderer->clazz->module_interface; > - svg->set_hooks(renderer, > - init_svg, > - free_svg, > - render_svg, > - get_buffer_size ); > - return FT_Err_Ok; > - } > -#else > - FT_EXPORT_DEF( FT_Error ) > - FT_Set_Svg_Hooks( FT_Library library, > - SVG_Lib_Init_Func init_svg, > - SVG_Lib_Free_Func free_svg, > - SVG_Lib_Render_Func render_svg, > - SVG_Lib_Get_Buffer_Size_Func get_buffer_size ) > - { > - FT_UNUSED( library ); > - FT_UNUSED( init_svg ); > - FT_UNUSED( free_svg ); > - FT_UNUSED( render_svg ); > - FT_UNUSED( get_buffer_size ); > - return FT_THROW( Unimplemented_Feature ); > - } > -#endif > - > /* END */ > diff --git a/src/svg/ftsvg.c b/src/svg/ftsvg.c > index f40999a..a87675b 100644 > --- a/src/svg/ftsvg.c > +++ b/src/svg/ftsvg.c > @@ -16,6 +16,8 @@ > */ > > #include <ft2build.h> > +#include FT_INTERNAL_DEBUG_H > +#include FT_SERVICE_PROPERTIES_H > #include FT_SVG_RENDER_H > #include FT_BBOX_H > > @@ -78,31 +80,90 @@ > } > > static FT_Error > - ft_svg_set_hooks( FT_Module module, > - SVG_Lib_Init_Func init_svg, > - SVG_Lib_Free_Func free_svg, > - SVG_Lib_Render_Func render_svg, > - SVG_Lib_Get_Buffer_Size_Func get_buffer_size ) > + ft_svg_property_set( FT_Module module, > + const char* property_name, > + const void* value, > + FT_Bool value_is_string ) > { > - SVG_Renderer renderer; > - > - renderer = (SVG_Renderer)module; > - renderer->hooks.init_svg = init_svg; > - renderer->hooks.free_svg = free_svg; > - renderer->hooks.render_svg = render_svg; > + FT_Error error = FT_Err_Ok; > + SVG_Renderer renderer = (SVG_Renderer)module; > + > + if ( !ft_strcmp( property_name, "init_svg_hook" ) ) > + renderer->hooks.init_svg = (SVG_Lib_Init_Func)value; > + else if ( !ft_strcmp( property_name, "free_svg_hook" ) ) > + renderer->hooks.free_svg = (SVG_Lib_Free_Func)value; > + else if ( !ft_strcmp( property_name, "render_svg_hook" ) ) > + renderer->hooks.render_svg = (SVG_Lib_Render_Func)value; > + else if ( !ft_strcmp( property_name, "get_buffer_size_hook" ) ) > + renderer->hooks.get_buffer_size = > (SVG_Lib_Get_Buffer_Size_Func)value; > + else > + { > + error = FT_THROW( Missing_Property ); > + } > + return error; > + } > > - renderer->hooks.get_buffer_size = get_buffer_size; > + static FT_Error > + ft_svg_property_get( FT_Module module, > + const char* property_name, > + const void* value ) > + { > + FT_Error error = FT_Err_Ok; > + SVG_Renderer renderer = (SVG_Renderer)module; > > - return FT_Err_Ok; > + if ( !ft_strcmp( property_name, "init_svg_hook" ) ) > + { > + SVG_Lib_Init_Func* val = (SVG_Lib_Init_Func*)value; > + *val = (SVG_Lib_Init_Func)renderer->hooks.init_svg; > + } > + else if ( !ft_strcmp( property_name, "free_svg_hook" ) ) > + { > + SVG_Lib_Free_Func* val = (SVG_Lib_Free_Func*)value; > + *val = (SVG_Lib_Free_Func)renderer->hooks.free_svg; > + } > + else if ( !ft_strcmp( property_name, "render_svg_hook" ) ) > + { > + SVG_Lib_Render_Func* val = (SVG_Lib_Render_Func*)value; > + *val = (SVG_Lib_Render_Func)renderer->hooks.render_svg; > + } > + else if ( !ft_strcmp( property_name, "get_buffer_size_hook" ) ) > + { > + SVG_Lib_Get_Buffer_Size_Func* val; > + val = (SVG_Lib_Get_Buffer_Size_Func*)value; > + *val = (SVG_Lib_Get_Buffer_Size_Func)renderer->hooks.render_svg; > + } > + else > + { > + error = FT_THROW( Missing_Property ); > + } > + return error; > } > > + FT_DEFINE_SERVICE_PROPERTIESREC( > + ft_svg_service_properties, > + > + (FT_Properties_SetFunc)ft_svg_property_set, /* set_property */ > + (FT_Properties_GetFunc)ft_svg_property_get /* get_property */ > + ) > + > + FT_DEFINE_SERVICEDESCREC1( > + ft_svg_services, > + FT_SERVICE_ID_PROPERTIES, &ft_svg_service_properties ) > + > > - static const SVG_Renderer_Interface svg_renderer_interface = > + FT_CALLBACK_DEF( FT_Module_Interface ) > + ft_svg_get_interface( FT_Module module, > + const char* ft_svg_interface ) > { > - (SVG_Set_Hooks_Func)ft_svg_set_hooks > - }; > + FT_Module_Interface result; > > > + result = ft_service_list_lookup( ft_svg_services, ft_svg_interface ); > + if ( result ) > + return result; > + return 0; > + } > + > FT_DEFINE_RENDERER( > ft_svg_renderer_class, > > @@ -112,10 +173,10 @@ > "ot-svg", > 0x10000L, > 0x20000L, > - (const void*)&svg_renderer_interface, /* module specific > interface */ > - (FT_Module_Constructor)ft_svg_init, /* module_init */ > - (FT_Module_Destructor)ft_svg_done, /* module_done */ > - NULL, > + NULL, /* module specific interface */ > + (FT_Module_Constructor)ft_svg_init, /* module_init */ > + (FT_Module_Destructor)ft_svg_done, /* module_done */ > + ft_svg_get_interface, /* get_interface */ > FT_GLYPH_FORMAT_SVG, > (FT_Renderer_RenderFunc)ft_svg_render, > NULL, > > -- behdad http://behdad.org/
_______________________________________________ Freetype-devel mailing list Freetype-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/freetype-devel