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 return font->y_scale;
164 hb_font_get_glyph_v_advance_parent (hb_font_t *font,
165 void *font_data HB_UNUSED,
166 hb_codepoint_t glyph,
167 void *user_data HB_UNUSED)
169 return font->parent_scale_y_distance (font->parent->get_glyph_v_advance (glyph));
173 hb_font_get_glyph_h_origin_nil (hb_font_t *font HB_UNUSED,
174 void *font_data HB_UNUSED,
175 hb_codepoint_t glyph,
178 void *user_data HB_UNUSED)
184 hb_font_get_glyph_h_origin_parent (hb_font_t *font,
185 void *font_data HB_UNUSED,
186 hb_codepoint_t glyph,
189 void *user_data HB_UNUSED)
191 hb_bool_t ret = font->parent->get_glyph_h_origin (glyph, x, y);
193 font->parent_scale_position (x, y);
198 hb_font_get_glyph_v_origin_nil (hb_font_t *font HB_UNUSED,
199 void *font_data HB_UNUSED,
200 hb_codepoint_t glyph,
203 void *user_data HB_UNUSED)
209 hb_font_get_glyph_v_origin_parent (hb_font_t *font,
210 void *font_data HB_UNUSED,
211 hb_codepoint_t glyph,
214 void *user_data HB_UNUSED)
216 hb_bool_t ret = font->parent->get_glyph_v_origin (glyph, x, y);
218 font->parent_scale_position (x, y);
223 hb_font_get_glyph_h_kerning_nil (hb_font_t *font HB_UNUSED,
224 void *font_data HB_UNUSED,
225 hb_codepoint_t left_glyph,
226 hb_codepoint_t right_glyph,
227 void *user_data HB_UNUSED)
232 hb_font_get_glyph_h_kerning_parent (hb_font_t *font,
233 void *font_data HB_UNUSED,
234 hb_codepoint_t left_glyph,
235 hb_codepoint_t right_glyph,
236 void *user_data HB_UNUSED)
238 return font->parent_scale_x_distance (font->parent->get_glyph_h_kerning (left_glyph, right_glyph));
242 hb_font_get_glyph_v_kerning_nil (hb_font_t *font HB_UNUSED,
243 void *font_data HB_UNUSED,
244 hb_codepoint_t top_glyph,
245 hb_codepoint_t bottom_glyph,
246 void *user_data HB_UNUSED)
251 hb_font_get_glyph_v_kerning_parent (hb_font_t *font,
252 void *font_data HB_UNUSED,
253 hb_codepoint_t top_glyph,
254 hb_codepoint_t bottom_glyph,
255 void *user_data HB_UNUSED)
257 return font->parent_scale_y_distance (font->parent->get_glyph_v_kerning (top_glyph, bottom_glyph));
261 hb_font_get_glyph_extents_nil (hb_font_t *font HB_UNUSED,
262 void *font_data HB_UNUSED,
263 hb_codepoint_t glyph,
264 hb_glyph_extents_t *extents,
265 void *user_data HB_UNUSED)
267 memset (extents, 0, sizeof (*extents));
271 hb_font_get_glyph_extents_parent (hb_font_t *font,
272 void *font_data HB_UNUSED,
273 hb_codepoint_t glyph,
274 hb_glyph_extents_t *extents,
275 void *user_data HB_UNUSED)
277 hb_bool_t ret = font->parent->get_glyph_extents (glyph, extents);
279 font->parent_scale_position (&extents->x_bearing, &extents->y_bearing);
280 font->parent_scale_distance (&extents->width, &extents->height);
286 hb_font_get_glyph_contour_point_nil (hb_font_t *font HB_UNUSED,
287 void *font_data HB_UNUSED,
288 hb_codepoint_t glyph,
289 unsigned int point_index,
292 void *user_data HB_UNUSED)
298 hb_font_get_glyph_contour_point_parent (hb_font_t *font,
299 void *font_data HB_UNUSED,
300 hb_codepoint_t glyph,
301 unsigned int point_index,
304 void *user_data HB_UNUSED)
306 hb_bool_t ret = font->parent->get_glyph_contour_point (glyph, point_index, x, y);
308 font->parent_scale_position (x, y);
313 hb_font_get_glyph_name_nil (hb_font_t *font HB_UNUSED,
314 void *font_data HB_UNUSED,
315 hb_codepoint_t glyph,
316 char *name, unsigned int size,
317 void *user_data HB_UNUSED)
319 if (size) *name = '\0';
323 hb_font_get_glyph_name_parent (hb_font_t *font,
324 void *font_data HB_UNUSED,
325 hb_codepoint_t glyph,
326 char *name, unsigned int size,
327 void *user_data HB_UNUSED)
329 return font->parent->get_glyph_name (glyph, name, size);
333 hb_font_get_glyph_from_name_nil (hb_font_t *font HB_UNUSED,
334 void *font_data HB_UNUSED,
335 const char *name, int len, /* -1 means nul-terminated */
336 hb_codepoint_t *glyph,
337 void *user_data HB_UNUSED)
343 hb_font_get_glyph_from_name_parent (hb_font_t *font,
344 void *font_data HB_UNUSED,
345 const char *name, int len, /* -1 means nul-terminated */
346 hb_codepoint_t *glyph,
347 void *user_data HB_UNUSED)
349 return font->parent->get_glyph_from_name (name, len, glyph);
352 static const hb_font_funcs_t _hb_font_funcs_nil = {
353 HB_OBJECT_HEADER_STATIC,
355 true, /* immutable */
358 #define HB_FONT_FUNC_IMPLEMENT(name) NULL,
359 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
360 #undef HB_FONT_FUNC_IMPLEMENT
363 #define HB_FONT_FUNC_IMPLEMENT(name) NULL,
364 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
365 #undef HB_FONT_FUNC_IMPLEMENT
369 #define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_nil,
370 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
371 #undef HB_FONT_FUNC_IMPLEMENT
375 static const hb_font_funcs_t _hb_font_funcs_parent = {
376 HB_OBJECT_HEADER_STATIC,
378 true, /* immutable */
381 #define HB_FONT_FUNC_IMPLEMENT(name) NULL,
382 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
383 #undef HB_FONT_FUNC_IMPLEMENT
386 #define HB_FONT_FUNC_IMPLEMENT(name) NULL,
387 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
388 #undef HB_FONT_FUNC_IMPLEMENT
392 #define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_parent,
393 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
394 #undef HB_FONT_FUNC_IMPLEMENT
401 * hb_font_funcs_create: (Xconstructor)
405 * Return value: (transfer full):
410 hb_font_funcs_create (void)
412 hb_font_funcs_t *ffuncs;
414 if (!(ffuncs = hb_object_create<hb_font_funcs_t> ()))
415 return hb_font_funcs_get_empty ();
417 ffuncs->get = _hb_font_funcs_parent.get;
423 * hb_font_funcs_get_empty:
427 * Return value: (transfer full):
432 hb_font_funcs_get_empty (void)
434 return const_cast<hb_font_funcs_t *> (&_hb_font_funcs_parent);
438 * hb_font_funcs_reference: (skip)
439 * @ffuncs: font functions.
448 hb_font_funcs_reference (hb_font_funcs_t *ffuncs)
450 return hb_object_reference (ffuncs);
454 * hb_font_funcs_destroy: (skip)
455 * @ffuncs: font functions.
462 hb_font_funcs_destroy (hb_font_funcs_t *ffuncs)
464 if (!hb_object_destroy (ffuncs)) return;
466 #define HB_FONT_FUNC_IMPLEMENT(name) if (ffuncs->destroy.name) \
467 ffuncs->destroy.name (ffuncs->user_data.name);
468 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
469 #undef HB_FONT_FUNC_IMPLEMENT
475 * hb_font_funcs_set_user_data: (skip)
476 * @ffuncs: font functions.
489 hb_font_funcs_set_user_data (hb_font_funcs_t *ffuncs,
490 hb_user_data_key_t *key,
492 hb_destroy_func_t destroy,
495 return hb_object_set_user_data (ffuncs, key, data, destroy, replace);
499 * hb_font_funcs_get_user_data: (skip)
500 * @ffuncs: font functions.
505 * Return value: (transfer none):
510 hb_font_funcs_get_user_data (hb_font_funcs_t *ffuncs,
511 hb_user_data_key_t *key)
513 return hb_object_get_user_data (ffuncs, key);
518 * hb_font_funcs_make_immutable:
519 * @ffuncs: font functions.
526 hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs)
528 if (unlikely (hb_object_is_inert (ffuncs)))
531 ffuncs->immutable = true;
535 * hb_font_funcs_is_immutable:
536 * @ffuncs: font functions.
545 hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs)
547 return ffuncs->immutable;
551 #define HB_FONT_FUNC_IMPLEMENT(name) \
554 hb_font_funcs_set_##name##_func (hb_font_funcs_t *ffuncs, \
555 hb_font_get_##name##_func_t func, \
557 hb_destroy_func_t destroy) \
559 if (ffuncs->immutable) { \
561 destroy (user_data); \
565 if (ffuncs->destroy.name) \
566 ffuncs->destroy.name (ffuncs->user_data.name); \
569 ffuncs->get.f.name = func; \
570 ffuncs->user_data.name = user_data; \
571 ffuncs->destroy.name = destroy; \
573 ffuncs->get.f.name = hb_font_get_##name##_parent; \
574 ffuncs->user_data.name = NULL; \
575 ffuncs->destroy.name = NULL; \
579 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
580 #undef HB_FONT_FUNC_IMPLEMENT
583 hb_font_t::has_func (unsigned int i)
585 if (parent && parent != hb_font_get_empty () && parent->has_func (i))
587 return this->klass->get.array[i] != _hb_font_funcs_parent.get.array[i];
593 * hb_font_get_h_extents:
604 hb_font_get_h_extents (hb_font_t *font,
605 hb_font_extents_t *extents)
607 return font->get_font_h_extents (extents);
611 * hb_font_get_v_extents:
622 hb_font_get_v_extents (hb_font_t *font,
623 hb_font_extents_t *extents)
625 return font->get_font_v_extents (extents);
632 * @variation_selector:
642 hb_font_get_glyph (hb_font_t *font,
643 hb_codepoint_t unicode, hb_codepoint_t variation_selector,
644 hb_codepoint_t *glyph)
646 if (unlikely (variation_selector))
647 return font->get_variation_glyph (unicode, variation_selector, glyph);
648 return font->get_nominal_glyph (unicode, glyph);
652 * hb_font_get_nominal_glyph:
664 hb_font_get_nominal_glyph (hb_font_t *font,
665 hb_codepoint_t unicode,
666 hb_codepoint_t *glyph)
668 return font->get_nominal_glyph (unicode, glyph);
672 * hb_font_get_variation_glyph:
675 * @variation_selector:
685 hb_font_get_variation_glyph (hb_font_t *font,
686 hb_codepoint_t unicode, hb_codepoint_t variation_selector,
687 hb_codepoint_t *glyph)
689 return font->get_variation_glyph (unicode, variation_selector, glyph);
693 * hb_font_get_glyph_h_advance:
704 hb_font_get_glyph_h_advance (hb_font_t *font,
705 hb_codepoint_t glyph)
707 return font->get_glyph_h_advance (glyph);
711 * hb_font_get_glyph_v_advance:
722 hb_font_get_glyph_v_advance (hb_font_t *font,
723 hb_codepoint_t glyph)
725 return font->get_glyph_v_advance (glyph);
729 * hb_font_get_glyph_h_origin:
742 hb_font_get_glyph_h_origin (hb_font_t *font,
743 hb_codepoint_t glyph,
744 hb_position_t *x, hb_position_t *y)
746 return font->get_glyph_h_origin (glyph, x, y);
750 * hb_font_get_glyph_v_origin:
763 hb_font_get_glyph_v_origin (hb_font_t *font,
764 hb_codepoint_t glyph,
765 hb_position_t *x, hb_position_t *y)
767 return font->get_glyph_v_origin (glyph, x, y);
771 * hb_font_get_glyph_h_kerning:
783 hb_font_get_glyph_h_kerning (hb_font_t *font,
784 hb_codepoint_t left_glyph, hb_codepoint_t right_glyph)
786 return font->get_glyph_h_kerning (left_glyph, right_glyph);
790 * hb_font_get_glyph_v_kerning:
802 hb_font_get_glyph_v_kerning (hb_font_t *font,
803 hb_codepoint_t top_glyph, hb_codepoint_t bottom_glyph)
805 return font->get_glyph_v_kerning (top_glyph, bottom_glyph);
809 * hb_font_get_glyph_extents:
821 hb_font_get_glyph_extents (hb_font_t *font,
822 hb_codepoint_t glyph,
823 hb_glyph_extents_t *extents)
825 return font->get_glyph_extents (glyph, extents);
829 * hb_font_get_glyph_contour_point:
843 hb_font_get_glyph_contour_point (hb_font_t *font,
844 hb_codepoint_t glyph, unsigned int point_index,
845 hb_position_t *x, hb_position_t *y)
847 return font->get_glyph_contour_point (glyph, point_index, x, y);
851 * hb_font_get_glyph_name:
854 * @name: (array length=size):
864 hb_font_get_glyph_name (hb_font_t *font,
865 hb_codepoint_t glyph,
866 char *name, unsigned int size)
868 return font->get_glyph_name (glyph, name, size);
872 * hb_font_get_glyph_from_name:
874 * @name: (array length=len):
885 hb_font_get_glyph_from_name (hb_font_t *font,
886 const char *name, int len, /* -1 means nul-terminated */
887 hb_codepoint_t *glyph)
889 return font->get_glyph_from_name (name, len, glyph);
893 /* A bit higher-level, and with fallback */
896 * hb_font_get_extents_for_direction:
906 hb_font_get_extents_for_direction (hb_font_t *font,
907 hb_direction_t direction,
908 hb_font_extents_t *extents)
910 return font->get_extents_for_direction (direction, extents);
913 * hb_font_get_glyph_advance_for_direction:
925 hb_font_get_glyph_advance_for_direction (hb_font_t *font,
926 hb_codepoint_t glyph,
927 hb_direction_t direction,
928 hb_position_t *x, hb_position_t *y)
930 return font->get_glyph_advance_for_direction (glyph, direction, x, y);
934 * hb_font_get_glyph_origin_for_direction:
946 hb_font_get_glyph_origin_for_direction (hb_font_t *font,
947 hb_codepoint_t glyph,
948 hb_direction_t direction,
949 hb_position_t *x, hb_position_t *y)
951 return font->get_glyph_origin_for_direction (glyph, direction, x, y);
955 * hb_font_add_glyph_origin_for_direction:
967 hb_font_add_glyph_origin_for_direction (hb_font_t *font,
968 hb_codepoint_t glyph,
969 hb_direction_t direction,
970 hb_position_t *x, hb_position_t *y)
972 return font->add_glyph_origin_for_direction (glyph, direction, x, y);
976 * hb_font_subtract_glyph_origin_for_direction:
988 hb_font_subtract_glyph_origin_for_direction (hb_font_t *font,
989 hb_codepoint_t glyph,
990 hb_direction_t direction,
991 hb_position_t *x, hb_position_t *y)
993 return font->subtract_glyph_origin_for_direction (glyph, direction, x, y);
997 * hb_font_get_glyph_kerning_for_direction:
1010 hb_font_get_glyph_kerning_for_direction (hb_font_t *font,
1011 hb_codepoint_t first_glyph, hb_codepoint_t second_glyph,
1012 hb_direction_t direction,
1013 hb_position_t *x, hb_position_t *y)
1015 return font->get_glyph_kerning_for_direction (first_glyph, second_glyph, direction, x, y);
1019 * hb_font_get_glyph_extents_for_origin:
1032 hb_font_get_glyph_extents_for_origin (hb_font_t *font,
1033 hb_codepoint_t glyph,
1034 hb_direction_t direction,
1035 hb_glyph_extents_t *extents)
1037 return font->get_glyph_extents_for_origin (glyph, direction, extents);
1041 * hb_font_get_glyph_contour_point_for_origin:
1056 hb_font_get_glyph_contour_point_for_origin (hb_font_t *font,
1057 hb_codepoint_t glyph, unsigned int point_index,
1058 hb_direction_t direction,
1059 hb_position_t *x, hb_position_t *y)
1061 return font->get_glyph_contour_point_for_origin (glyph, point_index, direction, x, y);
1064 /* Generates gidDDD if glyph has no name. */
1066 * hb_font_glyph_to_string:
1069 * @s: (array length=size):
1077 hb_font_glyph_to_string (hb_font_t *font,
1078 hb_codepoint_t glyph,
1079 char *s, unsigned int size)
1081 font->glyph_to_string (glyph, s, size);
1084 /* Parses gidDDD and uniUUUU strings automatically. */
1086 * hb_font_glyph_from_string:
1088 * @s: (array length=len) (element-type uint8_t):
1099 hb_font_glyph_from_string (hb_font_t *font,
1100 const char *s, int len, /* -1 means nul-terminated */
1101 hb_codepoint_t *glyph)
1103 return font->glyph_from_string (s, len, glyph);
1112 * hb_font_create: (Xconstructor)
1117 * Return value: (transfer full):
1122 hb_font_create (hb_face_t *face)
1126 if (unlikely (!face))
1127 face = hb_face_get_empty ();
1128 if (!(font = hb_object_create<hb_font_t> ()))
1129 return hb_font_get_empty ();
1131 hb_face_make_immutable (face);
1132 font->parent = hb_font_get_empty ();
1133 font->face = hb_face_reference (face);
1134 font->klass = hb_font_funcs_get_empty ();
1136 font->x_scale = font->y_scale = hb_face_get_upem (face);
1142 * hb_font_create_sub_font:
1143 * @parent: parent font.
1147 * Return value: (transfer full):
1152 hb_font_create_sub_font (hb_font_t *parent)
1154 if (unlikely (!parent))
1155 parent = hb_font_get_empty ();
1157 hb_font_t *font = hb_font_create (parent->face);
1159 if (unlikely (hb_object_is_inert (font)))
1162 font->parent = hb_font_reference (parent);
1164 font->x_scale = parent->x_scale;
1165 font->y_scale = parent->y_scale;
1166 font->x_ppem = parent->x_ppem;
1167 font->y_ppem = parent->y_ppem;
1173 * hb_font_get_empty:
1177 * Return value: (transfer full)
1182 hb_font_get_empty (void)
1184 static const hb_font_t _hb_font_nil = {
1185 HB_OBJECT_HEADER_STATIC,
1187 true, /* immutable */
1190 const_cast<hb_face_t *> (&_hb_face_nil),
1198 const_cast<hb_font_funcs_t *> (&_hb_font_funcs_nil), /* klass */
1199 NULL, /* user_data */
1203 #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID,
1204 #include "hb-shaper-list.hh"
1205 #undef HB_SHAPER_IMPLEMENT
1209 return const_cast<hb_font_t *> (&_hb_font_nil);
1213 * hb_font_reference: (skip)
1218 * Return value: (transfer full):
1223 hb_font_reference (hb_font_t *font)
1225 return hb_object_reference (font);
1229 * hb_font_destroy: (skip)
1237 hb_font_destroy (hb_font_t *font)
1239 if (!hb_object_destroy (font)) return;
1241 #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_DESTROY(shaper, font);
1242 #include "hb-shaper-list.hh"
1243 #undef HB_SHAPER_IMPLEMENT
1246 font->destroy (font->user_data);
1248 hb_font_destroy (font->parent);
1249 hb_face_destroy (font->face);
1250 hb_font_funcs_destroy (font->klass);
1256 * hb_font_set_user_data: (skip)
1270 hb_font_set_user_data (hb_font_t *font,
1271 hb_user_data_key_t *key,
1273 hb_destroy_func_t destroy,
1276 return hb_object_set_user_data (font, key, data, destroy, replace);
1280 * hb_font_get_user_data: (skip)
1286 * Return value: (transfer none):
1291 hb_font_get_user_data (hb_font_t *font,
1292 hb_user_data_key_t *key)
1294 return hb_object_get_user_data (font, key);
1298 * hb_font_make_immutable:
1306 hb_font_make_immutable (hb_font_t *font)
1308 if (unlikely (hb_object_is_inert (font)))
1312 hb_font_make_immutable (font->parent);
1314 font->immutable = true;
1318 * hb_font_is_immutable:
1328 hb_font_is_immutable (hb_font_t *font)
1330 return font->immutable;
1334 * hb_font_set_parent:
1336 * @parent: new parent.
1338 * Sets parent font of @font.
1343 hb_font_set_parent (hb_font_t *font,
1346 if (font->immutable)
1350 parent = hb_font_get_empty ();
1352 hb_font_t *old = font->parent;
1354 font->parent = hb_font_reference (parent);
1356 hb_font_destroy (old);
1360 * hb_font_get_parent:
1365 * Return value: (transfer none):
1370 hb_font_get_parent (hb_font_t *font)
1372 return font->parent;
1381 * Return value: (transfer none):
1386 hb_font_get_face (hb_font_t *font)
1393 * hb_font_set_funcs:
1395 * @klass: (closure font_data) (destroy destroy) (scope notified):
1404 hb_font_set_funcs (hb_font_t *font,
1405 hb_font_funcs_t *klass,
1407 hb_destroy_func_t destroy)
1409 if (font->immutable) {
1411 destroy (font_data);
1416 font->destroy (font->user_data);
1419 klass = hb_font_funcs_get_empty ();
1421 hb_font_funcs_reference (klass);
1422 hb_font_funcs_destroy (font->klass);
1423 font->klass = klass;
1424 font->user_data = font_data;
1425 font->destroy = destroy;
1429 * hb_font_set_funcs_data:
1431 * @font_data: (destroy destroy) (scope notified):
1439 hb_font_set_funcs_data (hb_font_t *font,
1441 hb_destroy_func_t destroy)
1443 /* Destroy user_data? */
1444 if (font->immutable) {
1446 destroy (font_data);
1451 font->destroy (font->user_data);
1453 font->user_data = font_data;
1454 font->destroy = destroy;
1459 * hb_font_set_scale:
1469 hb_font_set_scale (hb_font_t *font,
1473 if (font->immutable)
1476 font->x_scale = x_scale;
1477 font->y_scale = y_scale;
1481 * hb_font_get_scale:
1491 hb_font_get_scale (hb_font_t *font,
1495 if (x_scale) *x_scale = font->x_scale;
1496 if (y_scale) *y_scale = font->y_scale;
1510 hb_font_set_ppem (hb_font_t *font,
1511 unsigned int x_ppem,
1512 unsigned int y_ppem)
1514 if (font->immutable)
1517 font->x_ppem = x_ppem;
1518 font->y_ppem = y_ppem;
1532 hb_font_get_ppem (hb_font_t *font,
1533 unsigned int *x_ppem,
1534 unsigned int *y_ppem)
1536 if (x_ppem) *x_ppem = font->x_ppem;
1537 if (y_ppem) *y_ppem = font->y_ppem;
1541 #ifndef HB_DISABLE_DEPRECATED
1544 * Deprecated get_glyph_func():
1547 struct hb_trampoline_closure_t
1550 hb_destroy_func_t destroy;
1551 unsigned int ref_count;
1554 template <typename FuncType>
1555 struct hb_trampoline_t
1557 hb_trampoline_closure_t closure; /* Must be first. */
1561 template <typename FuncType>
1562 static hb_trampoline_t<FuncType> *
1563 trampoline_create (FuncType func,
1565 hb_destroy_func_t destroy)
1567 typedef hb_trampoline_t<FuncType> trampoline_t;
1569 trampoline_t *trampoline = (trampoline_t *) calloc (1, sizeof (trampoline_t));
1571 if (unlikely (!trampoline))
1574 trampoline->closure.user_data = user_data;
1575 trampoline->closure.destroy = destroy;
1576 trampoline->closure.ref_count = 1;
1577 trampoline->func = func;
1583 trampoline_reference (hb_trampoline_closure_t *closure)
1585 closure->ref_count++;
1589 trampoline_destroy (void *user_data)
1591 hb_trampoline_closure_t *closure = (hb_trampoline_closure_t *) user_data;
1593 if (--closure->ref_count)
1596 if (closure->destroy)
1597 closure->destroy (closure->user_data);
1601 typedef hb_trampoline_t<hb_font_get_glyph_func_t> hb_font_get_glyph_trampoline_t;
1604 hb_font_get_nominal_glyph_trampoline (hb_font_t *font,
1606 hb_codepoint_t unicode,
1607 hb_codepoint_t *glyph,
1610 hb_font_get_glyph_trampoline_t *trampoline = (hb_font_get_glyph_trampoline_t *) user_data;
1611 return trampoline->func (font, font_data, unicode, 0, glyph, trampoline->closure.user_data);
1615 hb_font_get_variation_glyph_trampoline (hb_font_t *font,
1617 hb_codepoint_t unicode,
1618 hb_codepoint_t variation_selector,
1619 hb_codepoint_t *glyph,
1622 hb_font_get_glyph_trampoline_t *trampoline = (hb_font_get_glyph_trampoline_t *) user_data;
1623 return trampoline->func (font, font_data, unicode, variation_selector, glyph, trampoline->closure.user_data);
1627 * hb_font_funcs_set_glyph_func:
1628 * @ffuncs: font functions.
1629 * @func: (closure user_data) (destroy destroy) (scope notified):
1633 * Deprecated. Use hb_font_funcs_set_nominal_glyph_func() and
1634 * hb_font_funcs_set_variation_glyph_func() instead.
1640 hb_font_funcs_set_glyph_func (hb_font_funcs_t *ffuncs,
1641 hb_font_get_glyph_func_t func,
1642 void *user_data, hb_destroy_func_t destroy)
1644 hb_font_get_glyph_trampoline_t *trampoline;
1646 trampoline = trampoline_create (func, user_data, destroy);
1647 if (unlikely (!trampoline))
1650 destroy (user_data);
1654 hb_font_funcs_set_nominal_glyph_func (ffuncs,
1655 hb_font_get_nominal_glyph_trampoline,
1657 trampoline_destroy);
1659 trampoline_reference (&trampoline->closure);
1660 hb_font_funcs_set_variation_glyph_func (ffuncs,
1661 hb_font_get_variation_glyph_trampoline,
1663 trampoline_destroy);
1666 #endif /* HB_DISABLE_DEPRECATED */