Revert of Update the extension whitelist for application host change. (patchset ...
[chromium-blink-merge.git] / third_party / harfbuzz-ng / src / hb-font.cc
blob4364ca72fb0c81ae66da9a00799f9dbeb0a19208
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: 1.0
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: 1.0
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: 1.0
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):
818 * @len:
819 * @glyph: (out):
823 * Return value:
825 * Since: 1.0
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 (unlikely (hb_object_is_inert (face)))
858 return hb_font_get_empty ();
859 if (!(font = hb_object_create<hb_font_t> ()))
860 return hb_font_get_empty ();
862 hb_face_make_immutable (face);
863 font->face = hb_face_reference (face);
864 font->klass = hb_font_funcs_get_empty ();
866 return font;
870 * hb_font_create_sub_font:
871 * @parent: parent font.
875 * Return value: (transfer full):
877 * Since: 1.0
879 hb_font_t *
880 hb_font_create_sub_font (hb_font_t *parent)
882 if (unlikely (!parent))
883 return hb_font_get_empty ();
885 hb_font_t *font = hb_font_create (parent->face);
887 if (unlikely (hb_object_is_inert (font)))
888 return font;
890 hb_font_make_immutable (parent);
891 font->parent = hb_font_reference (parent);
893 font->x_scale = parent->x_scale;
894 font->y_scale = parent->y_scale;
895 font->x_ppem = parent->x_ppem;
896 font->y_ppem = parent->y_ppem;
898 return font;
902 * hb_font_get_empty:
906 * Return value: (transfer full)
908 * Since: 1.0
910 hb_font_t *
911 hb_font_get_empty (void)
913 static const hb_font_t _hb_font_nil = {
914 HB_OBJECT_HEADER_STATIC,
916 true, /* immutable */
918 NULL, /* parent */
919 const_cast<hb_face_t *> (&_hb_face_nil),
921 0, /* x_scale */
922 0, /* y_scale */
924 0, /* x_ppem */
925 0, /* y_ppem */
927 const_cast<hb_font_funcs_t *> (&_hb_font_funcs_nil), /* klass */
928 NULL, /* user_data */
929 NULL, /* destroy */
932 #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID,
933 #include "hb-shaper-list.hh"
934 #undef HB_SHAPER_IMPLEMENT
938 return const_cast<hb_font_t *> (&_hb_font_nil);
942 * hb_font_reference: (skip)
943 * @font: a font.
947 * Return value: (transfer full):
949 * Since: 1.0
951 hb_font_t *
952 hb_font_reference (hb_font_t *font)
954 return hb_object_reference (font);
958 * hb_font_destroy: (skip)
959 * @font: a font.
963 * Since: 1.0
965 void
966 hb_font_destroy (hb_font_t *font)
968 if (!hb_object_destroy (font)) return;
970 #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_DESTROY(shaper, font);
971 #include "hb-shaper-list.hh"
972 #undef HB_SHAPER_IMPLEMENT
974 if (font->destroy)
975 font->destroy (font->user_data);
977 hb_font_destroy (font->parent);
978 hb_face_destroy (font->face);
979 hb_font_funcs_destroy (font->klass);
981 free (font);
985 * hb_font_set_user_data: (skip)
986 * @font: a font.
987 * @key:
988 * @data:
989 * @destroy:
990 * @replace:
994 * Return value:
996 * Since: 1.0
998 hb_bool_t
999 hb_font_set_user_data (hb_font_t *font,
1000 hb_user_data_key_t *key,
1001 void * data,
1002 hb_destroy_func_t destroy,
1003 hb_bool_t replace)
1005 return hb_object_set_user_data (font, key, data, destroy, replace);
1009 * hb_font_get_user_data: (skip)
1010 * @font: a font.
1011 * @key:
1015 * Return value: (transfer none):
1017 * Since: 1.0
1019 void *
1020 hb_font_get_user_data (hb_font_t *font,
1021 hb_user_data_key_t *key)
1023 return hb_object_get_user_data (font, key);
1027 * hb_font_make_immutable:
1028 * @font: a font.
1032 * Since: 1.0
1034 void
1035 hb_font_make_immutable (hb_font_t *font)
1037 if (unlikely (hb_object_is_inert (font)))
1038 return;
1040 font->immutable = true;
1044 * hb_font_is_immutable:
1045 * @font: a font.
1049 * Return value:
1051 * Since: 1.0
1053 hb_bool_t
1054 hb_font_is_immutable (hb_font_t *font)
1056 return font->immutable;
1060 * hb_font_get_parent:
1061 * @font: a font.
1065 * Return value: (transfer none):
1067 * Since: 1.0
1069 hb_font_t *
1070 hb_font_get_parent (hb_font_t *font)
1072 return font->parent;
1076 * hb_font_get_face:
1077 * @font: a font.
1081 * Return value: (transfer none):
1083 * Since: 1.0
1085 hb_face_t *
1086 hb_font_get_face (hb_font_t *font)
1088 return font->face;
1093 * hb_font_set_funcs:
1094 * @font: a font.
1095 * @klass: (closure font_data) (destroy destroy) (scope notified):
1096 * @font_data:
1097 * @destroy:
1101 * Since: 1.0
1103 void
1104 hb_font_set_funcs (hb_font_t *font,
1105 hb_font_funcs_t *klass,
1106 void *font_data,
1107 hb_destroy_func_t destroy)
1109 if (font->immutable) {
1110 if (destroy)
1111 destroy (font_data);
1112 return;
1115 if (font->destroy)
1116 font->destroy (font->user_data);
1118 if (!klass)
1119 klass = hb_font_funcs_get_empty ();
1121 hb_font_funcs_reference (klass);
1122 hb_font_funcs_destroy (font->klass);
1123 font->klass = klass;
1124 font->user_data = font_data;
1125 font->destroy = destroy;
1129 * hb_font_set_funcs_data:
1130 * @font: a font.
1131 * @font_data: (destroy destroy) (scope notified):
1132 * @destroy:
1136 * Since: 1.0
1138 void
1139 hb_font_set_funcs_data (hb_font_t *font,
1140 void *font_data,
1141 hb_destroy_func_t destroy)
1143 /* Destroy user_data? */
1144 if (font->immutable) {
1145 if (destroy)
1146 destroy (font_data);
1147 return;
1150 if (font->destroy)
1151 font->destroy (font->user_data);
1153 font->user_data = font_data;
1154 font->destroy = destroy;
1159 * hb_font_set_scale:
1160 * @font: a font.
1161 * @x_scale:
1162 * @y_scale:
1166 * Since: 1.0
1168 void
1169 hb_font_set_scale (hb_font_t *font,
1170 int x_scale,
1171 int y_scale)
1173 if (font->immutable)
1174 return;
1176 font->x_scale = x_scale;
1177 font->y_scale = y_scale;
1181 * hb_font_get_scale:
1182 * @font: a font.
1183 * @x_scale: (out):
1184 * @y_scale: (out):
1188 * Since: 1.0
1190 void
1191 hb_font_get_scale (hb_font_t *font,
1192 int *x_scale,
1193 int *y_scale)
1195 if (x_scale) *x_scale = font->x_scale;
1196 if (y_scale) *y_scale = font->y_scale;
1200 * hb_font_set_ppem:
1201 * @font: a font.
1202 * @x_ppem:
1203 * @y_ppem:
1207 * Since: 1.0
1209 void
1210 hb_font_set_ppem (hb_font_t *font,
1211 unsigned int x_ppem,
1212 unsigned int y_ppem)
1214 if (font->immutable)
1215 return;
1217 font->x_ppem = x_ppem;
1218 font->y_ppem = y_ppem;
1222 * hb_font_get_ppem:
1223 * @font: a font.
1224 * @x_ppem: (out):
1225 * @y_ppem: (out):
1229 * Since: 1.0
1231 void
1232 hb_font_get_ppem (hb_font_t *font,
1233 unsigned int *x_ppem,
1234 unsigned int *y_ppem)
1236 if (x_ppem) *x_ppem = font->x_ppem;
1237 if (y_ppem) *y_ppem = font->y_ppem;