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 * Font objects represent a font face at a certain size and other
47 * parameters (pixels per EM, points per EM, variation settings.)
48 * Fonts are created from font faces, and are used as input to
49 * hb_shape() among other things.
58 hb_font_get_font_h_extents_nil (hb_font_t *font HB_UNUSED,
59 void *font_data HB_UNUSED,
60 hb_font_extents_t *extents,
61 void *user_data HB_UNUSED)
63 memset (extents, 0, sizeof (*extents));
67 hb_font_get_font_h_extents_default (hb_font_t *font,
68 void *font_data HB_UNUSED,
69 hb_font_extents_t *extents,
70 void *user_data HB_UNUSED)
72 hb_bool_t ret = font->parent->get_font_h_extents (extents);
74 extents->ascender = font->parent_scale_y_distance (extents->ascender);
75 extents->descender = font->parent_scale_y_distance (extents->descender);
76 extents->line_gap = font->parent_scale_y_distance (extents->line_gap);
82 hb_font_get_font_v_extents_nil (hb_font_t *font HB_UNUSED,
83 void *font_data HB_UNUSED,
84 hb_font_extents_t *extents,
85 void *user_data HB_UNUSED)
87 memset (extents, 0, sizeof (*extents));
91 hb_font_get_font_v_extents_default (hb_font_t *font,
92 void *font_data HB_UNUSED,
93 hb_font_extents_t *extents,
94 void *user_data HB_UNUSED)
96 hb_bool_t ret = font->parent->get_font_v_extents (extents);
98 extents->ascender = font->parent_scale_x_distance (extents->ascender);
99 extents->descender = font->parent_scale_x_distance (extents->descender);
100 extents->line_gap = font->parent_scale_x_distance (extents->line_gap);
106 hb_font_get_nominal_glyph_nil (hb_font_t *font HB_UNUSED,
107 void *font_data HB_UNUSED,
108 hb_codepoint_t unicode HB_UNUSED,
109 hb_codepoint_t *glyph,
110 void *user_data HB_UNUSED)
116 hb_font_get_nominal_glyph_default (hb_font_t *font,
117 void *font_data HB_UNUSED,
118 hb_codepoint_t unicode,
119 hb_codepoint_t *glyph,
120 void *user_data HB_UNUSED)
122 if (font->has_nominal_glyphs_func_set ())
124 return font->get_nominal_glyphs (1, &unicode, 0, glyph, 0);
126 return font->parent->get_nominal_glyph (unicode, glyph);
129 #define hb_font_get_nominal_glyphs_nil hb_font_get_nominal_glyphs_default
131 hb_font_get_nominal_glyphs_default (hb_font_t *font,
132 void *font_data HB_UNUSED,
134 const hb_codepoint_t *first_unicode,
135 unsigned int unicode_stride,
136 hb_codepoint_t *first_glyph,
137 unsigned int glyph_stride,
138 void *user_data HB_UNUSED)
140 if (font->has_nominal_glyph_func_set ())
142 for (unsigned int i = 0; i < count; i++)
144 if (!font->get_nominal_glyph (*first_unicode, first_glyph))
147 first_unicode = &StructAtOffsetUnaligned<hb_codepoint_t> (first_unicode, unicode_stride);
148 first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
153 return font->parent->get_nominal_glyphs (count,
154 first_unicode, unicode_stride,
155 first_glyph, glyph_stride);
159 hb_font_get_variation_glyph_nil (hb_font_t *font HB_UNUSED,
160 void *font_data HB_UNUSED,
161 hb_codepoint_t unicode HB_UNUSED,
162 hb_codepoint_t variation_selector HB_UNUSED,
163 hb_codepoint_t *glyph,
164 void *user_data HB_UNUSED)
170 hb_font_get_variation_glyph_default (hb_font_t *font,
171 void *font_data HB_UNUSED,
172 hb_codepoint_t unicode,
173 hb_codepoint_t variation_selector,
174 hb_codepoint_t *glyph,
175 void *user_data HB_UNUSED)
177 return font->parent->get_variation_glyph (unicode, variation_selector, glyph);
182 hb_font_get_glyph_h_advance_nil (hb_font_t *font,
183 void *font_data HB_UNUSED,
184 hb_codepoint_t glyph HB_UNUSED,
185 void *user_data HB_UNUSED)
187 return font->x_scale;
190 hb_font_get_glyph_h_advance_default (hb_font_t *font,
191 void *font_data HB_UNUSED,
192 hb_codepoint_t glyph,
193 void *user_data HB_UNUSED)
195 if (font->has_glyph_h_advances_func_set ())
198 font->get_glyph_h_advances (1, &glyph, 0, &ret, 0);
201 return font->parent_scale_x_distance (font->parent->get_glyph_h_advance (glyph));
205 hb_font_get_glyph_v_advance_nil (hb_font_t *font,
206 void *font_data HB_UNUSED,
207 hb_codepoint_t glyph HB_UNUSED,
208 void *user_data HB_UNUSED)
210 /* TODO use font_extents.ascender+descender */
211 return font->y_scale;
214 hb_font_get_glyph_v_advance_default (hb_font_t *font,
215 void *font_data HB_UNUSED,
216 hb_codepoint_t glyph,
217 void *user_data HB_UNUSED)
219 if (font->has_glyph_v_advances_func_set ())
222 font->get_glyph_v_advances (1, &glyph, 0, &ret, 0);
225 return font->parent_scale_y_distance (font->parent->get_glyph_v_advance (glyph));
228 #define hb_font_get_glyph_h_advances_nil hb_font_get_glyph_h_advances_default
230 hb_font_get_glyph_h_advances_default (hb_font_t* font,
231 void* font_data HB_UNUSED,
233 const hb_codepoint_t *first_glyph,
234 unsigned int glyph_stride,
235 hb_position_t *first_advance,
236 unsigned int advance_stride,
237 void *user_data HB_UNUSED)
239 if (font->has_glyph_h_advance_func_set ())
241 for (unsigned int i = 0; i < count; i++)
243 *first_advance = font->get_glyph_h_advance (*first_glyph);
244 first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
245 first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
250 font->parent->get_glyph_h_advances (count,
251 first_glyph, glyph_stride,
252 first_advance, advance_stride);
253 for (unsigned int i = 0; i < count; i++)
255 *first_advance = font->parent_scale_x_distance (*first_advance);
256 first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
260 #define hb_font_get_glyph_v_advances_nil hb_font_get_glyph_v_advances_default
262 hb_font_get_glyph_v_advances_default (hb_font_t* font,
263 void* font_data HB_UNUSED,
265 const hb_codepoint_t *first_glyph,
266 unsigned int glyph_stride,
267 hb_position_t *first_advance,
268 unsigned int advance_stride,
269 void *user_data HB_UNUSED)
271 if (font->has_glyph_v_advance_func_set ())
273 for (unsigned int i = 0; i < count; i++)
275 *first_advance = font->get_glyph_v_advance (*first_glyph);
276 first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
277 first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
282 font->parent->get_glyph_v_advances (count,
283 first_glyph, glyph_stride,
284 first_advance, advance_stride);
285 for (unsigned int i = 0; i < count; i++)
287 *first_advance = font->parent_scale_y_distance (*first_advance);
288 first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
293 hb_font_get_glyph_h_origin_nil (hb_font_t *font HB_UNUSED,
294 void *font_data HB_UNUSED,
295 hb_codepoint_t glyph HB_UNUSED,
298 void *user_data HB_UNUSED)
304 hb_font_get_glyph_h_origin_default (hb_font_t *font,
305 void *font_data HB_UNUSED,
306 hb_codepoint_t glyph,
309 void *user_data HB_UNUSED)
311 hb_bool_t ret = font->parent->get_glyph_h_origin (glyph, x, y);
313 font->parent_scale_position (x, y);
318 hb_font_get_glyph_v_origin_nil (hb_font_t *font HB_UNUSED,
319 void *font_data HB_UNUSED,
320 hb_codepoint_t glyph HB_UNUSED,
323 void *user_data HB_UNUSED)
329 hb_font_get_glyph_v_origin_default (hb_font_t *font,
330 void *font_data HB_UNUSED,
331 hb_codepoint_t glyph,
334 void *user_data HB_UNUSED)
336 hb_bool_t ret = font->parent->get_glyph_v_origin (glyph, x, y);
338 font->parent_scale_position (x, y);
343 hb_font_get_glyph_h_kerning_nil (hb_font_t *font HB_UNUSED,
344 void *font_data HB_UNUSED,
345 hb_codepoint_t left_glyph HB_UNUSED,
346 hb_codepoint_t right_glyph HB_UNUSED,
347 void *user_data HB_UNUSED)
352 hb_font_get_glyph_h_kerning_default (hb_font_t *font,
353 void *font_data HB_UNUSED,
354 hb_codepoint_t left_glyph,
355 hb_codepoint_t right_glyph,
356 void *user_data HB_UNUSED)
358 return font->parent_scale_x_distance (font->parent->get_glyph_h_kerning (left_glyph, right_glyph));
361 #ifndef HB_DISABLE_DEPRECATED
363 hb_font_get_glyph_v_kerning_nil (hb_font_t *font HB_UNUSED,
364 void *font_data HB_UNUSED,
365 hb_codepoint_t top_glyph HB_UNUSED,
366 hb_codepoint_t bottom_glyph HB_UNUSED,
367 void *user_data HB_UNUSED)
372 hb_font_get_glyph_v_kerning_default (hb_font_t *font,
373 void *font_data HB_UNUSED,
374 hb_codepoint_t top_glyph,
375 hb_codepoint_t bottom_glyph,
376 void *user_data HB_UNUSED)
378 return font->parent_scale_y_distance (font->parent->get_glyph_v_kerning (top_glyph, bottom_glyph));
383 hb_font_get_glyph_extents_nil (hb_font_t *font HB_UNUSED,
384 void *font_data HB_UNUSED,
385 hb_codepoint_t glyph HB_UNUSED,
386 hb_glyph_extents_t *extents,
387 void *user_data HB_UNUSED)
389 memset (extents, 0, sizeof (*extents));
393 hb_font_get_glyph_extents_default (hb_font_t *font,
394 void *font_data HB_UNUSED,
395 hb_codepoint_t glyph,
396 hb_glyph_extents_t *extents,
397 void *user_data HB_UNUSED)
399 hb_bool_t ret = font->parent->get_glyph_extents (glyph, extents);
401 font->parent_scale_position (&extents->x_bearing, &extents->y_bearing);
402 font->parent_scale_distance (&extents->width, &extents->height);
408 hb_font_get_glyph_contour_point_nil (hb_font_t *font HB_UNUSED,
409 void *font_data HB_UNUSED,
410 hb_codepoint_t glyph HB_UNUSED,
411 unsigned int point_index HB_UNUSED,
414 void *user_data HB_UNUSED)
420 hb_font_get_glyph_contour_point_default (hb_font_t *font,
421 void *font_data HB_UNUSED,
422 hb_codepoint_t glyph,
423 unsigned int point_index,
426 void *user_data HB_UNUSED)
428 hb_bool_t ret = font->parent->get_glyph_contour_point (glyph, point_index, x, y);
430 font->parent_scale_position (x, y);
435 hb_font_get_glyph_name_nil (hb_font_t *font HB_UNUSED,
436 void *font_data HB_UNUSED,
437 hb_codepoint_t glyph HB_UNUSED,
438 char *name, unsigned int size,
439 void *user_data HB_UNUSED)
441 if (size) *name = '\0';
445 hb_font_get_glyph_name_default (hb_font_t *font,
446 void *font_data HB_UNUSED,
447 hb_codepoint_t glyph,
448 char *name, unsigned int size,
449 void *user_data HB_UNUSED)
451 return font->parent->get_glyph_name (glyph, name, size);
455 hb_font_get_glyph_from_name_nil (hb_font_t *font HB_UNUSED,
456 void *font_data HB_UNUSED,
457 const char *name HB_UNUSED,
458 int len HB_UNUSED, /* -1 means nul-terminated */
459 hb_codepoint_t *glyph,
460 void *user_data HB_UNUSED)
466 hb_font_get_glyph_from_name_default (hb_font_t *font,
467 void *font_data HB_UNUSED,
468 const char *name, int len, /* -1 means nul-terminated */
469 hb_codepoint_t *glyph,
470 void *user_data HB_UNUSED)
472 return font->parent->get_glyph_from_name (name, len, glyph);
475 DEFINE_NULL_INSTANCE (hb_font_funcs_t) =
477 HB_OBJECT_HEADER_STATIC,
480 #define HB_FONT_FUNC_IMPLEMENT(name) nullptr,
481 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
482 #undef HB_FONT_FUNC_IMPLEMENT
485 #define HB_FONT_FUNC_IMPLEMENT(name) nullptr,
486 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
487 #undef HB_FONT_FUNC_IMPLEMENT
491 #define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_nil,
492 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
493 #undef HB_FONT_FUNC_IMPLEMENT
498 static const hb_font_funcs_t _hb_font_funcs_default = {
499 HB_OBJECT_HEADER_STATIC,
502 #define HB_FONT_FUNC_IMPLEMENT(name) nullptr,
503 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
504 #undef HB_FONT_FUNC_IMPLEMENT
507 #define HB_FONT_FUNC_IMPLEMENT(name) nullptr,
508 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
509 #undef HB_FONT_FUNC_IMPLEMENT
513 #define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_default,
514 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
515 #undef HB_FONT_FUNC_IMPLEMENT
522 * hb_font_funcs_create: (Xconstructor)
526 * Return value: (transfer full):
531 hb_font_funcs_create ()
533 hb_font_funcs_t *ffuncs;
535 if (!(ffuncs = hb_object_create<hb_font_funcs_t> ()))
536 return hb_font_funcs_get_empty ();
538 ffuncs->get = _hb_font_funcs_default.get;
544 * hb_font_funcs_get_empty:
548 * Return value: (transfer full):
553 hb_font_funcs_get_empty ()
555 return const_cast<hb_font_funcs_t *> (&_hb_font_funcs_default);
559 * hb_font_funcs_reference: (skip)
560 * @ffuncs: font functions.
569 hb_font_funcs_reference (hb_font_funcs_t *ffuncs)
571 return hb_object_reference (ffuncs);
575 * hb_font_funcs_destroy: (skip)
576 * @ffuncs: font functions.
583 hb_font_funcs_destroy (hb_font_funcs_t *ffuncs)
585 if (!hb_object_destroy (ffuncs)) return;
587 #define HB_FONT_FUNC_IMPLEMENT(name) if (ffuncs->destroy.name) \
588 ffuncs->destroy.name (ffuncs->user_data.name);
589 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
590 #undef HB_FONT_FUNC_IMPLEMENT
596 * hb_font_funcs_set_user_data: (skip)
597 * @ffuncs: font functions.
610 hb_font_funcs_set_user_data (hb_font_funcs_t *ffuncs,
611 hb_user_data_key_t *key,
613 hb_destroy_func_t destroy,
616 return hb_object_set_user_data (ffuncs, key, data, destroy, replace);
620 * hb_font_funcs_get_user_data: (skip)
621 * @ffuncs: font functions.
626 * Return value: (transfer none):
631 hb_font_funcs_get_user_data (hb_font_funcs_t *ffuncs,
632 hb_user_data_key_t *key)
634 return hb_object_get_user_data (ffuncs, key);
639 * hb_font_funcs_make_immutable:
640 * @ffuncs: font functions.
647 hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs)
649 if (hb_object_is_immutable (ffuncs))
652 hb_object_make_immutable (ffuncs);
656 * hb_font_funcs_is_immutable:
657 * @ffuncs: font functions.
666 hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs)
668 return hb_object_is_immutable (ffuncs);
672 #define HB_FONT_FUNC_IMPLEMENT(name) \
675 hb_font_funcs_set_##name##_func (hb_font_funcs_t *ffuncs, \
676 hb_font_get_##name##_func_t func, \
678 hb_destroy_func_t destroy) \
680 if (hb_object_is_immutable (ffuncs)) \
683 destroy (user_data); \
687 if (ffuncs->destroy.name) \
688 ffuncs->destroy.name (ffuncs->user_data.name); \
691 ffuncs->get.f.name = func; \
692 ffuncs->user_data.name = user_data; \
693 ffuncs->destroy.name = destroy; \
695 ffuncs->get.f.name = hb_font_get_##name##_default; \
696 ffuncs->user_data.name = nullptr; \
697 ffuncs->destroy.name = nullptr; \
701 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
702 #undef HB_FONT_FUNC_IMPLEMENT
705 hb_font_t::has_func_set (unsigned int i)
707 return this->klass->get.array[i] != _hb_font_funcs_default.get.array[i];
711 hb_font_t::has_func (unsigned int i)
713 return has_func_set (i) ||
714 (parent && parent != &_hb_Null_hb_font_t && parent->has_func (i));
720 * hb_font_get_h_extents:
731 hb_font_get_h_extents (hb_font_t *font,
732 hb_font_extents_t *extents)
734 return font->get_font_h_extents (extents);
738 * hb_font_get_v_extents:
749 hb_font_get_v_extents (hb_font_t *font,
750 hb_font_extents_t *extents)
752 return font->get_font_v_extents (extents);
759 * @variation_selector:
769 hb_font_get_glyph (hb_font_t *font,
770 hb_codepoint_t unicode, hb_codepoint_t variation_selector,
771 hb_codepoint_t *glyph)
773 if (unlikely (variation_selector))
774 return font->get_variation_glyph (unicode, variation_selector, glyph);
775 return font->get_nominal_glyph (unicode, glyph);
779 * hb_font_get_nominal_glyph:
791 hb_font_get_nominal_glyph (hb_font_t *font,
792 hb_codepoint_t unicode,
793 hb_codepoint_t *glyph)
795 return font->get_nominal_glyph (unicode, glyph);
799 * hb_font_get_nominal_glyphs:
809 hb_font_get_nominal_glyphs (hb_font_t *font,
811 const hb_codepoint_t *first_unicode,
812 unsigned int unicode_stride,
813 hb_codepoint_t *first_glyph,
814 unsigned int glyph_stride)
816 return font->get_nominal_glyphs (count,
817 first_unicode, unicode_stride,
818 first_glyph, glyph_stride);
822 * hb_font_get_variation_glyph:
825 * @variation_selector:
835 hb_font_get_variation_glyph (hb_font_t *font,
836 hb_codepoint_t unicode, hb_codepoint_t variation_selector,
837 hb_codepoint_t *glyph)
839 return font->get_variation_glyph (unicode, variation_selector, glyph);
843 * hb_font_get_glyph_h_advance:
854 hb_font_get_glyph_h_advance (hb_font_t *font,
855 hb_codepoint_t glyph)
857 return font->get_glyph_h_advance (glyph);
861 * hb_font_get_glyph_v_advance:
872 hb_font_get_glyph_v_advance (hb_font_t *font,
873 hb_codepoint_t glyph)
875 return font->get_glyph_v_advance (glyph);
879 * hb_font_get_glyph_h_advances:
887 hb_font_get_glyph_h_advances (hb_font_t* font,
889 const hb_codepoint_t *first_glyph,
890 unsigned glyph_stride,
891 hb_position_t *first_advance,
892 unsigned advance_stride)
894 font->get_glyph_h_advances (count, first_glyph, glyph_stride, first_advance, advance_stride);
897 * hb_font_get_glyph_v_advances:
905 hb_font_get_glyph_v_advances (hb_font_t* font,
907 const hb_codepoint_t *first_glyph,
908 unsigned glyph_stride,
909 hb_position_t *first_advance,
910 unsigned advance_stride)
912 font->get_glyph_v_advances (count, first_glyph, glyph_stride, first_advance, advance_stride);
916 * hb_font_get_glyph_h_origin:
929 hb_font_get_glyph_h_origin (hb_font_t *font,
930 hb_codepoint_t glyph,
931 hb_position_t *x, hb_position_t *y)
933 return font->get_glyph_h_origin (glyph, x, y);
937 * hb_font_get_glyph_v_origin:
950 hb_font_get_glyph_v_origin (hb_font_t *font,
951 hb_codepoint_t glyph,
952 hb_position_t *x, hb_position_t *y)
954 return font->get_glyph_v_origin (glyph, x, y);
958 * hb_font_get_glyph_h_kerning:
970 hb_font_get_glyph_h_kerning (hb_font_t *font,
971 hb_codepoint_t left_glyph, hb_codepoint_t right_glyph)
973 return font->get_glyph_h_kerning (left_glyph, right_glyph);
976 #ifndef HB_DISABLE_DEPRECATED
978 * hb_font_get_glyph_v_kerning:
991 hb_font_get_glyph_v_kerning (hb_font_t *font,
992 hb_codepoint_t top_glyph, hb_codepoint_t bottom_glyph)
994 return font->get_glyph_v_kerning (top_glyph, bottom_glyph);
999 * hb_font_get_glyph_extents:
1011 hb_font_get_glyph_extents (hb_font_t *font,
1012 hb_codepoint_t glyph,
1013 hb_glyph_extents_t *extents)
1015 return font->get_glyph_extents (glyph, extents);
1019 * hb_font_get_glyph_contour_point:
1033 hb_font_get_glyph_contour_point (hb_font_t *font,
1034 hb_codepoint_t glyph, unsigned int point_index,
1035 hb_position_t *x, hb_position_t *y)
1037 return font->get_glyph_contour_point (glyph, point_index, x, y);
1041 * hb_font_get_glyph_name:
1044 * @name: (array length=size):
1054 hb_font_get_glyph_name (hb_font_t *font,
1055 hb_codepoint_t glyph,
1056 char *name, unsigned int size)
1058 return font->get_glyph_name (glyph, name, size);
1062 * hb_font_get_glyph_from_name:
1064 * @name: (array length=len):
1075 hb_font_get_glyph_from_name (hb_font_t *font,
1076 const char *name, int len, /* -1 means nul-terminated */
1077 hb_codepoint_t *glyph)
1079 return font->get_glyph_from_name (name, len, glyph);
1083 /* A bit higher-level, and with fallback */
1086 * hb_font_get_extents_for_direction:
1096 hb_font_get_extents_for_direction (hb_font_t *font,
1097 hb_direction_t direction,
1098 hb_font_extents_t *extents)
1100 return font->get_extents_for_direction (direction, extents);
1103 * hb_font_get_glyph_advance_for_direction:
1115 hb_font_get_glyph_advance_for_direction (hb_font_t *font,
1116 hb_codepoint_t glyph,
1117 hb_direction_t direction,
1118 hb_position_t *x, hb_position_t *y)
1120 return font->get_glyph_advance_for_direction (glyph, direction, x, y);
1123 * hb_font_get_glyph_advances_for_direction:
1132 hb_font_get_glyph_advances_for_direction (hb_font_t* font,
1133 hb_direction_t direction,
1135 const hb_codepoint_t *first_glyph,
1136 unsigned glyph_stride,
1137 hb_position_t *first_advance,
1138 unsigned advance_stride)
1140 font->get_glyph_advances_for_direction (direction, count, first_glyph, glyph_stride, first_advance, advance_stride);
1144 * hb_font_get_glyph_origin_for_direction:
1156 hb_font_get_glyph_origin_for_direction (hb_font_t *font,
1157 hb_codepoint_t glyph,
1158 hb_direction_t direction,
1159 hb_position_t *x, hb_position_t *y)
1161 return font->get_glyph_origin_for_direction (glyph, direction, x, y);
1165 * hb_font_add_glyph_origin_for_direction:
1177 hb_font_add_glyph_origin_for_direction (hb_font_t *font,
1178 hb_codepoint_t glyph,
1179 hb_direction_t direction,
1180 hb_position_t *x, hb_position_t *y)
1182 return font->add_glyph_origin_for_direction (glyph, direction, x, y);
1186 * hb_font_subtract_glyph_origin_for_direction:
1198 hb_font_subtract_glyph_origin_for_direction (hb_font_t *font,
1199 hb_codepoint_t glyph,
1200 hb_direction_t direction,
1201 hb_position_t *x, hb_position_t *y)
1203 return font->subtract_glyph_origin_for_direction (glyph, direction, x, y);
1207 * hb_font_get_glyph_kerning_for_direction:
1220 hb_font_get_glyph_kerning_for_direction (hb_font_t *font,
1221 hb_codepoint_t first_glyph, hb_codepoint_t second_glyph,
1222 hb_direction_t direction,
1223 hb_position_t *x, hb_position_t *y)
1225 return font->get_glyph_kerning_for_direction (first_glyph, second_glyph, direction, x, y);
1229 * hb_font_get_glyph_extents_for_origin:
1242 hb_font_get_glyph_extents_for_origin (hb_font_t *font,
1243 hb_codepoint_t glyph,
1244 hb_direction_t direction,
1245 hb_glyph_extents_t *extents)
1247 return font->get_glyph_extents_for_origin (glyph, direction, extents);
1251 * hb_font_get_glyph_contour_point_for_origin:
1266 hb_font_get_glyph_contour_point_for_origin (hb_font_t *font,
1267 hb_codepoint_t glyph, unsigned int point_index,
1268 hb_direction_t direction,
1269 hb_position_t *x, hb_position_t *y)
1271 return font->get_glyph_contour_point_for_origin (glyph, point_index, direction, x, y);
1274 /* Generates gidDDD if glyph has no name. */
1276 * hb_font_glyph_to_string:
1279 * @s: (array length=size):
1287 hb_font_glyph_to_string (hb_font_t *font,
1288 hb_codepoint_t glyph,
1289 char *s, unsigned int size)
1291 font->glyph_to_string (glyph, s, size);
1294 /* Parses gidDDD and uniUUUU strings automatically. */
1296 * hb_font_glyph_from_string:
1298 * @s: (array length=len) (element-type uint8_t):
1309 hb_font_glyph_from_string (hb_font_t *font,
1310 const char *s, int len, /* -1 means nul-terminated */
1311 hb_codepoint_t *glyph)
1313 return font->glyph_from_string (s, len, glyph);
1321 DEFINE_NULL_INSTANCE (hb_font_t) =
1323 HB_OBJECT_HEADER_STATIC,
1325 nullptr, /* parent */
1326 const_cast<hb_face_t *> (&_hb_Null_hb_face_t),
1338 nullptr, /* coords */
1339 nullptr, /* design_coords */
1341 const_cast<hb_font_funcs_t *> (&_hb_Null_hb_font_funcs_t),
1343 /* Zero for the rest is fine. */
1348 _hb_font_create (hb_face_t *face)
1352 if (unlikely (!face))
1353 face = hb_face_get_empty ();
1354 if (!(font = hb_object_create<hb_font_t> ()))
1355 return hb_font_get_empty ();
1357 hb_face_make_immutable (face);
1358 font->parent = hb_font_get_empty ();
1359 font->face = hb_face_reference (face);
1360 font->klass = hb_font_funcs_get_empty ();
1361 font->data.init0 (font);
1362 font->x_scale = font->y_scale = hb_face_get_upem (face);
1363 font->x_mult = font->y_mult = 1 << 16;
1369 * hb_font_create: (Xconstructor)
1374 * Return value: (transfer full):
1379 hb_font_create (hb_face_t *face)
1381 hb_font_t *font = _hb_font_create (face);
1383 #ifndef HB_NO_OT_FONT
1384 /* Install our in-house, very lightweight, funcs. */
1385 hb_ot_font_set_funcs (font);
1392 _hb_font_adopt_var_coords (hb_font_t *font,
1393 int *coords, /* 2.14 normalized */
1394 float *design_coords,
1395 unsigned int coords_length)
1397 free (font->coords);
1398 free (font->design_coords);
1400 font->coords = coords;
1401 font->design_coords = design_coords;
1402 font->num_coords = coords_length;
1406 * hb_font_create_sub_font:
1407 * @parent: parent font.
1411 * Return value: (transfer full):
1416 hb_font_create_sub_font (hb_font_t *parent)
1418 if (unlikely (!parent))
1419 parent = hb_font_get_empty ();
1421 hb_font_t *font = _hb_font_create (parent->face);
1423 if (unlikely (hb_object_is_immutable (font)))
1426 font->parent = hb_font_reference (parent);
1428 font->x_scale = parent->x_scale;
1429 font->y_scale = parent->y_scale;
1430 font->mults_changed ();
1431 font->x_ppem = parent->x_ppem;
1432 font->y_ppem = parent->y_ppem;
1433 font->ptem = parent->ptem;
1435 unsigned int num_coords = parent->num_coords;
1438 int *coords = (int *) calloc (num_coords, sizeof (parent->coords[0]));
1439 float *design_coords = (float *) calloc (num_coords, sizeof (parent->design_coords[0]));
1440 if (likely (coords && design_coords))
1442 memcpy (coords, parent->coords, num_coords * sizeof (parent->coords[0]));
1443 memcpy (design_coords, parent->design_coords, num_coords * sizeof (parent->design_coords[0]));
1444 _hb_font_adopt_var_coords (font, coords, design_coords, num_coords);
1449 free (design_coords);
1457 * hb_font_get_empty:
1461 * Return value: (transfer full)
1466 hb_font_get_empty ()
1468 return const_cast<hb_font_t *> (&Null (hb_font_t));
1472 * hb_font_reference: (skip)
1477 * Return value: (transfer full):
1482 hb_font_reference (hb_font_t *font)
1484 return hb_object_reference (font);
1488 * hb_font_destroy: (skip)
1496 hb_font_destroy (hb_font_t *font)
1498 if (!hb_object_destroy (font)) return;
1503 font->destroy (font->user_data);
1505 hb_font_destroy (font->parent);
1506 hb_face_destroy (font->face);
1507 hb_font_funcs_destroy (font->klass);
1509 free (font->coords);
1510 free (font->design_coords);
1516 * hb_font_set_user_data: (skip)
1530 hb_font_set_user_data (hb_font_t *font,
1531 hb_user_data_key_t *key,
1533 hb_destroy_func_t destroy,
1536 return hb_object_set_user_data (font, key, data, destroy, replace);
1540 * hb_font_get_user_data: (skip)
1546 * Return value: (transfer none):
1551 hb_font_get_user_data (hb_font_t *font,
1552 hb_user_data_key_t *key)
1554 return hb_object_get_user_data (font, key);
1558 * hb_font_make_immutable:
1566 hb_font_make_immutable (hb_font_t *font)
1568 if (hb_object_is_immutable (font))
1572 hb_font_make_immutable (font->parent);
1574 hb_object_make_immutable (font);
1578 * hb_font_is_immutable:
1588 hb_font_is_immutable (hb_font_t *font)
1590 return hb_object_is_immutable (font);
1594 * hb_font_set_parent:
1596 * @parent: new parent.
1598 * Sets parent font of @font.
1603 hb_font_set_parent (hb_font_t *font,
1606 if (hb_object_is_immutable (font))
1610 parent = hb_font_get_empty ();
1612 hb_font_t *old = font->parent;
1614 font->parent = hb_font_reference (parent);
1616 hb_font_destroy (old);
1620 * hb_font_get_parent:
1625 * Return value: (transfer none):
1630 hb_font_get_parent (hb_font_t *font)
1632 return font->parent;
1640 * Sets font-face of @font.
1645 hb_font_set_face (hb_font_t *font,
1648 if (hb_object_is_immutable (font))
1651 if (unlikely (!face))
1652 face = hb_face_get_empty ();
1654 hb_face_t *old = font->face;
1656 hb_face_make_immutable (face);
1657 font->face = hb_face_reference (face);
1658 font->mults_changed ();
1660 hb_face_destroy (old);
1669 * Return value: (transfer none):
1674 hb_font_get_face (hb_font_t *font)
1681 * hb_font_set_funcs:
1683 * @klass: (closure font_data) (destroy destroy) (scope notified):
1692 hb_font_set_funcs (hb_font_t *font,
1693 hb_font_funcs_t *klass,
1695 hb_destroy_func_t destroy)
1697 if (hb_object_is_immutable (font))
1700 destroy (font_data);
1705 font->destroy (font->user_data);
1708 klass = hb_font_funcs_get_empty ();
1710 hb_font_funcs_reference (klass);
1711 hb_font_funcs_destroy (font->klass);
1712 font->klass = klass;
1713 font->user_data = font_data;
1714 font->destroy = destroy;
1718 * hb_font_set_funcs_data:
1720 * @font_data: (destroy destroy) (scope notified):
1728 hb_font_set_funcs_data (hb_font_t *font,
1730 hb_destroy_func_t destroy)
1732 /* Destroy user_data? */
1733 if (hb_object_is_immutable (font))
1736 destroy (font_data);
1741 font->destroy (font->user_data);
1743 font->user_data = font_data;
1744 font->destroy = destroy;
1749 * hb_font_set_scale:
1759 hb_font_set_scale (hb_font_t *font,
1763 if (hb_object_is_immutable (font))
1766 font->x_scale = x_scale;
1767 font->y_scale = y_scale;
1768 font->mults_changed ();
1772 * hb_font_get_scale:
1782 hb_font_get_scale (hb_font_t *font,
1786 if (x_scale) *x_scale = font->x_scale;
1787 if (y_scale) *y_scale = font->y_scale;
1801 hb_font_set_ppem (hb_font_t *font,
1802 unsigned int x_ppem,
1803 unsigned int y_ppem)
1805 if (hb_object_is_immutable (font))
1808 font->x_ppem = x_ppem;
1809 font->y_ppem = y_ppem;
1823 hb_font_get_ppem (hb_font_t *font,
1824 unsigned int *x_ppem,
1825 unsigned int *y_ppem)
1827 if (x_ppem) *x_ppem = font->x_ppem;
1828 if (y_ppem) *y_ppem = font->y_ppem;
1834 * @ptem: font size in points.
1836 * Sets "point size" of the font. Set to 0 to unset.
1838 * There are 72 points in an inch.
1843 hb_font_set_ptem (hb_font_t *font, float ptem)
1845 if (hb_object_is_immutable (font))
1855 * Gets the "point size" of the font. A value of 0 means unset.
1857 * Return value: Point size.
1862 hb_font_get_ptem (hb_font_t *font)
1873 * hb_font_set_variations:
1878 hb_font_set_variations (hb_font_t *font,
1879 const hb_variation_t *variations,
1880 unsigned int variations_length)
1882 if (hb_object_is_immutable (font))
1885 if (!variations_length)
1887 hb_font_set_var_coords_normalized (font, nullptr, 0);
1891 unsigned int coords_length = hb_ot_var_get_axis_count (font->face);
1893 int *normalized = coords_length ? (int *) calloc (coords_length, sizeof (int)) : nullptr;
1894 float *design_coords = coords_length ? (float *) calloc (coords_length, sizeof (float)) : nullptr;
1896 if (unlikely (coords_length && !(normalized && design_coords)))
1899 free (design_coords);
1903 const OT::fvar &fvar = *font->face->table.fvar;
1904 for (unsigned int i = 0; i < variations_length; i++)
1906 hb_ot_var_axis_info_t info;
1907 if (hb_ot_var_find_axis_info (font->face, variations[i].tag, &info) &&
1908 info.axis_index < coords_length)
1910 float v = variations[i].value;
1911 design_coords[info.axis_index] = v;
1912 normalized[info.axis_index] = fvar.normalize_axis_value (info.axis_index, v);
1915 font->face->table.avar->map_coords (normalized, coords_length);
1917 _hb_font_adopt_var_coords (font, normalized, design_coords, coords_length);
1921 * hb_font_set_var_coords_design:
1926 hb_font_set_var_coords_design (hb_font_t *font,
1927 const float *coords,
1928 unsigned int coords_length)
1930 if (hb_object_is_immutable (font))
1933 int *normalized = coords_length ? (int *) calloc (coords_length, sizeof (int)) : nullptr;
1934 float *design_coords = coords_length ? (float *) calloc (coords_length, sizeof (float)) : nullptr;
1936 if (unlikely (coords_length && !(normalized && design_coords)))
1939 free (design_coords);
1944 memcpy (design_coords, coords, coords_length * sizeof (font->design_coords[0]));
1946 hb_ot_var_normalize_coords (font->face, coords_length, coords, normalized);
1947 _hb_font_adopt_var_coords (font, normalized, design_coords, coords_length);
1951 * hb_font_set_var_named_instance:
1953 * @instance_index: named instance index.
1955 * Sets design coords of a font from a named instance index.
1960 hb_font_set_var_named_instance (hb_font_t *font,
1961 unsigned instance_index)
1963 if (hb_object_is_immutable (font))
1966 unsigned int coords_length = hb_ot_var_named_instance_get_design_coords (font->face, instance_index, nullptr, nullptr);
1968 float *coords = coords_length ? (float *) calloc (coords_length, sizeof (float)) : nullptr;
1969 if (unlikely (coords_length && !coords))
1972 hb_ot_var_named_instance_get_design_coords (font->face, instance_index, &coords_length, coords);
1973 hb_font_set_var_coords_design (font, coords, coords_length);
1978 * hb_font_set_var_coords_normalized:
1983 hb_font_set_var_coords_normalized (hb_font_t *font,
1984 const int *coords, /* 2.14 normalized */
1985 unsigned int coords_length)
1987 if (hb_object_is_immutable (font))
1990 int *copy = coords_length ? (int *) calloc (coords_length, sizeof (coords[0])) : nullptr;
1991 int *unmapped = coords_length ? (int *) calloc (coords_length, sizeof (coords[0])) : nullptr;
1992 float *design_coords = coords_length ? (float *) calloc (coords_length, sizeof (design_coords[0])) : nullptr;
1994 if (unlikely (coords_length && !(copy && unmapped && design_coords)))
1998 free (design_coords);
2004 memcpy (copy, coords, coords_length * sizeof (coords[0]));
2005 memcpy (unmapped, coords, coords_length * sizeof (coords[0]));
2008 /* Best effort design coords simulation */
2009 font->face->table.avar->unmap_coords (unmapped, coords_length);
2010 for (unsigned int i = 0; i < coords_length; ++i)
2011 design_coords[i] = font->face->table.fvar->unnormalize_axis_value (i, unmapped[i]);
2014 _hb_font_adopt_var_coords (font, copy, design_coords, coords_length);
2018 * hb_font_get_var_coords_normalized:
2020 * Return value is valid as long as variation coordinates of the font
2026 hb_font_get_var_coords_normalized (hb_font_t *font,
2027 unsigned int *length)
2030 *length = font->num_coords;
2032 return font->coords;
2035 #ifdef HB_EXPERIMENTAL_API
2037 * hb_font_get_var_coords_design:
2039 * Return value is valid as long as variation coordinates of the font
2042 * Since: EXPERIMENTAL
2045 hb_font_get_var_coords_design (hb_font_t *font,
2046 unsigned int *length)
2049 *length = font->num_coords;
2051 return font->design_coords;
2056 #ifndef HB_DISABLE_DEPRECATED
2058 * Deprecated get_glyph_func():
2061 struct hb_trampoline_closure_t
2064 hb_destroy_func_t destroy;
2065 unsigned int ref_count;
2068 template <typename FuncType>
2069 struct hb_trampoline_t
2071 hb_trampoline_closure_t closure; /* Must be first. */
2075 template <typename FuncType>
2076 static hb_trampoline_t<FuncType> *
2077 trampoline_create (FuncType func,
2079 hb_destroy_func_t destroy)
2081 typedef hb_trampoline_t<FuncType> trampoline_t;
2083 trampoline_t *trampoline = (trampoline_t *) calloc (1, sizeof (trampoline_t));
2085 if (unlikely (!trampoline))
2088 trampoline->closure.user_data = user_data;
2089 trampoline->closure.destroy = destroy;
2090 trampoline->closure.ref_count = 1;
2091 trampoline->func = func;
2097 trampoline_reference (hb_trampoline_closure_t *closure)
2099 closure->ref_count++;
2103 trampoline_destroy (void *user_data)
2105 hb_trampoline_closure_t *closure = (hb_trampoline_closure_t *) user_data;
2107 if (--closure->ref_count)
2110 if (closure->destroy)
2111 closure->destroy (closure->user_data);
2115 typedef hb_trampoline_t<hb_font_get_glyph_func_t> hb_font_get_glyph_trampoline_t;
2118 hb_font_get_nominal_glyph_trampoline (hb_font_t *font,
2120 hb_codepoint_t unicode,
2121 hb_codepoint_t *glyph,
2124 hb_font_get_glyph_trampoline_t *trampoline = (hb_font_get_glyph_trampoline_t *) user_data;
2125 return trampoline->func (font, font_data, unicode, 0, glyph, trampoline->closure.user_data);
2129 hb_font_get_variation_glyph_trampoline (hb_font_t *font,
2131 hb_codepoint_t unicode,
2132 hb_codepoint_t variation_selector,
2133 hb_codepoint_t *glyph,
2136 hb_font_get_glyph_trampoline_t *trampoline = (hb_font_get_glyph_trampoline_t *) user_data;
2137 return trampoline->func (font, font_data, unicode, variation_selector, glyph, trampoline->closure.user_data);
2141 * hb_font_funcs_set_glyph_func:
2142 * @ffuncs: font functions.
2143 * @func: (closure user_data) (destroy destroy) (scope notified): callback function.
2144 * @user_data: data to pass to @func.
2145 * @destroy: function to call when @user_data is not needed anymore.
2147 * Deprecated. Use hb_font_funcs_set_nominal_glyph_func() and
2148 * hb_font_funcs_set_variation_glyph_func() instead.
2154 hb_font_funcs_set_glyph_func (hb_font_funcs_t *ffuncs,
2155 hb_font_get_glyph_func_t func,
2156 void *user_data, hb_destroy_func_t destroy)
2158 if (hb_object_is_immutable (ffuncs))
2161 destroy (user_data);
2165 hb_font_get_glyph_trampoline_t *trampoline;
2167 trampoline = trampoline_create (func, user_data, destroy);
2168 if (unlikely (!trampoline))
2171 destroy (user_data);
2175 hb_font_funcs_set_nominal_glyph_func (ffuncs,
2176 hb_font_get_nominal_glyph_trampoline,
2178 trampoline_destroy);
2180 trampoline_reference (&trampoline->closure);
2181 hb_font_funcs_set_variation_glyph_func (ffuncs,
2182 hb_font_get_variation_glyph_trampoline,
2184 trampoline_destroy);