2 * Copyright © 2009 Red Hat, Inc.
3 * Copyright © 2012 Google, Inc.
5 * This is part of HarfBuzz, a text shaping library.
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.
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
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.
25 * Red Hat Author(s): Behdad Esfahbod
26 * Google Author(s): Behdad Esfahbod
32 #include "hb-machinery.hh"
40 * @short_description: Font objects
43 * Font objects represent a font face at a certain size and other
44 * parameters (pixels per EM, points per EM, variation settings.)
45 * Fonts are created from font faces, and are used as input to
46 * hb_shape() among other things.
55 hb_font_get_font_h_extents_nil (hb_font_t *font HB_UNUSED,
56 void *font_data HB_UNUSED,
57 hb_font_extents_t *extents,
58 void *user_data HB_UNUSED)
60 memset (extents, 0, sizeof (*extents));
64 hb_font_get_font_h_extents_default (hb_font_t *font,
65 void *font_data HB_UNUSED,
66 hb_font_extents_t *extents,
67 void *user_data HB_UNUSED)
69 hb_bool_t ret = font->parent->get_font_h_extents (extents);
71 extents->ascender = font->parent_scale_y_distance (extents->ascender);
72 extents->descender = font->parent_scale_y_distance (extents->descender);
73 extents->line_gap = font->parent_scale_y_distance (extents->line_gap);
79 hb_font_get_font_v_extents_nil (hb_font_t *font HB_UNUSED,
80 void *font_data HB_UNUSED,
81 hb_font_extents_t *extents,
82 void *user_data HB_UNUSED)
84 memset (extents, 0, sizeof (*extents));
88 hb_font_get_font_v_extents_default (hb_font_t *font,
89 void *font_data HB_UNUSED,
90 hb_font_extents_t *extents,
91 void *user_data HB_UNUSED)
93 hb_bool_t ret = font->parent->get_font_v_extents (extents);
95 extents->ascender = font->parent_scale_x_distance (extents->ascender);
96 extents->descender = font->parent_scale_x_distance (extents->descender);
97 extents->line_gap = font->parent_scale_x_distance (extents->line_gap);
103 hb_font_get_nominal_glyph_nil (hb_font_t *font HB_UNUSED,
104 void *font_data HB_UNUSED,
105 hb_codepoint_t unicode HB_UNUSED,
106 hb_codepoint_t *glyph,
107 void *user_data HB_UNUSED)
113 hb_font_get_nominal_glyph_default (hb_font_t *font,
114 void *font_data HB_UNUSED,
115 hb_codepoint_t unicode,
116 hb_codepoint_t *glyph,
117 void *user_data HB_UNUSED)
119 if (font->has_nominal_glyphs_func_set ())
121 return font->get_nominal_glyphs (1, &unicode, 0, glyph, 0);
123 return font->parent->get_nominal_glyph (unicode, glyph);
126 #define hb_font_get_nominal_glyphs_nil hb_font_get_nominal_glyphs_default
128 hb_font_get_nominal_glyphs_default (hb_font_t *font,
129 void *font_data HB_UNUSED,
131 const hb_codepoint_t *first_unicode,
132 unsigned int unicode_stride,
133 hb_codepoint_t *first_glyph,
134 unsigned int glyph_stride,
135 void *user_data HB_UNUSED)
137 if (font->has_nominal_glyph_func_set ())
139 for (unsigned int i = 0; i < count; i++)
141 if (!font->get_nominal_glyph (*first_unicode, first_glyph))
144 first_unicode = &StructAtOffsetUnaligned<hb_codepoint_t> (first_unicode, unicode_stride);
145 first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
150 return font->parent->get_nominal_glyphs (count,
151 first_unicode, unicode_stride,
152 first_glyph, glyph_stride);
156 hb_font_get_variation_glyph_nil (hb_font_t *font HB_UNUSED,
157 void *font_data HB_UNUSED,
158 hb_codepoint_t unicode HB_UNUSED,
159 hb_codepoint_t variation_selector HB_UNUSED,
160 hb_codepoint_t *glyph,
161 void *user_data HB_UNUSED)
167 hb_font_get_variation_glyph_default (hb_font_t *font,
168 void *font_data HB_UNUSED,
169 hb_codepoint_t unicode,
170 hb_codepoint_t variation_selector,
171 hb_codepoint_t *glyph,
172 void *user_data HB_UNUSED)
174 return font->parent->get_variation_glyph (unicode, variation_selector, glyph);
179 hb_font_get_glyph_h_advance_nil (hb_font_t *font,
180 void *font_data HB_UNUSED,
181 hb_codepoint_t glyph HB_UNUSED,
182 void *user_data HB_UNUSED)
184 return font->x_scale;
187 hb_font_get_glyph_h_advance_default (hb_font_t *font,
188 void *font_data HB_UNUSED,
189 hb_codepoint_t glyph,
190 void *user_data HB_UNUSED)
192 if (font->has_glyph_h_advances_func_set ())
195 font->get_glyph_h_advances (1, &glyph, 0, &ret, 0);
198 return font->parent_scale_x_distance (font->parent->get_glyph_h_advance (glyph));
202 hb_font_get_glyph_v_advance_nil (hb_font_t *font,
203 void *font_data HB_UNUSED,
204 hb_codepoint_t glyph HB_UNUSED,
205 void *user_data HB_UNUSED)
207 /* TODO use font_extents.ascender+descender */
208 return font->y_scale;
211 hb_font_get_glyph_v_advance_default (hb_font_t *font,
212 void *font_data HB_UNUSED,
213 hb_codepoint_t glyph,
214 void *user_data HB_UNUSED)
216 if (font->has_glyph_v_advances_func_set ())
219 font->get_glyph_v_advances (1, &glyph, 0, &ret, 0);
222 return font->parent_scale_y_distance (font->parent->get_glyph_v_advance (glyph));
225 #define hb_font_get_glyph_h_advances_nil hb_font_get_glyph_h_advances_default
227 hb_font_get_glyph_h_advances_default (hb_font_t* font,
228 void* font_data HB_UNUSED,
230 const hb_codepoint_t *first_glyph,
231 unsigned int glyph_stride,
232 hb_position_t *first_advance,
233 unsigned int advance_stride,
234 void *user_data HB_UNUSED)
236 if (font->has_glyph_h_advance_func_set ())
238 for (unsigned int i = 0; i < count; i++)
240 *first_advance = font->get_glyph_h_advance (*first_glyph);
241 first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
242 first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
247 font->parent->get_glyph_h_advances (count,
248 first_glyph, glyph_stride,
249 first_advance, advance_stride);
250 for (unsigned int i = 0; i < count; i++)
252 *first_advance = font->parent_scale_x_distance (*first_advance);
253 first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
257 #define hb_font_get_glyph_v_advances_nil hb_font_get_glyph_v_advances_default
259 hb_font_get_glyph_v_advances_default (hb_font_t* font,
260 void* font_data HB_UNUSED,
262 const hb_codepoint_t *first_glyph,
263 unsigned int glyph_stride,
264 hb_position_t *first_advance,
265 unsigned int advance_stride,
266 void *user_data HB_UNUSED)
268 if (font->has_glyph_v_advance_func_set ())
270 for (unsigned int i = 0; i < count; i++)
272 *first_advance = font->get_glyph_v_advance (*first_glyph);
273 first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
274 first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
279 font->parent->get_glyph_v_advances (count,
280 first_glyph, glyph_stride,
281 first_advance, advance_stride);
282 for (unsigned int i = 0; i < count; i++)
284 *first_advance = font->parent_scale_y_distance (*first_advance);
285 first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
290 hb_font_get_glyph_h_origin_nil (hb_font_t *font HB_UNUSED,
291 void *font_data HB_UNUSED,
292 hb_codepoint_t glyph HB_UNUSED,
295 void *user_data HB_UNUSED)
301 hb_font_get_glyph_h_origin_default (hb_font_t *font,
302 void *font_data HB_UNUSED,
303 hb_codepoint_t glyph,
306 void *user_data HB_UNUSED)
308 hb_bool_t ret = font->parent->get_glyph_h_origin (glyph, x, y);
310 font->parent_scale_position (x, y);
315 hb_font_get_glyph_v_origin_nil (hb_font_t *font HB_UNUSED,
316 void *font_data HB_UNUSED,
317 hb_codepoint_t glyph HB_UNUSED,
320 void *user_data HB_UNUSED)
326 hb_font_get_glyph_v_origin_default (hb_font_t *font,
327 void *font_data HB_UNUSED,
328 hb_codepoint_t glyph,
331 void *user_data HB_UNUSED)
333 hb_bool_t ret = font->parent->get_glyph_v_origin (glyph, x, y);
335 font->parent_scale_position (x, y);
340 hb_font_get_glyph_h_kerning_nil (hb_font_t *font HB_UNUSED,
341 void *font_data HB_UNUSED,
342 hb_codepoint_t left_glyph HB_UNUSED,
343 hb_codepoint_t right_glyph HB_UNUSED,
344 void *user_data HB_UNUSED)
349 hb_font_get_glyph_h_kerning_default (hb_font_t *font,
350 void *font_data HB_UNUSED,
351 hb_codepoint_t left_glyph,
352 hb_codepoint_t right_glyph,
353 void *user_data HB_UNUSED)
355 return font->parent_scale_x_distance (font->parent->get_glyph_h_kerning (left_glyph, right_glyph));
358 #ifndef HB_DISABLE_DEPRECATED
360 hb_font_get_glyph_v_kerning_nil (hb_font_t *font HB_UNUSED,
361 void *font_data HB_UNUSED,
362 hb_codepoint_t top_glyph HB_UNUSED,
363 hb_codepoint_t bottom_glyph HB_UNUSED,
364 void *user_data HB_UNUSED)
369 hb_font_get_glyph_v_kerning_default (hb_font_t *font,
370 void *font_data HB_UNUSED,
371 hb_codepoint_t top_glyph,
372 hb_codepoint_t bottom_glyph,
373 void *user_data HB_UNUSED)
375 return font->parent_scale_y_distance (font->parent->get_glyph_v_kerning (top_glyph, bottom_glyph));
380 hb_font_get_glyph_extents_nil (hb_font_t *font HB_UNUSED,
381 void *font_data HB_UNUSED,
382 hb_codepoint_t glyph HB_UNUSED,
383 hb_glyph_extents_t *extents,
384 void *user_data HB_UNUSED)
386 memset (extents, 0, sizeof (*extents));
390 hb_font_get_glyph_extents_default (hb_font_t *font,
391 void *font_data HB_UNUSED,
392 hb_codepoint_t glyph,
393 hb_glyph_extents_t *extents,
394 void *user_data HB_UNUSED)
396 hb_bool_t ret = font->parent->get_glyph_extents (glyph, extents);
398 font->parent_scale_position (&extents->x_bearing, &extents->y_bearing);
399 font->parent_scale_distance (&extents->width, &extents->height);
405 hb_font_get_glyph_contour_point_nil (hb_font_t *font HB_UNUSED,
406 void *font_data HB_UNUSED,
407 hb_codepoint_t glyph HB_UNUSED,
408 unsigned int point_index HB_UNUSED,
411 void *user_data HB_UNUSED)
417 hb_font_get_glyph_contour_point_default (hb_font_t *font,
418 void *font_data HB_UNUSED,
419 hb_codepoint_t glyph,
420 unsigned int point_index,
423 void *user_data HB_UNUSED)
425 hb_bool_t ret = font->parent->get_glyph_contour_point (glyph, point_index, x, y);
427 font->parent_scale_position (x, y);
432 hb_font_get_glyph_name_nil (hb_font_t *font HB_UNUSED,
433 void *font_data HB_UNUSED,
434 hb_codepoint_t glyph HB_UNUSED,
435 char *name, unsigned int size,
436 void *user_data HB_UNUSED)
438 if (size) *name = '\0';
442 hb_font_get_glyph_name_default (hb_font_t *font,
443 void *font_data HB_UNUSED,
444 hb_codepoint_t glyph,
445 char *name, unsigned int size,
446 void *user_data HB_UNUSED)
448 return font->parent->get_glyph_name (glyph, name, size);
452 hb_font_get_glyph_from_name_nil (hb_font_t *font HB_UNUSED,
453 void *font_data HB_UNUSED,
454 const char *name HB_UNUSED,
455 int len HB_UNUSED, /* -1 means nul-terminated */
456 hb_codepoint_t *glyph,
457 void *user_data HB_UNUSED)
463 hb_font_get_glyph_from_name_default (hb_font_t *font,
464 void *font_data HB_UNUSED,
465 const char *name, int len, /* -1 means nul-terminated */
466 hb_codepoint_t *glyph,
467 void *user_data HB_UNUSED)
469 return font->parent->get_glyph_from_name (name, len, glyph);
472 DEFINE_NULL_INSTANCE (hb_font_funcs_t) =
474 HB_OBJECT_HEADER_STATIC,
477 #define HB_FONT_FUNC_IMPLEMENT(name) nullptr,
478 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
479 #undef HB_FONT_FUNC_IMPLEMENT
482 #define HB_FONT_FUNC_IMPLEMENT(name) nullptr,
483 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
484 #undef HB_FONT_FUNC_IMPLEMENT
488 #define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_nil,
489 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
490 #undef HB_FONT_FUNC_IMPLEMENT
495 static const hb_font_funcs_t _hb_font_funcs_default = {
496 HB_OBJECT_HEADER_STATIC,
499 #define HB_FONT_FUNC_IMPLEMENT(name) nullptr,
500 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
501 #undef HB_FONT_FUNC_IMPLEMENT
504 #define HB_FONT_FUNC_IMPLEMENT(name) nullptr,
505 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
506 #undef HB_FONT_FUNC_IMPLEMENT
510 #define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_default,
511 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
512 #undef HB_FONT_FUNC_IMPLEMENT
519 * hb_font_funcs_create: (Xconstructor)
523 * Return value: (transfer full):
528 hb_font_funcs_create ()
530 hb_font_funcs_t *ffuncs;
532 if (!(ffuncs = hb_object_create<hb_font_funcs_t> ()))
533 return hb_font_funcs_get_empty ();
535 ffuncs->get = _hb_font_funcs_default.get;
541 * hb_font_funcs_get_empty:
545 * Return value: (transfer full):
550 hb_font_funcs_get_empty ()
552 return const_cast<hb_font_funcs_t *> (&_hb_font_funcs_default);
556 * hb_font_funcs_reference: (skip)
557 * @ffuncs: font functions.
566 hb_font_funcs_reference (hb_font_funcs_t *ffuncs)
568 return hb_object_reference (ffuncs);
572 * hb_font_funcs_destroy: (skip)
573 * @ffuncs: font functions.
580 hb_font_funcs_destroy (hb_font_funcs_t *ffuncs)
582 if (!hb_object_destroy (ffuncs)) return;
584 #define HB_FONT_FUNC_IMPLEMENT(name) if (ffuncs->destroy.name) \
585 ffuncs->destroy.name (ffuncs->user_data.name);
586 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
587 #undef HB_FONT_FUNC_IMPLEMENT
593 * hb_font_funcs_set_user_data: (skip)
594 * @ffuncs: font functions.
607 hb_font_funcs_set_user_data (hb_font_funcs_t *ffuncs,
608 hb_user_data_key_t *key,
610 hb_destroy_func_t destroy,
613 return hb_object_set_user_data (ffuncs, key, data, destroy, replace);
617 * hb_font_funcs_get_user_data: (skip)
618 * @ffuncs: font functions.
623 * Return value: (transfer none):
628 hb_font_funcs_get_user_data (hb_font_funcs_t *ffuncs,
629 hb_user_data_key_t *key)
631 return hb_object_get_user_data (ffuncs, key);
636 * hb_font_funcs_make_immutable:
637 * @ffuncs: font functions.
644 hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs)
646 if (hb_object_is_immutable (ffuncs))
649 hb_object_make_immutable (ffuncs);
653 * hb_font_funcs_is_immutable:
654 * @ffuncs: font functions.
663 hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs)
665 return hb_object_is_immutable (ffuncs);
669 #define HB_FONT_FUNC_IMPLEMENT(name) \
672 hb_font_funcs_set_##name##_func (hb_font_funcs_t *ffuncs, \
673 hb_font_get_##name##_func_t func, \
675 hb_destroy_func_t destroy) \
677 if (hb_object_is_immutable (ffuncs)) { \
679 destroy (user_data); \
683 if (ffuncs->destroy.name) \
684 ffuncs->destroy.name (ffuncs->user_data.name); \
687 ffuncs->get.f.name = func; \
688 ffuncs->user_data.name = user_data; \
689 ffuncs->destroy.name = destroy; \
691 ffuncs->get.f.name = hb_font_get_##name##_default; \
692 ffuncs->user_data.name = nullptr; \
693 ffuncs->destroy.name = nullptr; \
697 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
698 #undef HB_FONT_FUNC_IMPLEMENT
701 hb_font_t::has_func_set (unsigned int i)
703 return this->klass->get.array[i] != _hb_font_funcs_default.get.array[i];
707 hb_font_t::has_func (unsigned int i)
709 return has_func_set (i) ||
710 (parent && parent != &_hb_Null_hb_font_t && parent->has_func (i));
716 * hb_font_get_h_extents:
727 hb_font_get_h_extents (hb_font_t *font,
728 hb_font_extents_t *extents)
730 return font->get_font_h_extents (extents);
734 * hb_font_get_v_extents:
745 hb_font_get_v_extents (hb_font_t *font,
746 hb_font_extents_t *extents)
748 return font->get_font_v_extents (extents);
755 * @variation_selector:
765 hb_font_get_glyph (hb_font_t *font,
766 hb_codepoint_t unicode, hb_codepoint_t variation_selector,
767 hb_codepoint_t *glyph)
769 if (unlikely (variation_selector))
770 return font->get_variation_glyph (unicode, variation_selector, glyph);
771 return font->get_nominal_glyph (unicode, glyph);
775 * hb_font_get_nominal_glyph:
787 hb_font_get_nominal_glyph (hb_font_t *font,
788 hb_codepoint_t unicode,
789 hb_codepoint_t *glyph)
791 return font->get_nominal_glyph (unicode, glyph);
795 * hb_font_get_nominal_glyphs:
805 hb_font_get_nominal_glyphs (hb_font_t *font,
807 const hb_codepoint_t *first_unicode,
808 unsigned int unicode_stride,
809 hb_codepoint_t *first_glyph,
810 unsigned int glyph_stride)
812 return font->get_nominal_glyphs (count,
813 first_unicode, unicode_stride,
814 first_glyph, glyph_stride);
818 * hb_font_get_variation_glyph:
821 * @variation_selector:
831 hb_font_get_variation_glyph (hb_font_t *font,
832 hb_codepoint_t unicode, hb_codepoint_t variation_selector,
833 hb_codepoint_t *glyph)
835 return font->get_variation_glyph (unicode, variation_selector, glyph);
839 * hb_font_get_glyph_h_advance:
850 hb_font_get_glyph_h_advance (hb_font_t *font,
851 hb_codepoint_t glyph)
853 return font->get_glyph_h_advance (glyph);
857 * hb_font_get_glyph_v_advance:
868 hb_font_get_glyph_v_advance (hb_font_t *font,
869 hb_codepoint_t glyph)
871 return font->get_glyph_v_advance (glyph);
875 * hb_font_get_glyph_h_advances:
883 hb_font_get_glyph_h_advances (hb_font_t* font,
885 const hb_codepoint_t *first_glyph,
886 unsigned glyph_stride,
887 hb_position_t *first_advance,
888 unsigned advance_stride)
890 font->get_glyph_h_advances (count, first_glyph, glyph_stride, first_advance, advance_stride);
893 * hb_font_get_glyph_v_advances:
901 hb_font_get_glyph_v_advances (hb_font_t* font,
903 const hb_codepoint_t *first_glyph,
904 unsigned glyph_stride,
905 hb_position_t *first_advance,
906 unsigned advance_stride)
908 font->get_glyph_v_advances (count, first_glyph, glyph_stride, first_advance, advance_stride);
912 * hb_font_get_glyph_h_origin:
925 hb_font_get_glyph_h_origin (hb_font_t *font,
926 hb_codepoint_t glyph,
927 hb_position_t *x, hb_position_t *y)
929 return font->get_glyph_h_origin (glyph, x, y);
933 * hb_font_get_glyph_v_origin:
946 hb_font_get_glyph_v_origin (hb_font_t *font,
947 hb_codepoint_t glyph,
948 hb_position_t *x, hb_position_t *y)
950 return font->get_glyph_v_origin (glyph, x, y);
954 * hb_font_get_glyph_h_kerning:
966 hb_font_get_glyph_h_kerning (hb_font_t *font,
967 hb_codepoint_t left_glyph, hb_codepoint_t right_glyph)
969 return font->get_glyph_h_kerning (left_glyph, right_glyph);
972 #ifndef HB_DISABLE_DEPRECATED
974 * hb_font_get_glyph_v_kerning:
987 hb_font_get_glyph_v_kerning (hb_font_t *font,
988 hb_codepoint_t top_glyph, hb_codepoint_t bottom_glyph)
990 return font->get_glyph_v_kerning (top_glyph, bottom_glyph);
995 * hb_font_get_glyph_extents:
1007 hb_font_get_glyph_extents (hb_font_t *font,
1008 hb_codepoint_t glyph,
1009 hb_glyph_extents_t *extents)
1011 return font->get_glyph_extents (glyph, extents);
1015 * hb_font_get_glyph_contour_point:
1029 hb_font_get_glyph_contour_point (hb_font_t *font,
1030 hb_codepoint_t glyph, unsigned int point_index,
1031 hb_position_t *x, hb_position_t *y)
1033 return font->get_glyph_contour_point (glyph, point_index, x, y);
1037 * hb_font_get_glyph_name:
1040 * @name: (array length=size):
1050 hb_font_get_glyph_name (hb_font_t *font,
1051 hb_codepoint_t glyph,
1052 char *name, unsigned int size)
1054 return font->get_glyph_name (glyph, name, size);
1058 * hb_font_get_glyph_from_name:
1060 * @name: (array length=len):
1071 hb_font_get_glyph_from_name (hb_font_t *font,
1072 const char *name, int len, /* -1 means nul-terminated */
1073 hb_codepoint_t *glyph)
1075 return font->get_glyph_from_name (name, len, glyph);
1079 /* A bit higher-level, and with fallback */
1082 * hb_font_get_extents_for_direction:
1092 hb_font_get_extents_for_direction (hb_font_t *font,
1093 hb_direction_t direction,
1094 hb_font_extents_t *extents)
1096 return font->get_extents_for_direction (direction, extents);
1099 * hb_font_get_glyph_advance_for_direction:
1111 hb_font_get_glyph_advance_for_direction (hb_font_t *font,
1112 hb_codepoint_t glyph,
1113 hb_direction_t direction,
1114 hb_position_t *x, hb_position_t *y)
1116 return font->get_glyph_advance_for_direction (glyph, direction, x, y);
1119 * hb_font_get_glyph_advances_for_direction:
1128 hb_font_get_glyph_advances_for_direction (hb_font_t* font,
1129 hb_direction_t direction,
1131 const hb_codepoint_t *first_glyph,
1132 unsigned glyph_stride,
1133 hb_position_t *first_advance,
1134 unsigned advance_stride)
1136 font->get_glyph_advances_for_direction (direction, count, first_glyph, glyph_stride, first_advance, advance_stride);
1140 * hb_font_get_glyph_origin_for_direction:
1152 hb_font_get_glyph_origin_for_direction (hb_font_t *font,
1153 hb_codepoint_t glyph,
1154 hb_direction_t direction,
1155 hb_position_t *x, hb_position_t *y)
1157 return font->get_glyph_origin_for_direction (glyph, direction, x, y);
1161 * hb_font_add_glyph_origin_for_direction:
1173 hb_font_add_glyph_origin_for_direction (hb_font_t *font,
1174 hb_codepoint_t glyph,
1175 hb_direction_t direction,
1176 hb_position_t *x, hb_position_t *y)
1178 return font->add_glyph_origin_for_direction (glyph, direction, x, y);
1182 * hb_font_subtract_glyph_origin_for_direction:
1194 hb_font_subtract_glyph_origin_for_direction (hb_font_t *font,
1195 hb_codepoint_t glyph,
1196 hb_direction_t direction,
1197 hb_position_t *x, hb_position_t *y)
1199 return font->subtract_glyph_origin_for_direction (glyph, direction, x, y);
1203 * hb_font_get_glyph_kerning_for_direction:
1216 hb_font_get_glyph_kerning_for_direction (hb_font_t *font,
1217 hb_codepoint_t first_glyph, hb_codepoint_t second_glyph,
1218 hb_direction_t direction,
1219 hb_position_t *x, hb_position_t *y)
1221 return font->get_glyph_kerning_for_direction (first_glyph, second_glyph, direction, x, y);
1225 * hb_font_get_glyph_extents_for_origin:
1238 hb_font_get_glyph_extents_for_origin (hb_font_t *font,
1239 hb_codepoint_t glyph,
1240 hb_direction_t direction,
1241 hb_glyph_extents_t *extents)
1243 return font->get_glyph_extents_for_origin (glyph, direction, extents);
1247 * hb_font_get_glyph_contour_point_for_origin:
1262 hb_font_get_glyph_contour_point_for_origin (hb_font_t *font,
1263 hb_codepoint_t glyph, unsigned int point_index,
1264 hb_direction_t direction,
1265 hb_position_t *x, hb_position_t *y)
1267 return font->get_glyph_contour_point_for_origin (glyph, point_index, direction, x, y);
1270 /* Generates gidDDD if glyph has no name. */
1272 * hb_font_glyph_to_string:
1275 * @s: (array length=size):
1283 hb_font_glyph_to_string (hb_font_t *font,
1284 hb_codepoint_t glyph,
1285 char *s, unsigned int size)
1287 font->glyph_to_string (glyph, s, size);
1290 /* Parses gidDDD and uniUUUU strings automatically. */
1292 * hb_font_glyph_from_string:
1294 * @s: (array length=len) (element-type uint8_t):
1305 hb_font_glyph_from_string (hb_font_t *font,
1306 const char *s, int len, /* -1 means nul-terminated */
1307 hb_codepoint_t *glyph)
1309 return font->glyph_from_string (s, len, glyph);
1317 DEFINE_NULL_INSTANCE (hb_font_t) =
1319 HB_OBJECT_HEADER_STATIC,
1321 nullptr, /* parent */
1322 const_cast<hb_face_t *> (&_hb_Null_hb_face_t),
1334 nullptr, /* coords */
1336 const_cast<hb_font_funcs_t *> (&_hb_Null_hb_font_funcs_t),
1338 /* Zero for the rest is fine. */
1343 _hb_font_create (hb_face_t *face)
1347 if (unlikely (!face))
1348 face = hb_face_get_empty ();
1349 if (!(font = hb_object_create<hb_font_t> ()))
1350 return hb_font_get_empty ();
1352 hb_face_make_immutable (face);
1353 font->parent = hb_font_get_empty ();
1354 font->face = hb_face_reference (face);
1355 font->klass = hb_font_funcs_get_empty ();
1356 font->data.init0 (font);
1357 font->x_scale = font->y_scale = hb_face_get_upem (face);
1358 font->x_mult = font->y_mult = 1 << 16;
1364 * hb_font_create: (Xconstructor)
1369 * Return value: (transfer full):
1374 hb_font_create (hb_face_t *face)
1376 hb_font_t *font = _hb_font_create (face);
1378 #ifndef HB_NO_OT_FONT
1379 /* Install our in-house, very lightweight, funcs. */
1380 hb_ot_font_set_funcs (font);
1387 * hb_font_create_sub_font:
1388 * @parent: parent font.
1392 * Return value: (transfer full):
1397 hb_font_create_sub_font (hb_font_t *parent)
1399 if (unlikely (!parent))
1400 parent = hb_font_get_empty ();
1402 hb_font_t *font = _hb_font_create (parent->face);
1404 if (unlikely (hb_object_is_immutable (font)))
1407 font->parent = hb_font_reference (parent);
1409 font->x_scale = parent->x_scale;
1410 font->y_scale = parent->y_scale;
1411 font->mults_changed ();
1412 font->x_ppem = parent->x_ppem;
1413 font->y_ppem = parent->y_ppem;
1414 font->ptem = parent->ptem;
1416 font->num_coords = parent->num_coords;
1417 if (font->num_coords)
1419 unsigned int size = parent->num_coords * sizeof (parent->coords[0]);
1420 font->coords = (int *) malloc (size);
1421 if (unlikely (!font->coords))
1422 font->num_coords = 0;
1424 memcpy (font->coords, parent->coords, size);
1431 * hb_font_get_empty:
1435 * Return value: (transfer full)
1440 hb_font_get_empty ()
1442 return const_cast<hb_font_t *> (&Null(hb_font_t));
1446 * hb_font_reference: (skip)
1451 * Return value: (transfer full):
1456 hb_font_reference (hb_font_t *font)
1458 return hb_object_reference (font);
1462 * hb_font_destroy: (skip)
1470 hb_font_destroy (hb_font_t *font)
1472 if (!hb_object_destroy (font)) return;
1477 font->destroy (font->user_data);
1479 hb_font_destroy (font->parent);
1480 hb_face_destroy (font->face);
1481 hb_font_funcs_destroy (font->klass);
1483 free (font->coords);
1489 * hb_font_set_user_data: (skip)
1503 hb_font_set_user_data (hb_font_t *font,
1504 hb_user_data_key_t *key,
1506 hb_destroy_func_t destroy,
1509 return hb_object_set_user_data (font, key, data, destroy, replace);
1513 * hb_font_get_user_data: (skip)
1519 * Return value: (transfer none):
1524 hb_font_get_user_data (hb_font_t *font,
1525 hb_user_data_key_t *key)
1527 return hb_object_get_user_data (font, key);
1531 * hb_font_make_immutable:
1539 hb_font_make_immutable (hb_font_t *font)
1541 if (hb_object_is_immutable (font))
1545 hb_font_make_immutable (font->parent);
1547 hb_object_make_immutable (font);
1551 * hb_font_is_immutable:
1561 hb_font_is_immutable (hb_font_t *font)
1563 return hb_object_is_immutable (font);
1567 * hb_font_set_parent:
1569 * @parent: new parent.
1571 * Sets parent font of @font.
1576 hb_font_set_parent (hb_font_t *font,
1579 if (hb_object_is_immutable (font))
1583 parent = hb_font_get_empty ();
1585 hb_font_t *old = font->parent;
1587 font->parent = hb_font_reference (parent);
1589 hb_font_destroy (old);
1593 * hb_font_get_parent:
1598 * Return value: (transfer none):
1603 hb_font_get_parent (hb_font_t *font)
1605 return font->parent;
1613 * Sets font-face of @font.
1618 hb_font_set_face (hb_font_t *font,
1621 if (hb_object_is_immutable (font))
1624 if (unlikely (!face))
1625 face = hb_face_get_empty ();
1627 hb_face_t *old = font->face;
1629 hb_face_make_immutable (face);
1630 font->face = hb_face_reference (face);
1631 font->mults_changed ();
1633 hb_face_destroy (old);
1642 * Return value: (transfer none):
1647 hb_font_get_face (hb_font_t *font)
1654 * hb_font_set_funcs:
1656 * @klass: (closure font_data) (destroy destroy) (scope notified):
1665 hb_font_set_funcs (hb_font_t *font,
1666 hb_font_funcs_t *klass,
1668 hb_destroy_func_t destroy)
1670 if (hb_object_is_immutable (font))
1673 destroy (font_data);
1678 font->destroy (font->user_data);
1681 klass = hb_font_funcs_get_empty ();
1683 hb_font_funcs_reference (klass);
1684 hb_font_funcs_destroy (font->klass);
1685 font->klass = klass;
1686 font->user_data = font_data;
1687 font->destroy = destroy;
1691 * hb_font_set_funcs_data:
1693 * @font_data: (destroy destroy) (scope notified):
1701 hb_font_set_funcs_data (hb_font_t *font,
1703 hb_destroy_func_t destroy)
1705 /* Destroy user_data? */
1706 if (hb_object_is_immutable (font))
1709 destroy (font_data);
1714 font->destroy (font->user_data);
1716 font->user_data = font_data;
1717 font->destroy = destroy;
1722 * hb_font_set_scale:
1732 hb_font_set_scale (hb_font_t *font,
1736 if (hb_object_is_immutable (font))
1739 font->x_scale = x_scale;
1740 font->y_scale = y_scale;
1741 font->mults_changed ();
1745 * hb_font_get_scale:
1755 hb_font_get_scale (hb_font_t *font,
1759 if (x_scale) *x_scale = font->x_scale;
1760 if (y_scale) *y_scale = font->y_scale;
1774 hb_font_set_ppem (hb_font_t *font,
1775 unsigned int x_ppem,
1776 unsigned int y_ppem)
1778 if (hb_object_is_immutable (font))
1781 font->x_ppem = x_ppem;
1782 font->y_ppem = y_ppem;
1796 hb_font_get_ppem (hb_font_t *font,
1797 unsigned int *x_ppem,
1798 unsigned int *y_ppem)
1800 if (x_ppem) *x_ppem = font->x_ppem;
1801 if (y_ppem) *y_ppem = font->y_ppem;
1807 * @ptem: font size in points.
1809 * Sets "point size" of the font. Set to 0 to unset.
1811 * There are 72 points in an inch.
1816 hb_font_set_ptem (hb_font_t *font, float ptem)
1818 if (hb_object_is_immutable (font))
1828 * Gets the "point size" of the font. A value of 0 means unset.
1830 * Return value: Point size.
1835 hb_font_get_ptem (hb_font_t *font)
1846 _hb_font_adopt_var_coords_normalized (hb_font_t *font,
1847 int *coords, /* 2.14 normalized */
1848 unsigned int coords_length)
1850 free (font->coords);
1852 font->coords = coords;
1853 font->num_coords = coords_length;
1857 * hb_font_set_variations:
1862 hb_font_set_variations (hb_font_t *font,
1863 const hb_variation_t *variations,
1864 unsigned int variations_length)
1866 if (hb_object_is_immutable (font))
1869 if (!variations_length)
1871 hb_font_set_var_coords_normalized (font, nullptr, 0);
1875 unsigned int coords_length = hb_ot_var_get_axis_count (font->face);
1877 int *normalized = coords_length ? (int *) calloc (coords_length, sizeof (int)) : nullptr;
1878 if (unlikely (coords_length && !normalized))
1881 hb_ot_var_normalize_variations (font->face,
1882 variations, variations_length,
1883 normalized, coords_length);
1884 _hb_font_adopt_var_coords_normalized (font, normalized, coords_length);
1888 * hb_font_set_var_coords_design:
1893 hb_font_set_var_coords_design (hb_font_t *font,
1894 const float *coords,
1895 unsigned int coords_length)
1897 if (hb_object_is_immutable (font))
1900 int *normalized = coords_length ? (int *) calloc (coords_length, sizeof (int)) : nullptr;
1901 if (unlikely (coords_length && !normalized))
1904 hb_ot_var_normalize_coords (font->face, coords_length, coords, normalized);
1905 _hb_font_adopt_var_coords_normalized (font, normalized, coords_length);
1909 * hb_font_set_var_named_instance:
1911 * @instance_index: named instance index.
1913 * Sets design coords of a font from a named instance index.
1918 hb_font_set_var_named_instance (hb_font_t *font,
1919 unsigned instance_index)
1921 if (hb_object_is_immutable (font))
1924 unsigned int coords_length = hb_ot_var_named_instance_get_design_coords (font->face, instance_index, nullptr, nullptr);
1926 float *coords = coords_length ? (float *) calloc (coords_length, sizeof (float)) : nullptr;
1927 if (unlikely (coords_length && !coords))
1930 hb_ot_var_named_instance_get_design_coords (font->face, instance_index, &coords_length, coords);
1931 hb_font_set_var_coords_design (font, coords, coords_length);
1936 * hb_font_set_var_coords_normalized:
1941 hb_font_set_var_coords_normalized (hb_font_t *font,
1942 const int *coords, /* 2.14 normalized */
1943 unsigned int coords_length)
1945 if (hb_object_is_immutable (font))
1948 int *copy = coords_length ? (int *) calloc (coords_length, sizeof (coords[0])) : nullptr;
1949 if (unlikely (coords_length && !copy))
1953 memcpy (copy, coords, coords_length * sizeof (coords[0]));
1955 _hb_font_adopt_var_coords_normalized (font, copy, coords_length);
1959 * hb_font_get_var_coords_normalized:
1961 * Return value is valid as long as variation coordinates of the font
1967 hb_font_get_var_coords_normalized (hb_font_t *font,
1968 unsigned int *length)
1971 *length = font->num_coords;
1973 return font->coords;
1977 #ifndef HB_DISABLE_DEPRECATED
1979 * Deprecated get_glyph_func():
1982 struct hb_trampoline_closure_t
1985 hb_destroy_func_t destroy;
1986 unsigned int ref_count;
1989 template <typename FuncType>
1990 struct hb_trampoline_t
1992 hb_trampoline_closure_t closure; /* Must be first. */
1996 template <typename FuncType>
1997 static hb_trampoline_t<FuncType> *
1998 trampoline_create (FuncType func,
2000 hb_destroy_func_t destroy)
2002 typedef hb_trampoline_t<FuncType> trampoline_t;
2004 trampoline_t *trampoline = (trampoline_t *) calloc (1, sizeof (trampoline_t));
2006 if (unlikely (!trampoline))
2009 trampoline->closure.user_data = user_data;
2010 trampoline->closure.destroy = destroy;
2011 trampoline->closure.ref_count = 1;
2012 trampoline->func = func;
2018 trampoline_reference (hb_trampoline_closure_t *closure)
2020 closure->ref_count++;
2024 trampoline_destroy (void *user_data)
2026 hb_trampoline_closure_t *closure = (hb_trampoline_closure_t *) user_data;
2028 if (--closure->ref_count)
2031 if (closure->destroy)
2032 closure->destroy (closure->user_data);
2036 typedef hb_trampoline_t<hb_font_get_glyph_func_t> hb_font_get_glyph_trampoline_t;
2039 hb_font_get_nominal_glyph_trampoline (hb_font_t *font,
2041 hb_codepoint_t unicode,
2042 hb_codepoint_t *glyph,
2045 hb_font_get_glyph_trampoline_t *trampoline = (hb_font_get_glyph_trampoline_t *) user_data;
2046 return trampoline->func (font, font_data, unicode, 0, glyph, trampoline->closure.user_data);
2050 hb_font_get_variation_glyph_trampoline (hb_font_t *font,
2052 hb_codepoint_t unicode,
2053 hb_codepoint_t variation_selector,
2054 hb_codepoint_t *glyph,
2057 hb_font_get_glyph_trampoline_t *trampoline = (hb_font_get_glyph_trampoline_t *) user_data;
2058 return trampoline->func (font, font_data, unicode, variation_selector, glyph, trampoline->closure.user_data);
2062 * hb_font_funcs_set_glyph_func:
2063 * @ffuncs: font functions.
2064 * @func: (closure user_data) (destroy destroy) (scope notified): callback function.
2065 * @user_data: data to pass to @func.
2066 * @destroy: function to call when @user_data is not needed anymore.
2068 * Deprecated. Use hb_font_funcs_set_nominal_glyph_func() and
2069 * hb_font_funcs_set_variation_glyph_func() instead.
2075 hb_font_funcs_set_glyph_func (hb_font_funcs_t *ffuncs,
2076 hb_font_get_glyph_func_t func,
2077 void *user_data, hb_destroy_func_t destroy)
2079 hb_font_get_glyph_trampoline_t *trampoline;
2081 trampoline = trampoline_create (func, user_data, destroy);
2082 if (unlikely (!trampoline))
2085 destroy (user_data);
2089 hb_font_funcs_set_nominal_glyph_func (ffuncs,
2090 hb_font_get_nominal_glyph_trampoline,
2092 trampoline_destroy);
2094 trampoline_reference (&trampoline->closure);
2095 hb_font_funcs_set_variation_glyph_func (ffuncs,
2096 hb_font_get_variation_glyph_trampoline,
2098 trampoline_destroy);