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
29 #include "hb-private.hh"
31 #include "hb-ot-layout-private.hh"
33 #include "hb-font-private.hh"
34 #include "hb-open-file-private.hh"
35 #include "hb-ot-head-table.hh"
36 #include "hb-ot-maxp-table.hh"
38 #include "hb-cache-private.hh"
48 hb_font_get_font_h_extents_nil (hb_font_t *font,
49 void *font_data HB_UNUSED,
50 hb_font_extents_t *metrics,
51 void *user_data HB_UNUSED)
53 memset (metrics, 0, sizeof (*metrics));
57 hb_font_get_font_h_extents_parent (hb_font_t *font,
58 void *font_data HB_UNUSED,
59 hb_font_extents_t *metrics,
60 void *user_data HB_UNUSED)
62 hb_bool_t ret = font->parent->get_font_h_extents (metrics);
64 metrics->ascender = font->parent_scale_y_distance (metrics->ascender);
65 metrics->descender = font->parent_scale_y_distance (metrics->descender);
66 metrics->line_gap = font->parent_scale_y_distance (metrics->line_gap);
72 hb_font_get_font_v_extents_nil (hb_font_t *font,
73 void *font_data HB_UNUSED,
74 hb_font_extents_t *metrics,
75 void *user_data HB_UNUSED)
77 memset (metrics, 0, sizeof (*metrics));
81 hb_font_get_font_v_extents_parent (hb_font_t *font,
82 void *font_data HB_UNUSED,
83 hb_font_extents_t *metrics,
84 void *user_data HB_UNUSED)
86 hb_bool_t ret = font->parent->get_font_v_extents (metrics);
88 metrics->ascender = font->parent_scale_x_distance (metrics->ascender);
89 metrics->descender = font->parent_scale_x_distance (metrics->descender);
90 metrics->line_gap = font->parent_scale_x_distance (metrics->line_gap);
96 hb_font_get_nominal_glyph_nil (hb_font_t *font HB_UNUSED,
97 void *font_data HB_UNUSED,
98 hb_codepoint_t unicode,
99 hb_codepoint_t *glyph,
100 void *user_data HB_UNUSED)
106 hb_font_get_nominal_glyph_parent (hb_font_t *font,
107 void *font_data HB_UNUSED,
108 hb_codepoint_t unicode,
109 hb_codepoint_t *glyph,
110 void *user_data HB_UNUSED)
112 return font->parent->get_nominal_glyph (unicode, glyph);
116 hb_font_get_variation_glyph_nil (hb_font_t *font HB_UNUSED,
117 void *font_data HB_UNUSED,
118 hb_codepoint_t unicode,
119 hb_codepoint_t variation_selector,
120 hb_codepoint_t *glyph,
121 void *user_data HB_UNUSED)
127 hb_font_get_variation_glyph_parent (hb_font_t *font,
128 void *font_data HB_UNUSED,
129 hb_codepoint_t unicode,
130 hb_codepoint_t variation_selector,
131 hb_codepoint_t *glyph,
132 void *user_data HB_UNUSED)
134 return font->parent->get_variation_glyph (unicode, variation_selector, glyph);
139 hb_font_get_glyph_h_advance_nil (hb_font_t *font HB_UNUSED,
140 void *font_data HB_UNUSED,
141 hb_codepoint_t glyph,
142 void *user_data HB_UNUSED)
144 return font->x_scale;
147 hb_font_get_glyph_h_advance_parent (hb_font_t *font,
148 void *font_data HB_UNUSED,
149 hb_codepoint_t glyph,
150 void *user_data HB_UNUSED)
152 return font->parent_scale_x_distance (font->parent->get_glyph_h_advance (glyph));
156 hb_font_get_glyph_v_advance_nil (hb_font_t *font HB_UNUSED,
157 void *font_data HB_UNUSED,
158 hb_codepoint_t glyph,
159 void *user_data HB_UNUSED)
161 /* TODO use font_extents.ascender+descender */
162 return font->y_scale;
165 hb_font_get_glyph_v_advance_parent (hb_font_t *font,
166 void *font_data HB_UNUSED,
167 hb_codepoint_t glyph,
168 void *user_data HB_UNUSED)
170 return font->parent_scale_y_distance (font->parent->get_glyph_v_advance (glyph));
174 hb_font_get_glyph_h_origin_nil (hb_font_t *font HB_UNUSED,
175 void *font_data HB_UNUSED,
176 hb_codepoint_t glyph,
179 void *user_data HB_UNUSED)
185 hb_font_get_glyph_h_origin_parent (hb_font_t *font,
186 void *font_data HB_UNUSED,
187 hb_codepoint_t glyph,
190 void *user_data HB_UNUSED)
192 hb_bool_t ret = font->parent->get_glyph_h_origin (glyph, x, y);
194 font->parent_scale_position (x, y);
199 hb_font_get_glyph_v_origin_nil (hb_font_t *font HB_UNUSED,
200 void *font_data HB_UNUSED,
201 hb_codepoint_t glyph,
204 void *user_data HB_UNUSED)
210 hb_font_get_glyph_v_origin_parent (hb_font_t *font,
211 void *font_data HB_UNUSED,
212 hb_codepoint_t glyph,
215 void *user_data HB_UNUSED)
217 hb_bool_t ret = font->parent->get_glyph_v_origin (glyph, x, y);
219 font->parent_scale_position (x, y);
224 hb_font_get_glyph_h_kerning_nil (hb_font_t *font HB_UNUSED,
225 void *font_data HB_UNUSED,
226 hb_codepoint_t left_glyph,
227 hb_codepoint_t right_glyph,
228 void *user_data HB_UNUSED)
233 hb_font_get_glyph_h_kerning_parent (hb_font_t *font,
234 void *font_data HB_UNUSED,
235 hb_codepoint_t left_glyph,
236 hb_codepoint_t right_glyph,
237 void *user_data HB_UNUSED)
239 return font->parent_scale_x_distance (font->parent->get_glyph_h_kerning (left_glyph, right_glyph));
243 hb_font_get_glyph_v_kerning_nil (hb_font_t *font HB_UNUSED,
244 void *font_data HB_UNUSED,
245 hb_codepoint_t top_glyph,
246 hb_codepoint_t bottom_glyph,
247 void *user_data HB_UNUSED)
252 hb_font_get_glyph_v_kerning_parent (hb_font_t *font,
253 void *font_data HB_UNUSED,
254 hb_codepoint_t top_glyph,
255 hb_codepoint_t bottom_glyph,
256 void *user_data HB_UNUSED)
258 return font->parent_scale_y_distance (font->parent->get_glyph_v_kerning (top_glyph, bottom_glyph));
262 hb_font_get_glyph_extents_nil (hb_font_t *font HB_UNUSED,
263 void *font_data HB_UNUSED,
264 hb_codepoint_t glyph,
265 hb_glyph_extents_t *extents,
266 void *user_data HB_UNUSED)
268 memset (extents, 0, sizeof (*extents));
272 hb_font_get_glyph_extents_parent (hb_font_t *font,
273 void *font_data HB_UNUSED,
274 hb_codepoint_t glyph,
275 hb_glyph_extents_t *extents,
276 void *user_data HB_UNUSED)
278 hb_bool_t ret = font->parent->get_glyph_extents (glyph, extents);
280 font->parent_scale_position (&extents->x_bearing, &extents->y_bearing);
281 font->parent_scale_distance (&extents->width, &extents->height);
287 hb_font_get_glyph_contour_point_nil (hb_font_t *font HB_UNUSED,
288 void *font_data HB_UNUSED,
289 hb_codepoint_t glyph,
290 unsigned int point_index,
293 void *user_data HB_UNUSED)
299 hb_font_get_glyph_contour_point_parent (hb_font_t *font,
300 void *font_data HB_UNUSED,
301 hb_codepoint_t glyph,
302 unsigned int point_index,
305 void *user_data HB_UNUSED)
307 hb_bool_t ret = font->parent->get_glyph_contour_point (glyph, point_index, x, y);
309 font->parent_scale_position (x, y);
314 hb_font_get_glyph_name_nil (hb_font_t *font HB_UNUSED,
315 void *font_data HB_UNUSED,
316 hb_codepoint_t glyph,
317 char *name, unsigned int size,
318 void *user_data HB_UNUSED)
320 if (size) *name = '\0';
324 hb_font_get_glyph_name_parent (hb_font_t *font,
325 void *font_data HB_UNUSED,
326 hb_codepoint_t glyph,
327 char *name, unsigned int size,
328 void *user_data HB_UNUSED)
330 return font->parent->get_glyph_name (glyph, name, size);
334 hb_font_get_glyph_from_name_nil (hb_font_t *font HB_UNUSED,
335 void *font_data HB_UNUSED,
336 const char *name, int len, /* -1 means nul-terminated */
337 hb_codepoint_t *glyph,
338 void *user_data HB_UNUSED)
344 hb_font_get_glyph_from_name_parent (hb_font_t *font,
345 void *font_data HB_UNUSED,
346 const char *name, int len, /* -1 means nul-terminated */
347 hb_codepoint_t *glyph,
348 void *user_data HB_UNUSED)
350 return font->parent->get_glyph_from_name (name, len, glyph);
353 static const hb_font_funcs_t _hb_font_funcs_nil = {
354 HB_OBJECT_HEADER_STATIC,
356 true, /* immutable */
359 #define HB_FONT_FUNC_IMPLEMENT(name) NULL,
360 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
361 #undef HB_FONT_FUNC_IMPLEMENT
364 #define HB_FONT_FUNC_IMPLEMENT(name) NULL,
365 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
366 #undef HB_FONT_FUNC_IMPLEMENT
370 #define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_nil,
371 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
372 #undef HB_FONT_FUNC_IMPLEMENT
376 static const hb_font_funcs_t _hb_font_funcs_parent = {
377 HB_OBJECT_HEADER_STATIC,
379 true, /* immutable */
382 #define HB_FONT_FUNC_IMPLEMENT(name) NULL,
383 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
384 #undef HB_FONT_FUNC_IMPLEMENT
387 #define HB_FONT_FUNC_IMPLEMENT(name) NULL,
388 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
389 #undef HB_FONT_FUNC_IMPLEMENT
393 #define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_parent,
394 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
395 #undef HB_FONT_FUNC_IMPLEMENT
402 * hb_font_funcs_create: (Xconstructor)
406 * Return value: (transfer full):
411 hb_font_funcs_create (void)
413 hb_font_funcs_t *ffuncs;
415 if (!(ffuncs = hb_object_create<hb_font_funcs_t> ()))
416 return hb_font_funcs_get_empty ();
418 ffuncs->get = _hb_font_funcs_parent.get;
424 * hb_font_funcs_get_empty:
428 * Return value: (transfer full):
433 hb_font_funcs_get_empty (void)
435 return const_cast<hb_font_funcs_t *> (&_hb_font_funcs_parent);
439 * hb_font_funcs_reference: (skip)
440 * @ffuncs: font functions.
449 hb_font_funcs_reference (hb_font_funcs_t *ffuncs)
451 return hb_object_reference (ffuncs);
455 * hb_font_funcs_destroy: (skip)
456 * @ffuncs: font functions.
463 hb_font_funcs_destroy (hb_font_funcs_t *ffuncs)
465 if (!hb_object_destroy (ffuncs)) return;
467 #define HB_FONT_FUNC_IMPLEMENT(name) if (ffuncs->destroy.name) \
468 ffuncs->destroy.name (ffuncs->user_data.name);
469 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
470 #undef HB_FONT_FUNC_IMPLEMENT
476 * hb_font_funcs_set_user_data: (skip)
477 * @ffuncs: font functions.
490 hb_font_funcs_set_user_data (hb_font_funcs_t *ffuncs,
491 hb_user_data_key_t *key,
493 hb_destroy_func_t destroy,
496 return hb_object_set_user_data (ffuncs, key, data, destroy, replace);
500 * hb_font_funcs_get_user_data: (skip)
501 * @ffuncs: font functions.
506 * Return value: (transfer none):
511 hb_font_funcs_get_user_data (hb_font_funcs_t *ffuncs,
512 hb_user_data_key_t *key)
514 return hb_object_get_user_data (ffuncs, key);
519 * hb_font_funcs_make_immutable:
520 * @ffuncs: font functions.
527 hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs)
529 if (unlikely (hb_object_is_inert (ffuncs)))
532 ffuncs->immutable = true;
536 * hb_font_funcs_is_immutable:
537 * @ffuncs: font functions.
546 hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs)
548 return ffuncs->immutable;
552 #define HB_FONT_FUNC_IMPLEMENT(name) \
555 hb_font_funcs_set_##name##_func (hb_font_funcs_t *ffuncs, \
556 hb_font_get_##name##_func_t func, \
558 hb_destroy_func_t destroy) \
560 if (ffuncs->immutable) { \
562 destroy (user_data); \
566 if (ffuncs->destroy.name) \
567 ffuncs->destroy.name (ffuncs->user_data.name); \
570 ffuncs->get.f.name = func; \
571 ffuncs->user_data.name = user_data; \
572 ffuncs->destroy.name = destroy; \
574 ffuncs->get.f.name = hb_font_get_##name##_parent; \
575 ffuncs->user_data.name = NULL; \
576 ffuncs->destroy.name = NULL; \
580 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
581 #undef HB_FONT_FUNC_IMPLEMENT
584 hb_font_t::has_func (unsigned int i)
586 if (parent && parent != hb_font_get_empty () && parent->has_func (i))
588 return this->klass->get.array[i] != _hb_font_funcs_parent.get.array[i];
594 * hb_font_get_h_extents:
605 hb_font_get_h_extents (hb_font_t *font,
606 hb_font_extents_t *extents)
608 return font->get_font_h_extents (extents);
612 * hb_font_get_v_extents:
623 hb_font_get_v_extents (hb_font_t *font,
624 hb_font_extents_t *extents)
626 return font->get_font_v_extents (extents);
633 * @variation_selector:
643 hb_font_get_glyph (hb_font_t *font,
644 hb_codepoint_t unicode, hb_codepoint_t variation_selector,
645 hb_codepoint_t *glyph)
647 if (unlikely (variation_selector))
648 return font->get_variation_glyph (unicode, variation_selector, glyph);
649 return font->get_nominal_glyph (unicode, glyph);
653 * hb_font_get_nominal_glyph:
665 hb_font_get_nominal_glyph (hb_font_t *font,
666 hb_codepoint_t unicode,
667 hb_codepoint_t *glyph)
669 return font->get_nominal_glyph (unicode, glyph);
673 * hb_font_get_variation_glyph:
676 * @variation_selector:
686 hb_font_get_variation_glyph (hb_font_t *font,
687 hb_codepoint_t unicode, hb_codepoint_t variation_selector,
688 hb_codepoint_t *glyph)
690 return font->get_variation_glyph (unicode, variation_selector, glyph);
694 * hb_font_get_glyph_h_advance:
705 hb_font_get_glyph_h_advance (hb_font_t *font,
706 hb_codepoint_t glyph)
708 return font->get_glyph_h_advance (glyph);
712 * hb_font_get_glyph_v_advance:
723 hb_font_get_glyph_v_advance (hb_font_t *font,
724 hb_codepoint_t glyph)
726 return font->get_glyph_v_advance (glyph);
730 * hb_font_get_glyph_h_origin:
743 hb_font_get_glyph_h_origin (hb_font_t *font,
744 hb_codepoint_t glyph,
745 hb_position_t *x, hb_position_t *y)
747 return font->get_glyph_h_origin (glyph, x, y);
751 * hb_font_get_glyph_v_origin:
764 hb_font_get_glyph_v_origin (hb_font_t *font,
765 hb_codepoint_t glyph,
766 hb_position_t *x, hb_position_t *y)
768 return font->get_glyph_v_origin (glyph, x, y);
772 * hb_font_get_glyph_h_kerning:
784 hb_font_get_glyph_h_kerning (hb_font_t *font,
785 hb_codepoint_t left_glyph, hb_codepoint_t right_glyph)
787 return font->get_glyph_h_kerning (left_glyph, right_glyph);
791 * hb_font_get_glyph_v_kerning:
803 hb_font_get_glyph_v_kerning (hb_font_t *font,
804 hb_codepoint_t top_glyph, hb_codepoint_t bottom_glyph)
806 return font->get_glyph_v_kerning (top_glyph, bottom_glyph);
810 * hb_font_get_glyph_extents:
822 hb_font_get_glyph_extents (hb_font_t *font,
823 hb_codepoint_t glyph,
824 hb_glyph_extents_t *extents)
826 return font->get_glyph_extents (glyph, extents);
830 * hb_font_get_glyph_contour_point:
844 hb_font_get_glyph_contour_point (hb_font_t *font,
845 hb_codepoint_t glyph, unsigned int point_index,
846 hb_position_t *x, hb_position_t *y)
848 return font->get_glyph_contour_point (glyph, point_index, x, y);
852 * hb_font_get_glyph_name:
855 * @name: (array length=size):
865 hb_font_get_glyph_name (hb_font_t *font,
866 hb_codepoint_t glyph,
867 char *name, unsigned int size)
869 return font->get_glyph_name (glyph, name, size);
873 * hb_font_get_glyph_from_name:
875 * @name: (array length=len):
886 hb_font_get_glyph_from_name (hb_font_t *font,
887 const char *name, int len, /* -1 means nul-terminated */
888 hb_codepoint_t *glyph)
890 return font->get_glyph_from_name (name, len, glyph);
894 /* A bit higher-level, and with fallback */
897 * hb_font_get_extents_for_direction:
907 hb_font_get_extents_for_direction (hb_font_t *font,
908 hb_direction_t direction,
909 hb_font_extents_t *extents)
911 return font->get_extents_for_direction (direction, extents);
914 * hb_font_get_glyph_advance_for_direction:
926 hb_font_get_glyph_advance_for_direction (hb_font_t *font,
927 hb_codepoint_t glyph,
928 hb_direction_t direction,
929 hb_position_t *x, hb_position_t *y)
931 return font->get_glyph_advance_for_direction (glyph, direction, x, y);
935 * hb_font_get_glyph_origin_for_direction:
947 hb_font_get_glyph_origin_for_direction (hb_font_t *font,
948 hb_codepoint_t glyph,
949 hb_direction_t direction,
950 hb_position_t *x, hb_position_t *y)
952 return font->get_glyph_origin_for_direction (glyph, direction, x, y);
956 * hb_font_add_glyph_origin_for_direction:
968 hb_font_add_glyph_origin_for_direction (hb_font_t *font,
969 hb_codepoint_t glyph,
970 hb_direction_t direction,
971 hb_position_t *x, hb_position_t *y)
973 return font->add_glyph_origin_for_direction (glyph, direction, x, y);
977 * hb_font_subtract_glyph_origin_for_direction:
989 hb_font_subtract_glyph_origin_for_direction (hb_font_t *font,
990 hb_codepoint_t glyph,
991 hb_direction_t direction,
992 hb_position_t *x, hb_position_t *y)
994 return font->subtract_glyph_origin_for_direction (glyph, direction, x, y);
998 * hb_font_get_glyph_kerning_for_direction:
1011 hb_font_get_glyph_kerning_for_direction (hb_font_t *font,
1012 hb_codepoint_t first_glyph, hb_codepoint_t second_glyph,
1013 hb_direction_t direction,
1014 hb_position_t *x, hb_position_t *y)
1016 return font->get_glyph_kerning_for_direction (first_glyph, second_glyph, direction, x, y);
1020 * hb_font_get_glyph_extents_for_origin:
1033 hb_font_get_glyph_extents_for_origin (hb_font_t *font,
1034 hb_codepoint_t glyph,
1035 hb_direction_t direction,
1036 hb_glyph_extents_t *extents)
1038 return font->get_glyph_extents_for_origin (glyph, direction, extents);
1042 * hb_font_get_glyph_contour_point_for_origin:
1057 hb_font_get_glyph_contour_point_for_origin (hb_font_t *font,
1058 hb_codepoint_t glyph, unsigned int point_index,
1059 hb_direction_t direction,
1060 hb_position_t *x, hb_position_t *y)
1062 return font->get_glyph_contour_point_for_origin (glyph, point_index, direction, x, y);
1065 /* Generates gidDDD if glyph has no name. */
1067 * hb_font_glyph_to_string:
1070 * @s: (array length=size):
1078 hb_font_glyph_to_string (hb_font_t *font,
1079 hb_codepoint_t glyph,
1080 char *s, unsigned int size)
1082 font->glyph_to_string (glyph, s, size);
1085 /* Parses gidDDD and uniUUUU strings automatically. */
1087 * hb_font_glyph_from_string:
1089 * @s: (array length=len) (element-type uint8_t):
1100 hb_font_glyph_from_string (hb_font_t *font,
1101 const char *s, int len, /* -1 means nul-terminated */
1102 hb_codepoint_t *glyph)
1104 return font->glyph_from_string (s, len, glyph);
1113 * hb_font_create: (Xconstructor)
1118 * Return value: (transfer full):
1123 hb_font_create (hb_face_t *face)
1127 if (unlikely (!face))
1128 face = hb_face_get_empty ();
1129 if (!(font = hb_object_create<hb_font_t> ()))
1130 return hb_font_get_empty ();
1132 hb_face_make_immutable (face);
1133 font->parent = hb_font_get_empty ();
1134 font->face = hb_face_reference (face);
1135 font->klass = hb_font_funcs_get_empty ();
1137 font->x_scale = font->y_scale = hb_face_get_upem (face);
1143 * hb_font_create_sub_font:
1144 * @parent: parent font.
1148 * Return value: (transfer full):
1153 hb_font_create_sub_font (hb_font_t *parent)
1155 if (unlikely (!parent))
1156 parent = hb_font_get_empty ();
1158 hb_font_t *font = hb_font_create (parent->face);
1160 if (unlikely (hb_object_is_inert (font)))
1163 font->parent = hb_font_reference (parent);
1165 font->x_scale = parent->x_scale;
1166 font->y_scale = parent->y_scale;
1167 font->x_ppem = parent->x_ppem;
1168 font->y_ppem = parent->y_ppem;
1174 * hb_font_get_empty:
1178 * Return value: (transfer full)
1183 hb_font_get_empty (void)
1185 static const hb_font_t _hb_font_nil = {
1186 HB_OBJECT_HEADER_STATIC,
1188 true, /* immutable */
1191 const_cast<hb_face_t *> (&_hb_face_nil),
1199 const_cast<hb_font_funcs_t *> (&_hb_font_funcs_nil), /* klass */
1200 NULL, /* user_data */
1204 #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID,
1205 #include "hb-shaper-list.hh"
1206 #undef HB_SHAPER_IMPLEMENT
1210 return const_cast<hb_font_t *> (&_hb_font_nil);
1214 * hb_font_reference: (skip)
1219 * Return value: (transfer full):
1224 hb_font_reference (hb_font_t *font)
1226 return hb_object_reference (font);
1230 * hb_font_destroy: (skip)
1238 hb_font_destroy (hb_font_t *font)
1240 if (!hb_object_destroy (font)) return;
1242 #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_DESTROY(shaper, font);
1243 #include "hb-shaper-list.hh"
1244 #undef HB_SHAPER_IMPLEMENT
1247 font->destroy (font->user_data);
1249 hb_font_destroy (font->parent);
1250 hb_face_destroy (font->face);
1251 hb_font_funcs_destroy (font->klass);
1257 * hb_font_set_user_data: (skip)
1271 hb_font_set_user_data (hb_font_t *font,
1272 hb_user_data_key_t *key,
1274 hb_destroy_func_t destroy,
1277 return hb_object_set_user_data (font, key, data, destroy, replace);
1281 * hb_font_get_user_data: (skip)
1287 * Return value: (transfer none):
1292 hb_font_get_user_data (hb_font_t *font,
1293 hb_user_data_key_t *key)
1295 return hb_object_get_user_data (font, key);
1299 * hb_font_make_immutable:
1307 hb_font_make_immutable (hb_font_t *font)
1309 if (unlikely (hb_object_is_inert (font)))
1313 hb_font_make_immutable (font->parent);
1315 font->immutable = true;
1319 * hb_font_is_immutable:
1329 hb_font_is_immutable (hb_font_t *font)
1331 return font->immutable;
1335 * hb_font_set_parent:
1337 * @parent: new parent.
1339 * Sets parent font of @font.
1344 hb_font_set_parent (hb_font_t *font,
1347 if (font->immutable)
1351 parent = hb_font_get_empty ();
1353 hb_font_t *old = font->parent;
1355 font->parent = hb_font_reference (parent);
1357 hb_font_destroy (old);
1361 * hb_font_get_parent:
1366 * Return value: (transfer none):
1371 hb_font_get_parent (hb_font_t *font)
1373 return font->parent;
1382 * Return value: (transfer none):
1387 hb_font_get_face (hb_font_t *font)
1394 * hb_font_set_funcs:
1396 * @klass: (closure font_data) (destroy destroy) (scope notified):
1405 hb_font_set_funcs (hb_font_t *font,
1406 hb_font_funcs_t *klass,
1408 hb_destroy_func_t destroy)
1410 if (font->immutable) {
1412 destroy (font_data);
1417 font->destroy (font->user_data);
1420 klass = hb_font_funcs_get_empty ();
1422 hb_font_funcs_reference (klass);
1423 hb_font_funcs_destroy (font->klass);
1424 font->klass = klass;
1425 font->user_data = font_data;
1426 font->destroy = destroy;
1430 * hb_font_set_funcs_data:
1432 * @font_data: (destroy destroy) (scope notified):
1440 hb_font_set_funcs_data (hb_font_t *font,
1442 hb_destroy_func_t destroy)
1444 /* Destroy user_data? */
1445 if (font->immutable) {
1447 destroy (font_data);
1452 font->destroy (font->user_data);
1454 font->user_data = font_data;
1455 font->destroy = destroy;
1460 * hb_font_set_scale:
1470 hb_font_set_scale (hb_font_t *font,
1474 if (font->immutable)
1477 font->x_scale = x_scale;
1478 font->y_scale = y_scale;
1482 * hb_font_get_scale:
1492 hb_font_get_scale (hb_font_t *font,
1496 if (x_scale) *x_scale = font->x_scale;
1497 if (y_scale) *y_scale = font->y_scale;
1511 hb_font_set_ppem (hb_font_t *font,
1512 unsigned int x_ppem,
1513 unsigned int y_ppem)
1515 if (font->immutable)
1518 font->x_ppem = x_ppem;
1519 font->y_ppem = y_ppem;
1533 hb_font_get_ppem (hb_font_t *font,
1534 unsigned int *x_ppem,
1535 unsigned int *y_ppem)
1537 if (x_ppem) *x_ppem = font->x_ppem;
1538 if (y_ppem) *y_ppem = font->y_ppem;
1542 #ifndef HB_DISABLE_DEPRECATED
1545 * Deprecated get_glyph_func():
1548 struct hb_trampoline_closure_t
1551 hb_destroy_func_t destroy;
1552 unsigned int ref_count;
1555 template <typename FuncType>
1556 struct hb_trampoline_t
1558 hb_trampoline_closure_t closure; /* Must be first. */
1562 template <typename FuncType>
1563 static hb_trampoline_t<FuncType> *
1564 trampoline_create (FuncType func,
1566 hb_destroy_func_t destroy)
1568 typedef hb_trampoline_t<FuncType> trampoline_t;
1570 trampoline_t *trampoline = (trampoline_t *) calloc (1, sizeof (trampoline_t));
1572 if (unlikely (!trampoline))
1575 trampoline->closure.user_data = user_data;
1576 trampoline->closure.destroy = destroy;
1577 trampoline->closure.ref_count = 1;
1578 trampoline->func = func;
1584 trampoline_reference (hb_trampoline_closure_t *closure)
1586 closure->ref_count++;
1590 trampoline_destroy (void *user_data)
1592 hb_trampoline_closure_t *closure = (hb_trampoline_closure_t *) user_data;
1594 if (--closure->ref_count)
1597 if (closure->destroy)
1598 closure->destroy (closure->user_data);
1602 typedef hb_trampoline_t<hb_font_get_glyph_func_t> hb_font_get_glyph_trampoline_t;
1605 hb_font_get_nominal_glyph_trampoline (hb_font_t *font,
1607 hb_codepoint_t unicode,
1608 hb_codepoint_t *glyph,
1611 hb_font_get_glyph_trampoline_t *trampoline = (hb_font_get_glyph_trampoline_t *) user_data;
1612 return trampoline->func (font, font_data, unicode, 0, glyph, trampoline->closure.user_data);
1616 hb_font_get_variation_glyph_trampoline (hb_font_t *font,
1618 hb_codepoint_t unicode,
1619 hb_codepoint_t variation_selector,
1620 hb_codepoint_t *glyph,
1623 hb_font_get_glyph_trampoline_t *trampoline = (hb_font_get_glyph_trampoline_t *) user_data;
1624 return trampoline->func (font, font_data, unicode, variation_selector, glyph, trampoline->closure.user_data);
1628 * hb_font_funcs_set_glyph_func:
1629 * @ffuncs: font functions.
1630 * @func: (closure user_data) (destroy destroy) (scope notified):
1634 * Deprecated. Use hb_font_funcs_set_nominal_glyph_func() and
1635 * hb_font_funcs_set_variation_glyph_func() instead.
1641 hb_font_funcs_set_glyph_func (hb_font_funcs_t *ffuncs,
1642 hb_font_get_glyph_func_t func,
1643 void *user_data, hb_destroy_func_t destroy)
1645 hb_font_get_glyph_trampoline_t *trampoline;
1647 trampoline = trampoline_create (func, user_data, destroy);
1648 if (unlikely (!trampoline))
1651 destroy (user_data);
1655 hb_font_funcs_set_nominal_glyph_func (ffuncs,
1656 hb_font_get_nominal_glyph_trampoline,
1658 trampoline_destroy);
1660 trampoline_reference (&trampoline->closure);
1661 hb_font_funcs_set_variation_glyph_func (ffuncs,
1662 hb_font_get_variation_glyph_trampoline,
1664 trampoline_destroy);
1667 #endif /* HB_DISABLE_DEPRECATED */