Restore variadic macros in DevToolsEmbedderMessageDispatcher
[chromium-blink-merge.git] / third_party / harfbuzz-ng / src / hb-font.cc
blob0cfba837a27aa46419cc8e6004b33e5b81dd5fd2
1 /*
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
17 * DAMAGE.
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"
40 #include <string.h>
44 * hb_font_funcs_t
47 static hb_bool_t
48 hb_font_get_glyph_nil (hb_font_t *font,
49 void *font_data HB_UNUSED,
50 hb_codepoint_t unicode,
51 hb_codepoint_t variation_selector,
52 hb_codepoint_t *glyph,
53 void *user_data HB_UNUSED)
55 if (font->parent)
56 return font->parent->get_glyph (unicode, variation_selector, glyph);
58 *glyph = 0;
59 return false;
62 static hb_position_t
63 hb_font_get_glyph_h_advance_nil (hb_font_t *font,
64 void *font_data HB_UNUSED,
65 hb_codepoint_t glyph,
66 void *user_data HB_UNUSED)
68 if (font->parent)
69 return font->parent_scale_x_distance (font->parent->get_glyph_h_advance (glyph));
71 return font->x_scale;
74 static hb_position_t
75 hb_font_get_glyph_v_advance_nil (hb_font_t *font,
76 void *font_data HB_UNUSED,
77 hb_codepoint_t glyph,
78 void *user_data HB_UNUSED)
80 if (font->parent)
81 return font->parent_scale_y_distance (font->parent->get_glyph_v_advance (glyph));
83 return font->y_scale;
86 static hb_bool_t
87 hb_font_get_glyph_h_origin_nil (hb_font_t *font,
88 void *font_data HB_UNUSED,
89 hb_codepoint_t glyph,
90 hb_position_t *x,
91 hb_position_t *y,
92 void *user_data HB_UNUSED)
94 if (font->parent) {
95 hb_bool_t ret = font->parent->get_glyph_h_origin (glyph, x, y);
96 if (ret)
97 font->parent_scale_position (x, y);
98 return ret;
101 *x = *y = 0;
102 return false;
105 static hb_bool_t
106 hb_font_get_glyph_v_origin_nil (hb_font_t *font,
107 void *font_data HB_UNUSED,
108 hb_codepoint_t glyph,
109 hb_position_t *x,
110 hb_position_t *y,
111 void *user_data HB_UNUSED)
113 if (font->parent) {
114 hb_bool_t ret = font->parent->get_glyph_v_origin (glyph, x, y);
115 if (ret)
116 font->parent_scale_position (x, y);
117 return ret;
120 *x = *y = 0;
121 return false;
124 static hb_position_t
125 hb_font_get_glyph_h_kerning_nil (hb_font_t *font,
126 void *font_data HB_UNUSED,
127 hb_codepoint_t left_glyph,
128 hb_codepoint_t right_glyph,
129 void *user_data HB_UNUSED)
131 if (font->parent)
132 return font->parent_scale_x_distance (font->parent->get_glyph_h_kerning (left_glyph, right_glyph));
134 return 0;
137 static hb_position_t
138 hb_font_get_glyph_v_kerning_nil (hb_font_t *font,
139 void *font_data HB_UNUSED,
140 hb_codepoint_t top_glyph,
141 hb_codepoint_t bottom_glyph,
142 void *user_data HB_UNUSED)
144 if (font->parent)
145 return font->parent_scale_y_distance (font->parent->get_glyph_v_kerning (top_glyph, bottom_glyph));
147 return 0;
150 static hb_bool_t
151 hb_font_get_glyph_extents_nil (hb_font_t *font,
152 void *font_data HB_UNUSED,
153 hb_codepoint_t glyph,
154 hb_glyph_extents_t *extents,
155 void *user_data HB_UNUSED)
157 if (font->parent) {
158 hb_bool_t ret = font->parent->get_glyph_extents (glyph, extents);
159 if (ret) {
160 font->parent_scale_position (&extents->x_bearing, &extents->y_bearing);
161 font->parent_scale_distance (&extents->width, &extents->height);
163 return ret;
166 memset (extents, 0, sizeof (*extents));
167 return false;
170 static hb_bool_t
171 hb_font_get_glyph_contour_point_nil (hb_font_t *font,
172 void *font_data HB_UNUSED,
173 hb_codepoint_t glyph,
174 unsigned int point_index,
175 hb_position_t *x,
176 hb_position_t *y,
177 void *user_data HB_UNUSED)
179 if (font->parent) {
180 hb_bool_t ret = font->parent->get_glyph_contour_point (glyph, point_index, x, y);
181 if (ret)
182 font->parent_scale_position (x, y);
183 return ret;
186 *x = *y = 0;
187 return false;
190 static hb_bool_t
191 hb_font_get_glyph_name_nil (hb_font_t *font,
192 void *font_data HB_UNUSED,
193 hb_codepoint_t glyph,
194 char *name, unsigned int size,
195 void *user_data HB_UNUSED)
197 if (font->parent)
198 return font->parent->get_glyph_name (glyph, name, size);
200 if (size) *name = '\0';
201 return false;
204 static hb_bool_t
205 hb_font_get_glyph_from_name_nil (hb_font_t *font,
206 void *font_data HB_UNUSED,
207 const char *name, int len, /* -1 means nul-terminated */
208 hb_codepoint_t *glyph,
209 void *user_data HB_UNUSED)
211 if (font->parent)
212 return font->parent->get_glyph_from_name (name, len, glyph);
214 *glyph = 0;
215 return false;
219 static const hb_font_funcs_t _hb_font_funcs_nil = {
220 HB_OBJECT_HEADER_STATIC,
222 true, /* immutable */
225 #define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_nil,
226 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
227 #undef HB_FONT_FUNC_IMPLEMENT
233 * hb_font_funcs_create: (Xconstructor)
237 * Return value: (transfer full):
239 * Since: 1.0
241 hb_font_funcs_t *
242 hb_font_funcs_create (void)
244 hb_font_funcs_t *ffuncs;
246 if (!(ffuncs = hb_object_create<hb_font_funcs_t> ()))
247 return hb_font_funcs_get_empty ();
249 ffuncs->get = _hb_font_funcs_nil.get;
251 return ffuncs;
255 * hb_font_funcs_get_empty:
259 * Return value: (transfer full):
261 * Since: 1.0
263 hb_font_funcs_t *
264 hb_font_funcs_get_empty (void)
266 return const_cast<hb_font_funcs_t *> (&_hb_font_funcs_nil);
270 * hb_font_funcs_reference: (skip)
271 * @ffuncs: font functions.
275 * Return value:
277 * Since: 1.0
279 hb_font_funcs_t *
280 hb_font_funcs_reference (hb_font_funcs_t *ffuncs)
282 return hb_object_reference (ffuncs);
286 * hb_font_funcs_destroy: (skip)
287 * @ffuncs: font functions.
291 * Since: 1.0
293 void
294 hb_font_funcs_destroy (hb_font_funcs_t *ffuncs)
296 if (!hb_object_destroy (ffuncs)) return;
298 #define HB_FONT_FUNC_IMPLEMENT(name) if (ffuncs->destroy.name) \
299 ffuncs->destroy.name (ffuncs->user_data.name);
300 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
301 #undef HB_FONT_FUNC_IMPLEMENT
303 free (ffuncs);
307 * hb_font_funcs_set_user_data: (skip)
308 * @ffuncs: font functions.
309 * @key:
310 * @data:
311 * @destroy:
312 * @replace:
316 * Return value:
318 * Since: 1.0
320 hb_bool_t
321 hb_font_funcs_set_user_data (hb_font_funcs_t *ffuncs,
322 hb_user_data_key_t *key,
323 void * data,
324 hb_destroy_func_t destroy,
325 hb_bool_t replace)
327 return hb_object_set_user_data (ffuncs, key, data, destroy, replace);
331 * hb_font_funcs_get_user_data: (skip)
332 * @ffuncs: font functions.
333 * @key:
337 * Return value: (transfer none):
339 * Since: 1.0
341 void *
342 hb_font_funcs_get_user_data (hb_font_funcs_t *ffuncs,
343 hb_user_data_key_t *key)
345 return hb_object_get_user_data (ffuncs, key);
350 * hb_font_funcs_make_immutable:
351 * @ffuncs: font functions.
355 * Since: 1.0
357 void
358 hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs)
360 if (unlikely (hb_object_is_inert (ffuncs)))
361 return;
363 ffuncs->immutable = true;
367 * hb_font_funcs_is_immutable:
368 * @ffuncs: font functions.
372 * Return value:
374 * Since: 1.0
376 hb_bool_t
377 hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs)
379 return ffuncs->immutable;
383 #define HB_FONT_FUNC_IMPLEMENT(name) \
385 void \
386 hb_font_funcs_set_##name##_func (hb_font_funcs_t *ffuncs, \
387 hb_font_get_##name##_func_t func, \
388 void *user_data, \
389 hb_destroy_func_t destroy) \
391 if (ffuncs->immutable) { \
392 if (destroy) \
393 destroy (user_data); \
394 return; \
397 if (ffuncs->destroy.name) \
398 ffuncs->destroy.name (ffuncs->user_data.name); \
400 if (func) { \
401 ffuncs->get.name = func; \
402 ffuncs->user_data.name = user_data; \
403 ffuncs->destroy.name = destroy; \
404 } else { \
405 ffuncs->get.name = hb_font_get_##name##_nil; \
406 ffuncs->user_data.name = NULL; \
407 ffuncs->destroy.name = NULL; \
411 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
412 #undef HB_FONT_FUNC_IMPLEMENT
415 /* Public getters */
418 * hb_font_get_glyph:
419 * @font: a font.
420 * @unicode:
421 * @variation_selector:
422 * @glyph: (out):
426 * Return value:
428 * Since: 1.0
430 hb_bool_t
431 hb_font_get_glyph (hb_font_t *font,
432 hb_codepoint_t unicode, hb_codepoint_t variation_selector,
433 hb_codepoint_t *glyph)
435 return font->get_glyph (unicode, variation_selector, glyph);
439 * hb_font_get_glyph_h_advance:
440 * @font: a font.
441 * @glyph:
445 * Return value:
447 * Since: 1.0
449 hb_position_t
450 hb_font_get_glyph_h_advance (hb_font_t *font,
451 hb_codepoint_t glyph)
453 return font->get_glyph_h_advance (glyph);
457 * hb_font_get_glyph_v_advance:
458 * @font: a font.
459 * @glyph:
463 * Return value:
465 * Since: 1.0
467 hb_position_t
468 hb_font_get_glyph_v_advance (hb_font_t *font,
469 hb_codepoint_t glyph)
471 return font->get_glyph_v_advance (glyph);
475 * hb_font_get_glyph_h_origin:
476 * @font: a font.
477 * @glyph:
478 * @x: (out):
479 * @y: (out):
483 * Return value:
485 * Since: 1.0
487 hb_bool_t
488 hb_font_get_glyph_h_origin (hb_font_t *font,
489 hb_codepoint_t glyph,
490 hb_position_t *x, hb_position_t *y)
492 return font->get_glyph_h_origin (glyph, x, y);
496 * hb_font_get_glyph_v_origin:
497 * @font: a font.
498 * @glyph:
499 * @x: (out):
500 * @y: (out):
504 * Return value:
506 * Since: 1.0
508 hb_bool_t
509 hb_font_get_glyph_v_origin (hb_font_t *font,
510 hb_codepoint_t glyph,
511 hb_position_t *x, hb_position_t *y)
513 return font->get_glyph_v_origin (glyph, x, y);
517 * hb_font_get_glyph_h_kerning:
518 * @font: a font.
519 * @left_glyph:
520 * @right_glyph:
524 * Return value:
526 * Since: 1.0
528 hb_position_t
529 hb_font_get_glyph_h_kerning (hb_font_t *font,
530 hb_codepoint_t left_glyph, hb_codepoint_t right_glyph)
532 return font->get_glyph_h_kerning (left_glyph, right_glyph);
536 * hb_font_get_glyph_v_kerning:
537 * @font: a font.
538 * @top_glyph:
539 * @bottom_glyph:
543 * Return value:
545 * Since: 1.0
547 hb_position_t
548 hb_font_get_glyph_v_kerning (hb_font_t *font,
549 hb_codepoint_t top_glyph, hb_codepoint_t bottom_glyph)
551 return font->get_glyph_v_kerning (top_glyph, bottom_glyph);
555 * hb_font_get_glyph_extents:
556 * @font: a font.
557 * @glyph:
558 * @extents: (out):
562 * Return value:
564 * Since: 1.0
566 hb_bool_t
567 hb_font_get_glyph_extents (hb_font_t *font,
568 hb_codepoint_t glyph,
569 hb_glyph_extents_t *extents)
571 return font->get_glyph_extents (glyph, extents);
575 * hb_font_get_glyph_contour_point:
576 * @font: a font.
577 * @glyph:
578 * @point_index:
579 * @x: (out):
580 * @y: (out):
584 * Return value:
586 * Since: 1.0
588 hb_bool_t
589 hb_font_get_glyph_contour_point (hb_font_t *font,
590 hb_codepoint_t glyph, unsigned int point_index,
591 hb_position_t *x, hb_position_t *y)
593 return font->get_glyph_contour_point (glyph, point_index, x, y);
597 * hb_font_get_glyph_name:
598 * @font: a font.
599 * @glyph:
600 * @name: (array length=size):
601 * @size:
605 * Return value:
607 * Since: 0.9.2
609 hb_bool_t
610 hb_font_get_glyph_name (hb_font_t *font,
611 hb_codepoint_t glyph,
612 char *name, unsigned int size)
614 return font->get_glyph_name (glyph, name, size);
618 * hb_font_get_glyph_from_name:
619 * @font: a font.
620 * @name: (array length=len):
621 * @len:
622 * @glyph: (out):
626 * Return value:
628 * Since: 0.9.2
630 hb_bool_t
631 hb_font_get_glyph_from_name (hb_font_t *font,
632 const char *name, int len, /* -1 means nul-terminated */
633 hb_codepoint_t *glyph)
635 return font->get_glyph_from_name (name, len, glyph);
639 /* A bit higher-level, and with fallback */
642 * hb_font_get_glyph_advance_for_direction:
643 * @font: a font.
644 * @glyph:
645 * @direction:
646 * @x: (out):
647 * @y: (out):
651 * Since: 1.0
653 void
654 hb_font_get_glyph_advance_for_direction (hb_font_t *font,
655 hb_codepoint_t glyph,
656 hb_direction_t direction,
657 hb_position_t *x, hb_position_t *y)
659 return font->get_glyph_advance_for_direction (glyph, direction, x, y);
663 * hb_font_get_glyph_origin_for_direction:
664 * @font: a font.
665 * @glyph:
666 * @direction:
667 * @x: (out):
668 * @y: (out):
672 * Since: 1.0
674 void
675 hb_font_get_glyph_origin_for_direction (hb_font_t *font,
676 hb_codepoint_t glyph,
677 hb_direction_t direction,
678 hb_position_t *x, hb_position_t *y)
680 return font->get_glyph_origin_for_direction (glyph, direction, x, y);
684 * hb_font_add_glyph_origin_for_direction:
685 * @font: a font.
686 * @glyph:
687 * @direction:
688 * @x: (out):
689 * @y: (out):
693 * Since: 1.0
695 void
696 hb_font_add_glyph_origin_for_direction (hb_font_t *font,
697 hb_codepoint_t glyph,
698 hb_direction_t direction,
699 hb_position_t *x, hb_position_t *y)
701 return font->add_glyph_origin_for_direction (glyph, direction, x, y);
705 * hb_font_subtract_glyph_origin_for_direction:
706 * @font: a font.
707 * @glyph:
708 * @direction:
709 * @x: (out):
710 * @y: (out):
714 * Since: 1.0
716 void
717 hb_font_subtract_glyph_origin_for_direction (hb_font_t *font,
718 hb_codepoint_t glyph,
719 hb_direction_t direction,
720 hb_position_t *x, hb_position_t *y)
722 return font->subtract_glyph_origin_for_direction (glyph, direction, x, y);
726 * hb_font_get_glyph_kerning_for_direction:
727 * @font: a font.
728 * @first_glyph:
729 * @second_glyph:
730 * @direction:
731 * @x: (out):
732 * @y: (out):
736 * Since: 1.0
738 void
739 hb_font_get_glyph_kerning_for_direction (hb_font_t *font,
740 hb_codepoint_t first_glyph, hb_codepoint_t second_glyph,
741 hb_direction_t direction,
742 hb_position_t *x, hb_position_t *y)
744 return font->get_glyph_kerning_for_direction (first_glyph, second_glyph, direction, x, y);
748 * hb_font_get_glyph_extents_for_origin:
749 * @font: a font.
750 * @glyph:
751 * @direction:
752 * @extents: (out):
756 * Return value:
758 * Since: 1.0
760 hb_bool_t
761 hb_font_get_glyph_extents_for_origin (hb_font_t *font,
762 hb_codepoint_t glyph,
763 hb_direction_t direction,
764 hb_glyph_extents_t *extents)
766 return font->get_glyph_extents_for_origin (glyph, direction, extents);
770 * hb_font_get_glyph_contour_point_for_origin:
771 * @font: a font.
772 * @glyph:
773 * @point_index:
774 * @direction:
775 * @x: (out):
776 * @y: (out):
780 * Return value:
782 * Since: 1.0
784 hb_bool_t
785 hb_font_get_glyph_contour_point_for_origin (hb_font_t *font,
786 hb_codepoint_t glyph, unsigned int point_index,
787 hb_direction_t direction,
788 hb_position_t *x, hb_position_t *y)
790 return font->get_glyph_contour_point_for_origin (glyph, point_index, direction, x, y);
793 /* Generates gidDDD if glyph has no name. */
795 * hb_font_glyph_to_string:
796 * @font: a font.
797 * @glyph:
798 * @s: (array length=size):
799 * @size:
803 * Since: 0.9.2
805 void
806 hb_font_glyph_to_string (hb_font_t *font,
807 hb_codepoint_t glyph,
808 char *s, unsigned int size)
810 font->glyph_to_string (glyph, s, size);
813 /* Parses gidDDD and uniUUUU strings automatically. */
815 * hb_font_glyph_from_string:
816 * @font: a font.
817 * @s: (array length=len) (element-type uint8_t):
818 * @len:
819 * @glyph: (out):
823 * Return value:
825 * Since: 0.9.2
827 hb_bool_t
828 hb_font_glyph_from_string (hb_font_t *font,
829 const char *s, int len, /* -1 means nul-terminated */
830 hb_codepoint_t *glyph)
832 return font->glyph_from_string (s, len, glyph);
837 * hb_font_t
841 * hb_font_create: (Xconstructor)
842 * @face: a face.
846 * Return value: (transfer full):
848 * Since: 1.0
850 hb_font_t *
851 hb_font_create (hb_face_t *face)
853 hb_font_t *font;
855 if (unlikely (!face))
856 face = hb_face_get_empty ();
857 if (!(font = hb_object_create<hb_font_t> ()))
858 return hb_font_get_empty ();
860 hb_face_make_immutable (face);
861 font->face = hb_face_reference (face);
862 font->klass = hb_font_funcs_get_empty ();
864 return font;
868 * hb_font_create_sub_font:
869 * @parent: parent font.
873 * Return value: (transfer full):
875 * Since: 1.0
877 hb_font_t *
878 hb_font_create_sub_font (hb_font_t *parent)
880 if (unlikely (!parent))
881 parent = hb_font_get_empty ();
883 hb_font_t *font = hb_font_create (parent->face);
885 if (unlikely (hb_object_is_inert (font)))
886 return font;
888 hb_font_make_immutable (parent);
889 font->parent = hb_font_reference (parent);
891 font->x_scale = parent->x_scale;
892 font->y_scale = parent->y_scale;
893 font->x_ppem = parent->x_ppem;
894 font->y_ppem = parent->y_ppem;
896 return font;
900 * hb_font_get_empty:
904 * Return value: (transfer full)
906 * Since: 1.0
908 hb_font_t *
909 hb_font_get_empty (void)
911 static const hb_font_t _hb_font_nil = {
912 HB_OBJECT_HEADER_STATIC,
914 true, /* immutable */
916 NULL, /* parent */
917 const_cast<hb_face_t *> (&_hb_face_nil),
919 0, /* x_scale */
920 0, /* y_scale */
922 0, /* x_ppem */
923 0, /* y_ppem */
925 const_cast<hb_font_funcs_t *> (&_hb_font_funcs_nil), /* klass */
926 NULL, /* user_data */
927 NULL, /* destroy */
930 #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID,
931 #include "hb-shaper-list.hh"
932 #undef HB_SHAPER_IMPLEMENT
936 return const_cast<hb_font_t *> (&_hb_font_nil);
940 * hb_font_reference: (skip)
941 * @font: a font.
945 * Return value: (transfer full):
947 * Since: 1.0
949 hb_font_t *
950 hb_font_reference (hb_font_t *font)
952 return hb_object_reference (font);
956 * hb_font_destroy: (skip)
957 * @font: a font.
961 * Since: 1.0
963 void
964 hb_font_destroy (hb_font_t *font)
966 if (!hb_object_destroy (font)) return;
968 #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_DESTROY(shaper, font);
969 #include "hb-shaper-list.hh"
970 #undef HB_SHAPER_IMPLEMENT
972 if (font->destroy)
973 font->destroy (font->user_data);
975 hb_font_destroy (font->parent);
976 hb_face_destroy (font->face);
977 hb_font_funcs_destroy (font->klass);
979 free (font);
983 * hb_font_set_user_data: (skip)
984 * @font: a font.
985 * @key:
986 * @data:
987 * @destroy:
988 * @replace:
992 * Return value:
994 * Since: 1.0
996 hb_bool_t
997 hb_font_set_user_data (hb_font_t *font,
998 hb_user_data_key_t *key,
999 void * data,
1000 hb_destroy_func_t destroy,
1001 hb_bool_t replace)
1003 return hb_object_set_user_data (font, key, data, destroy, replace);
1007 * hb_font_get_user_data: (skip)
1008 * @font: a font.
1009 * @key:
1013 * Return value: (transfer none):
1015 * Since: 1.0
1017 void *
1018 hb_font_get_user_data (hb_font_t *font,
1019 hb_user_data_key_t *key)
1021 return hb_object_get_user_data (font, key);
1025 * hb_font_make_immutable:
1026 * @font: a font.
1030 * Since: 1.0
1032 void
1033 hb_font_make_immutable (hb_font_t *font)
1035 if (unlikely (hb_object_is_inert (font)))
1036 return;
1038 font->immutable = true;
1042 * hb_font_is_immutable:
1043 * @font: a font.
1047 * Return value:
1049 * Since: 1.0
1051 hb_bool_t
1052 hb_font_is_immutable (hb_font_t *font)
1054 return font->immutable;
1058 * hb_font_get_parent:
1059 * @font: a font.
1063 * Return value: (transfer none):
1065 * Since: 1.0
1067 hb_font_t *
1068 hb_font_get_parent (hb_font_t *font)
1070 return font->parent;
1074 * hb_font_get_face:
1075 * @font: a font.
1079 * Return value: (transfer none):
1081 * Since: 0.9.2
1083 hb_face_t *
1084 hb_font_get_face (hb_font_t *font)
1086 return font->face;
1091 * hb_font_set_funcs:
1092 * @font: a font.
1093 * @klass: (closure font_data) (destroy destroy) (scope notified):
1094 * @font_data:
1095 * @destroy:
1099 * Since: 0.9.2
1101 void
1102 hb_font_set_funcs (hb_font_t *font,
1103 hb_font_funcs_t *klass,
1104 void *font_data,
1105 hb_destroy_func_t destroy)
1107 if (font->immutable) {
1108 if (destroy)
1109 destroy (font_data);
1110 return;
1113 if (font->destroy)
1114 font->destroy (font->user_data);
1116 if (!klass)
1117 klass = hb_font_funcs_get_empty ();
1119 hb_font_funcs_reference (klass);
1120 hb_font_funcs_destroy (font->klass);
1121 font->klass = klass;
1122 font->user_data = font_data;
1123 font->destroy = destroy;
1127 * hb_font_set_funcs_data:
1128 * @font: a font.
1129 * @font_data: (destroy destroy) (scope notified):
1130 * @destroy:
1134 * Since: 0.9.2
1136 void
1137 hb_font_set_funcs_data (hb_font_t *font,
1138 void *font_data,
1139 hb_destroy_func_t destroy)
1141 /* Destroy user_data? */
1142 if (font->immutable) {
1143 if (destroy)
1144 destroy (font_data);
1145 return;
1148 if (font->destroy)
1149 font->destroy (font->user_data);
1151 font->user_data = font_data;
1152 font->destroy = destroy;
1157 * hb_font_set_scale:
1158 * @font: a font.
1159 * @x_scale:
1160 * @y_scale:
1164 * Since: 1.0
1166 void
1167 hb_font_set_scale (hb_font_t *font,
1168 int x_scale,
1169 int y_scale)
1171 if (font->immutable)
1172 return;
1174 font->x_scale = x_scale;
1175 font->y_scale = y_scale;
1179 * hb_font_get_scale:
1180 * @font: a font.
1181 * @x_scale: (out):
1182 * @y_scale: (out):
1186 * Since: 1.0
1188 void
1189 hb_font_get_scale (hb_font_t *font,
1190 int *x_scale,
1191 int *y_scale)
1193 if (x_scale) *x_scale = font->x_scale;
1194 if (y_scale) *y_scale = font->y_scale;
1198 * hb_font_set_ppem:
1199 * @font: a font.
1200 * @x_ppem:
1201 * @y_ppem:
1205 * Since: 1.0
1207 void
1208 hb_font_set_ppem (hb_font_t *font,
1209 unsigned int x_ppem,
1210 unsigned int y_ppem)
1212 if (font->immutable)
1213 return;
1215 font->x_ppem = x_ppem;
1216 font->y_ppem = y_ppem;
1220 * hb_font_get_ppem:
1221 * @font: a font.
1222 * @x_ppem: (out):
1223 * @y_ppem: (out):
1227 * Since: 1.0
1229 void
1230 hb_font_get_ppem (hb_font_t *font,
1231 unsigned int *x_ppem,
1232 unsigned int *y_ppem)
1234 if (x_ppem) *x_ppem = font->x_ppem;
1235 if (y_ppem) *y_ppem = font->y_ppem;