blob: fa8da9639516fb437658d9dc862603a7bf110e6c [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 Esfahbodc77ae402018-08-25 22:36:36 -070029#include "hb.hh"
Behdad Esfahbodc62b5032009-08-01 19:54:49 -040030
Behdad Esfahbodc77ae402018-08-25 22:36:36 -070031#include "hb-font.hh"
32#include "hb-machinery.hh"
Behdad Esfahbod79512792009-11-03 20:27:05 -050033
Behdad Esfahbod07899432018-10-09 15:39:51 -040034#include "hb-ot.h"
35
Ebrahim Byagowiab2d3ec2019-08-14 18:42:51 +043036#include "hb-ot-var-avar-table.hh"
37#include "hb-ot-var-fvar-table.hh"
38
Behdad Esfahbodacdba3f2010-07-23 15:11:18 -040039
Behdad Esfahbod00cf4e52018-10-27 04:07:33 -070040/**
41 * SECTION:hb-font
Behdad Esfahbodcf5fa572018-10-27 04:50:38 -070042 * @title: hb-font
Behdad Esfahbod5dd86aa2018-10-27 04:28:40 -070043 * @short_description: Font objects
Behdad Esfahbod00cf4e52018-10-27 04:07:33 -070044 * @include: hb.h
45 *
Nathan Willisec987302019-04-17 14:44:25 +010046 * Functions for working with font objects.
47 *
48 * A font object represents a font face at a specific size and with
Nathan Willis82092d42019-04-22 15:31:24 +010049 * certain other parameters (pixels-per-em, points-per-em, variation
Nathan Willisec987302019-04-17 14:44:25 +010050 * settings) specified. Font objects are created from font face
51 * objects, and are used as input to hb_shape(), among other things.
Nathan Willis82092d42019-04-22 15:31:24 +010052 *
53 * Client programs can optionally pass in their own functions that
54 * implement the basic, lower-level queries of font objects. This set
55 * of font functions is defined by the virtual methods in
56 * #hb_font_funcs_t.
57 *
58 * HarfBuzz provides a built-in set of lightweight default
59 * functions for each method in #hb_font_funcs_t.
Behdad Esfahbod00cf4e52018-10-27 04:07:33 -070060 **/
61
62
Behdad Esfahbodc62b5032009-08-01 19:54:49 -040063/*
Behdad Esfahbod5c441882009-08-10 20:05:16 -040064 * hb_font_funcs_t
Behdad Esfahbodc62b5032009-08-01 19:54:49 -040065 */
66
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -040067static hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +010068hb_font_get_font_h_extents_nil (hb_font_t *font HB_UNUSED,
69 void *font_data HB_UNUSED,
Behdad Esfahbodb9db6102018-10-31 14:22:31 -070070 hb_font_extents_t *extents,
Nathan Willisec987302019-04-17 14:44:25 +010071 void *user_data HB_UNUSED)
Simon Cozens6f2e6de2015-10-26 16:23:22 +090072{
Behdad Esfahbodb9db6102018-10-31 14:22:31 -070073 memset (extents, 0, sizeof (*extents));
Simon Cozens6f2e6de2015-10-26 16:23:22 +090074 return false;
75}
Nathan Willis82092d42019-04-22 15:31:24 +010076
Simon Cozens6f2e6de2015-10-26 16:23:22 +090077static hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +010078hb_font_get_font_h_extents_default (hb_font_t *font,
79 void *font_data HB_UNUSED,
Behdad Esfahbodb9db6102018-10-31 14:22:31 -070080 hb_font_extents_t *extents,
Nathan Willisec987302019-04-17 14:44:25 +010081 void *user_data HB_UNUSED)
Simon Cozens6f2e6de2015-10-26 16:23:22 +090082{
Behdad Esfahbodb9db6102018-10-31 14:22:31 -070083 hb_bool_t ret = font->parent->get_font_h_extents (extents);
Simon Cozens6f2e6de2015-10-26 16:23:22 +090084 if (ret) {
Behdad Esfahbodb9db6102018-10-31 14:22:31 -070085 extents->ascender = font->parent_scale_y_distance (extents->ascender);
86 extents->descender = font->parent_scale_y_distance (extents->descender);
87 extents->line_gap = font->parent_scale_y_distance (extents->line_gap);
Simon Cozens6f2e6de2015-10-26 16:23:22 +090088 }
89 return ret;
90}
91
92static hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +010093hb_font_get_font_v_extents_nil (hb_font_t *font HB_UNUSED,
94 void *font_data HB_UNUSED,
Behdad Esfahbodb9db6102018-10-31 14:22:31 -070095 hb_font_extents_t *extents,
Nathan Willisec987302019-04-17 14:44:25 +010096 void *user_data HB_UNUSED)
Simon Cozens6f2e6de2015-10-26 16:23:22 +090097{
Behdad Esfahbodb9db6102018-10-31 14:22:31 -070098 memset (extents, 0, sizeof (*extents));
Simon Cozens6f2e6de2015-10-26 16:23:22 +090099 return false;
100}
Nathan Willis82092d42019-04-22 15:31:24 +0100101
Simon Cozens6f2e6de2015-10-26 16:23:22 +0900102static hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +0100103hb_font_get_font_v_extents_default (hb_font_t *font,
104 void *font_data HB_UNUSED,
Behdad Esfahbodb9db6102018-10-31 14:22:31 -0700105 hb_font_extents_t *extents,
Nathan Willisec987302019-04-17 14:44:25 +0100106 void *user_data HB_UNUSED)
Simon Cozens6f2e6de2015-10-26 16:23:22 +0900107{
Behdad Esfahbodb9db6102018-10-31 14:22:31 -0700108 hb_bool_t ret = font->parent->get_font_v_extents (extents);
Simon Cozens6f2e6de2015-10-26 16:23:22 +0900109 if (ret) {
Behdad Esfahbodb9db6102018-10-31 14:22:31 -0700110 extents->ascender = font->parent_scale_x_distance (extents->ascender);
111 extents->descender = font->parent_scale_x_distance (extents->descender);
112 extents->line_gap = font->parent_scale_x_distance (extents->line_gap);
Simon Cozens6f2e6de2015-10-26 16:23:22 +0900113 }
114 return ret;
115}
116
117static hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +0100118hb_font_get_nominal_glyph_nil (hb_font_t *font HB_UNUSED,
119 void *font_data HB_UNUSED,
120 hb_codepoint_t unicode HB_UNUSED,
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +0900121 hb_codepoint_t *glyph,
Nathan Willisec987302019-04-17 14:44:25 +0100122 void *user_data HB_UNUSED)
Behdad Esfahbod1ded6d82011-05-10 20:49:02 -0400123{
Behdad Esfahbod0fd8c2f2011-05-12 15:14:13 -0400124 *glyph = 0;
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400125 return false;
Behdad Esfahbod1ded6d82011-05-10 20:49:02 -0400126}
Nathan Willis82092d42019-04-22 15:31:24 +0100127
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800128static hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +0100129hb_font_get_nominal_glyph_default (hb_font_t *font,
130 void *font_data HB_UNUSED,
131 hb_codepoint_t unicode,
Behdad Esfahbod79e21982018-08-06 09:45:17 -0700132 hb_codepoint_t *glyph,
Nathan Willisec987302019-04-17 14:44:25 +0100133 void *user_data HB_UNUSED)
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800134{
Behdad Esfahbod08b71722018-10-19 19:12:33 -0700135 if (font->has_nominal_glyphs_func_set ())
Behdad Esfahbodb314c4e2018-10-09 09:23:51 -0400136 {
137 return font->get_nominal_glyphs (1, &unicode, 0, glyph, 0);
138 }
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +0900139 return font->parent->get_nominal_glyph (unicode, glyph);
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800140}
Behdad Esfahbod79512792009-11-03 20:27:05 -0500141
Behdad Esfahbodb314c4e2018-10-09 09:23:51 -0400142#define hb_font_get_nominal_glyphs_nil hb_font_get_nominal_glyphs_default
Nathan Willis82092d42019-04-22 15:31:24 +0100143
Behdad Esfahbodb314c4e2018-10-09 09:23:51 -0400144static unsigned int
Nathan Willisec987302019-04-17 14:44:25 +0100145hb_font_get_nominal_glyphs_default (hb_font_t *font,
146 void *font_data HB_UNUSED,
147 unsigned int count,
Behdad Esfahbodb314c4e2018-10-09 09:23:51 -0400148 const hb_codepoint_t *first_unicode,
Nathan Willisec987302019-04-17 14:44:25 +0100149 unsigned int unicode_stride,
150 hb_codepoint_t *first_glyph,
151 unsigned int glyph_stride,
152 void *user_data HB_UNUSED)
Behdad Esfahbodb314c4e2018-10-09 09:23:51 -0400153{
Behdad Esfahbod08b71722018-10-19 19:12:33 -0700154 if (font->has_nominal_glyph_func_set ())
Behdad Esfahbodb314c4e2018-10-09 09:23:51 -0400155 {
156 for (unsigned int i = 0; i < count; i++)
157 {
158 if (!font->get_nominal_glyph (*first_unicode, first_glyph))
Behdad Esfahbod447323b2019-01-22 12:45:40 +0100159 return i;
Behdad Esfahbodb314c4e2018-10-09 09:23:51 -0400160
Behdad Esfahbod447323b2019-01-22 12:45:40 +0100161 first_unicode = &StructAtOffsetUnaligned<hb_codepoint_t> (first_unicode, unicode_stride);
162 first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
Behdad Esfahbodb314c4e2018-10-09 09:23:51 -0400163 }
164 return count;
165 }
166
167 return font->parent->get_nominal_glyphs (count,
168 first_unicode, unicode_stride,
169 first_glyph, glyph_stride);
170}
171
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +0900172static hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +0100173hb_font_get_variation_glyph_nil (hb_font_t *font HB_UNUSED,
174 void *font_data HB_UNUSED,
175 hb_codepoint_t unicode HB_UNUSED,
176 hb_codepoint_t variation_selector HB_UNUSED,
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +0900177 hb_codepoint_t *glyph,
Nathan Willisec987302019-04-17 14:44:25 +0100178 void *user_data HB_UNUSED)
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +0900179{
180 *glyph = 0;
181 return false;
182}
Nathan Willis82092d42019-04-22 15:31:24 +0100183
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +0900184static hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +0100185hb_font_get_variation_glyph_default (hb_font_t *font,
186 void *font_data HB_UNUSED,
187 hb_codepoint_t unicode,
188 hb_codepoint_t variation_selector,
Behdad Esfahbod79e21982018-08-06 09:45:17 -0700189 hb_codepoint_t *glyph,
Nathan Willisec987302019-04-17 14:44:25 +0100190 void *user_data HB_UNUSED)
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +0900191{
192 return font->parent->get_variation_glyph (unicode, variation_selector, glyph);
193}
194
195
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400196static hb_position_t
Nathan Willisec987302019-04-17 14:44:25 +0100197hb_font_get_glyph_h_advance_nil (hb_font_t *font,
198 void *font_data HB_UNUSED,
199 hb_codepoint_t glyph HB_UNUSED,
200 void *user_data HB_UNUSED)
Behdad Esfahbod1ded6d82011-05-10 20:49:02 -0400201{
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400202 return font->x_scale;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400203}
Nathan Willis82092d42019-04-22 15:31:24 +0100204
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800205static hb_position_t
Nathan Willisec987302019-04-17 14:44:25 +0100206hb_font_get_glyph_h_advance_default (hb_font_t *font,
207 void *font_data HB_UNUSED,
208 hb_codepoint_t glyph,
209 void *user_data HB_UNUSED)
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800210{
Behdad Esfahbod08b71722018-10-19 19:12:33 -0700211 if (font->has_glyph_h_advances_func_set ())
Behdad Esfahbod8a31e402018-09-30 05:27:39 -0400212 {
213 hb_position_t ret;
214 font->get_glyph_h_advances (1, &glyph, 0, &ret, 0);
215 return ret;
216 }
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800217 return font->parent_scale_x_distance (font->parent->get_glyph_h_advance (glyph));
218}
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400219
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400220static hb_position_t
Nathan Willisec987302019-04-17 14:44:25 +0100221hb_font_get_glyph_v_advance_nil (hb_font_t *font,
222 void *font_data HB_UNUSED,
223 hb_codepoint_t glyph HB_UNUSED,
224 void *user_data HB_UNUSED)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400225{
Behdad Esfahbodaba4b0c2016-06-01 16:57:29 -0700226 /* TODO use font_extents.ascender+descender */
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400227 return font->y_scale;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400228}
Nathan Willis82092d42019-04-22 15:31:24 +0100229
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800230static hb_position_t
Nathan Willisec987302019-04-17 14:44:25 +0100231hb_font_get_glyph_v_advance_default (hb_font_t *font,
232 void *font_data HB_UNUSED,
233 hb_codepoint_t glyph,
234 void *user_data HB_UNUSED)
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400235{
Behdad Esfahbod08b71722018-10-19 19:12:33 -0700236 if (font->has_glyph_v_advances_func_set ())
Behdad Esfahbod8a31e402018-09-30 05:27:39 -0400237 {
238 hb_position_t ret;
239 font->get_glyph_v_advances (1, &glyph, 0, &ret, 0);
240 return ret;
241 }
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800242 return font->parent_scale_y_distance (font->parent->get_glyph_v_advance (glyph));
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400243}
244
Behdad Esfahbod3d7c5552018-08-07 09:37:52 -0700245#define hb_font_get_glyph_h_advances_nil hb_font_get_glyph_h_advances_default
Nathan Willis82092d42019-04-22 15:31:24 +0100246
Behdad Esfahbod79e21982018-08-06 09:45:17 -0700247static void
Nathan Willisec987302019-04-17 14:44:25 +0100248hb_font_get_glyph_h_advances_default (hb_font_t* font,
249 void* font_data HB_UNUSED,
250 unsigned int count,
Behdad Esfahbodbee93e22018-10-09 08:01:49 -0400251 const hb_codepoint_t *first_glyph,
Nathan Willisec987302019-04-17 14:44:25 +0100252 unsigned int glyph_stride,
253 hb_position_t *first_advance,
254 unsigned int advance_stride,
255 void *user_data HB_UNUSED)
Behdad Esfahbod79e21982018-08-06 09:45:17 -0700256{
Behdad Esfahbod08b71722018-10-19 19:12:33 -0700257 if (font->has_glyph_h_advance_func_set ())
Behdad Esfahbod79e21982018-08-06 09:45:17 -0700258 {
259 for (unsigned int i = 0; i < count; i++)
260 {
261 *first_advance = font->get_glyph_h_advance (*first_glyph);
Behdad Esfahbod447323b2019-01-22 12:45:40 +0100262 first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
263 first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
Behdad Esfahbod79e21982018-08-06 09:45:17 -0700264 }
265 return;
266 }
267
268 font->parent->get_glyph_h_advances (count,
269 first_glyph, glyph_stride,
270 first_advance, advance_stride);
271 for (unsigned int i = 0; i < count; i++)
272 {
273 *first_advance = font->parent_scale_x_distance (*first_advance);
Behdad Esfahbod447323b2019-01-22 12:45:40 +0100274 first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
Behdad Esfahbod79e21982018-08-06 09:45:17 -0700275 }
276}
277
Behdad Esfahbod3d7c5552018-08-07 09:37:52 -0700278#define hb_font_get_glyph_v_advances_nil hb_font_get_glyph_v_advances_default
Behdad Esfahbod79e21982018-08-06 09:45:17 -0700279static void
Nathan Willisec987302019-04-17 14:44:25 +0100280hb_font_get_glyph_v_advances_default (hb_font_t* font,
281 void* font_data HB_UNUSED,
282 unsigned int count,
Behdad Esfahbodbee93e22018-10-09 08:01:49 -0400283 const hb_codepoint_t *first_glyph,
Nathan Willisec987302019-04-17 14:44:25 +0100284 unsigned int glyph_stride,
285 hb_position_t *first_advance,
286 unsigned int advance_stride,
287 void *user_data HB_UNUSED)
Behdad Esfahbod79e21982018-08-06 09:45:17 -0700288{
Behdad Esfahbod08b71722018-10-19 19:12:33 -0700289 if (font->has_glyph_v_advance_func_set ())
Behdad Esfahbod79e21982018-08-06 09:45:17 -0700290 {
291 for (unsigned int i = 0; i < count; i++)
292 {
293 *first_advance = font->get_glyph_v_advance (*first_glyph);
Behdad Esfahbod447323b2019-01-22 12:45:40 +0100294 first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
295 first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
Behdad Esfahbod79e21982018-08-06 09:45:17 -0700296 }
297 return;
298 }
299
300 font->parent->get_glyph_v_advances (count,
301 first_glyph, glyph_stride,
302 first_advance, advance_stride);
303 for (unsigned int i = 0; i < count; i++)
304 {
305 *first_advance = font->parent_scale_y_distance (*first_advance);
Behdad Esfahbod447323b2019-01-22 12:45:40 +0100306 first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
Behdad Esfahbod79e21982018-08-06 09:45:17 -0700307 }
308}
309
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400310static hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +0100311hb_font_get_glyph_h_origin_nil (hb_font_t *font HB_UNUSED,
312 void *font_data HB_UNUSED,
313 hb_codepoint_t glyph HB_UNUSED,
314 hb_position_t *x,
315 hb_position_t *y,
316 void *user_data HB_UNUSED)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400317{
Behdad Esfahbod19098182011-05-17 23:27:22 -0400318 *x = *y = 0;
Behdad Esfahbodc41c1452015-11-26 18:43:15 -0500319 return true;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400320}
Nathan Willis82092d42019-04-22 15:31:24 +0100321
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800322static hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +0100323hb_font_get_glyph_h_origin_default (hb_font_t *font,
324 void *font_data HB_UNUSED,
325 hb_codepoint_t glyph,
326 hb_position_t *x,
327 hb_position_t *y,
328 void *user_data HB_UNUSED)
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800329{
330 hb_bool_t ret = font->parent->get_glyph_h_origin (glyph, x, y);
331 if (ret)
332 font->parent_scale_position (x, y);
333 return ret;
334}
335
336static hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +0100337hb_font_get_glyph_v_origin_nil (hb_font_t *font HB_UNUSED,
338 void *font_data HB_UNUSED,
339 hb_codepoint_t glyph HB_UNUSED,
340 hb_position_t *x,
341 hb_position_t *y,
342 void *user_data HB_UNUSED)
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800343{
344 *x = *y = 0;
345 return false;
346}
Nathan Willis82092d42019-04-22 15:31:24 +0100347
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800348static hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +0100349hb_font_get_glyph_v_origin_default (hb_font_t *font,
350 void *font_data HB_UNUSED,
351 hb_codepoint_t glyph,
352 hb_position_t *x,
353 hb_position_t *y,
354 void *user_data HB_UNUSED)
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800355{
356 hb_bool_t ret = font->parent->get_glyph_v_origin (glyph, x, y);
357 if (ret)
358 font->parent_scale_position (x, y);
359 return ret;
360}
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400361
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400362static hb_position_t
Nathan Willisec987302019-04-17 14:44:25 +0100363hb_font_get_glyph_h_kerning_nil (hb_font_t *font HB_UNUSED,
364 void *font_data HB_UNUSED,
365 hb_codepoint_t left_glyph HB_UNUSED,
366 hb_codepoint_t right_glyph HB_UNUSED,
367 void *user_data HB_UNUSED)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400368{
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400369 return 0;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400370}
Nathan Willis82092d42019-04-22 15:31:24 +0100371
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800372static hb_position_t
Nathan Willisec987302019-04-17 14:44:25 +0100373hb_font_get_glyph_h_kerning_default (hb_font_t *font,
374 void *font_data HB_UNUSED,
375 hb_codepoint_t left_glyph,
376 hb_codepoint_t right_glyph,
377 void *user_data HB_UNUSED)
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800378{
379 return font->parent_scale_x_distance (font->parent->get_glyph_h_kerning (left_glyph, right_glyph));
380}
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400381
Behdad Esfahbod0819f3c2019-06-17 14:02:47 -0700382#ifndef HB_DISABLE_DEPRECATED
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400383static hb_position_t
Nathan Willisec987302019-04-17 14:44:25 +0100384hb_font_get_glyph_v_kerning_nil (hb_font_t *font HB_UNUSED,
385 void *font_data HB_UNUSED,
386 hb_codepoint_t top_glyph HB_UNUSED,
387 hb_codepoint_t bottom_glyph HB_UNUSED,
388 void *user_data HB_UNUSED)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400389{
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400390 return 0;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400391}
Nathan Willis82092d42019-04-22 15:31:24 +0100392
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800393static hb_position_t
Nathan Willisec987302019-04-17 14:44:25 +0100394hb_font_get_glyph_v_kerning_default (hb_font_t *font,
395 void *font_data HB_UNUSED,
396 hb_codepoint_t top_glyph,
397 hb_codepoint_t bottom_glyph,
398 void *user_data HB_UNUSED)
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800399{
400 return font->parent_scale_y_distance (font->parent->get_glyph_v_kerning (top_glyph, bottom_glyph));
401}
Behdad Esfahbodfca27862019-05-11 00:37:01 -0700402#endif
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400403
404static hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +0100405hb_font_get_glyph_extents_nil (hb_font_t *font HB_UNUSED,
406 void *font_data HB_UNUSED,
407 hb_codepoint_t glyph HB_UNUSED,
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400408 hb_glyph_extents_t *extents,
Nathan Willisec987302019-04-17 14:44:25 +0100409 void *user_data HB_UNUSED)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400410{
Behdad Esfahbod60fbb362011-05-19 18:46:15 -0400411 memset (extents, 0, sizeof (*extents));
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400412 return false;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400413}
Nathan Willis82092d42019-04-22 15:31:24 +0100414
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800415static hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +0100416hb_font_get_glyph_extents_default (hb_font_t *font,
417 void *font_data HB_UNUSED,
418 hb_codepoint_t glyph,
Behdad Esfahbod79e21982018-08-06 09:45:17 -0700419 hb_glyph_extents_t *extents,
Nathan Willisec987302019-04-17 14:44:25 +0100420 void *user_data HB_UNUSED)
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800421{
422 hb_bool_t ret = font->parent->get_glyph_extents (glyph, extents);
423 if (ret) {
424 font->parent_scale_position (&extents->x_bearing, &extents->y_bearing);
425 font->parent_scale_distance (&extents->width, &extents->height);
426 }
427 return ret;
428}
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400429
430static hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +0100431hb_font_get_glyph_contour_point_nil (hb_font_t *font HB_UNUSED,
432 void *font_data HB_UNUSED,
433 hb_codepoint_t glyph HB_UNUSED,
434 unsigned int point_index HB_UNUSED,
435 hb_position_t *x,
436 hb_position_t *y,
437 void *user_data HB_UNUSED)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400438{
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400439 *x = *y = 0;
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400440 return false;
Behdad Esfahbod1ded6d82011-05-10 20:49:02 -0400441}
Nathan Willis82092d42019-04-22 15:31:24 +0100442
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800443static hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +0100444hb_font_get_glyph_contour_point_default (hb_font_t *font,
445 void *font_data HB_UNUSED,
446 hb_codepoint_t glyph,
447 unsigned int point_index,
448 hb_position_t *x,
449 hb_position_t *y,
450 void *user_data HB_UNUSED)
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800451{
452 hb_bool_t ret = font->parent->get_glyph_contour_point (glyph, point_index, x, y);
453 if (ret)
454 font->parent_scale_position (x, y);
455 return ret;
456}
Behdad Esfahbod79512792009-11-03 20:27:05 -0500457
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400458static hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +0100459hb_font_get_glyph_name_nil (hb_font_t *font HB_UNUSED,
460 void *font_data HB_UNUSED,
461 hb_codepoint_t glyph HB_UNUSED,
462 char *name,
463 unsigned int size,
464 void *user_data HB_UNUSED)
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400465{
Behdad Esfahbod6f3a3002012-08-07 22:13:25 -0400466 if (size) *name = '\0';
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400467 return false;
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400468}
Nathan Willis82092d42019-04-22 15:31:24 +0100469
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800470static hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +0100471hb_font_get_glyph_name_default (hb_font_t *font,
472 void *font_data HB_UNUSED,
473 hb_codepoint_t glyph,
474 char *name,
475 unsigned int size,
476 void *user_data HB_UNUSED)
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800477{
478 return font->parent->get_glyph_name (glyph, name, size);
479}
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400480
481static hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +0100482hb_font_get_glyph_from_name_nil (hb_font_t *font HB_UNUSED,
483 void *font_data HB_UNUSED,
484 const char *name HB_UNUSED,
485 int len HB_UNUSED, /* -1 means nul-terminated */
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400486 hb_codepoint_t *glyph,
Nathan Willisec987302019-04-17 14:44:25 +0100487 void *user_data HB_UNUSED)
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400488{
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400489 *glyph = 0;
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400490 return false;
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400491}
Nathan Willis82092d42019-04-22 15:31:24 +0100492
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800493static hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +0100494hb_font_get_glyph_from_name_default (hb_font_t *font,
495 void *font_data HB_UNUSED,
496 const char *name,
497 int len, /* -1 means nul-terminated */
Behdad Esfahbod79e21982018-08-06 09:45:17 -0700498 hb_codepoint_t *glyph,
Nathan Willisec987302019-04-17 14:44:25 +0100499 void *user_data HB_UNUSED)
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800500{
501 return font->parent->get_glyph_from_name (name, len, glyph);
502}
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400503
Behdad Esfahbod35066722018-08-06 06:17:48 -0700504DEFINE_NULL_INSTANCE (hb_font_funcs_t) =
505{
Behdad Esfahbodfca368c2011-04-21 18:24:02 -0400506 HB_OBJECT_HEADER_STATIC,
507
Behdad Esfahbodbf36a102010-05-24 17:46:21 +0100508 {
Behdad Esfahboddbdbfe32017-10-15 12:11:08 +0200509#define HB_FONT_FUNC_IMPLEMENT(name) nullptr,
Behdad Esfahbod28de1042015-11-04 22:00:25 -0800510 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
511#undef HB_FONT_FUNC_IMPLEMENT
512 },
513 {
Behdad Esfahboddbdbfe32017-10-15 12:11:08 +0200514#define HB_FONT_FUNC_IMPLEMENT(name) nullptr,
Behdad Esfahbod28de1042015-11-04 22:00:25 -0800515 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
516#undef HB_FONT_FUNC_IMPLEMENT
517 },
518 {
jfkthamef19c6db2015-11-20 08:43:49 +0000519 {
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400520#define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_nil,
jfkthamef19c6db2015-11-20 08:43:49 +0000521 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400522#undef HB_FONT_FUNC_IMPLEMENT
jfkthamef19c6db2015-11-20 08:43:49 +0000523 }
Behdad Esfahbodbf36a102010-05-24 17:46:21 +0100524 }
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400525};
Behdad Esfahbod35066722018-08-06 06:17:48 -0700526
Behdad Esfahbod79e21982018-08-06 09:45:17 -0700527static const hb_font_funcs_t _hb_font_funcs_default = {
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800528 HB_OBJECT_HEADER_STATIC,
529
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800530 {
Behdad Esfahboddbdbfe32017-10-15 12:11:08 +0200531#define HB_FONT_FUNC_IMPLEMENT(name) nullptr,
Behdad Esfahbod28de1042015-11-04 22:00:25 -0800532 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
533#undef HB_FONT_FUNC_IMPLEMENT
534 },
535 {
Behdad Esfahboddbdbfe32017-10-15 12:11:08 +0200536#define HB_FONT_FUNC_IMPLEMENT(name) nullptr,
Behdad Esfahbod28de1042015-11-04 22:00:25 -0800537 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
538#undef HB_FONT_FUNC_IMPLEMENT
539 },
540 {
jfkthamef19c6db2015-11-20 08:43:49 +0000541 {
Behdad Esfahbod79e21982018-08-06 09:45:17 -0700542#define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_default,
jfkthamef19c6db2015-11-20 08:43:49 +0000543 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800544#undef HB_FONT_FUNC_IMPLEMENT
jfkthamef19c6db2015-11-20 08:43:49 +0000545 }
Behdad Esfahbodda29b432015-11-04 20:22:44 -0800546 }
547};
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400548
Behdad Esfahbod56eb5ad2011-05-04 19:27:37 -0400549
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400550/**
Behdad Esfahbod085d4292013-09-12 17:14:33 -0400551 * hb_font_funcs_create: (Xconstructor)
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400552 *
Nathan Willis82092d42019-04-22 15:31:24 +0100553 * Creates a new #hb_font_funcs_t structure of font functions.
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400554 *
Nathan Willis82092d42019-04-22 15:31:24 +0100555 * Return value: (transfer full): The font-functions structure
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400556 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430557 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400558 **/
Behdad Esfahbod5c441882009-08-10 20:05:16 -0400559hb_font_funcs_t *
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330560hb_font_funcs_create ()
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400561{
Behdad Esfahbod5c441882009-08-10 20:05:16 -0400562 hb_font_funcs_t *ffuncs;
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400563
Behdad Esfahbod47e71d92011-04-27 16:38:03 -0400564 if (!(ffuncs = hb_object_create<hb_font_funcs_t> ()))
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -0400565 return hb_font_funcs_get_empty ();
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400566
Behdad Esfahbod79e21982018-08-06 09:45:17 -0700567 ffuncs->get = _hb_font_funcs_default.get;
Behdad Esfahbodf97bf4f2010-05-24 17:50:19 +0100568
Behdad Esfahbod5c441882009-08-10 20:05:16 -0400569 return ffuncs;
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400570}
571
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400572/**
573 * hb_font_funcs_get_empty:
574 *
Nathan Willis82092d42019-04-22 15:31:24 +0100575 * Fetches an empty font-functions structure.
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400576 *
Nathan Willis82092d42019-04-22 15:31:24 +0100577 * Return value: (transfer full): The font-functions structure
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400578 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430579 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400580 **/
Behdad Esfahbod5c441882009-08-10 20:05:16 -0400581hb_font_funcs_t *
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330582hb_font_funcs_get_empty ()
Behdad Esfahbod80a68332011-05-11 18:14:44 -0400583{
Behdad Esfahbod79e21982018-08-06 09:45:17 -0700584 return const_cast<hb_font_funcs_t *> (&_hb_font_funcs_default);
Behdad Esfahbod80a68332011-05-11 18:14:44 -0400585}
586
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400587/**
588 * hb_font_funcs_reference: (skip)
Nathan Willis82092d42019-04-22 15:31:24 +0100589 * @ffuncs: The font-functions structure
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400590 *
Nathan Willis82092d42019-04-22 15:31:24 +0100591 * Increases the reference count on a font-functions structure.
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400592 *
Nathan Willis82092d42019-04-22 15:31:24 +0100593 * Return value: The font-functions structure
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400594 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430595 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400596 **/
Behdad Esfahbod80a68332011-05-11 18:14:44 -0400597hb_font_funcs_t *
Behdad Esfahbod5c441882009-08-10 20:05:16 -0400598hb_font_funcs_reference (hb_font_funcs_t *ffuncs)
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400599{
Behdad Esfahbod47e71d92011-04-27 16:38:03 -0400600 return hb_object_reference (ffuncs);
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400601}
602
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400603/**
604 * hb_font_funcs_destroy: (skip)
Nathan Willis82092d42019-04-22 15:31:24 +0100605 * @ffuncs: The font-functions structure
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400606 *
Nathan Willis82092d42019-04-22 15:31:24 +0100607 * Decreases the reference count on a font-functions structure. When
608 * the reference count reaches zero, the font-functions structure is
609 * destroyed, freeing all memory.
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400610 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430611 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400612 **/
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400613void
Behdad Esfahbod5c441882009-08-10 20:05:16 -0400614hb_font_funcs_destroy (hb_font_funcs_t *ffuncs)
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400615{
Behdad Esfahbod47e71d92011-04-27 16:38:03 -0400616 if (!hb_object_destroy (ffuncs)) return;
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400617
Behdad Esfahbod4b6317c2011-07-07 23:14:42 -0400618#define HB_FONT_FUNC_IMPLEMENT(name) if (ffuncs->destroy.name) \
619 ffuncs->destroy.name (ffuncs->user_data.name);
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400620 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
621#undef HB_FONT_FUNC_IMPLEMENT
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400622
Behdad Esfahbod2337f0d2021-07-08 10:58:50 -0600623 hb_free (ffuncs);
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400624}
625
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400626/**
627 * hb_font_funcs_set_user_data: (skip)
Nathan Willis82092d42019-04-22 15:31:24 +0100628 * @ffuncs: The font-functions structure
629 * @key: The user-data key to set
630 * @data: A pointer to the user data set
Khaled Hosny99364902020-12-31 00:19:29 +0200631 * @destroy: (nullable): A callback to call when @data is not needed anymore
Nathan Willis82092d42019-04-22 15:31:24 +0100632 * @replace: Whether to replace an existing data with the same key
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400633 *
Nathan Willis82092d42019-04-22 15:31:24 +0100634 * Attaches a user-data key/data pair to the specified font-functions structure.
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400635 *
Khaled Hosnyf88e8452020-12-24 21:28:37 +0200636 * Return value: %true if success, %false otherwise
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400637 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430638 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400639 **/
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -0400640hb_bool_t
641hb_font_funcs_set_user_data (hb_font_funcs_t *ffuncs,
642 hb_user_data_key_t *key,
643 void * data,
Nathan Willis82092d42019-04-22 15:31:24 +0100644 hb_destroy_func_t destroy /* May be NULL. */,
Behdad Esfahbod33ccc772011-08-09 00:43:24 +0200645 hb_bool_t replace)
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -0400646{
Behdad Esfahbod33ccc772011-08-09 00:43:24 +0200647 return hb_object_set_user_data (ffuncs, key, data, destroy, replace);
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -0400648}
649
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400650/**
651 * hb_font_funcs_get_user_data: (skip)
Nathan Willis82092d42019-04-22 15:31:24 +0100652 * @ffuncs: The font-functions structure
653 * @key: The user-data key to query
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400654 *
Nathan Willis82092d42019-04-22 15:31:24 +0100655 * Fetches the user data associated with the specified key,
656 * attached to the specified font-functions structure.
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400657 *
Nathan Willis82092d42019-04-22 15:31:24 +0100658 * Return value: (transfer none): A pointer to the user data
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400659 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430660 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400661 **/
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -0400662void *
663hb_font_funcs_get_user_data (hb_font_funcs_t *ffuncs,
664 hb_user_data_key_t *key)
665{
666 return hb_object_get_user_data (ffuncs, key);
667}
668
669
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400670/**
671 * hb_font_funcs_make_immutable:
Nathan Willis82092d42019-04-22 15:31:24 +0100672 * @ffuncs: The font-functions structure
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400673 *
Nathan Willis82092d42019-04-22 15:31:24 +0100674 * Makes a font-functions structure immutable.
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400675 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430676 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400677 **/
Behdad Esfahbod8d703122009-08-10 23:50:51 -0400678void
679hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs)
680{
Behdad Esfahbod5570c872018-11-03 14:51:38 -0400681 if (hb_object_is_immutable (ffuncs))
Behdad Esfahbod90a0f9f2018-09-26 15:03:07 -0400682 return;
Behdad Esfahbod8d703122009-08-10 23:50:51 -0400683
Behdad Esfahbod5570c872018-11-03 14:51:38 -0400684 hb_object_make_immutable (ffuncs);
Behdad Esfahbod8d703122009-08-10 23:50:51 -0400685}
686
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400687/**
688 * hb_font_funcs_is_immutable:
Nathan Willis82092d42019-04-22 15:31:24 +0100689 * @ffuncs: The font-functions structure
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400690 *
Nathan Willis82092d42019-04-22 15:31:24 +0100691 * Tests whether a font-functions structure is immutable.
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400692 *
Khaled Hosnya8e72ee2020-12-30 23:08:40 +0200693 * Return value: %true if @ffuncs is immutable, %false otherwise
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400694 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430695 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400696 **/
Behdad Esfahbod645f6f22010-10-04 17:01:01 -0400697hb_bool_t
698hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs)
699{
Behdad Esfahbod5570c872018-11-03 14:51:38 -0400700 return hb_object_is_immutable (ffuncs);
Behdad Esfahbod645f6f22010-10-04 17:01:01 -0400701}
702
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400703
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400704#define HB_FONT_FUNC_IMPLEMENT(name) \
Ebrahim Byagowia0b4ac42019-08-24 17:57:14 +0430705 \
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400706void \
707hb_font_funcs_set_##name##_func (hb_font_funcs_t *ffuncs, \
Ebrahim Byagowia0b4ac42019-08-24 17:57:14 +0430708 hb_font_get_##name##_func_t func, \
709 void *user_data, \
710 hb_destroy_func_t destroy) \
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400711{ \
Ebrahim Byagowi352ac632020-02-11 03:03:03 +0330712 if (hb_object_is_immutable (ffuncs)) \
713 { \
Behdad Esfahbod0cd33592011-09-21 16:49:33 -0400714 if (destroy) \
715 destroy (user_data); \
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400716 return; \
Behdad Esfahbod0cd33592011-09-21 16:49:33 -0400717 } \
Ebrahim Byagowia0b4ac42019-08-24 17:57:14 +0430718 \
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400719 if (ffuncs->destroy.name) \
720 ffuncs->destroy.name (ffuncs->user_data.name); \
Ebrahim Byagowia0b4ac42019-08-24 17:57:14 +0430721 \
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400722 if (func) { \
Behdad Esfahbod88e9a9b2015-11-04 21:16:26 -0800723 ffuncs->get.f.name = func; \
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400724 ffuncs->user_data.name = user_data; \
725 ffuncs->destroy.name = destroy; \
726 } else { \
Behdad Esfahbod79e21982018-08-06 09:45:17 -0700727 ffuncs->get.f.name = hb_font_get_##name##_default; \
728 ffuncs->user_data.name = nullptr; \
729 ffuncs->destroy.name = nullptr; \
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400730 } \
Behdad Esfahbod79512792009-11-03 20:27:05 -0500731}
732
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400733HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
734#undef HB_FONT_FUNC_IMPLEMENT
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400735
Behdad Esfahbod762770c2015-11-04 21:42:55 -0800736bool
Behdad Esfahbod08b71722018-10-19 19:12:33 -0700737hb_font_t::has_func_set (unsigned int i)
738{
739 return this->klass->get.array[i] != _hb_font_funcs_default.get.array[i];
740}
741
742bool
Behdad Esfahbod762770c2015-11-04 21:42:55 -0800743hb_font_t::has_func (unsigned int i)
744{
Behdad Esfahbod08b71722018-10-19 19:12:33 -0700745 return has_func_set (i) ||
Behdad Esfahbod79e21982018-08-06 09:45:17 -0700746 (parent && parent != &_hb_Null_hb_font_t && parent->has_func (i));
Behdad Esfahbod762770c2015-11-04 21:42:55 -0800747}
Behdad Esfahbod502f4cb2010-10-27 01:13:56 -0400748
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400749/* Public getters */
750
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400751/**
Simon Cozens6f2e6de2015-10-26 16:23:22 +0900752 * hb_font_get_h_extents:
Nathan Willis82092d42019-04-22 15:31:24 +0100753 * @font: #hb_font_t to work upon
754 * @extents: (out): The font extents retrieved
Simon Cozens6f2e6de2015-10-26 16:23:22 +0900755 *
Khaled Hosnyaa107e62020-12-30 23:34:17 +0200756 * Fetches the extents for a specified font, for horizontal
Nathan Willis82092d42019-04-22 15:31:24 +0100757 * text segments.
Simon Cozens6f2e6de2015-10-26 16:23:22 +0900758 *
Khaled Hosnya8e72ee2020-12-30 23:08:40 +0200759 * Return value: %true if data found, %false otherwise
Simon Cozens6f2e6de2015-10-26 16:23:22 +0900760 *
Behdad Esfahbodf11c11a2015-12-16 17:08:36 +0100761 * Since: 1.1.3
Simon Cozens6f2e6de2015-10-26 16:23:22 +0900762 **/
763hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +0100764hb_font_get_h_extents (hb_font_t *font,
Simon Cozens6f2e6de2015-10-26 16:23:22 +0900765 hb_font_extents_t *extents)
766{
767 return font->get_font_h_extents (extents);
768}
769
770/**
771 * hb_font_get_v_extents:
Nathan Willis82092d42019-04-22 15:31:24 +0100772 * @font: #hb_font_t to work upon
773 * @extents: (out): The font extents retrieved
Simon Cozens6f2e6de2015-10-26 16:23:22 +0900774 *
Khaled Hosnyaa107e62020-12-30 23:34:17 +0200775 * Fetches the extents for a specified font, for vertical
Nathan Willis82092d42019-04-22 15:31:24 +0100776 * text segments.
Simon Cozens6f2e6de2015-10-26 16:23:22 +0900777 *
Khaled Hosnya8e72ee2020-12-30 23:08:40 +0200778 * Return value: %true if data found, %false otherwise
Simon Cozens6f2e6de2015-10-26 16:23:22 +0900779 *
Behdad Esfahbodf11c11a2015-12-16 17:08:36 +0100780 * Since: 1.1.3
Simon Cozens6f2e6de2015-10-26 16:23:22 +0900781 **/
782hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +0100783hb_font_get_v_extents (hb_font_t *font,
Simon Cozens6f2e6de2015-10-26 16:23:22 +0900784 hb_font_extents_t *extents)
785{
786 return font->get_font_v_extents (extents);
787}
788
789/**
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400790 * hb_font_get_glyph:
Nathan Willis82092d42019-04-22 15:31:24 +0100791 * @font: #hb_font_t to work upon
792 * @unicode: The Unicode code point to query
Khaled Hosnya64d56a2020-12-31 00:27:49 +0200793 * @variation_selector: A variation-selector code point
Nathan Willis82092d42019-04-22 15:31:24 +0100794 * @glyph: (out): The glyph ID retrieved
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400795 *
Nathan Willis82092d42019-04-22 15:31:24 +0100796 * Fetches the glyph ID for a Unicode code point in the specified
797 * font, with an optional variation selector.
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400798 *
Nathan Willis82092d42019-04-22 15:31:24 +0100799 * If @variation_selector is 0, calls hb_font_get_nominal_glyph();
800 * otherwise calls hb_font_get_variation_glyph().
Ebrahim Byagowi6a194b62019-08-14 18:49:57 +0430801 *
Khaled Hosnya8e72ee2020-12-30 23:08:40 +0200802 * Return value: %true if data found, %false otherwise
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400803 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430804 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400805 **/
Behdad Esfahbod0fd8c2f2011-05-12 15:14:13 -0400806hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +0100807hb_font_get_glyph (hb_font_t *font,
808 hb_codepoint_t unicode,
809 hb_codepoint_t variation_selector,
Behdad Esfahbod0fd8c2f2011-05-12 15:14:13 -0400810 hb_codepoint_t *glyph)
Behdad Esfahbod2e336692009-11-05 13:55:41 -0500811{
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +0900812 if (unlikely (variation_selector))
813 return font->get_variation_glyph (unicode, variation_selector, glyph);
814 return font->get_nominal_glyph (unicode, glyph);
815}
816
817/**
818 * hb_font_get_nominal_glyph:
Nathan Willis82092d42019-04-22 15:31:24 +0100819 * @font: #hb_font_t to work upon
820 * @unicode: The Unicode code point to query
821 * @glyph: (out): The glyph ID retrieved
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +0900822 *
Nathan Willis82092d42019-04-22 15:31:24 +0100823 * Fetches the nominal glyph ID for a Unicode code point in the
824 * specified font.
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +0900825 *
Nathan Willis82092d42019-04-22 15:31:24 +0100826 * This version of the function should not be used to fetch glyph IDs
827 * for code points modified by variation selectors. For variation-selector
828 * support, user hb_font_get_variation_glyph() or use hb_font_get_glyph().
Ebrahim Byagowi6a194b62019-08-14 18:49:57 +0430829 *
Khaled Hosnya8e72ee2020-12-30 23:08:40 +0200830 * Return value: %true if data found, %false otherwise
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +0900831 *
832 * Since: 1.2.3
833 **/
834hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +0100835hb_font_get_nominal_glyph (hb_font_t *font,
836 hb_codepoint_t unicode,
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +0900837 hb_codepoint_t *glyph)
838{
839 return font->get_nominal_glyph (unicode, glyph);
840}
841
842/**
Behdad Esfahbod5a59de22019-10-28 14:02:47 -0700843 * hb_font_get_nominal_glyphs:
Khaled Hosnyaa107e62020-12-30 23:34:17 +0200844 * @font: #hb_font_t to work upon
845 * @count: number of code points to query
846 * @first_unicode: The first Unicode code point to query
847 * @unicode_stride: The stride between successive code points
848 * @first_glyph: (out): The first glyph ID retrieved
849 * @glyph_stride: The stride between successive glyph IDs
Behdad Esfahbod5a59de22019-10-28 14:02:47 -0700850 *
Khaled Hosnyaa107e62020-12-30 23:34:17 +0200851 * Fetches the nominal glyph IDs for a sequence of Unicode code points. Glyph
852 * IDs must be returned in a #hb_codepoint_t output parameter.
Behdad Esfahbod5a59de22019-10-28 14:02:47 -0700853 *
Khaled Hosnyaa107e62020-12-30 23:34:17 +0200854 * Return value: the number of code points processed
Behdad Esfahbod5a59de22019-10-28 14:02:47 -0700855 *
Behdad Esfahbodce11df12019-10-28 14:45:31 -0700856 * Since: 2.6.3
Behdad Esfahbod5a59de22019-10-28 14:02:47 -0700857 **/
858unsigned int
859hb_font_get_nominal_glyphs (hb_font_t *font,
860 unsigned int count,
861 const hb_codepoint_t *first_unicode,
862 unsigned int unicode_stride,
863 hb_codepoint_t *first_glyph,
864 unsigned int glyph_stride)
865{
866 return font->get_nominal_glyphs (count,
867 first_unicode, unicode_stride,
868 first_glyph, glyph_stride);
869}
870
871/**
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +0900872 * hb_font_get_variation_glyph:
Nathan Willis82092d42019-04-22 15:31:24 +0100873 * @font: #hb_font_t to work upon
874 * @unicode: The Unicode code point to query
875 * @variation_selector: The variation-selector code point to query
876 * @glyph: (out): The glyph ID retrieved
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +0900877 *
Nathan Willis82092d42019-04-22 15:31:24 +0100878 * Fetches the glyph ID for a Unicode code point when followed by
879 * by the specified variation-selector code point, in the specified
880 * font.
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +0900881 *
Khaled Hosnya8e72ee2020-12-30 23:08:40 +0200882 * Return value: %true if data found, %false otherwise
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +0900883 *
884 * Since: 1.2.3
885 **/
886hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +0100887hb_font_get_variation_glyph (hb_font_t *font,
888 hb_codepoint_t unicode,
889 hb_codepoint_t variation_selector,
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +0900890 hb_codepoint_t *glyph)
891{
892 return font->get_variation_glyph (unicode, variation_selector, glyph);
Behdad Esfahbod2e336692009-11-05 13:55:41 -0500893}
894
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400895/**
896 * hb_font_get_glyph_h_advance:
Nathan Willis82092d42019-04-22 15:31:24 +0100897 * @font: #hb_font_t to work upon
898 * @glyph: The glyph ID to query
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400899 *
Nathan Willis82092d42019-04-22 15:31:24 +0100900 * Fetches the advance for a glyph ID in the specified font,
901 * for horizontal text segments.
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400902 *
Nathan Willis82092d42019-04-22 15:31:24 +0100903 * Return value: The advance of @glyph within @font
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400904 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430905 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400906 **/
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400907hb_position_t
Nathan Willisec987302019-04-17 14:44:25 +0100908hb_font_get_glyph_h_advance (hb_font_t *font,
909 hb_codepoint_t glyph)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400910{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400911 return font->get_glyph_h_advance (glyph);
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400912}
913
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400914/**
915 * hb_font_get_glyph_v_advance:
Nathan Willis82092d42019-04-22 15:31:24 +0100916 * @font: #hb_font_t to work upon
917 * @glyph: The glyph ID to query
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400918 *
Nathan Willis82092d42019-04-22 15:31:24 +0100919 * Fetches the advance for a glyph ID in the specified font,
920 * for vertical text segments.
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400921 *
Nathan Willis82092d42019-04-22 15:31:24 +0100922 * Return value: The advance of @glyph within @font
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400923 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430924 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400925 **/
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400926hb_position_t
Nathan Willisec987302019-04-17 14:44:25 +0100927hb_font_get_glyph_v_advance (hb_font_t *font,
928 hb_codepoint_t glyph)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400929{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400930 return font->get_glyph_v_advance (glyph);
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400931}
932
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400933/**
Behdad Esfahbod28e2f462018-08-07 09:47:00 -0700934 * hb_font_get_glyph_h_advances:
Nathan Willis82092d42019-04-22 15:31:24 +0100935 * @font: #hb_font_t to work upon
936 * @count: The number of glyph IDs in the sequence queried
937 * @first_glyph: The first glyph ID to query
938 * @glyph_stride: The stride between successive glyph IDs
939 * @first_advance: (out): The first advance retrieved
Khaled Hosnyaa107e62020-12-30 23:34:17 +0200940 * @advance_stride: The stride between successive advances
Behdad Esfahbod28e2f462018-08-07 09:47:00 -0700941 *
Nathan Willis82092d42019-04-22 15:31:24 +0100942 * Fetches the advances for a sequence of glyph IDs in the specified
943 * font, for horizontal text segments.
Behdad Esfahbod28e2f462018-08-07 09:47:00 -0700944 *
Behdad Esfahbode49a38b2018-08-07 09:55:42 -0700945 * Since: 1.8.6
Behdad Esfahbod28e2f462018-08-07 09:47:00 -0700946 **/
947void
Nathan Willisec987302019-04-17 14:44:25 +0100948hb_font_get_glyph_h_advances (hb_font_t* font,
949 unsigned int count,
Behdad Esfahbodbee93e22018-10-09 08:01:49 -0400950 const hb_codepoint_t *first_glyph,
Nathan Willisec987302019-04-17 14:44:25 +0100951 unsigned glyph_stride,
952 hb_position_t *first_advance,
953 unsigned advance_stride)
Behdad Esfahbod28e2f462018-08-07 09:47:00 -0700954{
955 font->get_glyph_h_advances (count, first_glyph, glyph_stride, first_advance, advance_stride);
956}
957/**
958 * hb_font_get_glyph_v_advances:
Nathan Willis82092d42019-04-22 15:31:24 +0100959 * @font: #hb_font_t to work upon
960 * @count: The number of glyph IDs in the sequence queried
961 * @first_glyph: The first glyph ID to query
962 * @glyph_stride: The stride between successive glyph IDs
963 * @first_advance: (out): The first advance retrieved
964 * @advance_stride: (out): The stride between successive advances
Behdad Esfahbod28e2f462018-08-07 09:47:00 -0700965 *
Nathan Willis82092d42019-04-22 15:31:24 +0100966 * Fetches the advances for a sequence of glyph IDs in the specified
967 * font, for vertical text segments.
Behdad Esfahbod28e2f462018-08-07 09:47:00 -0700968 *
Behdad Esfahbode49a38b2018-08-07 09:55:42 -0700969 * Since: 1.8.6
Behdad Esfahbod28e2f462018-08-07 09:47:00 -0700970 **/
971void
Nathan Willisec987302019-04-17 14:44:25 +0100972hb_font_get_glyph_v_advances (hb_font_t* font,
973 unsigned int count,
Behdad Esfahbodbee93e22018-10-09 08:01:49 -0400974 const hb_codepoint_t *first_glyph,
Nathan Willisec987302019-04-17 14:44:25 +0100975 unsigned glyph_stride,
976 hb_position_t *first_advance,
977 unsigned advance_stride)
Behdad Esfahbod28e2f462018-08-07 09:47:00 -0700978{
979 font->get_glyph_v_advances (count, first_glyph, glyph_stride, first_advance, advance_stride);
980}
981
982/**
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400983 * hb_font_get_glyph_h_origin:
Nathan Willis82092d42019-04-22 15:31:24 +0100984 * @font: #hb_font_t to work upon
985 * @glyph: The glyph ID to query
986 * @x: (out): The X coordinate of the origin
987 * @y: (out): The Y coordinate of the origin
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400988 *
Nathan Willis82092d42019-04-22 15:31:24 +0100989 * Fetches the (X,Y) coordinates of the origin for a glyph ID
990 * in the specified font, for horizontal text segments.
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400991 *
Khaled Hosnya8e72ee2020-12-30 23:08:40 +0200992 * Return value: %true if data found, %false otherwise
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400993 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +0430994 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -0400995 **/
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400996hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +0100997hb_font_get_glyph_h_origin (hb_font_t *font,
998 hb_codepoint_t glyph,
999 hb_position_t *x,
1000 hb_position_t *y)
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -04001001{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -04001002 return font->get_glyph_h_origin (glyph, x, y);
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -04001003}
1004
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001005/**
1006 * hb_font_get_glyph_v_origin:
Nathan Willis82092d42019-04-22 15:31:24 +01001007 * @font: #hb_font_t to work upon
1008 * @glyph: The glyph ID to query
1009 * @x: (out): The X coordinate of the origin
1010 * @y: (out): The Y coordinate of the origin
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001011 *
Nathan Willis82092d42019-04-22 15:31:24 +01001012 * Fetches the (X,Y) coordinates of the origin for a glyph ID
1013 * in the specified font, for vertical text segments.
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001014 *
Khaled Hosnya8e72ee2020-12-30 23:08:40 +02001015 * Return value: %true if data found, %false otherwise
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001016 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301017 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001018 **/
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -04001019hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +01001020hb_font_get_glyph_v_origin (hb_font_t *font,
1021 hb_codepoint_t glyph,
1022 hb_position_t *x,
1023 hb_position_t *y)
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001024{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -04001025 return font->get_glyph_v_origin (glyph, x, y);
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001026}
1027
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001028/**
1029 * hb_font_get_glyph_h_kerning:
Nathan Willis82092d42019-04-22 15:31:24 +01001030 * @font: #hb_font_t to work upon
1031 * @left_glyph: The glyph ID of the left glyph in the glyph pair
1032 * @right_glyph: The glyph ID of the right glyph in the glyph pair
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001033 *
Nathan Willis82092d42019-04-22 15:31:24 +01001034 * Fetches the kerning-adjustment value for a glyph-pair in
Khaled Hosnyaa107e62020-12-30 23:34:17 +02001035 * the specified font, for horizontal text segments.
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001036 *
Khaled Hosny35c4a152020-12-24 22:34:02 +02001037 * <note>It handles legacy kerning only (as returned by the corresponding
1038 * #hb_font_funcs_t function).</note>
1039 *
Nathan Willis82092d42019-04-22 15:31:24 +01001040 * Return value: The kerning adjustment value
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001041 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301042 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001043 **/
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -04001044hb_position_t
Nathan Willisec987302019-04-17 14:44:25 +01001045hb_font_get_glyph_h_kerning (hb_font_t *font,
1046 hb_codepoint_t left_glyph,
1047 hb_codepoint_t right_glyph)
Behdad Esfahbod2e336692009-11-05 13:55:41 -05001048{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -04001049 return font->get_glyph_h_kerning (left_glyph, right_glyph);
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001050}
1051
Behdad Esfahbod0819f3c2019-06-17 14:02:47 -07001052#ifndef HB_DISABLE_DEPRECATED
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001053/**
1054 * hb_font_get_glyph_v_kerning:
Nathan Willis82092d42019-04-22 15:31:24 +01001055 * @font: #hb_font_t to work upon
1056 * @top_glyph: The glyph ID of the top glyph in the glyph pair
1057 * @bottom_glyph: The glyph ID of the bottom glyph in the glyph pair
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001058 *
Nathan Willis82092d42019-04-22 15:31:24 +01001059 * Fetches the kerning-adjustment value for a glyph-pair in
Khaled Hosnyaa107e62020-12-30 23:34:17 +02001060 * the specified font, for vertical text segments.
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001061 *
Khaled Hosny35c4a152020-12-24 22:34:02 +02001062 * <note>It handles legacy kerning only (as returned by the corresponding
1063 * #hb_font_funcs_t function).</note>
1064 *
Nathan Willis82092d42019-04-22 15:31:24 +01001065 * Return value: The kerning adjustment value
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001066 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301067 * Since: 0.9.2
Behdad Esfahbod0819f3c2019-06-17 14:02:47 -07001068 * Deprecated: 2.0.0
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001069 **/
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -04001070hb_position_t
Nathan Willisec987302019-04-17 14:44:25 +01001071hb_font_get_glyph_v_kerning (hb_font_t *font,
1072 hb_codepoint_t top_glyph,
1073 hb_codepoint_t bottom_glyph)
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001074{
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001075 return font->get_glyph_v_kerning (top_glyph, bottom_glyph);
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001076}
Behdad Esfahbodfca27862019-05-11 00:37:01 -07001077#endif
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001078
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001079/**
1080 * hb_font_get_glyph_extents:
Nathan Willis82092d42019-04-22 15:31:24 +01001081 * @font: #hb_font_t to work upon
1082 * @glyph: The glyph ID to query
1083 * @extents: (out): The #hb_glyph_extents_t retrieved
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001084 *
Nathan Willis82092d42019-04-22 15:31:24 +01001085 * Fetches the #hb_glyph_extents_t data for a glyph ID
1086 * in the specified font.
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001087 *
Khaled Hosnya8e72ee2020-12-30 23:08:40 +02001088 * Return value: %true if data found, %false otherwise
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001089 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301090 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001091 **/
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001092hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +01001093hb_font_get_glyph_extents (hb_font_t *font,
1094 hb_codepoint_t glyph,
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001095 hb_glyph_extents_t *extents)
1096{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -04001097 return font->get_glyph_extents (glyph, extents);
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001098}
1099
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001100/**
1101 * hb_font_get_glyph_contour_point:
Nathan Willis82092d42019-04-22 15:31:24 +01001102 * @font: #hb_font_t to work upon
1103 * @glyph: The glyph ID to query
1104 * @point_index: The contour-point index to query
1105 * @x: (out): The X value retrieved for the contour point
1106 * @y: (out): The Y value retrieved for the contour point
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001107 *
Nathan Willis82092d42019-04-22 15:31:24 +01001108 * Fetches the (x,y) coordinates of a specified contour-point index
1109 * in the specified glyph, within the specified font.
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001110 *
Khaled Hosnya8e72ee2020-12-30 23:08:40 +02001111 * Return value: %true if data found, %false otherwise
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001112 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301113 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001114 **/
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001115hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +01001116hb_font_get_glyph_contour_point (hb_font_t *font,
1117 hb_codepoint_t glyph,
1118 unsigned int point_index,
1119 hb_position_t *x,
1120 hb_position_t *y)
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001121{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -04001122 return font->get_glyph_contour_point (glyph, point_index, x, y);
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001123}
1124
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001125/**
1126 * hb_font_get_glyph_name:
Nathan Willis82092d42019-04-22 15:31:24 +01001127 * @font: #hb_font_t to work upon
1128 * @glyph: The glyph ID to query
1129 * @name: (out) (array length=size): Name string retrieved for the glyph ID
1130 * @size: Length of the glyph-name string retrieved
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001131 *
Nathan Willis82092d42019-04-22 15:31:24 +01001132 * Fetches the glyph-name string for a glyph ID in the specified @font.
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001133 *
Khaled Hosnya8e72ee2020-12-30 23:08:40 +02001134 * Return value: %true if data found, %false otherwise
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001135 *
Sascha Brawer01c3a882015-06-01 13:22:01 +02001136 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001137 **/
Behdad Esfahbodbce09552012-05-27 11:29:21 -04001138hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +01001139hb_font_get_glyph_name (hb_font_t *font,
1140 hb_codepoint_t glyph,
1141 char *name,
1142 unsigned int size)
Behdad Esfahbodbce09552012-05-27 11:29:21 -04001143{
Behdad Esfahbod6f3a3002012-08-07 22:13:25 -04001144 return font->get_glyph_name (glyph, name, size);
Behdad Esfahbodbce09552012-05-27 11:29:21 -04001145}
1146
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001147/**
1148 * hb_font_get_glyph_from_name:
Nathan Willis82092d42019-04-22 15:31:24 +01001149 * @font: #hb_font_t to work upon
1150 * @name: (array length=len): The name string to query
1151 * @len: The length of the name queried
1152 * @glyph: (out): The glyph ID retrieved
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001153 *
Nathan Willis82092d42019-04-22 15:31:24 +01001154 * Fetches the glyph ID that corresponds to a name string in the specified @font.
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001155 *
Nathan Willis82092d42019-04-22 15:31:24 +01001156 * <note>Note: @len == -1 means the name string is null-terminated.</note>
Ebrahim Byagowi6a194b62019-08-14 18:49:57 +04301157 *
Khaled Hosnya8e72ee2020-12-30 23:08:40 +02001158 * Return value: %true if data found, %false otherwise
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001159 *
Sascha Brawer01c3a882015-06-01 13:22:01 +02001160 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001161 **/
Behdad Esfahbodbce09552012-05-27 11:29:21 -04001162hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +01001163hb_font_get_glyph_from_name (hb_font_t *font,
1164 const char *name,
1165 int len, /* -1 means nul-terminated */
Behdad Esfahbodbce09552012-05-27 11:29:21 -04001166 hb_codepoint_t *glyph)
1167{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -04001168 return font->get_glyph_from_name (name, len, glyph);
Behdad Esfahbodbce09552012-05-27 11:29:21 -04001169}
1170
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001171
1172/* A bit higher-level, and with fallback */
1173
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001174/**
Simon Cozens6f2e6de2015-10-26 16:23:22 +09001175 * hb_font_get_extents_for_direction:
Nathan Willis82092d42019-04-22 15:31:24 +01001176 * @font: #hb_font_t to work upon
1177 * @direction: The direction of the text segment
Khaled Hosny051a3c72021-01-20 22:35:34 +02001178 * @extents: (out): The #hb_font_extents_t retrieved
Simon Cozens6f2e6de2015-10-26 16:23:22 +09001179 *
Nathan Willis82092d42019-04-22 15:31:24 +01001180 * Fetches the extents for a font in a text segment of the
1181 * specified direction.
Simon Cozens6f2e6de2015-10-26 16:23:22 +09001182 *
Nathan Willis82092d42019-04-22 15:31:24 +01001183 * Calls the appropriate direction-specific variant (horizontal
1184 * or vertical) depending on the value of @direction.
Simon Cozens6f2e6de2015-10-26 16:23:22 +09001185 *
Behdad Esfahbodf11c11a2015-12-16 17:08:36 +01001186 * Since: 1.1.3
Simon Cozens6f2e6de2015-10-26 16:23:22 +09001187 **/
1188void
Nathan Willisec987302019-04-17 14:44:25 +01001189hb_font_get_extents_for_direction (hb_font_t *font,
1190 hb_direction_t direction,
Simon Cozens6f2e6de2015-10-26 16:23:22 +09001191 hb_font_extents_t *extents)
1192{
1193 return font->get_extents_for_direction (direction, extents);
1194}
1195/**
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001196 * hb_font_get_glyph_advance_for_direction:
Nathan Willis82092d42019-04-22 15:31:24 +01001197 * @font: #hb_font_t to work upon
1198 * @glyph: The glyph ID to query
1199 * @direction: The direction of the text segment
1200 * @x: (out): The horizontal advance retrieved
1201 * @y: (out): The vertical advance retrieved
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001202 *
Nathan Willis82092d42019-04-22 15:31:24 +01001203 * Fetches the advance for a glyph ID from the specified font,
1204 * in a text segment of the specified direction.
Ebrahim Byagowi6a194b62019-08-14 18:49:57 +04301205 *
Nathan Willis82092d42019-04-22 15:31:24 +01001206 * Calls the appropriate direction-specific variant (horizontal
1207 * or vertical) depending on the value of @direction.
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001208 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301209 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001210 **/
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001211void
Nathan Willisec987302019-04-17 14:44:25 +01001212hb_font_get_glyph_advance_for_direction (hb_font_t *font,
1213 hb_codepoint_t glyph,
1214 hb_direction_t direction,
1215 hb_position_t *x,
1216 hb_position_t *y)
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001217{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -04001218 return font->get_glyph_advance_for_direction (glyph, direction, x, y);
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001219}
Behdad Esfahbodb0ff79a2018-08-07 09:52:06 -07001220/**
1221 * hb_font_get_glyph_advances_for_direction:
Nathan Willis82092d42019-04-22 15:31:24 +01001222 * @font: #hb_font_t to work upon
1223 * @direction: The direction of the text segment
1224 * @count: The number of glyph IDs in the sequence queried
1225 * @first_glyph: The first glyph ID to query
1226 * @glyph_stride: The stride between successive glyph IDs
1227 * @first_advance: (out): The first advance retrieved
1228 * @advance_stride: (out): The stride between successive advances
Behdad Esfahbodb0ff79a2018-08-07 09:52:06 -07001229 *
Nathan Willis82092d42019-04-22 15:31:24 +01001230 * Fetches the advances for a sequence of glyph IDs in the specified
1231 * font, in a text segment of the specified direction.
Ebrahim Byagowi6a194b62019-08-14 18:49:57 +04301232 *
Nathan Willis82092d42019-04-22 15:31:24 +01001233 * Calls the appropriate direction-specific variant (horizontal
1234 * or vertical) depending on the value of @direction.
Behdad Esfahbodb0ff79a2018-08-07 09:52:06 -07001235 *
Behdad Esfahbode49a38b2018-08-07 09:55:42 -07001236 * Since: 1.8.6
Behdad Esfahbodb0ff79a2018-08-07 09:52:06 -07001237 **/
1238HB_EXTERN void
Nathan Willisec987302019-04-17 14:44:25 +01001239hb_font_get_glyph_advances_for_direction (hb_font_t* font,
1240 hb_direction_t direction,
1241 unsigned int count,
Behdad Esfahbodbee93e22018-10-09 08:01:49 -04001242 const hb_codepoint_t *first_glyph,
Nathan Willisec987302019-04-17 14:44:25 +01001243 unsigned glyph_stride,
1244 hb_position_t *first_advance,
1245 unsigned advance_stride)
Behdad Esfahbodb0ff79a2018-08-07 09:52:06 -07001246{
1247 font->get_glyph_advances_for_direction (direction, count, first_glyph, glyph_stride, first_advance, advance_stride);
1248}
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001249
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001250/**
1251 * hb_font_get_glyph_origin_for_direction:
Nathan Willis82092d42019-04-22 15:31:24 +01001252 * @font: #hb_font_t to work upon
1253 * @glyph: The glyph ID to query
1254 * @direction: The direction of the text segment
1255 * @x: (out): The X coordinate retrieved for the origin
1256 * @y: (out): The Y coordinate retrieved for the origin
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001257 *
Nathan Willis82092d42019-04-22 15:31:24 +01001258 * Fetches the (X,Y) coordinates of the origin for a glyph in
1259 * the specified font.
Ebrahim Byagowi6a194b62019-08-14 18:49:57 +04301260 *
Nathan Willis82092d42019-04-22 15:31:24 +01001261 * Calls the appropriate direction-specific variant (horizontal
1262 * or vertical) depending on the value of @direction.
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001263 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301264 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001265 **/
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001266void
Nathan Willisec987302019-04-17 14:44:25 +01001267hb_font_get_glyph_origin_for_direction (hb_font_t *font,
1268 hb_codepoint_t glyph,
1269 hb_direction_t direction,
1270 hb_position_t *x,
1271 hb_position_t *y)
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -04001272{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -04001273 return font->get_glyph_origin_for_direction (glyph, direction, x, y);
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -04001274}
1275
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001276/**
1277 * hb_font_add_glyph_origin_for_direction:
Nathan Willis82092d42019-04-22 15:31:24 +01001278 * @font: #hb_font_t to work upon
1279 * @glyph: The glyph ID to query
1280 * @direction: The direction of the text segment
1281 * @x: (inout): Input = The original X coordinate
1282 * Output = The X coordinate plus the X-coordinate of the origin
1283 * @y: (inout): Input = The original Y coordinate
1284 * Output = The Y coordinate plus the Y-coordinate of the origin
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001285 *
Nathan Willis82092d42019-04-22 15:31:24 +01001286 * Adds the origin coordinates to an (X,Y) point coordinate, in
1287 * the specified glyph ID in the specified font.
Ebrahim Byagowi6a194b62019-08-14 18:49:57 +04301288 *
Nathan Willis82092d42019-04-22 15:31:24 +01001289 * Calls the appropriate direction-specific variant (horizontal
1290 * or vertical) depending on the value of @direction.
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001291 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301292 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001293 **/
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -04001294void
Nathan Willisec987302019-04-17 14:44:25 +01001295hb_font_add_glyph_origin_for_direction (hb_font_t *font,
1296 hb_codepoint_t glyph,
1297 hb_direction_t direction,
1298 hb_position_t *x,
1299 hb_position_t *y)
Behdad Esfahbod8b38fae2011-05-19 13:08:00 -04001300{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -04001301 return font->add_glyph_origin_for_direction (glyph, direction, x, y);
Behdad Esfahbod8b38fae2011-05-19 13:08:00 -04001302}
1303
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001304/**
1305 * hb_font_subtract_glyph_origin_for_direction:
Nathan Willis82092d42019-04-22 15:31:24 +01001306 * @font: #hb_font_t to work upon
1307 * @glyph: The glyph ID to query
1308 * @direction: The direction of the text segment
1309 * @x: (inout): Input = The original X coordinate
1310 * Output = The X coordinate minus the X-coordinate of the origin
1311 * @y: (inout): Input = The original Y coordinate
1312 * Output = The Y coordinate minus the Y-coordinate of the origin
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001313 *
Nathan Willis82092d42019-04-22 15:31:24 +01001314 * Subtracts the origin coordinates from an (X,Y) point coordinate,
1315 * in the specified glyph ID in the specified font.
Ebrahim Byagowi6a194b62019-08-14 18:49:57 +04301316 *
Nathan Willis82092d42019-04-22 15:31:24 +01001317 * Calls the appropriate direction-specific variant (horizontal
1318 * or vertical) depending on the value of @direction.
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001319 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301320 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001321 **/
Behdad Esfahbod8b38fae2011-05-19 13:08:00 -04001322void
Nathan Willisec987302019-04-17 14:44:25 +01001323hb_font_subtract_glyph_origin_for_direction (hb_font_t *font,
1324 hb_codepoint_t glyph,
1325 hb_direction_t direction,
1326 hb_position_t *x,
1327 hb_position_t *y)
Behdad Esfahbod8b38fae2011-05-19 13:08:00 -04001328{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -04001329 return font->subtract_glyph_origin_for_direction (glyph, direction, x, y);
Behdad Esfahbod8b38fae2011-05-19 13:08:00 -04001330}
1331
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001332/**
1333 * hb_font_get_glyph_kerning_for_direction:
Nathan Willis82092d42019-04-22 15:31:24 +01001334 * @font: #hb_font_t to work upon
1335 * @first_glyph: The glyph ID of the first glyph in the glyph pair to query
1336 * @second_glyph: The glyph ID of the second glyph in the glyph pair to query
1337 * @direction: The direction of the text segment
1338 * @x: (out): The horizontal kerning-adjustment value retrieved
1339 * @y: (out): The vertical kerning-adjustment value retrieved
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001340 *
Nathan Willis82092d42019-04-22 15:31:24 +01001341 * Fetches the kerning-adjustment value for a glyph-pair in the specified font.
Ebrahim Byagowi6a194b62019-08-14 18:49:57 +04301342 *
Nathan Willis82092d42019-04-22 15:31:24 +01001343 * Calls the appropriate direction-specific variant (horizontal
1344 * or vertical) depending on the value of @direction.
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001345 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301346 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001347 **/
Behdad Esfahbod8b38fae2011-05-19 13:08:00 -04001348void
Nathan Willisec987302019-04-17 14:44:25 +01001349hb_font_get_glyph_kerning_for_direction (hb_font_t *font,
1350 hb_codepoint_t first_glyph,
1351 hb_codepoint_t second_glyph,
1352 hb_direction_t direction,
1353 hb_position_t *x,
1354 hb_position_t *y)
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001355{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -04001356 return font->get_glyph_kerning_for_direction (first_glyph, second_glyph, direction, x, y);
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001357}
1358
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001359/**
1360 * hb_font_get_glyph_extents_for_origin:
Nathan Willis82092d42019-04-22 15:31:24 +01001361 * @font: #hb_font_t to work upon
1362 * @glyph: The glyph ID to query
1363 * @direction: The direction of the text segment
1364 * @extents: (out): The #hb_glyph_extents_t retrieved
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001365 *
Nathan Willis82092d42019-04-22 15:31:24 +01001366 * Fetches the #hb_glyph_extents_t data for a glyph ID
1367 * in the specified font, with respect to the origin in
1368 * a text segment in the specified direction.
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001369 *
Nathan Willis82092d42019-04-22 15:31:24 +01001370 * Calls the appropriate direction-specific variant (horizontal
1371 * or vertical) depending on the value of @direction.
Ebrahim Byagowi6a194b62019-08-14 18:49:57 +04301372 *
Khaled Hosnya8e72ee2020-12-30 23:08:40 +02001373 * Return value: %true if data found, %false otherwise
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001374 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301375 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001376 **/
Behdad Esfahbod60fbb362011-05-19 18:46:15 -04001377hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +01001378hb_font_get_glyph_extents_for_origin (hb_font_t *font,
1379 hb_codepoint_t glyph,
1380 hb_direction_t direction,
Behdad Esfahbod60fbb362011-05-19 18:46:15 -04001381 hb_glyph_extents_t *extents)
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001382{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -04001383 return font->get_glyph_extents_for_origin (glyph, direction, extents);
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001384}
1385
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001386/**
1387 * hb_font_get_glyph_contour_point_for_origin:
Nathan Willis82092d42019-04-22 15:31:24 +01001388 * @font: #hb_font_t to work upon
1389 * @glyph: The glyph ID to query
1390 * @point_index: The contour-point index to query
1391 * @direction: The direction of the text segment
1392 * @x: (out): The X value retrieved for the contour point
1393 * @y: (out): The Y value retrieved for the contour point
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001394 *
Nathan Willis82092d42019-04-22 15:31:24 +01001395 * Fetches the (X,Y) coordinates of a specified contour-point index
1396 * in the specified glyph ID in the specified font, with respect
1397 * to the origin in a text segment in the specified direction.
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001398 *
Nathan Willis82092d42019-04-22 15:31:24 +01001399 * Calls the appropriate direction-specific variant (horizontal
1400 * or vertical) depending on the value of @direction.
Ebrahim Byagowi6a194b62019-08-14 18:49:57 +04301401 *
Khaled Hosnya8e72ee2020-12-30 23:08:40 +02001402 * Return value: %true if data found, %false otherwise
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001403 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301404 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001405 **/
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001406hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +01001407hb_font_get_glyph_contour_point_for_origin (hb_font_t *font,
1408 hb_codepoint_t glyph,
1409 unsigned int point_index,
1410 hb_direction_t direction,
1411 hb_position_t *x,
1412 hb_position_t *y)
Behdad Esfahbod744970a2011-05-16 18:15:37 -04001413{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -04001414 return font->get_glyph_contour_point_for_origin (glyph, point_index, direction, x, y);
Behdad Esfahbod2e336692009-11-05 13:55:41 -05001415}
1416
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001417/**
1418 * hb_font_glyph_to_string:
Nathan Willis82092d42019-04-22 15:31:24 +01001419 * @font: #hb_font_t to work upon
1420 * @glyph: The glyph ID to query
1421 * @s: (out) (array length=size): The string containing the glyph name
1422 * @size: Length of string @s
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001423 *
Nathan Willis82092d42019-04-22 15:31:24 +01001424 * Fetches the name of the specified glyph ID in @font and returns
1425 * it in string @s.
Ebrahim Byagowi6a194b62019-08-14 18:49:57 +04301426 *
Khaled Hosny35c4a152020-12-24 22:34:02 +02001427 * If the glyph ID has no name in @font, a string of the form `gidDDD` is
1428 * generated, with `DDD` being the glyph ID.
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001429 *
Sascha Brawer01c3a882015-06-01 13:22:01 +02001430 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001431 **/
Behdad Esfahbod6f3a3002012-08-07 22:13:25 -04001432void
Nathan Willisec987302019-04-17 14:44:25 +01001433hb_font_glyph_to_string (hb_font_t *font,
1434 hb_codepoint_t glyph,
1435 char *s,
1436 unsigned int size)
Behdad Esfahbod6f3a3002012-08-07 22:13:25 -04001437{
1438 font->glyph_to_string (glyph, s, size);
1439}
1440
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001441/**
1442 * hb_font_glyph_from_string:
Nathan Willis82092d42019-04-22 15:31:24 +01001443 * @font: #hb_font_t to work upon
1444 * @s: (array length=len) (element-type uint8_t): string to query
1445 * @len: The length of the string @s
1446 * @glyph: (out): The glyph ID corresponding to the string requested
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001447 *
Nathan Willis82092d42019-04-22 15:31:24 +01001448 * Fetches the glyph ID from @font that matches the specified string.
Khaled Hosny35c4a152020-12-24 22:34:02 +02001449 * Strings of the format `gidDDD` or `uniUUUU` are parsed automatically.
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001450 *
Nathan Willis82092d42019-04-22 15:31:24 +01001451 * <note>Note: @len == -1 means the string is null-terminated.</note>
Ebrahim Byagowi6a194b62019-08-14 18:49:57 +04301452 *
Khaled Hosnya8e72ee2020-12-30 23:08:40 +02001453 * Return value: %true if data found, %false otherwise
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001454 *
Sascha Brawer01c3a882015-06-01 13:22:01 +02001455 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001456 **/
Behdad Esfahbod6f3a3002012-08-07 22:13:25 -04001457hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +01001458hb_font_glyph_from_string (hb_font_t *font,
1459 const char *s,
Khaled Hosny35c4a152020-12-24 22:34:02 +02001460 int len,
Behdad Esfahbod6f3a3002012-08-07 22:13:25 -04001461 hb_codepoint_t *glyph)
1462{
1463 return font->glyph_from_string (s, len, glyph);
1464}
1465
Behdad Esfahbod1cebfbb2010-04-23 20:49:18 -04001466
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001467/*
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001468 * hb_font_t
1469 */
1470
Behdad Esfahbod35066722018-08-06 06:17:48 -07001471DEFINE_NULL_INSTANCE (hb_font_t) =
1472{
1473 HB_OBJECT_HEADER_STATIC,
1474
Behdad Esfahbod35066722018-08-06 06:17:48 -07001475 nullptr, /* parent */
1476 const_cast<hb_face_t *> (&_hb_Null_hb_face_t),
1477
1478 1000, /* x_scale */
1479 1000, /* y_scale */
Behdad Esfahbodb8477692019-07-05 13:52:09 -07001480 1<<16, /* x_mult */
1481 1<<16, /* y_mult */
Behdad Esfahbod35066722018-08-06 06:17:48 -07001482
1483 0, /* x_ppem */
1484 0, /* y_ppem */
1485 0, /* ptem */
1486
1487 0, /* num_coords */
1488 nullptr, /* coords */
Ebrahim Byagowiab2d3ec2019-08-14 18:42:51 +04301489 nullptr, /* design_coords */
Behdad Esfahbod35066722018-08-06 06:17:48 -07001490
Behdad Esfahbod925b7a22018-11-11 00:17:30 -05001491 const_cast<hb_font_funcs_t *> (&_hb_Null_hb_font_funcs_t),
Behdad Esfahbod35066722018-08-06 06:17:48 -07001492
Behdad Esfahbodce5da0f2018-11-16 02:29:13 -05001493 /* Zero for the rest is fine. */
Behdad Esfahbod35066722018-08-06 06:17:48 -07001494};
1495
1496
Behdad Esfahbod07899432018-10-09 15:39:51 -04001497static hb_font_t *
1498_hb_font_create (hb_face_t *face)
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001499{
1500 hb_font_t *font;
1501
Behdad Esfahbod72657e42011-05-02 20:46:32 -04001502 if (unlikely (!face))
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -04001503 face = hb_face_get_empty ();
Behdad Esfahbod47e71d92011-04-27 16:38:03 -04001504 if (!(font = hb_object_create<hb_font_t> ()))
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -04001505 return hb_font_get_empty ();
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001506
Behdad Esfahbod7fc5a302011-05-12 17:48:20 -04001507 hb_face_make_immutable (face);
Behdad Esfahbodda29b432015-11-04 20:22:44 -08001508 font->parent = hb_font_get_empty ();
Behdad Esfahbod72657e42011-05-02 20:46:32 -04001509 font->face = hb_face_reference (face);
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -04001510 font->klass = hb_font_funcs_get_empty ();
Behdad Esfahbodce5da0f2018-11-16 02:29:13 -05001511 font->data.init0 (font);
Behdad Esfahbod88da7bb2015-10-02 14:38:20 +01001512 font->x_scale = font->y_scale = hb_face_get_upem (face);
Behdad Esfahbodb8477692019-07-05 13:52:09 -07001513 font->x_mult = font->y_mult = 1 << 16;
Behdad Esfahbod88da7bb2015-10-02 14:38:20 +01001514
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001515 return font;
1516}
1517
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001518/**
Behdad Esfahbod07899432018-10-09 15:39:51 -04001519 * hb_font_create: (Xconstructor)
1520 * @face: a face.
1521 *
Nathan Willis82092d42019-04-22 15:31:24 +01001522 * Constructs a new font object from the specified face.
Behdad Esfahbod07899432018-10-09 15:39:51 -04001523 *
Nathan Willis82092d42019-04-22 15:31:24 +01001524 * Return value: (transfer full): The new font object
Behdad Esfahbod07899432018-10-09 15:39:51 -04001525 *
1526 * Since: 0.9.2
1527 **/
1528hb_font_t *
1529hb_font_create (hb_face_t *face)
1530{
1531 hb_font_t *font = _hb_font_create (face);
1532
Behdad Esfahbod227d85e2019-05-10 23:15:58 -07001533#ifndef HB_NO_OT_FONT
Behdad Esfahbod07899432018-10-09 15:39:51 -04001534 /* Install our in-house, very lightweight, funcs. */
1535 hb_ot_font_set_funcs (font);
Behdad Esfahbod4d316622019-04-10 15:40:03 -04001536#endif
Behdad Esfahbod07899432018-10-09 15:39:51 -04001537
1538 return font;
1539}
1540
Ebrahim Byagowiab2d3ec2019-08-14 18:42:51 +04301541static void
1542_hb_font_adopt_var_coords (hb_font_t *font,
1543 int *coords, /* 2.14 normalized */
1544 float *design_coords,
1545 unsigned int coords_length)
1546{
Behdad Esfahbod2337f0d2021-07-08 10:58:50 -06001547 hb_free (font->coords);
1548 hb_free (font->design_coords);
Ebrahim Byagowiab2d3ec2019-08-14 18:42:51 +04301549
1550 font->coords = coords;
1551 font->design_coords = design_coords;
1552 font->num_coords = coords_length;
1553}
1554
Behdad Esfahbod07899432018-10-09 15:39:51 -04001555/**
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001556 * hb_font_create_sub_font:
Nathan Willis82092d42019-04-22 15:31:24 +01001557 * @parent: The parent font object
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001558 *
Nathan Willis82092d42019-04-22 15:31:24 +01001559 * Constructs a sub-font font object from the specified @parent font,
1560 * replicating the parent's properties.
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001561 *
Nathan Willis82092d42019-04-22 15:31:24 +01001562 * Return value: (transfer full): The new sub-font font object
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001563 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301564 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001565 **/
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001566hb_font_t *
Behdad Esfahboddefc45b2011-05-10 20:02:49 -04001567hb_font_create_sub_font (hb_font_t *parent)
1568{
1569 if (unlikely (!parent))
Behdad Esfahbodeb0bf3a2014-08-06 15:36:41 -04001570 parent = hb_font_get_empty ();
Behdad Esfahboddefc45b2011-05-10 20:02:49 -04001571
Behdad Esfahbod07899432018-10-09 15:39:51 -04001572 hb_font_t *font = _hb_font_create (parent->face);
Behdad Esfahboddefc45b2011-05-10 20:02:49 -04001573
Behdad Esfahbod93ef20a2018-11-03 15:03:06 -04001574 if (unlikely (hb_object_is_immutable (font)))
Behdad Esfahboddefc45b2011-05-10 20:02:49 -04001575 return font;
1576
Behdad Esfahboddefc45b2011-05-10 20:02:49 -04001577 font->parent = hb_font_reference (parent);
1578
1579 font->x_scale = parent->x_scale;
1580 font->y_scale = parent->y_scale;
Behdad Esfahbodaaa85932019-08-20 13:06:10 -07001581 font->mults_changed ();
Behdad Esfahboddefc45b2011-05-10 20:02:49 -04001582 font->x_ppem = parent->x_ppem;
1583 font->y_ppem = parent->y_ppem;
Behdad Esfahbodb57f18d2017-10-11 11:47:47 +02001584 font->ptem = parent->ptem;
Behdad Esfahboddefc45b2011-05-10 20:02:49 -04001585
Ebrahim Byagowiab2d3ec2019-08-14 18:42:51 +04301586 unsigned int num_coords = parent->num_coords;
1587 if (num_coords)
Behdad Esfahbod3f9370d2017-10-11 11:34:53 +02001588 {
Behdad Esfahbod2337f0d2021-07-08 10:58:50 -06001589 int *coords = (int *) hb_calloc (num_coords, sizeof (parent->coords[0]));
1590 float *design_coords = (float *) hb_calloc (num_coords, sizeof (parent->design_coords[0]));
Ebrahim Byagowiab2d3ec2019-08-14 18:42:51 +04301591 if (likely (coords && design_coords))
1592 {
1593 memcpy (coords, parent->coords, num_coords * sizeof (parent->coords[0]));
1594 memcpy (design_coords, parent->design_coords, num_coords * sizeof (parent->design_coords[0]));
1595 _hb_font_adopt_var_coords (font, coords, design_coords, num_coords);
1596 }
Behdad Esfahbod3f9370d2017-10-11 11:34:53 +02001597 else
Ebrahim Byagowiab2d3ec2019-08-14 18:42:51 +04301598 {
Behdad Esfahbod2337f0d2021-07-08 10:58:50 -06001599 hb_free (coords);
1600 hb_free (design_coords);
Ebrahim Byagowiab2d3ec2019-08-14 18:42:51 +04301601 }
Behdad Esfahbod3f9370d2017-10-11 11:34:53 +02001602 }
Behdad Esfahbodca286702016-03-01 19:29:36 +09001603
Behdad Esfahboddefc45b2011-05-10 20:02:49 -04001604 return font;
1605}
1606
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001607/**
1608 * hb_font_get_empty:
1609 *
Nathan Willis82092d42019-04-22 15:31:24 +01001610 * Fetches the empty font object.
Ebrahim Byagowi6a194b62019-08-14 18:49:57 +04301611 *
Nathan Willis82092d42019-04-22 15:31:24 +01001612 * Return value: (transfer full): The empty font object
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001613 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301614 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001615 **/
Behdad Esfahboddefc45b2011-05-10 20:02:49 -04001616hb_font_t *
Ebrahim Byagowie4120082018-12-17 21:31:01 +03301617hb_font_get_empty ()
Behdad Esfahbod80a68332011-05-11 18:14:44 -04001618{
Ebrahim Byagowi2dda6dd2020-04-20 14:12:45 +04301619 return const_cast<hb_font_t *> (&Null (hb_font_t));
Behdad Esfahbod80a68332011-05-11 18:14:44 -04001620}
1621
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001622/**
1623 * hb_font_reference: (skip)
Nathan Willis82092d42019-04-22 15:31:24 +01001624 * @font: #hb_font_t to work upon
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001625 *
Nathan Willis82092d42019-04-22 15:31:24 +01001626 * Increases the reference count on the given font object.
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001627 *
Nathan Willis82092d42019-04-22 15:31:24 +01001628 * Return value: (transfer full): The @font object
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001629 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301630 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001631 **/
Behdad Esfahbod80a68332011-05-11 18:14:44 -04001632hb_font_t *
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001633hb_font_reference (hb_font_t *font)
1634{
Behdad Esfahbod47e71d92011-04-27 16:38:03 -04001635 return hb_object_reference (font);
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001636}
1637
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001638/**
1639 * hb_font_destroy: (skip)
Nathan Willis82092d42019-04-22 15:31:24 +01001640 * @font: #hb_font_t to work upon
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001641 *
Nathan Willis82092d42019-04-22 15:31:24 +01001642 * Decreases the reference count on the given font object. When the
1643 * reference count reaches zero, the font is destroyed,
1644 * freeing all memory.
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001645 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301646 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001647 **/
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001648void
1649hb_font_destroy (hb_font_t *font)
1650{
Behdad Esfahbod47e71d92011-04-27 16:38:03 -04001651 if (!hb_object_destroy (font)) return;
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001652
Behdad Esfahbodce5da0f2018-11-16 02:29:13 -05001653 font->data.fini ();
Behdad Esfahbod027857d2012-07-26 17:34:25 -04001654
1655 if (font->destroy)
1656 font->destroy (font->user_data);
1657
Behdad Esfahboddefc45b2011-05-10 20:02:49 -04001658 hb_font_destroy (font->parent);
Behdad Esfahbod72657e42011-05-02 20:46:32 -04001659 hb_face_destroy (font->face);
Behdad Esfahbod5c441882009-08-10 20:05:16 -04001660 hb_font_funcs_destroy (font->klass);
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001661
Behdad Esfahbod2337f0d2021-07-08 10:58:50 -06001662 hb_free (font->coords);
1663 hb_free (font->design_coords);
Behdad Esfahbodca286702016-03-01 19:29:36 +09001664
Behdad Esfahbod2337f0d2021-07-08 10:58:50 -06001665 hb_free (font);
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001666}
1667
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001668/**
1669 * hb_font_set_user_data: (skip)
Nathan Willis82092d42019-04-22 15:31:24 +01001670 * @font: #hb_font_t to work upon
1671 * @key: The user-data key
1672 * @data: A pointer to the user data
Khaled Hosny99364902020-12-31 00:19:29 +02001673 * @destroy: (nullable): A callback to call when @data is not needed anymore
Nathan Willis82092d42019-04-22 15:31:24 +01001674 * @replace: Whether to replace an existing data with the same key
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001675 *
Nathan Willis82092d42019-04-22 15:31:24 +01001676 * Attaches a user-data key/data pair to the specified font object.
Ebrahim Byagowi6a194b62019-08-14 18:49:57 +04301677 *
Khaled Hosnyaa107e62020-12-30 23:34:17 +02001678 * Return value: %true if success, %false otherwise
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001679 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301680 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001681 **/
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -04001682hb_bool_t
1683hb_font_set_user_data (hb_font_t *font,
1684 hb_user_data_key_t *key,
1685 void * data,
Nathan Willis82092d42019-04-22 15:31:24 +01001686 hb_destroy_func_t destroy /* May be NULL. */,
Behdad Esfahbod33ccc772011-08-09 00:43:24 +02001687 hb_bool_t replace)
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -04001688{
Behdad Esfahbod33ccc772011-08-09 00:43:24 +02001689 return hb_object_set_user_data (font, key, data, destroy, replace);
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -04001690}
1691
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001692/**
1693 * hb_font_get_user_data: (skip)
Nathan Willis82092d42019-04-22 15:31:24 +01001694 * @font: #hb_font_t to work upon
1695 * @key: The user-data key to query
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001696 *
Nathan Willis82092d42019-04-22 15:31:24 +01001697 * Fetches the user-data object associated with the specified key,
1698 * attached to the specified font object.
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001699 *
Nathan Willis82092d42019-04-22 15:31:24 +01001700 * Return value: (transfer none): Pointer to the user data
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001701 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301702 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001703 **/
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -04001704void *
1705hb_font_get_user_data (hb_font_t *font,
1706 hb_user_data_key_t *key)
1707{
1708 return hb_object_get_user_data (font, key);
1709}
1710
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001711/**
1712 * hb_font_make_immutable:
Nathan Willis82092d42019-04-22 15:31:24 +01001713 * @font: #hb_font_t to work upon
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001714 *
Nathan Willis82092d42019-04-22 15:31:24 +01001715 * Makes @font immutable.
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001716 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301717 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001718 **/
Behdad Esfahbod74f1d892011-05-10 19:39:32 -04001719void
1720hb_font_make_immutable (hb_font_t *font)
1721{
Behdad Esfahbod5570c872018-11-03 14:51:38 -04001722 if (hb_object_is_immutable (font))
Behdad Esfahbod90a0f9f2018-09-26 15:03:07 -04001723 return;
Behdad Esfahbod74f1d892011-05-10 19:39:32 -04001724
Behdad Esfahbod1866e172015-10-02 14:21:29 +01001725 if (font->parent)
1726 hb_font_make_immutable (font->parent);
1727
Behdad Esfahbod5570c872018-11-03 14:51:38 -04001728 hb_object_make_immutable (font);
Behdad Esfahbod74f1d892011-05-10 19:39:32 -04001729}
1730
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001731/**
1732 * hb_font_is_immutable:
Nathan Willis82092d42019-04-22 15:31:24 +01001733 * @font: #hb_font_t to work upon
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001734 *
Nathan Willis82092d42019-04-22 15:31:24 +01001735 * Tests whether a font object is immutable.
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001736 *
Khaled Hosnya8e72ee2020-12-30 23:08:40 +02001737 * Return value: %true if @font is immutable, %false otherwise
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001738 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301739 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001740 **/
Behdad Esfahbod74f1d892011-05-10 19:39:32 -04001741hb_bool_t
1742hb_font_is_immutable (hb_font_t *font)
1743{
Behdad Esfahbod5570c872018-11-03 14:51:38 -04001744 return hb_object_is_immutable (font);
Behdad Esfahbod74f1d892011-05-10 19:39:32 -04001745}
1746
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001747/**
Behdad Esfahbod3e905e32015-10-08 12:51:02 -04001748 * hb_font_set_parent:
Nathan Willis82092d42019-04-22 15:31:24 +01001749 * @font: #hb_font_t to work upon
1750 * @parent: The parent font object to assign
Behdad Esfahbod3e905e32015-10-08 12:51:02 -04001751 *
Nathan Willis82092d42019-04-22 15:31:24 +01001752 * Sets the parent font of @font.
Behdad Esfahbod3e905e32015-10-08 12:51:02 -04001753 *
1754 * Since: 1.0.5
1755 **/
1756void
1757hb_font_set_parent (hb_font_t *font,
1758 hb_font_t *parent)
1759{
Behdad Esfahbod5570c872018-11-03 14:51:38 -04001760 if (hb_object_is_immutable (font))
Behdad Esfahbod3e905e32015-10-08 12:51:02 -04001761 return;
1762
1763 if (!parent)
1764 parent = hb_font_get_empty ();
1765
1766 hb_font_t *old = font->parent;
1767
1768 font->parent = hb_font_reference (parent);
1769
1770 hb_font_destroy (old);
1771}
1772
1773/**
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001774 * hb_font_get_parent:
Nathan Willis82092d42019-04-22 15:31:24 +01001775 * @font: #hb_font_t to work upon
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001776 *
Nathan Willis82092d42019-04-22 15:31:24 +01001777 * Fetches the parent font of @font.
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001778 *
Nathan Willis82092d42019-04-22 15:31:24 +01001779 * Return value: (transfer none): The parent font object
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001780 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301781 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001782 **/
Behdad Esfahboddefc45b2011-05-10 20:02:49 -04001783hb_font_t *
1784hb_font_get_parent (hb_font_t *font)
1785{
1786 return font->parent;
1787}
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -04001788
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001789/**
Behdad Esfahbod95808ba2017-02-03 10:39:40 -08001790 * hb_font_set_face:
Nathan Willis82092d42019-04-22 15:31:24 +01001791 * @font: #hb_font_t to work upon
1792 * @face: The #hb_face_t to assign
Behdad Esfahbod95808ba2017-02-03 10:39:40 -08001793 *
Nathan Willis82092d42019-04-22 15:31:24 +01001794 * Sets @face as the font-face value of @font.
Behdad Esfahbod95808ba2017-02-03 10:39:40 -08001795 *
1796 * Since: 1.4.3
1797 **/
1798void
1799hb_font_set_face (hb_font_t *font,
1800 hb_face_t *face)
1801{
Behdad Esfahbod5570c872018-11-03 14:51:38 -04001802 if (hb_object_is_immutable (font))
Behdad Esfahbod95808ba2017-02-03 10:39:40 -08001803 return;
1804
1805 if (unlikely (!face))
1806 face = hb_face_get_empty ();
1807
Behdad Esfahbod95808ba2017-02-03 10:39:40 -08001808 hb_face_t *old = font->face;
1809
Behdad Esfahboddf6edcd2019-07-05 13:45:15 -07001810 hb_face_make_immutable (face);
Behdad Esfahbod95808ba2017-02-03 10:39:40 -08001811 font->face = hb_face_reference (face);
Behdad Esfahbodb8477692019-07-05 13:52:09 -07001812 font->mults_changed ();
Behdad Esfahbod95808ba2017-02-03 10:39:40 -08001813
1814 hb_face_destroy (old);
1815}
1816
1817/**
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001818 * hb_font_get_face:
Nathan Willis82092d42019-04-22 15:31:24 +01001819 * @font: #hb_font_t to work upon
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001820 *
Nathan Willis82092d42019-04-22 15:31:24 +01001821 * Fetches the face associated with the specified font object.
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001822 *
Nathan Willis82092d42019-04-22 15:31:24 +01001823 * Return value: (transfer none): The #hb_face_t value
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001824 *
Sascha Brawer01c3a882015-06-01 13:22:01 +02001825 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001826 **/
Behdad Esfahbod72657e42011-05-02 20:46:32 -04001827hb_face_t *
1828hb_font_get_face (hb_font_t *font)
1829{
1830 return font->face;
1831}
1832
1833
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001834/**
1835 * hb_font_set_funcs:
Nathan Willis82092d42019-04-22 15:31:24 +01001836 * @font: #hb_font_t to work upon
Khaled Hosnya44dd332021-01-01 01:36:57 +02001837 * @klass: (closure font_data) (destroy destroy) (scope notified): The font-functions structure.
Nathan Willis82092d42019-04-22 15:31:24 +01001838 * @font_data: Data to attach to @font
Khaled Hosny99364902020-12-31 00:19:29 +02001839 * @destroy: (nullable): The function to call when @font_data is not needed anymore
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001840 *
Nathan Willis82092d42019-04-22 15:31:24 +01001841 * Replaces the font-functions structure attached to a font, updating
1842 * the font's user-data with @font-data and the @destroy callback.
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001843 *
Sascha Brawer01c3a882015-06-01 13:22:01 +02001844 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001845 **/
Behdad Esfahbod5c441882009-08-10 20:05:16 -04001846void
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -05001847hb_font_set_funcs (hb_font_t *font,
1848 hb_font_funcs_t *klass,
Behdad Esfahbod70303cf2013-09-06 17:35:57 -04001849 void *font_data,
Nathan Willis82092d42019-04-22 15:31:24 +01001850 hb_destroy_func_t destroy /* May be NULL. */)
Behdad Esfahbod0ead4812009-08-02 17:41:36 -04001851{
Behdad Esfahbod5570c872018-11-03 14:51:38 -04001852 if (hb_object_is_immutable (font))
1853 {
Behdad Esfahbod0cd33592011-09-21 16:49:33 -04001854 if (destroy)
Behdad Esfahbod70303cf2013-09-06 17:35:57 -04001855 destroy (font_data);
Behdad Esfahbod5c441882009-08-10 20:05:16 -04001856 return;
Behdad Esfahbod0cd33592011-09-21 16:49:33 -04001857 }
Behdad Esfahbod0ead4812009-08-02 17:41:36 -04001858
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -05001859 if (font->destroy)
1860 font->destroy (font->user_data);
1861
Behdad Esfahbod0465e692009-12-20 16:25:18 +01001862 if (!klass)
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -04001863 klass = hb_font_funcs_get_empty ();
Behdad Esfahbod0465e692009-12-20 16:25:18 +01001864
Behdad Esfahbod5c441882009-08-10 20:05:16 -04001865 hb_font_funcs_reference (klass);
1866 hb_font_funcs_destroy (font->klass);
1867 font->klass = klass;
Behdad Esfahbod70303cf2013-09-06 17:35:57 -04001868 font->user_data = font_data;
Behdad Esfahbod56681892011-04-20 03:03:32 -04001869 font->destroy = destroy;
Behdad Esfahbod0ead4812009-08-02 17:41:36 -04001870}
1871
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001872/**
1873 * hb_font_set_funcs_data:
Nathan Willis82092d42019-04-22 15:31:24 +01001874 * @font: #hb_font_t to work upon
1875 * @font_data: (destroy destroy) (scope notified): Data to attach to @font
Khaled Hosny99364902020-12-31 00:19:29 +02001876 * @destroy: (nullable): The function to call when @font_data is not needed anymore
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001877 *
Nathan Willis82092d42019-04-22 15:31:24 +01001878 * Replaces the user data attached to a font, updating the font's
1879 * @destroy callback.
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001880 *
Sascha Brawer01c3a882015-06-01 13:22:01 +02001881 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001882 **/
Behdad Esfahbodb9415e72011-08-17 19:21:44 +02001883void
1884hb_font_set_funcs_data (hb_font_t *font,
Nathan Willis82092d42019-04-22 15:31:24 +01001885 void *font_data,
1886 hb_destroy_func_t destroy /* May be NULL. */)
Behdad Esfahbodb9415e72011-08-17 19:21:44 +02001887{
Behdad Esfahbod0cd33592011-09-21 16:49:33 -04001888 /* Destroy user_data? */
Behdad Esfahbod5570c872018-11-03 14:51:38 -04001889 if (hb_object_is_immutable (font))
1890 {
Behdad Esfahbod0cd33592011-09-21 16:49:33 -04001891 if (destroy)
Behdad Esfahbod70303cf2013-09-06 17:35:57 -04001892 destroy (font_data);
Behdad Esfahbodb9415e72011-08-17 19:21:44 +02001893 return;
Behdad Esfahbod0cd33592011-09-21 16:49:33 -04001894 }
Behdad Esfahbodb9415e72011-08-17 19:21:44 +02001895
1896 if (font->destroy)
1897 font->destroy (font->user_data);
1898
Behdad Esfahbod70303cf2013-09-06 17:35:57 -04001899 font->user_data = font_data;
Behdad Esfahbodb9415e72011-08-17 19:21:44 +02001900 font->destroy = destroy;
1901}
1902
Behdad Esfahbod19c0eab2010-10-04 16:45:21 -04001903
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001904/**
1905 * hb_font_set_scale:
Nathan Willis82092d42019-04-22 15:31:24 +01001906 * @font: #hb_font_t to work upon
1907 * @x_scale: Horizontal scale value to assign
1908 * @y_scale: Vertical scale value to assign
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001909 *
Nathan Willis82092d42019-04-22 15:31:24 +01001910 * Sets the horizontal and vertical scale of a font.
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001911 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301912 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001913 **/
Behdad Esfahbod19c0eab2010-10-04 16:45:21 -04001914void
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001915hb_font_set_scale (hb_font_t *font,
Nathan Willisec987302019-04-17 14:44:25 +01001916 int x_scale,
1917 int y_scale)
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001918{
Behdad Esfahbod5570c872018-11-03 14:51:38 -04001919 if (hb_object_is_immutable (font))
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001920 return;
1921
1922 font->x_scale = x_scale;
1923 font->y_scale = y_scale;
Behdad Esfahbodb8477692019-07-05 13:52:09 -07001924 font->mults_changed ();
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001925}
1926
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001927/**
1928 * hb_font_get_scale:
Nathan Willis82092d42019-04-22 15:31:24 +01001929 * @font: #hb_font_t to work upon
1930 * @x_scale: (out): Horizontal scale value
1931 * @y_scale: (out): Vertical scale value
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001932 *
Nathan Willis82092d42019-04-22 15:31:24 +01001933 * Fetches the horizontal and vertical scale of a font.
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001934 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301935 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001936 **/
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001937void
Behdad Esfahbod19c0eab2010-10-04 16:45:21 -04001938hb_font_get_scale (hb_font_t *font,
Nathan Willisec987302019-04-17 14:44:25 +01001939 int *x_scale,
1940 int *y_scale)
Behdad Esfahbod19c0eab2010-10-04 16:45:21 -04001941{
1942 if (x_scale) *x_scale = font->x_scale;
1943 if (y_scale) *y_scale = font->y_scale;
1944}
1945
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001946/**
1947 * hb_font_set_ppem:
Nathan Willis82092d42019-04-22 15:31:24 +01001948 * @font: #hb_font_t to work upon
1949 * @x_ppem: Horizontal ppem value to assign
1950 * @y_ppem: Vertical ppem value to assign
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001951 *
Khaled Hosny35c4a152020-12-24 22:34:02 +02001952 * Sets the horizontal and vertical pixels-per-em (ppem) of a font.
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001953 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301954 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001955 **/
Behdad Esfahbod19c0eab2010-10-04 16:45:21 -04001956void
Nathan Willisec987302019-04-17 14:44:25 +01001957hb_font_set_ppem (hb_font_t *font,
1958 unsigned int x_ppem,
1959 unsigned int y_ppem)
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001960{
Behdad Esfahbod5570c872018-11-03 14:51:38 -04001961 if (hb_object_is_immutable (font))
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001962 return;
1963
1964 font->x_ppem = x_ppem;
1965 font->y_ppem = y_ppem;
1966}
1967
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001968/**
1969 * hb_font_get_ppem:
Nathan Willis82092d42019-04-22 15:31:24 +01001970 * @font: #hb_font_t to work upon
1971 * @x_ppem: (out): Horizontal ppem value
1972 * @y_ppem: (out): Vertical ppem value
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001973 *
Nathan Willis82092d42019-04-22 15:31:24 +01001974 * Fetches the horizontal and vertical points-per-em (ppem) of a font.
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001975 *
Behdad Esfahbod5d74ff02015-09-03 14:55:59 +04301976 * Since: 0.9.2
Behdad Esfahbod288f2892013-09-06 15:40:22 -04001977 **/
Behdad Esfahbod19c0eab2010-10-04 16:45:21 -04001978void
Nathan Willisec987302019-04-17 14:44:25 +01001979hb_font_get_ppem (hb_font_t *font,
Behdad Esfahbod19c0eab2010-10-04 16:45:21 -04001980 unsigned int *x_ppem,
1981 unsigned int *y_ppem)
1982{
1983 if (x_ppem) *x_ppem = font->x_ppem;
1984 if (y_ppem) *y_ppem = font->y_ppem;
1985}
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09001986
Behdad Esfahbodb57f18d2017-10-11 11:47:47 +02001987/**
1988 * hb_font_set_ptem:
Nathan Willis82092d42019-04-22 15:31:24 +01001989 * @font: #hb_font_t to work upon
Behdad Esfahbod55bae682018-09-24 10:43:06 -04001990 * @ptem: font size in points.
Behdad Esfahbodb57f18d2017-10-11 11:47:47 +02001991 *
Nathan Willis82092d42019-04-22 15:31:24 +01001992 * Sets the "point size" of a font. Set to zero to unset.
1993 * Used in CoreText to implement optical sizing.
Behdad Esfahbod55bae682018-09-24 10:43:06 -04001994 *
Nathan Willis82092d42019-04-22 15:31:24 +01001995 * <note>Note: There are 72 points in an inch.</note>
Behdad Esfahbodb57f18d2017-10-11 11:47:47 +02001996 *
1997 * Since: 1.6.0
1998 **/
1999void
Nathan Willisec987302019-04-17 14:44:25 +01002000hb_font_set_ptem (hb_font_t *font,
2001 float ptem)
Behdad Esfahbodb57f18d2017-10-11 11:47:47 +02002002{
Behdad Esfahbod5570c872018-11-03 14:51:38 -04002003 if (hb_object_is_immutable (font))
Behdad Esfahbodb57f18d2017-10-11 11:47:47 +02002004 return;
2005
Behdad Esfahbodb57f18d2017-10-11 11:47:47 +02002006 font->ptem = ptem;
2007}
2008
2009/**
2010 * hb_font_get_ptem:
Nathan Willis82092d42019-04-22 15:31:24 +01002011 * @font: #hb_font_t to work upon
Behdad Esfahbodb57f18d2017-10-11 11:47:47 +02002012 *
Nathan Willis82092d42019-04-22 15:31:24 +01002013 * Fetches the "point size" of a font. Used in CoreText to
2014 * implement optical sizing.
Behdad Esfahbodb57f18d2017-10-11 11:47:47 +02002015 *
Nathan Willis82092d42019-04-22 15:31:24 +01002016 * Return value: Point size. A value of zero means "not set."
Behdad Esfahbodb57f18d2017-10-11 11:47:47 +02002017 *
2018 * Since: 0.9.2
2019 **/
2020float
2021hb_font_get_ptem (hb_font_t *font)
2022{
2023 return font->ptem;
2024}
2025
Ebrahim Byagowibc27f862019-08-14 22:37:00 +04302026#ifndef HB_NO_VAR
Behdad Esfahbod8b2a5802017-01-21 15:05:00 -08002027/*
2028 * Variations
2029 */
2030
Behdad Esfahbodd2f249e2017-01-22 17:42:33 -08002031/**
2032 * hb_font_set_variations:
Nathan Willis82092d42019-04-22 15:31:24 +01002033 * @font: #hb_font_t to work upon
2034 * @variations: (array length=variations_length): Array of variation settings to apply
2035 * @variations_length: Number of variations to apply
2036 *
2037 * Applies a list of font-variation settings to a font.
Behdad Esfahbodd2f249e2017-01-22 17:42:33 -08002038 *
2039 * Since: 1.4.2
2040 */
Behdad Esfahbod8b2a5802017-01-21 15:05:00 -08002041void
Nathan Willisec987302019-04-17 14:44:25 +01002042hb_font_set_variations (hb_font_t *font,
Behdad Esfahbodbb1e1922017-01-21 17:41:37 -08002043 const hb_variation_t *variations,
Nathan Willisec987302019-04-17 14:44:25 +01002044 unsigned int variations_length)
Behdad Esfahbod24911342017-01-21 15:21:50 -08002045{
Behdad Esfahbod5570c872018-11-03 14:51:38 -04002046 if (hb_object_is_immutable (font))
Behdad Esfahbod24911342017-01-21 15:21:50 -08002047 return;
2048
Behdad Esfahbodbb1e1922017-01-21 17:41:37 -08002049 if (!variations_length)
Behdad Esfahbod24911342017-01-21 15:21:50 -08002050 {
Behdad Esfahboddbdbfe32017-10-15 12:11:08 +02002051 hb_font_set_var_coords_normalized (font, nullptr, 0);
Behdad Esfahbod24911342017-01-21 15:21:50 -08002052 return;
2053 }
2054
Behdad Esfahboda9a607d2021-07-22 16:49:56 -07002055 const OT::fvar &fvar = *font->face->table.fvar;
2056 auto axes = fvar.get_axes ();
2057 const unsigned coords_length = axes.length;
Behdad Esfahbod24911342017-01-21 15:21:50 -08002058
Behdad Esfahbod2337f0d2021-07-08 10:58:50 -06002059 int *normalized = coords_length ? (int *) hb_calloc (coords_length, sizeof (int)) : nullptr;
2060 float *design_coords = coords_length ? (float *) hb_calloc (coords_length, sizeof (float)) : nullptr;
Ebrahim Byagowiab2d3ec2019-08-14 18:42:51 +04302061
2062 if (unlikely (coords_length && !(normalized && design_coords)))
2063 {
Behdad Esfahbod2337f0d2021-07-08 10:58:50 -06002064 hb_free (normalized);
2065 hb_free (design_coords);
Behdad Esfahbod64fe92b2017-01-21 15:36:35 -08002066 return;
Ebrahim Byagowiab2d3ec2019-08-14 18:42:51 +04302067 }
2068
2069 for (unsigned int i = 0; i < variations_length; i++)
2070 {
Behdad Esfahboda9a607d2021-07-22 16:49:56 -07002071 const auto tag = variations[i].tag;
2072 const auto v = variations[i].value;
2073 for (unsigned axis_index = 0; axis_index < coords_length; axis_index++)
2074 if (axes[axis_index].axisTag == tag)
2075 {
2076 design_coords[axis_index] = v;
2077 normalized[axis_index] = fvar.normalize_axis_value (axis_index, v);
2078 }
Ebrahim Byagowiab2d3ec2019-08-14 18:42:51 +04302079 }
Ebrahim Byagowi0b76e812019-08-20 15:15:22 +04302080 font->face->table.avar->map_coords (normalized, coords_length);
Behdad Esfahbod24911342017-01-21 15:21:50 -08002081
Ebrahim Byagowiab2d3ec2019-08-14 18:42:51 +04302082 _hb_font_adopt_var_coords (font, normalized, design_coords, coords_length);
Behdad Esfahbod24911342017-01-21 15:21:50 -08002083}
Ebrahim Byagowi40a4b6d2019-07-27 13:33:46 +04302084
Behdad Esfahbodd2f249e2017-01-22 17:42:33 -08002085/**
2086 * hb_font_set_var_coords_design:
Nathan Willis82092d42019-04-22 15:31:24 +01002087 * @font: #hb_font_t to work upon
2088 * @coords: (array length=coords_length): Array of variation coordinates to apply
2089 * @coords_length: Number of coordinates to apply
2090 *
2091 * Applies a list of variation coordinates (in design-space units)
2092 * to a font.
Behdad Esfahbodd2f249e2017-01-22 17:42:33 -08002093 *
2094 * Since: 1.4.2
2095 */
Behdad Esfahbod24911342017-01-21 15:21:50 -08002096void
Nathan Willisec987302019-04-17 14:44:25 +01002097hb_font_set_var_coords_design (hb_font_t *font,
2098 const float *coords,
2099 unsigned int coords_length)
Behdad Esfahbod8b2a5802017-01-21 15:05:00 -08002100{
Behdad Esfahbod5570c872018-11-03 14:51:38 -04002101 if (hb_object_is_immutable (font))
Behdad Esfahbod24911342017-01-21 15:21:50 -08002102 return;
2103
Behdad Esfahbod2337f0d2021-07-08 10:58:50 -06002104 int *normalized = coords_length ? (int *) hb_calloc (coords_length, sizeof (int)) : nullptr;
2105 float *design_coords = coords_length ? (float *) hb_calloc (coords_length, sizeof (float)) : nullptr;
Ebrahim Byagowiab2d3ec2019-08-14 18:42:51 +04302106
2107 if (unlikely (coords_length && !(normalized && design_coords)))
2108 {
Behdad Esfahbod2337f0d2021-07-08 10:58:50 -06002109 hb_free (normalized);
2110 hb_free (design_coords);
Behdad Esfahbod64fe92b2017-01-21 15:36:35 -08002111 return;
Ebrahim Byagowiab2d3ec2019-08-14 18:42:51 +04302112 }
2113
2114 if (coords_length)
Ebrahim Byagowi40166eb2020-02-08 13:17:06 +03302115 memcpy (design_coords, coords, coords_length * sizeof (font->design_coords[0]));
Behdad Esfahbod8b2a5802017-01-21 15:05:00 -08002116
Behdad Esfahbod5ec96d32017-01-22 18:52:00 -08002117 hb_ot_var_normalize_coords (font->face, coords_length, coords, normalized);
Ebrahim Byagowiab2d3ec2019-08-14 18:42:51 +04302118 _hb_font_adopt_var_coords (font, normalized, design_coords, coords_length);
Behdad Esfahbod8b2a5802017-01-21 15:05:00 -08002119}
Ebrahim Byagowi40a4b6d2019-07-27 13:33:46 +04302120
2121/**
2122 * hb_font_set_var_named_instance:
2123 * @font: a font.
2124 * @instance_index: named instance index.
2125 *
2126 * Sets design coords of a font from a named instance index.
2127 *
Behdad Esfahbod64611432019-08-13 22:20:54 -07002128 * Since: 2.6.0
Ebrahim Byagowi40a4b6d2019-07-27 13:33:46 +04302129 */
2130void
2131hb_font_set_var_named_instance (hb_font_t *font,
2132 unsigned instance_index)
2133{
2134 if (hb_object_is_immutable (font))
2135 return;
2136
2137 unsigned int coords_length = hb_ot_var_named_instance_get_design_coords (font->face, instance_index, nullptr, nullptr);
2138
Behdad Esfahbod2337f0d2021-07-08 10:58:50 -06002139 float *coords = coords_length ? (float *) hb_calloc (coords_length, sizeof (float)) : nullptr;
Ebrahim Byagowi40a4b6d2019-07-27 13:33:46 +04302140 if (unlikely (coords_length && !coords))
2141 return;
2142
2143 hb_ot_var_named_instance_get_design_coords (font->face, instance_index, &coords_length, coords);
2144 hb_font_set_var_coords_design (font, coords, coords_length);
Behdad Esfahbod2337f0d2021-07-08 10:58:50 -06002145 hb_free (coords);
Ebrahim Byagowi40a4b6d2019-07-27 13:33:46 +04302146}
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09002147
Behdad Esfahbodd2f249e2017-01-22 17:42:33 -08002148/**
2149 * hb_font_set_var_coords_normalized:
Nathan Willis82092d42019-04-22 15:31:24 +01002150 * @font: #hb_font_t to work upon
2151 * @coords: (array length=coords_length): Array of variation coordinates to apply
2152 * @coords_length: Number of coordinates to apply
2153 *
2154 * Applies a list of variation coordinates (in normalized units)
2155 * to a font.
2156 *
2157 * <note>Note: Coordinates should be normalized to 2.14.</note>
Behdad Esfahbodd2f249e2017-01-22 17:42:33 -08002158 *
2159 * Since: 1.4.2
2160 */
Behdad Esfahbodad69e8f2016-09-09 22:23:34 -07002161void
Nathan Willisec987302019-04-17 14:44:25 +01002162hb_font_set_var_coords_normalized (hb_font_t *font,
2163 const int *coords, /* 2.14 normalized */
2164 unsigned int coords_length)
Behdad Esfahbodad69e8f2016-09-09 22:23:34 -07002165{
Behdad Esfahbod5570c872018-11-03 14:51:38 -04002166 if (hb_object_is_immutable (font))
Behdad Esfahbodad69e8f2016-09-09 22:23:34 -07002167 return;
2168
Behdad Esfahbod2337f0d2021-07-08 10:58:50 -06002169 int *copy = coords_length ? (int *) hb_calloc (coords_length, sizeof (coords[0])) : nullptr;
2170 int *unmapped = coords_length ? (int *) hb_calloc (coords_length, sizeof (coords[0])) : nullptr;
2171 float *design_coords = coords_length ? (float *) hb_calloc (coords_length, sizeof (design_coords[0])) : nullptr;
Ebrahim Byagowiab2d3ec2019-08-14 18:42:51 +04302172
2173 if (unlikely (coords_length && !(copy && unmapped && design_coords)))
2174 {
Behdad Esfahbod2337f0d2021-07-08 10:58:50 -06002175 hb_free (copy);
2176 hb_free (unmapped);
2177 hb_free (design_coords);
Behdad Esfahbodad69e8f2016-09-09 22:23:34 -07002178 return;
Ebrahim Byagowiab2d3ec2019-08-14 18:42:51 +04302179 }
Behdad Esfahbodad69e8f2016-09-09 22:23:34 -07002180
Behdad Esfahbodc22176d2016-09-10 01:58:27 -07002181 if (coords_length)
Ebrahim Byagowiab2d3ec2019-08-14 18:42:51 +04302182 {
Behdad Esfahbodc22176d2016-09-10 01:58:27 -07002183 memcpy (copy, coords, coords_length * sizeof (coords[0]));
Ebrahim Byagowiab2d3ec2019-08-14 18:42:51 +04302184 memcpy (unmapped, coords, coords_length * sizeof (coords[0]));
2185 }
Behdad Esfahbodc22176d2016-09-10 01:58:27 -07002186
Ebrahim Byagowiab2d3ec2019-08-14 18:42:51 +04302187 /* Best effort design coords simulation */
2188 font->face->table.avar->unmap_coords (unmapped, coords_length);
2189 for (unsigned int i = 0; i < coords_length; ++i)
2190 design_coords[i] = font->face->table.fvar->unnormalize_axis_value (i, unmapped[i]);
Behdad Esfahbod2337f0d2021-07-08 10:58:50 -06002191 hb_free (unmapped);
Ebrahim Byagowiab2d3ec2019-08-14 18:42:51 +04302192
2193 _hb_font_adopt_var_coords (font, copy, design_coords, coords_length);
Behdad Esfahbodad69e8f2016-09-09 22:23:34 -07002194}
2195
Behdad Esfahbodd2f249e2017-01-22 17:42:33 -08002196/**
Behdad Esfahbod22af28a2017-01-23 23:42:53 -08002197 * hb_font_get_var_coords_normalized:
Nathan Willis82092d42019-04-22 15:31:24 +01002198 * @font: #hb_font_t to work upon
2199 * @length: Number of coordinates retrieved
2200 *
2201 * Fetches the list of normalized variation coordinates currently
2202 * set on a font.
Behdad Esfahbodd2f249e2017-01-22 17:42:33 -08002203 *
Behdad Esfahbod7647a052017-01-22 17:47:49 -08002204 * Return value is valid as long as variation coordinates of the font
2205 * are not modified.
2206 *
Behdad Esfahbodd2f249e2017-01-22 17:42:33 -08002207 * Since: 1.4.2
2208 */
Behdad Esfahbod7647a052017-01-22 17:47:49 -08002209const int *
Nathan Willisec987302019-04-17 14:44:25 +01002210hb_font_get_var_coords_normalized (hb_font_t *font,
Behdad Esfahbodbf0d3a62017-01-21 14:48:46 -08002211 unsigned int *length)
2212{
2213 if (length)
Behdad Esfahbod8b2a5802017-01-21 15:05:00 -08002214 *length = font->num_coords;
Behdad Esfahbodbf0d3a62017-01-21 14:48:46 -08002215
2216 return font->coords;
2217}
Ebrahim Byagowiab2d3ec2019-08-14 18:42:51 +04302218
Ebrahim Byagowi9b7fb5c2020-04-17 20:12:24 +04302219#ifdef HB_EXPERIMENTAL_API
Ebrahim Byagowiab2d3ec2019-08-14 18:42:51 +04302220/**
2221 * hb_font_get_var_coords_design:
Khaled Hosnyaa107e62020-12-30 23:34:17 +02002222 * @font: #hb_font_t to work upon
2223 * @length: (out): number of coordinates
Ebrahim Byagowiab2d3ec2019-08-14 18:42:51 +04302224 *
2225 * Return value is valid as long as variation coordinates of the font
2226 * are not modified.
2227 *
Khaled Hosnyaa107e62020-12-30 23:34:17 +02002228 * Return value: coordinates array
2229 *
Ebrahim Byagowi9b7fb5c2020-04-17 20:12:24 +04302230 * Since: EXPERIMENTAL
Ebrahim Byagowiab2d3ec2019-08-14 18:42:51 +04302231 */
2232const float *
2233hb_font_get_var_coords_design (hb_font_t *font,
2234 unsigned int *length)
2235{
2236 if (length)
2237 *length = font->num_coords;
2238
2239 return font->design_coords;
2240}
Ebrahim Byagowibc27f862019-08-14 22:37:00 +04302241#endif
Ebrahim Byagowi9b7fb5c2020-04-17 20:12:24 +04302242#endif
Behdad Esfahbodad69e8f2016-09-09 22:23:34 -07002243
Behdad Esfahbodfca27862019-05-11 00:37:01 -07002244#ifndef HB_DISABLE_DEPRECATED
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09002245/*
2246 * Deprecated get_glyph_func():
2247 */
2248
2249struct hb_trampoline_closure_t
2250{
2251 void *user_data;
2252 hb_destroy_func_t destroy;
Behdad Esfahbodc335fd72016-02-25 09:16:05 +09002253 unsigned int ref_count;
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09002254};
2255
2256template <typename FuncType>
2257struct hb_trampoline_t
2258{
2259 hb_trampoline_closure_t closure; /* Must be first. */
2260 FuncType func;
2261};
2262
2263template <typename FuncType>
2264static hb_trampoline_t<FuncType> *
2265trampoline_create (FuncType func,
2266 void *user_data,
2267 hb_destroy_func_t destroy)
2268{
2269 typedef hb_trampoline_t<FuncType> trampoline_t;
2270
Behdad Esfahbod2337f0d2021-07-08 10:58:50 -06002271 trampoline_t *trampoline = (trampoline_t *) hb_calloc (1, sizeof (trampoline_t));
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09002272
2273 if (unlikely (!trampoline))
Behdad Esfahboddbdbfe32017-10-15 12:11:08 +02002274 return nullptr;
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09002275
2276 trampoline->closure.user_data = user_data;
2277 trampoline->closure.destroy = destroy;
Behdad Esfahbodc335fd72016-02-25 09:16:05 +09002278 trampoline->closure.ref_count = 1;
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09002279 trampoline->func = func;
2280
2281 return trampoline;
2282}
2283
2284static void
Behdad Esfahbodc335fd72016-02-25 09:16:05 +09002285trampoline_reference (hb_trampoline_closure_t *closure)
2286{
2287 closure->ref_count++;
2288}
2289
2290static void
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09002291trampoline_destroy (void *user_data)
2292{
2293 hb_trampoline_closure_t *closure = (hb_trampoline_closure_t *) user_data;
Behdad Esfahbodc335fd72016-02-25 09:16:05 +09002294
2295 if (--closure->ref_count)
2296 return;
2297
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09002298 if (closure->destroy)
2299 closure->destroy (closure->user_data);
Behdad Esfahbod2337f0d2021-07-08 10:58:50 -06002300 hb_free (closure);
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09002301}
2302
2303typedef hb_trampoline_t<hb_font_get_glyph_func_t> hb_font_get_glyph_trampoline_t;
2304
2305static hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +01002306hb_font_get_nominal_glyph_trampoline (hb_font_t *font,
2307 void *font_data,
2308 hb_codepoint_t unicode,
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09002309 hb_codepoint_t *glyph,
Nathan Willisec987302019-04-17 14:44:25 +01002310 void *user_data)
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09002311{
2312 hb_font_get_glyph_trampoline_t *trampoline = (hb_font_get_glyph_trampoline_t *) user_data;
2313 return trampoline->func (font, font_data, unicode, 0, glyph, trampoline->closure.user_data);
2314}
2315
2316static hb_bool_t
Nathan Willisec987302019-04-17 14:44:25 +01002317hb_font_get_variation_glyph_trampoline (hb_font_t *font,
2318 void *font_data,
2319 hb_codepoint_t unicode,
2320 hb_codepoint_t variation_selector,
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09002321 hb_codepoint_t *glyph,
Nathan Willisec987302019-04-17 14:44:25 +01002322 void *user_data)
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09002323{
2324 hb_font_get_glyph_trampoline_t *trampoline = (hb_font_get_glyph_trampoline_t *) user_data;
2325 return trampoline->func (font, font_data, unicode, variation_selector, glyph, trampoline->closure.user_data);
2326}
2327
2328/**
2329 * hb_font_funcs_set_glyph_func:
Nathan Willis82092d42019-04-22 15:31:24 +01002330 * @ffuncs: The font-functions structure
2331 * @func: (closure user_data) (destroy destroy) (scope notified): callback function
2332 * @user_data: data to pass to @func
Khaled Hosny99364902020-12-31 00:19:29 +02002333 * @destroy: (nullable): function to call when @user_data is not needed anymore
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09002334 *
2335 * Deprecated. Use hb_font_funcs_set_nominal_glyph_func() and
2336 * hb_font_funcs_set_variation_glyph_func() instead.
2337 *
2338 * Since: 0.9.2
2339 * Deprecated: 1.2.3
2340 **/
2341void
Nathan Willisec987302019-04-17 14:44:25 +01002342hb_font_funcs_set_glyph_func (hb_font_funcs_t *ffuncs,
2343 hb_font_get_glyph_func_t func,
2344 void *user_data,
Nathan Willis82092d42019-04-22 15:31:24 +01002345 hb_destroy_func_t destroy /* May be NULL. */)
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09002346{
Ebrahim Byagowi352ac632020-02-11 03:03:03 +03302347 if (hb_object_is_immutable (ffuncs))
2348 {
2349 if (destroy)
2350 destroy (user_data);
2351 return;
2352 }
2353
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09002354 hb_font_get_glyph_trampoline_t *trampoline;
2355
2356 trampoline = trampoline_create (func, user_data, destroy);
Behdad Esfahbodc335fd72016-02-25 09:16:05 +09002357 if (unlikely (!trampoline))
2358 {
2359 if (destroy)
2360 destroy (user_data);
2361 return;
2362 }
2363
2364 hb_font_funcs_set_nominal_glyph_func (ffuncs,
2365 hb_font_get_nominal_glyph_trampoline,
2366 trampoline,
2367 trampoline_destroy);
2368
2369 trampoline_reference (&trampoline->closure);
2370 hb_font_funcs_set_variation_glyph_func (ffuncs,
2371 hb_font_get_variation_glyph_trampoline,
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09002372 trampoline,
2373 trampoline_destroy);
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +09002374}
Behdad Esfahbodfca27862019-05-11 00:37:01 -07002375#endif