Store the rendering port's state in library.

Before this commit, the state of a rendering port was being
held globally. Now, it'll be stored in library->svg_renderer_state.
This commit is contained in:
Moazin Khatti 2019-07-05 21:02:17 +05:00
parent e028be97b8
commit de44a3fda8
4 changed files with 41 additions and 14 deletions

View File

@ -890,6 +890,10 @@ FT_BEGIN_HEADER
* created. @FT_Reference_Library increments this counter, and
* @FT_Done_Library only destroys a library if the counter is~1,
* otherwise it simply decrements it.
*
* svg_renderer_state ::
* A pointer to a state object that will have the state of the SVG
* Renderer. This will be totally managed by the renderer.
*/
typedef struct FT_LibraryRec_
{
@ -917,6 +921,8 @@ FT_BEGIN_HEADER
FT_Int refcount;
void* svg_renderer_state;
} FT_LibraryRec;

View File

@ -38,12 +38,18 @@ FT_BEGIN_HEADER
* @description:
* A callback used to initiate the SVG Rendering port
*
* @input:
* library::
* A instance of library. This is required to initialize the renderer's
* state which will be held in the library.
*
*
* @return:
* FreeType error code. 0 means success.
*/
typedef FT_Error
(*SVG_Lib_Init)( );
(*SVG_Lib_Init)( FT_Library library );
/**************************************************************************
@ -55,12 +61,14 @@ FT_BEGIN_HEADER
* A callback used to free the SVG Rendering port. Calling this callback
* shall do all cleanups that the SVG Rendering port wants to do.
*
* @return:
* FreeType error code. 0 means success.
* @input:
* library::
* A instance of library. This is required to free the renderer's state
* which will be held in the library.
*/
typedef FT_Error
(*SVG_Lib_Free)( );
typedef void
(*SVG_Lib_Free)( FT_Library library );
/**************************************************************************

View File

@ -716,6 +716,7 @@
const FT_Glyph_Class* clazz;
FT_Library library;
FT_Memory memory = library->memory;
/* check argument */
@ -763,7 +764,13 @@
/* prepare dummy slot for rendering */
error = clazz->glyph_prepare( glyph, &dummy );
if ( !error )
{
error = FT_Render_Glyph_Internal( glyph->library, &dummy, render_mode );
if ( clazz == &ft_svg_glyph_class )
{
FT_FREE( dummy.other );
}
}
#if 1
if ( !destroy && origin )

View File

@ -37,13 +37,20 @@
static FT_Error
ft_svg_init( SVG_Renderer svg_module )
{
FT_Error error = FT_Err_Ok;
FT_Error error = FT_Err_Ok;
svg_module->loaded = FALSE;
return error;
}
static void
ft_svg_done( SVG_Renderer svg_module )
{
FT_Library library = svg_module->root.root.library;
if ( svg_module->loaded = TRUE )
svg_module->hooks.svg_lib_free( library );
svg_module->loaded = FALSE;
}
static FT_Error
ft_svg_render( FT_Renderer renderer,
FT_GlyphSlot slot,
@ -51,14 +58,13 @@
const FT_Vector* origin )
{
SVG_Renderer svg_renderer = (SVG_Renderer)renderer;
if( svg_renderer->loaded == FALSE )
FT_Library library = renderer->root.library;
FT_Error error;
if ( svg_renderer->loaded == FALSE )
{
error = svg_renderer->hooks.svg_lib_init( library );
svg_renderer->loaded = TRUE;
svg_renderer->hooks.svg_lib_init();
}
return svg_renderer->hooks.svg_lib_render( slot );
}
@ -96,7 +102,7 @@
0x20000L,
(const void*)&svg_renderer_interface, /* module specific interface */
(FT_Module_Constructor)ft_svg_init, /* module_init */
NULL,
(FT_Module_Destructor)ft_svg_done, /* module_done */
NULL,
FT_GLYPH_FORMAT_SVG,
(FT_Renderer_RenderFunc)ft_svg_render,