Add git cl format presubmit warning for extension and apps.
[chromium-blink-merge.git] / third_party / harfbuzz-ng / src / hb-font.cc
blob855864377e7f0fbb13a992376e683c146aa4d8ce
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-blob.h"
35 #include "hb-open-file-private.hh"
36 #include "hb-ot-head-table.hh"
37 #include "hb-ot-maxp-table.hh"
39 #include "hb-cache-private.hh"
41 #include <string.h>
45 * hb_font_funcs_t
48 static hb_bool_t
49 hb_font_get_glyph_nil (hb_font_t *font,
50 void *font_data HB_UNUSED,
51 hb_codepoint_t unicode,
52 hb_codepoint_t variation_selector,
53 hb_codepoint_t *glyph,
54 void *user_data HB_UNUSED)
56 if (font->parent)
57 return font->parent->get_glyph (unicode, variation_selector, glyph);
59 *glyph = 0;
60 return false;
63 static hb_position_t
64 hb_font_get_glyph_h_advance_nil (hb_font_t *font,
65 void *font_data HB_UNUSED,
66 hb_codepoint_t glyph,
67 void *user_data HB_UNUSED)
69 if (font->parent)
70 return font->parent_scale_x_distance (font->parent->get_glyph_h_advance (glyph));
72 return font->x_scale;
75 static hb_position_t
76 hb_font_get_glyph_v_advance_nil (hb_font_t *font,
77 void *font_data HB_UNUSED,
78 hb_codepoint_t glyph,
79 void *user_data HB_UNUSED)
81 if (font->parent)
82 return font->parent_scale_y_distance (font->parent->get_glyph_v_advance (glyph));
84 return font->y_scale;
87 static hb_bool_t
88 hb_font_get_glyph_h_origin_nil (hb_font_t *font,
89 void *font_data HB_UNUSED,
90 hb_codepoint_t glyph,
91 hb_position_t *x,
92 hb_position_t *y,
93 void *user_data HB_UNUSED)
95 if (font->parent) {
96 hb_bool_t ret = font->parent->get_glyph_h_origin (glyph, x, y);
97 if (ret)
98 font->parent_scale_position (x, y);
99 return ret;
102 *x = *y = 0;
103 return false;
106 static hb_bool_t
107 hb_font_get_glyph_v_origin_nil (hb_font_t *font,
108 void *font_data HB_UNUSED,
109 hb_codepoint_t glyph,
110 hb_position_t *x,
111 hb_position_t *y,
112 void *user_data HB_UNUSED)
114 if (font->parent) {
115 hb_bool_t ret = font->parent->get_glyph_v_origin (glyph, x, y);
116 if (ret)
117 font->parent_scale_position (x, y);
118 return ret;
121 *x = *y = 0;
122 return false;
125 static hb_position_t
126 hb_font_get_glyph_h_kerning_nil (hb_font_t *font,
127 void *font_data HB_UNUSED,
128 hb_codepoint_t left_glyph,
129 hb_codepoint_t right_glyph,
130 void *user_data HB_UNUSED)
132 if (font->parent)
133 return font->parent_scale_x_distance (font->parent->get_glyph_h_kerning (left_glyph, right_glyph));
135 return 0;
138 static hb_position_t
139 hb_font_get_glyph_v_kerning_nil (hb_font_t *font,
140 void *font_data HB_UNUSED,
141 hb_codepoint_t top_glyph,
142 hb_codepoint_t bottom_glyph,
143 void *user_data HB_UNUSED)
145 if (font->parent)
146 return font->parent_scale_y_distance (font->parent->get_glyph_v_kerning (top_glyph, bottom_glyph));
148 return 0;
151 static hb_bool_t
152 hb_font_get_glyph_extents_nil (hb_font_t *font,
153 void *font_data HB_UNUSED,
154 hb_codepoint_t glyph,
155 hb_glyph_extents_t *extents,
156 void *user_data HB_UNUSED)
158 if (font->parent) {
159 hb_bool_t ret = font->parent->get_glyph_extents (glyph, extents);
160 if (ret) {
161 font->parent_scale_position (&extents->x_bearing, &extents->y_bearing);
162 font->parent_scale_distance (&extents->width, &extents->height);
164 return ret;
167 memset (extents, 0, sizeof (*extents));
168 return false;
171 static hb_bool_t
172 hb_font_get_glyph_contour_point_nil (hb_font_t *font,
173 void *font_data HB_UNUSED,
174 hb_codepoint_t glyph,
175 unsigned int point_index,
176 hb_position_t *x,
177 hb_position_t *y,
178 void *user_data HB_UNUSED)
180 if (font->parent) {
181 hb_bool_t ret = font->parent->get_glyph_contour_point (glyph, point_index, x, y);
182 if (ret)
183 font->parent_scale_position (x, y);
184 return ret;
187 *x = *y = 0;
188 return false;
191 static hb_bool_t
192 hb_font_get_glyph_name_nil (hb_font_t *font,
193 void *font_data HB_UNUSED,
194 hb_codepoint_t glyph,
195 char *name, unsigned int size,
196 void *user_data HB_UNUSED)
198 if (font->parent)
199 return font->parent->get_glyph_name (glyph, name, size);
201 if (size) *name = '\0';
202 return false;
205 static hb_bool_t
206 hb_font_get_glyph_from_name_nil (hb_font_t *font,
207 void *font_data HB_UNUSED,
208 const char *name, int len, /* -1 means nul-terminated */
209 hb_codepoint_t *glyph,
210 void *user_data HB_UNUSED)
212 if (font->parent)
213 return font->parent->get_glyph_from_name (name, len, glyph);
215 *glyph = 0;
216 return false;
220 static const hb_font_funcs_t _hb_font_funcs_nil = {
221 HB_OBJECT_HEADER_STATIC,
223 true, /* immutable */
226 #define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_nil,
227 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
228 #undef HB_FONT_FUNC_IMPLEMENT
234 * hb_font_funcs_create: (Xconstructor)
238 * Return value: (transfer full):
240 * Since: 1.0
242 hb_font_funcs_t *
243 hb_font_funcs_create (void)
245 hb_font_funcs_t *ffuncs;
247 if (!(ffuncs = hb_object_create<hb_font_funcs_t> ()))
248 return hb_font_funcs_get_empty ();
250 ffuncs->get = _hb_font_funcs_nil.get;
252 return ffuncs;
256 * hb_font_funcs_get_empty:
260 * Return value: (transfer full):
262 * Since: 1.0
264 hb_font_funcs_t *
265 hb_font_funcs_get_empty (void)
267 return const_cast<hb_font_funcs_t *> (&_hb_font_funcs_nil);
271 * hb_font_funcs_reference: (skip)
272 * @ffuncs: font functions.
276 * Return value:
278 * Since: 1.0
280 hb_font_funcs_t *
281 hb_font_funcs_reference (hb_font_funcs_t *ffuncs)
283 return hb_object_reference (ffuncs);
287 * hb_font_funcs_destroy: (skip)
288 * @ffuncs: font functions.
292 * Since: 1.0
294 void
295 hb_font_funcs_destroy (hb_font_funcs_t *ffuncs)
297 if (!hb_object_destroy (ffuncs)) return;
299 #define HB_FONT_FUNC_IMPLEMENT(name) if (ffuncs->destroy.name) \
300 ffuncs->destroy.name (ffuncs->user_data.name);
301 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
302 #undef HB_FONT_FUNC_IMPLEMENT
304 free (ffuncs);
308 * hb_font_funcs_set_user_data: (skip)
309 * @ffuncs: font functions.
310 * @key:
311 * @data:
312 * @destroy:
313 * @replace:
317 * Return value:
319 * Since: 1.0
321 hb_bool_t
322 hb_font_funcs_set_user_data (hb_font_funcs_t *ffuncs,
323 hb_user_data_key_t *key,
324 void * data,
325 hb_destroy_func_t destroy,
326 hb_bool_t replace)
328 return hb_object_set_user_data (ffuncs, key, data, destroy, replace);
332 * hb_font_funcs_get_user_data: (skip)
333 * @ffuncs: font functions.
334 * @key:
338 * Return value: (transfer none):
340 * Since: 1.0
342 void *
343 hb_font_funcs_get_user_data (hb_font_funcs_t *ffuncs,
344 hb_user_data_key_t *key)
346 return hb_object_get_user_data (ffuncs, key);
351 * hb_font_funcs_make_immutable:
352 * @ffuncs: font functions.
356 * Since: 1.0
358 void
359 hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs)
361 if (hb_object_is_inert (ffuncs))
362 return;
364 ffuncs->immutable = true;
368 * hb_font_funcs_is_immutable:
369 * @ffuncs: font functions.
373 * Return value:
375 * Since: 1.0
377 hb_bool_t
378 hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs)
380 return ffuncs->immutable;
384 #define HB_FONT_FUNC_IMPLEMENT(name) \
386 void \
387 hb_font_funcs_set_##name##_func (hb_font_funcs_t *ffuncs, \
388 hb_font_get_##name##_func_t func, \
389 void *user_data, \
390 hb_destroy_func_t destroy) \
392 if (ffuncs->immutable) { \
393 if (destroy) \
394 destroy (user_data); \
395 return; \
398 if (ffuncs->destroy.name) \
399 ffuncs->destroy.name (ffuncs->user_data.name); \
401 if (func) { \
402 ffuncs->get.name = func; \
403 ffuncs->user_data.name = user_data; \
404 ffuncs->destroy.name = destroy; \
405 } else { \
406 ffuncs->get.name = hb_font_get_##name##_nil; \
407 ffuncs->user_data.name = NULL; \
408 ffuncs->destroy.name = NULL; \
412 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
413 #undef HB_FONT_FUNC_IMPLEMENT
416 /* Public getters */
419 * hb_font_get_glyph:
420 * @font: a font.
421 * @unicode:
422 * @variation_selector:
423 * @glyph: (out):
427 * Return value:
429 * Since: 1.0
431 hb_bool_t
432 hb_font_get_glyph (hb_font_t *font,
433 hb_codepoint_t unicode, hb_codepoint_t variation_selector,
434 hb_codepoint_t *glyph)
436 return font->get_glyph (unicode, variation_selector, glyph);
440 * hb_font_get_glyph_h_advance:
441 * @font: a font.
442 * @glyph:
446 * Return value:
448 * Since: 1.0
450 hb_position_t
451 hb_font_get_glyph_h_advance (hb_font_t *font,
452 hb_codepoint_t glyph)
454 return font->get_glyph_h_advance (glyph);
458 * hb_font_get_glyph_v_advance:
459 * @font: a font.
460 * @glyph:
464 * Return value:
466 * Since: 1.0
468 hb_position_t
469 hb_font_get_glyph_v_advance (hb_font_t *font,
470 hb_codepoint_t glyph)
472 return font->get_glyph_v_advance (glyph);
476 * hb_font_get_glyph_h_origin:
477 * @font: a font.
478 * @glyph:
479 * @x: (out):
480 * @y: (out):
484 * Return value:
486 * Since: 1.0
488 hb_bool_t
489 hb_font_get_glyph_h_origin (hb_font_t *font,
490 hb_codepoint_t glyph,
491 hb_position_t *x, hb_position_t *y)
493 return font->get_glyph_h_origin (glyph, x, y);
497 * hb_font_get_glyph_v_origin:
498 * @font: a font.
499 * @glyph:
500 * @x: (out):
501 * @y: (out):
505 * Return value:
507 * Since: 1.0
509 hb_bool_t
510 hb_font_get_glyph_v_origin (hb_font_t *font,
511 hb_codepoint_t glyph,
512 hb_position_t *x, hb_position_t *y)
514 return font->get_glyph_v_origin (glyph, x, y);
518 * hb_font_get_glyph_h_kerning:
519 * @font: a font.
520 * @left_glyph:
521 * @right_glyph:
525 * Return value:
527 * Since: 1.0
529 hb_position_t
530 hb_font_get_glyph_h_kerning (hb_font_t *font,
531 hb_codepoint_t left_glyph, hb_codepoint_t right_glyph)
533 return font->get_glyph_h_kerning (left_glyph, right_glyph);
537 * hb_font_get_glyph_v_kerning:
538 * @font: a font.
539 * @top_glyph:
540 * @bottom_glyph:
544 * Return value:
546 * Since: 1.0
548 hb_position_t
549 hb_font_get_glyph_v_kerning (hb_font_t *font,
550 hb_codepoint_t top_glyph, hb_codepoint_t bottom_glyph)
552 return font->get_glyph_v_kerning (top_glyph, bottom_glyph);
556 * hb_font_get_glyph_extents:
557 * @font: a font.
558 * @glyph:
559 * @extents: (out):
563 * Return value:
565 * Since: 1.0
567 hb_bool_t
568 hb_font_get_glyph_extents (hb_font_t *font,
569 hb_codepoint_t glyph,
570 hb_glyph_extents_t *extents)
572 return font->get_glyph_extents (glyph, extents);
576 * hb_font_get_glyph_contour_point:
577 * @font: a font.
578 * @glyph:
579 * @point_index:
580 * @x: (out):
581 * @y: (out):
585 * Return value:
587 * Since: 1.0
589 hb_bool_t
590 hb_font_get_glyph_contour_point (hb_font_t *font,
591 hb_codepoint_t glyph, unsigned int point_index,
592 hb_position_t *x, hb_position_t *y)
594 return font->get_glyph_contour_point (glyph, point_index, x, y);
598 * hb_font_get_glyph_name:
599 * @font: a font.
600 * @glyph:
601 * @name: (array length=size):
602 * @size:
606 * Return value:
608 * Since: 1.0
610 hb_bool_t
611 hb_font_get_glyph_name (hb_font_t *font,
612 hb_codepoint_t glyph,
613 char *name, unsigned int size)
615 return font->get_glyph_name (glyph, name, size);
619 * hb_font_get_glyph_from_name:
620 * @font: a font.
621 * @name: (array length=len):
622 * @len:
623 * @glyph: (out):
627 * Return value:
629 * Since: 1.0
631 hb_bool_t
632 hb_font_get_glyph_from_name (hb_font_t *font,
633 const char *name, int len, /* -1 means nul-terminated */
634 hb_codepoint_t *glyph)
636 return font->get_glyph_from_name (name, len, glyph);
640 /* A bit higher-level, and with fallback */
643 * hb_font_get_glyph_advance_for_direction:
644 * @font: a font.
645 * @glyph:
646 * @direction:
647 * @x: (out):
648 * @y: (out):
652 * Since: 1.0
654 void
655 hb_font_get_glyph_advance_for_direction (hb_font_t *font,
656 hb_codepoint_t glyph,
657 hb_direction_t direction,
658 hb_position_t *x, hb_position_t *y)
660 return font->get_glyph_advance_for_direction (glyph, direction, x, y);
664 * hb_font_get_glyph_origin_for_direction:
665 * @font: a font.
666 * @glyph:
667 * @direction:
668 * @x: (out):
669 * @y: (out):
673 * Since: 1.0
675 void
676 hb_font_get_glyph_origin_for_direction (hb_font_t *font,
677 hb_codepoint_t glyph,
678 hb_direction_t direction,
679 hb_position_t *x, hb_position_t *y)
681 return font->get_glyph_origin_for_direction (glyph, direction, x, y);
685 * hb_font_add_glyph_origin_for_direction:
686 * @font: a font.
687 * @glyph:
688 * @direction:
689 * @x: (out):
690 * @y: (out):
694 * Since: 1.0
696 void
697 hb_font_add_glyph_origin_for_direction (hb_font_t *font,
698 hb_codepoint_t glyph,
699 hb_direction_t direction,
700 hb_position_t *x, hb_position_t *y)
702 return font->add_glyph_origin_for_direction (glyph, direction, x, y);
706 * hb_font_subtract_glyph_origin_for_direction:
707 * @font: a font.
708 * @glyph:
709 * @direction:
710 * @x: (out):
711 * @y: (out):
715 * Since: 1.0
717 void
718 hb_font_subtract_glyph_origin_for_direction (hb_font_t *font,
719 hb_codepoint_t glyph,
720 hb_direction_t direction,
721 hb_position_t *x, hb_position_t *y)
723 return font->subtract_glyph_origin_for_direction (glyph, direction, x, y);
727 * hb_font_get_glyph_kerning_for_direction:
728 * @font: a font.
729 * @first_glyph:
730 * @second_glyph:
731 * @direction:
732 * @x: (out):
733 * @y: (out):
737 * Since: 1.0
739 void
740 hb_font_get_glyph_kerning_for_direction (hb_font_t *font,
741 hb_codepoint_t first_glyph, hb_codepoint_t second_glyph,
742 hb_direction_t direction,
743 hb_position_t *x, hb_position_t *y)
745 return font->get_glyph_kerning_for_direction (first_glyph, second_glyph, direction, x, y);
749 * hb_font_get_glyph_extents_for_origin:
750 * @font: a font.
751 * @glyph:
752 * @direction:
753 * @extents: (out):
757 * Return value:
759 * Since: 1.0
761 hb_bool_t
762 hb_font_get_glyph_extents_for_origin (hb_font_t *font,
763 hb_codepoint_t glyph,
764 hb_direction_t direction,
765 hb_glyph_extents_t *extents)
767 return font->get_glyph_extents_for_origin (glyph, direction, extents);
771 * hb_font_get_glyph_contour_point_for_origin:
772 * @font: a font.
773 * @glyph:
774 * @point_index:
775 * @direction:
776 * @x: (out):
777 * @y: (out):
781 * Return value:
783 * Since: 1.0
785 hb_bool_t
786 hb_font_get_glyph_contour_point_for_origin (hb_font_t *font,
787 hb_codepoint_t glyph, unsigned int point_index,
788 hb_direction_t direction,
789 hb_position_t *x, hb_position_t *y)
791 return font->get_glyph_contour_point_for_origin (glyph, point_index, direction, x, y);
794 /* Generates gidDDD if glyph has no name. */
796 * hb_font_glyph_to_string:
797 * @font: a font.
798 * @glyph:
799 * @s: (array length=size):
800 * @size:
804 * Since: 1.0
806 void
807 hb_font_glyph_to_string (hb_font_t *font,
808 hb_codepoint_t glyph,
809 char *s, unsigned int size)
811 font->glyph_to_string (glyph, s, size);
814 /* Parses gidDDD and uniUUUU strings automatically. */
816 * hb_font_glyph_from_string:
817 * @font: a font.
818 * @s: (array length=len):
819 * @len:
820 * @glyph: (out):
824 * Return value:
826 * Since: 1.0
828 hb_bool_t
829 hb_font_glyph_from_string (hb_font_t *font,
830 const char *s, int len, /* -1 means nul-terminated */
831 hb_codepoint_t *glyph)
833 return font->glyph_from_string (s, len, glyph);
838 * hb_font_t
842 * hb_font_create: (Xconstructor)
843 * @face: a face.
847 * Return value: (transfer full):
849 * Since: 1.0
851 hb_font_t *
852 hb_font_create (hb_face_t *face)
854 hb_font_t *font;
856 if (unlikely (!face))
857 face = hb_face_get_empty ();
858 if (unlikely (hb_object_is_inert (face)))
859 return hb_font_get_empty ();
860 if (!(font = hb_object_create<hb_font_t> ()))
861 return hb_font_get_empty ();
863 hb_face_make_immutable (face);
864 font->face = hb_face_reference (face);
865 font->klass = hb_font_funcs_get_empty ();
867 return font;
871 * hb_font_create_sub_font:
872 * @parent: parent font.
876 * Return value: (transfer full):
878 * Since: 1.0
880 hb_font_t *
881 hb_font_create_sub_font (hb_font_t *parent)
883 if (unlikely (!parent))
884 return hb_font_get_empty ();
886 hb_font_t *font = hb_font_create (parent->face);
888 if (unlikely (hb_object_is_inert (font)))
889 return font;
891 hb_font_make_immutable (parent);
892 font->parent = hb_font_reference (parent);
894 font->x_scale = parent->x_scale;
895 font->y_scale = parent->y_scale;
896 font->x_ppem = parent->x_ppem;
897 font->y_ppem = parent->y_ppem;
899 return font;
903 * hb_font_get_empty:
907 * Return value: (transfer full)
909 * Since: 1.0
911 hb_font_t *
912 hb_font_get_empty (void)
914 static const hb_font_t _hb_font_nil = {
915 HB_OBJECT_HEADER_STATIC,
917 true, /* immutable */
919 NULL, /* parent */
920 const_cast<hb_face_t *> (&_hb_face_nil),
922 0, /* x_scale */
923 0, /* y_scale */
925 0, /* x_ppem */
926 0, /* y_ppem */
928 const_cast<hb_font_funcs_t *> (&_hb_font_funcs_nil), /* klass */
929 NULL, /* user_data */
930 NULL, /* destroy */
933 #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID,
934 #include "hb-shaper-list.hh"
935 #undef HB_SHAPER_IMPLEMENT
939 return const_cast<hb_font_t *> (&_hb_font_nil);
943 * hb_font_reference: (skip)
944 * @font: a font.
948 * Return value: (transfer full):
950 * Since: 1.0
952 hb_font_t *
953 hb_font_reference (hb_font_t *font)
955 return hb_object_reference (font);
959 * hb_font_destroy: (skip)
960 * @font: a font.
964 * Since: 1.0
966 void
967 hb_font_destroy (hb_font_t *font)
969 if (!hb_object_destroy (font)) return;
971 #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_DESTROY(shaper, font);
972 #include "hb-shaper-list.hh"
973 #undef HB_SHAPER_IMPLEMENT
975 if (font->destroy)
976 font->destroy (font->user_data);
978 hb_font_destroy (font->parent);
979 hb_face_destroy (font->face);
980 hb_font_funcs_destroy (font->klass);
982 free (font);
986 * hb_font_set_user_data: (skip)
987 * @font: a font.
988 * @key:
989 * @data:
990 * @destroy:
991 * @replace:
995 * Return value:
997 * Since: 1.0
999 hb_bool_t
1000 hb_font_set_user_data (hb_font_t *font,
1001 hb_user_data_key_t *key,
1002 void * data,
1003 hb_destroy_func_t destroy,
1004 hb_bool_t replace)
1006 return hb_object_set_user_data (font, key, data, destroy, replace);
1010 * hb_font_get_user_data: (skip)
1011 * @font: a font.
1012 * @key:
1016 * Return value: (transfer none):
1018 * Since: 1.0
1020 void *
1021 hb_font_get_user_data (hb_font_t *font,
1022 hb_user_data_key_t *key)
1024 return hb_object_get_user_data (font, key);
1028 * hb_font_make_immutable:
1029 * @font: a font.
1033 * Since: 1.0
1035 void
1036 hb_font_make_immutable (hb_font_t *font)
1038 if (hb_object_is_inert (font))
1039 return;
1041 font->immutable = true;
1045 * hb_font_is_immutable:
1046 * @font: a font.
1050 * Return value:
1052 * Since: 1.0
1054 hb_bool_t
1055 hb_font_is_immutable (hb_font_t *font)
1057 return font->immutable;
1061 * hb_font_get_parent:
1062 * @font: a font.
1066 * Return value: (transfer none):
1068 * Since: 1.0
1070 hb_font_t *
1071 hb_font_get_parent (hb_font_t *font)
1073 return font->parent;
1077 * hb_font_get_face:
1078 * @font: a font.
1082 * Return value: (transfer none):
1084 * Since: 1.0
1086 hb_face_t *
1087 hb_font_get_face (hb_font_t *font)
1089 return font->face;
1094 * hb_font_set_funcs:
1095 * @font: a font.
1096 * @klass: (closure font_data) (destroy destroy) (scope notified):
1097 * @font_data:
1098 * @destroy:
1102 * Since: 1.0
1104 void
1105 hb_font_set_funcs (hb_font_t *font,
1106 hb_font_funcs_t *klass,
1107 void *font_data,
1108 hb_destroy_func_t destroy)
1110 if (font->immutable) {
1111 if (destroy)
1112 destroy (font_data);
1113 return;
1116 if (font->destroy)
1117 font->destroy (font->user_data);
1119 if (!klass)
1120 klass = hb_font_funcs_get_empty ();
1122 hb_font_funcs_reference (klass);
1123 hb_font_funcs_destroy (font->klass);
1124 font->klass = klass;
1125 font->user_data = font_data;
1126 font->destroy = destroy;
1130 * hb_font_set_funcs_data:
1131 * @font: a font.
1132 * @font_data: (destroy destroy) (scope notified):
1133 * @destroy:
1137 * Since: 1.0
1139 void
1140 hb_font_set_funcs_data (hb_font_t *font,
1141 void *font_data,
1142 hb_destroy_func_t destroy)
1144 /* Destroy user_data? */
1145 if (font->immutable) {
1146 if (destroy)
1147 destroy (font_data);
1148 return;
1151 if (font->destroy)
1152 font->destroy (font->user_data);
1154 font->user_data = font_data;
1155 font->destroy = destroy;
1160 * hb_font_set_scale:
1161 * @font: a font.
1162 * @x_scale:
1163 * @y_scale:
1167 * Since: 1.0
1169 void
1170 hb_font_set_scale (hb_font_t *font,
1171 int x_scale,
1172 int y_scale)
1174 if (font->immutable)
1175 return;
1177 font->x_scale = x_scale;
1178 font->y_scale = y_scale;
1182 * hb_font_get_scale:
1183 * @font: a font.
1184 * @x_scale: (out):
1185 * @y_scale: (out):
1189 * Since: 1.0
1191 void
1192 hb_font_get_scale (hb_font_t *font,
1193 int *x_scale,
1194 int *y_scale)
1196 if (x_scale) *x_scale = font->x_scale;
1197 if (y_scale) *y_scale = font->y_scale;
1201 * hb_font_set_ppem:
1202 * @font: a font.
1203 * @x_ppem:
1204 * @y_ppem:
1208 * Since: 1.0
1210 void
1211 hb_font_set_ppem (hb_font_t *font,
1212 unsigned int x_ppem,
1213 unsigned int y_ppem)
1215 if (font->immutable)
1216 return;
1218 font->x_ppem = x_ppem;
1219 font->y_ppem = y_ppem;
1223 * hb_font_get_ppem:
1224 * @font: a font.
1225 * @x_ppem: (out):
1226 * @y_ppem: (out):
1230 * Since: 1.0
1232 void
1233 hb_font_get_ppem (hb_font_t *font,
1234 unsigned int *x_ppem,
1235 unsigned int *y_ppem)
1237 if (x_ppem) *x_ppem = font->x_ppem;
1238 if (y_ppem) *y_ppem = font->y_ppem;