summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoazin Khatti <moazinkhatri@gmail.com>2019-08-06 23:32:41 +0500
committerMoazin Khatti <moazinkhatri@gmail.com>2019-08-26 01:17:14 +0500
commitdbcc809e7c6f6e943b8842af2b8bd76da2643d97 (patch)
treea067842c59d83ac0d867310be0490f6a924c8efe
parent398801e2c0dace6c1ea80f92dfd84a8e0178f932 (diff)
downloadfreetype2-dbcc809e7c6f6e943b8842af2b8bd76da2643d97.tar.gz
relying on cairo recording surface for extents and preset bitmap at load time, work in progress
-rw-r--r--include/freetype/internal/internal.h1
-rw-r--r--include/freetype/internal/svginterface.h42
-rw-r--r--include/freetype/svgrender.h31
-rw-r--r--src/base/ftobjs.c14
-rw-r--r--src/svg/ftsvg.c40
5 files changed, 94 insertions, 34 deletions
diff --git a/include/freetype/internal/internal.h b/include/freetype/internal/internal.h
index 3c8830f7e..79df6d74e 100644
--- a/include/freetype/internal/internal.h
+++ b/include/freetype/internal/internal.h
@@ -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>
diff --git a/include/freetype/internal/svginterface.h b/include/freetype/internal/svginterface.h
new file mode 100644
index 000000000..a94631e6f
--- /dev/null
+++ b/include/freetype/internal/svginterface.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
diff --git a/include/freetype/svgrender.h b/include/freetype/svgrender.h
index b0932b4a2..4c883580a 100644
--- a/include/freetype/svgrender.h
+++ b/include/freetype/svgrender.h
@@ -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,
- FT_BBox outline_bbox);
+ (*SVG_Lib_Render_Func)( FT_GlyphSlot slot );
/**************************************************************************
*
* @functype:
- * SVG_Lib_Get_Buffer_Size_Func
+ * SVG_Lib_Preset_Slot_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.
+ * A callback which is to preset the glyphslot.
*
* @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.
+ * The glyph slot which has the SVG document loaded.
*
* @return:
- * Size of the state structure in bytes.
+ * FreeType error code. 0 means success.
*/
- typedef FT_ULong
- (*SVG_Lib_Get_Buffer_Size_Func)( FT_GlyphSlot slot,
- FT_BBox bbox );
+ typedef FT_Error
+ (*SVG_Lib_Preset_Slot_Func)( FT_GlyphSlot slot, FT_Bool cache);
+
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:
diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c
index b4b626585..f4fb1db6c 100644
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -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 )
{
diff --git a/src/svg/ftsvg.c b/src/svg/ftsvg.c
index 2db947f28..ce778624b 100644
--- a/src/svg/ftsvg.c
+++ b/src/svg/ftsvg.c
@@ -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" ));
@@ -63,6 +64,23 @@
}
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,
FT_Render_Mode mode,
@@ -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 */