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"
36 #include "hb-ot-var-avar-table.hh"
37 #include "hb-ot-var-fvar-table.hh"
43 * @short_description: Font objects
46 * Functions for working with font objects.
48 * A font object represents a font face at a specific size and with
49 * certain other parameters (pixels-per-em, points-per-em, variation
50 * settings) specified. Font objects are created from font face
51 * objects, and are used as input to hb_shape(), among other things.
53 * Client programs can optionally pass in their own functions that
54 * implement the basic, lower-level queries of font objects. This set
55 * of font functions is defined by the virtual methods in
58 * HarfBuzz provides a built-in set of lightweight default
59 * functions for each method in #hb_font_funcs_t.
68 hb_font_get_font_h_extents_nil (hb_font_t *font HB_UNUSED,
69 void *font_data HB_UNUSED,
70 hb_font_extents_t *extents,
71 void *user_data HB_UNUSED)
73 memset (extents, 0, sizeof (*extents));
78 hb_font_get_font_h_extents_default (hb_font_t *font,
79 void *font_data HB_UNUSED,
80 hb_font_extents_t *extents,
81 void *user_data HB_UNUSED)
83 hb_bool_t ret = font->parent->get_font_h_extents (extents);
85 extents->ascender = font->parent_scale_y_distance (extents->ascender);
86 extents->descender = font->parent_scale_y_distance (extents->descender);
87 extents->line_gap = font->parent_scale_y_distance (extents->line_gap);
93 hb_font_get_font_v_extents_nil (hb_font_t *font HB_UNUSED,
94 void *font_data HB_UNUSED,
95 hb_font_extents_t *extents,
96 void *user_data HB_UNUSED)
98 memset (extents, 0, sizeof (*extents));
103 hb_font_get_font_v_extents_default (hb_font_t *font,
104 void *font_data HB_UNUSED,
105 hb_font_extents_t *extents,
106 void *user_data HB_UNUSED)
108 hb_bool_t ret = font->parent->get_font_v_extents (extents);
110 extents->ascender = font->parent_scale_x_distance (extents->ascender);
111 extents->descender = font->parent_scale_x_distance (extents->descender);
112 extents->line_gap = font->parent_scale_x_distance (extents->line_gap);
118 hb_font_get_nominal_glyph_nil (hb_font_t *font HB_UNUSED,
119 void *font_data HB_UNUSED,
120 hb_codepoint_t unicode HB_UNUSED,
121 hb_codepoint_t *glyph,
122 void *user_data HB_UNUSED)
129 hb_font_get_nominal_glyph_default (hb_font_t *font,
130 void *font_data HB_UNUSED,
131 hb_codepoint_t unicode,
132 hb_codepoint_t *glyph,
133 void *user_data HB_UNUSED)
135 if (font->has_nominal_glyphs_func_set ())
137 return font->get_nominal_glyphs (1, &unicode, 0, glyph, 0);
139 return font->parent->get_nominal_glyph (unicode, glyph);
142 #define hb_font_get_nominal_glyphs_nil hb_font_get_nominal_glyphs_default
145 hb_font_get_nominal_glyphs_default (hb_font_t *font,
146 void *font_data HB_UNUSED,
148 const hb_codepoint_t *first_unicode,
149 unsigned int unicode_stride,
150 hb_codepoint_t *first_glyph,
151 unsigned int glyph_stride,
152 void *user_data HB_UNUSED)
154 if (font->has_nominal_glyph_func_set ())
156 for (unsigned int i = 0; i < count; i++)
158 if (!font->get_nominal_glyph (*first_unicode, first_glyph))
161 first_unicode = &StructAtOffsetUnaligned<hb_codepoint_t> (first_unicode, unicode_stride);
162 first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
167 return font->parent->get_nominal_glyphs (count,
168 first_unicode, unicode_stride,
169 first_glyph, glyph_stride);
173 hb_font_get_variation_glyph_nil (hb_font_t *font HB_UNUSED,
174 void *font_data HB_UNUSED,
175 hb_codepoint_t unicode HB_UNUSED,
176 hb_codepoint_t variation_selector HB_UNUSED,
177 hb_codepoint_t *glyph,
178 void *user_data HB_UNUSED)
185 hb_font_get_variation_glyph_default (hb_font_t *font,
186 void *font_data HB_UNUSED,
187 hb_codepoint_t unicode,
188 hb_codepoint_t variation_selector,
189 hb_codepoint_t *glyph,
190 void *user_data HB_UNUSED)
192 return font->parent->get_variation_glyph (unicode, variation_selector, glyph);
197 hb_font_get_glyph_h_advance_nil (hb_font_t *font,
198 void *font_data HB_UNUSED,
199 hb_codepoint_t glyph HB_UNUSED,
200 void *user_data HB_UNUSED)
202 return font->x_scale;
206 hb_font_get_glyph_h_advance_default (hb_font_t *font,
207 void *font_data HB_UNUSED,
208 hb_codepoint_t glyph,
209 void *user_data HB_UNUSED)
211 if (font->has_glyph_h_advances_func_set ())
214 font->get_glyph_h_advances (1, &glyph, 0, &ret, 0);
217 return font->parent_scale_x_distance (font->parent->get_glyph_h_advance (glyph));
221 hb_font_get_glyph_v_advance_nil (hb_font_t *font,
222 void *font_data HB_UNUSED,
223 hb_codepoint_t glyph HB_UNUSED,
224 void *user_data HB_UNUSED)
226 /* TODO use font_extents.ascender+descender */
227 return font->y_scale;
231 hb_font_get_glyph_v_advance_default (hb_font_t *font,
232 void *font_data HB_UNUSED,
233 hb_codepoint_t glyph,
234 void *user_data HB_UNUSED)
236 if (font->has_glyph_v_advances_func_set ())
239 font->get_glyph_v_advances (1, &glyph, 0, &ret, 0);
242 return font->parent_scale_y_distance (font->parent->get_glyph_v_advance (glyph));
245 #define hb_font_get_glyph_h_advances_nil hb_font_get_glyph_h_advances_default
248 hb_font_get_glyph_h_advances_default (hb_font_t* font,
249 void* font_data HB_UNUSED,
251 const hb_codepoint_t *first_glyph,
252 unsigned int glyph_stride,
253 hb_position_t *first_advance,
254 unsigned int advance_stride,
255 void *user_data HB_UNUSED)
257 if (font->has_glyph_h_advance_func_set ())
259 for (unsigned int i = 0; i < count; i++)
261 *first_advance = font->get_glyph_h_advance (*first_glyph);
262 first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
263 first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
268 font->parent->get_glyph_h_advances (count,
269 first_glyph, glyph_stride,
270 first_advance, advance_stride);
271 for (unsigned int i = 0; i < count; i++)
273 *first_advance = font->parent_scale_x_distance (*first_advance);
274 first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
278 #define hb_font_get_glyph_v_advances_nil hb_font_get_glyph_v_advances_default
280 hb_font_get_glyph_v_advances_default (hb_font_t* font,
281 void* font_data HB_UNUSED,
283 const hb_codepoint_t *first_glyph,
284 unsigned int glyph_stride,
285 hb_position_t *first_advance,
286 unsigned int advance_stride,
287 void *user_data HB_UNUSED)
289 if (font->has_glyph_v_advance_func_set ())
291 for (unsigned int i = 0; i < count; i++)
293 *first_advance = font->get_glyph_v_advance (*first_glyph);
294 first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
295 first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
300 font->parent->get_glyph_v_advances (count,
301 first_glyph, glyph_stride,
302 first_advance, advance_stride);
303 for (unsigned int i = 0; i < count; i++)
305 *first_advance = font->parent_scale_y_distance (*first_advance);
306 first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
311 hb_font_get_glyph_h_origin_nil (hb_font_t *font HB_UNUSED,
312 void *font_data HB_UNUSED,
313 hb_codepoint_t glyph HB_UNUSED,
316 void *user_data HB_UNUSED)
323 hb_font_get_glyph_h_origin_default (hb_font_t *font,
324 void *font_data HB_UNUSED,
325 hb_codepoint_t glyph,
328 void *user_data HB_UNUSED)
330 hb_bool_t ret = font->parent->get_glyph_h_origin (glyph, x, y);
332 font->parent_scale_position (x, y);
337 hb_font_get_glyph_v_origin_nil (hb_font_t *font HB_UNUSED,
338 void *font_data HB_UNUSED,
339 hb_codepoint_t glyph HB_UNUSED,
342 void *user_data HB_UNUSED)
349 hb_font_get_glyph_v_origin_default (hb_font_t *font,
350 void *font_data HB_UNUSED,
351 hb_codepoint_t glyph,
354 void *user_data HB_UNUSED)
356 hb_bool_t ret = font->parent->get_glyph_v_origin (glyph, x, y);
358 font->parent_scale_position (x, y);
363 hb_font_get_glyph_h_kerning_nil (hb_font_t *font HB_UNUSED,
364 void *font_data HB_UNUSED,
365 hb_codepoint_t left_glyph HB_UNUSED,
366 hb_codepoint_t right_glyph HB_UNUSED,
367 void *user_data HB_UNUSED)
373 hb_font_get_glyph_h_kerning_default (hb_font_t *font,
374 void *font_data HB_UNUSED,
375 hb_codepoint_t left_glyph,
376 hb_codepoint_t right_glyph,
377 void *user_data HB_UNUSED)
379 return font->parent_scale_x_distance (font->parent->get_glyph_h_kerning (left_glyph, right_glyph));
382 #ifndef HB_DISABLE_DEPRECATED
384 hb_font_get_glyph_v_kerning_nil (hb_font_t *font HB_UNUSED,
385 void *font_data HB_UNUSED,
386 hb_codepoint_t top_glyph HB_UNUSED,
387 hb_codepoint_t bottom_glyph HB_UNUSED,
388 void *user_data HB_UNUSED)
394 hb_font_get_glyph_v_kerning_default (hb_font_t *font,
395 void *font_data HB_UNUSED,
396 hb_codepoint_t top_glyph,
397 hb_codepoint_t bottom_glyph,
398 void *user_data HB_UNUSED)
400 return font->parent_scale_y_distance (font->parent->get_glyph_v_kerning (top_glyph, bottom_glyph));
405 hb_font_get_glyph_extents_nil (hb_font_t *font HB_UNUSED,
406 void *font_data HB_UNUSED,
407 hb_codepoint_t glyph HB_UNUSED,
408 hb_glyph_extents_t *extents,
409 void *user_data HB_UNUSED)
411 memset (extents, 0, sizeof (*extents));
416 hb_font_get_glyph_extents_default (hb_font_t *font,
417 void *font_data HB_UNUSED,
418 hb_codepoint_t glyph,
419 hb_glyph_extents_t *extents,
420 void *user_data HB_UNUSED)
422 hb_bool_t ret = font->parent->get_glyph_extents (glyph, extents);
424 font->parent_scale_position (&extents->x_bearing, &extents->y_bearing);
425 font->parent_scale_distance (&extents->width, &extents->height);
431 hb_font_get_glyph_contour_point_nil (hb_font_t *font HB_UNUSED,
432 void *font_data HB_UNUSED,
433 hb_codepoint_t glyph HB_UNUSED,
434 unsigned int point_index HB_UNUSED,
437 void *user_data HB_UNUSED)
444 hb_font_get_glyph_contour_point_default (hb_font_t *font,
445 void *font_data HB_UNUSED,
446 hb_codepoint_t glyph,
447 unsigned int point_index,
450 void *user_data HB_UNUSED)
452 hb_bool_t ret = font->parent->get_glyph_contour_point (glyph, point_index, x, y);
454 font->parent_scale_position (x, y);
459 hb_font_get_glyph_name_nil (hb_font_t *font HB_UNUSED,
460 void *font_data HB_UNUSED,
461 hb_codepoint_t glyph HB_UNUSED,
464 void *user_data HB_UNUSED)
466 if (size) *name = '\0';
471 hb_font_get_glyph_name_default (hb_font_t *font,
472 void *font_data HB_UNUSED,
473 hb_codepoint_t glyph,
476 void *user_data HB_UNUSED)
478 return font->parent->get_glyph_name (glyph, name, size);
482 hb_font_get_glyph_from_name_nil (hb_font_t *font HB_UNUSED,
483 void *font_data HB_UNUSED,
484 const char *name HB_UNUSED,
485 int len HB_UNUSED, /* -1 means nul-terminated */
486 hb_codepoint_t *glyph,
487 void *user_data HB_UNUSED)
494 hb_font_get_glyph_from_name_default (hb_font_t *font,
495 void *font_data HB_UNUSED,
497 int len, /* -1 means nul-terminated */
498 hb_codepoint_t *glyph,
499 void *user_data HB_UNUSED)
501 return font->parent->get_glyph_from_name (name, len, glyph);
504 DEFINE_NULL_INSTANCE (hb_font_funcs_t) =
506 HB_OBJECT_HEADER_STATIC,
509 #define HB_FONT_FUNC_IMPLEMENT(name) nullptr,
510 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
511 #undef HB_FONT_FUNC_IMPLEMENT
514 #define HB_FONT_FUNC_IMPLEMENT(name) nullptr,
515 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
516 #undef HB_FONT_FUNC_IMPLEMENT
520 #define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_nil,
521 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
522 #undef HB_FONT_FUNC_IMPLEMENT
527 static const hb_font_funcs_t _hb_font_funcs_default = {
528 HB_OBJECT_HEADER_STATIC,
531 #define HB_FONT_FUNC_IMPLEMENT(name) nullptr,
532 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
533 #undef HB_FONT_FUNC_IMPLEMENT
536 #define HB_FONT_FUNC_IMPLEMENT(name) nullptr,
537 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
538 #undef HB_FONT_FUNC_IMPLEMENT
542 #define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_default,
543 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
544 #undef HB_FONT_FUNC_IMPLEMENT
551 * hb_font_funcs_create: (Xconstructor)
553 * Creates a new #hb_font_funcs_t structure of font functions.
555 * Return value: (transfer full): The font-functions structure
560 hb_font_funcs_create ()
562 hb_font_funcs_t *ffuncs;
564 if (!(ffuncs = hb_object_create<hb_font_funcs_t> ()))
565 return hb_font_funcs_get_empty ();
567 ffuncs->get = _hb_font_funcs_default.get;
573 * hb_font_funcs_get_empty:
575 * Fetches an empty font-functions structure.
577 * Return value: (transfer full): The font-functions structure
582 hb_font_funcs_get_empty ()
584 return const_cast<hb_font_funcs_t *> (&_hb_font_funcs_default);
588 * hb_font_funcs_reference: (skip)
589 * @ffuncs: The font-functions structure
591 * Increases the reference count on a font-functions structure.
593 * Return value: The font-functions structure
598 hb_font_funcs_reference (hb_font_funcs_t *ffuncs)
600 return hb_object_reference (ffuncs);
604 * hb_font_funcs_destroy: (skip)
605 * @ffuncs: The font-functions structure
607 * Decreases the reference count on a font-functions structure. When
608 * the reference count reaches zero, the font-functions structure is
609 * destroyed, freeing all memory.
614 hb_font_funcs_destroy (hb_font_funcs_t *ffuncs)
616 if (!hb_object_destroy (ffuncs)) return;
618 #define HB_FONT_FUNC_IMPLEMENT(name) if (ffuncs->destroy.name) \
619 ffuncs->destroy.name (ffuncs->user_data.name);
620 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
621 #undef HB_FONT_FUNC_IMPLEMENT
627 * hb_font_funcs_set_user_data: (skip)
628 * @ffuncs: The font-functions structure
629 * @key: The user-data key to set
630 * @data: A pointer to the user data set
631 * @destroy: (nullable): A callback to call when @data is not needed anymore
632 * @replace: Whether to replace an existing data with the same key
634 * Attaches a user-data key/data pair to the specified font-functions structure.
636 * Return value: %true if success, %false otherwise
641 hb_font_funcs_set_user_data (hb_font_funcs_t *ffuncs,
642 hb_user_data_key_t *key,
644 hb_destroy_func_t destroy /* May be NULL. */,
647 return hb_object_set_user_data (ffuncs, key, data, destroy, replace);
651 * hb_font_funcs_get_user_data: (skip)
652 * @ffuncs: The font-functions structure
653 * @key: The user-data key to query
655 * Fetches the user data associated with the specified key,
656 * attached to the specified font-functions structure.
658 * Return value: (transfer none): A pointer to the user data
663 hb_font_funcs_get_user_data (hb_font_funcs_t *ffuncs,
664 hb_user_data_key_t *key)
666 return hb_object_get_user_data (ffuncs, key);
671 * hb_font_funcs_make_immutable:
672 * @ffuncs: The font-functions structure
674 * Makes a font-functions structure immutable.
679 hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs)
681 if (hb_object_is_immutable (ffuncs))
684 hb_object_make_immutable (ffuncs);
688 * hb_font_funcs_is_immutable:
689 * @ffuncs: The font-functions structure
691 * Tests whether a font-functions structure is immutable.
693 * Return value: %true if @ffuncs is immutable, %false otherwise
698 hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs)
700 return hb_object_is_immutable (ffuncs);
704 #define HB_FONT_FUNC_IMPLEMENT(name) \
707 hb_font_funcs_set_##name##_func (hb_font_funcs_t *ffuncs, \
708 hb_font_get_##name##_func_t func, \
710 hb_destroy_func_t destroy) \
712 if (hb_object_is_immutable (ffuncs)) \
715 destroy (user_data); \
719 if (ffuncs->destroy.name) \
720 ffuncs->destroy.name (ffuncs->user_data.name); \
723 ffuncs->get.f.name = func; \
724 ffuncs->user_data.name = user_data; \
725 ffuncs->destroy.name = destroy; \
727 ffuncs->get.f.name = hb_font_get_##name##_default; \
728 ffuncs->user_data.name = nullptr; \
729 ffuncs->destroy.name = nullptr; \
733 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
734 #undef HB_FONT_FUNC_IMPLEMENT
737 hb_font_t::has_func_set (unsigned int i)
739 return this->klass->get.array[i] != _hb_font_funcs_default.get.array[i];
743 hb_font_t::has_func (unsigned int i)
745 return has_func_set (i) ||
746 (parent && parent != &_hb_Null_hb_font_t && parent->has_func (i));
752 * hb_font_get_h_extents:
753 * @font: #hb_font_t to work upon
754 * @extents: (out): The font extents retrieved
756 * Fetches the extents for a specified font, for horizontal
759 * Return value: %true if data found, %false otherwise
764 hb_font_get_h_extents (hb_font_t *font,
765 hb_font_extents_t *extents)
767 return font->get_font_h_extents (extents);
771 * hb_font_get_v_extents:
772 * @font: #hb_font_t to work upon
773 * @extents: (out): The font extents retrieved
775 * Fetches the extents for a specified font, for vertical
778 * Return value: %true if data found, %false otherwise
783 hb_font_get_v_extents (hb_font_t *font,
784 hb_font_extents_t *extents)
786 return font->get_font_v_extents (extents);
791 * @font: #hb_font_t to work upon
792 * @unicode: The Unicode code point to query
793 * @variation_selector: A variation-selector code point
794 * @glyph: (out): The glyph ID retrieved
796 * Fetches the glyph ID for a Unicode code point in the specified
797 * font, with an optional variation selector.
799 * If @variation_selector is 0, calls hb_font_get_nominal_glyph();
800 * otherwise calls hb_font_get_variation_glyph().
802 * Return value: %true if data found, %false otherwise
807 hb_font_get_glyph (hb_font_t *font,
808 hb_codepoint_t unicode,
809 hb_codepoint_t variation_selector,
810 hb_codepoint_t *glyph)
812 if (unlikely (variation_selector))
813 return font->get_variation_glyph (unicode, variation_selector, glyph);
814 return font->get_nominal_glyph (unicode, glyph);
818 * hb_font_get_nominal_glyph:
819 * @font: #hb_font_t to work upon
820 * @unicode: The Unicode code point to query
821 * @glyph: (out): The glyph ID retrieved
823 * Fetches the nominal glyph ID for a Unicode code point in the
826 * This version of the function should not be used to fetch glyph IDs
827 * for code points modified by variation selectors. For variation-selector
828 * support, user hb_font_get_variation_glyph() or use hb_font_get_glyph().
830 * Return value: %true if data found, %false otherwise
835 hb_font_get_nominal_glyph (hb_font_t *font,
836 hb_codepoint_t unicode,
837 hb_codepoint_t *glyph)
839 return font->get_nominal_glyph (unicode, glyph);
843 * hb_font_get_nominal_glyphs:
844 * @font: #hb_font_t to work upon
845 * @count: number of code points to query
846 * @first_unicode: The first Unicode code point to query
847 * @unicode_stride: The stride between successive code points
848 * @first_glyph: (out): The first glyph ID retrieved
849 * @glyph_stride: The stride between successive glyph IDs
851 * Fetches the nominal glyph IDs for a sequence of Unicode code points. Glyph
852 * IDs must be returned in a #hb_codepoint_t output parameter.
854 * Return value: the number of code points processed
859 hb_font_get_nominal_glyphs (hb_font_t *font,
861 const hb_codepoint_t *first_unicode,
862 unsigned int unicode_stride,
863 hb_codepoint_t *first_glyph,
864 unsigned int glyph_stride)
866 return font->get_nominal_glyphs (count,
867 first_unicode, unicode_stride,
868 first_glyph, glyph_stride);
872 * hb_font_get_variation_glyph:
873 * @font: #hb_font_t to work upon
874 * @unicode: The Unicode code point to query
875 * @variation_selector: The variation-selector code point to query
876 * @glyph: (out): The glyph ID retrieved
878 * Fetches the glyph ID for a Unicode code point when followed by
879 * by the specified variation-selector code point, in the specified
882 * Return value: %true if data found, %false otherwise
887 hb_font_get_variation_glyph (hb_font_t *font,
888 hb_codepoint_t unicode,
889 hb_codepoint_t variation_selector,
890 hb_codepoint_t *glyph)
892 return font->get_variation_glyph (unicode, variation_selector, glyph);
896 * hb_font_get_glyph_h_advance:
897 * @font: #hb_font_t to work upon
898 * @glyph: The glyph ID to query
900 * Fetches the advance for a glyph ID in the specified font,
901 * for horizontal text segments.
903 * Return value: The advance of @glyph within @font
908 hb_font_get_glyph_h_advance (hb_font_t *font,
909 hb_codepoint_t glyph)
911 return font->get_glyph_h_advance (glyph);
915 * hb_font_get_glyph_v_advance:
916 * @font: #hb_font_t to work upon
917 * @glyph: The glyph ID to query
919 * Fetches the advance for a glyph ID in the specified font,
920 * for vertical text segments.
922 * Return value: The advance of @glyph within @font
927 hb_font_get_glyph_v_advance (hb_font_t *font,
928 hb_codepoint_t glyph)
930 return font->get_glyph_v_advance (glyph);
934 * hb_font_get_glyph_h_advances:
935 * @font: #hb_font_t to work upon
936 * @count: The number of glyph IDs in the sequence queried
937 * @first_glyph: The first glyph ID to query
938 * @glyph_stride: The stride between successive glyph IDs
939 * @first_advance: (out): The first advance retrieved
940 * @advance_stride: The stride between successive advances
942 * Fetches the advances for a sequence of glyph IDs in the specified
943 * font, for horizontal text segments.
948 hb_font_get_glyph_h_advances (hb_font_t* font,
950 const hb_codepoint_t *first_glyph,
951 unsigned glyph_stride,
952 hb_position_t *first_advance,
953 unsigned advance_stride)
955 font->get_glyph_h_advances (count, first_glyph, glyph_stride, first_advance, advance_stride);
958 * hb_font_get_glyph_v_advances:
959 * @font: #hb_font_t to work upon
960 * @count: The number of glyph IDs in the sequence queried
961 * @first_glyph: The first glyph ID to query
962 * @glyph_stride: The stride between successive glyph IDs
963 * @first_advance: (out): The first advance retrieved
964 * @advance_stride: (out): The stride between successive advances
966 * Fetches the advances for a sequence of glyph IDs in the specified
967 * font, for vertical text segments.
972 hb_font_get_glyph_v_advances (hb_font_t* font,
974 const hb_codepoint_t *first_glyph,
975 unsigned glyph_stride,
976 hb_position_t *first_advance,
977 unsigned advance_stride)
979 font->get_glyph_v_advances (count, first_glyph, glyph_stride, first_advance, advance_stride);
983 * hb_font_get_glyph_h_origin:
984 * @font: #hb_font_t to work upon
985 * @glyph: The glyph ID to query
986 * @x: (out): The X coordinate of the origin
987 * @y: (out): The Y coordinate of the origin
989 * Fetches the (X,Y) coordinates of the origin for a glyph ID
990 * in the specified font, for horizontal text segments.
992 * Return value: %true if data found, %false otherwise
997 hb_font_get_glyph_h_origin (hb_font_t *font,
998 hb_codepoint_t glyph,
1002 return font->get_glyph_h_origin (glyph, x, y);
1006 * hb_font_get_glyph_v_origin:
1007 * @font: #hb_font_t to work upon
1008 * @glyph: The glyph ID to query
1009 * @x: (out): The X coordinate of the origin
1010 * @y: (out): The Y coordinate of the origin
1012 * Fetches the (X,Y) coordinates of the origin for a glyph ID
1013 * in the specified font, for vertical text segments.
1015 * Return value: %true if data found, %false otherwise
1020 hb_font_get_glyph_v_origin (hb_font_t *font,
1021 hb_codepoint_t glyph,
1025 return font->get_glyph_v_origin (glyph, x, y);
1029 * hb_font_get_glyph_h_kerning:
1030 * @font: #hb_font_t to work upon
1031 * @left_glyph: The glyph ID of the left glyph in the glyph pair
1032 * @right_glyph: The glyph ID of the right glyph in the glyph pair
1034 * Fetches the kerning-adjustment value for a glyph-pair in
1035 * the specified font, for horizontal text segments.
1037 * <note>It handles legacy kerning only (as returned by the corresponding
1038 * #hb_font_funcs_t function).</note>
1040 * Return value: The kerning adjustment value
1045 hb_font_get_glyph_h_kerning (hb_font_t *font,
1046 hb_codepoint_t left_glyph,
1047 hb_codepoint_t right_glyph)
1049 return font->get_glyph_h_kerning (left_glyph, right_glyph);
1052 #ifndef HB_DISABLE_DEPRECATED
1054 * hb_font_get_glyph_v_kerning:
1055 * @font: #hb_font_t to work upon
1056 * @top_glyph: The glyph ID of the top glyph in the glyph pair
1057 * @bottom_glyph: The glyph ID of the bottom glyph in the glyph pair
1059 * Fetches the kerning-adjustment value for a glyph-pair in
1060 * the specified font, for vertical text segments.
1062 * <note>It handles legacy kerning only (as returned by the corresponding
1063 * #hb_font_funcs_t function).</note>
1065 * Return value: The kerning adjustment value
1071 hb_font_get_glyph_v_kerning (hb_font_t *font,
1072 hb_codepoint_t top_glyph,
1073 hb_codepoint_t bottom_glyph)
1075 return font->get_glyph_v_kerning (top_glyph, bottom_glyph);
1080 * hb_font_get_glyph_extents:
1081 * @font: #hb_font_t to work upon
1082 * @glyph: The glyph ID to query
1083 * @extents: (out): The #hb_glyph_extents_t retrieved
1085 * Fetches the #hb_glyph_extents_t data for a glyph ID
1086 * in the specified font.
1088 * Return value: %true if data found, %false otherwise
1093 hb_font_get_glyph_extents (hb_font_t *font,
1094 hb_codepoint_t glyph,
1095 hb_glyph_extents_t *extents)
1097 return font->get_glyph_extents (glyph, extents);
1101 * hb_font_get_glyph_contour_point:
1102 * @font: #hb_font_t to work upon
1103 * @glyph: The glyph ID to query
1104 * @point_index: The contour-point index to query
1105 * @x: (out): The X value retrieved for the contour point
1106 * @y: (out): The Y value retrieved for the contour point
1108 * Fetches the (x,y) coordinates of a specified contour-point index
1109 * in the specified glyph, within the specified font.
1111 * Return value: %true if data found, %false otherwise
1116 hb_font_get_glyph_contour_point (hb_font_t *font,
1117 hb_codepoint_t glyph,
1118 unsigned int point_index,
1122 return font->get_glyph_contour_point (glyph, point_index, x, y);
1126 * hb_font_get_glyph_name:
1127 * @font: #hb_font_t to work upon
1128 * @glyph: The glyph ID to query
1129 * @name: (out) (array length=size): Name string retrieved for the glyph ID
1130 * @size: Length of the glyph-name string retrieved
1132 * Fetches the glyph-name string for a glyph ID in the specified @font.
1134 * Return value: %true if data found, %false otherwise
1139 hb_font_get_glyph_name (hb_font_t *font,
1140 hb_codepoint_t glyph,
1144 return font->get_glyph_name (glyph, name, size);
1148 * hb_font_get_glyph_from_name:
1149 * @font: #hb_font_t to work upon
1150 * @name: (array length=len): The name string to query
1151 * @len: The length of the name queried
1152 * @glyph: (out): The glyph ID retrieved
1154 * Fetches the glyph ID that corresponds to a name string in the specified @font.
1156 * <note>Note: @len == -1 means the name string is null-terminated.</note>
1158 * Return value: %true if data found, %false otherwise
1163 hb_font_get_glyph_from_name (hb_font_t *font,
1165 int len, /* -1 means nul-terminated */
1166 hb_codepoint_t *glyph)
1168 return font->get_glyph_from_name (name, len, glyph);
1172 /* A bit higher-level, and with fallback */
1175 * hb_font_get_extents_for_direction:
1176 * @font: #hb_font_t to work upon
1177 * @direction: The direction of the text segment
1178 * @extents: (out): The #hb_font_extents_t retrieved
1180 * Fetches the extents for a font in a text segment of the
1181 * specified direction.
1183 * Calls the appropriate direction-specific variant (horizontal
1184 * or vertical) depending on the value of @direction.
1189 hb_font_get_extents_for_direction (hb_font_t *font,
1190 hb_direction_t direction,
1191 hb_font_extents_t *extents)
1193 return font->get_extents_for_direction (direction, extents);
1196 * hb_font_get_glyph_advance_for_direction:
1197 * @font: #hb_font_t to work upon
1198 * @glyph: The glyph ID to query
1199 * @direction: The direction of the text segment
1200 * @x: (out): The horizontal advance retrieved
1201 * @y: (out): The vertical advance retrieved
1203 * Fetches the advance for a glyph ID from the specified font,
1204 * in a text segment of the specified direction.
1206 * Calls the appropriate direction-specific variant (horizontal
1207 * or vertical) depending on the value of @direction.
1212 hb_font_get_glyph_advance_for_direction (hb_font_t *font,
1213 hb_codepoint_t glyph,
1214 hb_direction_t direction,
1218 return font->get_glyph_advance_for_direction (glyph, direction, x, y);
1221 * hb_font_get_glyph_advances_for_direction:
1222 * @font: #hb_font_t to work upon
1223 * @direction: The direction of the text segment
1224 * @count: The number of glyph IDs in the sequence queried
1225 * @first_glyph: The first glyph ID to query
1226 * @glyph_stride: The stride between successive glyph IDs
1227 * @first_advance: (out): The first advance retrieved
1228 * @advance_stride: (out): The stride between successive advances
1230 * Fetches the advances for a sequence of glyph IDs in the specified
1231 * font, in a text segment of the specified direction.
1233 * Calls the appropriate direction-specific variant (horizontal
1234 * or vertical) depending on the value of @direction.
1239 hb_font_get_glyph_advances_for_direction (hb_font_t* font,
1240 hb_direction_t direction,
1242 const hb_codepoint_t *first_glyph,
1243 unsigned glyph_stride,
1244 hb_position_t *first_advance,
1245 unsigned advance_stride)
1247 font->get_glyph_advances_for_direction (direction, count, first_glyph, glyph_stride, first_advance, advance_stride);
1251 * hb_font_get_glyph_origin_for_direction:
1252 * @font: #hb_font_t to work upon
1253 * @glyph: The glyph ID to query
1254 * @direction: The direction of the text segment
1255 * @x: (out): The X coordinate retrieved for the origin
1256 * @y: (out): The Y coordinate retrieved for the origin
1258 * Fetches the (X,Y) coordinates of the origin for a glyph in
1259 * the specified font.
1261 * Calls the appropriate direction-specific variant (horizontal
1262 * or vertical) depending on the value of @direction.
1267 hb_font_get_glyph_origin_for_direction (hb_font_t *font,
1268 hb_codepoint_t glyph,
1269 hb_direction_t direction,
1273 return font->get_glyph_origin_for_direction (glyph, direction, x, y);
1277 * hb_font_add_glyph_origin_for_direction:
1278 * @font: #hb_font_t to work upon
1279 * @glyph: The glyph ID to query
1280 * @direction: The direction of the text segment
1281 * @x: (inout): Input = The original X coordinate
1282 * Output = The X coordinate plus the X-coordinate of the origin
1283 * @y: (inout): Input = The original Y coordinate
1284 * Output = The Y coordinate plus the Y-coordinate of the origin
1286 * Adds the origin coordinates to an (X,Y) point coordinate, in
1287 * the specified glyph ID in the specified font.
1289 * Calls the appropriate direction-specific variant (horizontal
1290 * or vertical) depending on the value of @direction.
1295 hb_font_add_glyph_origin_for_direction (hb_font_t *font,
1296 hb_codepoint_t glyph,
1297 hb_direction_t direction,
1301 return font->add_glyph_origin_for_direction (glyph, direction, x, y);
1305 * hb_font_subtract_glyph_origin_for_direction:
1306 * @font: #hb_font_t to work upon
1307 * @glyph: The glyph ID to query
1308 * @direction: The direction of the text segment
1309 * @x: (inout): Input = The original X coordinate
1310 * Output = The X coordinate minus the X-coordinate of the origin
1311 * @y: (inout): Input = The original Y coordinate
1312 * Output = The Y coordinate minus the Y-coordinate of the origin
1314 * Subtracts the origin coordinates from an (X,Y) point coordinate,
1315 * in the specified glyph ID in the specified font.
1317 * Calls the appropriate direction-specific variant (horizontal
1318 * or vertical) depending on the value of @direction.
1323 hb_font_subtract_glyph_origin_for_direction (hb_font_t *font,
1324 hb_codepoint_t glyph,
1325 hb_direction_t direction,
1329 return font->subtract_glyph_origin_for_direction (glyph, direction, x, y);
1333 * hb_font_get_glyph_kerning_for_direction:
1334 * @font: #hb_font_t to work upon
1335 * @first_glyph: The glyph ID of the first glyph in the glyph pair to query
1336 * @second_glyph: The glyph ID of the second glyph in the glyph pair to query
1337 * @direction: The direction of the text segment
1338 * @x: (out): The horizontal kerning-adjustment value retrieved
1339 * @y: (out): The vertical kerning-adjustment value retrieved
1341 * Fetches the kerning-adjustment value for a glyph-pair in the specified font.
1343 * Calls the appropriate direction-specific variant (horizontal
1344 * or vertical) depending on the value of @direction.
1349 hb_font_get_glyph_kerning_for_direction (hb_font_t *font,
1350 hb_codepoint_t first_glyph,
1351 hb_codepoint_t second_glyph,
1352 hb_direction_t direction,
1356 return font->get_glyph_kerning_for_direction (first_glyph, second_glyph, direction, x, y);
1360 * hb_font_get_glyph_extents_for_origin:
1361 * @font: #hb_font_t to work upon
1362 * @glyph: The glyph ID to query
1363 * @direction: The direction of the text segment
1364 * @extents: (out): The #hb_glyph_extents_t retrieved
1366 * Fetches the #hb_glyph_extents_t data for a glyph ID
1367 * in the specified font, with respect to the origin in
1368 * a text segment in the specified direction.
1370 * Calls the appropriate direction-specific variant (horizontal
1371 * or vertical) depending on the value of @direction.
1373 * Return value: %true if data found, %false otherwise
1378 hb_font_get_glyph_extents_for_origin (hb_font_t *font,
1379 hb_codepoint_t glyph,
1380 hb_direction_t direction,
1381 hb_glyph_extents_t *extents)
1383 return font->get_glyph_extents_for_origin (glyph, direction, extents);
1387 * hb_font_get_glyph_contour_point_for_origin:
1388 * @font: #hb_font_t to work upon
1389 * @glyph: The glyph ID to query
1390 * @point_index: The contour-point index to query
1391 * @direction: The direction of the text segment
1392 * @x: (out): The X value retrieved for the contour point
1393 * @y: (out): The Y value retrieved for the contour point
1395 * Fetches the (X,Y) coordinates of a specified contour-point index
1396 * in the specified glyph ID in the specified font, with respect
1397 * to the origin in a text segment in the specified direction.
1399 * Calls the appropriate direction-specific variant (horizontal
1400 * or vertical) depending on the value of @direction.
1402 * Return value: %true if data found, %false otherwise
1407 hb_font_get_glyph_contour_point_for_origin (hb_font_t *font,
1408 hb_codepoint_t glyph,
1409 unsigned int point_index,
1410 hb_direction_t direction,
1414 return font->get_glyph_contour_point_for_origin (glyph, point_index, direction, x, y);
1418 * hb_font_glyph_to_string:
1419 * @font: #hb_font_t to work upon
1420 * @glyph: The glyph ID to query
1421 * @s: (out) (array length=size): The string containing the glyph name
1422 * @size: Length of string @s
1424 * Fetches the name of the specified glyph ID in @font and returns
1427 * If the glyph ID has no name in @font, a string of the form `gidDDD` is
1428 * generated, with `DDD` being the glyph ID.
1433 hb_font_glyph_to_string (hb_font_t *font,
1434 hb_codepoint_t glyph,
1438 font->glyph_to_string (glyph, s, size);
1442 * hb_font_glyph_from_string:
1443 * @font: #hb_font_t to work upon
1444 * @s: (array length=len) (element-type uint8_t): string to query
1445 * @len: The length of the string @s
1446 * @glyph: (out): The glyph ID corresponding to the string requested
1448 * Fetches the glyph ID from @font that matches the specified string.
1449 * Strings of the format `gidDDD` or `uniUUUU` are parsed automatically.
1451 * <note>Note: @len == -1 means the string is null-terminated.</note>
1453 * Return value: %true if data found, %false otherwise
1458 hb_font_glyph_from_string (hb_font_t *font,
1461 hb_codepoint_t *glyph)
1463 return font->glyph_from_string (s, len, glyph);
1471 DEFINE_NULL_INSTANCE (hb_font_t) =
1473 HB_OBJECT_HEADER_STATIC,
1475 nullptr, /* parent */
1476 const_cast<hb_face_t *> (&_hb_Null_hb_face_t),
1490 nullptr, /* coords */
1491 nullptr, /* design_coords */
1493 const_cast<hb_font_funcs_t *> (&_hb_Null_hb_font_funcs_t),
1495 /* Zero for the rest is fine. */
1500 _hb_font_create (hb_face_t *face)
1504 if (unlikely (!face))
1505 face = hb_face_get_empty ();
1506 if (!(font = hb_object_create<hb_font_t> ()))
1507 return hb_font_get_empty ();
1509 hb_face_make_immutable (face);
1510 font->parent = hb_font_get_empty ();
1511 font->face = hb_face_reference (face);
1512 font->klass = hb_font_funcs_get_empty ();
1513 font->data.init0 (font);
1514 font->x_scale = font->y_scale = hb_face_get_upem (face);
1515 font->x_mult = font->y_mult = 1 << 16;
1521 * hb_font_create: (Xconstructor)
1524 * Constructs a new font object from the specified face.
1526 * <note>Note: If @face's index value (as passed to hb_face_create()
1527 * has non-zero top 16-bits, those bits minus one are passed to
1528 * hb_font_set_var_named_instance(), effectively loading a named-instance
1529 * of a variable font, instead of the default-instance. This allows
1530 * specifying which named-instance to load by default when creating the
1533 * Return value: (transfer full): The new font object
1538 hb_font_create (hb_face_t *face)
1540 hb_font_t *font = _hb_font_create (face);
1542 #ifndef HB_NO_OT_FONT
1543 /* Install our in-house, very lightweight, funcs. */
1544 hb_ot_font_set_funcs (font);
1548 if (face && face->index >> 16)
1549 hb_font_set_var_named_instance (font, (face->index >> 16) - 1);
1556 _hb_font_adopt_var_coords (hb_font_t *font,
1557 int *coords, /* 2.14 normalized */
1558 float *design_coords,
1559 unsigned int coords_length)
1561 hb_free (font->coords);
1562 hb_free (font->design_coords);
1564 font->coords = coords;
1565 font->design_coords = design_coords;
1566 font->num_coords = coords_length;
1570 * hb_font_create_sub_font:
1571 * @parent: The parent font object
1573 * Constructs a sub-font font object from the specified @parent font,
1574 * replicating the parent's properties.
1576 * Return value: (transfer full): The new sub-font font object
1581 hb_font_create_sub_font (hb_font_t *parent)
1583 if (unlikely (!parent))
1584 parent = hb_font_get_empty ();
1586 hb_font_t *font = _hb_font_create (parent->face);
1588 if (unlikely (hb_object_is_immutable (font)))
1591 font->parent = hb_font_reference (parent);
1593 font->x_scale = parent->x_scale;
1594 font->y_scale = parent->y_scale;
1595 font->slant = parent->slant;
1596 font->mults_changed ();
1597 font->x_ppem = parent->x_ppem;
1598 font->y_ppem = parent->y_ppem;
1599 font->ptem = parent->ptem;
1601 unsigned int num_coords = parent->num_coords;
1604 int *coords = (int *) hb_calloc (num_coords, sizeof (parent->coords[0]));
1605 float *design_coords = (float *) hb_calloc (num_coords, sizeof (parent->design_coords[0]));
1606 if (likely (coords && design_coords))
1608 memcpy (coords, parent->coords, num_coords * sizeof (parent->coords[0]));
1609 memcpy (design_coords, parent->design_coords, num_coords * sizeof (parent->design_coords[0]));
1610 _hb_font_adopt_var_coords (font, coords, design_coords, num_coords);
1615 hb_free (design_coords);
1623 * hb_font_get_empty:
1625 * Fetches the empty font object.
1627 * Return value: (transfer full): The empty font object
1632 hb_font_get_empty ()
1634 return const_cast<hb_font_t *> (&Null (hb_font_t));
1638 * hb_font_reference: (skip)
1639 * @font: #hb_font_t to work upon
1641 * Increases the reference count on the given font object.
1643 * Return value: (transfer full): The @font object
1648 hb_font_reference (hb_font_t *font)
1650 return hb_object_reference (font);
1654 * hb_font_destroy: (skip)
1655 * @font: #hb_font_t to work upon
1657 * Decreases the reference count on the given font object. When the
1658 * reference count reaches zero, the font is destroyed,
1659 * freeing all memory.
1664 hb_font_destroy (hb_font_t *font)
1666 if (!hb_object_destroy (font)) return;
1671 font->destroy (font->user_data);
1673 hb_font_destroy (font->parent);
1674 hb_face_destroy (font->face);
1675 hb_font_funcs_destroy (font->klass);
1677 hb_free (font->coords);
1678 hb_free (font->design_coords);
1684 * hb_font_set_user_data: (skip)
1685 * @font: #hb_font_t to work upon
1686 * @key: The user-data key
1687 * @data: A pointer to the user data
1688 * @destroy: (nullable): A callback to call when @data is not needed anymore
1689 * @replace: Whether to replace an existing data with the same key
1691 * Attaches a user-data key/data pair to the specified font object.
1693 * Return value: %true if success, %false otherwise
1698 hb_font_set_user_data (hb_font_t *font,
1699 hb_user_data_key_t *key,
1701 hb_destroy_func_t destroy /* May be NULL. */,
1704 return hb_object_set_user_data (font, key, data, destroy, replace);
1708 * hb_font_get_user_data: (skip)
1709 * @font: #hb_font_t to work upon
1710 * @key: The user-data key to query
1712 * Fetches the user-data object associated with the specified key,
1713 * attached to the specified font object.
1715 * Return value: (transfer none): Pointer to the user data
1720 hb_font_get_user_data (hb_font_t *font,
1721 hb_user_data_key_t *key)
1723 return hb_object_get_user_data (font, key);
1727 * hb_font_make_immutable:
1728 * @font: #hb_font_t to work upon
1730 * Makes @font immutable.
1735 hb_font_make_immutable (hb_font_t *font)
1737 if (hb_object_is_immutable (font))
1741 hb_font_make_immutable (font->parent);
1743 hb_object_make_immutable (font);
1747 * hb_font_is_immutable:
1748 * @font: #hb_font_t to work upon
1750 * Tests whether a font object is immutable.
1752 * Return value: %true if @font is immutable, %false otherwise
1757 hb_font_is_immutable (hb_font_t *font)
1759 return hb_object_is_immutable (font);
1763 * hb_font_set_parent:
1764 * @font: #hb_font_t to work upon
1765 * @parent: The parent font object to assign
1767 * Sets the parent font of @font.
1772 hb_font_set_parent (hb_font_t *font,
1775 if (hb_object_is_immutable (font))
1779 parent = hb_font_get_empty ();
1781 hb_font_t *old = font->parent;
1783 font->parent = hb_font_reference (parent);
1785 hb_font_destroy (old);
1789 * hb_font_get_parent:
1790 * @font: #hb_font_t to work upon
1792 * Fetches the parent font of @font.
1794 * Return value: (transfer none): The parent font object
1799 hb_font_get_parent (hb_font_t *font)
1801 return font->parent;
1806 * @font: #hb_font_t to work upon
1807 * @face: The #hb_face_t to assign
1809 * Sets @face as the font-face value of @font.
1814 hb_font_set_face (hb_font_t *font,
1817 if (hb_object_is_immutable (font))
1820 if (unlikely (!face))
1821 face = hb_face_get_empty ();
1823 hb_face_t *old = font->face;
1825 hb_face_make_immutable (face);
1826 font->face = hb_face_reference (face);
1827 font->mults_changed ();
1829 hb_face_destroy (old);
1834 * @font: #hb_font_t to work upon
1836 * Fetches the face associated with the specified font object.
1838 * Return value: (transfer none): The #hb_face_t value
1843 hb_font_get_face (hb_font_t *font)
1850 * hb_font_set_funcs:
1851 * @font: #hb_font_t to work upon
1852 * @klass: (closure font_data) (destroy destroy) (scope notified): The font-functions structure.
1853 * @font_data: Data to attach to @font
1854 * @destroy: (nullable): The function to call when @font_data is not needed anymore
1856 * Replaces the font-functions structure attached to a font, updating
1857 * the font's user-data with @font-data and the @destroy callback.
1862 hb_font_set_funcs (hb_font_t *font,
1863 hb_font_funcs_t *klass,
1865 hb_destroy_func_t destroy /* May be NULL. */)
1867 if (hb_object_is_immutable (font))
1870 destroy (font_data);
1875 font->destroy (font->user_data);
1878 klass = hb_font_funcs_get_empty ();
1880 hb_font_funcs_reference (klass);
1881 hb_font_funcs_destroy (font->klass);
1882 font->klass = klass;
1883 font->user_data = font_data;
1884 font->destroy = destroy;
1888 * hb_font_set_funcs_data:
1889 * @font: #hb_font_t to work upon
1890 * @font_data: (destroy destroy) (scope notified): Data to attach to @font
1891 * @destroy: (nullable): The function to call when @font_data is not needed anymore
1893 * Replaces the user data attached to a font, updating the font's
1894 * @destroy callback.
1899 hb_font_set_funcs_data (hb_font_t *font,
1901 hb_destroy_func_t destroy /* May be NULL. */)
1903 /* Destroy user_data? */
1904 if (hb_object_is_immutable (font))
1907 destroy (font_data);
1912 font->destroy (font->user_data);
1914 font->user_data = font_data;
1915 font->destroy = destroy;
1920 * hb_font_set_scale:
1921 * @font: #hb_font_t to work upon
1922 * @x_scale: Horizontal scale value to assign
1923 * @y_scale: Vertical scale value to assign
1925 * Sets the horizontal and vertical scale of a font.
1930 hb_font_set_scale (hb_font_t *font,
1934 if (hb_object_is_immutable (font))
1937 font->x_scale = x_scale;
1938 font->y_scale = y_scale;
1939 font->mults_changed ();
1943 * hb_font_get_scale:
1944 * @font: #hb_font_t to work upon
1945 * @x_scale: (out): Horizontal scale value
1946 * @y_scale: (out): Vertical scale value
1948 * Fetches the horizontal and vertical scale of a font.
1953 hb_font_get_scale (hb_font_t *font,
1957 if (x_scale) *x_scale = font->x_scale;
1958 if (y_scale) *y_scale = font->y_scale;
1963 * @font: #hb_font_t to work upon
1964 * @x_ppem: Horizontal ppem value to assign
1965 * @y_ppem: Vertical ppem value to assign
1967 * Sets the horizontal and vertical pixels-per-em (ppem) of a font.
1972 hb_font_set_ppem (hb_font_t *font,
1973 unsigned int x_ppem,
1974 unsigned int y_ppem)
1976 if (hb_object_is_immutable (font))
1979 font->x_ppem = x_ppem;
1980 font->y_ppem = y_ppem;
1985 * @font: #hb_font_t to work upon
1986 * @x_ppem: (out): Horizontal ppem value
1987 * @y_ppem: (out): Vertical ppem value
1989 * Fetches the horizontal and vertical points-per-em (ppem) of a font.
1994 hb_font_get_ppem (hb_font_t *font,
1995 unsigned int *x_ppem,
1996 unsigned int *y_ppem)
1998 if (x_ppem) *x_ppem = font->x_ppem;
1999 if (y_ppem) *y_ppem = font->y_ppem;
2004 * @font: #hb_font_t to work upon
2005 * @ptem: font size in points.
2007 * Sets the "point size" of a font. Set to zero to unset.
2008 * Used in CoreText to implement optical sizing.
2010 * <note>Note: There are 72 points in an inch.</note>
2015 hb_font_set_ptem (hb_font_t *font,
2018 if (hb_object_is_immutable (font))
2026 * @font: #hb_font_t to work upon
2028 * Fetches the "point size" of a font. Used in CoreText to
2029 * implement optical sizing.
2031 * Return value: Point size. A value of zero means "not set."
2036 hb_font_get_ptem (hb_font_t *font)
2042 * hb_font_set_synthetic_slant:
2043 * @font: #hb_font_t to work upon
2044 * @slant: synthetic slant value.
2046 * Sets the "synthetic slant" of a font. By default is zero.
2047 * Synthetic slant is the graphical skew that the renderer
2048 * applies to the font at rendering time.
2050 * HarfBuzz needs to know this value to adjust shaping results,
2051 * metrics, and style values to match the slanted rendering.
2053 * <note>Note: The slant value is a ratio. For example, a
2054 * 20% slant would be represented as a 0.2 value.</note>
2059 hb_font_set_synthetic_slant (hb_font_t *font, float slant)
2061 if (hb_object_is_immutable (font))
2064 font->slant = slant;
2065 font->mults_changed ();
2069 * hb_font_get_synthetic_slant:
2070 * @font: #hb_font_t to work upon
2072 * Fetches the "synthetic slant" of a font.
2074 * Return value: Synthetic slant. By default is zero.
2079 hb_font_get_synthetic_slant (hb_font_t *font)
2090 * hb_font_set_variations:
2091 * @font: #hb_font_t to work upon
2092 * @variations: (array length=variations_length): Array of variation settings to apply
2093 * @variations_length: Number of variations to apply
2095 * Applies a list of font-variation settings to a font.
2097 * Note that this overrides all existing variations set on @font.
2098 * Axes not included in @variations will be effectively set to their
2104 hb_font_set_variations (hb_font_t *font,
2105 const hb_variation_t *variations,
2106 unsigned int variations_length)
2108 if (hb_object_is_immutable (font))
2111 if (!variations_length)
2113 hb_font_set_var_coords_normalized (font, nullptr, 0);
2117 const OT::fvar &fvar = *font->face->table.fvar;
2118 auto axes = fvar.get_axes ();
2119 const unsigned coords_length = axes.length;
2121 int *normalized = coords_length ? (int *) hb_calloc (coords_length, sizeof (int)) : nullptr;
2122 float *design_coords = coords_length ? (float *) hb_calloc (coords_length, sizeof (float)) : nullptr;
2124 if (unlikely (coords_length && !(normalized && design_coords)))
2126 hb_free (normalized);
2127 hb_free (design_coords);
2131 for (unsigned int i = 0; i < variations_length; i++)
2133 const auto tag = variations[i].tag;
2134 const auto v = variations[i].value;
2135 for (unsigned axis_index = 0; axis_index < coords_length; axis_index++)
2136 if (axes[axis_index].axisTag == tag)
2138 design_coords[axis_index] = v;
2139 normalized[axis_index] = fvar.normalize_axis_value (axis_index, v);
2142 font->face->table.avar->map_coords (normalized, coords_length);
2144 _hb_font_adopt_var_coords (font, normalized, design_coords, coords_length);
2148 * hb_font_set_var_coords_design:
2149 * @font: #hb_font_t to work upon
2150 * @coords: (array length=coords_length): Array of variation coordinates to apply
2151 * @coords_length: Number of coordinates to apply
2153 * Applies a list of variation coordinates (in design-space units)
2156 * Note that this overrides all existing variations set on @font.
2157 * Axes not included in @coords will be effectively set to their
2163 hb_font_set_var_coords_design (hb_font_t *font,
2164 const float *coords,
2165 unsigned int coords_length)
2167 if (hb_object_is_immutable (font))
2170 int *normalized = coords_length ? (int *) hb_calloc (coords_length, sizeof (int)) : nullptr;
2171 float *design_coords = coords_length ? (float *) hb_calloc (coords_length, sizeof (float)) : nullptr;
2173 if (unlikely (coords_length && !(normalized && design_coords)))
2175 hb_free (normalized);
2176 hb_free (design_coords);
2181 memcpy (design_coords, coords, coords_length * sizeof (font->design_coords[0]));
2183 hb_ot_var_normalize_coords (font->face, coords_length, coords, normalized);
2184 _hb_font_adopt_var_coords (font, normalized, design_coords, coords_length);
2188 * hb_font_set_var_named_instance:
2190 * @instance_index: named instance index.
2192 * Sets design coords of a font from a named instance index.
2197 hb_font_set_var_named_instance (hb_font_t *font,
2198 unsigned instance_index)
2200 if (hb_object_is_immutable (font))
2203 unsigned int coords_length = hb_ot_var_named_instance_get_design_coords (font->face, instance_index, nullptr, nullptr);
2205 float *coords = coords_length ? (float *) hb_calloc (coords_length, sizeof (float)) : nullptr;
2206 if (unlikely (coords_length && !coords))
2209 hb_ot_var_named_instance_get_design_coords (font->face, instance_index, &coords_length, coords);
2210 hb_font_set_var_coords_design (font, coords, coords_length);
2215 * hb_font_set_var_coords_normalized:
2216 * @font: #hb_font_t to work upon
2217 * @coords: (array length=coords_length): Array of variation coordinates to apply
2218 * @coords_length: Number of coordinates to apply
2220 * Applies a list of variation coordinates (in normalized units)
2223 * Note that this overrides all existing variations set on @font.
2224 * Axes not included in @coords will be effectively set to their
2227 * <note>Note: Coordinates should be normalized to 2.14.</note>
2232 hb_font_set_var_coords_normalized (hb_font_t *font,
2233 const int *coords, /* 2.14 normalized */
2234 unsigned int coords_length)
2236 if (hb_object_is_immutable (font))
2239 int *copy = coords_length ? (int *) hb_calloc (coords_length, sizeof (coords[0])) : nullptr;
2240 int *unmapped = coords_length ? (int *) hb_calloc (coords_length, sizeof (coords[0])) : nullptr;
2241 float *design_coords = coords_length ? (float *) hb_calloc (coords_length, sizeof (design_coords[0])) : nullptr;
2243 if (unlikely (coords_length && !(copy && unmapped && design_coords)))
2247 hb_free (design_coords);
2253 memcpy (copy, coords, coords_length * sizeof (coords[0]));
2254 memcpy (unmapped, coords, coords_length * sizeof (coords[0]));
2257 /* Best effort design coords simulation */
2258 font->face->table.avar->unmap_coords (unmapped, coords_length);
2259 for (unsigned int i = 0; i < coords_length; ++i)
2260 design_coords[i] = font->face->table.fvar->unnormalize_axis_value (i, unmapped[i]);
2263 _hb_font_adopt_var_coords (font, copy, design_coords, coords_length);
2267 * hb_font_get_var_coords_normalized:
2268 * @font: #hb_font_t to work upon
2269 * @length: (out): Number of coordinates retrieved
2271 * Fetches the list of normalized variation coordinates currently
2274 * Note that this returned array may only contain values for some
2275 * (or none) of the axes; omitted axes effectively have zero values.
2277 * Return value is valid as long as variation coordinates of the font
2280 * Return value: coordinates array
2285 hb_font_get_var_coords_normalized (hb_font_t *font,
2286 unsigned int *length)
2289 *length = font->num_coords;
2291 return font->coords;
2295 * hb_font_get_var_coords_design:
2296 * @font: #hb_font_t to work upon
2297 * @length: (out): Number of coordinates retrieved
2299 * Fetches the list of variation coordinates (in design-space units) currently
2302 * Note that this returned array may only contain values for some
2303 * (or none) of the axes; omitted axes effectively have their default
2306 * Return value is valid as long as variation coordinates of the font
2309 * Return value: coordinates array
2314 hb_font_get_var_coords_design (hb_font_t *font,
2315 unsigned int *length)
2318 *length = font->num_coords;
2320 return font->design_coords;
2324 #ifndef HB_DISABLE_DEPRECATED
2326 * Deprecated get_glyph_func():
2329 struct hb_trampoline_closure_t
2332 hb_destroy_func_t destroy;
2333 unsigned int ref_count;
2336 template <typename FuncType>
2337 struct hb_trampoline_t
2339 hb_trampoline_closure_t closure; /* Must be first. */
2343 template <typename FuncType>
2344 static hb_trampoline_t<FuncType> *
2345 trampoline_create (FuncType func,
2347 hb_destroy_func_t destroy)
2349 typedef hb_trampoline_t<FuncType> trampoline_t;
2351 trampoline_t *trampoline = (trampoline_t *) hb_calloc (1, sizeof (trampoline_t));
2353 if (unlikely (!trampoline))
2356 trampoline->closure.user_data = user_data;
2357 trampoline->closure.destroy = destroy;
2358 trampoline->closure.ref_count = 1;
2359 trampoline->func = func;
2365 trampoline_reference (hb_trampoline_closure_t *closure)
2367 closure->ref_count++;
2371 trampoline_destroy (void *user_data)
2373 hb_trampoline_closure_t *closure = (hb_trampoline_closure_t *) user_data;
2375 if (--closure->ref_count)
2378 if (closure->destroy)
2379 closure->destroy (closure->user_data);
2383 typedef hb_trampoline_t<hb_font_get_glyph_func_t> hb_font_get_glyph_trampoline_t;
2386 hb_font_get_nominal_glyph_trampoline (hb_font_t *font,
2388 hb_codepoint_t unicode,
2389 hb_codepoint_t *glyph,
2392 hb_font_get_glyph_trampoline_t *trampoline = (hb_font_get_glyph_trampoline_t *) user_data;
2393 return trampoline->func (font, font_data, unicode, 0, glyph, trampoline->closure.user_data);
2397 hb_font_get_variation_glyph_trampoline (hb_font_t *font,
2399 hb_codepoint_t unicode,
2400 hb_codepoint_t variation_selector,
2401 hb_codepoint_t *glyph,
2404 hb_font_get_glyph_trampoline_t *trampoline = (hb_font_get_glyph_trampoline_t *) user_data;
2405 return trampoline->func (font, font_data, unicode, variation_selector, glyph, trampoline->closure.user_data);
2409 * hb_font_funcs_set_glyph_func:
2410 * @ffuncs: The font-functions structure
2411 * @func: (closure user_data) (destroy destroy) (scope notified): callback function
2412 * @user_data: data to pass to @func
2413 * @destroy: (nullable): function to call when @user_data is not needed anymore
2415 * Deprecated. Use hb_font_funcs_set_nominal_glyph_func() and
2416 * hb_font_funcs_set_variation_glyph_func() instead.
2422 hb_font_funcs_set_glyph_func (hb_font_funcs_t *ffuncs,
2423 hb_font_get_glyph_func_t func,
2425 hb_destroy_func_t destroy /* May be NULL. */)
2427 if (hb_object_is_immutable (ffuncs))
2430 destroy (user_data);
2434 hb_font_get_glyph_trampoline_t *trampoline;
2436 trampoline = trampoline_create (func, user_data, destroy);
2437 if (unlikely (!trampoline))
2440 destroy (user_data);
2444 hb_font_funcs_set_nominal_glyph_func (ffuncs,
2445 hb_font_get_nominal_glyph_trampoline,
2447 trampoline_destroy);
2449 trampoline_reference (&trampoline->closure);
2450 hb_font_funcs_set_variation_glyph_func (ffuncs,
2451 hb_font_get_variation_glyph_trampoline,
2453 trampoline_destroy);