blob: e900bd3f65aedd47a7a38448395a938809ae1ab1 [file] [log] [blame]
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001/*
Behdad Esfahbod2409d5f2011-04-21 17:14:28 -04002 * Copyright © 2009 Red Hat, Inc.
Behdad Esfahbod027857d2012-07-26 17:34:25 -04003 * Copyright © 2012 Google, Inc.
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04004 *
Behdad Esfahbodc755cb32010-04-22 00:11:43 -04005 * This is part of HarfBuzz, a text shaping library.
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04006 *
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.
12 *
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.
18 *
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.
24 *
25 * Red Hat Author(s): Behdad Esfahbod
Behdad Esfahbod027857d2012-07-26 17:34:25 -040026 * Google Author(s): Behdad Esfahbod
Behdad Esfahbodc62b5032009-08-01 19:54:49 -040027 */
28
Behdad Esfahbodc57d4542011-04-20 18:50:27 -040029#include "hb-private.hh"
Behdad Esfahbodc62b5032009-08-01 19:54:49 -040030
Behdad Esfahbodc57d4542011-04-20 18:50:27 -040031#include "hb-font-private.hh"
Behdad Esfahbod79512792009-11-03 20:27:05 -050032
Behdad Esfahbodacdba3f2010-07-23 15:11:18 -040033
Behdad Esfahbodc62b5032009-08-01 19:54:49 -040034/*
Behdad Esfahbod5c441882009-08-10 20:05:16 -040035 * hb_font_funcs_t
Behdad Esfahbodc62b5032009-08-01 19:54:49 -040036 */
37
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -040038static hb_bool_t
Simon Cozens6f2e6de2015-10-26 16:23:22 +090039hb_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)
43{
44 memset (metrics, 0, sizeof (*metrics));
45 return false;
46}
47static hb_bool_t
48hb_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)
52{
53 hb_bool_t ret = font->parent->get_font_h_extents (metrics);
54 if (ret) {
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);
58 }
59 return ret;
60}
61
62static hb_bool_t
63hb_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)
67{
68 memset (metrics, 0, sizeof (*metrics));
69 return false;
70}
71static hb_bool_t
72hb_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)
76{
77 hb_bool_t ret = font->parent->get_font_v_extents (metrics);
78 if (ret) {
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);
82 }
83 return ret;
84}
85
86static hb_bool_t
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +090087hb_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)
Behdad Esfahbod1ded6d82011-05-10 20:49:02 -040092{
Behdad Esfahbod0fd8c2f2011-05-12 15:14:13 -040093 *glyph = 0;
Behdad Esfahbod0594a242012-06-05 20:35:40 -040094 return false;
Behdad Esfahbod1ded6d82011-05-10 20:49:02 -040095}
Behdad Esfahbodda29b432015-11-04 20:22:44 -080096static hb_bool_t
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +090097hb_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)
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800102{
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +0900103 return font->parent->get_nominal_glyph (unicode, glyph);
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800104}
Behdad Esfahbod79512792009-11-03 20:27:05 -0500105
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +0900106static hb_bool_t
107hb_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)
113{
114 *glyph = 0;
115 return false;
116}
117static hb_bool_t
118hb_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)
124{
125 return font->parent->get_variation_glyph (unicode, variation_selector, glyph);
126}
127
128
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400129static hb_position_t
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800130hb_font_get_glyph_h_advance_nil (hb_font_t *font HB_UNUSED,
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400131 void *font_data HB_UNUSED,
132 hb_codepoint_t glyph,
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400133 void *user_data HB_UNUSED)
Behdad Esfahbod1ded6d82011-05-10 20:49:02 -0400134{
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400135 return font->x_scale;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400136}
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800137static hb_position_t
138hb_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)
142{
143 return font->parent_scale_x_distance (font->parent->get_glyph_h_advance (glyph));
144}
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400145
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400146static hb_position_t
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800147hb_font_get_glyph_v_advance_nil (hb_font_t *font HB_UNUSED,
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400148 void *font_data HB_UNUSED,
149 hb_codepoint_t glyph,
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400150 void *user_data HB_UNUSED)
151{
Behdad Esfahbodaba4b0c2016-06-01 16:57:29 -0700152 /* TODO use font_extents.ascender+descender */
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400153 return font->y_scale;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400154}
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800155static hb_position_t
156hb_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)
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400160{
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800161 return font->parent_scale_y_distance (font->parent->get_glyph_v_advance (glyph));
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400162}
163
164static hb_bool_t
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800165hb_font_get_glyph_h_origin_nil (hb_font_t *font HB_UNUSED,
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400166 void *font_data HB_UNUSED,
167 hb_codepoint_t glyph,
Behdad Esfahbod19098182011-05-17 23:27:22 -0400168 hb_position_t *x,
169 hb_position_t *y,
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400170 void *user_data HB_UNUSED)
171{
Behdad Esfahbod19098182011-05-17 23:27:22 -0400172 *x = *y = 0;
Behdad Esfahbodc41c1452015-11-26 18:43:15 -0500173 return true;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400174}
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800175static hb_bool_t
176hb_font_get_glyph_h_origin_parent (hb_font_t *font,
177 void *font_data HB_UNUSED,
178 hb_codepoint_t glyph,
179 hb_position_t *x,
180 hb_position_t *y,
181 void *user_data HB_UNUSED)
182{
183 hb_bool_t ret = font->parent->get_glyph_h_origin (glyph, x, y);
184 if (ret)
185 font->parent_scale_position (x, y);
186 return ret;
187}
188
189static hb_bool_t
190hb_font_get_glyph_v_origin_nil (hb_font_t *font HB_UNUSED,
191 void *font_data HB_UNUSED,
192 hb_codepoint_t glyph,
193 hb_position_t *x,
194 hb_position_t *y,
195 void *user_data HB_UNUSED)
196{
197 *x = *y = 0;
198 return false;
199}
200static hb_bool_t
201hb_font_get_glyph_v_origin_parent (hb_font_t *font,
202 void *font_data HB_UNUSED,
203 hb_codepoint_t glyph,
204 hb_position_t *x,
205 hb_position_t *y,
206 void *user_data HB_UNUSED)
207{
208 hb_bool_t ret = font->parent->get_glyph_v_origin (glyph, x, y);
209 if (ret)
210 font->parent_scale_position (x, y);
211 return ret;
212}
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400213
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400214static hb_position_t
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800215hb_font_get_glyph_h_kerning_nil (hb_font_t *font HB_UNUSED,
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400216 void *font_data HB_UNUSED,
217 hb_codepoint_t left_glyph,
218 hb_codepoint_t right_glyph,
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400219 void *user_data HB_UNUSED)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400220{
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400221 return 0;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400222}
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800223static hb_position_t
224hb_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)
229{
230 return font->parent_scale_x_distance (font->parent->get_glyph_h_kerning (left_glyph, right_glyph));
231}
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400232
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400233static hb_position_t
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800234hb_font_get_glyph_v_kerning_nil (hb_font_t *font HB_UNUSED,
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400235 void *font_data HB_UNUSED,
236 hb_codepoint_t top_glyph,
237 hb_codepoint_t bottom_glyph,
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400238 void *user_data HB_UNUSED)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400239{
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400240 return 0;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400241}
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800242static hb_position_t
243hb_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)
248{
249 return font->parent_scale_y_distance (font->parent->get_glyph_v_kerning (top_glyph, bottom_glyph));
250}
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400251
252static hb_bool_t
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800253hb_font_get_glyph_extents_nil (hb_font_t *font HB_UNUSED,
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400254 void *font_data HB_UNUSED,
255 hb_codepoint_t glyph,
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400256 hb_glyph_extents_t *extents,
257 void *user_data HB_UNUSED)
258{
Behdad Esfahbod60fbb362011-05-19 18:46:15 -0400259 memset (extents, 0, sizeof (*extents));
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400260 return false;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400261}
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800262static hb_bool_t
263hb_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)
268{
269 hb_bool_t ret = font->parent->get_glyph_extents (glyph, extents);
270 if (ret) {
271 font->parent_scale_position (&extents->x_bearing, &extents->y_bearing);
272 font->parent_scale_distance (&extents->width, &extents->height);
273 }
274 return ret;
275}
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400276
277static hb_bool_t
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800278hb_font_get_glyph_contour_point_nil (hb_font_t *font HB_UNUSED,
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400279 void *font_data HB_UNUSED,
280 hb_codepoint_t glyph,
281 unsigned int point_index,
282 hb_position_t *x,
283 hb_position_t *y,
284 void *user_data HB_UNUSED)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400285{
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400286 *x = *y = 0;
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400287 return false;
Behdad Esfahbod1ded6d82011-05-10 20:49:02 -0400288}
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800289static hb_bool_t
290hb_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,
294 hb_position_t *x,
295 hb_position_t *y,
296 void *user_data HB_UNUSED)
297{
298 hb_bool_t ret = font->parent->get_glyph_contour_point (glyph, point_index, x, y);
299 if (ret)
300 font->parent_scale_position (x, y);
301 return ret;
302}
Behdad Esfahbod79512792009-11-03 20:27:05 -0500303
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400304static hb_bool_t
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800305hb_font_get_glyph_name_nil (hb_font_t *font HB_UNUSED,
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400306 void *font_data HB_UNUSED,
307 hb_codepoint_t glyph,
308 char *name, unsigned int size,
309 void *user_data HB_UNUSED)
310{
Behdad Esfahbod6f3a3002012-08-07 22:13:25 -0400311 if (size) *name = '\0';
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400312 return false;
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400313}
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800314static hb_bool_t
315hb_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)
320{
321 return font->parent->get_glyph_name (glyph, name, size);
322}
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400323
324static hb_bool_t
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800325hb_font_get_glyph_from_name_nil (hb_font_t *font HB_UNUSED,
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400326 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)
330{
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400331 *glyph = 0;
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400332 return false;
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400333}
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800334static hb_bool_t
335hb_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)
340{
341 return font->parent->get_glyph_from_name (name, len, glyph);
342}
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400343
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -0400344static const hb_font_funcs_t _hb_font_funcs_nil = {
Behdad Esfahbodfca368c2011-04-21 18:24:02 -0400345 HB_OBJECT_HEADER_STATIC,
346
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400347 true, /* immutable */
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400348
Behdad Esfahbodbf36a102010-05-24 17:46:21 +0100349 {
Behdad Esfahbod28de1042015-11-04 22:00:25 -0800350#define HB_FONT_FUNC_IMPLEMENT(name) NULL,
351 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
352#undef HB_FONT_FUNC_IMPLEMENT
353 },
354 {
355#define HB_FONT_FUNC_IMPLEMENT(name) NULL,
356 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
357#undef HB_FONT_FUNC_IMPLEMENT
358 },
359 {
jfkthamef19c6db2015-11-20 08:43:49 +0000360 {
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400361#define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_nil,
jfkthamef19c6db2015-11-20 08:43:49 +0000362 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400363#undef HB_FONT_FUNC_IMPLEMENT
jfkthamef19c6db2015-11-20 08:43:49 +0000364 }
Behdad Esfahbodbf36a102010-05-24 17:46:21 +0100365 }
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400366};
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800367static const hb_font_funcs_t _hb_font_funcs_parent = {
368 HB_OBJECT_HEADER_STATIC,
369
370 true, /* immutable */
371
372 {
Behdad Esfahbod28de1042015-11-04 22:00:25 -0800373#define HB_FONT_FUNC_IMPLEMENT(name) NULL,
374 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
375#undef HB_FONT_FUNC_IMPLEMENT
376 },
377 {
378#define HB_FONT_FUNC_IMPLEMENT(name) NULL,
379 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
380#undef HB_FONT_FUNC_IMPLEMENT
381 },
382 {
jfkthamef19c6db2015-11-20 08:43:49 +0000383 {
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800384#define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_parent,
jfkthamef19c6db2015-11-20 08:43:49 +0000385 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800386#undef HB_FONT_FUNC_IMPLEMENT
jfkthamef19c6db2015-11-20 08:43:49 +0000387 }
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800388 }
389};
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400390
Behdad Esfahbod56eb5ad2011-05-04 19:27:37 -0400391
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400392/**
Behdad Esfahbod085d4292013-09-12 17:14:33 -0400393 * hb_font_funcs_create: (Xconstructor)
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400394 *
395 *
396 *
397 * Return value: (transfer full):
398 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430399 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400400 **/
Behdad Esfahbod5c441882009-08-10 20:05:16 -0400401hb_font_funcs_t *
402hb_font_funcs_create (void)
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400403{
Behdad Esfahbod5c441882009-08-10 20:05:16 -0400404 hb_font_funcs_t *ffuncs;
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400405
Behdad Esfahbod47e71d92011-04-27 16:38:03 -0400406 if (!(ffuncs = hb_object_create<hb_font_funcs_t> ()))
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -0400407 return hb_font_funcs_get_empty ();
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400408
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800409 ffuncs->get = _hb_font_funcs_parent.get;
Behdad Esfahbodf97bf4f2010-05-24 17:50:19 +0100410
Behdad Esfahbod5c441882009-08-10 20:05:16 -0400411 return ffuncs;
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400412}
413
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400414/**
415 * hb_font_funcs_get_empty:
416 *
417 *
418 *
419 * Return value: (transfer full):
420 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430421 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400422 **/
Behdad Esfahbod5c441882009-08-10 20:05:16 -0400423hb_font_funcs_t *
Behdad Esfahbod80a68332011-05-11 18:14:44 -0400424hb_font_funcs_get_empty (void)
425{
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800426 return const_cast<hb_font_funcs_t *> (&_hb_font_funcs_parent);
Behdad Esfahbod80a68332011-05-11 18:14:44 -0400427}
428
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400429/**
430 * hb_font_funcs_reference: (skip)
431 * @ffuncs: font functions.
432 *
433 *
434 *
435 * Return value:
436 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430437 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400438 **/
Behdad Esfahbod80a68332011-05-11 18:14:44 -0400439hb_font_funcs_t *
Behdad Esfahbod5c441882009-08-10 20:05:16 -0400440hb_font_funcs_reference (hb_font_funcs_t *ffuncs)
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400441{
Behdad Esfahbod47e71d92011-04-27 16:38:03 -0400442 return hb_object_reference (ffuncs);
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400443}
444
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400445/**
446 * hb_font_funcs_destroy: (skip)
447 * @ffuncs: font functions.
448 *
449 *
450 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430451 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400452 **/
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400453void
Behdad Esfahbod5c441882009-08-10 20:05:16 -0400454hb_font_funcs_destroy (hb_font_funcs_t *ffuncs)
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400455{
Behdad Esfahbod47e71d92011-04-27 16:38:03 -0400456 if (!hb_object_destroy (ffuncs)) return;
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400457
Behdad Esfahbod4b6317c2011-07-07 23:14:42 -0400458#define HB_FONT_FUNC_IMPLEMENT(name) if (ffuncs->destroy.name) \
459 ffuncs->destroy.name (ffuncs->user_data.name);
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400460 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
461#undef HB_FONT_FUNC_IMPLEMENT
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400462
Behdad Esfahbod5c441882009-08-10 20:05:16 -0400463 free (ffuncs);
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400464}
465
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400466/**
467 * hb_font_funcs_set_user_data: (skip)
468 * @ffuncs: font functions.
469 * @key:
470 * @data:
471 * @destroy:
472 * @replace:
473 *
474 *
475 *
476 * Return value:
477 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430478 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400479 **/
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -0400480hb_bool_t
481hb_font_funcs_set_user_data (hb_font_funcs_t *ffuncs,
482 hb_user_data_key_t *key,
483 void * data,
Behdad Esfahbod33ccc772011-08-09 00:43:24 +0200484 hb_destroy_func_t destroy,
485 hb_bool_t replace)
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -0400486{
Behdad Esfahbod33ccc772011-08-09 00:43:24 +0200487 return hb_object_set_user_data (ffuncs, key, data, destroy, replace);
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -0400488}
489
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400490/**
491 * hb_font_funcs_get_user_data: (skip)
492 * @ffuncs: font functions.
493 * @key:
494 *
495 *
496 *
497 * Return value: (transfer none):
498 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430499 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400500 **/
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -0400501void *
502hb_font_funcs_get_user_data (hb_font_funcs_t *ffuncs,
503 hb_user_data_key_t *key)
504{
505 return hb_object_get_user_data (ffuncs, key);
506}
507
508
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400509/**
510 * hb_font_funcs_make_immutable:
511 * @ffuncs: font functions.
512 *
513 *
514 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430515 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400516 **/
Behdad Esfahbod8d703122009-08-10 23:50:51 -0400517void
518hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs)
519{
Behdad Esfahbod3f310dc2014-07-22 16:26:27 -0400520 if (unlikely (hb_object_is_inert (ffuncs)))
Behdad Esfahbod8d703122009-08-10 23:50:51 -0400521 return;
522
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400523 ffuncs->immutable = true;
Behdad Esfahbod8d703122009-08-10 23:50:51 -0400524}
525
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400526/**
527 * hb_font_funcs_is_immutable:
528 * @ffuncs: font functions.
529 *
530 *
531 *
532 * Return value:
533 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430534 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400535 **/
Behdad Esfahbod645f6f22010-10-04 17:01:01 -0400536hb_bool_t
537hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs)
538{
Behdad Esfahbod3111b8a2010-10-13 10:41:53 -0400539 return ffuncs->immutable;
Behdad Esfahbod645f6f22010-10-04 17:01:01 -0400540}
541
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400542
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400543#define HB_FONT_FUNC_IMPLEMENT(name) \
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400544 \
545void \
546hb_font_funcs_set_##name##_func (hb_font_funcs_t *ffuncs, \
547 hb_font_get_##name##_func_t func, \
548 void *user_data, \
549 hb_destroy_func_t destroy) \
550{ \
Behdad Esfahbod0cd33592011-09-21 16:49:33 -0400551 if (ffuncs->immutable) { \
552 if (destroy) \
553 destroy (user_data); \
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400554 return; \
Behdad Esfahbod0cd33592011-09-21 16:49:33 -0400555 } \
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400556 \
557 if (ffuncs->destroy.name) \
558 ffuncs->destroy.name (ffuncs->user_data.name); \
559 \
560 if (func) { \
Behdad Esfahbod88e9a9b2015-11-04 21:16:26 -0800561 ffuncs->get.f.name = func; \
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400562 ffuncs->user_data.name = user_data; \
563 ffuncs->destroy.name = destroy; \
564 } else { \
Behdad Esfahbod88e9a9b2015-11-04 21:16:26 -0800565 ffuncs->get.f.name = hb_font_get_##name##_parent; \
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400566 ffuncs->user_data.name = NULL; \
567 ffuncs->destroy.name = NULL; \
568 } \
Behdad Esfahbod79512792009-11-03 20:27:05 -0500569}
570
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400571HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
572#undef HB_FONT_FUNC_IMPLEMENT
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400573
Behdad Esfahbod762770c2015-11-04 21:42:55 -0800574bool
575hb_font_t::has_func (unsigned int i)
576{
577 if (parent && parent != hb_font_get_empty () && parent->has_func (i))
578 return true;
579 return this->klass->get.array[i] != _hb_font_funcs_parent.get.array[i];
580}
Behdad Esfahbod502f4cb2010-10-27 01:13:56 -0400581
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400582/* Public getters */
583
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400584/**
Simon Cozens6f2e6de2015-10-26 16:23:22 +0900585 * hb_font_get_h_extents:
586 * @font: a font.
587 * @extents: (out):
588 *
589 *
590 *
591 * Return value:
592 *
Behdad Esfahbodf11c11a2015-12-16 17:08:36 +0100593 * Since: 1.1.3
Simon Cozens6f2e6de2015-10-26 16:23:22 +0900594 **/
595hb_bool_t
596hb_font_get_h_extents (hb_font_t *font,
597 hb_font_extents_t *extents)
598{
599 return font->get_font_h_extents (extents);
600}
601
602/**
603 * hb_font_get_v_extents:
604 * @font: a font.
605 * @extents: (out):
606 *
607 *
608 *
609 * Return value:
610 *
Behdad Esfahbodf11c11a2015-12-16 17:08:36 +0100611 * Since: 1.1.3
Simon Cozens6f2e6de2015-10-26 16:23:22 +0900612 **/
613hb_bool_t
614hb_font_get_v_extents (hb_font_t *font,
615 hb_font_extents_t *extents)
616{
617 return font->get_font_v_extents (extents);
618}
619
620/**
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400621 * hb_font_get_glyph:
622 * @font: a font.
623 * @unicode:
624 * @variation_selector:
625 * @glyph: (out):
626 *
627 *
628 *
629 * Return value:
630 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430631 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400632 **/
Behdad Esfahbod0fd8c2f2011-05-12 15:14:13 -0400633hb_bool_t
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400634hb_font_get_glyph (hb_font_t *font,
Behdad Esfahbod0fd8c2f2011-05-12 15:14:13 -0400635 hb_codepoint_t unicode, hb_codepoint_t variation_selector,
636 hb_codepoint_t *glyph)
Behdad Esfahbod2e336692009-11-05 13:55:41 -0500637{
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +0900638 if (unlikely (variation_selector))
639 return font->get_variation_glyph (unicode, variation_selector, glyph);
640 return font->get_nominal_glyph (unicode, glyph);
641}
642
643/**
644 * hb_font_get_nominal_glyph:
645 * @font: a font.
646 * @unicode:
647 * @glyph: (out):
648 *
649 *
650 *
651 * Return value:
652 *
653 * Since: 1.2.3
654 **/
655hb_bool_t
656hb_font_get_nominal_glyph (hb_font_t *font,
657 hb_codepoint_t unicode,
658 hb_codepoint_t *glyph)
659{
660 return font->get_nominal_glyph (unicode, glyph);
661}
662
663/**
664 * hb_font_get_variation_glyph:
665 * @font: a font.
666 * @unicode:
667 * @variation_selector:
668 * @glyph: (out):
669 *
670 *
671 *
672 * Return value:
673 *
674 * Since: 1.2.3
675 **/
676hb_bool_t
677hb_font_get_variation_glyph (hb_font_t *font,
678 hb_codepoint_t unicode, hb_codepoint_t variation_selector,
679 hb_codepoint_t *glyph)
680{
681 return font->get_variation_glyph (unicode, variation_selector, glyph);
Behdad Esfahbod2e336692009-11-05 13:55:41 -0500682}
683
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400684/**
685 * hb_font_get_glyph_h_advance:
686 * @font: a font.
687 * @glyph:
688 *
689 *
690 *
691 * Return value:
692 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430693 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400694 **/
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400695hb_position_t
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400696hb_font_get_glyph_h_advance (hb_font_t *font,
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400697 hb_codepoint_t glyph)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400698{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400699 return font->get_glyph_h_advance (glyph);
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400700}
701
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400702/**
703 * hb_font_get_glyph_v_advance:
704 * @font: a font.
705 * @glyph:
706 *
707 *
708 *
709 * Return value:
710 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430711 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400712 **/
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400713hb_position_t
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400714hb_font_get_glyph_v_advance (hb_font_t *font,
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400715 hb_codepoint_t glyph)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400716{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400717 return font->get_glyph_v_advance (glyph);
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400718}
719
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400720/**
721 * hb_font_get_glyph_h_origin:
722 * @font: a font.
723 * @glyph:
724 * @x: (out):
725 * @y: (out):
726 *
727 *
728 *
729 * Return value:
730 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430731 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400732 **/
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400733hb_bool_t
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400734hb_font_get_glyph_h_origin (hb_font_t *font,
735 hb_codepoint_t glyph,
Behdad Esfahbod19098182011-05-17 23:27:22 -0400736 hb_position_t *x, hb_position_t *y)
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400737{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400738 return font->get_glyph_h_origin (glyph, x, y);
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400739}
740
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400741/**
742 * hb_font_get_glyph_v_origin:
743 * @font: a font.
744 * @glyph:
745 * @x: (out):
746 * @y: (out):
747 *
748 *
749 *
750 * Return value:
751 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430752 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400753 **/
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400754hb_bool_t
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400755hb_font_get_glyph_v_origin (hb_font_t *font,
756 hb_codepoint_t glyph,
Behdad Esfahbod19098182011-05-17 23:27:22 -0400757 hb_position_t *x, hb_position_t *y)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400758{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400759 return font->get_glyph_v_origin (glyph, x, y);
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400760}
761
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400762/**
763 * hb_font_get_glyph_h_kerning:
764 * @font: a font.
765 * @left_glyph:
766 * @right_glyph:
767 *
768 *
769 *
770 * Return value:
771 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430772 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400773 **/
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400774hb_position_t
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400775hb_font_get_glyph_h_kerning (hb_font_t *font,
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400776 hb_codepoint_t left_glyph, hb_codepoint_t right_glyph)
Behdad Esfahbod2e336692009-11-05 13:55:41 -0500777{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400778 return font->get_glyph_h_kerning (left_glyph, right_glyph);
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400779}
780
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400781/**
782 * hb_font_get_glyph_v_kerning:
783 * @font: a font.
784 * @top_glyph:
785 * @bottom_glyph:
786 *
787 *
788 *
789 * Return value:
790 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430791 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400792 **/
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400793hb_position_t
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400794hb_font_get_glyph_v_kerning (hb_font_t *font,
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400795 hb_codepoint_t top_glyph, hb_codepoint_t bottom_glyph)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400796{
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400797 return font->get_glyph_v_kerning (top_glyph, bottom_glyph);
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400798}
799
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400800/**
801 * hb_font_get_glyph_extents:
802 * @font: a font.
803 * @glyph:
804 * @extents: (out):
805 *
806 *
807 *
808 * Return value:
809 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430810 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400811 **/
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400812hb_bool_t
813hb_font_get_glyph_extents (hb_font_t *font,
814 hb_codepoint_t glyph,
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400815 hb_glyph_extents_t *extents)
816{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400817 return font->get_glyph_extents (glyph, extents);
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400818}
819
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400820/**
821 * hb_font_get_glyph_contour_point:
822 * @font: a font.
823 * @glyph:
824 * @point_index:
825 * @x: (out):
826 * @y: (out):
827 *
828 *
829 *
830 * Return value:
831 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430832 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400833 **/
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400834hb_bool_t
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400835hb_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)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400838{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400839 return font->get_glyph_contour_point (glyph, point_index, x, y);
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400840}
841
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400842/**
843 * hb_font_get_glyph_name:
844 * @font: a font.
845 * @glyph:
846 * @name: (array length=size):
847 * @size:
848 *
849 *
850 *
851 * Return value:
852 *
Sascha Brawer01c3a882015-06-01 13:22:01 +0200853 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400854 **/
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400855hb_bool_t
856hb_font_get_glyph_name (hb_font_t *font,
857 hb_codepoint_t glyph,
858 char *name, unsigned int size)
859{
Behdad Esfahbod6f3a3002012-08-07 22:13:25 -0400860 return font->get_glyph_name (glyph, name, size);
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400861}
862
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400863/**
864 * hb_font_get_glyph_from_name:
865 * @font: a font.
866 * @name: (array length=len):
867 * @len:
868 * @glyph: (out):
869 *
870 *
871 *
872 * Return value:
873 *
Sascha Brawer01c3a882015-06-01 13:22:01 +0200874 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400875 **/
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400876hb_bool_t
877hb_font_get_glyph_from_name (hb_font_t *font,
878 const char *name, int len, /* -1 means nul-terminated */
879 hb_codepoint_t *glyph)
880{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400881 return font->get_glyph_from_name (name, len, glyph);
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400882}
883
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400884
885/* A bit higher-level, and with fallback */
886
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400887/**
Simon Cozens6f2e6de2015-10-26 16:23:22 +0900888 * hb_font_get_extents_for_direction:
889 * @font: a font.
890 * @direction:
891 * @extents:
892 *
893 *
894 *
Behdad Esfahbodf11c11a2015-12-16 17:08:36 +0100895 * Since: 1.1.3
Simon Cozens6f2e6de2015-10-26 16:23:22 +0900896 **/
897void
898hb_font_get_extents_for_direction (hb_font_t *font,
899 hb_direction_t direction,
900 hb_font_extents_t *extents)
901{
902 return font->get_extents_for_direction (direction, extents);
903}
904/**
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400905 * hb_font_get_glyph_advance_for_direction:
906 * @font: a font.
907 * @glyph:
908 * @direction:
909 * @x: (out):
910 * @y: (out):
911 *
912 *
913 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430914 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400915 **/
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400916void
917hb_font_get_glyph_advance_for_direction (hb_font_t *font,
918 hb_codepoint_t glyph,
919 hb_direction_t direction,
Behdad Esfahbod19098182011-05-17 23:27:22 -0400920 hb_position_t *x, hb_position_t *y)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400921{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400922 return font->get_glyph_advance_for_direction (glyph, direction, x, y);
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400923}
924
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400925/**
926 * hb_font_get_glyph_origin_for_direction:
927 * @font: a font.
928 * @glyph:
929 * @direction:
930 * @x: (out):
931 * @y: (out):
932 *
933 *
934 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430935 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400936 **/
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400937void
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400938hb_font_get_glyph_origin_for_direction (hb_font_t *font,
939 hb_codepoint_t glyph,
940 hb_direction_t direction,
Behdad Esfahbod19098182011-05-17 23:27:22 -0400941 hb_position_t *x, hb_position_t *y)
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400942{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400943 return font->get_glyph_origin_for_direction (glyph, direction, x, y);
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400944}
945
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400946/**
947 * hb_font_add_glyph_origin_for_direction:
948 * @font: a font.
949 * @glyph:
950 * @direction:
951 * @x: (out):
952 * @y: (out):
953 *
954 *
955 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430956 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400957 **/
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400958void
Behdad Esfahbod8b38fae2011-05-19 13:08:00 -0400959hb_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)
963{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400964 return font->add_glyph_origin_for_direction (glyph, direction, x, y);
Behdad Esfahbod8b38fae2011-05-19 13:08:00 -0400965}
966
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400967/**
968 * hb_font_subtract_glyph_origin_for_direction:
969 * @font: a font.
970 * @glyph:
971 * @direction:
972 * @x: (out):
973 * @y: (out):
974 *
975 *
976 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430977 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400978 **/
Behdad Esfahbod8b38fae2011-05-19 13:08:00 -0400979void
980hb_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)
984{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400985 return font->subtract_glyph_origin_for_direction (glyph, direction, x, y);
Behdad Esfahbod8b38fae2011-05-19 13:08:00 -0400986}
987
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400988/**
989 * hb_font_get_glyph_kerning_for_direction:
990 * @font: a font.
991 * @first_glyph:
992 * @second_glyph:
993 * @direction:
994 * @x: (out):
995 * @y: (out):
996 *
997 *
998 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430999 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001000 **/
Behdad Esfahbod8b38fae2011-05-19 13:08:00 -04001001void
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -04001002hb_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,
Behdad Esfahbod19098182011-05-17 23:27:22 -04001005 hb_position_t *x, hb_position_t *y)
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001006{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -04001007 return font->get_glyph_kerning_for_direction (first_glyph, second_glyph, direction, x, y);
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001008}
1009
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001010/**
1011 * hb_font_get_glyph_extents_for_origin:
1012 * @font: a font.
1013 * @glyph:
1014 * @direction:
1015 * @extents: (out):
1016 *
1017 *
1018 *
1019 * Return value:
1020 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301021 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001022 **/
Behdad Esfahbod60fbb362011-05-19 18:46:15 -04001023hb_bool_t
1024hb_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)
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001028{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -04001029 return font->get_glyph_extents_for_origin (glyph, direction, extents);
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001030}
1031
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001032/**
1033 * hb_font_get_glyph_contour_point_for_origin:
1034 * @font: a font.
1035 * @glyph:
1036 * @point_index:
1037 * @direction:
1038 * @x: (out):
1039 * @y: (out):
1040 *
1041 *
1042 *
1043 * Return value:
1044 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301045 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001046 **/
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001047hb_bool_t
Behdad Esfahbod60fbb362011-05-19 18:46:15 -04001048hb_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)
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001052{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -04001053 return font->get_glyph_contour_point_for_origin (glyph, point_index, direction, x, y);
Behdad Esfahbod2e336692009-11-05 13:55:41 -05001054}
1055
Behdad Esfahbod6f3a3002012-08-07 22:13:25 -04001056/* Generates gidDDD if glyph has no name. */
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001057/**
1058 * hb_font_glyph_to_string:
1059 * @font: a font.
1060 * @glyph:
1061 * @s: (array length=size):
1062 * @size:
1063 *
1064 *
1065 *
Sascha Brawer01c3a882015-06-01 13:22:01 +02001066 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001067 **/
Behdad Esfahbod6f3a3002012-08-07 22:13:25 -04001068void
1069hb_font_glyph_to_string (hb_font_t *font,
1070 hb_codepoint_t glyph,
1071 char *s, unsigned int size)
1072{
1073 font->glyph_to_string (glyph, s, size);
1074}
1075
1076/* Parses gidDDD and uniUUUU strings automatically. */
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001077/**
1078 * hb_font_glyph_from_string:
1079 * @font: a font.
Khaled Hosnya394bb62015-03-22 20:29:10 +02001080 * @s: (array length=len) (element-type uint8_t):
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001081 * @len:
1082 * @glyph: (out):
1083 *
1084 *
1085 *
1086 * Return value:
1087 *
Sascha Brawer01c3a882015-06-01 13:22:01 +02001088 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001089 **/
Behdad Esfahbod6f3a3002012-08-07 22:13:25 -04001090hb_bool_t
1091hb_font_glyph_from_string (hb_font_t *font,
1092 const char *s, int len, /* -1 means nul-terminated */
1093 hb_codepoint_t *glyph)
1094{
1095 return font->glyph_from_string (s, len, glyph);
1096}
1097
Behdad Esfahbod1cebfbb2010-04-23 20:49:18 -04001098
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001099/*
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001100 * hb_font_t
1101 */
1102
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001103/**
Behdad Esfahbod085d4292013-09-12 17:14:33 -04001104 * hb_font_create: (Xconstructor)
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001105 * @face: a face.
1106 *
1107 *
1108 *
1109 * Return value: (transfer full):
1110 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301111 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001112 **/
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001113hb_font_t *
Behdad Esfahbod72657e42011-05-02 20:46:32 -04001114hb_font_create (hb_face_t *face)
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001115{
1116 hb_font_t *font;
1117
Behdad Esfahbod72657e42011-05-02 20:46:32 -04001118 if (unlikely (!face))
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -04001119 face = hb_face_get_empty ();
Behdad Esfahbod47e71d92011-04-27 16:38:03 -04001120 if (!(font = hb_object_create<hb_font_t> ()))
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -04001121 return hb_font_get_empty ();
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001122
Behdad Esfahbod7fc5a302011-05-12 17:48:20 -04001123 hb_face_make_immutable (face);
Behdad Esfahbodda29b432015-11-04 20:22:44 -08001124 font->parent = hb_font_get_empty ();
Behdad Esfahbod72657e42011-05-02 20:46:32 -04001125 font->face = hb_face_reference (face);
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -04001126 font->klass = hb_font_funcs_get_empty ();
Behdad Esfahbod85555a92009-11-05 18:25:56 -05001127
Behdad Esfahbod88da7bb2015-10-02 14:38:20 +01001128 font->x_scale = font->y_scale = hb_face_get_upem (face);
1129
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001130 return font;
1131}
1132
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001133/**
1134 * hb_font_create_sub_font:
1135 * @parent: parent font.
1136 *
1137 *
1138 *
1139 * Return value: (transfer full):
1140 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301141 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001142 **/
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001143hb_font_t *
Behdad Esfahboddefc45b2011-05-10 20:02:49 -04001144hb_font_create_sub_font (hb_font_t *parent)
1145{
1146 if (unlikely (!parent))
Behdad Esfahbodeb0bf3a2014-08-06 15:36:41 -04001147 parent = hb_font_get_empty ();
Behdad Esfahboddefc45b2011-05-10 20:02:49 -04001148
1149 hb_font_t *font = hb_font_create (parent->face);
1150
1151 if (unlikely (hb_object_is_inert (font)))
1152 return font;
1153
Behdad Esfahboddefc45b2011-05-10 20:02:49 -04001154 font->parent = hb_font_reference (parent);
1155
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;
1160
Behdad Esfahbodca286702016-03-01 19:29:36 +09001161 /* TODO: copy variation coordinates. */
1162
Behdad Esfahboddefc45b2011-05-10 20:02:49 -04001163 return font;
1164}
1165
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001166/**
1167 * hb_font_get_empty:
1168 *
1169 *
1170 *
1171 * Return value: (transfer full)
1172 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301173 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001174 **/
Behdad Esfahboddefc45b2011-05-10 20:02:49 -04001175hb_font_t *
Behdad Esfahbod80a68332011-05-11 18:14:44 -04001176hb_font_get_empty (void)
1177{
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -04001178 static const hb_font_t _hb_font_nil = {
1179 HB_OBJECT_HEADER_STATIC,
1180
Behdad Esfahbod0594a242012-06-05 20:35:40 -04001181 true, /* immutable */
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -04001182
1183 NULL, /* parent */
1184 const_cast<hb_face_t *> (&_hb_face_nil),
1185
Behdad Esfahbodda29b432015-11-04 20:22:44 -08001186 1000, /* x_scale */
1187 1000, /* y_scale */
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -04001188
1189 0, /* x_ppem */
1190 0, /* y_ppem */
1191
Behdad Esfahbodca286702016-03-01 19:29:36 +09001192 0, /* num_coords */
Behdad Esfahbod26648ce2016-09-10 02:11:05 -07001193 NULL, /* coords */
Behdad Esfahbod6d9d3c52016-03-01 19:12:08 +09001194
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -04001195 const_cast<hb_font_funcs_t *> (&_hb_font_funcs_nil), /* klass */
1196 NULL, /* user_data */
Behdad Esfahbodea278d32012-07-27 02:12:28 -04001197 NULL, /* destroy */
1198
Behdad Esfahbodd3d36912017-02-03 15:42:03 -08001199 hb_font_t::NOTHING, /* dirty */
Behdad Esfahbod2171f482017-02-03 10:58:09 -08001200
Behdad Esfahbodea278d32012-07-27 02:12:28 -04001201 {
1202#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID,
1203#include "hb-shaper-list.hh"
1204#undef HB_SHAPER_IMPLEMENT
1205 }
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -04001206 };
1207
1208 return const_cast<hb_font_t *> (&_hb_font_nil);
Behdad Esfahbod80a68332011-05-11 18:14:44 -04001209}
1210
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001211/**
1212 * hb_font_reference: (skip)
1213 * @font: a font.
1214 *
1215 *
1216 *
1217 * Return value: (transfer full):
1218 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301219 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001220 **/
Behdad Esfahbod80a68332011-05-11 18:14:44 -04001221hb_font_t *
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001222hb_font_reference (hb_font_t *font)
1223{
Behdad Esfahbod47e71d92011-04-27 16:38:03 -04001224 return hb_object_reference (font);
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001225}
1226
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001227/**
1228 * hb_font_destroy: (skip)
1229 * @font: a font.
1230 *
1231 *
1232 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301233 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001234 **/
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001235void
1236hb_font_destroy (hb_font_t *font)
1237{
Behdad Esfahbod47e71d92011-04-27 16:38:03 -04001238 if (!hb_object_destroy (font)) return;
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001239
Behdad Esfahbod027857d2012-07-26 17:34:25 -04001240#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_DESTROY(shaper, font);
1241#include "hb-shaper-list.hh"
1242#undef HB_SHAPER_IMPLEMENT
1243
1244 if (font->destroy)
1245 font->destroy (font->user_data);
1246
Behdad Esfahboddefc45b2011-05-10 20:02:49 -04001247 hb_font_destroy (font->parent);
Behdad Esfahbod72657e42011-05-02 20:46:32 -04001248 hb_face_destroy (font->face);
Behdad Esfahbod5c441882009-08-10 20:05:16 -04001249 hb_font_funcs_destroy (font->klass);
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001250
Behdad Esfahbod72ada4f2016-09-10 03:57:24 -07001251 free (font->coords);
Behdad Esfahbodca286702016-03-01 19:29:36 +09001252
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001253 free (font);
1254}
1255
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001256/**
1257 * hb_font_set_user_data: (skip)
1258 * @font: a font.
1259 * @key:
1260 * @data:
1261 * @destroy:
1262 * @replace:
1263 *
1264 *
1265 *
1266 * Return value:
1267 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301268 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001269 **/
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -04001270hb_bool_t
1271hb_font_set_user_data (hb_font_t *font,
1272 hb_user_data_key_t *key,
1273 void * data,
Behdad Esfahbod33ccc772011-08-09 00:43:24 +02001274 hb_destroy_func_t destroy,
1275 hb_bool_t replace)
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -04001276{
Behdad Esfahbod33ccc772011-08-09 00:43:24 +02001277 return hb_object_set_user_data (font, key, data, destroy, replace);
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -04001278}
1279
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001280/**
1281 * hb_font_get_user_data: (skip)
1282 * @font: a font.
1283 * @key:
1284 *
1285 *
1286 *
1287 * Return value: (transfer none):
1288 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301289 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001290 **/
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -04001291void *
1292hb_font_get_user_data (hb_font_t *font,
1293 hb_user_data_key_t *key)
1294{
1295 return hb_object_get_user_data (font, key);
1296}
1297
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001298/**
1299 * hb_font_make_immutable:
1300 * @font: a font.
1301 *
1302 *
1303 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301304 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001305 **/
Behdad Esfahbod74f1d892011-05-10 19:39:32 -04001306void
1307hb_font_make_immutable (hb_font_t *font)
1308{
Behdad Esfahbod3f310dc2014-07-22 16:26:27 -04001309 if (unlikely (hb_object_is_inert (font)))
Behdad Esfahbod74f1d892011-05-10 19:39:32 -04001310 return;
1311
Behdad Esfahbod1866e172015-10-02 14:21:29 +01001312 if (font->parent)
1313 hb_font_make_immutable (font->parent);
1314
Behdad Esfahbod74f1d892011-05-10 19:39:32 -04001315 font->immutable = true;
1316}
1317
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001318/**
1319 * hb_font_is_immutable:
1320 * @font: a font.
1321 *
1322 *
1323 *
1324 * Return value:
1325 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301326 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001327 **/
Behdad Esfahbod74f1d892011-05-10 19:39:32 -04001328hb_bool_t
1329hb_font_is_immutable (hb_font_t *font)
1330{
1331 return font->immutable;
1332}
1333
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001334/**
Behdad Esfahbod3e905e32015-10-08 12:51:02 -04001335 * hb_font_set_parent:
1336 * @font: a font.
1337 * @parent: new parent.
1338 *
1339 * Sets parent font of @font.
1340 *
1341 * Since: 1.0.5
1342 **/
1343void
1344hb_font_set_parent (hb_font_t *font,
1345 hb_font_t *parent)
1346{
1347 if (font->immutable)
1348 return;
1349
1350 if (!parent)
1351 parent = hb_font_get_empty ();
1352
Behdad Esfahbod2171f482017-02-03 10:58:09 -08001353 if (parent == font->parent)
1354 return;
1355
1356 font->dirty |= font->PARENT;
1357
Behdad Esfahbod3e905e32015-10-08 12:51:02 -04001358 hb_font_t *old = font->parent;
1359
1360 font->parent = hb_font_reference (parent);
1361
1362 hb_font_destroy (old);
1363}
1364
1365/**
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001366 * hb_font_get_parent:
1367 * @font: a font.
1368 *
1369 *
1370 *
1371 * Return value: (transfer none):
1372 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301373 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001374 **/
Behdad Esfahboddefc45b2011-05-10 20:02:49 -04001375hb_font_t *
1376hb_font_get_parent (hb_font_t *font)
1377{
1378 return font->parent;
1379}
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -04001380
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001381/**
Behdad Esfahbod95808ba2017-02-03 10:39:40 -08001382 * hb_font_set_face:
1383 * @font: a font.
1384 * @face: new face.
1385 *
1386 * Sets font-face of @font.
1387 *
1388 * Since: 1.4.3
1389 **/
1390void
1391hb_font_set_face (hb_font_t *font,
1392 hb_face_t *face)
1393{
1394 if (font->immutable)
1395 return;
1396
1397 if (unlikely (!face))
1398 face = hb_face_get_empty ();
1399
1400 if (font->face == face)
1401 return;
1402
Behdad Esfahbod2171f482017-02-03 10:58:09 -08001403 font->dirty |= font->FACE;
1404
Behdad Esfahbod95808ba2017-02-03 10:39:40 -08001405 hb_face_t *old = font->face;
1406
1407 font->face = hb_face_reference (face);
1408
1409 hb_face_destroy (old);
1410}
1411
1412/**
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001413 * hb_font_get_face:
1414 * @font: a font.
1415 *
1416 *
1417 *
1418 * Return value: (transfer none):
1419 *
Sascha Brawer01c3a882015-06-01 13:22:01 +02001420 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001421 **/
Behdad Esfahbod72657e42011-05-02 20:46:32 -04001422hb_face_t *
1423hb_font_get_face (hb_font_t *font)
1424{
1425 return font->face;
1426}
1427
1428
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001429/**
1430 * hb_font_set_funcs:
1431 * @font: a font.
Behdad Esfahboda8949df2013-09-13 20:23:51 -04001432 * @klass: (closure font_data) (destroy destroy) (scope notified):
Behdad Esfahbod70303cf2013-09-06 17:35:57 -04001433 * @font_data:
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001434 * @destroy:
1435 *
1436 *
1437 *
Sascha Brawer01c3a882015-06-01 13:22:01 +02001438 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001439 **/
Behdad Esfahbod5c441882009-08-10 20:05:16 -04001440void
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -05001441hb_font_set_funcs (hb_font_t *font,
1442 hb_font_funcs_t *klass,
Behdad Esfahbod70303cf2013-09-06 17:35:57 -04001443 void *font_data,
Behdad Esfahbod56681892011-04-20 03:03:32 -04001444 hb_destroy_func_t destroy)
Behdad Esfahbod0ead4812009-08-02 17:41:36 -04001445{
Behdad Esfahbod0cd33592011-09-21 16:49:33 -04001446 if (font->immutable) {
1447 if (destroy)
Behdad Esfahbod70303cf2013-09-06 17:35:57 -04001448 destroy (font_data);
Behdad Esfahbod5c441882009-08-10 20:05:16 -04001449 return;
Behdad Esfahbod0cd33592011-09-21 16:49:33 -04001450 }
Behdad Esfahbod0ead4812009-08-02 17:41:36 -04001451
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -05001452 if (font->destroy)
1453 font->destroy (font->user_data);
1454
Behdad Esfahbod0465e692009-12-20 16:25:18 +01001455 if (!klass)
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -04001456 klass = hb_font_funcs_get_empty ();
Behdad Esfahbod0465e692009-12-20 16:25:18 +01001457
Behdad Esfahbod2171f482017-02-03 10:58:09 -08001458 font->dirty |= font->FUNCS;
1459
Behdad Esfahbod5c441882009-08-10 20:05:16 -04001460 hb_font_funcs_reference (klass);
1461 hb_font_funcs_destroy (font->klass);
1462 font->klass = klass;
Behdad Esfahbod70303cf2013-09-06 17:35:57 -04001463 font->user_data = font_data;
Behdad Esfahbod56681892011-04-20 03:03:32 -04001464 font->destroy = destroy;
Behdad Esfahbod0ead4812009-08-02 17:41:36 -04001465}
1466
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001467/**
1468 * hb_font_set_funcs_data:
1469 * @font: a font.
Behdad Esfahboda8949df2013-09-13 20:23:51 -04001470 * @font_data: (destroy destroy) (scope notified):
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001471 * @destroy:
1472 *
1473 *
1474 *
Sascha Brawer01c3a882015-06-01 13:22:01 +02001475 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001476 **/
Behdad Esfahbodb9415e72011-08-17 19:21:44 +02001477void
1478hb_font_set_funcs_data (hb_font_t *font,
Behdad Esfahbod70303cf2013-09-06 17:35:57 -04001479 void *font_data,
Behdad Esfahbodb9415e72011-08-17 19:21:44 +02001480 hb_destroy_func_t destroy)
1481{
Behdad Esfahbod0cd33592011-09-21 16:49:33 -04001482 /* Destroy user_data? */
1483 if (font->immutable) {
1484 if (destroy)
Behdad Esfahbod70303cf2013-09-06 17:35:57 -04001485 destroy (font_data);
Behdad Esfahbodb9415e72011-08-17 19:21:44 +02001486 return;
Behdad Esfahbod0cd33592011-09-21 16:49:33 -04001487 }
Behdad Esfahbodb9415e72011-08-17 19:21:44 +02001488
1489 if (font->destroy)
1490 font->destroy (font->user_data);
1491
Behdad Esfahbod70303cf2013-09-06 17:35:57 -04001492 font->user_data = font_data;
Behdad Esfahbodb9415e72011-08-17 19:21:44 +02001493 font->destroy = destroy;
1494}
1495
Behdad Esfahbod19c0eab2010-10-04 16:45:21 -04001496
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001497/**
1498 * hb_font_set_scale:
1499 * @font: a font.
1500 * @x_scale:
1501 * @y_scale:
1502 *
1503 *
1504 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301505 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001506 **/
Behdad Esfahbod19c0eab2010-10-04 16:45:21 -04001507void
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001508hb_font_set_scale (hb_font_t *font,
Behdad Esfahbodda975412011-04-21 15:08:01 -04001509 int x_scale,
1510 int y_scale)
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001511{
Behdad Esfahbod74f1d892011-05-10 19:39:32 -04001512 if (font->immutable)
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001513 return;
1514
Behdad Esfahbod2171f482017-02-03 10:58:09 -08001515 if (font->x_scale == x_scale && font->y_scale == y_scale)
1516 return;
1517
1518 font->dirty |= font->SCALE;
1519
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001520 font->x_scale = x_scale;
1521 font->y_scale = y_scale;
1522}
1523
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001524/**
1525 * hb_font_get_scale:
1526 * @font: a font.
1527 * @x_scale: (out):
1528 * @y_scale: (out):
1529 *
1530 *
1531 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301532 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001533 **/
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001534void
Behdad Esfahbod19c0eab2010-10-04 16:45:21 -04001535hb_font_get_scale (hb_font_t *font,
Behdad Esfahbodda975412011-04-21 15:08:01 -04001536 int *x_scale,
1537 int *y_scale)
Behdad Esfahbod19c0eab2010-10-04 16:45:21 -04001538{
1539 if (x_scale) *x_scale = font->x_scale;
1540 if (y_scale) *y_scale = font->y_scale;
1541}
1542
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001543/**
1544 * hb_font_set_ppem:
1545 * @font: a font.
1546 * @x_ppem:
1547 * @y_ppem:
1548 *
1549 *
1550 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301551 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001552 **/
Behdad Esfahbod19c0eab2010-10-04 16:45:21 -04001553void
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001554hb_font_set_ppem (hb_font_t *font,
1555 unsigned int x_ppem,
1556 unsigned int y_ppem)
1557{
Behdad Esfahbod74f1d892011-05-10 19:39:32 -04001558 if (font->immutable)
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001559 return;
1560
Behdad Esfahbod2171f482017-02-03 10:58:09 -08001561 if (font->x_ppem == x_ppem && font->y_ppem == y_ppem)
1562 return;
1563
1564 font->dirty |= font->PPEM;
1565
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001566 font->x_ppem = x_ppem;
1567 font->y_ppem = y_ppem;
1568}
1569
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001570/**
1571 * hb_font_get_ppem:
1572 * @font: a font.
1573 * @x_ppem: (out):
1574 * @y_ppem: (out):
1575 *
1576 *
1577 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301578 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001579 **/
Behdad Esfahbod19c0eab2010-10-04 16:45:21 -04001580void
1581hb_font_get_ppem (hb_font_t *font,
1582 unsigned int *x_ppem,
1583 unsigned int *y_ppem)
1584{
1585 if (x_ppem) *x_ppem = font->x_ppem;
1586 if (y_ppem) *y_ppem = font->y_ppem;
1587}
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09001588
Behdad Esfahbod8b2a5802017-01-21 15:05:00 -08001589/*
1590 * Variations
1591 */
1592
Behdad Esfahbod64fe92b2017-01-21 15:36:35 -08001593static void
1594_hb_font_adopt_var_coords_normalized (hb_font_t *font,
1595 int *coords, /* 2.14 normalized */
1596 unsigned int coords_length)
1597{
Behdad Esfahbod2171f482017-02-03 10:58:09 -08001598 if (font->num_coords == coords_length &&
Philip Withnallffde3c92017-02-08 21:56:57 +00001599 (coords_length == 0 ||
1600 0 == memcmp (font->coords, coords, coords_length * sizeof (coords[0]))))
Behdad Esfahbod2171f482017-02-03 10:58:09 -08001601 {
1602 free (coords);
1603 return;
1604 }
1605
1606 font->dirty |= font->VARIATIONS;
1607
Behdad Esfahbod64fe92b2017-01-21 15:36:35 -08001608 free (font->coords);
1609
1610 font->coords = coords;
1611 font->num_coords = coords_length;
1612}
1613
Behdad Esfahbodd2f249e2017-01-22 17:42:33 -08001614/**
1615 * hb_font_set_variations:
1616 *
1617 * Since: 1.4.2
1618 */
Behdad Esfahbod8b2a5802017-01-21 15:05:00 -08001619void
Behdad Esfahbodbb1e1922017-01-21 17:41:37 -08001620hb_font_set_variations (hb_font_t *font,
1621 const hb_variation_t *variations,
1622 unsigned int variations_length)
Behdad Esfahbod24911342017-01-21 15:21:50 -08001623{
1624 if (font->immutable)
1625 return;
1626
Behdad Esfahbodbb1e1922017-01-21 17:41:37 -08001627 if (!variations_length)
Behdad Esfahbod24911342017-01-21 15:21:50 -08001628 {
1629 hb_font_set_var_coords_normalized (font, NULL, 0);
1630 return;
1631 }
1632
Behdad Esfahbod5ec96d32017-01-22 18:52:00 -08001633 unsigned int coords_length = hb_ot_var_get_axis_count (font->face);
Behdad Esfahbod24911342017-01-21 15:21:50 -08001634
Behdad Esfahbodbb1e1922017-01-21 17:41:37 -08001635 int *normalized = coords_length ? (int *) calloc (coords_length, sizeof (int)) : NULL;
1636 if (unlikely (coords_length && !normalized))
Behdad Esfahbod64fe92b2017-01-21 15:36:35 -08001637 return;
Behdad Esfahbod24911342017-01-21 15:21:50 -08001638
Behdad Esfahbod5ec96d32017-01-22 18:52:00 -08001639 hb_ot_var_normalize_variations (font->face,
1640 variations, variations_length,
1641 normalized, coords_length);
Behdad Esfahbod64fe92b2017-01-21 15:36:35 -08001642 _hb_font_adopt_var_coords_normalized (font, normalized, coords_length);
Behdad Esfahbod24911342017-01-21 15:21:50 -08001643}
1644
Behdad Esfahbodd2f249e2017-01-22 17:42:33 -08001645/**
1646 * hb_font_set_var_coords_design:
1647 *
1648 * Since: 1.4.2
1649 */
Behdad Esfahbod24911342017-01-21 15:21:50 -08001650void
Behdad Esfahbod8b2a5802017-01-21 15:05:00 -08001651hb_font_set_var_coords_design (hb_font_t *font,
Behdad Esfahbod24911342017-01-21 15:21:50 -08001652 const float *coords,
Behdad Esfahbod8b2a5802017-01-21 15:05:00 -08001653 unsigned int coords_length)
1654{
Behdad Esfahbod24911342017-01-21 15:21:50 -08001655 if (font->immutable)
1656 return;
1657
Behdad Esfahbod64fe92b2017-01-21 15:36:35 -08001658 int *normalized = coords_length ? (int *) calloc (coords_length, sizeof (int)) : NULL;
1659 if (unlikely (coords_length && !normalized))
1660 return;
Behdad Esfahbod8b2a5802017-01-21 15:05:00 -08001661
Behdad Esfahbod5ec96d32017-01-22 18:52:00 -08001662 hb_ot_var_normalize_coords (font->face, coords_length, coords, normalized);
Behdad Esfahbod64fe92b2017-01-21 15:36:35 -08001663 _hb_font_adopt_var_coords_normalized (font, normalized, coords_length);
Behdad Esfahbod8b2a5802017-01-21 15:05:00 -08001664}
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09001665
Behdad Esfahbodd2f249e2017-01-22 17:42:33 -08001666/**
1667 * hb_font_set_var_coords_normalized:
1668 *
1669 * Since: 1.4.2
1670 */
Behdad Esfahbodad69e8f2016-09-09 22:23:34 -07001671void
1672hb_font_set_var_coords_normalized (hb_font_t *font,
Behdad Esfahbod24911342017-01-21 15:21:50 -08001673 const int *coords, /* 2.14 normalized */
Behdad Esfahbodad69e8f2016-09-09 22:23:34 -07001674 unsigned int coords_length)
1675{
1676 if (font->immutable)
1677 return;
1678
Behdad Esfahbodc22176d2016-09-10 01:58:27 -07001679 int *copy = coords_length ? (int *) calloc (coords_length, sizeof (coords[0])) : NULL;
1680 if (unlikely (coords_length && !copy))
Behdad Esfahbodad69e8f2016-09-09 22:23:34 -07001681 return;
1682
Behdad Esfahbodc22176d2016-09-10 01:58:27 -07001683 if (coords_length)
1684 memcpy (copy, coords, coords_length * sizeof (coords[0]));
1685
Behdad Esfahbod64fe92b2017-01-21 15:36:35 -08001686 _hb_font_adopt_var_coords_normalized (font, copy, coords_length);
Behdad Esfahbodad69e8f2016-09-09 22:23:34 -07001687}
1688
Behdad Esfahbodd2f249e2017-01-22 17:42:33 -08001689/**
Behdad Esfahbod22af28a2017-01-23 23:42:53 -08001690 * hb_font_get_var_coords_normalized:
Behdad Esfahbodd2f249e2017-01-22 17:42:33 -08001691 *
Behdad Esfahbod7647a052017-01-22 17:47:49 -08001692 * Return value is valid as long as variation coordinates of the font
1693 * are not modified.
1694 *
Behdad Esfahbodd2f249e2017-01-22 17:42:33 -08001695 * Since: 1.4.2
1696 */
Behdad Esfahbod7647a052017-01-22 17:47:49 -08001697const int *
Behdad Esfahbodbf0d3a62017-01-21 14:48:46 -08001698hb_font_get_var_coords_normalized (hb_font_t *font,
1699 unsigned int *length)
1700{
1701 if (length)
Behdad Esfahbod8b2a5802017-01-21 15:05:00 -08001702 *length = font->num_coords;
Behdad Esfahbodbf0d3a62017-01-21 14:48:46 -08001703
1704 return font->coords;
1705}
1706
Behdad Esfahbodad69e8f2016-09-09 22:23:34 -07001707
Konstantin Ritt71248a82016-02-25 18:55:28 +04001708#ifndef HB_DISABLE_DEPRECATED
1709
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09001710/*
1711 * Deprecated get_glyph_func():
1712 */
1713
1714struct hb_trampoline_closure_t
1715{
1716 void *user_data;
1717 hb_destroy_func_t destroy;
Behdad Esfahbodc335fd72016-02-25 09:16:05 +09001718 unsigned int ref_count;
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09001719};
1720
1721template <typename FuncType>
1722struct hb_trampoline_t
1723{
1724 hb_trampoline_closure_t closure; /* Must be first. */
1725 FuncType func;
1726};
1727
1728template <typename FuncType>
1729static hb_trampoline_t<FuncType> *
1730trampoline_create (FuncType func,
1731 void *user_data,
1732 hb_destroy_func_t destroy)
1733{
1734 typedef hb_trampoline_t<FuncType> trampoline_t;
1735
1736 trampoline_t *trampoline = (trampoline_t *) calloc (1, sizeof (trampoline_t));
1737
1738 if (unlikely (!trampoline))
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09001739 return NULL;
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09001740
1741 trampoline->closure.user_data = user_data;
1742 trampoline->closure.destroy = destroy;
Behdad Esfahbodc335fd72016-02-25 09:16:05 +09001743 trampoline->closure.ref_count = 1;
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09001744 trampoline->func = func;
1745
1746 return trampoline;
1747}
1748
1749static void
Behdad Esfahbodc335fd72016-02-25 09:16:05 +09001750trampoline_reference (hb_trampoline_closure_t *closure)
1751{
1752 closure->ref_count++;
1753}
1754
1755static void
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09001756trampoline_destroy (void *user_data)
1757{
1758 hb_trampoline_closure_t *closure = (hb_trampoline_closure_t *) user_data;
Behdad Esfahbodc335fd72016-02-25 09:16:05 +09001759
1760 if (--closure->ref_count)
1761 return;
1762
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09001763 if (closure->destroy)
1764 closure->destroy (closure->user_data);
1765 free (closure);
1766}
1767
1768typedef hb_trampoline_t<hb_font_get_glyph_func_t> hb_font_get_glyph_trampoline_t;
1769
1770static hb_bool_t
1771hb_font_get_nominal_glyph_trampoline (hb_font_t *font,
1772 void *font_data,
1773 hb_codepoint_t unicode,
1774 hb_codepoint_t *glyph,
1775 void *user_data)
1776{
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);
1779}
1780
1781static hb_bool_t
1782hb_font_get_variation_glyph_trampoline (hb_font_t *font,
1783 void *font_data,
1784 hb_codepoint_t unicode,
1785 hb_codepoint_t variation_selector,
1786 hb_codepoint_t *glyph,
1787 void *user_data)
1788{
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);
1791}
1792
1793/**
1794 * hb_font_funcs_set_glyph_func:
1795 * @ffuncs: font functions.
1796 * @func: (closure user_data) (destroy destroy) (scope notified):
1797 * @user_data:
1798 * @destroy:
1799 *
1800 * Deprecated. Use hb_font_funcs_set_nominal_glyph_func() and
1801 * hb_font_funcs_set_variation_glyph_func() instead.
1802 *
1803 * Since: 0.9.2
1804 * Deprecated: 1.2.3
1805 **/
1806void
1807hb_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)
1810{
1811 hb_font_get_glyph_trampoline_t *trampoline;
1812
1813 trampoline = trampoline_create (func, user_data, destroy);
Behdad Esfahbodc335fd72016-02-25 09:16:05 +09001814 if (unlikely (!trampoline))
1815 {
1816 if (destroy)
1817 destroy (user_data);
1818 return;
1819 }
1820
1821 hb_font_funcs_set_nominal_glyph_func (ffuncs,
1822 hb_font_get_nominal_glyph_trampoline,
1823 trampoline,
1824 trampoline_destroy);
1825
1826 trampoline_reference (&trampoline->closure);
1827 hb_font_funcs_set_variation_glyph_func (ffuncs,
1828 hb_font_get_variation_glyph_trampoline,
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09001829 trampoline,
1830 trampoline_destroy);
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09001831}
Konstantin Ritt71248a82016-02-25 18:55:28 +04001832
1833#endif /* HB_DISABLE_DEPRECATED */