/work/workdir/UnpackedTarball/harfbuzz/src/hb-font.cc
Line | Count | Source |
1 | | /* |
2 | | * Copyright © 2009 Red Hat, Inc. |
3 | | * Copyright © 2012 Google, Inc. |
4 | | * |
5 | | * This is part of HarfBuzz, a text shaping library. |
6 | | * |
7 | | * Permission is hereby granted, without written agreement and without |
8 | | * license or royalty fees, to use, copy, modify, and distribute this |
9 | | * software and its documentation for any purpose, provided that the |
10 | | * above copyright notice and the following two paragraphs appear in |
11 | | * all copies of this software. |
12 | | * |
13 | | * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
14 | | * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
15 | | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
16 | | * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
17 | | * DAMAGE. |
18 | | * |
19 | | * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
20 | | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
21 | | * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
22 | | * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
23 | | * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
24 | | * |
25 | | * Red Hat Author(s): Behdad Esfahbod |
26 | | * Google Author(s): Behdad Esfahbod |
27 | | */ |
28 | | |
29 | | #include "hb.hh" |
30 | | |
31 | | #include "hb-font.hh" |
32 | | #include "hb-draw.hh" |
33 | | #include "hb-paint.hh" |
34 | | #include "hb-machinery.hh" |
35 | | |
36 | | #include "hb-ot.h" |
37 | | |
38 | | #include "hb-ot-var-avar-table.hh" |
39 | | #include "hb-ot-var-fvar-table.hh" |
40 | | |
41 | | #ifndef HB_NO_OT_FONT |
42 | | #include "hb-ot.h" |
43 | | #endif |
44 | | #ifdef HAVE_FREETYPE |
45 | | #include "hb-ft.h" |
46 | | #endif |
47 | | #ifdef HAVE_FONTATIONS |
48 | | #include "hb-fontations.h" |
49 | | #endif |
50 | | #ifdef HAVE_CORETEXT |
51 | | #include "hb-coretext.h" |
52 | | #endif |
53 | | #ifdef HAVE_DIRECTWRITE |
54 | | #include "hb-directwrite.h" |
55 | | #endif |
56 | | |
57 | | |
58 | | /** |
59 | | * SECTION:hb-font |
60 | | * @title: hb-font |
61 | | * @short_description: Font objects |
62 | | * @include: hb.h |
63 | | * |
64 | | * Functions for working with font objects. |
65 | | * |
66 | | * A font object represents a font face at a specific size and with |
67 | | * certain other parameters (pixels-per-em, points-per-em, variation |
68 | | * settings) specified. Font objects are created from font face |
69 | | * objects, and are used as input to hb_shape(), among other things. |
70 | | * |
71 | | * Client programs can optionally pass in their own functions that |
72 | | * implement the basic, lower-level queries of font objects. This set |
73 | | * of font functions is defined by the virtual methods in |
74 | | * #hb_font_funcs_t. |
75 | | * |
76 | | * HarfBuzz provides a built-in set of lightweight default |
77 | | * functions for each method in #hb_font_funcs_t. |
78 | | * |
79 | | * The default font functions are implemented in terms of the |
80 | | * #hb_font_funcs_t methods of the parent font object. This allows |
81 | | * client programs to override only the methods they need to, and |
82 | | * otherwise inherit the parent font's implementation, if any. |
83 | | **/ |
84 | | |
85 | | |
86 | | /* |
87 | | * hb_font_funcs_t |
88 | | */ |
89 | | |
90 | | static hb_bool_t |
91 | | hb_font_get_font_h_extents_nil (hb_font_t *font HB_UNUSED, |
92 | | void *font_data HB_UNUSED, |
93 | | hb_font_extents_t *extents, |
94 | | void *user_data HB_UNUSED) |
95 | 0 | { |
96 | 0 | hb_memset (extents, 0, sizeof (*extents)); |
97 | 0 | return false; |
98 | 0 | } |
99 | | |
100 | | static hb_bool_t |
101 | | hb_font_get_font_h_extents_default (hb_font_t *font, |
102 | | void *font_data HB_UNUSED, |
103 | | hb_font_extents_t *extents, |
104 | | void *user_data HB_UNUSED) |
105 | 0 | { |
106 | 0 | hb_bool_t ret = font->parent->get_font_h_extents (extents, false); |
107 | 0 | if (ret) { |
108 | 0 | extents->ascender = font->parent_scale_y_distance (extents->ascender); |
109 | 0 | extents->descender = font->parent_scale_y_distance (extents->descender); |
110 | 0 | extents->line_gap = font->parent_scale_y_distance (extents->line_gap); |
111 | 0 | } |
112 | 0 | return ret; |
113 | 0 | } |
114 | | |
115 | | static hb_bool_t |
116 | | hb_font_get_font_v_extents_nil (hb_font_t *font HB_UNUSED, |
117 | | void *font_data HB_UNUSED, |
118 | | hb_font_extents_t *extents, |
119 | | void *user_data HB_UNUSED) |
120 | 0 | { |
121 | 0 | hb_memset (extents, 0, sizeof (*extents)); |
122 | 0 | return false; |
123 | 0 | } |
124 | | |
125 | | static hb_bool_t |
126 | | hb_font_get_font_v_extents_default (hb_font_t *font, |
127 | | void *font_data HB_UNUSED, |
128 | | hb_font_extents_t *extents, |
129 | | void *user_data HB_UNUSED) |
130 | 0 | { |
131 | 0 | hb_bool_t ret = font->parent->get_font_v_extents (extents, false); |
132 | 0 | if (ret) { |
133 | 0 | extents->ascender = font->parent_scale_x_distance (extents->ascender); |
134 | 0 | extents->descender = font->parent_scale_x_distance (extents->descender); |
135 | 0 | extents->line_gap = font->parent_scale_x_distance (extents->line_gap); |
136 | 0 | } |
137 | 0 | return ret; |
138 | 0 | } |
139 | | |
140 | | static hb_bool_t |
141 | | hb_font_get_nominal_glyph_nil (hb_font_t *font HB_UNUSED, |
142 | | void *font_data HB_UNUSED, |
143 | | hb_codepoint_t unicode HB_UNUSED, |
144 | | hb_codepoint_t *glyph, |
145 | | void *user_data HB_UNUSED) |
146 | 0 | { |
147 | 0 | *glyph = 0; |
148 | 0 | return false; |
149 | 0 | } |
150 | | |
151 | | static hb_bool_t |
152 | | hb_font_get_nominal_glyph_default (hb_font_t *font, |
153 | | void *font_data HB_UNUSED, |
154 | | hb_codepoint_t unicode, |
155 | | hb_codepoint_t *glyph, |
156 | | void *user_data HB_UNUSED) |
157 | 0 | { |
158 | 0 | if (font->has_nominal_glyphs_func_set ()) |
159 | 0 | { |
160 | 0 | return font->get_nominal_glyphs (1, &unicode, 0, glyph, 0); |
161 | 0 | } |
162 | 0 | return font->parent->get_nominal_glyph (unicode, glyph); |
163 | 0 | } |
164 | | |
165 | | #define hb_font_get_nominal_glyphs_nil hb_font_get_nominal_glyphs_default |
166 | | |
167 | | static unsigned int |
168 | | hb_font_get_nominal_glyphs_default (hb_font_t *font, |
169 | | void *font_data HB_UNUSED, |
170 | | unsigned int count, |
171 | | const hb_codepoint_t *first_unicode, |
172 | | unsigned int unicode_stride, |
173 | | hb_codepoint_t *first_glyph, |
174 | | unsigned int glyph_stride, |
175 | | void *user_data HB_UNUSED) |
176 | 0 | { |
177 | 0 | if (font->has_nominal_glyph_func_set ()) |
178 | 0 | { |
179 | 0 | for (unsigned int i = 0; i < count; i++) |
180 | 0 | { |
181 | 0 | if (!font->get_nominal_glyph (*first_unicode, first_glyph)) |
182 | 0 | return i; |
183 | | |
184 | 0 | first_unicode = &StructAtOffsetUnaligned<hb_codepoint_t> (first_unicode, unicode_stride); |
185 | 0 | first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride); |
186 | 0 | } |
187 | 0 | return count; |
188 | 0 | } |
189 | | |
190 | 0 | return font->parent->get_nominal_glyphs (count, |
191 | 0 | first_unicode, unicode_stride, |
192 | 0 | first_glyph, glyph_stride); |
193 | 0 | } |
194 | | |
195 | | static hb_bool_t |
196 | | hb_font_get_variation_glyph_nil (hb_font_t *font HB_UNUSED, |
197 | | void *font_data HB_UNUSED, |
198 | | hb_codepoint_t unicode HB_UNUSED, |
199 | | hb_codepoint_t variation_selector HB_UNUSED, |
200 | | hb_codepoint_t *glyph, |
201 | | void *user_data HB_UNUSED) |
202 | 0 | { |
203 | 0 | *glyph = 0; |
204 | 0 | return false; |
205 | 0 | } |
206 | | |
207 | | static hb_bool_t |
208 | | hb_font_get_variation_glyph_default (hb_font_t *font, |
209 | | void *font_data HB_UNUSED, |
210 | | hb_codepoint_t unicode, |
211 | | hb_codepoint_t variation_selector, |
212 | | hb_codepoint_t *glyph, |
213 | | void *user_data HB_UNUSED) |
214 | 0 | { |
215 | 0 | return font->parent->get_variation_glyph (unicode, variation_selector, glyph); |
216 | 0 | } |
217 | | |
218 | | |
219 | | static hb_position_t |
220 | | hb_font_get_glyph_h_advance_nil (hb_font_t *font, |
221 | | void *font_data HB_UNUSED, |
222 | | hb_codepoint_t glyph HB_UNUSED, |
223 | | void *user_data HB_UNUSED) |
224 | 0 | { |
225 | 0 | return font->x_scale; |
226 | 0 | } |
227 | | |
228 | | static hb_position_t |
229 | | hb_font_get_glyph_h_advance_default (hb_font_t *font, |
230 | | void *font_data HB_UNUSED, |
231 | | hb_codepoint_t glyph, |
232 | | void *user_data HB_UNUSED) |
233 | 9.77M | { |
234 | 9.77M | if (font->has_glyph_h_advances_func_set ()) |
235 | 9.77M | { |
236 | 9.77M | hb_position_t ret; |
237 | 9.77M | font->get_glyph_h_advances (1, &glyph, 0, &ret, 0, false); |
238 | 9.77M | return ret; |
239 | 9.77M | } |
240 | 0 | return font->parent_scale_x_distance (font->parent->get_glyph_h_advance (glyph, false)); |
241 | 9.77M | } |
242 | | |
243 | | static hb_position_t |
244 | | hb_font_get_glyph_v_advance_nil (hb_font_t *font, |
245 | | void *font_data HB_UNUSED, |
246 | | hb_codepoint_t glyph HB_UNUSED, |
247 | | void *user_data HB_UNUSED) |
248 | 0 | { |
249 | 0 | return -font->y_scale; |
250 | 0 | } |
251 | | |
252 | | static hb_position_t |
253 | | hb_font_get_glyph_v_advance_default (hb_font_t *font, |
254 | | void *font_data HB_UNUSED, |
255 | | hb_codepoint_t glyph, |
256 | | void *user_data HB_UNUSED) |
257 | 0 | { |
258 | 0 | if (font->has_glyph_v_advances_func_set ()) |
259 | 0 | { |
260 | 0 | hb_position_t ret; |
261 | 0 | font->get_glyph_v_advances (1, &glyph, 0, &ret, 0, false); |
262 | 0 | return ret; |
263 | 0 | } |
264 | 0 | return font->parent_scale_y_distance (font->parent->get_glyph_v_advance (glyph, false)); |
265 | 0 | } |
266 | | |
267 | | #define hb_font_get_glyph_h_advances_nil hb_font_get_glyph_h_advances_default |
268 | | |
269 | | static void |
270 | | hb_font_get_glyph_h_advances_default (hb_font_t* font, |
271 | | void* font_data HB_UNUSED, |
272 | | unsigned int count, |
273 | | const hb_codepoint_t *first_glyph, |
274 | | unsigned int glyph_stride, |
275 | | hb_position_t *first_advance, |
276 | | unsigned int advance_stride, |
277 | | void *user_data HB_UNUSED) |
278 | 0 | { |
279 | 0 | if (font->has_glyph_h_advance_func_set ()) |
280 | 0 | { |
281 | 0 | for (unsigned int i = 0; i < count; i++) |
282 | 0 | { |
283 | 0 | *first_advance = font->get_glyph_h_advance (*first_glyph, false); |
284 | 0 | first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride); |
285 | 0 | first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride); |
286 | 0 | } |
287 | 0 | return; |
288 | 0 | } |
289 | | |
290 | 0 | font->parent->get_glyph_h_advances (count, |
291 | 0 | first_glyph, glyph_stride, |
292 | 0 | first_advance, advance_stride, |
293 | 0 | false); |
294 | 0 | for (unsigned int i = 0; i < count; i++) |
295 | 0 | { |
296 | 0 | *first_advance = font->parent_scale_x_distance (*first_advance); |
297 | 0 | first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride); |
298 | 0 | } |
299 | 0 | } |
300 | | |
301 | | #define hb_font_get_glyph_v_advances_nil hb_font_get_glyph_v_advances_default |
302 | | static void |
303 | | hb_font_get_glyph_v_advances_default (hb_font_t* font, |
304 | | void* font_data HB_UNUSED, |
305 | | unsigned int count, |
306 | | const hb_codepoint_t *first_glyph, |
307 | | unsigned int glyph_stride, |
308 | | hb_position_t *first_advance, |
309 | | unsigned int advance_stride, |
310 | | void *user_data HB_UNUSED) |
311 | 0 | { |
312 | 0 | if (font->has_glyph_v_advance_func_set ()) |
313 | 0 | { |
314 | 0 | for (unsigned int i = 0; i < count; i++) |
315 | 0 | { |
316 | 0 | *first_advance = font->get_glyph_v_advance (*first_glyph, false); |
317 | 0 | first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride); |
318 | 0 | first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride); |
319 | 0 | } |
320 | 0 | return; |
321 | 0 | } |
322 | | |
323 | 0 | font->parent->get_glyph_v_advances (count, |
324 | 0 | first_glyph, glyph_stride, |
325 | 0 | first_advance, advance_stride, |
326 | 0 | false); |
327 | 0 | for (unsigned int i = 0; i < count; i++) |
328 | 0 | { |
329 | 0 | *first_advance = font->parent_scale_y_distance (*first_advance); |
330 | 0 | first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride); |
331 | 0 | } |
332 | 0 | } |
333 | | |
334 | | static hb_bool_t |
335 | | hb_font_get_glyph_h_origin_nil (hb_font_t *font HB_UNUSED, |
336 | | void *font_data HB_UNUSED, |
337 | | hb_codepoint_t glyph HB_UNUSED, |
338 | | hb_position_t *x, |
339 | | hb_position_t *y, |
340 | | void *user_data HB_UNUSED) |
341 | 0 | { |
342 | 0 | *x = *y = 0; |
343 | 0 | return true; |
344 | 0 | } |
345 | | |
346 | | static hb_bool_t |
347 | | hb_font_get_glyph_h_origin_default (hb_font_t *font, |
348 | | void *font_data HB_UNUSED, |
349 | | hb_codepoint_t glyph, |
350 | | hb_position_t *x, |
351 | | hb_position_t *y, |
352 | | void *user_data HB_UNUSED) |
353 | 0 | { |
354 | 0 | if (font->has_glyph_h_origins_func_set ()) |
355 | 0 | { |
356 | 0 | return font->get_glyph_h_origins (1, &glyph, 0, x, 0, y, 0, false); |
357 | 0 | } |
358 | 0 | hb_bool_t ret = font->parent->get_glyph_h_origin (glyph, x, y); |
359 | 0 | if (ret) |
360 | 0 | font->parent_scale_position (x, y); |
361 | 0 | return ret; |
362 | 0 | } |
363 | | |
364 | | static hb_bool_t |
365 | | hb_font_get_glyph_v_origin_nil (hb_font_t *font HB_UNUSED, |
366 | | void *font_data HB_UNUSED, |
367 | | hb_codepoint_t glyph HB_UNUSED, |
368 | | hb_position_t *x, |
369 | | hb_position_t *y, |
370 | | void *user_data HB_UNUSED) |
371 | 0 | { |
372 | 0 | return false; |
373 | 0 | } |
374 | | |
375 | | static hb_bool_t |
376 | | hb_font_get_glyph_v_origin_default (hb_font_t *font, |
377 | | void *font_data HB_UNUSED, |
378 | | hb_codepoint_t glyph, |
379 | | hb_position_t *x, |
380 | | hb_position_t *y, |
381 | | void *user_data HB_UNUSED) |
382 | 0 | { |
383 | 0 | if (font->has_glyph_v_origins_func_set ()) |
384 | 0 | { |
385 | 0 | return font->get_glyph_v_origins (1, &glyph, 0, x, 0, y, 0, false); |
386 | 0 | } |
387 | 0 | hb_bool_t ret = font->parent->get_glyph_v_origin (glyph, x, y); |
388 | 0 | if (ret) |
389 | 0 | font->parent_scale_position (x, y); |
390 | 0 | return ret; |
391 | 0 | } |
392 | | |
393 | | #define hb_font_get_glyph_h_origins_nil hb_font_get_glyph_h_origins_default |
394 | | |
395 | | static hb_bool_t |
396 | | hb_font_get_glyph_h_origins_default (hb_font_t *font HB_UNUSED, |
397 | | void *font_data HB_UNUSED, |
398 | | unsigned int count, |
399 | | const hb_codepoint_t *first_glyph HB_UNUSED, |
400 | | unsigned glyph_stride HB_UNUSED, |
401 | | hb_position_t *first_x, |
402 | | unsigned x_stride, |
403 | | hb_position_t *first_y, |
404 | | unsigned y_stride, |
405 | | void *user_data HB_UNUSED) |
406 | 0 | { |
407 | 0 | if (font->has_glyph_h_origin_func_set ()) |
408 | 0 | { |
409 | 0 | hb_bool_t ret = true; |
410 | 0 | for (unsigned int i = 0; i < count; i++) |
411 | 0 | { |
412 | 0 | ret &= font->get_glyph_h_origin (*first_glyph, first_x, first_y, false); |
413 | 0 | first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride); |
414 | 0 | first_x = &StructAtOffsetUnaligned<hb_position_t> (first_x, x_stride); |
415 | 0 | first_y = &StructAtOffsetUnaligned<hb_position_t> (first_y, y_stride); |
416 | 0 | } |
417 | 0 | return ret; |
418 | 0 | } |
419 | | |
420 | 0 | hb_bool_t ret = font->parent->get_glyph_h_origins (count, |
421 | 0 | first_glyph, glyph_stride, |
422 | 0 | first_x, x_stride, |
423 | 0 | first_y, y_stride); |
424 | 0 | if (ret) |
425 | 0 | { |
426 | 0 | for (unsigned i = 0; i < count; i++) |
427 | 0 | { |
428 | 0 | font->parent_scale_position (first_x, first_y); |
429 | 0 | first_x = &StructAtOffsetUnaligned<hb_position_t> (first_x, x_stride); |
430 | 0 | first_y = &StructAtOffsetUnaligned<hb_position_t> (first_y, y_stride); |
431 | 0 | } |
432 | 0 | } |
433 | 0 | return ret; |
434 | 0 | } |
435 | | |
436 | | #define hb_font_get_glyph_v_origins_nil hb_font_get_glyph_v_origins_default |
437 | | |
438 | | static hb_bool_t |
439 | | hb_font_get_glyph_v_origins_default (hb_font_t *font HB_UNUSED, |
440 | | void *font_data HB_UNUSED, |
441 | | unsigned int count, |
442 | | const hb_codepoint_t *first_glyph HB_UNUSED, |
443 | | unsigned glyph_stride HB_UNUSED, |
444 | | hb_position_t *first_x, |
445 | | unsigned x_stride, |
446 | | hb_position_t *first_y, |
447 | | unsigned y_stride, |
448 | | void *user_data HB_UNUSED) |
449 | 0 | { |
450 | 0 | if (font->has_glyph_v_origin_func_set ()) |
451 | 0 | { |
452 | 0 | hb_bool_t ret = true; |
453 | 0 | for (unsigned int i = 0; i < count; i++) |
454 | 0 | { |
455 | 0 | ret &= font->get_glyph_v_origin (*first_glyph, first_x, first_y, false); |
456 | 0 | first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride); |
457 | 0 | first_x = &StructAtOffsetUnaligned<hb_position_t> (first_x, x_stride); |
458 | 0 | first_y = &StructAtOffsetUnaligned<hb_position_t> (first_y, y_stride); |
459 | 0 | } |
460 | 0 | return ret; |
461 | 0 | } |
462 | | |
463 | 0 | hb_bool_t ret = font->parent->get_glyph_v_origins (count, |
464 | 0 | first_glyph, glyph_stride, |
465 | 0 | first_x, x_stride, |
466 | 0 | first_y, y_stride); |
467 | 0 | if (ret) |
468 | 0 | { |
469 | 0 | for (unsigned i = 0; i < count; i++) |
470 | 0 | { |
471 | 0 | font->parent_scale_position (first_x, first_y); |
472 | 0 | first_x = &StructAtOffsetUnaligned<hb_position_t> (first_x, x_stride); |
473 | 0 | first_y = &StructAtOffsetUnaligned<hb_position_t> (first_y, y_stride); |
474 | 0 | } |
475 | 0 | } |
476 | 0 | return ret; |
477 | 0 | } |
478 | | |
479 | | static hb_position_t |
480 | | hb_font_get_glyph_h_kerning_nil (hb_font_t *font HB_UNUSED, |
481 | | void *font_data HB_UNUSED, |
482 | | hb_codepoint_t left_glyph HB_UNUSED, |
483 | | hb_codepoint_t right_glyph HB_UNUSED, |
484 | | void *user_data HB_UNUSED) |
485 | 0 | { |
486 | 0 | return 0; |
487 | 0 | } |
488 | | |
489 | | static hb_position_t |
490 | | hb_font_get_glyph_h_kerning_default (hb_font_t *font, |
491 | | void *font_data HB_UNUSED, |
492 | | hb_codepoint_t left_glyph, |
493 | | hb_codepoint_t right_glyph, |
494 | | void *user_data HB_UNUSED) |
495 | 0 | { |
496 | 0 | return font->parent_scale_x_distance (font->parent->get_glyph_h_kerning (left_glyph, right_glyph)); |
497 | 0 | } |
498 | | |
499 | | #ifndef HB_DISABLE_DEPRECATED |
500 | | static hb_position_t |
501 | | hb_font_get_glyph_v_kerning_nil (hb_font_t *font HB_UNUSED, |
502 | | void *font_data HB_UNUSED, |
503 | | hb_codepoint_t top_glyph HB_UNUSED, |
504 | | hb_codepoint_t bottom_glyph HB_UNUSED, |
505 | | void *user_data HB_UNUSED) |
506 | 0 | { |
507 | 0 | return 0; |
508 | 0 | } |
509 | | |
510 | | static hb_position_t |
511 | | hb_font_get_glyph_v_kerning_default (hb_font_t *font, |
512 | | void *font_data HB_UNUSED, |
513 | | hb_codepoint_t top_glyph, |
514 | | hb_codepoint_t bottom_glyph, |
515 | | void *user_data HB_UNUSED) |
516 | 0 | { |
517 | 0 | return font->parent_scale_y_distance (font->parent->get_glyph_v_kerning (top_glyph, bottom_glyph)); |
518 | 0 | } |
519 | | #endif |
520 | | |
521 | | static hb_bool_t |
522 | | hb_font_get_glyph_extents_nil (hb_font_t *font HB_UNUSED, |
523 | | void *font_data HB_UNUSED, |
524 | | hb_codepoint_t glyph HB_UNUSED, |
525 | | hb_glyph_extents_t *extents, |
526 | | void *user_data HB_UNUSED) |
527 | 0 | { |
528 | 0 | hb_memset (extents, 0, sizeof (*extents)); |
529 | 0 | return false; |
530 | 0 | } |
531 | | |
532 | | static hb_bool_t |
533 | | hb_font_get_glyph_extents_default (hb_font_t *font, |
534 | | void *font_data HB_UNUSED, |
535 | | hb_codepoint_t glyph, |
536 | | hb_glyph_extents_t *extents, |
537 | | void *user_data HB_UNUSED) |
538 | 0 | { |
539 | 0 | hb_bool_t ret = font->parent->get_glyph_extents (glyph, extents, false); |
540 | 0 | if (ret) { |
541 | 0 | font->parent_scale_position (&extents->x_bearing, &extents->y_bearing); |
542 | 0 | font->parent_scale_distance (&extents->width, &extents->height); |
543 | 0 | } |
544 | 0 | return ret; |
545 | 0 | } |
546 | | |
547 | | static hb_bool_t |
548 | | hb_font_get_glyph_contour_point_nil (hb_font_t *font HB_UNUSED, |
549 | | void *font_data HB_UNUSED, |
550 | | hb_codepoint_t glyph HB_UNUSED, |
551 | | unsigned int point_index HB_UNUSED, |
552 | | hb_position_t *x, |
553 | | hb_position_t *y, |
554 | | void *user_data HB_UNUSED) |
555 | 0 | { |
556 | 0 | *x = *y = 0; |
557 | 0 | return false; |
558 | 0 | } |
559 | | |
560 | | static hb_bool_t |
561 | | hb_font_get_glyph_contour_point_default (hb_font_t *font, |
562 | | void *font_data HB_UNUSED, |
563 | | hb_codepoint_t glyph, |
564 | | unsigned int point_index, |
565 | | hb_position_t *x, |
566 | | hb_position_t *y, |
567 | | void *user_data HB_UNUSED) |
568 | 0 | { |
569 | 0 | hb_bool_t ret = font->parent->get_glyph_contour_point (glyph, point_index, x, y, false); |
570 | 0 | if (ret) |
571 | 0 | font->parent_scale_position (x, y); |
572 | 0 | return ret; |
573 | 0 | } |
574 | | |
575 | | static hb_bool_t |
576 | | hb_font_get_glyph_name_nil (hb_font_t *font HB_UNUSED, |
577 | | void *font_data HB_UNUSED, |
578 | | hb_codepoint_t glyph HB_UNUSED, |
579 | | char *name, |
580 | | unsigned int size, |
581 | | void *user_data HB_UNUSED) |
582 | 0 | { |
583 | 0 | if (size) *name = '\0'; |
584 | 0 | return false; |
585 | 0 | } |
586 | | |
587 | | static hb_bool_t |
588 | | hb_font_get_glyph_name_default (hb_font_t *font, |
589 | | void *font_data HB_UNUSED, |
590 | | hb_codepoint_t glyph, |
591 | | char *name, |
592 | | unsigned int size, |
593 | | void *user_data HB_UNUSED) |
594 | 0 | { |
595 | 0 | return font->parent->get_glyph_name (glyph, name, size); |
596 | 0 | } |
597 | | |
598 | | static hb_bool_t |
599 | | hb_font_get_glyph_from_name_nil (hb_font_t *font HB_UNUSED, |
600 | | void *font_data HB_UNUSED, |
601 | | const char *name HB_UNUSED, |
602 | | int len HB_UNUSED, /* -1 means nul-terminated */ |
603 | | hb_codepoint_t *glyph, |
604 | | void *user_data HB_UNUSED) |
605 | 0 | { |
606 | 0 | *glyph = 0; |
607 | 0 | return false; |
608 | 0 | } |
609 | | |
610 | | static hb_bool_t |
611 | | hb_font_get_glyph_from_name_default (hb_font_t *font, |
612 | | void *font_data HB_UNUSED, |
613 | | const char *name, |
614 | | int len, /* -1 means nul-terminated */ |
615 | | hb_codepoint_t *glyph, |
616 | | void *user_data HB_UNUSED) |
617 | 0 | { |
618 | 0 | return font->parent->get_glyph_from_name (name, len, glyph); |
619 | 0 | } |
620 | | |
621 | | static hb_bool_t |
622 | | hb_font_draw_glyph_or_fail_nil (hb_font_t *font HB_UNUSED, |
623 | | void *font_data HB_UNUSED, |
624 | | hb_codepoint_t glyph, |
625 | | hb_draw_funcs_t *draw_funcs, |
626 | | void *draw_data, |
627 | | void *user_data HB_UNUSED) |
628 | 0 | { |
629 | 0 | return false; |
630 | 0 | } |
631 | | |
632 | | static hb_bool_t |
633 | | hb_font_paint_glyph_or_fail_nil (hb_font_t *font HB_UNUSED, |
634 | | void *font_data HB_UNUSED, |
635 | | hb_codepoint_t glyph HB_UNUSED, |
636 | | hb_paint_funcs_t *paint_funcs HB_UNUSED, |
637 | | void *paint_data HB_UNUSED, |
638 | | unsigned int palette HB_UNUSED, |
639 | | hb_color_t foreground HB_UNUSED, |
640 | | void *user_data HB_UNUSED) |
641 | 0 | { |
642 | 0 | return false; |
643 | 0 | } |
644 | | |
645 | | typedef struct hb_font_draw_glyph_default_adaptor_t { |
646 | | hb_draw_funcs_t *draw_funcs; |
647 | | void *draw_data; |
648 | | float x_scale; |
649 | | float y_scale; |
650 | | } hb_font_draw_glyph_default_adaptor_t; |
651 | | |
652 | | static void |
653 | | hb_draw_move_to_default (hb_draw_funcs_t *dfuncs HB_UNUSED, |
654 | | void *draw_data, |
655 | | hb_draw_state_t *st, |
656 | | float to_x, float to_y, |
657 | | void *user_data HB_UNUSED) |
658 | 0 | { |
659 | 0 | hb_font_draw_glyph_default_adaptor_t *adaptor = (hb_font_draw_glyph_default_adaptor_t *) draw_data; |
660 | 0 | float x_scale = adaptor->x_scale; |
661 | 0 | float y_scale = adaptor->y_scale; |
662 | |
|
663 | 0 | adaptor->draw_funcs->emit_move_to (adaptor->draw_data, *st, |
664 | 0 | x_scale * to_x, y_scale * to_y); |
665 | 0 | } |
666 | | |
667 | | static void |
668 | | hb_draw_line_to_default (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data, |
669 | | hb_draw_state_t *st, |
670 | | float to_x, float to_y, |
671 | | void *user_data HB_UNUSED) |
672 | 0 | { |
673 | 0 | hb_font_draw_glyph_default_adaptor_t *adaptor = (hb_font_draw_glyph_default_adaptor_t *) draw_data; |
674 | 0 | float x_scale = adaptor->x_scale; |
675 | 0 | float y_scale = adaptor->y_scale; |
676 | |
|
677 | 0 | st->current_x = st->current_x * x_scale; |
678 | 0 | st->current_y = st->current_y * y_scale; |
679 | |
|
680 | 0 | adaptor->draw_funcs->emit_line_to (adaptor->draw_data, *st, |
681 | 0 | x_scale * to_x, y_scale * to_y); |
682 | 0 | } |
683 | | |
684 | | static void |
685 | | hb_draw_quadratic_to_default (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data, |
686 | | hb_draw_state_t *st, |
687 | | float control_x, float control_y, |
688 | | float to_x, float to_y, |
689 | | void *user_data HB_UNUSED) |
690 | 0 | { |
691 | 0 | hb_font_draw_glyph_default_adaptor_t *adaptor = (hb_font_draw_glyph_default_adaptor_t *) draw_data; |
692 | 0 | float x_scale = adaptor->x_scale; |
693 | 0 | float y_scale = adaptor->y_scale; |
694 | |
|
695 | 0 | st->current_x = st->current_x * x_scale; |
696 | 0 | st->current_y = st->current_y * y_scale; |
697 | |
|
698 | 0 | adaptor->draw_funcs->emit_quadratic_to (adaptor->draw_data, *st, |
699 | 0 | x_scale * control_x, y_scale * control_y, |
700 | 0 | x_scale * to_x, y_scale * to_y); |
701 | 0 | } |
702 | | |
703 | | static void |
704 | | hb_draw_cubic_to_default (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data, |
705 | | hb_draw_state_t *st, |
706 | | float control1_x, float control1_y, |
707 | | float control2_x, float control2_y, |
708 | | float to_x, float to_y, |
709 | | void *user_data HB_UNUSED) |
710 | 0 | { |
711 | 0 | hb_font_draw_glyph_default_adaptor_t *adaptor = (hb_font_draw_glyph_default_adaptor_t *) draw_data; |
712 | 0 | float x_scale = adaptor->x_scale; |
713 | 0 | float y_scale = adaptor->y_scale; |
714 | |
|
715 | 0 | st->current_x = st->current_x * x_scale; |
716 | 0 | st->current_y = st->current_y * y_scale; |
717 | |
|
718 | 0 | adaptor->draw_funcs->emit_cubic_to (adaptor->draw_data, *st, |
719 | 0 | x_scale * control1_x, y_scale * control1_y, |
720 | 0 | x_scale * control2_x, y_scale * control2_y, |
721 | 0 | x_scale * to_x, y_scale * to_y); |
722 | 0 | } |
723 | | |
724 | | static void |
725 | | hb_draw_close_path_default (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data, |
726 | | hb_draw_state_t *st, |
727 | | void *user_data HB_UNUSED) |
728 | 0 | { |
729 | 0 | hb_font_draw_glyph_default_adaptor_t *adaptor = (hb_font_draw_glyph_default_adaptor_t *) draw_data; |
730 | |
|
731 | 0 | adaptor->draw_funcs->emit_close_path (adaptor->draw_data, *st); |
732 | 0 | } |
733 | | |
734 | | static const hb_draw_funcs_t _hb_draw_funcs_default = { |
735 | | HB_OBJECT_HEADER_STATIC, |
736 | | |
737 | | { |
738 | | #define HB_DRAW_FUNC_IMPLEMENT(name) hb_draw_##name##_default, |
739 | | HB_DRAW_FUNCS_IMPLEMENT_CALLBACKS |
740 | | #undef HB_DRAW_FUNC_IMPLEMENT |
741 | | } |
742 | | }; |
743 | | |
744 | | static hb_bool_t |
745 | | hb_font_draw_glyph_or_fail_default (hb_font_t *font, |
746 | | void *font_data HB_UNUSED, |
747 | | hb_codepoint_t glyph, |
748 | | hb_draw_funcs_t *draw_funcs, |
749 | | void *draw_data, |
750 | | void *user_data HB_UNUSED) |
751 | 0 | { |
752 | 0 | hb_font_draw_glyph_default_adaptor_t adaptor = { |
753 | 0 | draw_funcs, |
754 | 0 | draw_data, |
755 | 0 | font->parent->x_scale ? (float) font->x_scale / (float) font->parent->x_scale : 0.f, |
756 | 0 | font->parent->y_scale ? (float) font->y_scale / (float) font->parent->y_scale : 0.f |
757 | 0 | }; |
758 | |
|
759 | 0 | return font->parent->draw_glyph_or_fail (glyph, |
760 | 0 | const_cast<hb_draw_funcs_t *> (&_hb_draw_funcs_default), |
761 | 0 | &adaptor, |
762 | 0 | false); |
763 | 0 | } |
764 | | |
765 | | static hb_bool_t |
766 | | hb_font_paint_glyph_or_fail_default (hb_font_t *font, |
767 | | void *font_data, |
768 | | hb_codepoint_t glyph, |
769 | | hb_paint_funcs_t *paint_funcs, |
770 | | void *paint_data, |
771 | | unsigned int palette, |
772 | | hb_color_t foreground, |
773 | | void *user_data) |
774 | 0 | { |
775 | 0 | paint_funcs->push_transform (paint_data, |
776 | 0 | font->parent->x_scale ? (float) font->x_scale / (float) font->parent->x_scale : 0, 0, |
777 | 0 | 0, font->parent->y_scale ? (float) font->y_scale / (float) font->parent->y_scale : 0, |
778 | 0 | 0, 0); |
779 | |
|
780 | 0 | bool ret = font->parent->paint_glyph_or_fail (glyph, paint_funcs, paint_data, palette, foreground); |
781 | |
|
782 | 0 | paint_funcs->pop_transform (paint_data); |
783 | |
|
784 | 0 | return ret; |
785 | 0 | } |
786 | | |
787 | | DEFINE_NULL_INSTANCE (hb_font_funcs_t) = |
788 | | { |
789 | | HB_OBJECT_HEADER_STATIC, |
790 | | |
791 | | nullptr, |
792 | | nullptr, |
793 | | { |
794 | | { |
795 | | #define HB_FONT_FUNC_IMPLEMENT(get_,name) hb_font_##get_##name##_nil, |
796 | | HB_FONT_FUNCS_IMPLEMENT_CALLBACKS |
797 | | #undef HB_FONT_FUNC_IMPLEMENT |
798 | | } |
799 | | } |
800 | | }; |
801 | | |
802 | | static const hb_font_funcs_t _hb_font_funcs_default = { |
803 | | HB_OBJECT_HEADER_STATIC, |
804 | | |
805 | | nullptr, |
806 | | nullptr, |
807 | | { |
808 | | { |
809 | | #define HB_FONT_FUNC_IMPLEMENT(get_,name) hb_font_##get_##name##_default, |
810 | | HB_FONT_FUNCS_IMPLEMENT_CALLBACKS |
811 | | #undef HB_FONT_FUNC_IMPLEMENT |
812 | | } |
813 | | } |
814 | | }; |
815 | | |
816 | | |
817 | | /** |
818 | | * hb_font_funcs_create: |
819 | | * |
820 | | * Creates a new #hb_font_funcs_t structure of font functions. |
821 | | * |
822 | | * Return value: (transfer full): The font-functions structure |
823 | | * |
824 | | * Since: 0.9.2 |
825 | | **/ |
826 | | hb_font_funcs_t * |
827 | | hb_font_funcs_create () |
828 | 29 | { |
829 | 29 | hb_font_funcs_t *ffuncs; |
830 | | |
831 | 29 | if (!(ffuncs = hb_object_create<hb_font_funcs_t> ())) |
832 | 0 | return hb_font_funcs_get_empty (); |
833 | | |
834 | 29 | ffuncs->get = _hb_font_funcs_default.get; |
835 | | |
836 | 29 | return ffuncs; |
837 | 29 | } |
838 | | |
839 | | /** |
840 | | * hb_font_funcs_get_empty: |
841 | | * |
842 | | * Fetches an empty font-functions structure. |
843 | | * |
844 | | * Return value: (transfer full): The font-functions structure |
845 | | * |
846 | | * Since: 0.9.2 |
847 | | **/ |
848 | | hb_font_funcs_t * |
849 | | hb_font_funcs_get_empty () |
850 | 429k | { |
851 | 429k | return const_cast<hb_font_funcs_t *> (&_hb_font_funcs_default); |
852 | 429k | } |
853 | | |
854 | | /** |
855 | | * hb_font_funcs_reference: (skip) |
856 | | * @ffuncs: The font-functions structure |
857 | | * |
858 | | * Increases the reference count on a font-functions structure. |
859 | | * |
860 | | * Return value: The font-functions structure |
861 | | * |
862 | | * Since: 0.9.2 |
863 | | **/ |
864 | | hb_font_funcs_t * |
865 | | hb_font_funcs_reference (hb_font_funcs_t *ffuncs) |
866 | 422k | { |
867 | 422k | return hb_object_reference (ffuncs); |
868 | 422k | } |
869 | | |
870 | | /** |
871 | | * hb_font_funcs_destroy: (skip) |
872 | | * @ffuncs: The font-functions structure |
873 | | * |
874 | | * Decreases the reference count on a font-functions structure. When |
875 | | * the reference count reaches zero, the font-functions structure is |
876 | | * destroyed, freeing all memory. |
877 | | * |
878 | | * Since: 0.9.2 |
879 | | **/ |
880 | | void |
881 | | hb_font_funcs_destroy (hb_font_funcs_t *ffuncs) |
882 | 636k | { |
883 | 636k | if (!hb_object_destroy (ffuncs)) return; |
884 | | |
885 | 0 | if (ffuncs->destroy) |
886 | 0 | { |
887 | 0 | #define HB_FONT_FUNC_IMPLEMENT(get_,name) if (ffuncs->destroy->name) \ |
888 | 0 | ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); |
889 | 0 | HB_FONT_FUNCS_IMPLEMENT_CALLBACKS |
890 | 0 | #undef HB_FONT_FUNC_IMPLEMENT |
891 | 0 | } |
892 | |
|
893 | 0 | hb_free (ffuncs->destroy); |
894 | 0 | hb_free (ffuncs->user_data); |
895 | |
|
896 | 0 | hb_free (ffuncs); |
897 | 0 | } |
898 | | |
899 | | /** |
900 | | * hb_font_funcs_set_user_data: (skip) |
901 | | * @ffuncs: The font-functions structure |
902 | | * @key: The user-data key to set |
903 | | * @data: A pointer to the user data set |
904 | | * @destroy: (nullable): A callback to call when @data is not needed anymore |
905 | | * @replace: Whether to replace an existing data with the same key |
906 | | * |
907 | | * Attaches a user-data key/data pair to the specified font-functions structure. |
908 | | * |
909 | | * Return value: `true` if success, `false` otherwise |
910 | | * |
911 | | * Since: 0.9.2 |
912 | | **/ |
913 | | hb_bool_t |
914 | | hb_font_funcs_set_user_data (hb_font_funcs_t *ffuncs, |
915 | | hb_user_data_key_t *key, |
916 | | void * data, |
917 | | hb_destroy_func_t destroy /* May be NULL. */, |
918 | | hb_bool_t replace) |
919 | 0 | { |
920 | 0 | return hb_object_set_user_data (ffuncs, key, data, destroy, replace); |
921 | 0 | } |
922 | | |
923 | | /** |
924 | | * hb_font_funcs_get_user_data: (skip) |
925 | | * @ffuncs: The font-functions structure |
926 | | * @key: The user-data key to query |
927 | | * |
928 | | * Fetches the user data associated with the specified key, |
929 | | * attached to the specified font-functions structure. |
930 | | * |
931 | | * Return value: (transfer none): A pointer to the user data |
932 | | * |
933 | | * Since: 0.9.2 |
934 | | **/ |
935 | | void * |
936 | | hb_font_funcs_get_user_data (const hb_font_funcs_t *ffuncs, |
937 | | hb_user_data_key_t *key) |
938 | 0 | { |
939 | 0 | return hb_object_get_user_data (ffuncs, key); |
940 | 0 | } |
941 | | |
942 | | |
943 | | /** |
944 | | * hb_font_funcs_make_immutable: |
945 | | * @ffuncs: The font-functions structure |
946 | | * |
947 | | * Makes a font-functions structure immutable. |
948 | | * |
949 | | * Since: 0.9.2 |
950 | | **/ |
951 | | void |
952 | | hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs) |
953 | 29 | { |
954 | 29 | if (hb_object_is_immutable (ffuncs)) |
955 | 0 | return; |
956 | | |
957 | 29 | hb_object_make_immutable (ffuncs); |
958 | 29 | } |
959 | | |
960 | | /** |
961 | | * hb_font_funcs_is_immutable: |
962 | | * @ffuncs: The font-functions structure |
963 | | * |
964 | | * Tests whether a font-functions structure is immutable. |
965 | | * |
966 | | * Return value: `true` if @ffuncs is immutable, `false` otherwise |
967 | | * |
968 | | * Since: 0.9.2 |
969 | | **/ |
970 | | hb_bool_t |
971 | | hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs) |
972 | 0 | { |
973 | 0 | return hb_object_is_immutable (ffuncs); |
974 | 0 | } |
975 | | |
976 | | |
977 | | static bool |
978 | | _hb_font_funcs_set_preamble (hb_font_funcs_t *ffuncs, |
979 | | bool func_is_null, |
980 | | void **user_data, |
981 | | hb_destroy_func_t *destroy) |
982 | 377 | { |
983 | 377 | if (hb_object_is_immutable (ffuncs)) |
984 | 0 | { |
985 | 0 | if (*destroy) |
986 | 0 | (*destroy) (*user_data); |
987 | 0 | return false; |
988 | 0 | } |
989 | | |
990 | 377 | if (func_is_null) |
991 | 0 | { |
992 | 0 | if (*destroy) |
993 | 0 | (*destroy) (*user_data); |
994 | 0 | *destroy = nullptr; |
995 | 0 | *user_data = nullptr; |
996 | 0 | } |
997 | | |
998 | 377 | return true; |
999 | 377 | } |
1000 | | |
1001 | | static bool |
1002 | | _hb_font_funcs_set_middle (hb_font_funcs_t *ffuncs, |
1003 | | void *user_data, |
1004 | | hb_destroy_func_t destroy) |
1005 | 377 | { |
1006 | 377 | if (user_data && !ffuncs->user_data) |
1007 | 0 | { |
1008 | 0 | ffuncs->user_data = (decltype (ffuncs->user_data)) hb_calloc (1, sizeof (*ffuncs->user_data)); |
1009 | 0 | if (unlikely (!ffuncs->user_data)) |
1010 | 0 | goto fail; |
1011 | 0 | } |
1012 | 377 | if (destroy && !ffuncs->destroy) |
1013 | 0 | { |
1014 | 0 | ffuncs->destroy = (decltype (ffuncs->destroy)) hb_calloc (1, sizeof (*ffuncs->destroy)); |
1015 | 0 | if (unlikely (!ffuncs->destroy)) |
1016 | 0 | goto fail; |
1017 | 0 | } |
1018 | | |
1019 | 377 | return true; |
1020 | | |
1021 | 0 | fail: |
1022 | 0 | if (destroy) |
1023 | 0 | (destroy) (user_data); |
1024 | 0 | return false; |
1025 | 377 | } |
1026 | | |
1027 | | #define HB_FONT_FUNC_IMPLEMENT(get_,name) \ |
1028 | | \ |
1029 | | void \ |
1030 | | hb_font_funcs_set_##name##_func (hb_font_funcs_t *ffuncs, \ |
1031 | | hb_font_##get_##name##_func_t func, \ |
1032 | | void *user_data, \ |
1033 | 377 | hb_destroy_func_t destroy) \ |
1034 | 377 | { \ |
1035 | 377 | if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\ |
1036 | 377 | return; \ |
1037 | 377 | \ |
1038 | 377 | if (ffuncs->destroy && ffuncs->destroy->name) \ |
1039 | 377 | ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \ |
1040 | 377 | \ |
1041 | 377 | if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy)) \ |
1042 | 377 | return; \ |
1043 | 377 | \ |
1044 | 377 | if (func) \ |
1045 | 377 | ffuncs->get.f.name = func; \ |
1046 | 377 | else \ |
1047 | 377 | ffuncs->get.f.name = hb_font_##get_##name##_default; \ |
1048 | 377 | \ |
1049 | 377 | if (ffuncs->user_data) \ |
1050 | 377 | ffuncs->user_data->name = user_data; \ |
1051 | 377 | if (ffuncs->destroy) \ |
1052 | 377 | ffuncs->destroy->name = destroy; \ |
1053 | 377 | } hb_font_funcs_set_font_h_extents_func Line | Count | Source | 1033 | 29 | hb_destroy_func_t destroy) \ | 1034 | 29 | { \ | 1035 | 29 | if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\ | 1036 | 29 | return; \ | 1037 | 29 | \ | 1038 | 29 | if (ffuncs->destroy && ffuncs->destroy->name) \ | 1039 | 29 | ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \ | 1040 | 29 | \ | 1041 | 29 | if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy)) \ | 1042 | 29 | return; \ | 1043 | 29 | \ | 1044 | 29 | if (func) \ | 1045 | 29 | ffuncs->get.f.name = func; \ | 1046 | 29 | else \ | 1047 | 29 | ffuncs->get.f.name = hb_font_##get_##name##_default; \ | 1048 | 29 | \ | 1049 | 29 | if (ffuncs->user_data) \ | 1050 | 29 | ffuncs->user_data->name = user_data; \ | 1051 | 29 | if (ffuncs->destroy) \ | 1052 | 29 | ffuncs->destroy->name = destroy; \ | 1053 | 29 | } |
hb_font_funcs_set_font_v_extents_func Line | Count | Source | 1033 | 29 | hb_destroy_func_t destroy) \ | 1034 | 29 | { \ | 1035 | 29 | if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\ | 1036 | 29 | return; \ | 1037 | 29 | \ | 1038 | 29 | if (ffuncs->destroy && ffuncs->destroy->name) \ | 1039 | 29 | ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \ | 1040 | 29 | \ | 1041 | 29 | if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy)) \ | 1042 | 29 | return; \ | 1043 | 29 | \ | 1044 | 29 | if (func) \ | 1045 | 29 | ffuncs->get.f.name = func; \ | 1046 | 29 | else \ | 1047 | 29 | ffuncs->get.f.name = hb_font_##get_##name##_default; \ | 1048 | 29 | \ | 1049 | 29 | if (ffuncs->user_data) \ | 1050 | 29 | ffuncs->user_data->name = user_data; \ | 1051 | 29 | if (ffuncs->destroy) \ | 1052 | 29 | ffuncs->destroy->name = destroy; \ | 1053 | 29 | } |
hb_font_funcs_set_nominal_glyph_func Line | Count | Source | 1033 | 29 | hb_destroy_func_t destroy) \ | 1034 | 29 | { \ | 1035 | 29 | if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\ | 1036 | 29 | return; \ | 1037 | 29 | \ | 1038 | 29 | if (ffuncs->destroy && ffuncs->destroy->name) \ | 1039 | 29 | ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \ | 1040 | 29 | \ | 1041 | 29 | if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy)) \ | 1042 | 29 | return; \ | 1043 | 29 | \ | 1044 | 29 | if (func) \ | 1045 | 29 | ffuncs->get.f.name = func; \ | 1046 | 29 | else \ | 1047 | 29 | ffuncs->get.f.name = hb_font_##get_##name##_default; \ | 1048 | 29 | \ | 1049 | 29 | if (ffuncs->user_data) \ | 1050 | 29 | ffuncs->user_data->name = user_data; \ | 1051 | 29 | if (ffuncs->destroy) \ | 1052 | 29 | ffuncs->destroy->name = destroy; \ | 1053 | 29 | } |
hb_font_funcs_set_nominal_glyphs_func Line | Count | Source | 1033 | 29 | hb_destroy_func_t destroy) \ | 1034 | 29 | { \ | 1035 | 29 | if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\ | 1036 | 29 | return; \ | 1037 | 29 | \ | 1038 | 29 | if (ffuncs->destroy && ffuncs->destroy->name) \ | 1039 | 29 | ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \ | 1040 | 29 | \ | 1041 | 29 | if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy)) \ | 1042 | 29 | return; \ | 1043 | 29 | \ | 1044 | 29 | if (func) \ | 1045 | 29 | ffuncs->get.f.name = func; \ | 1046 | 29 | else \ | 1047 | 29 | ffuncs->get.f.name = hb_font_##get_##name##_default; \ | 1048 | 29 | \ | 1049 | 29 | if (ffuncs->user_data) \ | 1050 | 29 | ffuncs->user_data->name = user_data; \ | 1051 | 29 | if (ffuncs->destroy) \ | 1052 | 29 | ffuncs->destroy->name = destroy; \ | 1053 | 29 | } |
hb_font_funcs_set_variation_glyph_func Line | Count | Source | 1033 | 29 | hb_destroy_func_t destroy) \ | 1034 | 29 | { \ | 1035 | 29 | if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\ | 1036 | 29 | return; \ | 1037 | 29 | \ | 1038 | 29 | if (ffuncs->destroy && ffuncs->destroy->name) \ | 1039 | 29 | ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \ | 1040 | 29 | \ | 1041 | 29 | if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy)) \ | 1042 | 29 | return; \ | 1043 | 29 | \ | 1044 | 29 | if (func) \ | 1045 | 29 | ffuncs->get.f.name = func; \ | 1046 | 29 | else \ | 1047 | 29 | ffuncs->get.f.name = hb_font_##get_##name##_default; \ | 1048 | 29 | \ | 1049 | 29 | if (ffuncs->user_data) \ | 1050 | 29 | ffuncs->user_data->name = user_data; \ | 1051 | 29 | if (ffuncs->destroy) \ | 1052 | 29 | ffuncs->destroy->name = destroy; \ | 1053 | 29 | } |
Unexecuted instantiation: hb_font_funcs_set_glyph_h_advance_func Unexecuted instantiation: hb_font_funcs_set_glyph_v_advance_func hb_font_funcs_set_glyph_h_advances_func Line | Count | Source | 1033 | 29 | hb_destroy_func_t destroy) \ | 1034 | 29 | { \ | 1035 | 29 | if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\ | 1036 | 29 | return; \ | 1037 | 29 | \ | 1038 | 29 | if (ffuncs->destroy && ffuncs->destroy->name) \ | 1039 | 29 | ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \ | 1040 | 29 | \ | 1041 | 29 | if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy)) \ | 1042 | 29 | return; \ | 1043 | 29 | \ | 1044 | 29 | if (func) \ | 1045 | 29 | ffuncs->get.f.name = func; \ | 1046 | 29 | else \ | 1047 | 29 | ffuncs->get.f.name = hb_font_##get_##name##_default; \ | 1048 | 29 | \ | 1049 | 29 | if (ffuncs->user_data) \ | 1050 | 29 | ffuncs->user_data->name = user_data; \ | 1051 | 29 | if (ffuncs->destroy) \ | 1052 | 29 | ffuncs->destroy->name = destroy; \ | 1053 | 29 | } |
hb_font_funcs_set_glyph_v_advances_func Line | Count | Source | 1033 | 29 | hb_destroy_func_t destroy) \ | 1034 | 29 | { \ | 1035 | 29 | if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\ | 1036 | 29 | return; \ | 1037 | 29 | \ | 1038 | 29 | if (ffuncs->destroy && ffuncs->destroy->name) \ | 1039 | 29 | ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \ | 1040 | 29 | \ | 1041 | 29 | if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy)) \ | 1042 | 29 | return; \ | 1043 | 29 | \ | 1044 | 29 | if (func) \ | 1045 | 29 | ffuncs->get.f.name = func; \ | 1046 | 29 | else \ | 1047 | 29 | ffuncs->get.f.name = hb_font_##get_##name##_default; \ | 1048 | 29 | \ | 1049 | 29 | if (ffuncs->user_data) \ | 1050 | 29 | ffuncs->user_data->name = user_data; \ | 1051 | 29 | if (ffuncs->destroy) \ | 1052 | 29 | ffuncs->destroy->name = destroy; \ | 1053 | 29 | } |
Unexecuted instantiation: hb_font_funcs_set_glyph_h_origin_func Unexecuted instantiation: hb_font_funcs_set_glyph_v_origin_func Unexecuted instantiation: hb_font_funcs_set_glyph_h_origins_func hb_font_funcs_set_glyph_v_origins_func Line | Count | Source | 1033 | 29 | hb_destroy_func_t destroy) \ | 1034 | 29 | { \ | 1035 | 29 | if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\ | 1036 | 29 | return; \ | 1037 | 29 | \ | 1038 | 29 | if (ffuncs->destroy && ffuncs->destroy->name) \ | 1039 | 29 | ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \ | 1040 | 29 | \ | 1041 | 29 | if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy)) \ | 1042 | 29 | return; \ | 1043 | 29 | \ | 1044 | 29 | if (func) \ | 1045 | 29 | ffuncs->get.f.name = func; \ | 1046 | 29 | else \ | 1047 | 29 | ffuncs->get.f.name = hb_font_##get_##name##_default; \ | 1048 | 29 | \ | 1049 | 29 | if (ffuncs->user_data) \ | 1050 | 29 | ffuncs->user_data->name = user_data; \ | 1051 | 29 | if (ffuncs->destroy) \ | 1052 | 29 | ffuncs->destroy->name = destroy; \ | 1053 | 29 | } |
Unexecuted instantiation: hb_font_funcs_set_glyph_h_kerning_func hb_font_funcs_set_glyph_extents_func Line | Count | Source | 1033 | 29 | hb_destroy_func_t destroy) \ | 1034 | 29 | { \ | 1035 | 29 | if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\ | 1036 | 29 | return; \ | 1037 | 29 | \ | 1038 | 29 | if (ffuncs->destroy && ffuncs->destroy->name) \ | 1039 | 29 | ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \ | 1040 | 29 | \ | 1041 | 29 | if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy)) \ | 1042 | 29 | return; \ | 1043 | 29 | \ | 1044 | 29 | if (func) \ | 1045 | 29 | ffuncs->get.f.name = func; \ | 1046 | 29 | else \ | 1047 | 29 | ffuncs->get.f.name = hb_font_##get_##name##_default; \ | 1048 | 29 | \ | 1049 | 29 | if (ffuncs->user_data) \ | 1050 | 29 | ffuncs->user_data->name = user_data; \ | 1051 | 29 | if (ffuncs->destroy) \ | 1052 | 29 | ffuncs->destroy->name = destroy; \ | 1053 | 29 | } |
Unexecuted instantiation: hb_font_funcs_set_glyph_contour_point_func hb_font_funcs_set_glyph_name_func Line | Count | Source | 1033 | 29 | hb_destroy_func_t destroy) \ | 1034 | 29 | { \ | 1035 | 29 | if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\ | 1036 | 29 | return; \ | 1037 | 29 | \ | 1038 | 29 | if (ffuncs->destroy && ffuncs->destroy->name) \ | 1039 | 29 | ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \ | 1040 | 29 | \ | 1041 | 29 | if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy)) \ | 1042 | 29 | return; \ | 1043 | 29 | \ | 1044 | 29 | if (func) \ | 1045 | 29 | ffuncs->get.f.name = func; \ | 1046 | 29 | else \ | 1047 | 29 | ffuncs->get.f.name = hb_font_##get_##name##_default; \ | 1048 | 29 | \ | 1049 | 29 | if (ffuncs->user_data) \ | 1050 | 29 | ffuncs->user_data->name = user_data; \ | 1051 | 29 | if (ffuncs->destroy) \ | 1052 | 29 | ffuncs->destroy->name = destroy; \ | 1053 | 29 | } |
hb_font_funcs_set_glyph_from_name_func Line | Count | Source | 1033 | 29 | hb_destroy_func_t destroy) \ | 1034 | 29 | { \ | 1035 | 29 | if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\ | 1036 | 29 | return; \ | 1037 | 29 | \ | 1038 | 29 | if (ffuncs->destroy && ffuncs->destroy->name) \ | 1039 | 29 | ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \ | 1040 | 29 | \ | 1041 | 29 | if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy)) \ | 1042 | 29 | return; \ | 1043 | 29 | \ | 1044 | 29 | if (func) \ | 1045 | 29 | ffuncs->get.f.name = func; \ | 1046 | 29 | else \ | 1047 | 29 | ffuncs->get.f.name = hb_font_##get_##name##_default; \ | 1048 | 29 | \ | 1049 | 29 | if (ffuncs->user_data) \ | 1050 | 29 | ffuncs->user_data->name = user_data; \ | 1051 | 29 | if (ffuncs->destroy) \ | 1052 | 29 | ffuncs->destroy->name = destroy; \ | 1053 | 29 | } |
hb_font_funcs_set_draw_glyph_or_fail_func Line | Count | Source | 1033 | 29 | hb_destroy_func_t destroy) \ | 1034 | 29 | { \ | 1035 | 29 | if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\ | 1036 | 29 | return; \ | 1037 | 29 | \ | 1038 | 29 | if (ffuncs->destroy && ffuncs->destroy->name) \ | 1039 | 29 | ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \ | 1040 | 29 | \ | 1041 | 29 | if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy)) \ | 1042 | 29 | return; \ | 1043 | 29 | \ | 1044 | 29 | if (func) \ | 1045 | 29 | ffuncs->get.f.name = func; \ | 1046 | 29 | else \ | 1047 | 29 | ffuncs->get.f.name = hb_font_##get_##name##_default; \ | 1048 | 29 | \ | 1049 | 29 | if (ffuncs->user_data) \ | 1050 | 29 | ffuncs->user_data->name = user_data; \ | 1051 | 29 | if (ffuncs->destroy) \ | 1052 | 29 | ffuncs->destroy->name = destroy; \ | 1053 | 29 | } |
hb_font_funcs_set_paint_glyph_or_fail_func Line | Count | Source | 1033 | 29 | hb_destroy_func_t destroy) \ | 1034 | 29 | { \ | 1035 | 29 | if (!_hb_font_funcs_set_preamble (ffuncs, !func, &user_data, &destroy))\ | 1036 | 29 | return; \ | 1037 | 29 | \ | 1038 | 29 | if (ffuncs->destroy && ffuncs->destroy->name) \ | 1039 | 29 | ffuncs->destroy->name (!ffuncs->user_data ? nullptr : ffuncs->user_data->name); \ | 1040 | 29 | \ | 1041 | 29 | if (!_hb_font_funcs_set_middle (ffuncs, user_data, destroy)) \ | 1042 | 29 | return; \ | 1043 | 29 | \ | 1044 | 29 | if (func) \ | 1045 | 29 | ffuncs->get.f.name = func; \ | 1046 | 29 | else \ | 1047 | 29 | ffuncs->get.f.name = hb_font_##get_##name##_default; \ | 1048 | 29 | \ | 1049 | 29 | if (ffuncs->user_data) \ | 1050 | 29 | ffuncs->user_data->name = user_data; \ | 1051 | 29 | if (ffuncs->destroy) \ | 1052 | 29 | ffuncs->destroy->name = destroy; \ | 1053 | 29 | } |
|
1054 | | |
1055 | | HB_FONT_FUNCS_IMPLEMENT_CALLBACKS |
1056 | | #undef HB_FONT_FUNC_IMPLEMENT |
1057 | | |
1058 | | bool |
1059 | | hb_font_t::has_func_set (unsigned int i) |
1060 | 195M | { |
1061 | 195M | return this->klass->get.array[i] != _hb_font_funcs_default.get.array[i]; |
1062 | 195M | } |
1063 | | |
1064 | | bool |
1065 | | hb_font_t::has_func (unsigned int i) |
1066 | 185M | { |
1067 | 185M | return has_func_set (i) || |
1068 | 183M | (parent && parent != &_hb_Null_hb_font_t && parent->has_func (i)); |
1069 | 185M | } |
1070 | | |
1071 | | /* Public getters */ |
1072 | | |
1073 | | /** |
1074 | | * hb_font_get_h_extents: |
1075 | | * @font: #hb_font_t to work upon |
1076 | | * @extents: (out): The font extents retrieved |
1077 | | * |
1078 | | * Fetches the extents for a specified font, for horizontal |
1079 | | * text segments. |
1080 | | * |
1081 | | * Return value: `true` if data found, `false` otherwise |
1082 | | * |
1083 | | * Since: 1.1.3 |
1084 | | **/ |
1085 | | hb_bool_t |
1086 | | hb_font_get_h_extents (hb_font_t *font, |
1087 | | hb_font_extents_t *extents) |
1088 | 271k | { |
1089 | 271k | return font->get_font_h_extents (extents); |
1090 | 271k | } |
1091 | | |
1092 | | /** |
1093 | | * hb_font_get_v_extents: |
1094 | | * @font: #hb_font_t to work upon |
1095 | | * @extents: (out): The font extents retrieved |
1096 | | * |
1097 | | * Fetches the extents for a specified font, for vertical |
1098 | | * text segments. |
1099 | | * |
1100 | | * Return value: `true` if data found, `false` otherwise |
1101 | | * |
1102 | | * Since: 1.1.3 |
1103 | | **/ |
1104 | | hb_bool_t |
1105 | | hb_font_get_v_extents (hb_font_t *font, |
1106 | | hb_font_extents_t *extents) |
1107 | 0 | { |
1108 | 0 | return font->get_font_v_extents (extents); |
1109 | 0 | } |
1110 | | |
1111 | | /** |
1112 | | * hb_font_get_glyph: |
1113 | | * @font: #hb_font_t to work upon |
1114 | | * @unicode: The Unicode code point to query |
1115 | | * @variation_selector: A variation-selector code point |
1116 | | * @glyph: (out): The glyph ID retrieved |
1117 | | * |
1118 | | * Fetches the glyph ID for a Unicode code point in the specified |
1119 | | * font, with an optional variation selector. |
1120 | | * |
1121 | | * If @variation_selector is 0, calls hb_font_get_nominal_glyph(); |
1122 | | * otherwise calls hb_font_get_variation_glyph(). |
1123 | | * |
1124 | | * Return value: `true` if data found, `false` otherwise |
1125 | | * |
1126 | | * Since: 0.9.2 |
1127 | | **/ |
1128 | | hb_bool_t |
1129 | | hb_font_get_glyph (hb_font_t *font, |
1130 | | hb_codepoint_t unicode, |
1131 | | hb_codepoint_t variation_selector, |
1132 | | hb_codepoint_t *glyph) |
1133 | 584k | { |
1134 | 584k | if (unlikely (variation_selector)) |
1135 | 45 | return font->get_variation_glyph (unicode, variation_selector, glyph); |
1136 | 584k | return font->get_nominal_glyph (unicode, glyph); |
1137 | 584k | } |
1138 | | |
1139 | | /** |
1140 | | * hb_font_get_nominal_glyph: |
1141 | | * @font: #hb_font_t to work upon |
1142 | | * @unicode: The Unicode code point to query |
1143 | | * @glyph: (out): The glyph ID retrieved |
1144 | | * |
1145 | | * Fetches the nominal glyph ID for a Unicode code point in the |
1146 | | * specified font. |
1147 | | * |
1148 | | * This version of the function should not be used to fetch glyph IDs |
1149 | | * for code points modified by variation selectors. For variation-selector |
1150 | | * support, user hb_font_get_variation_glyph() or use hb_font_get_glyph(). |
1151 | | * |
1152 | | * Return value: `true` if data found, `false` otherwise |
1153 | | * |
1154 | | * Since: 1.2.3 |
1155 | | **/ |
1156 | | hb_bool_t |
1157 | | hb_font_get_nominal_glyph (hb_font_t *font, |
1158 | | hb_codepoint_t unicode, |
1159 | | hb_codepoint_t *glyph) |
1160 | 0 | { |
1161 | 0 | return font->get_nominal_glyph (unicode, glyph); |
1162 | 0 | } |
1163 | | |
1164 | | /** |
1165 | | * hb_font_get_nominal_glyphs: |
1166 | | * @font: #hb_font_t to work upon |
1167 | | * @count: number of code points to query |
1168 | | * @first_unicode: The first Unicode code point to query |
1169 | | * @unicode_stride: The stride between successive code points |
1170 | | * @first_glyph: (out): The first glyph ID retrieved |
1171 | | * @glyph_stride: The stride between successive glyph IDs |
1172 | | * |
1173 | | * Fetches the nominal glyph IDs for a sequence of Unicode code points. Glyph |
1174 | | * IDs must be returned in a #hb_codepoint_t output parameter. Stops at the |
1175 | | * first unsupported glyph ID. |
1176 | | * |
1177 | | * Return value: the number of code points processed |
1178 | | * |
1179 | | * Since: 2.6.3 |
1180 | | **/ |
1181 | | unsigned int |
1182 | | hb_font_get_nominal_glyphs (hb_font_t *font, |
1183 | | unsigned int count, |
1184 | | const hb_codepoint_t *first_unicode, |
1185 | | unsigned int unicode_stride, |
1186 | | hb_codepoint_t *first_glyph, |
1187 | | unsigned int glyph_stride) |
1188 | 0 | { |
1189 | 0 | return font->get_nominal_glyphs (count, |
1190 | 0 | first_unicode, unicode_stride, |
1191 | 0 | first_glyph, glyph_stride); |
1192 | 0 | } |
1193 | | |
1194 | | /** |
1195 | | * hb_font_get_variation_glyph: |
1196 | | * @font: #hb_font_t to work upon |
1197 | | * @unicode: The Unicode code point to query |
1198 | | * @variation_selector: The variation-selector code point to query |
1199 | | * @glyph: (out): The glyph ID retrieved |
1200 | | * |
1201 | | * Fetches the glyph ID for a Unicode code point when followed by |
1202 | | * by the specified variation-selector code point, in the specified |
1203 | | * font. |
1204 | | * |
1205 | | * Return value: `true` if data found, `false` otherwise |
1206 | | * |
1207 | | * Since: 1.2.3 |
1208 | | **/ |
1209 | | hb_bool_t |
1210 | | hb_font_get_variation_glyph (hb_font_t *font, |
1211 | | hb_codepoint_t unicode, |
1212 | | hb_codepoint_t variation_selector, |
1213 | | hb_codepoint_t *glyph) |
1214 | 0 | { |
1215 | 0 | return font->get_variation_glyph (unicode, variation_selector, glyph); |
1216 | 0 | } |
1217 | | |
1218 | | /** |
1219 | | * hb_font_get_glyph_h_advance: |
1220 | | * @font: #hb_font_t to work upon |
1221 | | * @glyph: The glyph ID to query |
1222 | | * |
1223 | | * Fetches the advance for a glyph ID in the specified font, |
1224 | | * for horizontal text segments. |
1225 | | * |
1226 | | * Return value: The advance of @glyph within @font |
1227 | | * |
1228 | | * Since: 0.9.2 |
1229 | | **/ |
1230 | | hb_position_t |
1231 | | hb_font_get_glyph_h_advance (hb_font_t *font, |
1232 | | hb_codepoint_t glyph) |
1233 | 9.77M | { |
1234 | 9.77M | return font->get_glyph_h_advance (glyph); |
1235 | 9.77M | } |
1236 | | |
1237 | | /** |
1238 | | * hb_font_get_glyph_v_advance: |
1239 | | * @font: #hb_font_t to work upon |
1240 | | * @glyph: The glyph ID to query |
1241 | | * |
1242 | | * Fetches the advance for a glyph ID in the specified font, |
1243 | | * for vertical text segments. |
1244 | | * |
1245 | | * Return value: The advance of @glyph within @font |
1246 | | * |
1247 | | * Since: 0.9.2 |
1248 | | **/ |
1249 | | hb_position_t |
1250 | | hb_font_get_glyph_v_advance (hb_font_t *font, |
1251 | | hb_codepoint_t glyph) |
1252 | 0 | { |
1253 | 0 | return font->get_glyph_v_advance (glyph); |
1254 | 0 | } |
1255 | | |
1256 | | /** |
1257 | | * hb_font_get_glyph_h_advances: |
1258 | | * @font: #hb_font_t to work upon |
1259 | | * @count: The number of glyph IDs in the sequence queried |
1260 | | * @first_glyph: The first glyph ID to query |
1261 | | * @glyph_stride: The stride between successive glyph IDs |
1262 | | * @first_advance: (out): The first advance retrieved |
1263 | | * @advance_stride: The stride between successive advances |
1264 | | * |
1265 | | * Fetches the advances for a sequence of glyph IDs in the specified |
1266 | | * font, for horizontal text segments. |
1267 | | * |
1268 | | * Since: 1.8.6 |
1269 | | **/ |
1270 | | void |
1271 | | hb_font_get_glyph_h_advances (hb_font_t* font, |
1272 | | unsigned int count, |
1273 | | const hb_codepoint_t *first_glyph, |
1274 | | unsigned glyph_stride, |
1275 | | hb_position_t *first_advance, |
1276 | | unsigned advance_stride) |
1277 | 0 | { |
1278 | 0 | font->get_glyph_h_advances (count, first_glyph, glyph_stride, first_advance, advance_stride); |
1279 | 0 | } |
1280 | | /** |
1281 | | * hb_font_get_glyph_v_advances: |
1282 | | * @font: #hb_font_t to work upon |
1283 | | * @count: The number of glyph IDs in the sequence queried |
1284 | | * @first_glyph: The first glyph ID to query |
1285 | | * @glyph_stride: The stride between successive glyph IDs |
1286 | | * @first_advance: (out): The first advance retrieved |
1287 | | * @advance_stride: (out): The stride between successive advances |
1288 | | * |
1289 | | * Fetches the advances for a sequence of glyph IDs in the specified |
1290 | | * font, for vertical text segments. |
1291 | | * |
1292 | | * Since: 1.8.6 |
1293 | | **/ |
1294 | | void |
1295 | | hb_font_get_glyph_v_advances (hb_font_t* font, |
1296 | | unsigned int count, |
1297 | | const hb_codepoint_t *first_glyph, |
1298 | | unsigned glyph_stride, |
1299 | | hb_position_t *first_advance, |
1300 | | unsigned advance_stride) |
1301 | 0 | { |
1302 | 0 | font->get_glyph_v_advances (count, first_glyph, glyph_stride, first_advance, advance_stride); |
1303 | 0 | } |
1304 | | |
1305 | | /** |
1306 | | * hb_font_get_glyph_h_origin: |
1307 | | * @font: #hb_font_t to work upon |
1308 | | * @glyph: The glyph ID to query |
1309 | | * @x: (out): The X coordinate of the origin |
1310 | | * @y: (out): The Y coordinate of the origin |
1311 | | * |
1312 | | * Fetches the (X,Y) coordinates of the origin for a glyph ID |
1313 | | * in the specified font, for horizontal text segments. |
1314 | | * |
1315 | | * Return value: `true` if data found, `false` otherwise |
1316 | | * |
1317 | | * Since: 0.9.2 |
1318 | | **/ |
1319 | | hb_bool_t |
1320 | | hb_font_get_glyph_h_origin (hb_font_t *font, |
1321 | | hb_codepoint_t glyph, |
1322 | | hb_position_t *x, |
1323 | | hb_position_t *y) |
1324 | 0 | { |
1325 | 0 | return font->get_glyph_h_origin (glyph, x, y); |
1326 | 0 | } |
1327 | | |
1328 | | /** |
1329 | | * hb_font_get_glyph_v_origin: |
1330 | | * @font: #hb_font_t to work upon |
1331 | | * @glyph: The glyph ID to query |
1332 | | * @x: (out): The X coordinate of the origin |
1333 | | * @y: (out): The Y coordinate of the origin |
1334 | | * |
1335 | | * Fetches the (X,Y) coordinates of the origin for a glyph ID |
1336 | | * in the specified font, for vertical text segments. |
1337 | | * |
1338 | | * Return value: `true` if data found, `false` otherwise |
1339 | | * |
1340 | | * Since: 0.9.2 |
1341 | | **/ |
1342 | | hb_bool_t |
1343 | | hb_font_get_glyph_v_origin (hb_font_t *font, |
1344 | | hb_codepoint_t glyph, |
1345 | | hb_position_t *x, |
1346 | | hb_position_t *y) |
1347 | 0 | { |
1348 | 0 | return font->get_glyph_v_origin (glyph, x, y); |
1349 | 0 | } |
1350 | | |
1351 | | /** |
1352 | | * hb_font_get_glyph_h_origins: |
1353 | | * @font: #hb_font_t to work upon |
1354 | | * @count: The number of glyph IDs in the sequence queried |
1355 | | * @first_glyph: The first glyph ID to query |
1356 | | * @glyph_stride: The stride between successive glyph IDs |
1357 | | * @first_x: (out): The first X coordinate of the origin retrieved |
1358 | | * @x_stride: The stride between successive X coordinates |
1359 | | * @first_y: (out): The first Y coordinate of the origin retrieved |
1360 | | * @y_stride: The stride between successive Y coordinates |
1361 | | * |
1362 | | * Fetches the (X,Y) coordinates of the origin for requested glyph IDs |
1363 | | * in the specified font, for horizontal text segments. |
1364 | | * |
1365 | | * Return value: `true` if data found, `false` otherwise |
1366 | | * |
1367 | | * Since: 11.3.0 |
1368 | | **/ |
1369 | | hb_bool_t |
1370 | | hb_font_get_glyph_h_origins (hb_font_t *font, |
1371 | | unsigned int count, |
1372 | | const hb_codepoint_t *first_glyph, |
1373 | | unsigned int glyph_stride, |
1374 | | hb_position_t *first_x, |
1375 | | unsigned int x_stride, |
1376 | | hb_position_t *first_y, |
1377 | | unsigned int y_stride) |
1378 | | |
1379 | 0 | { |
1380 | 0 | return font->get_glyph_h_origins (count, |
1381 | 0 | first_glyph, glyph_stride, |
1382 | 0 | first_x, x_stride, |
1383 | 0 | first_y, y_stride); |
1384 | 0 | } |
1385 | | |
1386 | | /** |
1387 | | * hb_font_get_glyph_v_origins: |
1388 | | * @font: #hb_font_t to work upon |
1389 | | * @count: The number of glyph IDs in the sequence queried |
1390 | | * @first_glyph: The first glyph ID to query |
1391 | | * @glyph_stride: The stride between successive glyph IDs |
1392 | | * @first_x: (out): The first X coordinate of the origin retrieved |
1393 | | * @x_stride: The stride between successive X coordinates |
1394 | | * @first_y: (out): The first Y coordinate of the origin retrieved |
1395 | | * @y_stride: The stride between successive Y coordinates |
1396 | | * |
1397 | | * Fetches the (X,Y) coordinates of the origin for requested glyph IDs |
1398 | | * in the specified font, for vertical text segments. |
1399 | | * |
1400 | | * Return value: `true` if data found, `false` otherwise |
1401 | | * |
1402 | | * Since: 11.3.0 |
1403 | | **/ |
1404 | | hb_bool_t |
1405 | | hb_font_get_glyph_v_origins (hb_font_t *font, |
1406 | | unsigned int count, |
1407 | | const hb_codepoint_t *first_glyph, |
1408 | | unsigned int glyph_stride, |
1409 | | hb_position_t *first_x, |
1410 | | unsigned int x_stride, |
1411 | | hb_position_t *first_y, |
1412 | | unsigned int y_stride) |
1413 | | |
1414 | 0 | { |
1415 | 0 | return font->get_glyph_v_origins (count, |
1416 | 0 | first_glyph, glyph_stride, |
1417 | 0 | first_x, x_stride, |
1418 | 0 | first_y, y_stride); |
1419 | 0 | } |
1420 | | |
1421 | | |
1422 | | /** |
1423 | | * hb_font_get_glyph_h_kerning: |
1424 | | * @font: #hb_font_t to work upon |
1425 | | * @left_glyph: The glyph ID of the left glyph in the glyph pair |
1426 | | * @right_glyph: The glyph ID of the right glyph in the glyph pair |
1427 | | * |
1428 | | * Fetches the kerning-adjustment value for a glyph-pair in |
1429 | | * the specified font, for horizontal text segments. |
1430 | | * |
1431 | | * <note>It handles legacy kerning only (as returned by the corresponding |
1432 | | * #hb_font_funcs_t function).</note> |
1433 | | * |
1434 | | * Return value: The kerning adjustment value |
1435 | | * |
1436 | | * Since: 0.9.2 |
1437 | | **/ |
1438 | | hb_position_t |
1439 | | hb_font_get_glyph_h_kerning (hb_font_t *font, |
1440 | | hb_codepoint_t left_glyph, |
1441 | | hb_codepoint_t right_glyph) |
1442 | 0 | { |
1443 | 0 | return font->get_glyph_h_kerning (left_glyph, right_glyph); |
1444 | 0 | } |
1445 | | |
1446 | | #ifndef HB_DISABLE_DEPRECATED |
1447 | | /** |
1448 | | * hb_font_get_glyph_v_kerning: |
1449 | | * @font: #hb_font_t to work upon |
1450 | | * @top_glyph: The glyph ID of the top glyph in the glyph pair |
1451 | | * @bottom_glyph: The glyph ID of the bottom glyph in the glyph pair |
1452 | | * |
1453 | | * Fetches the kerning-adjustment value for a glyph-pair in |
1454 | | * the specified font, for vertical text segments. |
1455 | | * |
1456 | | * <note>It handles legacy kerning only (as returned by the corresponding |
1457 | | * #hb_font_funcs_t function).</note> |
1458 | | * |
1459 | | * Return value: The kerning adjustment value |
1460 | | * |
1461 | | * Since: 0.9.2 |
1462 | | * Deprecated: 2.0.0 |
1463 | | **/ |
1464 | | hb_position_t |
1465 | | hb_font_get_glyph_v_kerning (hb_font_t *font, |
1466 | | hb_codepoint_t top_glyph, |
1467 | | hb_codepoint_t bottom_glyph) |
1468 | 0 | { |
1469 | 0 | return font->get_glyph_v_kerning (top_glyph, bottom_glyph); |
1470 | 0 | } |
1471 | | #endif |
1472 | | |
1473 | | /** |
1474 | | * hb_font_get_glyph_extents: |
1475 | | * @font: #hb_font_t to work upon |
1476 | | * @glyph: The glyph ID to query |
1477 | | * @extents: (out): The #hb_glyph_extents_t retrieved |
1478 | | * |
1479 | | * Fetches the #hb_glyph_extents_t data for a glyph ID |
1480 | | * in the specified font. |
1481 | | * |
1482 | | * Return value: `true` if data found, `false` otherwise |
1483 | | * |
1484 | | * Since: 0.9.2 |
1485 | | **/ |
1486 | | hb_bool_t |
1487 | | hb_font_get_glyph_extents (hb_font_t *font, |
1488 | | hb_codepoint_t glyph, |
1489 | | hb_glyph_extents_t *extents) |
1490 | 733k | { |
1491 | 733k | return font->get_glyph_extents (glyph, extents); |
1492 | 733k | } |
1493 | | |
1494 | | /** |
1495 | | * hb_font_get_glyph_contour_point: |
1496 | | * @font: #hb_font_t to work upon |
1497 | | * @glyph: The glyph ID to query |
1498 | | * @point_index: The contour-point index to query |
1499 | | * @x: (out): The X value retrieved for the contour point |
1500 | | * @y: (out): The Y value retrieved for the contour point |
1501 | | * |
1502 | | * Fetches the (x,y) coordinates of a specified contour-point index |
1503 | | * in the specified glyph, within the specified font. |
1504 | | * |
1505 | | * Return value: `true` if data found, `false` otherwise |
1506 | | * |
1507 | | * Since: 0.9.2 |
1508 | | **/ |
1509 | | hb_bool_t |
1510 | | hb_font_get_glyph_contour_point (hb_font_t *font, |
1511 | | hb_codepoint_t glyph, |
1512 | | unsigned int point_index, |
1513 | | hb_position_t *x, |
1514 | | hb_position_t *y) |
1515 | 0 | { |
1516 | 0 | return font->get_glyph_contour_point (glyph, point_index, x, y); |
1517 | 0 | } |
1518 | | |
1519 | | /** |
1520 | | * hb_font_get_glyph_name: |
1521 | | * @font: #hb_font_t to work upon |
1522 | | * @glyph: The glyph ID to query |
1523 | | * @name: (out) (array length=size): Name string retrieved for the glyph ID |
1524 | | * @size: Length of the glyph-name string retrieved |
1525 | | * |
1526 | | * Fetches the glyph-name string for a glyph ID in the specified @font. |
1527 | | * |
1528 | | * According to the OpenType specification, glyph names are limited to 63 |
1529 | | * characters and can only contain (a subset of) ASCII. |
1530 | | * |
1531 | | * Return value: `true` if data found, `false` otherwise |
1532 | | * |
1533 | | * Since: 0.9.2 |
1534 | | **/ |
1535 | | hb_bool_t |
1536 | | hb_font_get_glyph_name (hb_font_t *font, |
1537 | | hb_codepoint_t glyph, |
1538 | | char *name, |
1539 | | unsigned int size) |
1540 | 0 | { |
1541 | 0 | return font->get_glyph_name (glyph, name, size); |
1542 | 0 | } |
1543 | | |
1544 | | /** |
1545 | | * hb_font_get_glyph_from_name: |
1546 | | * @font: #hb_font_t to work upon |
1547 | | * @name: (array length=len): The name string to query |
1548 | | * @len: The length of the name queried |
1549 | | * @glyph: (out): The glyph ID retrieved |
1550 | | * |
1551 | | * Fetches the glyph ID that corresponds to a name string in the specified @font. |
1552 | | * |
1553 | | * <note>Note: @len == -1 means the name string is null-terminated.</note> |
1554 | | * |
1555 | | * Return value: `true` if data found, `false` otherwise |
1556 | | * |
1557 | | * Since: 0.9.2 |
1558 | | **/ |
1559 | | hb_bool_t |
1560 | | hb_font_get_glyph_from_name (hb_font_t *font, |
1561 | | const char *name, |
1562 | | int len, /* -1 means nul-terminated */ |
1563 | | hb_codepoint_t *glyph) |
1564 | 0 | { |
1565 | 0 | return font->get_glyph_from_name (name, len, glyph); |
1566 | 0 | } |
1567 | | |
1568 | | #ifndef HB_DISABLE_DEPRECATED |
1569 | | /** |
1570 | | * hb_font_get_glyph_shape: |
1571 | | * @font: #hb_font_t to work upon |
1572 | | * @glyph: The glyph ID |
1573 | | * @dfuncs: #hb_draw_funcs_t to draw to |
1574 | | * @draw_data: User data to pass to draw callbacks |
1575 | | * |
1576 | | * Fetches the glyph shape that corresponds to a glyph in the specified @font. |
1577 | | * The shape is returned by way of calls to the callbacks of the @dfuncs |
1578 | | * objects, with @draw_data passed to them. |
1579 | | * |
1580 | | * Since: 4.0.0 |
1581 | | * Deprecated: 7.0.0: Use hb_font_draw_glyph() instead |
1582 | | */ |
1583 | | void |
1584 | | hb_font_get_glyph_shape (hb_font_t *font, |
1585 | | hb_codepoint_t glyph, |
1586 | | hb_draw_funcs_t *dfuncs, void *draw_data) |
1587 | 0 | { |
1588 | 0 | hb_font_draw_glyph (font, glyph, dfuncs, draw_data); |
1589 | 0 | } |
1590 | | #endif |
1591 | | |
1592 | | /** |
1593 | | * hb_font_draw_glyph_or_fail: |
1594 | | * @font: #hb_font_t to work upon |
1595 | | * @glyph: The glyph ID |
1596 | | * @dfuncs: #hb_draw_funcs_t to draw to |
1597 | | * @draw_data: User data to pass to draw callbacks |
1598 | | * |
1599 | | * Draws the outline that corresponds to a glyph in the specified @font. |
1600 | | * |
1601 | | * This is a newer name for hb_font_draw_glyph(), that returns `false` |
1602 | | * if the font has no outlines for the glyph. |
1603 | | * |
1604 | | * The outline is returned by way of calls to the callbacks of the @dfuncs |
1605 | | * objects, with @draw_data passed to them. |
1606 | | * |
1607 | | * Return value: `true` if glyph was drawn, `false` otherwise |
1608 | | * |
1609 | | * Since: 11.2.0 |
1610 | | **/ |
1611 | | hb_bool_t |
1612 | | hb_font_draw_glyph_or_fail (hb_font_t *font, |
1613 | | hb_codepoint_t glyph, |
1614 | | hb_draw_funcs_t *dfuncs, void *draw_data) |
1615 | 0 | { |
1616 | 0 | return font->draw_glyph_or_fail (glyph, dfuncs, draw_data); |
1617 | 0 | } |
1618 | | |
1619 | | /** |
1620 | | * hb_font_paint_glyph_or_fail: |
1621 | | * @font: #hb_font_t to work upon |
1622 | | * @glyph: The glyph ID |
1623 | | * @pfuncs: #hb_paint_funcs_t to paint with |
1624 | | * @paint_data: User data to pass to paint callbacks |
1625 | | * @palette_index: The index of the font's color palette to use |
1626 | | * @foreground: The foreground color, unpremultipled |
1627 | | * |
1628 | | * Paints a color glyph. |
1629 | | * |
1630 | | * This function is similar to, but lower-level than, |
1631 | | * hb_font_paint_glyph(). It is suitable for clients that |
1632 | | * need more control. If there are no color glyphs available, |
1633 | | * it will return `false`. The client can then fall back to |
1634 | | * hb_font_draw_glyph_or_fail() for the monochrome outline glyph. |
1635 | | * |
1636 | | * The painting instructions are returned by way of calls to |
1637 | | * the callbacks of the @funcs object, with @paint_data passed |
1638 | | * to them. |
1639 | | * |
1640 | | * If the font has color palettes (see hb_ot_color_has_palettes()), |
1641 | | * then @palette_index selects the palette to use. If the font only |
1642 | | * has one palette, this will be 0. |
1643 | | * |
1644 | | * Return value: `true` if glyph was painted, `false` otherwise |
1645 | | * |
1646 | | * Since: 11.2.0 |
1647 | | */ |
1648 | | hb_bool_t |
1649 | | hb_font_paint_glyph_or_fail (hb_font_t *font, |
1650 | | hb_codepoint_t glyph, |
1651 | | hb_paint_funcs_t *pfuncs, void *paint_data, |
1652 | | unsigned int palette_index, |
1653 | | hb_color_t foreground) |
1654 | 0 | { |
1655 | 0 | return font->paint_glyph_or_fail (glyph, pfuncs, paint_data, palette_index, foreground); |
1656 | 0 | } |
1657 | | |
1658 | | /* A bit higher-level, and with fallback */ |
1659 | | |
1660 | | void |
1661 | | hb_font_t::paint_glyph (hb_codepoint_t glyph, |
1662 | | hb_paint_funcs_t *paint_funcs, void *paint_data, |
1663 | | unsigned int palette, |
1664 | | hb_color_t foreground) |
1665 | 0 | { |
1666 | 0 | if (paint_glyph_or_fail (glyph, |
1667 | 0 | paint_funcs, paint_data, |
1668 | 0 | palette, foreground)) |
1669 | 0 | return; |
1670 | | |
1671 | | /* Fallback for outline glyph. */ |
1672 | 0 | paint_funcs->push_clip_glyph (paint_data, glyph, this); |
1673 | 0 | paint_funcs->color (paint_data, true, foreground); |
1674 | 0 | paint_funcs->pop_clip (paint_data); |
1675 | 0 | } |
1676 | | |
1677 | | |
1678 | | /** |
1679 | | * hb_font_draw_glyph: |
1680 | | * @font: #hb_font_t to work upon |
1681 | | * @glyph: The glyph ID |
1682 | | * @dfuncs: #hb_draw_funcs_t to draw to |
1683 | | * @draw_data: User data to pass to draw callbacks |
1684 | | * |
1685 | | * Draws the outline that corresponds to a glyph in the specified @font. |
1686 | | * |
1687 | | * This is an older name for hb_font_draw_glyph_or_fail(), with no |
1688 | | * return value. |
1689 | | * |
1690 | | * The outline is returned by way of calls to the callbacks of the @dfuncs |
1691 | | * objects, with @draw_data passed to them. |
1692 | | * |
1693 | | * Since: 7.0.0 |
1694 | | **/ |
1695 | | void |
1696 | | hb_font_draw_glyph (hb_font_t *font, |
1697 | | hb_codepoint_t glyph, |
1698 | | hb_draw_funcs_t *dfuncs, void *draw_data) |
1699 | 0 | { |
1700 | 0 | (void) hb_font_draw_glyph_or_fail (font, glyph, dfuncs, draw_data); |
1701 | 0 | } |
1702 | | |
1703 | | /** |
1704 | | * hb_font_paint_glyph: |
1705 | | * @font: #hb_font_t to work upon |
1706 | | * @glyph: The glyph ID |
1707 | | * @pfuncs: #hb_paint_funcs_t to paint with |
1708 | | * @paint_data: User data to pass to paint callbacks |
1709 | | * @palette_index: The index of the font's color palette to use |
1710 | | * @foreground: The foreground color, unpremultipled |
1711 | | * |
1712 | | * Paints the glyph. This function is similar to |
1713 | | * hb_font_paint_glyph_or_fail(), but if painting a color glyph |
1714 | | * failed, it will fall back to painting an outline monochrome |
1715 | | * glyph. |
1716 | | * |
1717 | | * The painting instructions are returned by way of calls to |
1718 | | * the callbacks of the @funcs object, with @paint_data passed |
1719 | | * to them. |
1720 | | * |
1721 | | * If the font has color palettes (see hb_ot_color_has_palettes()), |
1722 | | * then @palette_index selects the palette to use. If the font only |
1723 | | * has one palette, this will be 0. |
1724 | | * |
1725 | | * Since: 7.0.0 |
1726 | | */ |
1727 | | void |
1728 | | hb_font_paint_glyph (hb_font_t *font, |
1729 | | hb_codepoint_t glyph, |
1730 | | hb_paint_funcs_t *pfuncs, void *paint_data, |
1731 | | unsigned int palette_index, |
1732 | | hb_color_t foreground) |
1733 | 0 | { |
1734 | 0 | font->paint_glyph (glyph, pfuncs, paint_data, palette_index, foreground); |
1735 | 0 | } |
1736 | | |
1737 | | /** |
1738 | | * hb_font_get_extents_for_direction: |
1739 | | * @font: #hb_font_t to work upon |
1740 | | * @direction: The direction of the text segment |
1741 | | * @extents: (out): The #hb_font_extents_t retrieved |
1742 | | * |
1743 | | * Fetches the extents for a font in a text segment of the |
1744 | | * specified direction. |
1745 | | * |
1746 | | * Calls the appropriate direction-specific variant (horizontal |
1747 | | * or vertical) depending on the value of @direction. |
1748 | | * |
1749 | | * Since: 1.1.3 |
1750 | | **/ |
1751 | | void |
1752 | | hb_font_get_extents_for_direction (hb_font_t *font, |
1753 | | hb_direction_t direction, |
1754 | | hb_font_extents_t *extents) |
1755 | 0 | { |
1756 | 0 | font->get_extents_for_direction (direction, extents); |
1757 | 0 | } |
1758 | | /** |
1759 | | * hb_font_get_glyph_advance_for_direction: |
1760 | | * @font: #hb_font_t to work upon |
1761 | | * @glyph: The glyph ID to query |
1762 | | * @direction: The direction of the text segment |
1763 | | * @x: (out): The horizontal advance retrieved |
1764 | | * @y: (out): The vertical advance retrieved |
1765 | | * |
1766 | | * Fetches the advance for a glyph ID from the specified font, |
1767 | | * in a text segment of the specified direction. |
1768 | | * |
1769 | | * Calls the appropriate direction-specific variant (horizontal |
1770 | | * or vertical) depending on the value of @direction. |
1771 | | * |
1772 | | * Since: 0.9.2 |
1773 | | **/ |
1774 | | void |
1775 | | hb_font_get_glyph_advance_for_direction (hb_font_t *font, |
1776 | | hb_codepoint_t glyph, |
1777 | | hb_direction_t direction, |
1778 | | hb_position_t *x, |
1779 | | hb_position_t *y) |
1780 | 0 | { |
1781 | 0 | font->get_glyph_advance_for_direction (glyph, direction, x, y); |
1782 | 0 | } |
1783 | | /** |
1784 | | * hb_font_get_glyph_advances_for_direction: |
1785 | | * @font: #hb_font_t to work upon |
1786 | | * @direction: The direction of the text segment |
1787 | | * @count: The number of glyph IDs in the sequence queried |
1788 | | * @first_glyph: The first glyph ID to query |
1789 | | * @glyph_stride: The stride between successive glyph IDs |
1790 | | * @first_advance: (out): The first advance retrieved |
1791 | | * @advance_stride: (out): The stride between successive advances |
1792 | | * |
1793 | | * Fetches the advances for a sequence of glyph IDs in the specified |
1794 | | * font, in a text segment of the specified direction. |
1795 | | * |
1796 | | * Calls the appropriate direction-specific variant (horizontal |
1797 | | * or vertical) depending on the value of @direction. |
1798 | | * |
1799 | | * Since: 1.8.6 |
1800 | | **/ |
1801 | | HB_EXTERN void |
1802 | | hb_font_get_glyph_advances_for_direction (hb_font_t* font, |
1803 | | hb_direction_t direction, |
1804 | | unsigned int count, |
1805 | | const hb_codepoint_t *first_glyph, |
1806 | | unsigned glyph_stride, |
1807 | | hb_position_t *first_advance, |
1808 | | unsigned advance_stride) |
1809 | 0 | { |
1810 | 0 | font->get_glyph_advances_for_direction (direction, count, first_glyph, glyph_stride, first_advance, advance_stride); |
1811 | 0 | } |
1812 | | |
1813 | | /** |
1814 | | * hb_font_get_glyph_origin_for_direction: |
1815 | | * @font: #hb_font_t to work upon |
1816 | | * @glyph: The glyph ID to query |
1817 | | * @direction: The direction of the text segment |
1818 | | * @x: (out): The X coordinate retrieved for the origin |
1819 | | * @y: (out): The Y coordinate retrieved for the origin |
1820 | | * |
1821 | | * Fetches the (X,Y) coordinates of the origin for a glyph in |
1822 | | * the specified font. |
1823 | | * |
1824 | | * Calls the appropriate direction-specific variant (horizontal |
1825 | | * or vertical) depending on the value of @direction. |
1826 | | * |
1827 | | * Since: 0.9.2 |
1828 | | **/ |
1829 | | void |
1830 | | hb_font_get_glyph_origin_for_direction (hb_font_t *font, |
1831 | | hb_codepoint_t glyph, |
1832 | | hb_direction_t direction, |
1833 | | hb_position_t *x, |
1834 | | hb_position_t *y) |
1835 | 0 | { |
1836 | 0 | return font->get_glyph_origin_for_direction (glyph, direction, x, y); |
1837 | 0 | } |
1838 | | |
1839 | | /** |
1840 | | * hb_font_add_glyph_origin_for_direction: |
1841 | | * @font: #hb_font_t to work upon |
1842 | | * @glyph: The glyph ID to query |
1843 | | * @direction: The direction of the text segment |
1844 | | * @x: (inout): Input = The original X coordinate |
1845 | | * Output = The X coordinate plus the X-coordinate of the origin |
1846 | | * @y: (inout): Input = The original Y coordinate |
1847 | | * Output = The Y coordinate plus the Y-coordinate of the origin |
1848 | | * |
1849 | | * Adds the origin coordinates to an (X,Y) point coordinate, in |
1850 | | * the specified glyph ID in the specified font. |
1851 | | * |
1852 | | * Calls the appropriate direction-specific variant (horizontal |
1853 | | * or vertical) depending on the value of @direction. |
1854 | | * |
1855 | | * Since: 0.9.2 |
1856 | | **/ |
1857 | | void |
1858 | | hb_font_add_glyph_origin_for_direction (hb_font_t *font, |
1859 | | hb_codepoint_t glyph, |
1860 | | hb_direction_t direction, |
1861 | | hb_position_t *x, |
1862 | | hb_position_t *y) |
1863 | 0 | { |
1864 | 0 | return font->add_glyph_origin_for_direction (glyph, direction, x, y); |
1865 | 0 | } |
1866 | | |
1867 | | /** |
1868 | | * hb_font_subtract_glyph_origin_for_direction: |
1869 | | * @font: #hb_font_t to work upon |
1870 | | * @glyph: The glyph ID to query |
1871 | | * @direction: The direction of the text segment |
1872 | | * @x: (inout): Input = The original X coordinate |
1873 | | * Output = The X coordinate minus the X-coordinate of the origin |
1874 | | * @y: (inout): Input = The original Y coordinate |
1875 | | * Output = The Y coordinate minus the Y-coordinate of the origin |
1876 | | * |
1877 | | * Subtracts the origin coordinates from an (X,Y) point coordinate, |
1878 | | * in the specified glyph ID in the specified font. |
1879 | | * |
1880 | | * Calls the appropriate direction-specific variant (horizontal |
1881 | | * or vertical) depending on the value of @direction. |
1882 | | * |
1883 | | * Since: 0.9.2 |
1884 | | **/ |
1885 | | void |
1886 | | hb_font_subtract_glyph_origin_for_direction (hb_font_t *font, |
1887 | | hb_codepoint_t glyph, |
1888 | | hb_direction_t direction, |
1889 | | hb_position_t *x, |
1890 | | hb_position_t *y) |
1891 | 0 | { |
1892 | 0 | return font->subtract_glyph_origin_for_direction (glyph, direction, x, y); |
1893 | 0 | } |
1894 | | |
1895 | | /** |
1896 | | * hb_font_get_glyph_kerning_for_direction: |
1897 | | * @font: #hb_font_t to work upon |
1898 | | * @first_glyph: The glyph ID of the first glyph in the glyph pair to query |
1899 | | * @second_glyph: The glyph ID of the second glyph in the glyph pair to query |
1900 | | * @direction: The direction of the text segment |
1901 | | * @x: (out): The horizontal kerning-adjustment value retrieved |
1902 | | * @y: (out): The vertical kerning-adjustment value retrieved |
1903 | | * |
1904 | | * Fetches the kerning-adjustment value for a glyph-pair in the specified font. |
1905 | | * |
1906 | | * Calls the appropriate direction-specific variant (horizontal |
1907 | | * or vertical) depending on the value of @direction. |
1908 | | * |
1909 | | * Since: 0.9.2 |
1910 | | **/ |
1911 | | void |
1912 | | hb_font_get_glyph_kerning_for_direction (hb_font_t *font, |
1913 | | hb_codepoint_t first_glyph, |
1914 | | hb_codepoint_t second_glyph, |
1915 | | hb_direction_t direction, |
1916 | | hb_position_t *x, |
1917 | | hb_position_t *y) |
1918 | 0 | { |
1919 | 0 | return font->get_glyph_kerning_for_direction (first_glyph, second_glyph, direction, x, y); |
1920 | 0 | } |
1921 | | |
1922 | | /** |
1923 | | * hb_font_get_glyph_extents_for_origin: |
1924 | | * @font: #hb_font_t to work upon |
1925 | | * @glyph: The glyph ID to query |
1926 | | * @direction: The direction of the text segment |
1927 | | * @extents: (out): The #hb_glyph_extents_t retrieved |
1928 | | * |
1929 | | * Fetches the #hb_glyph_extents_t data for a glyph ID |
1930 | | * in the specified font, with respect to the origin in |
1931 | | * a text segment in the specified direction. |
1932 | | * |
1933 | | * Calls the appropriate direction-specific variant (horizontal |
1934 | | * or vertical) depending on the value of @direction. |
1935 | | * |
1936 | | * Return value: `true` if data found, `false` otherwise |
1937 | | * |
1938 | | * Since: 0.9.2 |
1939 | | **/ |
1940 | | hb_bool_t |
1941 | | hb_font_get_glyph_extents_for_origin (hb_font_t *font, |
1942 | | hb_codepoint_t glyph, |
1943 | | hb_direction_t direction, |
1944 | | hb_glyph_extents_t *extents) |
1945 | 0 | { |
1946 | 0 | return font->get_glyph_extents_for_origin (glyph, direction, extents); |
1947 | 0 | } |
1948 | | |
1949 | | /** |
1950 | | * hb_font_get_glyph_contour_point_for_origin: |
1951 | | * @font: #hb_font_t to work upon |
1952 | | * @glyph: The glyph ID to query |
1953 | | * @point_index: The contour-point index to query |
1954 | | * @direction: The direction of the text segment |
1955 | | * @x: (out): The X value retrieved for the contour point |
1956 | | * @y: (out): The Y value retrieved for the contour point |
1957 | | * |
1958 | | * Fetches the (X,Y) coordinates of a specified contour-point index |
1959 | | * in the specified glyph ID in the specified font, with respect |
1960 | | * to the origin in a text segment in the specified direction. |
1961 | | * |
1962 | | * Calls the appropriate direction-specific variant (horizontal |
1963 | | * or vertical) depending on the value of @direction. |
1964 | | * |
1965 | | * Return value: `true` if data found, `false` otherwise |
1966 | | * |
1967 | | * Since: 0.9.2 |
1968 | | **/ |
1969 | | hb_bool_t |
1970 | | hb_font_get_glyph_contour_point_for_origin (hb_font_t *font, |
1971 | | hb_codepoint_t glyph, |
1972 | | unsigned int point_index, |
1973 | | hb_direction_t direction, |
1974 | | hb_position_t *x, |
1975 | | hb_position_t *y) |
1976 | 0 | { |
1977 | 0 | return font->get_glyph_contour_point_for_origin (glyph, point_index, direction, x, y); |
1978 | 0 | } |
1979 | | |
1980 | | /** |
1981 | | * hb_font_glyph_to_string: |
1982 | | * @font: #hb_font_t to work upon |
1983 | | * @glyph: The glyph ID to query |
1984 | | * @s: (out) (array length=size): The string containing the glyph name |
1985 | | * @size: Length of string @s |
1986 | | * |
1987 | | * Fetches the name of the specified glyph ID in @font and returns |
1988 | | * it in string @s. |
1989 | | * |
1990 | | * If the glyph ID has no name in @font, a string of the form `gidDDD` is |
1991 | | * generated, with `DDD` being the glyph ID. |
1992 | | * |
1993 | | * According to the OpenType specification, glyph names are limited to 63 |
1994 | | * characters and can only contain (a subset of) ASCII. |
1995 | | * |
1996 | | * Since: 0.9.2 |
1997 | | **/ |
1998 | | void |
1999 | | hb_font_glyph_to_string (hb_font_t *font, |
2000 | | hb_codepoint_t glyph, |
2001 | | char *s, |
2002 | | unsigned int size) |
2003 | 0 | { |
2004 | 0 | font->glyph_to_string (glyph, s, size); |
2005 | 0 | } |
2006 | | |
2007 | | /** |
2008 | | * hb_font_glyph_from_string: |
2009 | | * @font: #hb_font_t to work upon |
2010 | | * @s: (array length=len) (element-type uint8_t): string to query |
2011 | | * @len: The length of the string @s |
2012 | | * @glyph: (out): The glyph ID corresponding to the string requested |
2013 | | * |
2014 | | * Fetches the glyph ID from @font that matches the specified string. |
2015 | | * Strings of the format `gidDDD` or `uniUUUU` are parsed automatically. |
2016 | | * |
2017 | | * <note>Note: @len == -1 means the string is null-terminated.</note> |
2018 | | * |
2019 | | * Return value: `true` if data found, `false` otherwise |
2020 | | * |
2021 | | * Since: 0.9.2 |
2022 | | **/ |
2023 | | hb_bool_t |
2024 | | hb_font_glyph_from_string (hb_font_t *font, |
2025 | | const char *s, |
2026 | | int len, |
2027 | | hb_codepoint_t *glyph) |
2028 | 0 | { |
2029 | 0 | return font->glyph_from_string (s, len, glyph); |
2030 | 0 | } |
2031 | | |
2032 | | |
2033 | | /* |
2034 | | * hb_font_t |
2035 | | */ |
2036 | | |
2037 | | DEFINE_NULL_INSTANCE (hb_font_t) = |
2038 | | { |
2039 | | HB_OBJECT_HEADER_STATIC, |
2040 | | |
2041 | | 0, /* serial */ |
2042 | | 0, /* serial_coords */ |
2043 | | |
2044 | | nullptr, /* parent */ |
2045 | | const_cast<hb_face_t *> (&_hb_Null_hb_face_t), |
2046 | | |
2047 | | 1000, /* x_scale */ |
2048 | | 1000, /* y_scale */ |
2049 | | false, /* is_synthetic */ |
2050 | | 0.f, /* x_embolden */ |
2051 | | 0.f, /* y_embolden */ |
2052 | | true, /* embolden_in_place */ |
2053 | | 0, /* x_strength */ |
2054 | | 0, /* y_strength */ |
2055 | | 0.f, /* slant */ |
2056 | | 0.f, /* slant_xy; */ |
2057 | | 1.f, /* x_multf */ |
2058 | | 1.f, /* y_multf */ |
2059 | | 1<<16, /* x_mult */ |
2060 | | 1<<16, /* y_mult */ |
2061 | | |
2062 | | 0, /* x_ppem */ |
2063 | | 0, /* y_ppem */ |
2064 | | 0, /* ptem */ |
2065 | | |
2066 | | HB_FONT_NO_VAR_NAMED_INSTANCE, /* instance_index */ |
2067 | | false, /* has_nonzero_coords */ |
2068 | | 0, /* num_coords */ |
2069 | | nullptr, /* coords */ |
2070 | | nullptr, /* design_coords */ |
2071 | | |
2072 | | const_cast<hb_font_funcs_t *> (&_hb_Null_hb_font_funcs_t), |
2073 | | |
2074 | | /* Zero for the rest is fine. */ |
2075 | | }; |
2076 | | |
2077 | | |
2078 | | static hb_font_t * |
2079 | | _hb_font_create (hb_face_t *face) |
2080 | 214k | { |
2081 | 214k | hb_font_t *font; |
2082 | | |
2083 | 214k | if (unlikely (!face)) |
2084 | 0 | face = hb_face_get_empty (); |
2085 | | |
2086 | 214k | if (!(font = hb_object_create<hb_font_t> ())) |
2087 | 0 | return hb_font_get_empty (); |
2088 | | |
2089 | 214k | hb_face_make_immutable (face); |
2090 | 214k | font->parent = hb_font_get_empty (); |
2091 | 214k | font->face = hb_face_reference (face); |
2092 | 214k | font->klass = hb_font_funcs_get_empty (); |
2093 | 214k | font->data.init0 (font); |
2094 | 214k | font->x_scale = font->y_scale = face->get_upem (); |
2095 | 214k | font->embolden_in_place = true; |
2096 | 214k | font->x_multf = font->y_multf = 1.f; |
2097 | 214k | font->x_mult = font->y_mult = 1 << 16; |
2098 | 214k | font->instance_index = HB_FONT_NO_VAR_NAMED_INSTANCE; |
2099 | | |
2100 | 214k | return font; |
2101 | 214k | } |
2102 | | |
2103 | | /** |
2104 | | * hb_font_create: |
2105 | | * @face: a face. |
2106 | | * |
2107 | | * Constructs a new font object from the specified face. |
2108 | | * |
2109 | | * <note>Note: If @face's index value (as passed to hb_face_create() |
2110 | | * has non-zero top 16-bits, those bits minus one are passed to |
2111 | | * hb_font_set_var_named_instance(), effectively loading a named-instance |
2112 | | * of a variable font, instead of the default-instance. This allows |
2113 | | * specifying which named-instance to load by default when creating the |
2114 | | * face.</note> |
2115 | | * |
2116 | | * Return value: (transfer full): The new font object |
2117 | | * |
2118 | | * Since: 0.9.2 |
2119 | | **/ |
2120 | | hb_font_t * |
2121 | | hb_font_create (hb_face_t *face) |
2122 | 214k | { |
2123 | 214k | hb_font_t *font = _hb_font_create (face); |
2124 | | |
2125 | 214k | hb_font_set_funcs_using (font, nullptr); |
2126 | | |
2127 | 214k | #ifndef HB_NO_VAR |
2128 | | // Initialize variations. |
2129 | 214k | if (likely (face)) |
2130 | 214k | { |
2131 | 214k | if (face->index >> 16) |
2132 | 0 | hb_font_set_var_named_instance (font, (face->index >> 16) - 1); |
2133 | 214k | else |
2134 | 214k | hb_font_set_variations (font, nullptr, 0); |
2135 | 214k | } |
2136 | 214k | #endif |
2137 | | |
2138 | 214k | return font; |
2139 | 214k | } |
2140 | | |
2141 | | static void |
2142 | | _hb_font_adopt_var_coords (hb_font_t *font, |
2143 | | int *coords, /* 2.14 normalized */ |
2144 | | float *design_coords, |
2145 | | unsigned int coords_length) |
2146 | 231k | { |
2147 | 231k | hb_free (font->coords); |
2148 | 231k | hb_free (font->design_coords); |
2149 | | |
2150 | 231k | font->coords = coords; |
2151 | 231k | font->design_coords = design_coords; |
2152 | 231k | font->num_coords = coords_length; |
2153 | 231k | font->has_nonzero_coords = hb_any (hb_array (coords, coords_length)); |
2154 | | |
2155 | 231k | font->changed (); |
2156 | 231k | font->serial_coords = font->serial; |
2157 | 231k | } |
2158 | | |
2159 | | /** |
2160 | | * hb_font_create_sub_font: |
2161 | | * @parent: The parent font object |
2162 | | * |
2163 | | * Constructs a sub-font font object from the specified @parent font, |
2164 | | * replicating the parent's properties. |
2165 | | * |
2166 | | * Return value: (transfer full): The new sub-font font object |
2167 | | * |
2168 | | * Since: 0.9.2 |
2169 | | **/ |
2170 | | hb_font_t * |
2171 | | hb_font_create_sub_font (hb_font_t *parent) |
2172 | 0 | { |
2173 | 0 | if (unlikely (!parent)) |
2174 | 0 | parent = hb_font_get_empty (); |
2175 | |
|
2176 | 0 | hb_font_t *font = _hb_font_create (parent->face); |
2177 | |
|
2178 | 0 | if (unlikely (hb_object_is_immutable (font))) |
2179 | 0 | return font; |
2180 | | |
2181 | 0 | font->parent = hb_font_reference (parent); |
2182 | |
|
2183 | 0 | font->x_scale = parent->x_scale; |
2184 | 0 | font->y_scale = parent->y_scale; |
2185 | 0 | font->x_embolden = parent->x_embolden; |
2186 | 0 | font->y_embolden = parent->y_embolden; |
2187 | 0 | font->embolden_in_place = parent->embolden_in_place; |
2188 | 0 | font->slant = parent->slant; |
2189 | 0 | font->x_ppem = parent->x_ppem; |
2190 | 0 | font->y_ppem = parent->y_ppem; |
2191 | 0 | font->ptem = parent->ptem; |
2192 | |
|
2193 | 0 | unsigned int num_coords = parent->num_coords; |
2194 | 0 | if (num_coords) |
2195 | 0 | { |
2196 | 0 | int *coords = (int *) hb_calloc (num_coords, sizeof (parent->coords[0])); |
2197 | 0 | float *design_coords = (float *) hb_calloc (num_coords, sizeof (parent->design_coords[0])); |
2198 | 0 | if (likely (coords && design_coords)) |
2199 | 0 | { |
2200 | 0 | hb_memcpy (coords, parent->coords, num_coords * sizeof (parent->coords[0])); |
2201 | 0 | hb_memcpy (design_coords, parent->design_coords, num_coords * sizeof (parent->design_coords[0])); |
2202 | 0 | _hb_font_adopt_var_coords (font, coords, design_coords, num_coords); |
2203 | 0 | } |
2204 | 0 | else |
2205 | 0 | { |
2206 | 0 | hb_free (coords); |
2207 | 0 | hb_free (design_coords); |
2208 | 0 | } |
2209 | 0 | } |
2210 | |
|
2211 | 0 | font->changed (); |
2212 | 0 | font->serial_coords = font->serial; |
2213 | |
|
2214 | 0 | return font; |
2215 | 0 | } |
2216 | | |
2217 | | /** |
2218 | | * hb_font_get_empty: |
2219 | | * |
2220 | | * Fetches the empty font object. |
2221 | | * |
2222 | | * Return value: (transfer full): The empty font object |
2223 | | * |
2224 | | * Since: 0.9.2 |
2225 | | **/ |
2226 | | hb_font_t * |
2227 | | hb_font_get_empty () |
2228 | 214k | { |
2229 | 214k | return const_cast<hb_font_t *> (&Null (hb_font_t)); |
2230 | 214k | } |
2231 | | |
2232 | | /** |
2233 | | * hb_font_reference: (skip) |
2234 | | * @font: #hb_font_t to work upon |
2235 | | * |
2236 | | * Increases the reference count on the given font object. |
2237 | | * |
2238 | | * Return value: (transfer full): The @font object |
2239 | | * |
2240 | | * Since: 0.9.2 |
2241 | | **/ |
2242 | | hb_font_t * |
2243 | | hb_font_reference (hb_font_t *font) |
2244 | 0 | { |
2245 | 0 | return hb_object_reference (font); |
2246 | 0 | } |
2247 | | |
2248 | | /** |
2249 | | * hb_font_destroy: (skip) |
2250 | | * @font: #hb_font_t to work upon |
2251 | | * |
2252 | | * Decreases the reference count on the given font object. When the |
2253 | | * reference count reaches zero, the font is destroyed, |
2254 | | * freeing all memory. |
2255 | | * |
2256 | | * Since: 0.9.2 |
2257 | | **/ |
2258 | | void |
2259 | | hb_font_destroy (hb_font_t *font) |
2260 | 427k | { |
2261 | 427k | if (!hb_object_destroy (font)) return; |
2262 | | |
2263 | 213k | font->data.fini (); |
2264 | | |
2265 | 213k | if (font->destroy) |
2266 | 213k | font->destroy (font->user_data); |
2267 | | |
2268 | 213k | hb_font_destroy (font->parent); |
2269 | 213k | hb_face_destroy (font->face); |
2270 | 213k | hb_font_funcs_destroy (font->klass); |
2271 | | |
2272 | 213k | hb_free (font->coords); |
2273 | 213k | hb_free (font->design_coords); |
2274 | | |
2275 | 213k | hb_free (font); |
2276 | 213k | } |
2277 | | |
2278 | | /** |
2279 | | * hb_font_set_user_data: (skip) |
2280 | | * @font: #hb_font_t to work upon |
2281 | | * @key: The user-data key |
2282 | | * @data: A pointer to the user data |
2283 | | * @destroy: (nullable): A callback to call when @data is not needed anymore |
2284 | | * @replace: Whether to replace an existing data with the same key |
2285 | | * |
2286 | | * Attaches a user-data key/data pair to the specified font object. |
2287 | | * |
2288 | | * Return value: `true` if success, `false` otherwise |
2289 | | * |
2290 | | * Since: 0.9.2 |
2291 | | **/ |
2292 | | hb_bool_t |
2293 | | hb_font_set_user_data (hb_font_t *font, |
2294 | | hb_user_data_key_t *key, |
2295 | | void * data, |
2296 | | hb_destroy_func_t destroy /* May be NULL. */, |
2297 | | hb_bool_t replace) |
2298 | 0 | { |
2299 | 0 | if (!hb_object_is_immutable (font)) |
2300 | 0 | font->changed (); |
2301 | |
|
2302 | 0 | return hb_object_set_user_data (font, key, data, destroy, replace); |
2303 | 0 | } |
2304 | | |
2305 | | /** |
2306 | | * hb_font_get_user_data: (skip) |
2307 | | * @font: #hb_font_t to work upon |
2308 | | * @key: The user-data key to query |
2309 | | * |
2310 | | * Fetches the user-data object associated with the specified key, |
2311 | | * attached to the specified font object. |
2312 | | * |
2313 | | * Return value: (transfer none): Pointer to the user data |
2314 | | * |
2315 | | * Since: 0.9.2 |
2316 | | **/ |
2317 | | void * |
2318 | | hb_font_get_user_data (const hb_font_t *font, |
2319 | | hb_user_data_key_t *key) |
2320 | 0 | { |
2321 | 0 | return hb_object_get_user_data (font, key); |
2322 | 0 | } |
2323 | | |
2324 | | /** |
2325 | | * hb_font_make_immutable: |
2326 | | * @font: #hb_font_t to work upon |
2327 | | * |
2328 | | * Makes @font immutable. |
2329 | | * |
2330 | | * Since: 0.9.2 |
2331 | | **/ |
2332 | | void |
2333 | | hb_font_make_immutable (hb_font_t *font) |
2334 | 0 | { |
2335 | 0 | if (hb_object_is_immutable (font)) |
2336 | 0 | return; |
2337 | | |
2338 | 0 | if (font->parent) |
2339 | 0 | hb_font_make_immutable (font->parent); |
2340 | |
|
2341 | 0 | hb_object_make_immutable (font); |
2342 | 0 | } |
2343 | | |
2344 | | /** |
2345 | | * hb_font_is_immutable: |
2346 | | * @font: #hb_font_t to work upon |
2347 | | * |
2348 | | * Tests whether a font object is immutable. |
2349 | | * |
2350 | | * Return value: `true` if @font is immutable, `false` otherwise |
2351 | | * |
2352 | | * Since: 0.9.2 |
2353 | | **/ |
2354 | | hb_bool_t |
2355 | | hb_font_is_immutable (hb_font_t *font) |
2356 | 0 | { |
2357 | 0 | return hb_object_is_immutable (font); |
2358 | 0 | } |
2359 | | |
2360 | | /** |
2361 | | * hb_font_get_serial: |
2362 | | * @font: #hb_font_t to work upon |
2363 | | * |
2364 | | * Returns the internal serial number of the font. The serial |
2365 | | * number is increased every time a setting on the font is |
2366 | | * changed, using a setter function. |
2367 | | * |
2368 | | * Return value: serial number |
2369 | | * |
2370 | | * Since: 4.4.0 |
2371 | | **/ |
2372 | | unsigned int |
2373 | | hb_font_get_serial (hb_font_t *font) |
2374 | 0 | { |
2375 | 0 | return font->serial.get_acquire (); |
2376 | 0 | } |
2377 | | |
2378 | | /** |
2379 | | * hb_font_changed: |
2380 | | * @font: #hb_font_t to work upon |
2381 | | * |
2382 | | * Notifies the @font that underlying font data has changed. |
2383 | | * This has the effect of increasing the serial as returned |
2384 | | * by hb_font_get_serial(), which invalidates internal caches. |
2385 | | * |
2386 | | * Since: 4.4.0 |
2387 | | **/ |
2388 | | void |
2389 | | hb_font_changed (hb_font_t *font) |
2390 | 0 | { |
2391 | 0 | if (hb_object_is_immutable (font)) |
2392 | 0 | return; |
2393 | | |
2394 | 0 | font->changed (); |
2395 | 0 | } |
2396 | | |
2397 | | /** |
2398 | | * hb_font_set_parent: |
2399 | | * @font: #hb_font_t to work upon |
2400 | | * @parent: The parent font object to assign |
2401 | | * |
2402 | | * Sets the parent font of @font. |
2403 | | * |
2404 | | * Since: 1.0.5 |
2405 | | **/ |
2406 | | void |
2407 | | hb_font_set_parent (hb_font_t *font, |
2408 | | hb_font_t *parent) |
2409 | 0 | { |
2410 | 0 | if (hb_object_is_immutable (font)) |
2411 | 0 | return; |
2412 | | |
2413 | 0 | if (parent == font->parent) |
2414 | 0 | return; |
2415 | | |
2416 | 0 | if (!parent) |
2417 | 0 | parent = hb_font_get_empty (); |
2418 | |
|
2419 | 0 | for (hb_font_t *p = parent; p && p != hb_font_get_empty(); p = p->parent) |
2420 | 0 | if (p == font) |
2421 | 0 | return; /* Would create a cycle - reject */ |
2422 | | |
2423 | 0 | hb_font_t *old = font->parent; |
2424 | |
|
2425 | 0 | font->parent = hb_font_reference (parent); |
2426 | |
|
2427 | 0 | hb_font_destroy (old); |
2428 | |
|
2429 | 0 | font->changed (); |
2430 | 0 | } |
2431 | | |
2432 | | /** |
2433 | | * hb_font_get_parent: |
2434 | | * @font: #hb_font_t to work upon |
2435 | | * |
2436 | | * Fetches the parent font of @font. |
2437 | | * |
2438 | | * Return value: (transfer none): The parent font object |
2439 | | * |
2440 | | * Since: 0.9.2 |
2441 | | **/ |
2442 | | hb_font_t * |
2443 | | hb_font_get_parent (hb_font_t *font) |
2444 | 0 | { |
2445 | 0 | return font->parent; |
2446 | 0 | } |
2447 | | |
2448 | | /** |
2449 | | * hb_font_set_face: |
2450 | | * @font: #hb_font_t to work upon |
2451 | | * @face: The #hb_face_t to assign |
2452 | | * |
2453 | | * Sets @face as the font-face value of @font. |
2454 | | * |
2455 | | * Since: 1.4.3 |
2456 | | **/ |
2457 | | void |
2458 | | hb_font_set_face (hb_font_t *font, |
2459 | | hb_face_t *face) |
2460 | 0 | { |
2461 | 0 | if (hb_object_is_immutable (font)) |
2462 | 0 | return; |
2463 | | |
2464 | 0 | if (face == font->face) |
2465 | 0 | return; |
2466 | | |
2467 | 0 | if (unlikely (!face)) |
2468 | 0 | face = hb_face_get_empty (); |
2469 | |
|
2470 | 0 | hb_face_t *old = font->face; |
2471 | |
|
2472 | 0 | hb_face_make_immutable (face); |
2473 | 0 | font->face = hb_face_reference (face); |
2474 | 0 | font->changed (); |
2475 | |
|
2476 | 0 | hb_face_destroy (old); |
2477 | |
|
2478 | 0 | font->changed (); |
2479 | 0 | font->serial_coords = font->serial; |
2480 | 0 | } |
2481 | | |
2482 | | /** |
2483 | | * hb_font_get_face: |
2484 | | * @font: #hb_font_t to work upon |
2485 | | * |
2486 | | * Fetches the face associated with the specified font object. |
2487 | | * |
2488 | | * Return value: (transfer none): The #hb_face_t value |
2489 | | * |
2490 | | * Since: 0.9.2 |
2491 | | **/ |
2492 | | hb_face_t * |
2493 | | hb_font_get_face (hb_font_t *font) |
2494 | 14.8M | { |
2495 | 14.8M | return font->face; |
2496 | 14.8M | } |
2497 | | |
2498 | | |
2499 | | /** |
2500 | | * hb_font_set_funcs: |
2501 | | * @font: #hb_font_t to work upon |
2502 | | * @klass: (closure font_data) (destroy destroy) (scope notified): The font-functions structure. |
2503 | | * @font_data: Data to attach to @font |
2504 | | * @destroy: (nullable): The function to call when @font_data is not needed anymore |
2505 | | * |
2506 | | * Replaces the font-functions structure attached to a font, updating |
2507 | | * the font's user-data with @font-data and the @destroy callback. |
2508 | | * |
2509 | | * Since: 0.9.2 |
2510 | | **/ |
2511 | | void |
2512 | | hb_font_set_funcs (hb_font_t *font, |
2513 | | hb_font_funcs_t *klass, |
2514 | | void *font_data, |
2515 | | hb_destroy_func_t destroy /* May be NULL. */) |
2516 | 422k | { |
2517 | 422k | if (hb_object_is_immutable (font)) |
2518 | 0 | { |
2519 | 0 | if (destroy) |
2520 | 0 | destroy (font_data); |
2521 | 0 | return; |
2522 | 0 | } |
2523 | | |
2524 | 422k | if (font->destroy) |
2525 | 208k | font->destroy (font->user_data); |
2526 | | |
2527 | 422k | if (!klass) |
2528 | 0 | klass = hb_font_funcs_get_empty (); |
2529 | | |
2530 | 422k | hb_font_funcs_reference (klass); |
2531 | 422k | hb_font_funcs_destroy (font->klass); |
2532 | 422k | font->klass = klass; |
2533 | 422k | font->user_data = font_data; |
2534 | 422k | font->destroy = destroy; |
2535 | | |
2536 | 422k | font->changed (); |
2537 | 422k | } |
2538 | | |
2539 | | /** |
2540 | | * hb_font_set_funcs_data: |
2541 | | * @font: #hb_font_t to work upon |
2542 | | * @font_data: (destroy destroy) (scope notified): Data to attach to @font |
2543 | | * @destroy: (nullable): The function to call when @font_data is not needed anymore |
2544 | | * |
2545 | | * Replaces the user data attached to a font, updating the font's |
2546 | | * @destroy callback. |
2547 | | * |
2548 | | * Since: 0.9.2 |
2549 | | **/ |
2550 | | void |
2551 | | hb_font_set_funcs_data (hb_font_t *font, |
2552 | | void *font_data, |
2553 | | hb_destroy_func_t destroy /* May be NULL. */) |
2554 | 0 | { |
2555 | | /* Destroy user_data? */ |
2556 | 0 | if (hb_object_is_immutable (font)) |
2557 | 0 | { |
2558 | 0 | if (destroy) |
2559 | 0 | destroy (font_data); |
2560 | 0 | return; |
2561 | 0 | } |
2562 | | |
2563 | 0 | if (font->destroy) |
2564 | 0 | font->destroy (font->user_data); |
2565 | |
|
2566 | 0 | font->user_data = font_data; |
2567 | 0 | font->destroy = destroy; |
2568 | |
|
2569 | 0 | font->changed (); |
2570 | 0 | } |
2571 | | |
2572 | | static const struct supported_font_funcs_t { |
2573 | | char name[16]; |
2574 | | void (*func) (hb_font_t *); |
2575 | | } supported_font_funcs[] = |
2576 | | { |
2577 | | #ifndef HB_NO_OT_FONT |
2578 | | {"ot", hb_ot_font_set_funcs}, |
2579 | | #endif |
2580 | | #ifdef HAVE_FREETYPE |
2581 | | {"ft", hb_ft_font_set_funcs}, |
2582 | | #endif |
2583 | | #ifdef HAVE_FONTATIONS |
2584 | | {"fontations",hb_fontations_font_set_funcs}, |
2585 | | #endif |
2586 | | #ifdef HAVE_CORETEXT |
2587 | | {"coretext", hb_coretext_font_set_funcs}, |
2588 | | #endif |
2589 | | #ifdef HAVE_DIRECTWRITE |
2590 | | {"directwrite",hb_directwrite_font_set_funcs}, |
2591 | | #endif |
2592 | | }; |
2593 | | |
2594 | | static const char *get_default_funcs_name () |
2595 | 214k | { |
2596 | 214k | static hb_atomic_t<const char *> static_funcs_name; |
2597 | 214k | const char *name = static_funcs_name.get_acquire (); |
2598 | 214k | if (!name) |
2599 | 29 | { |
2600 | 29 | name = getenv ("HB_FONT_FUNCS"); |
2601 | 29 | if (!name) |
2602 | 29 | name = ""; |
2603 | 29 | if (!static_funcs_name.cmpexch (nullptr, name)) |
2604 | 0 | name = static_funcs_name.get_acquire (); |
2605 | 29 | } |
2606 | 214k | return name; |
2607 | 214k | } |
2608 | | |
2609 | | /** |
2610 | | * hb_font_set_funcs_using: |
2611 | | * @font: #hb_font_t to work upon |
2612 | | * @name: The name of the font-functions structure to use, or `NULL` |
2613 | | * |
2614 | | * Sets the font-functions structure to use for a font, based on the |
2615 | | * specified name. |
2616 | | * |
2617 | | * If @name is `NULL` or the empty string, the default (first) functioning font-functions |
2618 | | * are used. This default can be changed by setting the `HB_FONT_FUNCS` environment |
2619 | | * variable to the name of the desired font-functions. |
2620 | | * |
2621 | | * Return value: `true` if the font-functions was found and set, `false` otherwise |
2622 | | * |
2623 | | * Since: 11.0.0 |
2624 | | **/ |
2625 | | hb_bool_t |
2626 | | hb_font_set_funcs_using (hb_font_t *font, |
2627 | | const char *name) |
2628 | 214k | { |
2629 | 214k | if (unlikely (hb_object_is_immutable (font))) |
2630 | 0 | return false; |
2631 | | |
2632 | 214k | bool retry = false; |
2633 | | |
2634 | 214k | if (!name || !*name) |
2635 | 214k | { |
2636 | 214k | name = get_default_funcs_name (); |
2637 | 214k | retry = true; |
2638 | 214k | } |
2639 | 214k | if (name && !*name) name = nullptr; |
2640 | | |
2641 | 214k | retry: |
2642 | 214k | for (unsigned i = 0; i < ARRAY_LENGTH (supported_font_funcs); i++) |
2643 | 214k | if (!name || strcmp (supported_font_funcs[i].name, name) == 0) |
2644 | 214k | { |
2645 | 214k | supported_font_funcs[i].func (font); |
2646 | 214k | if (name || font->klass != hb_font_funcs_get_empty ()) |
2647 | 214k | return true; |
2648 | 214k | } |
2649 | | |
2650 | 0 | if (retry) |
2651 | 0 | { |
2652 | 0 | retry = false; |
2653 | 0 | name = nullptr; |
2654 | 0 | goto retry; |
2655 | 0 | } |
2656 | | |
2657 | 0 | return false; |
2658 | 0 | } |
2659 | | |
2660 | | static inline void free_static_font_funcs_list (); |
2661 | | |
2662 | | static const char * const nil_font_funcs_list[] = {nullptr}; |
2663 | | |
2664 | | static struct hb_font_funcs_list_lazy_loader_t : hb_lazy_loader_t<const char *, |
2665 | | hb_font_funcs_list_lazy_loader_t> |
2666 | | { |
2667 | | static const char ** create () |
2668 | 0 | { |
2669 | 0 | const char **font_funcs_list = (const char **) hb_calloc (1 + ARRAY_LENGTH (supported_font_funcs), sizeof (const char *)); |
2670 | 0 | if (unlikely (!font_funcs_list)) |
2671 | 0 | return nullptr; |
2672 | | |
2673 | 0 | unsigned i; |
2674 | 0 | for (i = 0; i < ARRAY_LENGTH (supported_font_funcs); i++) |
2675 | 0 | font_funcs_list[i] = supported_font_funcs[i].name; |
2676 | 0 | font_funcs_list[i] = nullptr; |
2677 | |
|
2678 | 0 | hb_atexit (free_static_font_funcs_list); |
2679 | |
|
2680 | 0 | return font_funcs_list; |
2681 | 0 | } |
2682 | | static void destroy (const char **l) |
2683 | 0 | { hb_free (l); } |
2684 | | static const char * const * get_null () |
2685 | 0 | { return nil_font_funcs_list; } |
2686 | | } static_font_funcs_list; |
2687 | | |
2688 | | static inline |
2689 | | void free_static_font_funcs_list () |
2690 | 0 | { |
2691 | 0 | static_font_funcs_list.free_instance (); |
2692 | 0 | } |
2693 | | |
2694 | | /** |
2695 | | * hb_font_list_funcs: |
2696 | | * |
2697 | | * Retrieves the list of font functions supported by HarfBuzz. |
2698 | | * |
2699 | | * Return value: (transfer none) (array zero-terminated=1): a |
2700 | | * `NULL`-terminated array of supported font functions |
2701 | | * constant strings. The returned array is owned by HarfBuzz |
2702 | | * and should not be modified or freed. |
2703 | | * |
2704 | | * Since: 11.0.0 |
2705 | | **/ |
2706 | | const char ** |
2707 | | hb_font_list_funcs () |
2708 | 0 | { |
2709 | 0 | return static_font_funcs_list.get_unconst (); |
2710 | 0 | } |
2711 | | |
2712 | | /** |
2713 | | * hb_font_set_scale: |
2714 | | * @font: #hb_font_t to work upon |
2715 | | * @x_scale: Horizontal scale value to assign |
2716 | | * @y_scale: Vertical scale value to assign |
2717 | | * |
2718 | | * Sets the horizontal and vertical scale of a font. |
2719 | | * |
2720 | | * The font scale is a number related to, but not the same as, |
2721 | | * font size. Typically the client establishes a scale factor |
2722 | | * to be used between the two. For example, 64, or 256, which |
2723 | | * would be the fractional-precision part of the font scale. |
2724 | | * This is necessary because #hb_position_t values are integer |
2725 | | * types and you need to leave room for fractional values |
2726 | | * in there. |
2727 | | * |
2728 | | * For example, to set the font size to 20, with 64 |
2729 | | * levels of fractional precision you would call |
2730 | | * `hb_font_set_scale(font, 20 * 64, 20 * 64)`. |
2731 | | * |
2732 | | * In the example above, even what font size 20 means is up to |
2733 | | * you. It might be 20 pixels, or 20 points, or 20 millimeters. |
2734 | | * HarfBuzz does not care about that. You can set the point |
2735 | | * size of the font using hb_font_set_ptem(), and the pixel |
2736 | | * size using hb_font_set_ppem(). |
2737 | | * |
2738 | | * The choice of scale is yours but needs to be consistent between |
2739 | | * what you set here, and what you expect out of #hb_position_t |
2740 | | * as well has draw / paint API output values. |
2741 | | * |
2742 | | * Fonts default to a scale equal to the UPEM value of their face. |
2743 | | * A font with this setting is sometimes called an "unscaled" font. |
2744 | | * |
2745 | | * Since: 0.9.2 |
2746 | | **/ |
2747 | | void |
2748 | | hb_font_set_scale (hb_font_t *font, |
2749 | | int x_scale, |
2750 | | int y_scale) |
2751 | 208k | { |
2752 | 208k | if (hb_object_is_immutable (font)) |
2753 | 0 | return; |
2754 | | |
2755 | 208k | if (font->x_scale == x_scale && font->y_scale == y_scale) |
2756 | 208k | return; |
2757 | | |
2758 | 0 | font->x_scale = x_scale; |
2759 | 0 | font->y_scale = y_scale; |
2760 | |
|
2761 | 0 | font->changed (); |
2762 | 0 | } |
2763 | | |
2764 | | /** |
2765 | | * hb_font_get_scale: |
2766 | | * @font: #hb_font_t to work upon |
2767 | | * @x_scale: (out): Horizontal scale value |
2768 | | * @y_scale: (out): Vertical scale value |
2769 | | * |
2770 | | * Fetches the horizontal and vertical scale of a font. |
2771 | | * |
2772 | | * Since: 0.9.2 |
2773 | | **/ |
2774 | | void |
2775 | | hb_font_get_scale (hb_font_t *font, |
2776 | | int *x_scale, |
2777 | | int *y_scale) |
2778 | 0 | { |
2779 | 0 | if (x_scale) *x_scale = font->x_scale; |
2780 | 0 | if (y_scale) *y_scale = font->y_scale; |
2781 | 0 | } |
2782 | | |
2783 | | /** |
2784 | | * hb_font_set_ppem: |
2785 | | * @font: #hb_font_t to work upon |
2786 | | * @x_ppem: Horizontal ppem value to assign |
2787 | | * @y_ppem: Vertical ppem value to assign |
2788 | | * |
2789 | | * Sets the horizontal and vertical pixels-per-em (PPEM) of a font. |
2790 | | * |
2791 | | * These values are used for pixel-size-specific adjustment to |
2792 | | * shaping and draw results, though for the most part they are |
2793 | | * unused and can be left unset. |
2794 | | * |
2795 | | * Since: 0.9.2 |
2796 | | **/ |
2797 | | void |
2798 | | hb_font_set_ppem (hb_font_t *font, |
2799 | | unsigned int x_ppem, |
2800 | | unsigned int y_ppem) |
2801 | 0 | { |
2802 | 0 | if (hb_object_is_immutable (font)) |
2803 | 0 | return; |
2804 | | |
2805 | 0 | if (font->x_ppem == x_ppem && font->y_ppem == y_ppem) |
2806 | 0 | return; |
2807 | | |
2808 | 0 | font->x_ppem = x_ppem; |
2809 | 0 | font->y_ppem = y_ppem; |
2810 | |
|
2811 | 0 | font->changed (); |
2812 | 0 | } |
2813 | | |
2814 | | /** |
2815 | | * hb_font_get_ppem: |
2816 | | * @font: #hb_font_t to work upon |
2817 | | * @x_ppem: (out): Horizontal ppem value |
2818 | | * @y_ppem: (out): Vertical ppem value |
2819 | | * |
2820 | | * Fetches the horizontal and vertical points-per-em (ppem) of a font. |
2821 | | * |
2822 | | * Since: 0.9.2 |
2823 | | **/ |
2824 | | void |
2825 | | hb_font_get_ppem (hb_font_t *font, |
2826 | | unsigned int *x_ppem, |
2827 | | unsigned int *y_ppem) |
2828 | 0 | { |
2829 | 0 | if (x_ppem) *x_ppem = font->x_ppem; |
2830 | 0 | if (y_ppem) *y_ppem = font->y_ppem; |
2831 | 0 | } |
2832 | | |
2833 | | /** |
2834 | | * hb_font_set_ptem: |
2835 | | * @font: #hb_font_t to work upon |
2836 | | * @ptem: font size in points. |
2837 | | * |
2838 | | * Sets the "point size" of a font. Set to zero to unset. |
2839 | | * Used in CoreText to implement optical sizing. |
2840 | | * |
2841 | | * <note>Note: There are 72 points in an inch.</note> |
2842 | | * |
2843 | | * Since: 1.6.0 |
2844 | | **/ |
2845 | | void |
2846 | | hb_font_set_ptem (hb_font_t *font, |
2847 | | float ptem) |
2848 | 0 | { |
2849 | 0 | if (hb_object_is_immutable (font)) |
2850 | 0 | return; |
2851 | | |
2852 | 0 | if (font->ptem == ptem) |
2853 | 0 | return; |
2854 | | |
2855 | 0 | font->ptem = ptem; |
2856 | |
|
2857 | 0 | font->changed (); |
2858 | 0 | } |
2859 | | |
2860 | | /** |
2861 | | * hb_font_get_ptem: |
2862 | | * @font: #hb_font_t to work upon |
2863 | | * |
2864 | | * Fetches the "point size" of a font. Used in CoreText to |
2865 | | * implement optical sizing. |
2866 | | * |
2867 | | * Return value: Point size. A value of zero means "not set." |
2868 | | * |
2869 | | * Since: 1.6.0 |
2870 | | **/ |
2871 | | float |
2872 | | hb_font_get_ptem (hb_font_t *font) |
2873 | 0 | { |
2874 | 0 | return font->ptem; |
2875 | 0 | } |
2876 | | |
2877 | | /** |
2878 | | * hb_font_is_synthetic: |
2879 | | * @font: #hb_font_t to work upon |
2880 | | * |
2881 | | * Tests whether a font is synthetic. A synthetic font is one |
2882 | | * that has either synthetic slant or synthetic bold set on it. |
2883 | | * |
2884 | | * Return value: `true` if the font is synthetic, `false` otherwise. |
2885 | | * |
2886 | | * Since: 11.2.0 |
2887 | | */ |
2888 | | hb_bool_t |
2889 | | hb_font_is_synthetic (hb_font_t *font) |
2890 | 0 | { |
2891 | 0 | return font->is_synthetic; |
2892 | 0 | } |
2893 | | |
2894 | | /** |
2895 | | * hb_font_set_synthetic_bold: |
2896 | | * @font: #hb_font_t to work upon |
2897 | | * @x_embolden: the amount to embolden horizontally |
2898 | | * @y_embolden: the amount to embolden vertically |
2899 | | * @in_place: whether to embolden glyphs in-place |
2900 | | * |
2901 | | * Sets the "synthetic boldness" of a font. |
2902 | | * |
2903 | | * Positive values for @x_embolden / @y_embolden make a font |
2904 | | * bolder, negative values thinner. Typical values are in the |
2905 | | * 0.01 to 0.05 range. The default value is zero. |
2906 | | * |
2907 | | * Synthetic boldness is applied by offsetting the contour |
2908 | | * points of the glyph shape. |
2909 | | * |
2910 | | * Synthetic boldness is applied when rendering a glyph via |
2911 | | * hb_font_draw_glyph_or_fail(). |
2912 | | * |
2913 | | * If @in_place is `false`, then glyph advance-widths are also |
2914 | | * adjusted, otherwise they are not. The in-place mode is |
2915 | | * useful for simulating [font grading](https://fonts.google.com/knowledge/glossary/grade). |
2916 | | * |
2917 | | * |
2918 | | * Since: 7.0.0 |
2919 | | **/ |
2920 | | void |
2921 | | hb_font_set_synthetic_bold (hb_font_t *font, |
2922 | | float x_embolden, |
2923 | | float y_embolden, |
2924 | | hb_bool_t in_place) |
2925 | 0 | { |
2926 | 0 | if (hb_object_is_immutable (font)) |
2927 | 0 | return; |
2928 | | |
2929 | 0 | if (font->x_embolden == x_embolden && |
2930 | 0 | font->y_embolden == y_embolden && |
2931 | 0 | font->embolden_in_place == (bool) in_place) |
2932 | 0 | return; |
2933 | | |
2934 | 0 | font->x_embolden = x_embolden; |
2935 | 0 | font->y_embolden = y_embolden; |
2936 | 0 | font->embolden_in_place = in_place; |
2937 | |
|
2938 | 0 | font->changed (); |
2939 | 0 | } |
2940 | | |
2941 | | /** |
2942 | | * hb_font_get_synthetic_bold: |
2943 | | * @font: #hb_font_t to work upon |
2944 | | * @x_embolden: (out): return location for horizontal value |
2945 | | * @y_embolden: (out): return location for vertical value |
2946 | | * @in_place: (out): return location for in-place value |
2947 | | * |
2948 | | * Fetches the "synthetic boldness" parameters of a font. |
2949 | | * |
2950 | | * Since: 7.0.0 |
2951 | | **/ |
2952 | | void |
2953 | | hb_font_get_synthetic_bold (hb_font_t *font, |
2954 | | float *x_embolden, |
2955 | | float *y_embolden, |
2956 | | hb_bool_t *in_place) |
2957 | 0 | { |
2958 | 0 | if (x_embolden) *x_embolden = font->x_embolden; |
2959 | 0 | if (y_embolden) *y_embolden = font->y_embolden; |
2960 | 0 | if (in_place) *in_place = font->embolden_in_place; |
2961 | 0 | } |
2962 | | |
2963 | | /** |
2964 | | * hb_font_set_synthetic_slant: |
2965 | | * @font: #hb_font_t to work upon |
2966 | | * @slant: synthetic slant value. |
2967 | | * |
2968 | | * Sets the "synthetic slant" of a font. By default is zero. |
2969 | | * Synthetic slant is the graphical skew applied to the font |
2970 | | * at rendering time. |
2971 | | * |
2972 | | * HarfBuzz needs to know this value to adjust shaping results, |
2973 | | * metrics, and style values to match the slanted rendering. |
2974 | | * |
2975 | | * <note>Note: The glyph shape fetched via the hb_font_draw_glyph_or_fail() |
2976 | | * function is slanted to reflect this value as well.</note> |
2977 | | * |
2978 | | * <note>Note: The slant value is a ratio. For example, a |
2979 | | * 20% slant would be represented as a 0.2 value.</note> |
2980 | | * |
2981 | | * Since: 3.3.0 |
2982 | | **/ |
2983 | | HB_EXTERN void |
2984 | | hb_font_set_synthetic_slant (hb_font_t *font, float slant) |
2985 | 0 | { |
2986 | 0 | if (hb_object_is_immutable (font)) |
2987 | 0 | return; |
2988 | | |
2989 | 0 | if (font->slant == slant) |
2990 | 0 | return; |
2991 | | |
2992 | 0 | font->slant = slant; |
2993 | |
|
2994 | 0 | font->changed (); |
2995 | 0 | } |
2996 | | |
2997 | | /** |
2998 | | * hb_font_get_synthetic_slant: |
2999 | | * @font: #hb_font_t to work upon |
3000 | | * |
3001 | | * Fetches the "synthetic slant" of a font. |
3002 | | * |
3003 | | * Return value: Synthetic slant. By default is zero. |
3004 | | * |
3005 | | * Since: 3.3.0 |
3006 | | **/ |
3007 | | HB_EXTERN float |
3008 | | hb_font_get_synthetic_slant (hb_font_t *font) |
3009 | 0 | { |
3010 | 0 | return font->slant; |
3011 | 0 | } |
3012 | | |
3013 | | #ifndef HB_NO_VAR |
3014 | | /* |
3015 | | * Variations |
3016 | | */ |
3017 | | |
3018 | | /** |
3019 | | * hb_font_set_variations: |
3020 | | * @font: #hb_font_t to work upon |
3021 | | * @variations: (array length=variations_length): Array of variation settings to apply |
3022 | | * @variations_length: Number of variations to apply |
3023 | | * |
3024 | | * Applies a list of font-variation settings to a font. |
3025 | | * |
3026 | | * Note that this overrides all existing variations set on @font. |
3027 | | * Axes not included in @variations will be effectively set to their |
3028 | | * default values. |
3029 | | * |
3030 | | * Since: 1.4.2 |
3031 | | */ |
3032 | | void |
3033 | | hb_font_set_variations (hb_font_t *font, |
3034 | | const hb_variation_t *variations, |
3035 | | unsigned int variations_length) |
3036 | 231k | { |
3037 | 231k | if (hb_object_is_immutable (font)) |
3038 | 0 | return; |
3039 | | |
3040 | 231k | const OT::fvar &fvar = *font->face->table.fvar; |
3041 | 231k | auto axes = fvar.get_axes (); |
3042 | 231k | const unsigned coords_length = axes.length; |
3043 | | |
3044 | 231k | int *normalized = coords_length ? (int *) hb_calloc (coords_length, sizeof (int)) : nullptr; |
3045 | 231k | float *design_coords = coords_length ? (float *) hb_calloc (coords_length, sizeof (float)) : nullptr; |
3046 | | |
3047 | 231k | if (unlikely (coords_length && !(normalized && design_coords))) |
3048 | 0 | { |
3049 | 0 | hb_free (normalized); |
3050 | 0 | hb_free (design_coords); |
3051 | 0 | return; |
3052 | 0 | } |
3053 | | |
3054 | | /* Initialize design coords. */ |
3055 | 231k | for (unsigned int i = 0; i < coords_length; i++) |
3056 | 0 | design_coords[i] = axes[i].get_default (); |
3057 | 231k | if (font->instance_index != HB_FONT_NO_VAR_NAMED_INSTANCE) |
3058 | 0 | { |
3059 | 0 | unsigned count = coords_length; |
3060 | | /* This may fail if index is out-of-range; |
3061 | | * That's why we initialize design_coords from fvar above |
3062 | | * unconditionally. */ |
3063 | 0 | hb_ot_var_named_instance_get_design_coords (font->face, font->instance_index, |
3064 | 0 | &count, design_coords); |
3065 | 0 | } |
3066 | | |
3067 | 248k | for (unsigned int i = 0; i < variations_length; i++) |
3068 | 16.6k | { |
3069 | 16.6k | const auto tag = variations[i].tag; |
3070 | 16.6k | const auto v = variations[i].value; |
3071 | 16.6k | for (unsigned axis_index = 0; axis_index < coords_length; axis_index++) |
3072 | 0 | if (axes[axis_index].axisTag == tag) |
3073 | 0 | design_coords[axis_index] = v; |
3074 | 16.6k | } |
3075 | | |
3076 | 231k | hb_ot_var_normalize_coords (font->face, coords_length, design_coords, normalized); |
3077 | 231k | _hb_font_adopt_var_coords (font, normalized, design_coords, coords_length); |
3078 | 231k | } |
3079 | | |
3080 | | /** |
3081 | | * hb_font_set_variation: |
3082 | | * @font: #hb_font_t to work upon |
3083 | | * @tag: The #hb_tag_t tag of the variation-axis name |
3084 | | * @value: The value of the variation axis |
3085 | | * |
3086 | | * Change the value of one variation axis on the font. |
3087 | | * |
3088 | | * Note: This function is expensive to be called repeatedly. |
3089 | | * If you want to set multiple variation axes at the same time, |
3090 | | * use hb_font_set_variations() instead. |
3091 | | * |
3092 | | * Since: 7.1.0 |
3093 | | */ |
3094 | | void |
3095 | | hb_font_set_variation (hb_font_t *font, |
3096 | | hb_tag_t tag, |
3097 | | float value) |
3098 | 0 | { |
3099 | 0 | if (hb_object_is_immutable (font)) |
3100 | 0 | return; |
3101 | | |
3102 | | // TODO Share some of this code with set_variations() |
3103 | | |
3104 | 0 | const OT::fvar &fvar = *font->face->table.fvar; |
3105 | 0 | auto axes = fvar.get_axes (); |
3106 | 0 | const unsigned coords_length = axes.length; |
3107 | |
|
3108 | 0 | int *normalized = coords_length ? (int *) hb_calloc (coords_length, sizeof (int)) : nullptr; |
3109 | 0 | float *design_coords = coords_length ? (float *) hb_calloc (coords_length, sizeof (float)) : nullptr; |
3110 | |
|
3111 | 0 | if (unlikely (coords_length && !(normalized && design_coords))) |
3112 | 0 | { |
3113 | 0 | hb_free (normalized); |
3114 | 0 | hb_free (design_coords); |
3115 | 0 | return; |
3116 | 0 | } |
3117 | | |
3118 | | /* Initialize design coords. */ |
3119 | 0 | if (font->design_coords) |
3120 | 0 | { |
3121 | 0 | assert (coords_length == font->num_coords); |
3122 | 0 | for (unsigned int i = 0; i < coords_length; i++) |
3123 | 0 | design_coords[i] = font->design_coords[i]; |
3124 | 0 | } |
3125 | 0 | else |
3126 | 0 | { |
3127 | 0 | for (unsigned int i = 0; i < coords_length; i++) |
3128 | 0 | design_coords[i] = axes[i].get_default (); |
3129 | 0 | if (font->instance_index != HB_FONT_NO_VAR_NAMED_INSTANCE) |
3130 | 0 | { |
3131 | 0 | unsigned count = coords_length; |
3132 | | /* This may fail if index is out-of-range; |
3133 | | * That's why we initialize design_coords from fvar above |
3134 | | * unconditionally. */ |
3135 | 0 | hb_ot_var_named_instance_get_design_coords (font->face, font->instance_index, |
3136 | 0 | &count, design_coords); |
3137 | 0 | } |
3138 | 0 | } |
3139 | |
|
3140 | 0 | for (unsigned axis_index = 0; axis_index < coords_length; axis_index++) |
3141 | 0 | if (axes[axis_index].axisTag == tag) |
3142 | 0 | design_coords[axis_index] = value; |
3143 | |
|
3144 | 0 | hb_ot_var_normalize_coords (font->face, coords_length, design_coords, normalized); |
3145 | 0 | _hb_font_adopt_var_coords (font, normalized, design_coords, coords_length); |
3146 | 0 | } |
3147 | | |
3148 | | /** |
3149 | | * hb_font_set_var_coords_design: |
3150 | | * @font: #hb_font_t to work upon |
3151 | | * @coords: (array length=coords_length): Array of variation coordinates to apply |
3152 | | * @coords_length: Number of coordinates to apply |
3153 | | * |
3154 | | * Applies a list of variation coordinates (in design-space units) |
3155 | | * to a font. |
3156 | | * |
3157 | | * Note that this overrides all existing variations set on @font. |
3158 | | * Axes not included in @coords will be effectively set to their |
3159 | | * default values. |
3160 | | * |
3161 | | * Since: 1.4.2 |
3162 | | */ |
3163 | | void |
3164 | | hb_font_set_var_coords_design (hb_font_t *font, |
3165 | | const float *coords, |
3166 | | unsigned int input_coords_length) |
3167 | 0 | { |
3168 | 0 | if (hb_object_is_immutable (font)) |
3169 | 0 | return; |
3170 | | |
3171 | 0 | const OT::fvar &fvar = *font->face->table.fvar; |
3172 | 0 | auto axes = fvar.get_axes (); |
3173 | 0 | const unsigned coords_length = axes.length; |
3174 | |
|
3175 | 0 | input_coords_length = hb_min (input_coords_length, coords_length); |
3176 | 0 | int *normalized = coords_length ? (int *) hb_calloc (coords_length, sizeof (int)) : nullptr; |
3177 | 0 | float *design_coords = coords_length ? (float *) hb_calloc (coords_length, sizeof (float)) : nullptr; |
3178 | |
|
3179 | 0 | if (unlikely (coords_length && !(normalized && design_coords))) |
3180 | 0 | { |
3181 | 0 | hb_free (normalized); |
3182 | 0 | hb_free (design_coords); |
3183 | 0 | return; |
3184 | 0 | } |
3185 | | |
3186 | 0 | if (input_coords_length) |
3187 | 0 | hb_memcpy (design_coords, coords, input_coords_length * sizeof (font->design_coords[0])); |
3188 | | // Fill in the rest with default values |
3189 | 0 | for (unsigned int i = input_coords_length; i < coords_length; i++) |
3190 | 0 | design_coords[i] = axes[i].get_default (); |
3191 | |
|
3192 | 0 | hb_ot_var_normalize_coords (font->face, coords_length, design_coords, normalized); |
3193 | 0 | _hb_font_adopt_var_coords (font, normalized, design_coords, coords_length); |
3194 | 0 | } |
3195 | | |
3196 | | /** |
3197 | | * hb_font_set_var_named_instance: |
3198 | | * @font: a font. |
3199 | | * @instance_index: named instance index. |
3200 | | * |
3201 | | * Sets design coords of a font from a named-instance index. |
3202 | | * |
3203 | | * Since: 2.6.0 |
3204 | | */ |
3205 | | void |
3206 | | hb_font_set_var_named_instance (hb_font_t *font, |
3207 | | unsigned int instance_index) |
3208 | 0 | { |
3209 | 0 | if (hb_object_is_immutable (font)) |
3210 | 0 | return; |
3211 | | |
3212 | 0 | if (font->instance_index == instance_index) |
3213 | 0 | return; |
3214 | | |
3215 | 0 | font->instance_index = instance_index; |
3216 | 0 | hb_font_set_variations (font, nullptr, 0); |
3217 | 0 | } |
3218 | | |
3219 | | /** |
3220 | | * hb_font_get_var_named_instance: |
3221 | | * @font: a font. |
3222 | | * |
3223 | | * Returns the currently-set named-instance index of the font. |
3224 | | * |
3225 | | * Return value: Named-instance index or %HB_FONT_NO_VAR_NAMED_INSTANCE. |
3226 | | * |
3227 | | * Since: 7.0.0 |
3228 | | **/ |
3229 | | unsigned int |
3230 | | hb_font_get_var_named_instance (hb_font_t *font) |
3231 | 0 | { |
3232 | 0 | return font->instance_index; |
3233 | 0 | } |
3234 | | |
3235 | | /** |
3236 | | * hb_font_set_var_coords_normalized: |
3237 | | * @font: #hb_font_t to work upon |
3238 | | * @coords: (array length=coords_length): Array of variation coordinates to apply |
3239 | | * @coords_length: Number of coordinates to apply |
3240 | | * |
3241 | | * Applies a list of variation coordinates (in normalized units) |
3242 | | * to a font. |
3243 | | * |
3244 | | * Note that this overrides all existing variations set on @font. |
3245 | | * Axes not included in @coords will be effectively set to their |
3246 | | * default values. |
3247 | | * |
3248 | | * <note>Note: Coordinates should be normalized to 2.14.</note> |
3249 | | * |
3250 | | * Since: 1.4.2 |
3251 | | */ |
3252 | | void |
3253 | | hb_font_set_var_coords_normalized (hb_font_t *font, |
3254 | | const int *coords, /* 2.14 normalized */ |
3255 | | unsigned int input_coords_length) |
3256 | 0 | { |
3257 | 0 | if (hb_object_is_immutable (font)) |
3258 | 0 | return; |
3259 | | |
3260 | 0 | const OT::fvar &fvar = *font->face->table.fvar; |
3261 | 0 | auto axes = fvar.get_axes (); |
3262 | 0 | unsigned coords_length = axes.length; |
3263 | |
|
3264 | 0 | input_coords_length = hb_min (input_coords_length, coords_length); |
3265 | 0 | int *copy = coords_length ? (int *) hb_calloc (coords_length, sizeof (coords[0])) : nullptr; |
3266 | 0 | float *design_coords = coords_length ? (float *) hb_calloc (coords_length, sizeof (design_coords[0])) : nullptr; |
3267 | |
|
3268 | 0 | if (unlikely (coords_length && !(copy && design_coords))) |
3269 | 0 | { |
3270 | 0 | hb_free (copy); |
3271 | 0 | hb_free (design_coords); |
3272 | 0 | return; |
3273 | 0 | } |
3274 | | |
3275 | 0 | if (input_coords_length) |
3276 | 0 | hb_memcpy (copy, coords, input_coords_length * sizeof (coords[0])); |
3277 | |
|
3278 | 0 | for (unsigned int i = 0; i < coords_length; ++i) |
3279 | 0 | design_coords[i] = NAN; |
3280 | |
|
3281 | 0 | _hb_font_adopt_var_coords (font, copy, design_coords, coords_length); |
3282 | 0 | } |
3283 | | |
3284 | | /** |
3285 | | * hb_font_get_var_coords_normalized: |
3286 | | * @font: #hb_font_t to work upon |
3287 | | * @length: (out): Number of coordinates retrieved |
3288 | | * |
3289 | | * Fetches the list of normalized variation coordinates currently |
3290 | | * set on a font. |
3291 | | * |
3292 | | * <note>Note that if no variation coordinates are set, this function may |
3293 | | * return %NULL.</note> |
3294 | | * |
3295 | | * Return value is valid as long as variation coordinates of the font |
3296 | | * are not modified. |
3297 | | * |
3298 | | * Return value: coordinates array |
3299 | | * |
3300 | | * Since: 1.4.2 |
3301 | | */ |
3302 | | const int * |
3303 | | hb_font_get_var_coords_normalized (hb_font_t *font, |
3304 | | unsigned int *length) |
3305 | 0 | { |
3306 | 0 | if (length) |
3307 | 0 | *length = font->num_coords; |
3308 | |
|
3309 | 0 | return font->coords; |
3310 | 0 | } |
3311 | | |
3312 | | /** |
3313 | | * hb_font_get_var_coords_design: |
3314 | | * @font: #hb_font_t to work upon |
3315 | | * @length: (out): Number of coordinates retrieved |
3316 | | * |
3317 | | * Fetches the list of variation coordinates (in design-space units) currently |
3318 | | * set on a font. |
3319 | | * |
3320 | | * <note>Note that if no variation coordinates are set, this function may |
3321 | | * return %NULL.</note> |
3322 | | * |
3323 | | * <note>If variations have been set on the font using normalized coordinates |
3324 | | * (i.e. via hb_font_set_var_coords_normalized()), the design coordinates will |
3325 | | * have NaN (Not a Number) values.</note> |
3326 | | * |
3327 | | * Return value is valid as long as variation coordinates of the font |
3328 | | * are not modified. |
3329 | | * |
3330 | | * Return value: coordinates array |
3331 | | * |
3332 | | * Since: 3.3.0 |
3333 | | */ |
3334 | | const float * |
3335 | | hb_font_get_var_coords_design (hb_font_t *font, |
3336 | | unsigned int *length) |
3337 | 0 | { |
3338 | 0 | if (length) |
3339 | 0 | *length = font->num_coords; |
3340 | |
|
3341 | 0 | return font->design_coords; |
3342 | 0 | } |
3343 | | #endif |
3344 | | |
3345 | | #ifndef HB_DISABLE_DEPRECATED |
3346 | | /* |
3347 | | * Deprecated get_glyph_func(): |
3348 | | */ |
3349 | | |
3350 | | struct hb_trampoline_closure_t |
3351 | | { |
3352 | | void *user_data; |
3353 | | hb_destroy_func_t destroy; |
3354 | | unsigned int ref_count; |
3355 | | }; |
3356 | | |
3357 | | template <typename FuncType> |
3358 | | struct hb_trampoline_t |
3359 | | { |
3360 | | hb_trampoline_closure_t closure; /* Must be first. */ |
3361 | | FuncType func; |
3362 | | }; |
3363 | | |
3364 | | template <typename FuncType> |
3365 | | static hb_trampoline_t<FuncType> * |
3366 | | trampoline_create (FuncType func, |
3367 | | void *user_data, |
3368 | | hb_destroy_func_t destroy) |
3369 | 0 | { |
3370 | 0 | typedef hb_trampoline_t<FuncType> trampoline_t; |
3371 | |
|
3372 | 0 | trampoline_t *trampoline = (trampoline_t *) hb_calloc (1, sizeof (trampoline_t)); |
3373 | |
|
3374 | 0 | if (unlikely (!trampoline)) |
3375 | 0 | return nullptr; |
3376 | | |
3377 | 0 | trampoline->closure.user_data = user_data; |
3378 | 0 | trampoline->closure.destroy = destroy; |
3379 | 0 | trampoline->closure.ref_count = 1; |
3380 | 0 | trampoline->func = func; |
3381 | |
|
3382 | 0 | return trampoline; |
3383 | 0 | } |
3384 | | |
3385 | | static void |
3386 | | trampoline_reference (hb_trampoline_closure_t *closure) |
3387 | 0 | { |
3388 | 0 | closure->ref_count++; |
3389 | 0 | } |
3390 | | |
3391 | | static void |
3392 | | trampoline_destroy (void *user_data) |
3393 | 0 | { |
3394 | 0 | hb_trampoline_closure_t *closure = (hb_trampoline_closure_t *) user_data; |
3395 | |
|
3396 | 0 | if (--closure->ref_count) |
3397 | 0 | return; |
3398 | | |
3399 | 0 | if (closure->destroy) |
3400 | 0 | closure->destroy (closure->user_data); |
3401 | 0 | hb_free (closure); |
3402 | 0 | } |
3403 | | |
3404 | | typedef hb_trampoline_t<hb_font_get_glyph_func_t> hb_font_get_glyph_trampoline_t; |
3405 | | |
3406 | | static hb_bool_t |
3407 | | hb_font_get_nominal_glyph_trampoline (hb_font_t *font, |
3408 | | void *font_data, |
3409 | | hb_codepoint_t unicode, |
3410 | | hb_codepoint_t *glyph, |
3411 | | void *user_data) |
3412 | 0 | { |
3413 | 0 | hb_font_get_glyph_trampoline_t *trampoline = (hb_font_get_glyph_trampoline_t *) user_data; |
3414 | 0 | return trampoline->func (font, font_data, unicode, 0, glyph, trampoline->closure.user_data); |
3415 | 0 | } |
3416 | | |
3417 | | static hb_bool_t |
3418 | | hb_font_get_variation_glyph_trampoline (hb_font_t *font, |
3419 | | void *font_data, |
3420 | | hb_codepoint_t unicode, |
3421 | | hb_codepoint_t variation_selector, |
3422 | | hb_codepoint_t *glyph, |
3423 | | void *user_data) |
3424 | 0 | { |
3425 | 0 | hb_font_get_glyph_trampoline_t *trampoline = (hb_font_get_glyph_trampoline_t *) user_data; |
3426 | 0 | return trampoline->func (font, font_data, unicode, variation_selector, glyph, trampoline->closure.user_data); |
3427 | 0 | } |
3428 | | |
3429 | | /** |
3430 | | * hb_font_funcs_set_glyph_func: |
3431 | | * @ffuncs: The font-functions structure |
3432 | | * @func: (closure user_data) (destroy destroy) (scope notified): callback function |
3433 | | * @user_data: data to pass to @func |
3434 | | * @destroy: (nullable): function to call when @user_data is not needed anymore |
3435 | | * |
3436 | | * Deprecated. Use hb_font_funcs_set_nominal_glyph_func() and |
3437 | | * hb_font_funcs_set_variation_glyph_func() instead. |
3438 | | * |
3439 | | * Since: 0.9.2 |
3440 | | * Deprecated: 1.2.3 |
3441 | | **/ |
3442 | | void |
3443 | | hb_font_funcs_set_glyph_func (hb_font_funcs_t *ffuncs, |
3444 | | hb_font_get_glyph_func_t func, |
3445 | | void *user_data, |
3446 | | hb_destroy_func_t destroy /* May be NULL. */) |
3447 | 0 | { |
3448 | 0 | if (hb_object_is_immutable (ffuncs)) |
3449 | 0 | { |
3450 | 0 | if (destroy) |
3451 | 0 | destroy (user_data); |
3452 | 0 | return; |
3453 | 0 | } |
3454 | | |
3455 | 0 | hb_font_get_glyph_trampoline_t *trampoline; |
3456 | |
|
3457 | 0 | trampoline = trampoline_create (func, user_data, destroy); |
3458 | 0 | if (unlikely (!trampoline)) |
3459 | 0 | { |
3460 | 0 | if (destroy) |
3461 | 0 | destroy (user_data); |
3462 | 0 | return; |
3463 | 0 | } |
3464 | | |
3465 | | /* Since we pass it to two destroying functions. */ |
3466 | 0 | trampoline_reference (&trampoline->closure); |
3467 | |
|
3468 | 0 | hb_font_funcs_set_nominal_glyph_func (ffuncs, |
3469 | 0 | hb_font_get_nominal_glyph_trampoline, |
3470 | 0 | trampoline, |
3471 | 0 | trampoline_destroy); |
3472 | |
|
3473 | 0 | hb_font_funcs_set_variation_glyph_func (ffuncs, |
3474 | 0 | hb_font_get_variation_glyph_trampoline, |
3475 | 0 | trampoline, |
3476 | 0 | trampoline_destroy); |
3477 | 0 | } |
3478 | | #endif |
3479 | | |
3480 | | |
3481 | | #ifndef HB_DISABLE_DEPRECATED |
3482 | | |
3483 | | struct hb_draw_glyph_closure_t |
3484 | | { |
3485 | | hb_font_draw_glyph_func_t func; |
3486 | | void *user_data; |
3487 | | hb_destroy_func_t destroy; |
3488 | | }; |
3489 | | static hb_bool_t |
3490 | | hb_font_draw_glyph_trampoline (hb_font_t *font, |
3491 | | void *font_data, |
3492 | | hb_codepoint_t glyph, |
3493 | | hb_draw_funcs_t *draw_funcs, |
3494 | | void *draw_data, |
3495 | | void *user_data) |
3496 | 0 | { |
3497 | 0 | hb_draw_glyph_closure_t *closure = (hb_draw_glyph_closure_t *) user_data; |
3498 | 0 | closure->func (font, font_data, glyph, draw_funcs, draw_data, closure->user_data); |
3499 | 0 | return true; |
3500 | 0 | } |
3501 | | static void |
3502 | | hb_font_draw_glyph_closure_destroy (void *user_data) |
3503 | 0 | { |
3504 | 0 | hb_draw_glyph_closure_t *closure = (hb_draw_glyph_closure_t *) user_data; |
3505 | |
|
3506 | 0 | if (closure->destroy) |
3507 | 0 | closure->destroy (closure->user_data); |
3508 | 0 | hb_free (closure); |
3509 | 0 | } |
3510 | | static void |
3511 | | _hb_font_funcs_set_draw_glyph_func (hb_font_funcs_t *ffuncs, |
3512 | | hb_font_draw_glyph_func_t func, |
3513 | | void *user_data, |
3514 | | hb_destroy_func_t destroy /* May be NULL. */) |
3515 | 0 | { |
3516 | 0 | if (hb_object_is_immutable (ffuncs)) |
3517 | 0 | { |
3518 | 0 | if (destroy) |
3519 | 0 | destroy (user_data); |
3520 | 0 | return; |
3521 | 0 | } |
3522 | 0 | hb_draw_glyph_closure_t *closure = (hb_draw_glyph_closure_t *) hb_calloc (1, sizeof (hb_draw_glyph_closure_t)); |
3523 | 0 | if (unlikely (!closure)) |
3524 | 0 | { |
3525 | 0 | if (destroy) |
3526 | 0 | destroy (user_data); |
3527 | 0 | return; |
3528 | 0 | } |
3529 | 0 | closure->func = func; |
3530 | 0 | closure->user_data = user_data; |
3531 | 0 | closure->destroy = destroy; |
3532 | |
|
3533 | 0 | hb_font_funcs_set_draw_glyph_or_fail_func (ffuncs, |
3534 | 0 | hb_font_draw_glyph_trampoline, |
3535 | 0 | closure, |
3536 | 0 | hb_font_draw_glyph_closure_destroy); |
3537 | 0 | } |
3538 | | void |
3539 | | hb_font_funcs_set_draw_glyph_func (hb_font_funcs_t *ffuncs, |
3540 | | hb_font_draw_glyph_func_t func, |
3541 | | void *user_data, |
3542 | | hb_destroy_func_t destroy /* May be NULL. */) |
3543 | 0 | { |
3544 | 0 | _hb_font_funcs_set_draw_glyph_func (ffuncs, func, user_data, destroy); |
3545 | 0 | } |
3546 | | void |
3547 | | hb_font_funcs_set_glyph_shape_func (hb_font_funcs_t *ffuncs, |
3548 | | hb_font_get_glyph_shape_func_t func, |
3549 | | void *user_data, |
3550 | | hb_destroy_func_t destroy /* May be NULL. */) |
3551 | 0 | { |
3552 | 0 | _hb_font_funcs_set_draw_glyph_func (ffuncs, func, user_data, destroy); |
3553 | 0 | } |
3554 | | |
3555 | | struct hb_paint_glyph_closure_t |
3556 | | { |
3557 | | hb_font_paint_glyph_func_t func; |
3558 | | void *user_data; |
3559 | | hb_destroy_func_t destroy; |
3560 | | }; |
3561 | | static hb_bool_t |
3562 | | hb_font_paint_glyph_trampoline (hb_font_t *font, |
3563 | | void *font_data, |
3564 | | hb_codepoint_t glyph, |
3565 | | hb_paint_funcs_t *paint_funcs, |
3566 | | void *paint_data, |
3567 | | unsigned int palette, |
3568 | | hb_color_t foreground, |
3569 | | void *user_data) |
3570 | 0 | { |
3571 | 0 | hb_paint_glyph_closure_t *closure = (hb_paint_glyph_closure_t *) user_data; |
3572 | 0 | closure->func (font, font_data, glyph, paint_funcs, paint_data, palette, foreground, closure->user_data); |
3573 | 0 | return true; |
3574 | 0 | } |
3575 | | static void |
3576 | | hb_font_paint_glyph_closure_destroy (void *user_data) |
3577 | 0 | { |
3578 | 0 | hb_paint_glyph_closure_t *closure = (hb_paint_glyph_closure_t *) user_data; |
3579 | |
|
3580 | 0 | if (closure->destroy) |
3581 | 0 | closure->destroy (closure->user_data); |
3582 | 0 | hb_free (closure); |
3583 | 0 | } |
3584 | | void |
3585 | | hb_font_funcs_set_paint_glyph_func (hb_font_funcs_t *ffuncs, |
3586 | | hb_font_paint_glyph_func_t func, |
3587 | | void *user_data, |
3588 | | hb_destroy_func_t destroy /* May be NULL. */) |
3589 | 0 | { |
3590 | 0 | if (hb_object_is_immutable (ffuncs)) |
3591 | 0 | { |
3592 | 0 | if (destroy) |
3593 | 0 | destroy (user_data); |
3594 | 0 | return; |
3595 | 0 | } |
3596 | 0 | hb_paint_glyph_closure_t *closure = (hb_paint_glyph_closure_t *) hb_calloc (1, sizeof (hb_paint_glyph_closure_t)); |
3597 | 0 | if (unlikely (!closure)) |
3598 | 0 | { |
3599 | 0 | if (destroy) |
3600 | 0 | destroy (user_data); |
3601 | 0 | return; |
3602 | 0 | } |
3603 | 0 | closure->func = func; |
3604 | 0 | closure->user_data = user_data; |
3605 | 0 | closure->destroy = destroy; |
3606 | |
|
3607 | 0 | hb_font_funcs_set_paint_glyph_or_fail_func (ffuncs, |
3608 | 0 | hb_font_paint_glyph_trampoline, |
3609 | 0 | closure, |
3610 | 0 | hb_font_paint_glyph_closure_destroy); |
3611 | 0 | } |
3612 | | #endif |