blob: 97a2c82e6832dcc8ceb89a7b151d0a0cc396dc94 [file] [log] [blame]
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -05001/*
Behdad Esfahbod2409d5f2011-04-21 17:14:28 -04002 * Copyright © 2009 Red Hat, Inc.
3 * Copyright © 2009 Keith Stribley
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -04004 * Copyright © 2015 Google, Inc.
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -05005 *
Behdad Esfahbodc755cb32010-04-22 00:11:43 -04006 * This is part of HarfBuzz, a text shaping library.
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -05007 *
8 * Permission is hereby granted, without written agreement and without
9 * license or royalty fees, to use, copy, modify, and distribute this
10 * software and its documentation for any purpose, provided that the
11 * above copyright notice and the following two paragraphs appear in
12 * all copies of this software.
13 *
14 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
15 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
16 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
17 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
18 * DAMAGE.
19 *
20 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
21 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
22 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
23 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
24 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
25 *
26 * Red Hat Author(s): Behdad Esfahbod
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -040027 * Google Author(s): Behdad Esfahbod
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -050028 */
29
Behdad Esfahbodc77ae402018-08-25 22:36:36 -070030#include "hb.hh"
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -050031
Behdad Esfahbodaa3450c2019-06-17 22:41:49 -070032#ifdef HAVE_FREETYPE
33
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -050034#include "hb-ft.h"
35
Behdad Esfahbodc77ae402018-08-25 22:36:36 -070036#include "hb-font.hh"
37#include "hb-machinery.hh"
Behdad Esfahbod0f520ad2018-09-11 12:02:34 +020038#include "hb-cache.hh"
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -050039
Behdad Esfahbod0b7e4d92011-08-15 20:41:59 +020040#include FT_ADVANCES_H
Sascha Brawer72873cf2016-09-13 18:40:07 +020041#include FT_MULTIPLE_MASTERS_H
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -050042#include FT_TRUETYPE_TABLES_H
43
Behdad Esfahbodacdba3f2010-07-23 15:11:18 -040044
Behdad Esfahbod04981ee2018-10-27 04:40:43 -070045/**
46 * SECTION:hb-ft
47 * @title: hb-ft
48 * @short_description: FreeType integration
49 * @include: hb-ft.h
50 *
Nathan Willis9126a5f2019-05-20 17:37:56 +010051 * Functions for using HarfBuzz with the FreeType library.
52 *
53 * HarfBuzz supports using FreeType to provide face and
Behdad Esfahbod04981ee2018-10-27 04:40:43 -070054 * font data.
Nathan Willis9126a5f2019-05-20 17:37:56 +010055 *
56 * <note>Note that FreeType is not thread-safe, therefore these
57 * functions are not thread-safe either.</note>
Behdad Esfahbod04981ee2018-10-27 04:40:43 -070058 **/
59
60
Behdad Esfahbod744970a2011-05-16 18:15:37 -040061/* TODO:
62 *
63 * In general, this file does a fine job of what it's supposed to do.
64 * There are, however, things that need more work:
65 *
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -040066 * - FreeType works in 26.6 mode. Clients can decide to use that mode, and everything
Behdad Esfahbodf34aaba2014-12-28 18:56:15 -080067 * would work fine. However, we also abuse this API for performing in font-space,
68 * but don't pass the correct flags to FreeType. We just abuse the no-hinting mode
69 * for that, such that no rounding etc happens. As such, we don't set ppem, and
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -040070 * pass NO_HINTING as load_flags. Would be much better to use NO_SCALE, and scale
Behdad Esfahbodd18c3c52018-10-09 16:07:55 -040071 * ourselves.
Behdad Esfahbodf34aaba2014-12-28 18:56:15 -080072 *
Behdad Esfahbod744970a2011-05-16 18:15:37 -040073 * - We don't handle / allow for emboldening / obliqueing.
74 *
Behdad Esfahbod190e19e2013-03-09 20:30:22 -050075 * - In the future, we should add constructors to create fonts in font space?
Behdad Esfahbod744970a2011-05-16 18:15:37 -040076 */
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -050077
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -040078
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -040079struct hb_ft_font_t
80{
Behdad Esfahbodbe2f1482018-10-09 16:24:50 -040081 mutable hb_mutex_t lock;
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -040082 FT_Face ft_face;
83 int load_flags;
Behdad Esfahbod34f9aa52016-07-20 02:35:54 -070084 bool symbol; /* Whether selected cmap is symbol cmap. */
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -040085 bool unref; /* Whether to destroy ft_face when done. */
Behdad Esfahbod383060c2018-09-11 14:41:19 +020086
Behdad Esfahbod12a283d2021-02-22 12:50:41 -070087 mutable int cached_x_scale;
Behdad Esfahbod54998be2018-09-11 14:35:26 +020088 mutable hb_advance_cache_t advance_cache;
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -040089};
90
91static hb_ft_font_t *
Behdad Esfahbod34f9aa52016-07-20 02:35:54 -070092_hb_ft_font_create (FT_Face ft_face, bool symbol, bool unref)
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -040093{
Behdad Esfahbod2337f0d2021-07-08 10:58:50 -060094 hb_ft_font_t *ft_font = (hb_ft_font_t *) hb_calloc (1, sizeof (hb_ft_font_t));
Behdad Esfahbod26b96702020-06-28 14:52:15 -070095 if (unlikely (!ft_font)) return nullptr;
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -040096
Behdad Esfahbodbe2f1482018-10-09 16:24:50 -040097 ft_font->lock.init ();
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -040098 ft_font->ft_face = ft_face;
Behdad Esfahbod34f9aa52016-07-20 02:35:54 -070099 ft_font->symbol = symbol;
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -0400100 ft_font->unref = unref;
101
Behdad Esfahbodca97ea72015-10-15 20:20:22 -0300102 ft_font->load_flags = FT_LOAD_DEFAULT | FT_LOAD_NO_HINTING;
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -0400103
Behdad Esfahbod12a283d2021-02-22 12:50:41 -0700104 ft_font->cached_x_scale = 0;
Behdad Esfahbod54998be2018-09-11 14:35:26 +0200105 ft_font->advance_cache.init ();
106
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -0400107 return ft_font;
108}
109
110static void
Behdad Esfahbode1b6d922017-10-11 15:51:31 +0200111_hb_ft_face_destroy (void *data)
Birunthan Mohanathas6bf9db42016-07-11 13:38:23 -0700112{
Behdad Esfahbode1b6d922017-10-11 15:51:31 +0200113 FT_Done_Face ((FT_Face) data);
Birunthan Mohanathas6bf9db42016-07-11 13:38:23 -0700114}
115
116static void
Behdad Esfahbode1b6d922017-10-11 15:51:31 +0200117_hb_ft_font_destroy (void *data)
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -0400118{
Behdad Esfahbode1b6d922017-10-11 15:51:31 +0200119 hb_ft_font_t *ft_font = (hb_ft_font_t *) data;
120
Behdad Esfahbod54998be2018-09-11 14:35:26 +0200121 ft_font->advance_cache.fini ();
122
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -0400123 if (ft_font->unref)
Birunthan Mohanathas6bf9db42016-07-11 13:38:23 -0700124 _hb_ft_face_destroy (ft_font->ft_face);
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -0400125
Behdad Esfahbodbe2f1482018-10-09 16:24:50 -0400126 ft_font->lock.fini ();
127
Behdad Esfahbod2337f0d2021-07-08 10:58:50 -0600128 hb_free (ft_font);
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -0400129}
130
Behdad Esfahbodedeb3da2015-10-08 12:47:15 -0400131/**
132 * hb_ft_font_set_load_flags:
Nathan Willis9126a5f2019-05-20 17:37:56 +0100133 * @font: #hb_font_t to work upon
134 * @load_flags: The FreeType load flags to set
Behdad Esfahbodedeb3da2015-10-08 12:47:15 -0400135 *
Nathan Willis9126a5f2019-05-20 17:37:56 +0100136 * Sets the FT_Load_Glyph load flags for the specified #hb_font_t.
Ebrahim Byagowi70d36542018-03-30 05:00:28 +0430137 *
Nathan Willis9126a5f2019-05-20 17:37:56 +0100138 * For more information, see
139 * https://www.freetype.org/freetype2/docs/reference/ft2-base_interface.html#ft_load_xxx
Behdad Esfahbodedeb3da2015-10-08 12:47:15 -0400140 *
141 * Since: 1.0.5
142 **/
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -0400143void
144hb_ft_font_set_load_flags (hb_font_t *font, int load_flags)
145{
Behdad Esfahbod5570c872018-11-03 14:51:38 -0400146 if (hb_object_is_immutable (font))
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -0400147 return;
148
Behdad Esfahbodd5338ba2019-11-22 16:22:27 -0500149 if (unlikely (font->destroy != (hb_destroy_func_t) _hb_ft_font_destroy))
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -0400150 return;
151
152 hb_ft_font_t *ft_font = (hb_ft_font_t *) font->user_data;
153
154 ft_font->load_flags = load_flags;
155}
156
Behdad Esfahbodedeb3da2015-10-08 12:47:15 -0400157/**
158 * hb_ft_font_get_load_flags:
Nathan Willis9126a5f2019-05-20 17:37:56 +0100159 * @font: #hb_font_t to work upon
Behdad Esfahbodedeb3da2015-10-08 12:47:15 -0400160 *
Nathan Willis9126a5f2019-05-20 17:37:56 +0100161 * Fetches the FT_Load_Glyph load flags of the specified #hb_font_t.
Ebrahim Byagowi70d36542018-03-30 05:00:28 +0430162 *
Nathan Willis9126a5f2019-05-20 17:37:56 +0100163 * For more information, see
164 * https://www.freetype.org/freetype2/docs/reference/ft2-base_interface.html#ft_load_xxx
Behdad Esfahbodedeb3da2015-10-08 12:47:15 -0400165 *
Nathan Willis9126a5f2019-05-20 17:37:56 +0100166 * Return value: FT_Load_Glyph flags found
167 *
Behdad Esfahbodedeb3da2015-10-08 12:47:15 -0400168 * Since: 1.0.5
169 **/
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -0400170int
171hb_ft_font_get_load_flags (hb_font_t *font)
172{
Behdad Esfahbodd5338ba2019-11-22 16:22:27 -0500173 if (unlikely (font->destroy != (hb_destroy_func_t) _hb_ft_font_destroy))
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -0400174 return 0;
175
176 const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font->user_data;
177
178 return ft_font->load_flags;
179}
180
Nathan Willis9126a5f2019-05-20 17:37:56 +0100181/**
Khaled Hosnya31a51c2020-12-30 23:48:25 +0200182 * hb_ft_font_get_face:
Nathan Willis9126a5f2019-05-20 17:37:56 +0100183 * @font: #hb_font_t to work upon
184 *
185 * Fetches the FT_Face associated with the specified #hb_font_t
186 * font object.
187 *
Khaled Hosnya31a51c2020-12-30 23:48:25 +0200188 * Return value: (nullable): the FT_Face found or %NULL
Nathan Willis9126a5f2019-05-20 17:37:56 +0100189 *
Behdad Esfahbodd5338ba2019-11-22 16:22:27 -0500190 * Since: 0.9.2
Nathan Willis9126a5f2019-05-20 17:37:56 +0100191 **/
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -0400192FT_Face
193hb_ft_font_get_face (hb_font_t *font)
194{
Behdad Esfahbodd5338ba2019-11-22 16:22:27 -0500195 if (unlikely (font->destroy != (hb_destroy_func_t) _hb_ft_font_destroy))
Behdad Esfahboddbdbfe32017-10-15 12:11:08 +0200196 return nullptr;
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -0400197
198 const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font->user_data;
199
200 return ft_font->ft_face;
201}
202
Behdad Esfahbodd5338ba2019-11-22 16:22:27 -0500203/**
204 * hb_ft_font_lock_face:
Khaled Hosnya31a51c2020-12-30 23:48:25 +0200205 * @font: #hb_font_t to work upon
Behdad Esfahbodd5338ba2019-11-22 16:22:27 -0500206 *
Khaled Hosnya31a51c2020-12-30 23:48:25 +0200207 * Gets the FT_Face associated with @font, This face will be kept around until
208 * you call hb_ft_font_unlock_face().
Behdad Esfahbodd5338ba2019-11-22 16:22:27 -0500209 *
Khaled Hosnya31a51c2020-12-30 23:48:25 +0200210 * Return value: (nullable): the FT_Face associated with @font or %NULL
Ebrahim Byagowif9bc3732020-04-17 22:37:48 +0430211 * Since: 2.6.5
Behdad Esfahbodd5338ba2019-11-22 16:22:27 -0500212 **/
213FT_Face
214hb_ft_font_lock_face (hb_font_t *font)
215{
216 if (unlikely (font->destroy != (hb_destroy_func_t) _hb_ft_font_destroy))
217 return nullptr;
218
219 const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font->user_data;
220
221 ft_font->lock.lock ();
222
223 return ft_font->ft_face;
224}
225
226/**
227 * hb_ft_font_unlock_face:
Khaled Hosnya31a51c2020-12-30 23:48:25 +0200228 * @font: #hb_font_t to work upon
Behdad Esfahbodd5338ba2019-11-22 16:22:27 -0500229 *
Khaled Hosnya31a51c2020-12-30 23:48:25 +0200230 * Releases an FT_Face previously obtained with hb_ft_font_lock_face().
Behdad Esfahbodd5338ba2019-11-22 16:22:27 -0500231 *
Ebrahim Byagowif9bc3732020-04-17 22:37:48 +0430232 * Since: 2.6.5
Behdad Esfahbodd5338ba2019-11-22 16:22:27 -0500233 **/
234void
235hb_ft_font_unlock_face (hb_font_t *font)
236{
237 if (unlikely (font->destroy != (hb_destroy_func_t) _hb_ft_font_destroy))
238 return;
239
240 const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font->user_data;
241
242 ft_font->lock.unlock ();
243}
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -0400244
245
Behdad Esfahbod0fd8c2f2011-05-12 15:14:13 -0400246static hb_bool_t
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +0900247hb_ft_get_nominal_glyph (hb_font_t *font HB_UNUSED,
248 void *font_data,
249 hb_codepoint_t unicode,
250 hb_codepoint_t *glyph,
251 void *user_data HB_UNUSED)
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400252{
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -0400253 const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font_data;
Behdad Esfahbodbe2f1482018-10-09 16:24:50 -0400254 hb_lock_t lock (ft_font->lock);
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +0900255 unsigned int g = FT_Get_Char_Index (ft_font->ft_face, unicode);
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400256
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +0900257 if (unlikely (!g))
Behdad Esfahbod34f9aa52016-07-20 02:35:54 -0700258 {
259 if (unlikely (ft_font->symbol) && unicode <= 0x00FFu)
260 {
261 /* For symbol-encoded OpenType fonts, we duplicate the
262 * U+F000..F0FF range at U+0000..U+00FF. That's what
263 * Windows seems to do, and that's hinted about at:
Ebrahim Byagowif24b0b92018-04-12 13:40:45 +0430264 * https://docs.microsoft.com/en-us/typography/opentype/spec/recom
Behdad Esfahbod34f9aa52016-07-20 02:35:54 -0700265 * under "Non-Standard (Symbol) Fonts". */
266 g = FT_Get_Char_Index (ft_font->ft_face, 0xF000u + unicode);
267 if (!g)
268 return false;
269 }
270 else
271 return false;
272 }
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +0900273
274 *glyph = g;
275 return true;
276}
277
Behdad Esfahbodec844602018-10-09 15:07:04 -0400278static unsigned int
279hb_ft_get_nominal_glyphs (hb_font_t *font HB_UNUSED,
280 void *font_data,
281 unsigned int count,
282 const hb_codepoint_t *first_unicode,
283 unsigned int unicode_stride,
284 hb_codepoint_t *first_glyph,
285 unsigned int glyph_stride,
286 void *user_data HB_UNUSED)
287{
288 const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font_data;
Behdad Esfahbodbe2f1482018-10-09 16:24:50 -0400289 hb_lock_t lock (ft_font->lock);
Behdad Esfahbodec844602018-10-09 15:07:04 -0400290 unsigned int done;
291 for (done = 0;
292 done < count && (*first_glyph = FT_Get_Char_Index (ft_font->ft_face, *first_unicode));
293 done++)
294 {
Behdad Esfahbod447323b2019-01-22 12:45:40 +0100295 first_unicode = &StructAtOffsetUnaligned<hb_codepoint_t> (first_unicode, unicode_stride);
296 first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
Behdad Esfahbodec844602018-10-09 15:07:04 -0400297 }
298 /* We don't need to do ft_font->symbol dance here, since HB calls the singular
299 * nominal_glyph() for what we don't handle here. */
300 return done;
301}
302
303
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +0900304static hb_bool_t
305hb_ft_get_variation_glyph (hb_font_t *font HB_UNUSED,
306 void *font_data,
307 hb_codepoint_t unicode,
308 hb_codepoint_t variation_selector,
309 hb_codepoint_t *glyph,
310 void *user_data HB_UNUSED)
311{
312 const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font_data;
Behdad Esfahbodbe2f1482018-10-09 16:24:50 -0400313 hb_lock_t lock (ft_font->lock);
Behdad Esfahbod8b5bc142016-02-24 19:05:23 +0900314 unsigned int g = FT_Face_GetCharVariantIndex (ft_font->ft_face, unicode, variation_selector);
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400315
Behdad Esfahbod9df099b2015-05-18 18:37:06 -0700316 if (unlikely (!g))
317 return false;
318
319 *glyph = g;
320 return true;
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400321}
322
Behdad Esfahbod237f2152018-09-11 13:05:47 +0200323static void
324hb_ft_get_glyph_h_advances (hb_font_t* font, void* font_data,
325 unsigned count,
Behdad Esfahbodbee93e22018-10-09 08:01:49 -0400326 const hb_codepoint_t *first_glyph,
Behdad Esfahbod237f2152018-09-11 13:05:47 +0200327 unsigned glyph_stride,
328 hb_position_t *first_advance,
329 unsigned advance_stride,
330 void *user_data HB_UNUSED)
331{
332 const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font_data;
Behdad Esfahbodbe2f1482018-10-09 16:24:50 -0400333 hb_lock_t lock (ft_font->lock);
Behdad Esfahbod237f2152018-09-11 13:05:47 +0200334 FT_Face ft_face = ft_font->ft_face;
Behdad Esfahbod54998be2018-09-11 14:35:26 +0200335 int load_flags = ft_font->load_flags;
Behdad Esfahbod237f2152018-09-11 13:05:47 +0200336 int mult = font->x_scale < 0 ? -1 : +1;
Behdad Esfahbod237f2152018-09-11 13:05:47 +0200337
Behdad Esfahbod12a283d2021-02-22 12:50:41 -0700338 if (font->x_scale != ft_font->cached_x_scale)
Behdad Esfahbod383060c2018-09-11 14:41:19 +0200339 {
340 ft_font->advance_cache.clear ();
Behdad Esfahbod12a283d2021-02-22 12:50:41 -0700341 ft_font->cached_x_scale = font->x_scale;
Behdad Esfahbod383060c2018-09-11 14:41:19 +0200342 }
343
Behdad Esfahbod54998be2018-09-11 14:35:26 +0200344 for (unsigned int i = 0; i < count; i++)
Behdad Esfahbod237f2152018-09-11 13:05:47 +0200345 {
Behdad Esfahbod047a84c2018-09-11 14:05:16 +0200346 FT_Fixed v = 0;
Behdad Esfahbod54998be2018-09-11 14:35:26 +0200347 hb_codepoint_t glyph = *first_glyph;
Behdad Esfahbod047a84c2018-09-11 14:05:16 +0200348
Behdad Esfahbod54998be2018-09-11 14:35:26 +0200349 unsigned int cv;
350 if (ft_font->advance_cache.get (glyph, &cv))
351 v = cv;
352 else
353 {
354 FT_Get_Advance (ft_face, glyph, load_flags, &v);
355 ft_font->advance_cache.set (glyph, v);
356 }
357
Behdad Esfahbod237f2152018-09-11 13:05:47 +0200358 *first_advance = (v * mult + (1<<9)) >> 10;
Behdad Esfahbod447323b2019-01-22 12:45:40 +0100359 first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
360 first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);
Behdad Esfahbod237f2152018-09-11 13:05:47 +0200361 }
362}
363
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400364static hb_position_t
Ebrahim Byagowi24b8b9b2018-04-23 19:03:57 +0430365hb_ft_get_glyph_v_advance (hb_font_t *font,
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400366 void *font_data,
367 hb_codepoint_t glyph,
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400368 void *user_data HB_UNUSED)
369{
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -0400370 const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font_data;
Behdad Esfahbodbe2f1482018-10-09 16:24:50 -0400371 hb_lock_t lock (ft_font->lock);
Behdad Esfahbod0b7e4d92011-08-15 20:41:59 +0200372 FT_Fixed v;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400373
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -0400374 if (unlikely (FT_Get_Advance (ft_font->ft_face, glyph, ft_font->load_flags | FT_LOAD_VERTICAL_LAYOUT, &v)))
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400375 return 0;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400376
Behdad Esfahbod7888a6b2015-01-28 12:40:40 -0800377 if (font->y_scale < 0)
378 v = -v;
379
Behdad Esfahbod8b38fae2011-05-19 13:08:00 -0400380 /* Note: FreeType's vertical metrics grows downward while other FreeType coordinates
381 * have a Y growing upward. Hence the extra negation. */
Behdad Esfahbod755b44c2013-10-18 11:17:42 +0200382 return (-v + (1<<9)) >> 10;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400383}
384
385static hb_bool_t
Ebrahim Byagowi24b8b9b2018-04-23 19:03:57 +0430386hb_ft_get_glyph_v_origin (hb_font_t *font,
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400387 void *font_data,
388 hb_codepoint_t glyph,
Behdad Esfahbod19098182011-05-17 23:27:22 -0400389 hb_position_t *x,
390 hb_position_t *y,
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400391 void *user_data HB_UNUSED)
392{
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -0400393 const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font_data;
Behdad Esfahbodbe2f1482018-10-09 16:24:50 -0400394 hb_lock_t lock (ft_font->lock);
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -0400395 FT_Face ft_face = ft_font->ft_face;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400396
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -0400397 if (unlikely (FT_Load_Glyph (ft_face, glyph, ft_font->load_flags)))
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400398 return false;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400399
Behdad Esfahbod8b38fae2011-05-19 13:08:00 -0400400 /* Note: FreeType's vertical metrics grows downward while other FreeType coordinates
401 * have a Y growing upward. Hence the extra negation. */
402 *x = ft_face->glyph->metrics.horiBearingX - ft_face->glyph->metrics.vertBearingX;
403 *y = ft_face->glyph->metrics.horiBearingY - (-ft_face->glyph->metrics.vertBearingY);
404
Behdad Esfahbod7888a6b2015-01-28 12:40:40 -0800405 if (font->x_scale < 0)
406 *x = -*x;
407 if (font->y_scale < 0)
408 *y = -*y;
409
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400410 return true;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400411}
412
Behdad Esfahbodbfb55692019-06-17 14:06:04 -0700413#ifndef HB_NO_OT_SHAPE_FALLBACK
Behdad Esfahbod896416b2019-06-17 13:39:49 -0700414static hb_position_t
415hb_ft_get_glyph_h_kerning (hb_font_t *font,
416 void *font_data,
417 hb_codepoint_t left_glyph,
418 hb_codepoint_t right_glyph,
419 void *user_data HB_UNUSED)
420{
421 const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font_data;
422 FT_Vector kerningv;
423
424 FT_Kerning_Mode mode = font->x_ppem ? FT_KERNING_DEFAULT : FT_KERNING_UNFITTED;
425 if (FT_Get_Kerning (ft_font->ft_face, left_glyph, right_glyph, mode, &kerningv))
426 return 0;
427
428 return kerningv.x;
429}
Behdad Esfahbodbfb55692019-06-17 14:06:04 -0700430#endif
Behdad Esfahbod896416b2019-06-17 13:39:49 -0700431
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400432static hb_bool_t
Ebrahim Byagowi24b8b9b2018-04-23 19:03:57 +0430433hb_ft_get_glyph_extents (hb_font_t *font,
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400434 void *font_data,
435 hb_codepoint_t glyph,
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400436 hb_glyph_extents_t *extents,
437 void *user_data HB_UNUSED)
438{
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -0400439 const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font_data;
Behdad Esfahbodbe2f1482018-10-09 16:24:50 -0400440 hb_lock_t lock (ft_font->lock);
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -0400441 FT_Face ft_face = ft_font->ft_face;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400442
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -0400443 if (unlikely (FT_Load_Glyph (ft_face, glyph, ft_font->load_flags)))
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400444 return false;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400445
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400446 extents->x_bearing = ft_face->glyph->metrics.horiBearingX;
447 extents->y_bearing = ft_face->glyph->metrics.horiBearingY;
448 extents->width = ft_face->glyph->metrics.width;
Behdad Esfahbod21756932012-08-08 01:20:45 -0400449 extents->height = -ft_face->glyph->metrics.height;
Behdad Esfahbodc743ec52015-11-05 17:33:57 -0800450 if (font->x_scale < 0)
451 {
452 extents->x_bearing = -extents->x_bearing;
453 extents->width = -extents->width;
454 }
455 if (font->y_scale < 0)
456 {
457 extents->y_bearing = -extents->y_bearing;
458 extents->height = -extents->height;
459 }
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400460 return true;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400461}
462
463static hb_bool_t
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400464hb_ft_get_glyph_contour_point (hb_font_t *font HB_UNUSED,
465 void *font_data,
466 hb_codepoint_t glyph,
467 unsigned int point_index,
468 hb_position_t *x,
469 hb_position_t *y,
470 void *user_data HB_UNUSED)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400471{
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -0400472 const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font_data;
Behdad Esfahbodbe2f1482018-10-09 16:24:50 -0400473 hb_lock_t lock (ft_font->lock);
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -0400474 FT_Face ft_face = ft_font->ft_face;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400475
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -0400476 if (unlikely (FT_Load_Glyph (ft_face, glyph, ft_font->load_flags)))
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400477 return false;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400478
479 if (unlikely (ft_face->glyph->format != FT_GLYPH_FORMAT_OUTLINE))
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400480 return false;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400481
482 if (unlikely (point_index >= (unsigned int) ft_face->glyph->outline.n_points))
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400483 return false;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400484
485 *x = ft_face->glyph->outline.points[point_index].x;
486 *y = ft_face->glyph->outline.points[point_index].y;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400487
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400488 return true;
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -0500489}
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -0500490
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400491static hb_bool_t
Behdad Esfahbod271c8f82012-07-13 09:32:30 -0400492hb_ft_get_glyph_name (hb_font_t *font HB_UNUSED,
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400493 void *font_data,
494 hb_codepoint_t glyph,
495 char *name, unsigned int size,
496 void *user_data HB_UNUSED)
497{
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -0400498 const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font_data;
Behdad Esfahbodbe2f1482018-10-09 16:24:50 -0400499 hb_lock_t lock (ft_font->lock);
500 FT_Face ft_face = ft_font->ft_face;
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400501
Behdad Esfahbodbe2f1482018-10-09 16:24:50 -0400502 hb_bool_t ret = !FT_Get_Glyph_Name (ft_face, glyph, name, size);
Behdad Esfahbod5594c2d2013-03-06 19:37:31 -0500503 if (ret && (size && !*name))
504 ret = false;
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400505
506 return ret;
507}
508
509static hb_bool_t
Behdad Esfahbod271c8f82012-07-13 09:32:30 -0400510hb_ft_get_glyph_from_name (hb_font_t *font HB_UNUSED,
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400511 void *font_data,
512 const char *name, int len, /* -1 means nul-terminated */
513 hb_codepoint_t *glyph,
514 void *user_data HB_UNUSED)
515{
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -0400516 const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font_data;
Behdad Esfahbodbe2f1482018-10-09 16:24:50 -0400517 hb_lock_t lock (ft_font->lock);
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -0400518 FT_Face ft_face = ft_font->ft_face;
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400519
520 if (len < 0)
521 *glyph = FT_Get_Name_Index (ft_face, (FT_String *) name);
522 else {
523 /* Make a nul-terminated version. */
524 char buf[128];
Behdad Esfahbod41248cc2019-05-07 20:54:31 -0700525 len = hb_min (len, (int) sizeof (buf) - 1);
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400526 strncpy (buf, name, len);
527 buf[len] = '\0';
528 *glyph = FT_Get_Name_Index (ft_face, buf);
529 }
530
Behdad Esfahbode509d352013-07-11 14:56:45 -0400531 if (*glyph == 0)
532 {
533 /* Check whether the given name was actually the name of glyph 0. */
534 char buf[128];
535 if (!FT_Get_Glyph_Name(ft_face, 0, buf, sizeof (buf)) &&
Ebrahim Byagowia0b4ac42019-08-24 17:57:14 +0430536 len < 0 ? !strcmp (buf, name) : !strncmp (buf, name, len))
Behdad Esfahbode509d352013-07-11 14:56:45 -0400537 return true;
538 }
539
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400540 return *glyph != 0;
541}
542
Simon Cozens6f2e6de2015-10-26 16:23:22 +0900543static hb_bool_t
544hb_ft_get_font_h_extents (hb_font_t *font HB_UNUSED,
545 void *font_data,
546 hb_font_extents_t *metrics,
547 void *user_data HB_UNUSED)
548{
549 const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font_data;
Behdad Esfahbodbe2f1482018-10-09 16:24:50 -0400550 hb_lock_t lock (ft_font->lock);
Simon Cozens6f2e6de2015-10-26 16:23:22 +0900551 FT_Face ft_face = ft_font->ft_face;
HinTak7ec694d2018-11-07 13:19:36 +0000552 metrics->ascender = FT_MulFix(ft_face->ascender, ft_face->size->metrics.y_scale);
553 metrics->descender = FT_MulFix(ft_face->descender, ft_face->size->metrics.y_scale);
554 metrics->line_gap = FT_MulFix( ft_face->height, ft_face->size->metrics.y_scale ) - (metrics->ascender - metrics->descender);
Simon Cozens6f2e6de2015-10-26 16:23:22 +0900555 if (font->y_scale < 0)
556 {
557 metrics->ascender = -metrics->ascender;
558 metrics->descender = -metrics->descender;
559 metrics->line_gap = -metrics->line_gap;
560 }
561 return true;
562}
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400563
Behdad Esfahboded116322021-09-14 07:09:54 -0400564static inline void free_static_ft_funcs ();
Behdad Esfahbod7918c262015-11-04 20:37:49 -0800565
Behdad Esfahbodc7ca30a2018-08-12 13:46:53 -0700566static struct hb_ft_font_funcs_lazy_loader_t : hb_font_funcs_lazy_loader_t<hb_ft_font_funcs_lazy_loader_t>
Behdad Esfahbod7918c262015-11-04 20:37:49 -0800567{
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330568 static hb_font_funcs_t *create ()
Behdad Esfahbod7918c262015-11-04 20:37:49 -0800569 {
Behdad Esfahbodc7ca30a2018-08-12 13:46:53 -0700570 hb_font_funcs_t *funcs = hb_font_funcs_create ();
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -0400571
Behdad Esfahboddbdbfe32017-10-15 12:11:08 +0200572 hb_font_funcs_set_font_h_extents_func (funcs, hb_ft_get_font_h_extents, nullptr, nullptr);
573 //hb_font_funcs_set_font_v_extents_func (funcs, hb_ft_get_font_v_extents, nullptr, nullptr);
574 hb_font_funcs_set_nominal_glyph_func (funcs, hb_ft_get_nominal_glyph, nullptr, nullptr);
Behdad Esfahbodec844602018-10-09 15:07:04 -0400575 hb_font_funcs_set_nominal_glyphs_func (funcs, hb_ft_get_nominal_glyphs, nullptr, nullptr);
Behdad Esfahboddbdbfe32017-10-15 12:11:08 +0200576 hb_font_funcs_set_variation_glyph_func (funcs, hb_ft_get_variation_glyph, nullptr, nullptr);
Behdad Esfahbod237f2152018-09-11 13:05:47 +0200577 hb_font_funcs_set_glyph_h_advances_func (funcs, hb_ft_get_glyph_h_advances, nullptr, nullptr);
Behdad Esfahboddbdbfe32017-10-15 12:11:08 +0200578 hb_font_funcs_set_glyph_v_advance_func (funcs, hb_ft_get_glyph_v_advance, nullptr, nullptr);
579 //hb_font_funcs_set_glyph_h_origin_func (funcs, hb_ft_get_glyph_h_origin, nullptr, nullptr);
580 hb_font_funcs_set_glyph_v_origin_func (funcs, hb_ft_get_glyph_v_origin, nullptr, nullptr);
Behdad Esfahbodbfb55692019-06-17 14:06:04 -0700581#ifndef HB_NO_OT_SHAPE_FALLBACK
Behdad Esfahbod896416b2019-06-17 13:39:49 -0700582 hb_font_funcs_set_glyph_h_kerning_func (funcs, hb_ft_get_glyph_h_kerning, nullptr, nullptr);
Behdad Esfahbodbfb55692019-06-17 14:06:04 -0700583#endif
Behdad Esfahbod896416b2019-06-17 13:39:49 -0700584 //hb_font_funcs_set_glyph_v_kerning_func (funcs, hb_ft_get_glyph_v_kerning, nullptr, nullptr);
Behdad Esfahboddbdbfe32017-10-15 12:11:08 +0200585 hb_font_funcs_set_glyph_extents_func (funcs, hb_ft_get_glyph_extents, nullptr, nullptr);
586 hb_font_funcs_set_glyph_contour_point_func (funcs, hb_ft_get_glyph_contour_point, nullptr, nullptr);
587 hb_font_funcs_set_glyph_name_func (funcs, hb_ft_get_glyph_name, nullptr, nullptr);
588 hb_font_funcs_set_glyph_from_name_func (funcs, hb_ft_get_glyph_from_name, nullptr, nullptr);
Behdad Esfahbod7918c262015-11-04 20:37:49 -0800589
Behdad Esfahbod44f82752015-11-04 20:40:05 -0800590 hb_font_funcs_make_immutable (funcs);
591
Behdad Esfahboded116322021-09-14 07:09:54 -0400592 hb_atexit (free_static_ft_funcs);
Behdad Esfahbodc7ca30a2018-08-12 13:46:53 -0700593
594 return funcs;
595 }
596} static_ft_funcs;
Behdad Esfahbod7918c262015-11-04 20:37:49 -0800597
Behdad Esfahboded116322021-09-14 07:09:54 -0400598static inline
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330599void free_static_ft_funcs ()
Behdad Esfahbodc7ca30a2018-08-12 13:46:53 -0700600{
Behdad Esfahbod7bd508a2018-08-12 17:19:55 -0700601 static_ft_funcs.free_instance ();
Behdad Esfahbodc7ca30a2018-08-12 13:46:53 -0700602}
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -0400603
Behdad Esfahbodc7ca30a2018-08-12 13:46:53 -0700604static hb_font_funcs_t *
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330605_hb_ft_get_font_funcs ()
Behdad Esfahbodc7ca30a2018-08-12 13:46:53 -0700606{
Behdad Esfahbod53442be2018-08-12 16:20:11 -0700607 return static_ft_funcs.get_unconst ();
Behdad Esfahbodc7ca30a2018-08-12 13:46:53 -0700608}
609
610static void
611_hb_ft_font_set_funcs (hb_font_t *font, FT_Face ft_face, bool unref)
612{
Behdad Esfahbod34f9aa52016-07-20 02:35:54 -0700613 bool symbol = ft_face->charmap && ft_face->charmap->encoding == FT_ENCODING_MS_SYMBOL;
614
Behdad Esfahbod26b96702020-06-28 14:52:15 -0700615 hb_ft_font_t *ft_font = _hb_ft_font_create (ft_face, symbol, unref);
616 if (unlikely (!ft_font)) return;
617
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -0400618 hb_font_set_funcs (font,
Behdad Esfahbodc7ca30a2018-08-12 13:46:53 -0700619 _hb_ft_get_font_funcs (),
Behdad Esfahbod26b96702020-06-28 14:52:15 -0700620 ft_font,
Behdad Esfahbode1b6d922017-10-11 15:51:31 +0200621 _hb_ft_font_destroy);
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -0500622}
623
624
625static hb_blob_t *
Ebrahim Byagowi9fea6b42019-07-05 18:46:41 +0430626_hb_ft_reference_table (hb_face_t *face HB_UNUSED, hb_tag_t tag, void *user_data)
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -0500627{
628 FT_Face ft_face = (FT_Face) user_data;
629 FT_Byte *buffer;
630 FT_ULong length = 0;
631 FT_Error error;
632
Behdad Esfahbod38973352011-08-08 23:37:41 +0200633 /* Note: FreeType like HarfBuzz uses the NONE tag for fetching the entire blob */
Behdad Esfahbod2cd1ea42010-04-29 14:15:32 -0400634
Behdad Esfahboddbdbfe32017-10-15 12:11:08 +0200635 error = FT_Load_Sfnt_Table (ft_face, tag, 0, nullptr, &length);
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -0500636 if (error)
Behdad Esfahboddbdbfe32017-10-15 12:11:08 +0200637 return nullptr;
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -0500638
Behdad Esfahbod2337f0d2021-07-08 10:58:50 -0600639 buffer = (FT_Byte *) hb_malloc (length);
Behdad Esfahbod68af14d2017-08-09 17:09:21 -0700640 if (!buffer)
Behdad Esfahboddbdbfe32017-10-15 12:11:08 +0200641 return nullptr;
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -0500642
643 error = FT_Load_Sfnt_Table (ft_face, tag, 0, buffer, &length);
Behdad Esfahbod42c183f2018-07-27 14:55:29 -0700644 if (error)
645 {
Behdad Esfahbod2337f0d2021-07-08 10:58:50 -0600646 hb_free (buffer);
Behdad Esfahboddbdbfe32017-10-15 12:11:08 +0200647 return nullptr;
prrace2e25d8f2018-07-27 13:58:27 -0700648 }
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -0500649
650 return hb_blob_create ((const char *) buffer, length,
651 HB_MEMORY_MODE_WRITABLE,
Behdad Esfahbod2337f0d2021-07-08 10:58:50 -0600652 buffer, hb_free);
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -0500653}
654
Behdad Esfahbodace5c7e2013-09-13 20:34:42 -0400655/**
656 * hb_ft_face_create:
Nathan Willis9126a5f2019-05-20 17:37:56 +0100657 * @ft_face: (destroy destroy) (scope notified): FT_Face to work upon
Khaled Hosny99364902020-12-31 00:19:29 +0200658 * @destroy: (nullable): A callback to call when the face object is not needed anymore
Behdad Esfahbodace5c7e2013-09-13 20:34:42 -0400659 *
Nathan Willis9126a5f2019-05-20 17:37:56 +0100660 * Creates an #hb_face_t face object from the specified FT_Face.
Behdad Esfahbodace5c7e2013-09-13 20:34:42 -0400661 *
Nathan Willis9126a5f2019-05-20 17:37:56 +0100662 * This variant of the function does not provide any life-cycle management.
Ebrahim Byagowi70d36542018-03-30 05:00:28 +0430663 *
Nathan Willis9126a5f2019-05-20 17:37:56 +0100664 * Most client programs should use hb_ft_face_create_referenced()
665 * (or, perhaps, hb_ft_face_create_cached()) instead.
666 *
667 * If you know you have valid reasons not to use hb_ft_face_create_referenced(),
668 * then it is the client program's responsibility to destroy @ft_face
669 * after the #hb_face_t face object has been destroyed.
670 *
671 * Return value: (transfer full): the new #hb_face_t face object
672 *
Behdad Esfahbodb8811422015-09-03 15:53:22 +0430673 * Since: 0.9.2
Behdad Esfahbodace5c7e2013-09-13 20:34:42 -0400674 **/
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -0500675hb_face_t *
676hb_ft_face_create (FT_Face ft_face,
677 hb_destroy_func_t destroy)
678{
679 hb_face_t *face;
680
Behdad Esfahbod68af14d2017-08-09 17:09:21 -0700681 if (!ft_face->stream->read) {
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -0500682 hb_blob_t *blob;
683
684 blob = hb_blob_create ((const char *) ft_face->stream->base,
685 (unsigned int) ft_face->stream->size,
Behdad Esfahbodaffacf22014-12-28 16:20:31 -0800686 HB_MEMORY_MODE_READONLY,
Behdad Esfahbod56681892011-04-20 03:03:32 -0400687 ft_face, destroy);
Behdad Esfahbod9a146882011-05-11 22:49:29 -0400688 face = hb_face_create (blob, ft_face->face_index);
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -0500689 hb_blob_destroy (blob);
690 } else {
Ebrahim Byagowi9fea6b42019-07-05 18:46:41 +0430691 face = hb_face_create_for_tables (_hb_ft_reference_table, ft_face, destroy);
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -0500692 }
693
Behdad Esfahbodde1e1cf2011-08-09 00:19:38 +0200694 hb_face_set_index (face, ft_face->face_index);
695 hb_face_set_upem (face, ft_face->units_per_EM);
696
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -0500697 return face;
698}
699
Behdad Esfahbod350f3a02014-12-28 17:44:26 -0800700/**
701 * hb_ft_face_create_referenced:
Nathan Willis9126a5f2019-05-20 17:37:56 +0100702 * @ft_face: FT_Face to work upon
Behdad Esfahbod350f3a02014-12-28 17:44:26 -0800703 *
Nathan Willis9126a5f2019-05-20 17:37:56 +0100704 * Creates an #hb_face_t face object from the specified FT_Face.
Behdad Esfahbod350f3a02014-12-28 17:44:26 -0800705 *
Nathan Willis9126a5f2019-05-20 17:37:56 +0100706 * This is the preferred variant of the hb_ft_face_create*
707 * function family, because it calls FT_Reference_Face() on @ft_face,
708 * ensuring that @ft_face remains alive as long as the resulting
n8willis80c01d72020-04-15 18:08:55 +0100709 * #hb_face_t face object remains alive. Also calls FT_Done_Face()
710 * when the #hb_face_t face object is destroyed.
Ebrahim Byagowi70d36542018-03-30 05:00:28 +0430711 *
Nathan Willis9126a5f2019-05-20 17:37:56 +0100712 * Use this version unless you know you have good reasons not to.
713 *
714 * Return value: (transfer full): the new #hb_face_t face object
715 *
Sascha Brawer01c3a882015-06-01 13:22:01 +0200716 * Since: 0.9.38
Behdad Esfahbod350f3a02014-12-28 17:44:26 -0800717 **/
718hb_face_t *
719hb_ft_face_create_referenced (FT_Face ft_face)
720{
721 FT_Reference_Face (ft_face);
Behdad Esfahbode1b6d922017-10-11 15:51:31 +0200722 return hb_ft_face_create (ft_face, _hb_ft_face_destroy);
Behdad Esfahbod350f3a02014-12-28 17:44:26 -0800723}
724
Behdad Esfahbod3648bdf2009-11-05 20:17:53 -0500725static void
726hb_ft_face_finalize (FT_Face ft_face)
727{
Behdad Esfahbod22da7fd2010-05-12 18:23:21 -0400728 hb_face_destroy ((hb_face_t *) ft_face->generic.data);
Behdad Esfahbod3648bdf2009-11-05 20:17:53 -0500729}
730
Behdad Esfahbodace5c7e2013-09-13 20:34:42 -0400731/**
732 * hb_ft_face_create_cached:
Nathan Willis9126a5f2019-05-20 17:37:56 +0100733 * @ft_face: FT_Face to work upon
Behdad Esfahbodace5c7e2013-09-13 20:34:42 -0400734 *
Nathan Willis9126a5f2019-05-20 17:37:56 +0100735 * Creates an #hb_face_t face object from the specified FT_Face.
Behdad Esfahbodace5c7e2013-09-13 20:34:42 -0400736 *
Nathan Willis9126a5f2019-05-20 17:37:56 +0100737 * This variant of the function caches the newly created #hb_face_t
n8willis9b916692020-04-13 16:40:15 +0100738 * face object, using the @generic pointer of @ft_face. Subsequent function
Nathan Willis9126a5f2019-05-20 17:37:56 +0100739 * calls that are passed the same @ft_face parameter will have the same
740 * #hb_face_t returned to them, and that #hb_face_t will be correctly
741 * reference counted.
Ebrahim Byagowi70d36542018-03-30 05:00:28 +0430742 *
Nathan Willis9126a5f2019-05-20 17:37:56 +0100743 * However, client programs are still responsible for destroying
744 * @ft_face after the last #hb_face_t face object has been destroyed.
745 *
746 * Return value: (transfer full): the new #hb_face_t face object
747 *
Behdad Esfahbodb8811422015-09-03 15:53:22 +0430748 * Since: 0.9.2
Behdad Esfahbodace5c7e2013-09-13 20:34:42 -0400749 **/
Behdad Esfahbod6358ff42009-11-05 17:39:16 -0500750hb_face_t *
751hb_ft_face_create_cached (FT_Face ft_face)
752{
Behdad Esfahbod64d3fc82010-05-03 22:51:19 -0400753 if (unlikely (!ft_face->generic.data || ft_face->generic.finalizer != (FT_Generic_Finalizer) hb_ft_face_finalize))
Behdad Esfahbodf4281e02009-11-05 17:58:41 -0500754 {
755 if (ft_face->generic.finalizer)
Behdad Esfahbodedb54e92009-11-06 15:19:22 -0500756 ft_face->generic.finalizer (ft_face);
Behdad Esfahbod6358ff42009-11-05 17:39:16 -0500757
Behdad Esfahboddbdbfe32017-10-15 12:11:08 +0200758 ft_face->generic.data = hb_ft_face_create (ft_face, nullptr);
Behdad Esfahbod3648bdf2009-11-05 20:17:53 -0500759 ft_face->generic.finalizer = (FT_Generic_Finalizer) hb_ft_face_finalize;
Behdad Esfahbodf4281e02009-11-05 17:58:41 -0500760 }
Behdad Esfahbod6358ff42009-11-05 17:39:16 -0500761
Behdad Esfahbod22da7fd2010-05-12 18:23:21 -0400762 return hb_face_reference ((hb_face_t *) ft_face->generic.data);
Behdad Esfahbod6358ff42009-11-05 17:39:16 -0500763}
764
Behdad Esfahbodace5c7e2013-09-13 20:34:42 -0400765/**
766 * hb_ft_font_create:
Nathan Willis9126a5f2019-05-20 17:37:56 +0100767 * @ft_face: (destroy destroy) (scope notified): FT_Face to work upon
Khaled Hosny99364902020-12-31 00:19:29 +0200768 * @destroy: (nullable): A callback to call when the font object is not needed anymore
Behdad Esfahbodace5c7e2013-09-13 20:34:42 -0400769 *
Nathan Willis9126a5f2019-05-20 17:37:56 +0100770 * Creates an #hb_font_t font object from the specified FT_Face.
Behdad Esfahbodace5c7e2013-09-13 20:34:42 -0400771 *
Nathan Willis9126a5f2019-05-20 17:37:56 +0100772 * <note>Note: You must set the face size on @ft_face before calling
Khaled Hosnyc7b2e642020-12-27 00:53:23 +0200773 * hb_ft_font_create() on it. HarfBuzz assumes size is always set and will
774 * access `size` member of FT_Face unconditionally.</note>
Ebrahim Byagowi70d36542018-03-30 05:00:28 +0430775 *
Nathan Willis9126a5f2019-05-20 17:37:56 +0100776 * This variant of the function does not provide any life-cycle management.
777 *
778 * Most client programs should use hb_ft_font_create_referenced()
779 * instead.
780 *
781 * If you know you have valid reasons not to use hb_ft_font_create_referenced(),
782 * then it is the client program's responsibility to destroy @ft_face
783 * after the #hb_font_t font object has been destroyed.
784 *
n8willisb57b9042020-04-15 18:46:31 +0100785 * HarfBuzz will use the @destroy callback on the #hb_font_t font object
786 * if it is supplied when you use this function. However, even if @destroy
787 * is provided, it is the client program's responsibility to destroy @ft_face,
788 * and it is the client program's responsibility to ensure that @ft_face is
789 * destroyed only after the #hb_font_t font object has been destroyed.
790 *
Nathan Willis9126a5f2019-05-20 17:37:56 +0100791 * Return value: (transfer full): the new #hb_font_t font object
792 *
Behdad Esfahbodb8811422015-09-03 15:53:22 +0430793 * Since: 0.9.2
Behdad Esfahbodace5c7e2013-09-13 20:34:42 -0400794 **/
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -0500795hb_font_t *
796hb_ft_font_create (FT_Face ft_face,
797 hb_destroy_func_t destroy)
798{
799 hb_font_t *font;
Behdad Esfahbodd2928852011-05-03 01:03:53 -0400800 hb_face_t *face;
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -0500801
Behdad Esfahbodd2928852011-05-03 01:03:53 -0400802 face = hb_ft_face_create (ft_face, destroy);
803 font = hb_font_create (face);
804 hb_face_destroy (face);
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -0400805 _hb_ft_font_set_funcs (font, ft_face, false);
Behdad Esfahbod4e478132017-10-12 10:33:16 +0200806 hb_ft_font_changed (font);
807 return font;
808}
809
Nathan Willis9126a5f2019-05-20 17:37:56 +0100810/**
Khaled Hosnya31a51c2020-12-30 23:48:25 +0200811 * hb_ft_font_changed:
Nathan Willis9126a5f2019-05-20 17:37:56 +0100812 * @font: #hb_font_t to work upon
813 *
814 * Refreshes the state of @font when the underlying FT_Face has changed.
815 * This function should be called after changing the size or
816 * variation-axis settings on the FT_Face.
817 *
818 * Since: 1.0.5
819 **/
Behdad Esfahbod4e478132017-10-12 10:33:16 +0200820void
821hb_ft_font_changed (hb_font_t *font)
822{
Behdad Esfahbodb8e406f2018-06-10 17:22:38 -0400823 if (font->destroy != (hb_destroy_func_t) _hb_ft_font_destroy)
Behdad Esfahbod4e478132017-10-12 10:33:16 +0200824 return;
825
826 hb_ft_font_t *ft_font = (hb_ft_font_t *) font->user_data;
Sebastian Rasmussen2267da42020-06-28 11:18:16 +0800827
Behdad Esfahbod4e478132017-10-12 10:33:16 +0200828 FT_Face ft_face = ft_font->ft_face;
829
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -0500830 hb_font_set_scale (font,
Behdad Esfahbod33317312016-08-08 17:24:04 -0700831 (int) (((uint64_t) ft_face->size->metrics.x_scale * (uint64_t) ft_face->units_per_EM + (1u<<15)) >> 16),
832 (int) (((uint64_t) ft_face->size->metrics.y_scale * (uint64_t) ft_face->units_per_EM + (1u<<15)) >> 16));
Behdad Esfahbodf34aaba2014-12-28 18:56:15 -0800833#if 0 /* hb-ft works in no-hinting model */
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -0500834 hb_font_set_ppem (font,
835 ft_face->size->metrics.x_ppem,
836 ft_face->size->metrics.y_ppem);
Behdad Esfahbodf34aaba2014-12-28 18:56:15 -0800837#endif
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -0500838
Behdad Esfahbode4a101e2019-11-19 20:04:00 -0500839#if defined(HAVE_FT_GET_VAR_BLEND_COORDINATES) && !defined(HB_NO_VAR)
Behdad Esfahboddbdbfe32017-10-15 12:11:08 +0200840 FT_MM_Var *mm_var = nullptr;
Behdad Esfahbod42c81422016-09-13 23:49:46 +0200841 if (!FT_Get_MM_Var (ft_face, &mm_var))
842 {
Behdad Esfahbod2337f0d2021-07-08 10:58:50 -0600843 FT_Fixed *ft_coords = (FT_Fixed *) hb_calloc (mm_var->num_axis, sizeof (FT_Fixed));
844 int *coords = (int *) hb_calloc (mm_var->num_axis, sizeof (int));
Behdad Esfahbod825e4042017-01-22 16:41:45 -0800845 if (coords && ft_coords)
Behdad Esfahbod42c81422016-09-13 23:49:46 +0200846 {
Behdad Esfahbod825e4042017-01-22 16:41:45 -0800847 if (!FT_Get_Var_Blend_Coordinates (ft_face, mm_var->num_axis, ft_coords))
848 {
Behdad Esfahbodcb43bdb2018-01-05 13:06:25 +0000849 bool nonzero = false;
Behdad Esfahbod42c81422016-09-13 23:49:46 +0200850
Behdad Esfahbodcb43bdb2018-01-05 13:06:25 +0000851 for (unsigned int i = 0; i < mm_var->num_axis; ++i)
852 {
853 coords[i] = ft_coords[i] >>= 2;
854 nonzero = nonzero || coords[i];
855 }
856
857 if (nonzero)
858 hb_font_set_var_coords_normalized (font, coords, mm_var->num_axis);
859 else
860 hb_font_set_var_coords_normalized (font, nullptr, 0);
Behdad Esfahbod825e4042017-01-22 16:41:45 -0800861 }
Sascha Brawer72873cf2016-09-13 18:40:07 +0200862 }
Behdad Esfahbod2337f0d2021-07-08 10:58:50 -0600863 hb_free (coords);
864 hb_free (ft_coords);
Behdad Esfahbod0473d952018-01-08 10:07:46 +0000865#ifdef HAVE_FT_DONE_MM_VAR
866 FT_Done_MM_Var (ft_face->glyph->library, mm_var);
867#else
Behdad Esfahbod2337f0d2021-07-08 10:58:50 -0600868 hb_free (mm_var);
Behdad Esfahbod0473d952018-01-08 10:07:46 +0000869#endif
Sascha Brawer72873cf2016-09-13 18:40:07 +0200870 }
Behdad Esfahbod42c81422016-09-13 23:49:46 +0200871#endif
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -0500872}
Behdad Esfahbodacdba3f2010-07-23 15:11:18 -0400873
Behdad Esfahbod350f3a02014-12-28 17:44:26 -0800874/**
875 * hb_ft_font_create_referenced:
Nathan Willis9126a5f2019-05-20 17:37:56 +0100876 * @ft_face: FT_Face to work upon
Behdad Esfahbod350f3a02014-12-28 17:44:26 -0800877 *
Nathan Willis9126a5f2019-05-20 17:37:56 +0100878 * Creates an #hb_font_t font object from the specified FT_Face.
Behdad Esfahbod350f3a02014-12-28 17:44:26 -0800879 *
Nathan Willis9126a5f2019-05-20 17:37:56 +0100880 * <note>Note: You must set the face size on @ft_face before calling
Khaled Hosnyc7b2e642020-12-27 00:53:23 +0200881 * hb_ft_font_create_referenced() on it. HarfBuzz assumes size is always set
882 * and will access `size` member of FT_Face unconditionally.</note>
Ebrahim Byagowi70d36542018-03-30 05:00:28 +0430883 *
Nathan Willis9126a5f2019-05-20 17:37:56 +0100884 * This is the preferred variant of the hb_ft_font_create*
885 * function family, because it calls FT_Reference_Face() on @ft_face,
886 * ensuring that @ft_face remains alive as long as the resulting
887 * #hb_font_t font object remains alive.
888 *
889 * Use this version unless you know you have good reasons not to.
890 *
891 * Return value: (transfer full): the new #hb_font_t font object
892 *
Sascha Brawer01c3a882015-06-01 13:22:01 +0200893 * Since: 0.9.38
Behdad Esfahbod350f3a02014-12-28 17:44:26 -0800894 **/
895hb_font_t *
896hb_ft_font_create_referenced (FT_Face ft_face)
897{
898 FT_Reference_Face (ft_face);
Behdad Esfahbode1b6d922017-10-11 15:51:31 +0200899 return hb_ft_font_create (ft_face, _hb_ft_face_destroy);
Behdad Esfahbod350f3a02014-12-28 17:44:26 -0800900}
901
Behdad Esfahboded116322021-09-14 07:09:54 -0400902static inline void free_static_ft_library ();
Behdad Esfahbodf64b2eb2012-06-05 19:23:29 -0400903
Behdad Esfahbod54ece292019-04-16 16:45:53 -0400904static struct hb_ft_library_lazy_loader_t : hb_lazy_loader_t<hb_remove_pointer<FT_Library>,
Behdad Esfahbod69010902018-08-12 16:57:06 -0700905 hb_ft_library_lazy_loader_t>
Behdad Esfahbod53442be2018-08-12 16:20:11 -0700906{
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330907 static FT_Library create ()
Behdad Esfahbod53442be2018-08-12 16:20:11 -0700908 {
909 FT_Library l;
910 if (FT_Init_FreeType (&l))
911 return nullptr;
912
Behdad Esfahboded116322021-09-14 07:09:54 -0400913 hb_atexit (free_static_ft_library);
Behdad Esfahbod53442be2018-08-12 16:20:11 -0700914
915 return l;
916 }
Ebrahim Byagowib2ebaa92018-12-16 22:38:10 +0330917 static void destroy (FT_Library l)
Behdad Esfahbod53442be2018-08-12 16:20:11 -0700918 {
919 FT_Done_FreeType (l);
920 }
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330921 static FT_Library get_null ()
Behdad Esfahbod53442be2018-08-12 16:20:11 -0700922 {
923 return nullptr;
924 }
925} static_ft_library;
Behdad Esfahbod38b21182011-08-09 10:51:24 +0200926
Behdad Esfahboded116322021-09-14 07:09:54 -0400927static inline
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330928void free_static_ft_library ()
Behdad Esfahbod04aed572012-06-05 18:30:19 -0400929{
Behdad Esfahbod7bd508a2018-08-12 17:19:55 -0700930 static_ft_library.free_instance ();
Behdad Esfahbod04aed572012-06-05 18:30:19 -0400931}
932
933static FT_Library
Ebrahim Byagowie4120082018-12-17 21:31:01 +0330934get_ft_library ()
Behdad Esfahbod04aed572012-06-05 18:30:19 -0400935{
Behdad Esfahbod53442be2018-08-12 16:20:11 -0700936 return static_ft_library.get_unconst ();
Behdad Esfahbod38b21182011-08-09 10:51:24 +0200937}
938
939static void
940_release_blob (FT_Face ft_face)
941{
942 hb_blob_destroy ((hb_blob_t *) ft_face->generic.data);
943}
944
Nathan Willis9126a5f2019-05-20 17:37:56 +0100945/**
946 * hb_ft_font_set_funcs:
947 * @font: #hb_font_t to work upon
948 *
949 * Configures the font-functions structure of the specified
950 * #hb_font_t font object to use FreeType font functions.
951 *
n8willis1bca2be2020-04-15 18:30:47 +0100952 * In particular, you can use this function to configure an
953 * existing #hb_face_t face object for use with FreeType font
954 * functions even if that #hb_face_t face object was initially
955 * created with hb_face_create(), and therefore was not
956 * initially configured to use FreeType font functions.
957 *
958 * An #hb_face_t face object created with hb_ft_face_create()
959 * is preconfigured for FreeType font functions and does not
960 * require this function to be used.
961 *
Nathan Willis9126a5f2019-05-20 17:37:56 +0100962 * <note>Note: Internally, this function creates an FT_Face.
n8willis1bca2be2020-04-15 18:30:47 +0100963* </note>
Nathan Willis9126a5f2019-05-20 17:37:56 +0100964 *
965 * Since: 1.0.5
966 **/
Behdad Esfahbod38b21182011-08-09 10:51:24 +0200967void
968hb_ft_font_set_funcs (hb_font_t *font)
969{
970 hb_blob_t *blob = hb_face_reference_blob (font->face);
971 unsigned int blob_length;
972 const char *blob_data = hb_blob_get_data (blob, &blob_length);
973 if (unlikely (!blob_length))
974 DEBUG_MSG (FT, font, "Font face has empty blob");
975
Behdad Esfahboddbdbfe32017-10-15 12:11:08 +0200976 FT_Face ft_face = nullptr;
Behdad Esfahbod04aed572012-06-05 18:30:19 -0400977 FT_Error err = FT_New_Memory_Face (get_ft_library (),
Behdad Esfahbod38b21182011-08-09 10:51:24 +0200978 (const FT_Byte *) blob_data,
979 blob_length,
980 hb_face_get_index (font->face),
981 &ft_face);
982
983 if (unlikely (err)) {
984 hb_blob_destroy (blob);
985 DEBUG_MSG (FT, font, "Font face FT_New_Memory_Face() failed");
986 return;
987 }
988
Khaled Hosny0954c8f2019-09-01 17:09:08 +0200989 if (FT_Select_Charmap (ft_face, FT_ENCODING_MS_SYMBOL))
990 FT_Select_Charmap (ft_face, FT_ENCODING_UNICODE);
Behdad Esfahbod254142b2011-08-15 16:15:44 +0200991
Behdad Esfahbod38b21182011-08-09 10:51:24 +0200992 FT_Set_Char_Size (ft_face,
Behdad Esfahboda319d072015-01-23 12:44:24 -0800993 abs (font->x_scale), abs (font->y_scale),
Behdad Esfahbod2023e2b2012-07-11 19:00:30 -0400994 0, 0);
995#if 0
Behdad Esfahbod38b21182011-08-09 10:51:24 +0200996 font->x_ppem * 72 * 64 / font->x_scale,
997 font->y_ppem * 72 * 64 / font->y_scale);
Behdad Esfahbod2023e2b2012-07-11 19:00:30 -0400998#endif
Behdad Esfahboda319d072015-01-23 12:44:24 -0800999 if (font->x_scale < 0 || font->y_scale < 0)
1000 {
1001 FT_Matrix matrix = { font->x_scale < 0 ? -1 : +1, 0,
1002 0, font->y_scale < 0 ? -1 : +1};
Behdad Esfahboddbdbfe32017-10-15 12:11:08 +02001003 FT_Set_Transform (ft_face, &matrix, nullptr);
Behdad Esfahboda319d072015-01-23 12:44:24 -08001004 }
Behdad Esfahbod38b21182011-08-09 10:51:24 +02001005
Behdad Esfahbode4a101e2019-11-19 20:04:00 -05001006#if defined(HAVE_FT_GET_VAR_BLEND_COORDINATES) && !defined(HB_NO_VAR)
Behdad Esfahbod47ee34e2017-01-21 18:10:08 -08001007 unsigned int num_coords;
Behdad Esfahbod7647a052017-01-22 17:47:49 -08001008 const int *coords = hb_font_get_var_coords_normalized (font, &num_coords);
Behdad Esfahbod47ee34e2017-01-21 18:10:08 -08001009 if (num_coords)
1010 {
Behdad Esfahbod2337f0d2021-07-08 10:58:50 -06001011 FT_Fixed *ft_coords = (FT_Fixed *) hb_calloc (num_coords, sizeof (FT_Fixed));
Behdad Esfahbod825e4042017-01-22 16:41:45 -08001012 if (ft_coords)
1013 {
1014 for (unsigned int i = 0; i < num_coords; i++)
Ebrahim Byagowibb41b742019-09-18 00:55:24 +04301015 ft_coords[i] = coords[i] * 4;
Behdad Esfahbod825e4042017-01-22 16:41:45 -08001016 FT_Set_Var_Blend_Coordinates (ft_face, num_coords, ft_coords);
Behdad Esfahbod2337f0d2021-07-08 10:58:50 -06001017 hb_free (ft_coords);
Behdad Esfahbod825e4042017-01-22 16:41:45 -08001018 }
Behdad Esfahbod47ee34e2017-01-21 18:10:08 -08001019 }
Olivier Blin0fd89dc2017-12-04 18:58:41 +01001020#endif
Behdad Esfahbod47ee34e2017-01-21 18:10:08 -08001021
Behdad Esfahbod38b21182011-08-09 10:51:24 +02001022 ft_face->generic.data = blob;
1023 ft_face->generic.finalizer = (FT_Generic_Finalizer) _release_blob;
1024
Behdad Esfahbod2a9627c2015-10-07 17:33:20 -04001025 _hb_ft_font_set_funcs (font, ft_face, true);
1026 hb_ft_font_set_load_flags (font, FT_LOAD_DEFAULT | FT_LOAD_NO_HINTING);
Behdad Esfahbod01ec13a2011-08-10 22:00:35 +02001027}
Behdad Esfahbodaa3450c2019-06-17 22:41:49 -07001028
1029
1030#endif