forked from minhngoc25a/freetype2
relying on cairo recording surface for extents and preset bitmap at load time, work in progress
This commit is contained in:
parent
398801e2c0
commit
dbcc809e7c
|
@ -37,6 +37,7 @@
|
|||
#define FT_INTERNAL_SERVICE_H <freetype/internal/ftserv.h>
|
||||
#define FT_INTERNAL_RFORK_H <freetype/internal/ftrfork.h>
|
||||
#define FT_INTERNAL_VALIDATE_H <freetype/internal/ftvalid.h>
|
||||
#define FT_INTERNAL_SVG_INTERFACE_H <freetype/internal/svginterface.h>
|
||||
|
||||
#define FT_INTERNAL_TRUETYPE_TYPES_H <freetype/internal/tttypes.h>
|
||||
#define FT_INTERNAL_TYPE1_TYPES_H <freetype/internal/t1types.h>
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
/****************************************************************************
|
||||
*
|
||||
* svginterface.h
|
||||
*
|
||||
* Exposes the interface of ot-svg module
|
||||
*
|
||||
* Copyright (C) 1996-2019 by
|
||||
* David Turner, Robert Wilhelm, Werner Lemberg and Moazin Khatti.
|
||||
*
|
||||
* This file is part of the FreeType project, and may only be used,
|
||||
* modified, and distributed under the terms of the FreeType project
|
||||
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
||||
* this file you indicate that you have read the license and
|
||||
* understand and accept it fully.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef SVGINTERFACE_H
|
||||
#define SVGINTERFACE_H
|
||||
|
||||
#include <ft2build.h>
|
||||
#include FT_SVG_RENDER_H
|
||||
|
||||
|
||||
FT_BEGIN_HEADER
|
||||
|
||||
typedef FT_Error
|
||||
(*Preset_Bitmap_Func)( FT_Module module,
|
||||
FT_GlyphSlot slot,
|
||||
FT_Bool cache );
|
||||
|
||||
typedef struct SVG_Interface_
|
||||
{
|
||||
Preset_Bitmap_Func preset_slot;
|
||||
} SVG_Interface;
|
||||
|
||||
typedef SVG_Interface* SVG_Service;
|
||||
|
||||
FT_END_HEADER
|
||||
|
||||
#endif
|
|
@ -82,44 +82,32 @@ FT_BEGIN_HEADER
|
|||
* slot ::
|
||||
* The whole glyph slot object.
|
||||
*
|
||||
* outline_bbox ::
|
||||
* The bounding box of the glyph in font units. So that the renderer
|
||||
* may not need to calculate it again.
|
||||
* @return:
|
||||
* FreeType error code. 0 means success.
|
||||
*/
|
||||
|
||||
typedef FT_Error
|
||||
(*SVG_Lib_Render_Func)( FT_GlyphSlot slot );
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @functype:
|
||||
* SVG_Lib_Preset_Slot_Func
|
||||
*
|
||||
* @description:
|
||||
* A callback which is to preset the glyphslot.
|
||||
*
|
||||
* @input:
|
||||
* slot ::
|
||||
* The glyph slot which has the SVG document loaded.
|
||||
*
|
||||
* @return:
|
||||
* FreeType error code. 0 means success.
|
||||
*/
|
||||
|
||||
typedef FT_Error
|
||||
(*SVG_Lib_Render_Func)( FT_GlyphSlot slot,
|
||||
FT_BBox outline_bbox);
|
||||
(*SVG_Lib_Preset_Slot_Func)( FT_GlyphSlot slot, FT_Bool cache);
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @functype:
|
||||
* SVG_Lib_Get_Buffer_Size_Func
|
||||
*
|
||||
* @description:
|
||||
* A callback which is called to get the size of the image buffer needed.
|
||||
* This buffer will ultimately be populated by `SVG_Lib_Render_Func`
|
||||
* hook.
|
||||
*
|
||||
* @input:
|
||||
* slot ::
|
||||
* The glyph slot which has the SVG document loaded as well as other
|
||||
* info.
|
||||
*
|
||||
* bbox ::
|
||||
* The bbox in font units. This is required for the rendering port to
|
||||
* predict the final size of the image buffer.
|
||||
*
|
||||
* @return:
|
||||
* Size of the state structure in bytes.
|
||||
*/
|
||||
|
||||
typedef FT_ULong
|
||||
(*SVG_Lib_Get_Buffer_Size_Func)( FT_GlyphSlot slot,
|
||||
FT_BBox bbox );
|
||||
|
||||
typedef struct SVG_RendererHooks_
|
||||
{
|
||||
|
@ -128,9 +116,10 @@ FT_BEGIN_HEADER
|
|||
SVG_Lib_Free_Func free_svg;
|
||||
SVG_Lib_Render_Func render_svg;
|
||||
|
||||
SVG_Lib_Get_Buffer_Size_Func get_buffer_size;
|
||||
SVG_Lib_Preset_Slot_Func preset_slot;
|
||||
} SVG_RendererHooks;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @struct:
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include FT_INTERNAL_STREAM_H
|
||||
#include FT_INTERNAL_SFNT_H /* for SFNT_Load_Table_Func */
|
||||
#include FT_INTERNAL_POSTSCRIPT_AUX_H /* for PS_Driver */
|
||||
#include FT_INTERNAL_SVG_INTERFACE_H
|
||||
|
||||
#include FT_TRUETYPE_TABLES_H
|
||||
#include FT_TRUETYPE_TAGS_H
|
||||
|
@ -363,6 +364,7 @@
|
|||
{
|
||||
FT_Outline* outline = &slot->outline;
|
||||
FT_Bitmap* bitmap = &slot->bitmap;
|
||||
FT_Module module;
|
||||
|
||||
FT_Pixel_Mode pixel_mode;
|
||||
|
||||
|
@ -374,7 +376,17 @@
|
|||
|
||||
|
||||
if ( slot->format != FT_GLYPH_FORMAT_OUTLINE )
|
||||
return 1;
|
||||
{
|
||||
if ( slot->format == FT_GLYPH_FORMAT_SVG )
|
||||
{
|
||||
module = FT_Get_Module(slot->library, "ot-svg" );
|
||||
SVG_Service svg_service = module->clazz->module_interface;
|
||||
|
||||
svg_service->preset_slot( module, slot, FALSE );
|
||||
}
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ( origin )
|
||||
{
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include FT_INTERNAL_DEBUG_H
|
||||
#include FT_SERVICE_PROPERTIES_H
|
||||
#include FT_SVG_RENDER_H
|
||||
#include FT_INTERNAL_SVG_INTERFACE_H
|
||||
#include FT_BBOX_H
|
||||
|
||||
#ifdef FT_CONFIG_OPTION_DEFAULT_SVG
|
||||
|
@ -43,7 +44,7 @@
|
|||
svg_module->hooks.init_svg = (SVG_Lib_Init_Func)rsvg_port_init;
|
||||
svg_module->hooks.free_svg = (SVG_Lib_Free_Func)rsvg_port_free;
|
||||
svg_module->hooks.render_svg = (SVG_Lib_Render_Func)rsvg_port_render;
|
||||
svg_module->hooks.get_buffer_size = (SVG_Lib_Get_Buffer_Size_Func)rsvg_port_get_buffer_size;
|
||||
svg_module->hooks.preset_slot = (SVG_Lib_Preset_Slot_Func)rsvg_port_preset_slot;
|
||||
svg_module->hooks_set = TRUE;
|
||||
#else
|
||||
FT_TRACE3(( "ft_svg_init: No default hooks set\n" ));
|
||||
|
@ -62,6 +63,23 @@
|
|||
svg_module->loaded = FALSE;
|
||||
}
|
||||
|
||||
static FT_Error
|
||||
ft_svg_preset_slot( FT_Module module,
|
||||
FT_GlyphSlot slot,
|
||||
FT_Bool cache )
|
||||
{
|
||||
SVG_Renderer svg_renderer = (SVG_Renderer)module;
|
||||
SVG_RendererHooks hooks = svg_renderer->hooks;
|
||||
|
||||
if ( svg_renderer->hooks_set == FALSE )
|
||||
{
|
||||
FT_TRACE1(( "Hooks are NOT set. Can't render OT-SVG glyphs\n" ));
|
||||
return FT_THROW( Missing_SVG_Hooks );
|
||||
}
|
||||
|
||||
return hooks.preset_slot( slot, cache );
|
||||
}
|
||||
|
||||
static FT_Error
|
||||
ft_svg_render( FT_Renderer renderer,
|
||||
FT_GlyphSlot slot,
|
||||
|
@ -71,7 +89,6 @@
|
|||
SVG_Renderer svg_renderer = (SVG_Renderer)renderer;
|
||||
FT_Library library = renderer->root.library;
|
||||
FT_Memory memory = library->memory;
|
||||
FT_BBox outline_bbox;
|
||||
FT_Error error;
|
||||
FT_ULong size_image_buffer;
|
||||
|
||||
|
@ -90,20 +107,19 @@
|
|||
svg_renderer->loaded = TRUE;
|
||||
}
|
||||
|
||||
/* Let's calculate the bounding box in font units here */
|
||||
error = FT_Outline_Get_BBox( &slot->outline, &outline_bbox );
|
||||
if( error != FT_Err_Ok )
|
||||
return error;
|
||||
|
||||
size_image_buffer = hooks.get_buffer_size( slot, outline_bbox );
|
||||
|
||||
FT_MEM_ALLOC( slot->bitmap.buffer, size_image_buffer );
|
||||
ft_svg_preset_slot( renderer, slot, TRUE);
|
||||
size_image_buffer = slot->bitmap.pitch * slot->bitmap.rows;
|
||||
FT_MEM_ALLOC( slot->bitmap.buffer, size_image_buffer);
|
||||
if ( error )
|
||||
return error;
|
||||
|
||||
return hooks.render_svg( slot, outline_bbox );
|
||||
return hooks.render_svg( slot );
|
||||
}
|
||||
|
||||
static const SVG_Interface svg_interface = {
|
||||
(Preset_Bitmap_Func)ft_svg_preset_slot
|
||||
};
|
||||
|
||||
static FT_Error
|
||||
ft_svg_property_set( FT_Module module,
|
||||
const char* property_name,
|
||||
|
@ -188,7 +204,7 @@
|
|||
"ot-svg",
|
||||
0x10000L,
|
||||
0x20000L,
|
||||
NULL, /* module specific interface */
|
||||
(const void*)&svg_interface, /* module specific interface */
|
||||
(FT_Module_Constructor)PUT_SVG_MODULE( ft_svg_init ), /* module_init */
|
||||
(FT_Module_Destructor)PUT_SVG_MODULE( ft_svg_done ), /* module_done */
|
||||
PUT_SVG_MODULE( ft_svg_get_interface ), /* get_interface */
|
||||
|
|
Loading…
Reference in New Issue