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-font-private.hh"
39 hb_font_get_font_h_extents_nil (hb_font_t *font,
40 void *font_data HB_UNUSED,
41 hb_font_extents_t *metrics,
42 void *user_data HB_UNUSED)
44 memset (metrics, 0, sizeof (*metrics));
48 hb_font_get_font_h_extents_parent (hb_font_t *font,
49 void *font_data HB_UNUSED,
50 hb_font_extents_t *metrics,
51 void *user_data HB_UNUSED)
53 hb_bool_t ret = font->parent->get_font_h_extents (metrics);
55 metrics->ascender = font->parent_scale_y_distance (metrics->ascender);
56 metrics->descender = font->parent_scale_y_distance (metrics->descender);
57 metrics->line_gap = font->parent_scale_y_distance (metrics->line_gap);
63 hb_font_get_font_v_extents_nil (hb_font_t *font,
64 void *font_data HB_UNUSED,
65 hb_font_extents_t *metrics,
66 void *user_data HB_UNUSED)
68 memset (metrics, 0, sizeof (*metrics));
72 hb_font_get_font_v_extents_parent (hb_font_t *font,
73 void *font_data HB_UNUSED,
74 hb_font_extents_t *metrics,
75 void *user_data HB_UNUSED)
77 hb_bool_t ret = font->parent->get_font_v_extents (metrics);
79 metrics->ascender = font->parent_scale_x_distance (metrics->ascender);
80 metrics->descender = font->parent_scale_x_distance (metrics->descender);
81 metrics->line_gap = font->parent_scale_x_distance (metrics->line_gap);
87 hb_font_get_nominal_glyph_nil (hb_font_t *font HB_UNUSED,
88 void *font_data HB_UNUSED,
89 hb_codepoint_t unicode,
90 hb_codepoint_t *glyph,
91 void *user_data HB_UNUSED)
97 hb_font_get_nominal_glyph_parent (hb_font_t *font,
98 void *font_data HB_UNUSED,
99 hb_codepoint_t unicode,
100 hb_codepoint_t *glyph,
101 void *user_data HB_UNUSED)
103 return font->parent->get_nominal_glyph (unicode, glyph);
107 hb_font_get_variation_glyph_nil (hb_font_t *font HB_UNUSED,
108 void *font_data HB_UNUSED,
109 hb_codepoint_t unicode,
110 hb_codepoint_t variation_selector,
111 hb_codepoint_t *glyph,
112 void *user_data HB_UNUSED)
118 hb_font_get_variation_glyph_parent (hb_font_t *font,
119 void *font_data HB_UNUSED,
120 hb_codepoint_t unicode,
121 hb_codepoint_t variation_selector,
122 hb_codepoint_t *glyph,
123 void *user_data HB_UNUSED)
125 return font->parent->get_variation_glyph (unicode, variation_selector, glyph);
130 hb_font_get_glyph_h_advance_nil (hb_font_t *font HB_UNUSED,
131 void *font_data HB_UNUSED,
132 hb_codepoint_t glyph,
133 void *user_data HB_UNUSED)
135 return font->x_scale;
138 hb_font_get_glyph_h_advance_parent (hb_font_t *font,
139 void *font_data HB_UNUSED,
140 hb_codepoint_t glyph,
141 void *user_data HB_UNUSED)
143 return font->parent_scale_x_distance (font->parent->get_glyph_h_advance (glyph));
147 hb_font_get_glyph_v_advance_nil (hb_font_t *font HB_UNUSED,
148 void *font_data HB_UNUSED,
149 hb_codepoint_t glyph,
150 void *user_data HB_UNUSED)
152 /* TODO use font_extents.ascender+descender */
153 return font->y_scale;
156 hb_font_get_glyph_v_advance_parent (hb_font_t *font,
157 void *font_data HB_UNUSED,
158 hb_codepoint_t glyph,
159 void *user_data HB_UNUSED)
161 return font->parent_scale_y_distance (font->parent->get_glyph_v_advance (glyph));
165 hb_font_get_glyph_h_origin_nil (hb_font_t *font HB_UNUSED,
166 void *font_data HB_UNUSED,
167 hb_codepoint_t glyph,
170 void *user_data HB_UNUSED)
176 hb_font_get_glyph_h_origin_parent (hb_font_t *font,
177 void *font_data HB_UNUSED,
178 hb_codepoint_t glyph,
181 void *user_data HB_UNUSED)
183 hb_bool_t ret = font->parent->get_glyph_h_origin (glyph, x, y);
185 font->parent_scale_position (x, y);
190 hb_font_get_glyph_v_origin_nil (hb_font_t *font HB_UNUSED,
191 void *font_data HB_UNUSED,
192 hb_codepoint_t glyph,
195 void *user_data HB_UNUSED)
201 hb_font_get_glyph_v_origin_parent (hb_font_t *font,
202 void *font_data HB_UNUSED,
203 hb_codepoint_t glyph,
206 void *user_data HB_UNUSED)
208 hb_bool_t ret = font->parent->get_glyph_v_origin (glyph, x, y);
210 font->parent_scale_position (x, y);
215 hb_font_get_glyph_h_kerning_nil (hb_font_t *font HB_UNUSED,
216 void *font_data HB_UNUSED,
217 hb_codepoint_t left_glyph,
218 hb_codepoint_t right_glyph,
219 void *user_data HB_UNUSED)
224 hb_font_get_glyph_h_kerning_parent (hb_font_t *font,
225 void *font_data HB_UNUSED,
226 hb_codepoint_t left_glyph,
227 hb_codepoint_t right_glyph,
228 void *user_data HB_UNUSED)
230 return font->parent_scale_x_distance (font->parent->get_glyph_h_kerning (left_glyph, right_glyph));
234 hb_font_get_glyph_v_kerning_nil (hb_font_t *font HB_UNUSED,
235 void *font_data HB_UNUSED,
236 hb_codepoint_t top_glyph,
237 hb_codepoint_t bottom_glyph,
238 void *user_data HB_UNUSED)
243 hb_font_get_glyph_v_kerning_parent (hb_font_t *font,
244 void *font_data HB_UNUSED,
245 hb_codepoint_t top_glyph,
246 hb_codepoint_t bottom_glyph,
247 void *user_data HB_UNUSED)
249 return font->parent_scale_y_distance (font->parent->get_glyph_v_kerning (top_glyph, bottom_glyph));
253 hb_font_get_glyph_extents_nil (hb_font_t *font HB_UNUSED,
254 void *font_data HB_UNUSED,
255 hb_codepoint_t glyph,
256 hb_glyph_extents_t *extents,
257 void *user_data HB_UNUSED)
259 memset (extents, 0, sizeof (*extents));
263 hb_font_get_glyph_extents_parent (hb_font_t *font,
264 void *font_data HB_UNUSED,
265 hb_codepoint_t glyph,
266 hb_glyph_extents_t *extents,
267 void *user_data HB_UNUSED)
269 hb_bool_t ret = font->parent->get_glyph_extents (glyph, extents);
271 font->parent_scale_position (&extents->x_bearing, &extents->y_bearing);
272 font->parent_scale_distance (&extents->width, &extents->height);
278 hb_font_get_glyph_contour_point_nil (hb_font_t *font HB_UNUSED,
279 void *font_data HB_UNUSED,
280 hb_codepoint_t glyph,
281 unsigned int point_index,
284 void *user_data HB_UNUSED)
290 hb_font_get_glyph_contour_point_parent (hb_font_t *font,
291 void *font_data HB_UNUSED,
292 hb_codepoint_t glyph,
293 unsigned int point_index,
296 void *user_data HB_UNUSED)
298 hb_bool_t ret = font->parent->get_glyph_contour_point (glyph, point_index, x, y);
300 font->parent_scale_position (x, y);
305 hb_font_get_glyph_name_nil (hb_font_t *font HB_UNUSED,
306 void *font_data HB_UNUSED,
307 hb_codepoint_t glyph,
308 char *name, unsigned int size,
309 void *user_data HB_UNUSED)
311 if (size) *name = '\0';
315 hb_font_get_glyph_name_parent (hb_font_t *font,
316 void *font_data HB_UNUSED,
317 hb_codepoint_t glyph,
318 char *name, unsigned int size,
319 void *user_data HB_UNUSED)
321 return font->parent->get_glyph_name (glyph, name, size);
325 hb_font_get_glyph_from_name_nil (hb_font_t *font HB_UNUSED,
326 void *font_data HB_UNUSED,
327 const char *name, int len, /* -1 means nul-terminated */
328 hb_codepoint_t *glyph,
329 void *user_data HB_UNUSED)
335 hb_font_get_glyph_from_name_parent (hb_font_t *font,
336 void *font_data HB_UNUSED,
337 const char *name, int len, /* -1 means nul-terminated */
338 hb_codepoint_t *glyph,
339 void *user_data HB_UNUSED)
341 return font->parent->get_glyph_from_name (name, len, glyph);
344 static const hb_font_funcs_t _hb_font_funcs_nil = {
345 HB_OBJECT_HEADER_STATIC,
347 true, /* immutable */
350 #define HB_FONT_FUNC_IMPLEMENT(name) NULL,
351 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
352 #undef HB_FONT_FUNC_IMPLEMENT
355 #define HB_FONT_FUNC_IMPLEMENT(name) NULL,
356 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
357 #undef HB_FONT_FUNC_IMPLEMENT
361 #define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_nil,
362 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
363 #undef HB_FONT_FUNC_IMPLEMENT
367 static const hb_font_funcs_t _hb_font_funcs_parent = {
368 HB_OBJECT_HEADER_STATIC,
370 true, /* immutable */
373 #define HB_FONT_FUNC_IMPLEMENT(name) NULL,
374 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
375 #undef HB_FONT_FUNC_IMPLEMENT
378 #define HB_FONT_FUNC_IMPLEMENT(name) NULL,
379 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
380 #undef HB_FONT_FUNC_IMPLEMENT
384 #define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_parent,
385 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
386 #undef HB_FONT_FUNC_IMPLEMENT
393 * hb_font_funcs_create: (Xconstructor)
397 * Return value: (transfer full):
402 hb_font_funcs_create (void)
404 hb_font_funcs_t *ffuncs;
406 if (!(ffuncs = hb_object_create<hb_font_funcs_t> ()))
407 return hb_font_funcs_get_empty ();
409 ffuncs->get = _hb_font_funcs_parent.get;
415 * hb_font_funcs_get_empty:
419 * Return value: (transfer full):
424 hb_font_funcs_get_empty (void)
426 return const_cast<hb_font_funcs_t *> (&_hb_font_funcs_parent);
430 * hb_font_funcs_reference: (skip)
431 * @ffuncs: font functions.
440 hb_font_funcs_reference (hb_font_funcs_t *ffuncs)
442 return hb_object_reference (ffuncs);
446 * hb_font_funcs_destroy: (skip)
447 * @ffuncs: font functions.
454 hb_font_funcs_destroy (hb_font_funcs_t *ffuncs)
456 if (!hb_object_destroy (ffuncs)) return;
458 #define HB_FONT_FUNC_IMPLEMENT(name) if (ffuncs->destroy.name) \
459 ffuncs->destroy.name (ffuncs->user_data.name);
460 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
461 #undef HB_FONT_FUNC_IMPLEMENT
467 * hb_font_funcs_set_user_data: (skip)
468 * @ffuncs: font functions.
481 hb_font_funcs_set_user_data (hb_font_funcs_t *ffuncs,
482 hb_user_data_key_t *key,
484 hb_destroy_func_t destroy,
487 return hb_object_set_user_data (ffuncs, key, data, destroy, replace);
491 * hb_font_funcs_get_user_data: (skip)
492 * @ffuncs: font functions.
497 * Return value: (transfer none):
502 hb_font_funcs_get_user_data (hb_font_funcs_t *ffuncs,
503 hb_user_data_key_t *key)
505 return hb_object_get_user_data (ffuncs, key);
510 * hb_font_funcs_make_immutable:
511 * @ffuncs: font functions.
518 hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs)
520 if (unlikely (hb_object_is_inert (ffuncs)))
523 ffuncs->immutable = true;
527 * hb_font_funcs_is_immutable:
528 * @ffuncs: font functions.
537 hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs)
539 return ffuncs->immutable;
543 #define HB_FONT_FUNC_IMPLEMENT(name) \
546 hb_font_funcs_set_##name##_func (hb_font_funcs_t *ffuncs, \
547 hb_font_get_##name##_func_t func, \
549 hb_destroy_func_t destroy) \
551 if (ffuncs->immutable) { \
553 destroy (user_data); \
557 if (ffuncs->destroy.name) \
558 ffuncs->destroy.name (ffuncs->user_data.name); \
561 ffuncs->get.f.name = func; \
562 ffuncs->user_data.name = user_data; \
563 ffuncs->destroy.name = destroy; \
565 ffuncs->get.f.name = hb_font_get_##name##_parent; \
566 ffuncs->user_data.name = NULL; \
567 ffuncs->destroy.name = NULL; \
571 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
572 #undef HB_FONT_FUNC_IMPLEMENT
575 hb_font_t::has_func (unsigned int i)
577 if (parent && parent != hb_font_get_empty () && parent->has_func (i))
579 return this->klass->get.array[i] != _hb_font_funcs_parent.get.array[i];
585 * hb_font_get_h_extents:
596 hb_font_get_h_extents (hb_font_t *font,
597 hb_font_extents_t *extents)
599 return font->get_font_h_extents (extents);
603 * hb_font_get_v_extents:
614 hb_font_get_v_extents (hb_font_t *font,
615 hb_font_extents_t *extents)
617 return font->get_font_v_extents (extents);
624 * @variation_selector:
634 hb_font_get_glyph (hb_font_t *font,
635 hb_codepoint_t unicode, hb_codepoint_t variation_selector,
636 hb_codepoint_t *glyph)
638 if (unlikely (variation_selector))
639 return font->get_variation_glyph (unicode, variation_selector, glyph);
640 return font->get_nominal_glyph (unicode, glyph);
644 * hb_font_get_nominal_glyph:
656 hb_font_get_nominal_glyph (hb_font_t *font,
657 hb_codepoint_t unicode,
658 hb_codepoint_t *glyph)
660 return font->get_nominal_glyph (unicode, glyph);
664 * hb_font_get_variation_glyph:
667 * @variation_selector:
677 hb_font_get_variation_glyph (hb_font_t *font,
678 hb_codepoint_t unicode, hb_codepoint_t variation_selector,
679 hb_codepoint_t *glyph)
681 return font->get_variation_glyph (unicode, variation_selector, glyph);
685 * hb_font_get_glyph_h_advance:
696 hb_font_get_glyph_h_advance (hb_font_t *font,
697 hb_codepoint_t glyph)
699 return font->get_glyph_h_advance (glyph);
703 * hb_font_get_glyph_v_advance:
714 hb_font_get_glyph_v_advance (hb_font_t *font,
715 hb_codepoint_t glyph)
717 return font->get_glyph_v_advance (glyph);
721 * hb_font_get_glyph_h_origin:
734 hb_font_get_glyph_h_origin (hb_font_t *font,
735 hb_codepoint_t glyph,
736 hb_position_t *x, hb_position_t *y)
738 return font->get_glyph_h_origin (glyph, x, y);
742 * hb_font_get_glyph_v_origin:
755 hb_font_get_glyph_v_origin (hb_font_t *font,
756 hb_codepoint_t glyph,
757 hb_position_t *x, hb_position_t *y)
759 return font->get_glyph_v_origin (glyph, x, y);
763 * hb_font_get_glyph_h_kerning:
775 hb_font_get_glyph_h_kerning (hb_font_t *font,
776 hb_codepoint_t left_glyph, hb_codepoint_t right_glyph)
778 return font->get_glyph_h_kerning (left_glyph, right_glyph);
782 * hb_font_get_glyph_v_kerning:
794 hb_font_get_glyph_v_kerning (hb_font_t *font,
795 hb_codepoint_t top_glyph, hb_codepoint_t bottom_glyph)
797 return font->get_glyph_v_kerning (top_glyph, bottom_glyph);
801 * hb_font_get_glyph_extents:
813 hb_font_get_glyph_extents (hb_font_t *font,
814 hb_codepoint_t glyph,
815 hb_glyph_extents_t *extents)
817 return font->get_glyph_extents (glyph, extents);
821 * hb_font_get_glyph_contour_point:
835 hb_font_get_glyph_contour_point (hb_font_t *font,
836 hb_codepoint_t glyph, unsigned int point_index,
837 hb_position_t *x, hb_position_t *y)
839 return font->get_glyph_contour_point (glyph, point_index, x, y);
843 * hb_font_get_glyph_name:
846 * @name: (array length=size):
856 hb_font_get_glyph_name (hb_font_t *font,
857 hb_codepoint_t glyph,
858 char *name, unsigned int size)
860 return font->get_glyph_name (glyph, name, size);
864 * hb_font_get_glyph_from_name:
866 * @name: (array length=len):
877 hb_font_get_glyph_from_name (hb_font_t *font,
878 const char *name, int len, /* -1 means nul-terminated */
879 hb_codepoint_t *glyph)
881 return font->get_glyph_from_name (name, len, glyph);
885 /* A bit higher-level, and with fallback */
888 * hb_font_get_extents_for_direction:
898 hb_font_get_extents_for_direction (hb_font_t *font,
899 hb_direction_t direction,
900 hb_font_extents_t *extents)
902 return font->get_extents_for_direction (direction, extents);
905 * hb_font_get_glyph_advance_for_direction:
917 hb_font_get_glyph_advance_for_direction (hb_font_t *font,
918 hb_codepoint_t glyph,
919 hb_direction_t direction,
920 hb_position_t *x, hb_position_t *y)
922 return font->get_glyph_advance_for_direction (glyph, direction, x, y);
926 * hb_font_get_glyph_origin_for_direction:
938 hb_font_get_glyph_origin_for_direction (hb_font_t *font,
939 hb_codepoint_t glyph,
940 hb_direction_t direction,
941 hb_position_t *x, hb_position_t *y)
943 return font->get_glyph_origin_for_direction (glyph, direction, x, y);
947 * hb_font_add_glyph_origin_for_direction:
959 hb_font_add_glyph_origin_for_direction (hb_font_t *font,
960 hb_codepoint_t glyph,
961 hb_direction_t direction,
962 hb_position_t *x, hb_position_t *y)
964 return font->add_glyph_origin_for_direction (glyph, direction, x, y);
968 * hb_font_subtract_glyph_origin_for_direction:
980 hb_font_subtract_glyph_origin_for_direction (hb_font_t *font,
981 hb_codepoint_t glyph,
982 hb_direction_t direction,
983 hb_position_t *x, hb_position_t *y)
985 return font->subtract_glyph_origin_for_direction (glyph, direction, x, y);
989 * hb_font_get_glyph_kerning_for_direction:
1002 hb_font_get_glyph_kerning_for_direction (hb_font_t *font,
1003 hb_codepoint_t first_glyph, hb_codepoint_t second_glyph,
1004 hb_direction_t direction,
1005 hb_position_t *x, hb_position_t *y)
1007 return font->get_glyph_kerning_for_direction (first_glyph, second_glyph, direction, x, y);
1011 * hb_font_get_glyph_extents_for_origin:
1024 hb_font_get_glyph_extents_for_origin (hb_font_t *font,
1025 hb_codepoint_t glyph,
1026 hb_direction_t direction,
1027 hb_glyph_extents_t *extents)
1029 return font->get_glyph_extents_for_origin (glyph, direction, extents);
1033 * hb_font_get_glyph_contour_point_for_origin:
1048 hb_font_get_glyph_contour_point_for_origin (hb_font_t *font,
1049 hb_codepoint_t glyph, unsigned int point_index,
1050 hb_direction_t direction,
1051 hb_position_t *x, hb_position_t *y)
1053 return font->get_glyph_contour_point_for_origin (glyph, point_index, direction, x, y);
1056 /* Generates gidDDD if glyph has no name. */
1058 * hb_font_glyph_to_string:
1061 * @s: (array length=size):
1069 hb_font_glyph_to_string (hb_font_t *font,
1070 hb_codepoint_t glyph,
1071 char *s, unsigned int size)
1073 font->glyph_to_string (glyph, s, size);
1076 /* Parses gidDDD and uniUUUU strings automatically. */
1078 * hb_font_glyph_from_string:
1080 * @s: (array length=len) (element-type uint8_t):
1091 hb_font_glyph_from_string (hb_font_t *font,
1092 const char *s, int len, /* -1 means nul-terminated */
1093 hb_codepoint_t *glyph)
1095 return font->glyph_from_string (s, len, glyph);
1104 * hb_font_create: (Xconstructor)
1109 * Return value: (transfer full):
1114 hb_font_create (hb_face_t *face)
1118 if (unlikely (!face))
1119 face = hb_face_get_empty ();
1120 if (!(font = hb_object_create<hb_font_t> ()))
1121 return hb_font_get_empty ();
1123 hb_face_make_immutable (face);
1124 font->parent = hb_font_get_empty ();
1125 font->face = hb_face_reference (face);
1126 font->klass = hb_font_funcs_get_empty ();
1128 font->x_scale = font->y_scale = hb_face_get_upem (face);
1134 * hb_font_create_sub_font:
1135 * @parent: parent font.
1139 * Return value: (transfer full):
1144 hb_font_create_sub_font (hb_font_t *parent)
1146 if (unlikely (!parent))
1147 parent = hb_font_get_empty ();
1149 hb_font_t *font = hb_font_create (parent->face);
1151 if (unlikely (hb_object_is_inert (font)))
1154 font->parent = hb_font_reference (parent);
1156 font->x_scale = parent->x_scale;
1157 font->y_scale = parent->y_scale;
1158 font->x_ppem = parent->x_ppem;
1159 font->y_ppem = parent->y_ppem;
1161 /* TODO: copy variation coordinates. */
1167 * hb_font_get_empty:
1171 * Return value: (transfer full)
1176 hb_font_get_empty (void)
1178 static const hb_font_t _hb_font_nil = {
1179 HB_OBJECT_HEADER_STATIC,
1181 true, /* immutable */
1184 const_cast<hb_face_t *> (&_hb_face_nil),
1195 const_cast<hb_font_funcs_t *> (&_hb_font_funcs_nil), /* klass */
1196 NULL, /* user_data */
1199 hb_font_t::NOTHING, /* dirty */
1202 #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID,
1203 #include "hb-shaper-list.hh"
1204 #undef HB_SHAPER_IMPLEMENT
1208 return const_cast<hb_font_t *> (&_hb_font_nil);
1212 * hb_font_reference: (skip)
1217 * Return value: (transfer full):
1222 hb_font_reference (hb_font_t *font)
1224 return hb_object_reference (font);
1228 * hb_font_destroy: (skip)
1236 hb_font_destroy (hb_font_t *font)
1238 if (!hb_object_destroy (font)) return;
1240 #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_DESTROY(shaper, font);
1241 #include "hb-shaper-list.hh"
1242 #undef HB_SHAPER_IMPLEMENT
1245 font->destroy (font->user_data);
1247 hb_font_destroy (font->parent);
1248 hb_face_destroy (font->face);
1249 hb_font_funcs_destroy (font->klass);
1251 free (font->coords);
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 if (parent == font->parent)
1356 font->dirty |= font->PARENT;
1358 hb_font_t *old = font->parent;
1360 font->parent = hb_font_reference (parent);
1362 hb_font_destroy (old);
1366 * hb_font_get_parent:
1371 * Return value: (transfer none):
1376 hb_font_get_parent (hb_font_t *font)
1378 return font->parent;
1386 * Sets font-face of @font.
1391 hb_font_set_face (hb_font_t *font,
1394 if (font->immutable)
1397 if (unlikely (!face))
1398 face = hb_face_get_empty ();
1400 if (font->face == face)
1403 font->dirty |= font->FACE;
1405 hb_face_t *old = font->face;
1407 font->face = hb_face_reference (face);
1409 hb_face_destroy (old);
1418 * Return value: (transfer none):
1423 hb_font_get_face (hb_font_t *font)
1430 * hb_font_set_funcs:
1432 * @klass: (closure font_data) (destroy destroy) (scope notified):
1441 hb_font_set_funcs (hb_font_t *font,
1442 hb_font_funcs_t *klass,
1444 hb_destroy_func_t destroy)
1446 if (font->immutable) {
1448 destroy (font_data);
1453 font->destroy (font->user_data);
1456 klass = hb_font_funcs_get_empty ();
1458 font->dirty |= font->FUNCS;
1460 hb_font_funcs_reference (klass);
1461 hb_font_funcs_destroy (font->klass);
1462 font->klass = klass;
1463 font->user_data = font_data;
1464 font->destroy = destroy;
1468 * hb_font_set_funcs_data:
1470 * @font_data: (destroy destroy) (scope notified):
1478 hb_font_set_funcs_data (hb_font_t *font,
1480 hb_destroy_func_t destroy)
1482 /* Destroy user_data? */
1483 if (font->immutable) {
1485 destroy (font_data);
1490 font->destroy (font->user_data);
1492 font->user_data = font_data;
1493 font->destroy = destroy;
1498 * hb_font_set_scale:
1508 hb_font_set_scale (hb_font_t *font,
1512 if (font->immutable)
1515 if (font->x_scale == x_scale && font->y_scale == y_scale)
1518 font->dirty |= font->SCALE;
1520 font->x_scale = x_scale;
1521 font->y_scale = y_scale;
1525 * hb_font_get_scale:
1535 hb_font_get_scale (hb_font_t *font,
1539 if (x_scale) *x_scale = font->x_scale;
1540 if (y_scale) *y_scale = font->y_scale;
1554 hb_font_set_ppem (hb_font_t *font,
1555 unsigned int x_ppem,
1556 unsigned int y_ppem)
1558 if (font->immutable)
1561 if (font->x_ppem == x_ppem && font->y_ppem == y_ppem)
1564 font->dirty |= font->PPEM;
1566 font->x_ppem = x_ppem;
1567 font->y_ppem = y_ppem;
1581 hb_font_get_ppem (hb_font_t *font,
1582 unsigned int *x_ppem,
1583 unsigned int *y_ppem)
1585 if (x_ppem) *x_ppem = font->x_ppem;
1586 if (y_ppem) *y_ppem = font->y_ppem;
1594 _hb_font_adopt_var_coords_normalized (hb_font_t *font,
1595 int *coords, /* 2.14 normalized */
1596 unsigned int coords_length)
1598 if (font->num_coords == coords_length &&
1599 (coords_length == 0 ||
1600 0 == memcmp (font->coords, coords, coords_length * sizeof (coords[0]))))
1606 font->dirty |= font->VARIATIONS;
1608 free (font->coords);
1610 font->coords = coords;
1611 font->num_coords = coords_length;
1615 * hb_font_set_variations:
1620 hb_font_set_variations (hb_font_t *font,
1621 const hb_variation_t *variations,
1622 unsigned int variations_length)
1624 if (font->immutable)
1627 if (!variations_length)
1629 hb_font_set_var_coords_normalized (font, NULL, 0);
1633 unsigned int coords_length = hb_ot_var_get_axis_count (font->face);
1635 int *normalized = coords_length ? (int *) calloc (coords_length, sizeof (int)) : NULL;
1636 if (unlikely (coords_length && !normalized))
1639 hb_ot_var_normalize_variations (font->face,
1640 variations, variations_length,
1641 normalized, coords_length);
1642 _hb_font_adopt_var_coords_normalized (font, normalized, coords_length);
1646 * hb_font_set_var_coords_design:
1651 hb_font_set_var_coords_design (hb_font_t *font,
1652 const float *coords,
1653 unsigned int coords_length)
1655 if (font->immutable)
1658 int *normalized = coords_length ? (int *) calloc (coords_length, sizeof (int)) : NULL;
1659 if (unlikely (coords_length && !normalized))
1662 hb_ot_var_normalize_coords (font->face, coords_length, coords, normalized);
1663 _hb_font_adopt_var_coords_normalized (font, normalized, coords_length);
1667 * hb_font_set_var_coords_normalized:
1672 hb_font_set_var_coords_normalized (hb_font_t *font,
1673 const int *coords, /* 2.14 normalized */
1674 unsigned int coords_length)
1676 if (font->immutable)
1679 int *copy = coords_length ? (int *) calloc (coords_length, sizeof (coords[0])) : NULL;
1680 if (unlikely (coords_length && !copy))
1684 memcpy (copy, coords, coords_length * sizeof (coords[0]));
1686 _hb_font_adopt_var_coords_normalized (font, copy, coords_length);
1690 * hb_font_get_var_coords_normalized:
1692 * Return value is valid as long as variation coordinates of the font
1698 hb_font_get_var_coords_normalized (hb_font_t *font,
1699 unsigned int *length)
1702 *length = font->num_coords;
1704 return font->coords;
1708 #ifndef HB_DISABLE_DEPRECATED
1711 * Deprecated get_glyph_func():
1714 struct hb_trampoline_closure_t
1717 hb_destroy_func_t destroy;
1718 unsigned int ref_count;
1721 template <typename FuncType>
1722 struct hb_trampoline_t
1724 hb_trampoline_closure_t closure; /* Must be first. */
1728 template <typename FuncType>
1729 static hb_trampoline_t<FuncType> *
1730 trampoline_create (FuncType func,
1732 hb_destroy_func_t destroy)
1734 typedef hb_trampoline_t<FuncType> trampoline_t;
1736 trampoline_t *trampoline = (trampoline_t *) calloc (1, sizeof (trampoline_t));
1738 if (unlikely (!trampoline))
1741 trampoline->closure.user_data = user_data;
1742 trampoline->closure.destroy = destroy;
1743 trampoline->closure.ref_count = 1;
1744 trampoline->func = func;
1750 trampoline_reference (hb_trampoline_closure_t *closure)
1752 closure->ref_count++;
1756 trampoline_destroy (void *user_data)
1758 hb_trampoline_closure_t *closure = (hb_trampoline_closure_t *) user_data;
1760 if (--closure->ref_count)
1763 if (closure->destroy)
1764 closure->destroy (closure->user_data);
1768 typedef hb_trampoline_t<hb_font_get_glyph_func_t> hb_font_get_glyph_trampoline_t;
1771 hb_font_get_nominal_glyph_trampoline (hb_font_t *font,
1773 hb_codepoint_t unicode,
1774 hb_codepoint_t *glyph,
1777 hb_font_get_glyph_trampoline_t *trampoline = (hb_font_get_glyph_trampoline_t *) user_data;
1778 return trampoline->func (font, font_data, unicode, 0, glyph, trampoline->closure.user_data);
1782 hb_font_get_variation_glyph_trampoline (hb_font_t *font,
1784 hb_codepoint_t unicode,
1785 hb_codepoint_t variation_selector,
1786 hb_codepoint_t *glyph,
1789 hb_font_get_glyph_trampoline_t *trampoline = (hb_font_get_glyph_trampoline_t *) user_data;
1790 return trampoline->func (font, font_data, unicode, variation_selector, glyph, trampoline->closure.user_data);
1794 * hb_font_funcs_set_glyph_func:
1795 * @ffuncs: font functions.
1796 * @func: (closure user_data) (destroy destroy) (scope notified):
1800 * Deprecated. Use hb_font_funcs_set_nominal_glyph_func() and
1801 * hb_font_funcs_set_variation_glyph_func() instead.
1807 hb_font_funcs_set_glyph_func (hb_font_funcs_t *ffuncs,
1808 hb_font_get_glyph_func_t func,
1809 void *user_data, hb_destroy_func_t destroy)
1811 hb_font_get_glyph_trampoline_t *trampoline;
1813 trampoline = trampoline_create (func, user_data, destroy);
1814 if (unlikely (!trampoline))
1817 destroy (user_data);
1821 hb_font_funcs_set_nominal_glyph_func (ffuncs,
1822 hb_font_get_nominal_glyph_trampoline,
1824 trampoline_destroy);
1826 trampoline_reference (&trampoline->closure);
1827 hb_font_funcs_set_variation_glyph_func (ffuncs,
1828 hb_font_get_variation_glyph_trampoline,
1830 trampoline_destroy);
1833 #endif /* HB_DISABLE_DEPRECATED */