sdk-world v2026.11.05
PS2 SDK - world tier (copyleft-allowed, non-essential packages)
Loading...
Searching...
No Matches
otsvg.h
Go to the documentation of this file.
1/****************************************************************************
2 *
3 * otsvg.h
4 *
5 * Interface for OT-SVG support related things (specification).
6 *
7 * Copyright (C) 2022-2025 by
8 * David Turner, Robert Wilhelm, Werner Lemberg, and Moazin Khatti.
9 *
10 * This file is part of the FreeType project, and may only be used,
11 * modified, and distributed under the terms of the FreeType project
12 * license, LICENSE.TXT. By continuing to use, modify, or distribute
13 * this file you indicate that you have read the license and
14 * understand and accept it fully.
15 *
16 */
17
18
23#ifndef OTSVG_H_
24#define OTSVG_H_
25
26#include <freetype/freetype.h>
27
28#ifdef FREETYPE_H
29#error "freetype.h of FreeType 1 has been loaded!"
30#error "Please fix the directory search order for header files"
31#error "so that freetype.h of FreeType 2 is found first."
32#endif
33
34
35FT_BEGIN_HEADER
36
37
38 /**************************************************************************
39 *
40 * @section:
41 * svg_fonts
42 *
43 * @title:
44 * OpenType SVG Fonts
45 *
46 * @abstract:
47 * OT-SVG API between FreeType and an external SVG rendering library.
48 *
49 * @description:
50 * This section describes the four hooks necessary to render SVG
51 * 'documents' that are contained in an OpenType font's 'SVG~' table.
52 *
53 * For more information on the implementation, see our standard hooks
54 * based on 'librsvg' in the [FreeType Demo
55 * Programs](https://gitlab.freedesktop.org/freetype/freetype-demos)
56 * repository.
57 *
58 */
59
60
61 /**************************************************************************
62 *
63 * @functype:
64 * SVG_Lib_Init_Func
65 *
66 * @description:
67 * A callback that is called when the first OT-SVG glyph is rendered in
68 * the lifetime of an @FT_Library object. In a typical implementation,
69 * one would want to allocate a structure and point the `data_pointer`
70 * to it and perform any library initializations that might be needed.
71 *
72 * @inout:
73 * data_pointer ::
74 * The SVG rendering module stores a pointer variable that can be used
75 * by clients to store any data that needs to be shared across
76 * different hooks. `data_pointer` is essentially a pointer to that
77 * pointer such that it can be written to as well as read from.
78 *
79 * @return:
80 * FreeType error code. 0 means success.
81 *
82 * @since:
83 * 2.12
84 */
85 typedef FT_Error
86 (*SVG_Lib_Init_Func)( FT_Pointer *data_pointer );
87
88
89 /**************************************************************************
90 *
91 * @functype:
92 * SVG_Lib_Free_Func
93 *
94 * @description:
95 * A callback that is called when the `ot-svg` module is being freed.
96 * It is only called if the init hook was called earlier. This means
97 * that neither the init nor the free hook is called if no OT-SVG glyph
98 * is rendered.
99 *
100 * In a typical implementation, one would want to free any state
101 * structure that was allocated in the init hook and perform any
102 * library-related closure that might be needed.
103 *
104 * @inout:
105 * data_pointer ::
106 * The SVG rendering module stores a pointer variable that can be used
107 * by clients to store any data that needs to be shared across
108 * different hooks. `data_pointer` is essentially a pointer to that
109 * pointer such that it can be written to as well as read from.
110 *
111 * @since:
112 * 2.12
113 */
114 typedef void
115 (*SVG_Lib_Free_Func)( FT_Pointer *data_pointer );
116
117
118 /**************************************************************************
119 *
120 * @functype:
121 * SVG_Lib_Render_Func
122 *
123 * @description:
124 * A callback that is called to render an OT-SVG glyph. This callback
125 * hook is called right after the preset hook @SVG_Lib_Preset_Slot_Func
126 * has been called with `cache` set to `TRUE`. The data necessary to
127 * render is available through the handle @FT_SVG_Document, which is set
128 * in the `other` field of @FT_GlyphSlotRec.
129 *
130 * The render hook is expected to render the SVG glyph to the bitmap
131 * buffer that is allocated already at `slot->bitmap.buffer`. It also
132 * sets the `num_grays` value as well as `slot->format`.
133 *
134 * @input:
135 * slot ::
136 * The slot to render.
137 *
138 * @inout:
139 * data_pointer ::
140 * The SVG rendering module stores a pointer variable that can be used
141 * by clients to store any data that needs to be shared across
142 * different hooks. `data_pointer` is essentially a pointer to that
143 * pointer such that it can be written to as well as read from.
144 *
145 * @return:
146 * FreeType error code. 0 means success.
147 *
148 * @since:
149 * 2.12
150 */
151 typedef FT_Error
152 (*SVG_Lib_Render_Func)( FT_GlyphSlot slot,
153 FT_Pointer *data_pointer );
154
155
156 /**************************************************************************
157 *
158 * @functype:
159 * SVG_Lib_Preset_Slot_Func
160 *
161 * @description:
162 * A callback that is called to preset the glyph slot. It is called from
163 * two places.
164 *
165 * 1. When `FT_Load_Glyph` needs to preset the glyph slot.
166 *
167 * 2. Right before the `svg` module calls the render callback hook.
168 *
169 * When it is the former, the argument `cache` is set to `FALSE`. When
170 * it is the latter, the argument `cache` is set to `TRUE`. This
171 * distinction has been made because many calculations that are necessary
172 * for presetting a glyph slot are the same needed later for the render
173 * callback hook. Thus, if `cache` is `TRUE`, the hook can _cache_ those
174 * calculations in a memory block referenced by the state pointer.
175 *
176 * This hook is expected to preset the slot by setting parameters such as
177 * `bitmap_left`, `bitmap_top`, `width`, `rows`, `pitch`, and
178 * `pixel_mode`. It is also expected to set all the metrics for the slot
179 * including the vertical advance if it is not already set. Typically,
180 * fonts have horizontal advances but not vertical ones. If those are
181 * available, they had already been set, otherwise they have to be
182 * estimated and set manually. The hook must take into account the
183 * transformations that have been set, and translate the transformation
184 * matrices into the SVG coordinate system, as the original matrix is
185 * intended for the TTF/CFF coordinate system.
186 *
187 * @input:
188 * slot ::
189 * The glyph slot that has the SVG document loaded.
190 *
191 * cache ::
192 * See description.
193 *
194 * @inout:
195 * data_pointer ::
196 * The SVG rendering module stores a pointer variable that can be used
197 * by clients to store any data that needs to be shared across
198 * different hooks. `data_pointer` is essentially a pointer to that
199 * pointer such that it can be written to as well as read from.
200 *
201 * @return:
202 * FreeType error code. 0 means success.
203 *
204 * @since:
205 * 2.12
206 */
207 typedef FT_Error
208 (*SVG_Lib_Preset_Slot_Func)( FT_GlyphSlot slot,
209 FT_Bool cache,
210 FT_Pointer *state );
211
212
213 /**************************************************************************
214 *
215 * @struct:
216 * SVG_RendererHooks
217 *
218 * @description:
219 * A structure that stores the four hooks needed to render OT-SVG glyphs
220 * properly. The structure is publicly used to set the hooks via the
221 * @svg-hooks driver property.
222 *
223 * The behavior of each hook is described in its documentation. One
224 * thing to note is that the preset hook and the render hook often need
225 * to do the same operations; therefore, it's better to cache the
226 * intermediate data in a state structure to avoid calculating it twice.
227 * For example, in the preset hook one can draw the glyph on a recorder
228 * surface and later create a bitmap surface from it in the render hook.
229 *
230 * All four hooks must be non-NULL.
231 *
232 * @fields:
233 * init_svg ::
234 * The initialization hook.
235 *
236 * free_svg ::
237 * The cleanup hook.
238 *
239 * render_hook ::
240 * The render hook.
241 *
242 * preset_slot ::
243 * The preset hook.
244 *
245 * @since:
246 * 2.12
247 */
248 typedef struct SVG_RendererHooks_
249 {
250 SVG_Lib_Init_Func init_svg;
251 SVG_Lib_Free_Func free_svg;
252 SVG_Lib_Render_Func render_svg;
253
254 SVG_Lib_Preset_Slot_Func preset_slot;
255
256 } SVG_RendererHooks;
257
258
259 /**************************************************************************
260 *
261 * @struct:
262 * FT_SVG_DocumentRec
263 *
264 * @description:
265 * A structure that models one SVG document.
266 *
267 * @fields:
268 * svg_document ::
269 * A pointer to the SVG document.
270 *
271 * svg_document_length ::
272 * The length of `svg_document`.
273 *
274 * metrics ::
275 * A metrics object storing the size information.
276 *
277 * units_per_EM ::
278 * The size of the EM square.
279 *
280 * start_glyph_id ::
281 * The first glyph ID in the glyph range covered by this document.
282 *
283 * end_glyph_id ::
284 * The last glyph ID in the glyph range covered by this document.
285 *
286 * transform ::
287 * A 2x2 transformation matrix to apply to the glyph while rendering
288 * it.
289 *
290 * delta ::
291 * The translation to apply to the glyph while rendering.
292 *
293 * @note:
294 * When an @FT_GlyphSlot object `slot` is passed down to a renderer, the
295 * renderer can only access the `metrics` and `units_per_EM` fields via
296 * `slot->face`. However, when @FT_Glyph_To_Bitmap sets up a dummy
297 * object, it has no way to set a `face` object. Thus, metrics
298 * information and `units_per_EM` (which is necessary for OT-SVG) has to
299 * be stored separately.
300 *
301 * @since:
302 * 2.12
303 */
304 typedef struct FT_SVG_DocumentRec_
305 {
306 FT_Byte* svg_document;
307 FT_ULong svg_document_length;
308
309 FT_Size_Metrics metrics;
310 FT_UShort units_per_EM;
311
312 FT_UShort start_glyph_id;
313 FT_UShort end_glyph_id;
314
315 FT_Matrix transform;
316 FT_Vector delta;
317
318 } FT_SVG_DocumentRec;
319
320
321 /**************************************************************************
322 *
323 * @type:
324 * FT_SVG_Document
325 *
326 * @description:
327 * A handle to an @FT_SVG_DocumentRec object.
328 *
329 * @since:
330 * 2.12
331 */
332 typedef struct FT_SVG_DocumentRec_* FT_SVG_Document;
333
334
335FT_END_HEADER
336
337#endif /* OTSVG_H_ */
338
339
340/* END */