blob: b4b4d0a52719f3b6d245c218a5fd0ad3d114cc57 [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 Esfahbod266b3442011-05-03 00:35:53 -040031#include "hb-ot-layout-private.hh"
32
Behdad Esfahbodc57d4542011-04-20 18:50:27 -040033#include "hb-font-private.hh"
Behdad Esfahbod23c86aa2009-08-03 21:40:20 -040034#include "hb-open-file-private.hh"
Behdad Esfahbod7a750ac2011-08-17 14:19:59 +020035#include "hb-ot-head-table.hh"
Behdad Esfahbode05a9992012-11-15 16:23:21 -080036#include "hb-ot-maxp-table.hh"
Behdad Esfahbodc62b5032009-08-01 19:54:49 -040037
Behdad Esfahbod79512792009-11-03 20:27:05 -050038#include <string.h>
39
Behdad Esfahbodacdba3f2010-07-23 15:11:18 -040040
Behdad Esfahbodc62b5032009-08-01 19:54:49 -040041/*
Behdad Esfahbod5c441882009-08-10 20:05:16 -040042 * hb_font_funcs_t
Behdad Esfahbodc62b5032009-08-01 19:54:49 -040043 */
44
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -040045static hb_bool_t
Simon Cozens6f2e6de2015-10-26 16:23:22 +090046hb_font_get_font_h_extents_nil (hb_font_t *font,
47 void *font_data HB_UNUSED,
48 hb_font_extents_t *metrics,
49 void *user_data HB_UNUSED)
50{
51 memset (metrics, 0, sizeof (*metrics));
52 return false;
53}
54static hb_bool_t
55hb_font_get_font_h_extents_parent (hb_font_t *font,
56 void *font_data HB_UNUSED,
57 hb_font_extents_t *metrics,
58 void *user_data HB_UNUSED)
59{
60 hb_bool_t ret = font->parent->get_font_h_extents (metrics);
61 if (ret) {
62 metrics->ascender = font->parent_scale_y_distance (metrics->ascender);
63 metrics->descender = font->parent_scale_y_distance (metrics->descender);
64 metrics->line_gap = font->parent_scale_y_distance (metrics->line_gap);
65 }
66 return ret;
67}
68
69static hb_bool_t
70hb_font_get_font_v_extents_nil (hb_font_t *font,
71 void *font_data HB_UNUSED,
72 hb_font_extents_t *metrics,
73 void *user_data HB_UNUSED)
74{
75 memset (metrics, 0, sizeof (*metrics));
76 return false;
77}
78static hb_bool_t
79hb_font_get_font_v_extents_parent (hb_font_t *font,
80 void *font_data HB_UNUSED,
81 hb_font_extents_t *metrics,
82 void *user_data HB_UNUSED)
83{
84 hb_bool_t ret = font->parent->get_font_v_extents (metrics);
85 if (ret) {
86 metrics->ascender = font->parent_scale_x_distance (metrics->ascender);
87 metrics->descender = font->parent_scale_x_distance (metrics->descender);
88 metrics->line_gap = font->parent_scale_x_distance (metrics->line_gap);
89 }
90 return ret;
91}
92
93static hb_bool_t
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +090094hb_font_get_nominal_glyph_nil (hb_font_t *font HB_UNUSED,
95 void *font_data HB_UNUSED,
96 hb_codepoint_t unicode,
97 hb_codepoint_t *glyph,
98 void *user_data HB_UNUSED)
Behdad Esfahbod1ded6d82011-05-10 20:49:02 -040099{
Behdad Esfahbod0fd8c2f2011-05-12 15:14:13 -0400100 *glyph = 0;
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400101 return false;
Behdad Esfahbod1ded6d82011-05-10 20:49:02 -0400102}
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800103static hb_bool_t
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +0900104hb_font_get_nominal_glyph_parent (hb_font_t *font,
105 void *font_data HB_UNUSED,
106 hb_codepoint_t unicode,
107 hb_codepoint_t *glyph,
108 void *user_data HB_UNUSED)
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800109{
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +0900110 return font->parent->get_nominal_glyph (unicode, glyph);
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800111}
Behdad Esfahbod79512792009-11-03 20:27:05 -0500112
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +0900113static hb_bool_t
114hb_font_get_variation_glyph_nil (hb_font_t *font HB_UNUSED,
115 void *font_data HB_UNUSED,
116 hb_codepoint_t unicode,
117 hb_codepoint_t variation_selector,
118 hb_codepoint_t *glyph,
119 void *user_data HB_UNUSED)
120{
121 *glyph = 0;
122 return false;
123}
124static hb_bool_t
125hb_font_get_variation_glyph_parent (hb_font_t *font,
126 void *font_data HB_UNUSED,
127 hb_codepoint_t unicode,
128 hb_codepoint_t variation_selector,
129 hb_codepoint_t *glyph,
130 void *user_data HB_UNUSED)
131{
132 return font->parent->get_variation_glyph (unicode, variation_selector, glyph);
133}
134
135
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400136static hb_position_t
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800137hb_font_get_glyph_h_advance_nil (hb_font_t *font HB_UNUSED,
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400138 void *font_data HB_UNUSED,
139 hb_codepoint_t glyph,
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400140 void *user_data HB_UNUSED)
Behdad Esfahbod1ded6d82011-05-10 20:49:02 -0400141{
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400142 return font->x_scale;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400143}
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800144static hb_position_t
145hb_font_get_glyph_h_advance_parent (hb_font_t *font,
146 void *font_data HB_UNUSED,
147 hb_codepoint_t glyph,
148 void *user_data HB_UNUSED)
149{
150 return font->parent_scale_x_distance (font->parent->get_glyph_h_advance (glyph));
151}
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400152
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400153static hb_position_t
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800154hb_font_get_glyph_v_advance_nil (hb_font_t *font HB_UNUSED,
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400155 void *font_data HB_UNUSED,
156 hb_codepoint_t glyph,
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400157 void *user_data HB_UNUSED)
158{
Behdad Esfahbodaba4b0c2016-06-01 16:57:29 -0700159 /* TODO use font_extents.ascender+descender */
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400160 return font->y_scale;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400161}
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800162static hb_position_t
163hb_font_get_glyph_v_advance_parent (hb_font_t *font,
164 void *font_data HB_UNUSED,
165 hb_codepoint_t glyph,
166 void *user_data HB_UNUSED)
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400167{
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800168 return font->parent_scale_y_distance (font->parent->get_glyph_v_advance (glyph));
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400169}
170
171static hb_bool_t
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800172hb_font_get_glyph_h_origin_nil (hb_font_t *font HB_UNUSED,
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400173 void *font_data HB_UNUSED,
174 hb_codepoint_t glyph,
Behdad Esfahbod19098182011-05-17 23:27:22 -0400175 hb_position_t *x,
176 hb_position_t *y,
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400177 void *user_data HB_UNUSED)
178{
Behdad Esfahbod19098182011-05-17 23:27:22 -0400179 *x = *y = 0;
Behdad Esfahbodc41c1452015-11-26 18:43:15 -0500180 return true;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400181}
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800182static hb_bool_t
183hb_font_get_glyph_h_origin_parent (hb_font_t *font,
184 void *font_data HB_UNUSED,
185 hb_codepoint_t glyph,
186 hb_position_t *x,
187 hb_position_t *y,
188 void *user_data HB_UNUSED)
189{
190 hb_bool_t ret = font->parent->get_glyph_h_origin (glyph, x, y);
191 if (ret)
192 font->parent_scale_position (x, y);
193 return ret;
194}
195
196static hb_bool_t
197hb_font_get_glyph_v_origin_nil (hb_font_t *font HB_UNUSED,
198 void *font_data HB_UNUSED,
199 hb_codepoint_t glyph,
200 hb_position_t *x,
201 hb_position_t *y,
202 void *user_data HB_UNUSED)
203{
204 *x = *y = 0;
205 return false;
206}
207static hb_bool_t
208hb_font_get_glyph_v_origin_parent (hb_font_t *font,
209 void *font_data HB_UNUSED,
210 hb_codepoint_t glyph,
211 hb_position_t *x,
212 hb_position_t *y,
213 void *user_data HB_UNUSED)
214{
215 hb_bool_t ret = font->parent->get_glyph_v_origin (glyph, x, y);
216 if (ret)
217 font->parent_scale_position (x, y);
218 return ret;
219}
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400220
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400221static hb_position_t
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800222hb_font_get_glyph_h_kerning_nil (hb_font_t *font HB_UNUSED,
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400223 void *font_data HB_UNUSED,
224 hb_codepoint_t left_glyph,
225 hb_codepoint_t right_glyph,
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400226 void *user_data HB_UNUSED)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400227{
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400228 return 0;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400229}
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800230static hb_position_t
231hb_font_get_glyph_h_kerning_parent (hb_font_t *font,
232 void *font_data HB_UNUSED,
233 hb_codepoint_t left_glyph,
234 hb_codepoint_t right_glyph,
235 void *user_data HB_UNUSED)
236{
237 return font->parent_scale_x_distance (font->parent->get_glyph_h_kerning (left_glyph, right_glyph));
238}
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400239
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400240static hb_position_t
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800241hb_font_get_glyph_v_kerning_nil (hb_font_t *font HB_UNUSED,
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400242 void *font_data HB_UNUSED,
243 hb_codepoint_t top_glyph,
244 hb_codepoint_t bottom_glyph,
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400245 void *user_data HB_UNUSED)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400246{
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400247 return 0;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400248}
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800249static hb_position_t
250hb_font_get_glyph_v_kerning_parent (hb_font_t *font,
251 void *font_data HB_UNUSED,
252 hb_codepoint_t top_glyph,
253 hb_codepoint_t bottom_glyph,
254 void *user_data HB_UNUSED)
255{
256 return font->parent_scale_y_distance (font->parent->get_glyph_v_kerning (top_glyph, bottom_glyph));
257}
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400258
259static hb_bool_t
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800260hb_font_get_glyph_extents_nil (hb_font_t *font HB_UNUSED,
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400261 void *font_data HB_UNUSED,
262 hb_codepoint_t glyph,
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400263 hb_glyph_extents_t *extents,
264 void *user_data HB_UNUSED)
265{
Behdad Esfahbod60fbb362011-05-19 18:46:15 -0400266 memset (extents, 0, sizeof (*extents));
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400267 return false;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400268}
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800269static hb_bool_t
270hb_font_get_glyph_extents_parent (hb_font_t *font,
271 void *font_data HB_UNUSED,
272 hb_codepoint_t glyph,
273 hb_glyph_extents_t *extents,
274 void *user_data HB_UNUSED)
275{
276 hb_bool_t ret = font->parent->get_glyph_extents (glyph, extents);
277 if (ret) {
278 font->parent_scale_position (&extents->x_bearing, &extents->y_bearing);
279 font->parent_scale_distance (&extents->width, &extents->height);
280 }
281 return ret;
282}
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400283
284static hb_bool_t
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800285hb_font_get_glyph_contour_point_nil (hb_font_t *font HB_UNUSED,
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400286 void *font_data HB_UNUSED,
287 hb_codepoint_t glyph,
288 unsigned int point_index,
289 hb_position_t *x,
290 hb_position_t *y,
291 void *user_data HB_UNUSED)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400292{
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400293 *x = *y = 0;
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400294 return false;
Behdad Esfahbod1ded6d82011-05-10 20:49:02 -0400295}
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800296static hb_bool_t
297hb_font_get_glyph_contour_point_parent (hb_font_t *font,
298 void *font_data HB_UNUSED,
299 hb_codepoint_t glyph,
300 unsigned int point_index,
301 hb_position_t *x,
302 hb_position_t *y,
303 void *user_data HB_UNUSED)
304{
305 hb_bool_t ret = font->parent->get_glyph_contour_point (glyph, point_index, x, y);
306 if (ret)
307 font->parent_scale_position (x, y);
308 return ret;
309}
Behdad Esfahbod79512792009-11-03 20:27:05 -0500310
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400311static hb_bool_t
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800312hb_font_get_glyph_name_nil (hb_font_t *font HB_UNUSED,
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400313 void *font_data HB_UNUSED,
314 hb_codepoint_t glyph,
315 char *name, unsigned int size,
316 void *user_data HB_UNUSED)
317{
Behdad Esfahbod6f3a3002012-08-07 22:13:25 -0400318 if (size) *name = '\0';
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400319 return false;
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400320}
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800321static hb_bool_t
322hb_font_get_glyph_name_parent (hb_font_t *font,
323 void *font_data HB_UNUSED,
324 hb_codepoint_t glyph,
325 char *name, unsigned int size,
326 void *user_data HB_UNUSED)
327{
328 return font->parent->get_glyph_name (glyph, name, size);
329}
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400330
331static hb_bool_t
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800332hb_font_get_glyph_from_name_nil (hb_font_t *font HB_UNUSED,
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400333 void *font_data HB_UNUSED,
334 const char *name, int len, /* -1 means nul-terminated */
335 hb_codepoint_t *glyph,
336 void *user_data HB_UNUSED)
337{
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400338 *glyph = 0;
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400339 return false;
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400340}
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800341static hb_bool_t
342hb_font_get_glyph_from_name_parent (hb_font_t *font,
343 void *font_data HB_UNUSED,
344 const char *name, int len, /* -1 means nul-terminated */
345 hb_codepoint_t *glyph,
346 void *user_data HB_UNUSED)
347{
348 return font->parent->get_glyph_from_name (name, len, glyph);
349}
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400350
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -0400351static const hb_font_funcs_t _hb_font_funcs_nil = {
Behdad Esfahbodfca368c2011-04-21 18:24:02 -0400352 HB_OBJECT_HEADER_STATIC,
353
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400354 true, /* immutable */
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400355
Behdad Esfahbodbf36a102010-05-24 17:46:21 +0100356 {
Behdad Esfahbod28de1042015-11-04 22:00:25 -0800357#define HB_FONT_FUNC_IMPLEMENT(name) NULL,
358 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
359#undef HB_FONT_FUNC_IMPLEMENT
360 },
361 {
362#define HB_FONT_FUNC_IMPLEMENT(name) NULL,
363 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
364#undef HB_FONT_FUNC_IMPLEMENT
365 },
366 {
jfkthamef19c6db2015-11-20 08:43:49 +0000367 {
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400368#define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_nil,
jfkthamef19c6db2015-11-20 08:43:49 +0000369 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400370#undef HB_FONT_FUNC_IMPLEMENT
jfkthamef19c6db2015-11-20 08:43:49 +0000371 }
Behdad Esfahbodbf36a102010-05-24 17:46:21 +0100372 }
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400373};
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800374static const hb_font_funcs_t _hb_font_funcs_parent = {
375 HB_OBJECT_HEADER_STATIC,
376
377 true, /* immutable */
378
379 {
Behdad Esfahbod28de1042015-11-04 22:00:25 -0800380#define HB_FONT_FUNC_IMPLEMENT(name) NULL,
381 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
382#undef HB_FONT_FUNC_IMPLEMENT
383 },
384 {
385#define HB_FONT_FUNC_IMPLEMENT(name) NULL,
386 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
387#undef HB_FONT_FUNC_IMPLEMENT
388 },
389 {
jfkthamef19c6db2015-11-20 08:43:49 +0000390 {
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800391#define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_parent,
jfkthamef19c6db2015-11-20 08:43:49 +0000392 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800393#undef HB_FONT_FUNC_IMPLEMENT
jfkthamef19c6db2015-11-20 08:43:49 +0000394 }
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800395 }
396};
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400397
Behdad Esfahbod56eb5ad2011-05-04 19:27:37 -0400398
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400399/**
Behdad Esfahbod085d4292013-09-12 17:14:33 -0400400 * hb_font_funcs_create: (Xconstructor)
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400401 *
402 *
403 *
404 * Return value: (transfer full):
405 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430406 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400407 **/
Behdad Esfahbod5c441882009-08-10 20:05:16 -0400408hb_font_funcs_t *
409hb_font_funcs_create (void)
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400410{
Behdad Esfahbod5c441882009-08-10 20:05:16 -0400411 hb_font_funcs_t *ffuncs;
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400412
Behdad Esfahbod47e71d92011-04-27 16:38:03 -0400413 if (!(ffuncs = hb_object_create<hb_font_funcs_t> ()))
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -0400414 return hb_font_funcs_get_empty ();
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400415
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800416 ffuncs->get = _hb_font_funcs_parent.get;
Behdad Esfahbodf97bf4f2010-05-24 17:50:19 +0100417
Behdad Esfahbod5c441882009-08-10 20:05:16 -0400418 return ffuncs;
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400419}
420
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400421/**
422 * hb_font_funcs_get_empty:
423 *
424 *
425 *
426 * Return value: (transfer full):
427 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430428 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400429 **/
Behdad Esfahbod5c441882009-08-10 20:05:16 -0400430hb_font_funcs_t *
Behdad Esfahbod80a68332011-05-11 18:14:44 -0400431hb_font_funcs_get_empty (void)
432{
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800433 return const_cast<hb_font_funcs_t *> (&_hb_font_funcs_parent);
Behdad Esfahbod80a68332011-05-11 18:14:44 -0400434}
435
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400436/**
437 * hb_font_funcs_reference: (skip)
438 * @ffuncs: font functions.
439 *
440 *
441 *
442 * Return value:
443 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430444 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400445 **/
Behdad Esfahbod80a68332011-05-11 18:14:44 -0400446hb_font_funcs_t *
Behdad Esfahbod5c441882009-08-10 20:05:16 -0400447hb_font_funcs_reference (hb_font_funcs_t *ffuncs)
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400448{
Behdad Esfahbod47e71d92011-04-27 16:38:03 -0400449 return hb_object_reference (ffuncs);
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400450}
451
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400452/**
453 * hb_font_funcs_destroy: (skip)
454 * @ffuncs: font functions.
455 *
456 *
457 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430458 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400459 **/
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400460void
Behdad Esfahbod5c441882009-08-10 20:05:16 -0400461hb_font_funcs_destroy (hb_font_funcs_t *ffuncs)
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400462{
Behdad Esfahbod47e71d92011-04-27 16:38:03 -0400463 if (!hb_object_destroy (ffuncs)) return;
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400464
Behdad Esfahbod4b6317c2011-07-07 23:14:42 -0400465#define HB_FONT_FUNC_IMPLEMENT(name) if (ffuncs->destroy.name) \
466 ffuncs->destroy.name (ffuncs->user_data.name);
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400467 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
468#undef HB_FONT_FUNC_IMPLEMENT
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400469
Behdad Esfahbod5c441882009-08-10 20:05:16 -0400470 free (ffuncs);
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400471}
472
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400473/**
474 * hb_font_funcs_set_user_data: (skip)
475 * @ffuncs: font functions.
476 * @key:
477 * @data:
478 * @destroy:
479 * @replace:
480 *
481 *
482 *
483 * Return value:
484 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430485 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400486 **/
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -0400487hb_bool_t
488hb_font_funcs_set_user_data (hb_font_funcs_t *ffuncs,
489 hb_user_data_key_t *key,
490 void * data,
Behdad Esfahbod33ccc772011-08-09 00:43:24 +0200491 hb_destroy_func_t destroy,
492 hb_bool_t replace)
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -0400493{
Behdad Esfahbod33ccc772011-08-09 00:43:24 +0200494 return hb_object_set_user_data (ffuncs, key, data, destroy, replace);
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -0400495}
496
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400497/**
498 * hb_font_funcs_get_user_data: (skip)
499 * @ffuncs: font functions.
500 * @key:
501 *
502 *
503 *
504 * Return value: (transfer none):
505 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430506 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400507 **/
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -0400508void *
509hb_font_funcs_get_user_data (hb_font_funcs_t *ffuncs,
510 hb_user_data_key_t *key)
511{
512 return hb_object_get_user_data (ffuncs, key);
513}
514
515
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400516/**
517 * hb_font_funcs_make_immutable:
518 * @ffuncs: font functions.
519 *
520 *
521 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430522 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400523 **/
Behdad Esfahbod8d703122009-08-10 23:50:51 -0400524void
525hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs)
526{
Behdad Esfahbod3f310dc2014-07-22 16:26:27 -0400527 if (unlikely (hb_object_is_inert (ffuncs)))
Behdad Esfahbod8d703122009-08-10 23:50:51 -0400528 return;
529
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400530 ffuncs->immutable = true;
Behdad Esfahbod8d703122009-08-10 23:50:51 -0400531}
532
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400533/**
534 * hb_font_funcs_is_immutable:
535 * @ffuncs: font functions.
536 *
537 *
538 *
539 * Return value:
540 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430541 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400542 **/
Behdad Esfahbod645f6f22010-10-04 17:01:01 -0400543hb_bool_t
544hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs)
545{
Behdad Esfahbod3111b8a2010-10-13 10:41:53 -0400546 return ffuncs->immutable;
Behdad Esfahbod645f6f22010-10-04 17:01:01 -0400547}
548
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400549
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400550#define HB_FONT_FUNC_IMPLEMENT(name) \
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400551 \
552void \
553hb_font_funcs_set_##name##_func (hb_font_funcs_t *ffuncs, \
554 hb_font_get_##name##_func_t func, \
555 void *user_data, \
556 hb_destroy_func_t destroy) \
557{ \
Behdad Esfahbod0cd33592011-09-21 16:49:33 -0400558 if (ffuncs->immutable) { \
559 if (destroy) \
560 destroy (user_data); \
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400561 return; \
Behdad Esfahbod0cd33592011-09-21 16:49:33 -0400562 } \
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400563 \
564 if (ffuncs->destroy.name) \
565 ffuncs->destroy.name (ffuncs->user_data.name); \
566 \
567 if (func) { \
Behdad Esfahbod88e9a9b2015-11-04 21:16:26 -0800568 ffuncs->get.f.name = func; \
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400569 ffuncs->user_data.name = user_data; \
570 ffuncs->destroy.name = destroy; \
571 } else { \
Behdad Esfahbod88e9a9b2015-11-04 21:16:26 -0800572 ffuncs->get.f.name = hb_font_get_##name##_parent; \
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400573 ffuncs->user_data.name = NULL; \
574 ffuncs->destroy.name = NULL; \
575 } \
Behdad Esfahbod79512792009-11-03 20:27:05 -0500576}
577
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400578HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
579#undef HB_FONT_FUNC_IMPLEMENT
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400580
Behdad Esfahbod762770c2015-11-04 21:42:55 -0800581bool
582hb_font_t::has_func (unsigned int i)
583{
584 if (parent && parent != hb_font_get_empty () && parent->has_func (i))
585 return true;
586 return this->klass->get.array[i] != _hb_font_funcs_parent.get.array[i];
587}
Behdad Esfahbod502f4cb2010-10-27 01:13:56 -0400588
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400589/* Public getters */
590
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400591/**
Simon Cozens6f2e6de2015-10-26 16:23:22 +0900592 * hb_font_get_h_extents:
593 * @font: a font.
594 * @extents: (out):
595 *
596 *
597 *
598 * Return value:
599 *
Behdad Esfahbodf11c11a2015-12-16 17:08:36 +0100600 * Since: 1.1.3
Simon Cozens6f2e6de2015-10-26 16:23:22 +0900601 **/
602hb_bool_t
603hb_font_get_h_extents (hb_font_t *font,
604 hb_font_extents_t *extents)
605{
606 return font->get_font_h_extents (extents);
607}
608
609/**
610 * hb_font_get_v_extents:
611 * @font: a font.
612 * @extents: (out):
613 *
614 *
615 *
616 * Return value:
617 *
Behdad Esfahbodf11c11a2015-12-16 17:08:36 +0100618 * Since: 1.1.3
Simon Cozens6f2e6de2015-10-26 16:23:22 +0900619 **/
620hb_bool_t
621hb_font_get_v_extents (hb_font_t *font,
622 hb_font_extents_t *extents)
623{
624 return font->get_font_v_extents (extents);
625}
626
627/**
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400628 * hb_font_get_glyph:
629 * @font: a font.
630 * @unicode:
631 * @variation_selector:
632 * @glyph: (out):
633 *
634 *
635 *
636 * Return value:
637 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430638 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400639 **/
Behdad Esfahbod0fd8c2f2011-05-12 15:14:13 -0400640hb_bool_t
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400641hb_font_get_glyph (hb_font_t *font,
Behdad Esfahbod0fd8c2f2011-05-12 15:14:13 -0400642 hb_codepoint_t unicode, hb_codepoint_t variation_selector,
643 hb_codepoint_t *glyph)
Behdad Esfahbod2e336692009-11-05 13:55:41 -0500644{
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +0900645 if (unlikely (variation_selector))
646 return font->get_variation_glyph (unicode, variation_selector, glyph);
647 return font->get_nominal_glyph (unicode, glyph);
648}
649
650/**
651 * hb_font_get_nominal_glyph:
652 * @font: a font.
653 * @unicode:
654 * @glyph: (out):
655 *
656 *
657 *
658 * Return value:
659 *
660 * Since: 1.2.3
661 **/
662hb_bool_t
663hb_font_get_nominal_glyph (hb_font_t *font,
664 hb_codepoint_t unicode,
665 hb_codepoint_t *glyph)
666{
667 return font->get_nominal_glyph (unicode, glyph);
668}
669
670/**
671 * hb_font_get_variation_glyph:
672 * @font: a font.
673 * @unicode:
674 * @variation_selector:
675 * @glyph: (out):
676 *
677 *
678 *
679 * Return value:
680 *
681 * Since: 1.2.3
682 **/
683hb_bool_t
684hb_font_get_variation_glyph (hb_font_t *font,
685 hb_codepoint_t unicode, hb_codepoint_t variation_selector,
686 hb_codepoint_t *glyph)
687{
688 return font->get_variation_glyph (unicode, variation_selector, glyph);
Behdad Esfahbod2e336692009-11-05 13:55:41 -0500689}
690
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400691/**
692 * hb_font_get_glyph_h_advance:
693 * @font: a font.
694 * @glyph:
695 *
696 *
697 *
698 * Return value:
699 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430700 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400701 **/
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400702hb_position_t
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400703hb_font_get_glyph_h_advance (hb_font_t *font,
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400704 hb_codepoint_t glyph)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400705{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400706 return font->get_glyph_h_advance (glyph);
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400707}
708
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400709/**
710 * hb_font_get_glyph_v_advance:
711 * @font: a font.
712 * @glyph:
713 *
714 *
715 *
716 * Return value:
717 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430718 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400719 **/
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400720hb_position_t
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400721hb_font_get_glyph_v_advance (hb_font_t *font,
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400722 hb_codepoint_t glyph)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400723{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400724 return font->get_glyph_v_advance (glyph);
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400725}
726
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400727/**
728 * hb_font_get_glyph_h_origin:
729 * @font: a font.
730 * @glyph:
731 * @x: (out):
732 * @y: (out):
733 *
734 *
735 *
736 * Return value:
737 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430738 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400739 **/
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400740hb_bool_t
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400741hb_font_get_glyph_h_origin (hb_font_t *font,
742 hb_codepoint_t glyph,
Behdad Esfahbod19098182011-05-17 23:27:22 -0400743 hb_position_t *x, hb_position_t *y)
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400744{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400745 return font->get_glyph_h_origin (glyph, x, y);
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400746}
747
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400748/**
749 * hb_font_get_glyph_v_origin:
750 * @font: a font.
751 * @glyph:
752 * @x: (out):
753 * @y: (out):
754 *
755 *
756 *
757 * Return value:
758 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430759 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400760 **/
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400761hb_bool_t
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400762hb_font_get_glyph_v_origin (hb_font_t *font,
763 hb_codepoint_t glyph,
Behdad Esfahbod19098182011-05-17 23:27:22 -0400764 hb_position_t *x, hb_position_t *y)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400765{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400766 return font->get_glyph_v_origin (glyph, x, y);
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400767}
768
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400769/**
770 * hb_font_get_glyph_h_kerning:
771 * @font: a font.
772 * @left_glyph:
773 * @right_glyph:
774 *
775 *
776 *
777 * Return value:
778 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430779 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400780 **/
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400781hb_position_t
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400782hb_font_get_glyph_h_kerning (hb_font_t *font,
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400783 hb_codepoint_t left_glyph, hb_codepoint_t right_glyph)
Behdad Esfahbod2e336692009-11-05 13:55:41 -0500784{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400785 return font->get_glyph_h_kerning (left_glyph, right_glyph);
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400786}
787
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400788/**
789 * hb_font_get_glyph_v_kerning:
790 * @font: a font.
791 * @top_glyph:
792 * @bottom_glyph:
793 *
794 *
795 *
796 * Return value:
797 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430798 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400799 **/
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400800hb_position_t
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400801hb_font_get_glyph_v_kerning (hb_font_t *font,
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400802 hb_codepoint_t top_glyph, hb_codepoint_t bottom_glyph)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400803{
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400804 return font->get_glyph_v_kerning (top_glyph, bottom_glyph);
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400805}
806
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400807/**
808 * hb_font_get_glyph_extents:
809 * @font: a font.
810 * @glyph:
811 * @extents: (out):
812 *
813 *
814 *
815 * Return value:
816 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430817 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400818 **/
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400819hb_bool_t
820hb_font_get_glyph_extents (hb_font_t *font,
821 hb_codepoint_t glyph,
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400822 hb_glyph_extents_t *extents)
823{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400824 return font->get_glyph_extents (glyph, extents);
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400825}
826
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400827/**
828 * hb_font_get_glyph_contour_point:
829 * @font: a font.
830 * @glyph:
831 * @point_index:
832 * @x: (out):
833 * @y: (out):
834 *
835 *
836 *
837 * Return value:
838 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430839 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400840 **/
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400841hb_bool_t
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400842hb_font_get_glyph_contour_point (hb_font_t *font,
843 hb_codepoint_t glyph, unsigned int point_index,
844 hb_position_t *x, hb_position_t *y)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400845{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400846 return font->get_glyph_contour_point (glyph, point_index, x, y);
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400847}
848
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400849/**
850 * hb_font_get_glyph_name:
851 * @font: a font.
852 * @glyph:
853 * @name: (array length=size):
854 * @size:
855 *
856 *
857 *
858 * Return value:
859 *
Sascha Brawer01c3a882015-06-01 13:22:01 +0200860 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400861 **/
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400862hb_bool_t
863hb_font_get_glyph_name (hb_font_t *font,
864 hb_codepoint_t glyph,
865 char *name, unsigned int size)
866{
Behdad Esfahbod6f3a3002012-08-07 22:13:25 -0400867 return font->get_glyph_name (glyph, name, size);
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400868}
869
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400870/**
871 * hb_font_get_glyph_from_name:
872 * @font: a font.
873 * @name: (array length=len):
874 * @len:
875 * @glyph: (out):
876 *
877 *
878 *
879 * Return value:
880 *
Sascha Brawer01c3a882015-06-01 13:22:01 +0200881 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400882 **/
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400883hb_bool_t
884hb_font_get_glyph_from_name (hb_font_t *font,
885 const char *name, int len, /* -1 means nul-terminated */
886 hb_codepoint_t *glyph)
887{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400888 return font->get_glyph_from_name (name, len, glyph);
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400889}
890
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400891
892/* A bit higher-level, and with fallback */
893
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400894/**
Simon Cozens6f2e6de2015-10-26 16:23:22 +0900895 * hb_font_get_extents_for_direction:
896 * @font: a font.
897 * @direction:
898 * @extents:
899 *
900 *
901 *
Behdad Esfahbodf11c11a2015-12-16 17:08:36 +0100902 * Since: 1.1.3
Simon Cozens6f2e6de2015-10-26 16:23:22 +0900903 **/
904void
905hb_font_get_extents_for_direction (hb_font_t *font,
906 hb_direction_t direction,
907 hb_font_extents_t *extents)
908{
909 return font->get_extents_for_direction (direction, extents);
910}
911/**
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400912 * hb_font_get_glyph_advance_for_direction:
913 * @font: a font.
914 * @glyph:
915 * @direction:
916 * @x: (out):
917 * @y: (out):
918 *
919 *
920 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430921 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400922 **/
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400923void
924hb_font_get_glyph_advance_for_direction (hb_font_t *font,
925 hb_codepoint_t glyph,
926 hb_direction_t direction,
Behdad Esfahbod19098182011-05-17 23:27:22 -0400927 hb_position_t *x, hb_position_t *y)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400928{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400929 return font->get_glyph_advance_for_direction (glyph, direction, x, y);
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400930}
931
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400932/**
933 * hb_font_get_glyph_origin_for_direction:
934 * @font: a font.
935 * @glyph:
936 * @direction:
937 * @x: (out):
938 * @y: (out):
939 *
940 *
941 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430942 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400943 **/
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400944void
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400945hb_font_get_glyph_origin_for_direction (hb_font_t *font,
946 hb_codepoint_t glyph,
947 hb_direction_t direction,
Behdad Esfahbod19098182011-05-17 23:27:22 -0400948 hb_position_t *x, hb_position_t *y)
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400949{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400950 return font->get_glyph_origin_for_direction (glyph, direction, x, y);
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400951}
952
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400953/**
954 * hb_font_add_glyph_origin_for_direction:
955 * @font: a font.
956 * @glyph:
957 * @direction:
958 * @x: (out):
959 * @y: (out):
960 *
961 *
962 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430963 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400964 **/
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400965void
Behdad Esfahbod8b38fae2011-05-19 13:08:00 -0400966hb_font_add_glyph_origin_for_direction (hb_font_t *font,
967 hb_codepoint_t glyph,
968 hb_direction_t direction,
969 hb_position_t *x, hb_position_t *y)
970{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400971 return font->add_glyph_origin_for_direction (glyph, direction, x, y);
Behdad Esfahbod8b38fae2011-05-19 13:08:00 -0400972}
973
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400974/**
975 * hb_font_subtract_glyph_origin_for_direction:
976 * @font: a font.
977 * @glyph:
978 * @direction:
979 * @x: (out):
980 * @y: (out):
981 *
982 *
983 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430984 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400985 **/
Behdad Esfahbod8b38fae2011-05-19 13:08:00 -0400986void
987hb_font_subtract_glyph_origin_for_direction (hb_font_t *font,
988 hb_codepoint_t glyph,
989 hb_direction_t direction,
990 hb_position_t *x, hb_position_t *y)
991{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400992 return font->subtract_glyph_origin_for_direction (glyph, direction, x, y);
Behdad Esfahbod8b38fae2011-05-19 13:08:00 -0400993}
994
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400995/**
996 * hb_font_get_glyph_kerning_for_direction:
997 * @font: a font.
998 * @first_glyph:
999 * @second_glyph:
1000 * @direction:
1001 * @x: (out):
1002 * @y: (out):
1003 *
1004 *
1005 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301006 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001007 **/
Behdad Esfahbod8b38fae2011-05-19 13:08:00 -04001008void
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -04001009hb_font_get_glyph_kerning_for_direction (hb_font_t *font,
1010 hb_codepoint_t first_glyph, hb_codepoint_t second_glyph,
1011 hb_direction_t direction,
Behdad Esfahbod19098182011-05-17 23:27:22 -04001012 hb_position_t *x, hb_position_t *y)
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001013{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -04001014 return font->get_glyph_kerning_for_direction (first_glyph, second_glyph, direction, x, y);
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001015}
1016
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001017/**
1018 * hb_font_get_glyph_extents_for_origin:
1019 * @font: a font.
1020 * @glyph:
1021 * @direction:
1022 * @extents: (out):
1023 *
1024 *
1025 *
1026 * Return value:
1027 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301028 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001029 **/
Behdad Esfahbod60fbb362011-05-19 18:46:15 -04001030hb_bool_t
1031hb_font_get_glyph_extents_for_origin (hb_font_t *font,
1032 hb_codepoint_t glyph,
1033 hb_direction_t direction,
1034 hb_glyph_extents_t *extents)
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001035{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -04001036 return font->get_glyph_extents_for_origin (glyph, direction, extents);
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001037}
1038
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001039/**
1040 * hb_font_get_glyph_contour_point_for_origin:
1041 * @font: a font.
1042 * @glyph:
1043 * @point_index:
1044 * @direction:
1045 * @x: (out):
1046 * @y: (out):
1047 *
1048 *
1049 *
1050 * Return value:
1051 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301052 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001053 **/
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001054hb_bool_t
Behdad Esfahbod60fbb362011-05-19 18:46:15 -04001055hb_font_get_glyph_contour_point_for_origin (hb_font_t *font,
1056 hb_codepoint_t glyph, unsigned int point_index,
1057 hb_direction_t direction,
1058 hb_position_t *x, hb_position_t *y)
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001059{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -04001060 return font->get_glyph_contour_point_for_origin (glyph, point_index, direction, x, y);
Behdad Esfahbod2e336692009-11-05 13:55:41 -05001061}
1062
Behdad Esfahbod6f3a3002012-08-07 22:13:25 -04001063/* Generates gidDDD if glyph has no name. */
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001064/**
1065 * hb_font_glyph_to_string:
1066 * @font: a font.
1067 * @glyph:
1068 * @s: (array length=size):
1069 * @size:
1070 *
1071 *
1072 *
Sascha Brawer01c3a882015-06-01 13:22:01 +02001073 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001074 **/
Behdad Esfahbod6f3a3002012-08-07 22:13:25 -04001075void
1076hb_font_glyph_to_string (hb_font_t *font,
1077 hb_codepoint_t glyph,
1078 char *s, unsigned int size)
1079{
1080 font->glyph_to_string (glyph, s, size);
1081}
1082
1083/* Parses gidDDD and uniUUUU strings automatically. */
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001084/**
1085 * hb_font_glyph_from_string:
1086 * @font: a font.
Khaled Hosnya394bb62015-03-22 20:29:10 +02001087 * @s: (array length=len) (element-type uint8_t):
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001088 * @len:
1089 * @glyph: (out):
1090 *
1091 *
1092 *
1093 * Return value:
1094 *
Sascha Brawer01c3a882015-06-01 13:22:01 +02001095 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001096 **/
Behdad Esfahbod6f3a3002012-08-07 22:13:25 -04001097hb_bool_t
1098hb_font_glyph_from_string (hb_font_t *font,
1099 const char *s, int len, /* -1 means nul-terminated */
1100 hb_codepoint_t *glyph)
1101{
1102 return font->glyph_from_string (s, len, glyph);
1103}
1104
Behdad Esfahbod1cebfbb2010-04-23 20:49:18 -04001105
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001106/*
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001107 * hb_font_t
1108 */
1109
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001110/**
Behdad Esfahbod085d4292013-09-12 17:14:33 -04001111 * hb_font_create: (Xconstructor)
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001112 * @face: a face.
1113 *
1114 *
1115 *
1116 * Return value: (transfer full):
1117 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301118 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001119 **/
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001120hb_font_t *
Behdad Esfahbod72657e42011-05-02 20:46:32 -04001121hb_font_create (hb_face_t *face)
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001122{
1123 hb_font_t *font;
1124
Behdad Esfahbod72657e42011-05-02 20:46:32 -04001125 if (unlikely (!face))
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -04001126 face = hb_face_get_empty ();
Behdad Esfahbod47e71d92011-04-27 16:38:03 -04001127 if (!(font = hb_object_create<hb_font_t> ()))
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -04001128 return hb_font_get_empty ();
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001129
Behdad Esfahbod7fc5a302011-05-12 17:48:20 -04001130 hb_face_make_immutable (face);
Behdad Esfahbodda29b432015-11-04 20:22:44 -08001131 font->parent = hb_font_get_empty ();
Behdad Esfahbod72657e42011-05-02 20:46:32 -04001132 font->face = hb_face_reference (face);
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -04001133 font->klass = hb_font_funcs_get_empty ();
Behdad Esfahbod85555a92009-11-05 18:25:56 -05001134
Behdad Esfahbod88da7bb2015-10-02 14:38:20 +01001135 font->x_scale = font->y_scale = hb_face_get_upem (face);
1136
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001137 return font;
1138}
1139
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001140/**
1141 * hb_font_create_sub_font:
1142 * @parent: parent font.
1143 *
1144 *
1145 *
1146 * Return value: (transfer full):
1147 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301148 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001149 **/
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001150hb_font_t *
Behdad Esfahboddefc45b2011-05-10 20:02:49 -04001151hb_font_create_sub_font (hb_font_t *parent)
1152{
1153 if (unlikely (!parent))
Behdad Esfahbodeb0bf3a2014-08-06 15:36:41 -04001154 parent = hb_font_get_empty ();
Behdad Esfahboddefc45b2011-05-10 20:02:49 -04001155
1156 hb_font_t *font = hb_font_create (parent->face);
1157
1158 if (unlikely (hb_object_is_inert (font)))
1159 return font;
1160
Behdad Esfahboddefc45b2011-05-10 20:02:49 -04001161 font->parent = hb_font_reference (parent);
1162
1163 font->x_scale = parent->x_scale;
1164 font->y_scale = parent->y_scale;
1165 font->x_ppem = parent->x_ppem;
1166 font->y_ppem = parent->y_ppem;
1167
Behdad Esfahboddefc45b2011-05-10 20:02:49 -04001168 return font;
1169}
1170
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001171/**
1172 * hb_font_get_empty:
1173 *
1174 *
1175 *
1176 * Return value: (transfer full)
1177 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301178 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001179 **/
Behdad Esfahboddefc45b2011-05-10 20:02:49 -04001180hb_font_t *
Behdad Esfahbod80a68332011-05-11 18:14:44 -04001181hb_font_get_empty (void)
1182{
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -04001183 static const hb_font_t _hb_font_nil = {
1184 HB_OBJECT_HEADER_STATIC,
1185
Behdad Esfahbod0594a242012-06-05 20:35:40 -04001186 true, /* immutable */
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -04001187
1188 NULL, /* parent */
1189 const_cast<hb_face_t *> (&_hb_face_nil),
1190
Behdad Esfahbodda29b432015-11-04 20:22:44 -08001191 1000, /* x_scale */
1192 1000, /* y_scale */
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -04001193
1194 0, /* x_ppem */
1195 0, /* y_ppem */
1196
Behdad Esfahbod6d9d3c52016-03-01 19:12:08 +09001197 NULL, /* coords */
1198 0, /* coord_count */
1199
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -04001200 const_cast<hb_font_funcs_t *> (&_hb_font_funcs_nil), /* klass */
1201 NULL, /* user_data */
Behdad Esfahbodea278d32012-07-27 02:12:28 -04001202 NULL, /* destroy */
1203
1204 {
1205#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID,
1206#include "hb-shaper-list.hh"
1207#undef HB_SHAPER_IMPLEMENT
1208 }
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -04001209 };
1210
1211 return const_cast<hb_font_t *> (&_hb_font_nil);
Behdad Esfahbod80a68332011-05-11 18:14:44 -04001212}
1213
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001214/**
1215 * hb_font_reference: (skip)
1216 * @font: a font.
1217 *
1218 *
1219 *
1220 * Return value: (transfer full):
1221 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301222 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001223 **/
Behdad Esfahbod80a68332011-05-11 18:14:44 -04001224hb_font_t *
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001225hb_font_reference (hb_font_t *font)
1226{
Behdad Esfahbod47e71d92011-04-27 16:38:03 -04001227 return hb_object_reference (font);
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001228}
1229
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001230/**
1231 * hb_font_destroy: (skip)
1232 * @font: a font.
1233 *
1234 *
1235 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301236 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001237 **/
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001238void
1239hb_font_destroy (hb_font_t *font)
1240{
Behdad Esfahbod47e71d92011-04-27 16:38:03 -04001241 if (!hb_object_destroy (font)) return;
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001242
Behdad Esfahbod027857d2012-07-26 17:34:25 -04001243#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_DESTROY(shaper, font);
1244#include "hb-shaper-list.hh"
1245#undef HB_SHAPER_IMPLEMENT
1246
1247 if (font->destroy)
1248 font->destroy (font->user_data);
1249
Behdad Esfahboddefc45b2011-05-10 20:02:49 -04001250 hb_font_destroy (font->parent);
Behdad Esfahbod72657e42011-05-02 20:46:32 -04001251 hb_face_destroy (font->face);
Behdad Esfahbod5c441882009-08-10 20:05:16 -04001252 hb_font_funcs_destroy (font->klass);
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001253
1254 free (font);
1255}
1256
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001257/**
1258 * hb_font_set_user_data: (skip)
1259 * @font: a font.
1260 * @key:
1261 * @data:
1262 * @destroy:
1263 * @replace:
1264 *
1265 *
1266 *
1267 * Return value:
1268 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301269 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001270 **/
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -04001271hb_bool_t
1272hb_font_set_user_data (hb_font_t *font,
1273 hb_user_data_key_t *key,
1274 void * data,
Behdad Esfahbod33ccc772011-08-09 00:43:24 +02001275 hb_destroy_func_t destroy,
1276 hb_bool_t replace)
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -04001277{
Behdad Esfahbod33ccc772011-08-09 00:43:24 +02001278 return hb_object_set_user_data (font, key, data, destroy, replace);
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -04001279}
1280
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001281/**
1282 * hb_font_get_user_data: (skip)
1283 * @font: a font.
1284 * @key:
1285 *
1286 *
1287 *
1288 * Return value: (transfer none):
1289 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301290 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001291 **/
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -04001292void *
1293hb_font_get_user_data (hb_font_t *font,
1294 hb_user_data_key_t *key)
1295{
1296 return hb_object_get_user_data (font, key);
1297}
1298
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001299/**
1300 * hb_font_make_immutable:
1301 * @font: a font.
1302 *
1303 *
1304 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301305 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001306 **/
Behdad Esfahbod74f1d892011-05-10 19:39:32 -04001307void
1308hb_font_make_immutable (hb_font_t *font)
1309{
Behdad Esfahbod3f310dc2014-07-22 16:26:27 -04001310 if (unlikely (hb_object_is_inert (font)))
Behdad Esfahbod74f1d892011-05-10 19:39:32 -04001311 return;
1312
Behdad Esfahbod1866e172015-10-02 14:21:29 +01001313 if (font->parent)
1314 hb_font_make_immutable (font->parent);
1315
Behdad Esfahbod74f1d892011-05-10 19:39:32 -04001316 font->immutable = true;
1317}
1318
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001319/**
1320 * hb_font_is_immutable:
1321 * @font: a font.
1322 *
1323 *
1324 *
1325 * Return value:
1326 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301327 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001328 **/
Behdad Esfahbod74f1d892011-05-10 19:39:32 -04001329hb_bool_t
1330hb_font_is_immutable (hb_font_t *font)
1331{
1332 return font->immutable;
1333}
1334
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001335/**
Behdad Esfahbod3e905e32015-10-08 12:51:02 -04001336 * hb_font_set_parent:
1337 * @font: a font.
1338 * @parent: new parent.
1339 *
1340 * Sets parent font of @font.
1341 *
1342 * Since: 1.0.5
1343 **/
1344void
1345hb_font_set_parent (hb_font_t *font,
1346 hb_font_t *parent)
1347{
1348 if (font->immutable)
1349 return;
1350
1351 if (!parent)
1352 parent = hb_font_get_empty ();
1353
1354 hb_font_t *old = font->parent;
1355
1356 font->parent = hb_font_reference (parent);
1357
1358 hb_font_destroy (old);
1359}
1360
1361/**
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001362 * hb_font_get_parent:
1363 * @font: a font.
1364 *
1365 *
1366 *
1367 * Return value: (transfer none):
1368 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301369 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001370 **/
Behdad Esfahboddefc45b2011-05-10 20:02:49 -04001371hb_font_t *
1372hb_font_get_parent (hb_font_t *font)
1373{
1374 return font->parent;
1375}
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -04001376
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001377/**
1378 * hb_font_get_face:
1379 * @font: a font.
1380 *
1381 *
1382 *
1383 * Return value: (transfer none):
1384 *
Sascha Brawer01c3a882015-06-01 13:22:01 +02001385 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001386 **/
Behdad Esfahbod72657e42011-05-02 20:46:32 -04001387hb_face_t *
1388hb_font_get_face (hb_font_t *font)
1389{
1390 return font->face;
1391}
1392
1393
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001394/**
1395 * hb_font_set_funcs:
1396 * @font: a font.
Behdad Esfahboda8949df2013-09-13 20:23:51 -04001397 * @klass: (closure font_data) (destroy destroy) (scope notified):
Behdad Esfahbod70303cf2013-09-06 17:35:57 -04001398 * @font_data:
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001399 * @destroy:
1400 *
1401 *
1402 *
Sascha Brawer01c3a882015-06-01 13:22:01 +02001403 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001404 **/
Behdad Esfahbod5c441882009-08-10 20:05:16 -04001405void
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -05001406hb_font_set_funcs (hb_font_t *font,
1407 hb_font_funcs_t *klass,
Behdad Esfahbod70303cf2013-09-06 17:35:57 -04001408 void *font_data,
Behdad Esfahbod56681892011-04-20 03:03:32 -04001409 hb_destroy_func_t destroy)
Behdad Esfahbod0ead4812009-08-02 17:41:36 -04001410{
Behdad Esfahbod0cd33592011-09-21 16:49:33 -04001411 if (font->immutable) {
1412 if (destroy)
Behdad Esfahbod70303cf2013-09-06 17:35:57 -04001413 destroy (font_data);
Behdad Esfahbod5c441882009-08-10 20:05:16 -04001414 return;
Behdad Esfahbod0cd33592011-09-21 16:49:33 -04001415 }
Behdad Esfahbod0ead4812009-08-02 17:41:36 -04001416
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -05001417 if (font->destroy)
1418 font->destroy (font->user_data);
1419
Behdad Esfahbod0465e692009-12-20 16:25:18 +01001420 if (!klass)
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -04001421 klass = hb_font_funcs_get_empty ();
Behdad Esfahbod0465e692009-12-20 16:25:18 +01001422
Behdad Esfahbod5c441882009-08-10 20:05:16 -04001423 hb_font_funcs_reference (klass);
1424 hb_font_funcs_destroy (font->klass);
1425 font->klass = klass;
Behdad Esfahbod70303cf2013-09-06 17:35:57 -04001426 font->user_data = font_data;
Behdad Esfahbod56681892011-04-20 03:03:32 -04001427 font->destroy = destroy;
Behdad Esfahbod0ead4812009-08-02 17:41:36 -04001428}
1429
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001430/**
1431 * hb_font_set_funcs_data:
1432 * @font: a font.
Behdad Esfahboda8949df2013-09-13 20:23:51 -04001433 * @font_data: (destroy destroy) (scope notified):
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 Esfahbodb9415e72011-08-17 19:21:44 +02001440void
1441hb_font_set_funcs_data (hb_font_t *font,
Behdad Esfahbod70303cf2013-09-06 17:35:57 -04001442 void *font_data,
Behdad Esfahbodb9415e72011-08-17 19:21:44 +02001443 hb_destroy_func_t destroy)
1444{
Behdad Esfahbod0cd33592011-09-21 16:49:33 -04001445 /* Destroy user_data? */
1446 if (font->immutable) {
1447 if (destroy)
Behdad Esfahbod70303cf2013-09-06 17:35:57 -04001448 destroy (font_data);
Behdad Esfahbodb9415e72011-08-17 19:21:44 +02001449 return;
Behdad Esfahbod0cd33592011-09-21 16:49:33 -04001450 }
Behdad Esfahbodb9415e72011-08-17 19:21:44 +02001451
1452 if (font->destroy)
1453 font->destroy (font->user_data);
1454
Behdad Esfahbod70303cf2013-09-06 17:35:57 -04001455 font->user_data = font_data;
Behdad Esfahbodb9415e72011-08-17 19:21:44 +02001456 font->destroy = destroy;
1457}
1458
Behdad Esfahbod19c0eab2010-10-04 16:45:21 -04001459
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001460/**
1461 * hb_font_set_scale:
1462 * @font: a font.
1463 * @x_scale:
1464 * @y_scale:
1465 *
1466 *
1467 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301468 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001469 **/
Behdad Esfahbod19c0eab2010-10-04 16:45:21 -04001470void
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001471hb_font_set_scale (hb_font_t *font,
Behdad Esfahbodda975412011-04-21 15:08:01 -04001472 int x_scale,
1473 int y_scale)
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001474{
Behdad Esfahbod74f1d892011-05-10 19:39:32 -04001475 if (font->immutable)
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001476 return;
1477
1478 font->x_scale = x_scale;
1479 font->y_scale = y_scale;
1480}
1481
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001482/**
1483 * hb_font_get_scale:
1484 * @font: a font.
1485 * @x_scale: (out):
1486 * @y_scale: (out):
1487 *
1488 *
1489 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301490 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001491 **/
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001492void
Behdad Esfahbod19c0eab2010-10-04 16:45:21 -04001493hb_font_get_scale (hb_font_t *font,
Behdad Esfahbodda975412011-04-21 15:08:01 -04001494 int *x_scale,
1495 int *y_scale)
Behdad Esfahbod19c0eab2010-10-04 16:45:21 -04001496{
1497 if (x_scale) *x_scale = font->x_scale;
1498 if (y_scale) *y_scale = font->y_scale;
1499}
1500
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001501/**
1502 * hb_font_set_ppem:
1503 * @font: a font.
1504 * @x_ppem:
1505 * @y_ppem:
1506 *
1507 *
1508 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301509 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001510 **/
Behdad Esfahbod19c0eab2010-10-04 16:45:21 -04001511void
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001512hb_font_set_ppem (hb_font_t *font,
1513 unsigned int x_ppem,
1514 unsigned int y_ppem)
1515{
Behdad Esfahbod74f1d892011-05-10 19:39:32 -04001516 if (font->immutable)
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001517 return;
1518
1519 font->x_ppem = x_ppem;
1520 font->y_ppem = y_ppem;
1521}
1522
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001523/**
1524 * hb_font_get_ppem:
1525 * @font: a font.
1526 * @x_ppem: (out):
1527 * @y_ppem: (out):
1528 *
1529 *
1530 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301531 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001532 **/
Behdad Esfahbod19c0eab2010-10-04 16:45:21 -04001533void
1534hb_font_get_ppem (hb_font_t *font,
1535 unsigned int *x_ppem,
1536 unsigned int *y_ppem)
1537{
1538 if (x_ppem) *x_ppem = font->x_ppem;
1539 if (y_ppem) *y_ppem = font->y_ppem;
1540}
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09001541
1542
Konstantin Ritt71248a82016-02-25 18:55:28 +04001543#ifndef HB_DISABLE_DEPRECATED
1544
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09001545/*
1546 * Deprecated get_glyph_func():
1547 */
1548
1549struct hb_trampoline_closure_t
1550{
1551 void *user_data;
1552 hb_destroy_func_t destroy;
Behdad Esfahbodc335fd72016-02-25 09:16:05 +09001553 unsigned int ref_count;
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09001554};
1555
1556template <typename FuncType>
1557struct hb_trampoline_t
1558{
1559 hb_trampoline_closure_t closure; /* Must be first. */
1560 FuncType func;
1561};
1562
1563template <typename FuncType>
1564static hb_trampoline_t<FuncType> *
1565trampoline_create (FuncType func,
1566 void *user_data,
1567 hb_destroy_func_t destroy)
1568{
1569 typedef hb_trampoline_t<FuncType> trampoline_t;
1570
1571 trampoline_t *trampoline = (trampoline_t *) calloc (1, sizeof (trampoline_t));
1572
1573 if (unlikely (!trampoline))
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09001574 return NULL;
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09001575
1576 trampoline->closure.user_data = user_data;
1577 trampoline->closure.destroy = destroy;
Behdad Esfahbodc335fd72016-02-25 09:16:05 +09001578 trampoline->closure.ref_count = 1;
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09001579 trampoline->func = func;
1580
1581 return trampoline;
1582}
1583
1584static void
Behdad Esfahbodc335fd72016-02-25 09:16:05 +09001585trampoline_reference (hb_trampoline_closure_t *closure)
1586{
1587 closure->ref_count++;
1588}
1589
1590static void
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09001591trampoline_destroy (void *user_data)
1592{
1593 hb_trampoline_closure_t *closure = (hb_trampoline_closure_t *) user_data;
Behdad Esfahbodc335fd72016-02-25 09:16:05 +09001594
1595 if (--closure->ref_count)
1596 return;
1597
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09001598 if (closure->destroy)
1599 closure->destroy (closure->user_data);
1600 free (closure);
1601}
1602
1603typedef hb_trampoline_t<hb_font_get_glyph_func_t> hb_font_get_glyph_trampoline_t;
1604
1605static hb_bool_t
1606hb_font_get_nominal_glyph_trampoline (hb_font_t *font,
1607 void *font_data,
1608 hb_codepoint_t unicode,
1609 hb_codepoint_t *glyph,
1610 void *user_data)
1611{
1612 hb_font_get_glyph_trampoline_t *trampoline = (hb_font_get_glyph_trampoline_t *) user_data;
1613 return trampoline->func (font, font_data, unicode, 0, glyph, trampoline->closure.user_data);
1614}
1615
1616static hb_bool_t
1617hb_font_get_variation_glyph_trampoline (hb_font_t *font,
1618 void *font_data,
1619 hb_codepoint_t unicode,
1620 hb_codepoint_t variation_selector,
1621 hb_codepoint_t *glyph,
1622 void *user_data)
1623{
1624 hb_font_get_glyph_trampoline_t *trampoline = (hb_font_get_glyph_trampoline_t *) user_data;
1625 return trampoline->func (font, font_data, unicode, variation_selector, glyph, trampoline->closure.user_data);
1626}
1627
1628/**
1629 * hb_font_funcs_set_glyph_func:
1630 * @ffuncs: font functions.
1631 * @func: (closure user_data) (destroy destroy) (scope notified):
1632 * @user_data:
1633 * @destroy:
1634 *
1635 * Deprecated. Use hb_font_funcs_set_nominal_glyph_func() and
1636 * hb_font_funcs_set_variation_glyph_func() instead.
1637 *
1638 * Since: 0.9.2
1639 * Deprecated: 1.2.3
1640 **/
1641void
1642hb_font_funcs_set_glyph_func (hb_font_funcs_t *ffuncs,
1643 hb_font_get_glyph_func_t func,
1644 void *user_data, hb_destroy_func_t destroy)
1645{
1646 hb_font_get_glyph_trampoline_t *trampoline;
1647
1648 trampoline = trampoline_create (func, user_data, destroy);
Behdad Esfahbodc335fd72016-02-25 09:16:05 +09001649 if (unlikely (!trampoline))
1650 {
1651 if (destroy)
1652 destroy (user_data);
1653 return;
1654 }
1655
1656 hb_font_funcs_set_nominal_glyph_func (ffuncs,
1657 hb_font_get_nominal_glyph_trampoline,
1658 trampoline,
1659 trampoline_destroy);
1660
1661 trampoline_reference (&trampoline->closure);
1662 hb_font_funcs_set_variation_glyph_func (ffuncs,
1663 hb_font_get_variation_glyph_trampoline,
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09001664 trampoline,
1665 trampoline_destroy);
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09001666}
Konstantin Ritt71248a82016-02-25 18:55:28 +04001667
1668#endif /* HB_DISABLE_DEPRECATED */