1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
/****************************************************************************
*
* ftsvg.c
*
* The FreeType svg renderer interface (body).
*
* 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.
*
*/
#include <ft2build.h>
#include FT_INTERNAL_DEBUG_H
#include FT_SERVICE_PROPERTIES_H
#include FT_SVG_RENDER_H
#include FT_BBOX_H
#include <stdio.h>
#include "ftsvg.h"
/* ft_svg_init */
static FT_Error
ft_svg_init( SVG_Renderer svg_module )
{
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.free_svg( library );
svg_module->loaded = FALSE;
}
static FT_Error
ft_svg_render( FT_Renderer renderer,
FT_GlyphSlot slot,
FT_Render_Mode mode,
const FT_Vector* origin )
{
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;
SVG_RendererHooks hooks = svg_renderer->hooks;
if ( svg_renderer->loaded == FALSE )
{
error = hooks.init_svg( library );
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 );
if ( error )
return error;
return hooks.render_svg( slot, outline_bbox );
}
static FT_Error
ft_svg_property_set( FT_Module module,
const char* property_name,
const void* value,
FT_Bool value_is_string )
{
FT_Error error = FT_Err_Ok;
SVG_Renderer renderer = (SVG_Renderer)module;
if ( !ft_strcmp( property_name, "svg_hooks" ) )
{
SVG_RendererHooks* hooks = (SVG_RendererHooks*)value;
renderer->hooks = *hooks;
}
else
{
error = FT_THROW( Missing_Property );
}
return error;
}
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;
if ( !ft_strcmp( property_name, "svg_hooks" ) )
{
SVG_RendererHooks* hooks = (SVG_RendererHooks*)value;
*hooks = renderer->hooks;
}
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 )
FT_CALLBACK_DEF( FT_Module_Interface )
ft_svg_get_interface( FT_Module module,
const char* ft_svg_interface )
{
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,
FT_MODULE_RENDERER,
sizeof( SVG_RendererRec ),
"ot-svg",
0x10000L,
0x20000L,
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,
NULL,
NULL,
NULL
)
|