blob: c2f6f6ddd55dfe45cc17bedfe2dbace02033744d [file] [log] [blame]
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04001/*
Behdad Esfahbod2409d5f2011-04-21 17:14:28 -04002 * Copyright © 2009 Red Hat, Inc.
Behdad Esfahbod027857d2012-07-26 17:34:25 -04003 * Copyright © 2012 Google, Inc.
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04004 *
Behdad Esfahbodc755cb32010-04-22 00:11:43 -04005 * This is part of HarfBuzz, a text shaping library.
Behdad Esfahbodc62b5032009-08-01 19:54:49 -04006 *
7 * Permission is hereby granted, without written agreement and without
8 * license or royalty fees, to use, copy, modify, and distribute this
9 * software and its documentation for any purpose, provided that the
10 * above copyright notice and the following two paragraphs appear in
11 * all copies of this software.
12 *
13 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
14 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
15 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
16 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
17 * DAMAGE.
18 *
19 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
20 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
22 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
23 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24 *
25 * Red Hat Author(s): Behdad Esfahbod
Behdad Esfahbod027857d2012-07-26 17:34:25 -040026 * Google Author(s): Behdad Esfahbod
Behdad Esfahbodc62b5032009-08-01 19:54:49 -040027 */
28
Behdad Esfahbodc57d4542011-04-20 18:50:27 -040029#include "hb-private.hh"
Behdad Esfahbodc62b5032009-08-01 19:54:49 -040030
Behdad Esfahbod266b3442011-05-03 00:35:53 -040031#include "hb-ot-layout-private.hh"
32
Behdad Esfahbodc57d4542011-04-20 18:50:27 -040033#include "hb-font-private.hh"
Behdad Esfahbod56eb5ad2011-05-04 19:27:37 -040034#include "hb-blob.h"
Behdad Esfahbod23c86aa2009-08-03 21:40:20 -040035#include "hb-open-file-private.hh"
Behdad Esfahbod7a750ac2011-08-17 14:19:59 +020036#include "hb-ot-head-table.hh"
Behdad Esfahbode05a9992012-11-15 16:23:21 -080037#include "hb-ot-maxp-table.hh"
Behdad Esfahbodc62b5032009-08-01 19:54:49 -040038
Behdad Esfahbod20fdb0f2012-05-17 22:04:45 -040039#include "hb-cache-private.hh"
40
Behdad Esfahbod79512792009-11-03 20:27:05 -050041#include <string.h>
42
Behdad Esfahbodacdba3f2010-07-23 15:11:18 -040043
Behdad Esfahbodc62b5032009-08-01 19:54:49 -040044/*
Behdad Esfahbod5c441882009-08-10 20:05:16 -040045 * hb_font_funcs_t
Behdad Esfahbodc62b5032009-08-01 19:54:49 -040046 */
47
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -040048static hb_bool_t
Behdad Esfahbodbce09552012-05-27 11:29:21 -040049hb_font_get_glyph_nil (hb_font_t *font,
Behdad Esfahbodb4678272011-05-11 23:25:28 -040050 void *font_data HB_UNUSED,
Behdad Esfahboda513dbc2011-05-11 00:24:34 -040051 hb_codepoint_t unicode,
52 hb_codepoint_t variation_selector,
Behdad Esfahbod0fd8c2f2011-05-12 15:14:13 -040053 hb_codepoint_t *glyph,
Behdad Esfahbodb4678272011-05-11 23:25:28 -040054 void *user_data HB_UNUSED)
Behdad Esfahbod1ded6d82011-05-10 20:49:02 -040055{
56 if (font->parent)
Behdad Esfahbod4c8ac4f2012-08-08 17:44:19 -040057 return font->parent->get_glyph (unicode, variation_selector, glyph);
Behdad Esfahbod1ded6d82011-05-10 20:49:02 -040058
Behdad Esfahbod0fd8c2f2011-05-12 15:14:13 -040059 *glyph = 0;
Behdad Esfahbod0594a242012-06-05 20:35:40 -040060 return false;
Behdad Esfahbod1ded6d82011-05-10 20:49:02 -040061}
Behdad Esfahbod79512792009-11-03 20:27:05 -050062
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -040063static hb_position_t
Behdad Esfahbodbce09552012-05-27 11:29:21 -040064hb_font_get_glyph_h_advance_nil (hb_font_t *font,
Behdad Esfahbod744970a2011-05-16 18:15:37 -040065 void *font_data HB_UNUSED,
66 hb_codepoint_t glyph,
Behdad Esfahbod744970a2011-05-16 18:15:37 -040067 void *user_data HB_UNUSED)
Behdad Esfahbod1ded6d82011-05-10 20:49:02 -040068{
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -040069 if (font->parent)
Behdad Esfahbod4c8ac4f2012-08-08 17:44:19 -040070 return font->parent_scale_x_distance (font->parent->get_glyph_h_advance (glyph));
Behdad Esfahbod744970a2011-05-16 18:15:37 -040071
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -040072 return font->x_scale;
Behdad Esfahbod744970a2011-05-16 18:15:37 -040073}
74
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -040075static hb_position_t
Behdad Esfahbodbce09552012-05-27 11:29:21 -040076hb_font_get_glyph_v_advance_nil (hb_font_t *font,
Behdad Esfahbod744970a2011-05-16 18:15:37 -040077 void *font_data HB_UNUSED,
78 hb_codepoint_t glyph,
Behdad Esfahbod744970a2011-05-16 18:15:37 -040079 void *user_data HB_UNUSED)
80{
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -040081 if (font->parent)
Behdad Esfahbod4c8ac4f2012-08-08 17:44:19 -040082 return font->parent_scale_y_distance (font->parent->get_glyph_v_advance (glyph));
Behdad Esfahbod744970a2011-05-16 18:15:37 -040083
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -040084 return font->y_scale;
Behdad Esfahbod744970a2011-05-16 18:15:37 -040085}
86
87static hb_bool_t
Behdad Esfahbodbce09552012-05-27 11:29:21 -040088hb_font_get_glyph_h_origin_nil (hb_font_t *font,
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -040089 void *font_data HB_UNUSED,
90 hb_codepoint_t glyph,
Behdad Esfahbod19098182011-05-17 23:27:22 -040091 hb_position_t *x,
92 hb_position_t *y,
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -040093 void *user_data HB_UNUSED)
94{
95 if (font->parent) {
Behdad Esfahbod4c8ac4f2012-08-08 17:44:19 -040096 hb_bool_t ret = font->parent->get_glyph_h_origin (glyph, x, y);
Behdad Esfahbod60fbb362011-05-19 18:46:15 -040097 if (ret)
98 font->parent_scale_position (x, y);
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -040099 return ret;
100 }
101
Behdad Esfahbod19098182011-05-17 23:27:22 -0400102 *x = *y = 0;
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400103 return false;
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400104}
105
106static hb_bool_t
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400107hb_font_get_glyph_v_origin_nil (hb_font_t *font,
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400108 void *font_data HB_UNUSED,
109 hb_codepoint_t glyph,
Behdad Esfahbod19098182011-05-17 23:27:22 -0400110 hb_position_t *x,
111 hb_position_t *y,
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400112 void *user_data HB_UNUSED)
113{
114 if (font->parent) {
Behdad Esfahbod4c8ac4f2012-08-08 17:44:19 -0400115 hb_bool_t ret = font->parent->get_glyph_v_origin (glyph, x, y);
Behdad Esfahbod60fbb362011-05-19 18:46:15 -0400116 if (ret)
117 font->parent_scale_position (x, y);
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400118 return ret;
119 }
120
Behdad Esfahbod19098182011-05-17 23:27:22 -0400121 *x = *y = 0;
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400122 return false;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400123}
124
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400125static hb_position_t
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400126hb_font_get_glyph_h_kerning_nil (hb_font_t *font,
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400127 void *font_data HB_UNUSED,
128 hb_codepoint_t left_glyph,
129 hb_codepoint_t right_glyph,
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400130 void *user_data HB_UNUSED)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400131{
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400132 if (font->parent)
Behdad Esfahbod4c8ac4f2012-08-08 17:44:19 -0400133 return font->parent_scale_x_distance (font->parent->get_glyph_h_kerning (left_glyph, right_glyph));
Behdad Esfahbod1ded6d82011-05-10 20:49:02 -0400134
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400135 return 0;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400136}
137
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400138static hb_position_t
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400139hb_font_get_glyph_v_kerning_nil (hb_font_t *font,
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400140 void *font_data HB_UNUSED,
141 hb_codepoint_t top_glyph,
142 hb_codepoint_t bottom_glyph,
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400143 void *user_data HB_UNUSED)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400144{
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400145 if (font->parent)
Behdad Esfahbod4c8ac4f2012-08-08 17:44:19 -0400146 return font->parent_scale_y_distance (font->parent->get_glyph_v_kerning (top_glyph, bottom_glyph));
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400147
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400148 return 0;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400149}
150
151static hb_bool_t
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400152hb_font_get_glyph_extents_nil (hb_font_t *font,
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400153 void *font_data HB_UNUSED,
154 hb_codepoint_t glyph,
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400155 hb_glyph_extents_t *extents,
156 void *user_data HB_UNUSED)
157{
158 if (font->parent) {
Behdad Esfahbod4c8ac4f2012-08-08 17:44:19 -0400159 hb_bool_t ret = font->parent->get_glyph_extents (glyph, extents);
Behdad Esfahbod60fbb362011-05-19 18:46:15 -0400160 if (ret) {
161 font->parent_scale_position (&extents->x_bearing, &extents->y_bearing);
162 font->parent_scale_distance (&extents->width, &extents->height);
163 }
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400164 return ret;
165 }
166
Behdad Esfahbod60fbb362011-05-19 18:46:15 -0400167 memset (extents, 0, sizeof (*extents));
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400168 return false;
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400169}
170
171static hb_bool_t
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400172hb_font_get_glyph_contour_point_nil (hb_font_t *font,
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400173 void *font_data HB_UNUSED,
174 hb_codepoint_t glyph,
175 unsigned int point_index,
176 hb_position_t *x,
177 hb_position_t *y,
178 void *user_data HB_UNUSED)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400179{
180 if (font->parent) {
Behdad Esfahbod4c8ac4f2012-08-08 17:44:19 -0400181 hb_bool_t ret = font->parent->get_glyph_contour_point (glyph, point_index, x, y);
Behdad Esfahbod60fbb362011-05-19 18:46:15 -0400182 if (ret)
183 font->parent_scale_position (x, y);
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400184 return ret;
185 }
186
187 *x = *y = 0;
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400188 return false;
Behdad Esfahbod1ded6d82011-05-10 20:49:02 -0400189}
Behdad Esfahbod79512792009-11-03 20:27:05 -0500190
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400191static hb_bool_t
192hb_font_get_glyph_name_nil (hb_font_t *font,
193 void *font_data HB_UNUSED,
194 hb_codepoint_t glyph,
195 char *name, unsigned int size,
196 void *user_data HB_UNUSED)
197{
198 if (font->parent)
Behdad Esfahbod4c8ac4f2012-08-08 17:44:19 -0400199 return font->parent->get_glyph_name (glyph, name, size);
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400200
Behdad Esfahbod6f3a3002012-08-07 22:13:25 -0400201 if (size) *name = '\0';
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400202 return false;
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400203}
204
205static hb_bool_t
206hb_font_get_glyph_from_name_nil (hb_font_t *font,
207 void *font_data HB_UNUSED,
208 const char *name, int len, /* -1 means nul-terminated */
209 hb_codepoint_t *glyph,
210 void *user_data HB_UNUSED)
211{
212 if (font->parent)
Behdad Esfahbod4c8ac4f2012-08-08 17:44:19 -0400213 return font->parent->get_glyph_from_name (name, len, glyph);
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400214
215 *glyph = 0;
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400216 return false;
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400217}
218
Behdad Esfahbod56eb5ad2011-05-04 19:27:37 -0400219
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -0400220static const hb_font_funcs_t _hb_font_funcs_nil = {
Behdad Esfahbodfca368c2011-04-21 18:24:02 -0400221 HB_OBJECT_HEADER_STATIC,
222
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400223 true, /* immutable */
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400224
Behdad Esfahbodbf36a102010-05-24 17:46:21 +0100225 {
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400226#define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_nil,
227 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
228#undef HB_FONT_FUNC_IMPLEMENT
Behdad Esfahbodbf36a102010-05-24 17:46:21 +0100229 }
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400230};
231
Behdad Esfahbod56eb5ad2011-05-04 19:27:37 -0400232
Behdad Esfahbod5c441882009-08-10 20:05:16 -0400233hb_font_funcs_t *
234hb_font_funcs_create (void)
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400235{
Behdad Esfahbod5c441882009-08-10 20:05:16 -0400236 hb_font_funcs_t *ffuncs;
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400237
Behdad Esfahbod47e71d92011-04-27 16:38:03 -0400238 if (!(ffuncs = hb_object_create<hb_font_funcs_t> ()))
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -0400239 return hb_font_funcs_get_empty ();
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400240
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400241 ffuncs->get = _hb_font_funcs_nil.get;
Behdad Esfahbodf97bf4f2010-05-24 17:50:19 +0100242
Behdad Esfahbod5c441882009-08-10 20:05:16 -0400243 return ffuncs;
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400244}
245
Behdad Esfahbod5c441882009-08-10 20:05:16 -0400246hb_font_funcs_t *
Behdad Esfahbod80a68332011-05-11 18:14:44 -0400247hb_font_funcs_get_empty (void)
248{
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -0400249 return const_cast<hb_font_funcs_t *> (&_hb_font_funcs_nil);
Behdad Esfahbod80a68332011-05-11 18:14:44 -0400250}
251
252hb_font_funcs_t *
Behdad Esfahbod5c441882009-08-10 20:05:16 -0400253hb_font_funcs_reference (hb_font_funcs_t *ffuncs)
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400254{
Behdad Esfahbod47e71d92011-04-27 16:38:03 -0400255 return hb_object_reference (ffuncs);
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400256}
257
258void
Behdad Esfahbod5c441882009-08-10 20:05:16 -0400259hb_font_funcs_destroy (hb_font_funcs_t *ffuncs)
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400260{
Behdad Esfahbod47e71d92011-04-27 16:38:03 -0400261 if (!hb_object_destroy (ffuncs)) return;
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400262
Behdad Esfahbod4b6317c2011-07-07 23:14:42 -0400263#define HB_FONT_FUNC_IMPLEMENT(name) if (ffuncs->destroy.name) \
264 ffuncs->destroy.name (ffuncs->user_data.name);
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400265 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
266#undef HB_FONT_FUNC_IMPLEMENT
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400267
Behdad Esfahbod5c441882009-08-10 20:05:16 -0400268 free (ffuncs);
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400269}
270
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -0400271hb_bool_t
272hb_font_funcs_set_user_data (hb_font_funcs_t *ffuncs,
273 hb_user_data_key_t *key,
274 void * data,
Behdad Esfahbod33ccc772011-08-09 00:43:24 +0200275 hb_destroy_func_t destroy,
276 hb_bool_t replace)
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -0400277{
Behdad Esfahbod33ccc772011-08-09 00:43:24 +0200278 return hb_object_set_user_data (ffuncs, key, data, destroy, replace);
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -0400279}
280
281void *
282hb_font_funcs_get_user_data (hb_font_funcs_t *ffuncs,
283 hb_user_data_key_t *key)
284{
285 return hb_object_get_user_data (ffuncs, key);
286}
287
288
Behdad Esfahbod8d703122009-08-10 23:50:51 -0400289void
290hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs)
291{
Behdad Esfahbod47e71d92011-04-27 16:38:03 -0400292 if (hb_object_is_inert (ffuncs))
Behdad Esfahbod8d703122009-08-10 23:50:51 -0400293 return;
294
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400295 ffuncs->immutable = true;
Behdad Esfahbod8d703122009-08-10 23:50:51 -0400296}
297
Behdad Esfahbod645f6f22010-10-04 17:01:01 -0400298hb_bool_t
299hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs)
300{
Behdad Esfahbod3111b8a2010-10-13 10:41:53 -0400301 return ffuncs->immutable;
Behdad Esfahbod645f6f22010-10-04 17:01:01 -0400302}
303
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400304
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400305#define HB_FONT_FUNC_IMPLEMENT(name) \
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400306 \
307void \
308hb_font_funcs_set_##name##_func (hb_font_funcs_t *ffuncs, \
309 hb_font_get_##name##_func_t func, \
310 void *user_data, \
311 hb_destroy_func_t destroy) \
312{ \
Behdad Esfahbod0cd33592011-09-21 16:49:33 -0400313 if (ffuncs->immutable) { \
314 if (destroy) \
315 destroy (user_data); \
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400316 return; \
Behdad Esfahbod0cd33592011-09-21 16:49:33 -0400317 } \
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400318 \
319 if (ffuncs->destroy.name) \
320 ffuncs->destroy.name (ffuncs->user_data.name); \
321 \
322 if (func) { \
323 ffuncs->get.name = func; \
324 ffuncs->user_data.name = user_data; \
325 ffuncs->destroy.name = destroy; \
326 } else { \
327 ffuncs->get.name = hb_font_get_##name##_nil; \
328 ffuncs->user_data.name = NULL; \
329 ffuncs->destroy.name = NULL; \
330 } \
Behdad Esfahbod79512792009-11-03 20:27:05 -0500331}
332
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400333HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
334#undef HB_FONT_FUNC_IMPLEMENT
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400335
Behdad Esfahbod502f4cb2010-10-27 01:13:56 -0400336
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400337/* Public getters */
338
Behdad Esfahbod0fd8c2f2011-05-12 15:14:13 -0400339hb_bool_t
Behdad Esfahbodb9d975b2011-05-10 20:41:13 -0400340hb_font_get_glyph (hb_font_t *font,
Behdad Esfahbod0fd8c2f2011-05-12 15:14:13 -0400341 hb_codepoint_t unicode, hb_codepoint_t variation_selector,
342 hb_codepoint_t *glyph)
Behdad Esfahbod2e336692009-11-05 13:55:41 -0500343{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400344 return font->get_glyph (unicode, variation_selector, glyph);
Behdad Esfahbod2e336692009-11-05 13:55:41 -0500345}
346
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400347hb_position_t
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400348hb_font_get_glyph_h_advance (hb_font_t *font,
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400349 hb_codepoint_t glyph)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400350{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400351 return font->get_glyph_h_advance (glyph);
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400352}
353
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400354hb_position_t
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400355hb_font_get_glyph_v_advance (hb_font_t *font,
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400356 hb_codepoint_t glyph)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400357{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400358 return font->get_glyph_v_advance (glyph);
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400359}
360
361hb_bool_t
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400362hb_font_get_glyph_h_origin (hb_font_t *font,
363 hb_codepoint_t glyph,
Behdad Esfahbod19098182011-05-17 23:27:22 -0400364 hb_position_t *x, hb_position_t *y)
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400365{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400366 return font->get_glyph_h_origin (glyph, x, y);
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400367}
368
369hb_bool_t
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400370hb_font_get_glyph_v_origin (hb_font_t *font,
371 hb_codepoint_t glyph,
Behdad Esfahbod19098182011-05-17 23:27:22 -0400372 hb_position_t *x, hb_position_t *y)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400373{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400374 return font->get_glyph_v_origin (glyph, x, y);
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400375}
376
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400377hb_position_t
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400378hb_font_get_glyph_h_kerning (hb_font_t *font,
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400379 hb_codepoint_t left_glyph, hb_codepoint_t right_glyph)
Behdad Esfahbod2e336692009-11-05 13:55:41 -0500380{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400381 return font->get_glyph_h_kerning (left_glyph, right_glyph);
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400382}
383
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400384hb_position_t
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400385hb_font_get_glyph_v_kerning (hb_font_t *font,
Behdad Esfahbod2d8ebcb2011-05-25 11:27:33 -0400386 hb_codepoint_t left_glyph, hb_codepoint_t right_glyph)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400387{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400388 return font->get_glyph_v_kerning (left_glyph, right_glyph);
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400389}
390
391hb_bool_t
392hb_font_get_glyph_extents (hb_font_t *font,
393 hb_codepoint_t glyph,
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400394 hb_glyph_extents_t *extents)
395{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400396 return font->get_glyph_extents (glyph, extents);
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400397}
398
399hb_bool_t
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400400hb_font_get_glyph_contour_point (hb_font_t *font,
401 hb_codepoint_t glyph, unsigned int point_index,
402 hb_position_t *x, hb_position_t *y)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400403{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400404 return font->get_glyph_contour_point (glyph, point_index, x, y);
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400405}
406
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400407hb_bool_t
408hb_font_get_glyph_name (hb_font_t *font,
409 hb_codepoint_t glyph,
410 char *name, unsigned int size)
411{
Behdad Esfahbod6f3a3002012-08-07 22:13:25 -0400412 return font->get_glyph_name (glyph, name, size);
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400413}
414
415hb_bool_t
416hb_font_get_glyph_from_name (hb_font_t *font,
417 const char *name, int len, /* -1 means nul-terminated */
418 hb_codepoint_t *glyph)
419{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400420 return font->get_glyph_from_name (name, len, glyph);
Behdad Esfahbodbce09552012-05-27 11:29:21 -0400421}
422
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400423
424/* A bit higher-level, and with fallback */
425
426void
427hb_font_get_glyph_advance_for_direction (hb_font_t *font,
428 hb_codepoint_t glyph,
429 hb_direction_t direction,
Behdad Esfahbod19098182011-05-17 23:27:22 -0400430 hb_position_t *x, hb_position_t *y)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400431{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400432 return font->get_glyph_advance_for_direction (glyph, direction, x, y);
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400433}
434
435void
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400436hb_font_get_glyph_origin_for_direction (hb_font_t *font,
437 hb_codepoint_t glyph,
438 hb_direction_t direction,
Behdad Esfahbod19098182011-05-17 23:27:22 -0400439 hb_position_t *x, hb_position_t *y)
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400440{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400441 return font->get_glyph_origin_for_direction (glyph, direction, x, y);
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400442}
443
444void
Behdad Esfahbod8b38fae2011-05-19 13:08:00 -0400445hb_font_add_glyph_origin_for_direction (hb_font_t *font,
446 hb_codepoint_t glyph,
447 hb_direction_t direction,
448 hb_position_t *x, hb_position_t *y)
449{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400450 return font->add_glyph_origin_for_direction (glyph, direction, x, y);
Behdad Esfahbod8b38fae2011-05-19 13:08:00 -0400451}
452
453void
454hb_font_subtract_glyph_origin_for_direction (hb_font_t *font,
455 hb_codepoint_t glyph,
456 hb_direction_t direction,
457 hb_position_t *x, hb_position_t *y)
458{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400459 return font->subtract_glyph_origin_for_direction (glyph, direction, x, y);
Behdad Esfahbod8b38fae2011-05-19 13:08:00 -0400460}
461
462void
Behdad Esfahbod7e2c85d2011-05-17 17:55:03 -0400463hb_font_get_glyph_kerning_for_direction (hb_font_t *font,
464 hb_codepoint_t first_glyph, hb_codepoint_t second_glyph,
465 hb_direction_t direction,
Behdad Esfahbod19098182011-05-17 23:27:22 -0400466 hb_position_t *x, hb_position_t *y)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400467{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400468 return font->get_glyph_kerning_for_direction (first_glyph, second_glyph, direction, x, y);
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400469}
470
Behdad Esfahbod60fbb362011-05-19 18:46:15 -0400471hb_bool_t
472hb_font_get_glyph_extents_for_origin (hb_font_t *font,
473 hb_codepoint_t glyph,
474 hb_direction_t direction,
475 hb_glyph_extents_t *extents)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400476{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400477 return font->get_glyph_extents_for_origin (glyph, direction, extents);
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400478}
479
480hb_bool_t
Behdad Esfahbod60fbb362011-05-19 18:46:15 -0400481hb_font_get_glyph_contour_point_for_origin (hb_font_t *font,
482 hb_codepoint_t glyph, unsigned int point_index,
483 hb_direction_t direction,
484 hb_position_t *x, hb_position_t *y)
Behdad Esfahbod744970a2011-05-16 18:15:37 -0400485{
Behdad Esfahbod8fbfda92012-08-01 19:03:46 -0400486 return font->get_glyph_contour_point_for_origin (glyph, point_index, direction, x, y);
Behdad Esfahbod2e336692009-11-05 13:55:41 -0500487}
488
Behdad Esfahbod6f3a3002012-08-07 22:13:25 -0400489/* Generates gidDDD if glyph has no name. */
490void
491hb_font_glyph_to_string (hb_font_t *font,
492 hb_codepoint_t glyph,
493 char *s, unsigned int size)
494{
495 font->glyph_to_string (glyph, s, size);
496}
497
498/* Parses gidDDD and uniUUUU strings automatically. */
499hb_bool_t
500hb_font_glyph_from_string (hb_font_t *font,
501 const char *s, int len, /* -1 means nul-terminated */
502 hb_codepoint_t *glyph)
503{
504 return font->glyph_from_string (s, len, glyph);
505}
506
Behdad Esfahbod1cebfbb2010-04-23 20:49:18 -0400507
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400508/*
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400509 * hb_font_t
510 */
511
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400512hb_font_t *
Behdad Esfahbod72657e42011-05-02 20:46:32 -0400513hb_font_create (hb_face_t *face)
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400514{
515 hb_font_t *font;
516
Behdad Esfahbod72657e42011-05-02 20:46:32 -0400517 if (unlikely (!face))
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -0400518 face = hb_face_get_empty ();
Behdad Esfahbod72657e42011-05-02 20:46:32 -0400519 if (unlikely (hb_object_is_inert (face)))
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -0400520 return hb_font_get_empty ();
Behdad Esfahbod47e71d92011-04-27 16:38:03 -0400521 if (!(font = hb_object_create<hb_font_t> ()))
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -0400522 return hb_font_get_empty ();
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400523
Behdad Esfahbod7fc5a302011-05-12 17:48:20 -0400524 hb_face_make_immutable (face);
Behdad Esfahbod72657e42011-05-02 20:46:32 -0400525 font->face = hb_face_reference (face);
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -0400526 font->klass = hb_font_funcs_get_empty ();
Behdad Esfahbod85555a92009-11-05 18:25:56 -0500527
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400528 return font;
529}
530
531hb_font_t *
Behdad Esfahboddefc45b2011-05-10 20:02:49 -0400532hb_font_create_sub_font (hb_font_t *parent)
533{
534 if (unlikely (!parent))
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -0400535 return hb_font_get_empty ();
Behdad Esfahboddefc45b2011-05-10 20:02:49 -0400536
537 hb_font_t *font = hb_font_create (parent->face);
538
539 if (unlikely (hb_object_is_inert (font)))
540 return font;
541
542 hb_font_make_immutable (parent);
543 font->parent = hb_font_reference (parent);
544
545 font->x_scale = parent->x_scale;
546 font->y_scale = parent->y_scale;
547 font->x_ppem = parent->x_ppem;
548 font->y_ppem = parent->y_ppem;
549
Behdad Esfahboddefc45b2011-05-10 20:02:49 -0400550 return font;
551}
552
553hb_font_t *
Behdad Esfahbod80a68332011-05-11 18:14:44 -0400554hb_font_get_empty (void)
555{
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -0400556 static const hb_font_t _hb_font_nil = {
557 HB_OBJECT_HEADER_STATIC,
558
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400559 true, /* immutable */
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -0400560
561 NULL, /* parent */
562 const_cast<hb_face_t *> (&_hb_face_nil),
563
564 0, /* x_scale */
565 0, /* y_scale */
566
567 0, /* x_ppem */
568 0, /* y_ppem */
569
570 const_cast<hb_font_funcs_t *> (&_hb_font_funcs_nil), /* klass */
571 NULL, /* user_data */
Behdad Esfahbodea278d32012-07-27 02:12:28 -0400572 NULL, /* destroy */
573
574 {
575#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID,
576#include "hb-shaper-list.hh"
577#undef HB_SHAPER_IMPLEMENT
578 }
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -0400579 };
580
581 return const_cast<hb_font_t *> (&_hb_font_nil);
Behdad Esfahbod80a68332011-05-11 18:14:44 -0400582}
583
584hb_font_t *
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400585hb_font_reference (hb_font_t *font)
586{
Behdad Esfahbod47e71d92011-04-27 16:38:03 -0400587 return hb_object_reference (font);
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400588}
589
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400590void
591hb_font_destroy (hb_font_t *font)
592{
Behdad Esfahbod47e71d92011-04-27 16:38:03 -0400593 if (!hb_object_destroy (font)) return;
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400594
Behdad Esfahbod027857d2012-07-26 17:34:25 -0400595#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_DESTROY(shaper, font);
596#include "hb-shaper-list.hh"
597#undef HB_SHAPER_IMPLEMENT
598
599 if (font->destroy)
600 font->destroy (font->user_data);
601
Behdad Esfahboddefc45b2011-05-10 20:02:49 -0400602 hb_font_destroy (font->parent);
Behdad Esfahbod72657e42011-05-02 20:46:32 -0400603 hb_face_destroy (font->face);
Behdad Esfahbod5c441882009-08-10 20:05:16 -0400604 hb_font_funcs_destroy (font->klass);
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400605
606 free (font);
607}
608
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -0400609hb_bool_t
610hb_font_set_user_data (hb_font_t *font,
611 hb_user_data_key_t *key,
612 void * data,
Behdad Esfahbod33ccc772011-08-09 00:43:24 +0200613 hb_destroy_func_t destroy,
614 hb_bool_t replace)
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -0400615{
Behdad Esfahbod33ccc772011-08-09 00:43:24 +0200616 return hb_object_set_user_data (font, key, data, destroy, replace);
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -0400617}
618
619void *
620hb_font_get_user_data (hb_font_t *font,
621 hb_user_data_key_t *key)
622{
623 return hb_object_get_user_data (font, key);
624}
625
Behdad Esfahbod74f1d892011-05-10 19:39:32 -0400626void
627hb_font_make_immutable (hb_font_t *font)
628{
629 if (hb_object_is_inert (font))
630 return;
631
632 font->immutable = true;
633}
634
635hb_bool_t
636hb_font_is_immutable (hb_font_t *font)
637{
638 return font->immutable;
639}
640
Behdad Esfahboddefc45b2011-05-10 20:02:49 -0400641hb_font_t *
642hb_font_get_parent (hb_font_t *font)
643{
644 return font->parent;
645}
Behdad Esfahbod5fa849b2011-04-27 21:46:01 -0400646
Behdad Esfahbod72657e42011-05-02 20:46:32 -0400647hb_face_t *
648hb_font_get_face (hb_font_t *font)
649{
650 return font->face;
651}
652
653
Behdad Esfahbod5c441882009-08-10 20:05:16 -0400654void
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -0500655hb_font_set_funcs (hb_font_t *font,
656 hb_font_funcs_t *klass,
Behdad Esfahbod56681892011-04-20 03:03:32 -0400657 void *user_data,
658 hb_destroy_func_t destroy)
Behdad Esfahbod0ead4812009-08-02 17:41:36 -0400659{
Behdad Esfahbod0cd33592011-09-21 16:49:33 -0400660 if (font->immutable) {
661 if (destroy)
662 destroy (user_data);
Behdad Esfahbod5c441882009-08-10 20:05:16 -0400663 return;
Behdad Esfahbod0cd33592011-09-21 16:49:33 -0400664 }
Behdad Esfahbod0ead4812009-08-02 17:41:36 -0400665
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -0500666 if (font->destroy)
667 font->destroy (font->user_data);
668
Behdad Esfahbod0465e692009-12-20 16:25:18 +0100669 if (!klass)
Behdad Esfahbodf06ab8a2012-06-05 12:31:51 -0400670 klass = hb_font_funcs_get_empty ();
Behdad Esfahbod0465e692009-12-20 16:25:18 +0100671
Behdad Esfahbod5c441882009-08-10 20:05:16 -0400672 hb_font_funcs_reference (klass);
673 hb_font_funcs_destroy (font->klass);
674 font->klass = klass;
Behdad Esfahbod8fb3d1a2009-11-03 18:34:20 -0500675 font->user_data = user_data;
Behdad Esfahbod56681892011-04-20 03:03:32 -0400676 font->destroy = destroy;
Behdad Esfahbod0ead4812009-08-02 17:41:36 -0400677}
678
Behdad Esfahbodb9415e72011-08-17 19:21:44 +0200679void
680hb_font_set_funcs_data (hb_font_t *font,
681 void *user_data,
682 hb_destroy_func_t destroy)
683{
Behdad Esfahbod0cd33592011-09-21 16:49:33 -0400684 /* Destroy user_data? */
685 if (font->immutable) {
686 if (destroy)
687 destroy (user_data);
Behdad Esfahbodb9415e72011-08-17 19:21:44 +0200688 return;
Behdad Esfahbod0cd33592011-09-21 16:49:33 -0400689 }
Behdad Esfahbodb9415e72011-08-17 19:21:44 +0200690
691 if (font->destroy)
692 font->destroy (font->user_data);
693
694 font->user_data = user_data;
695 font->destroy = destroy;
696}
697
Behdad Esfahbod19c0eab2010-10-04 16:45:21 -0400698
699void
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400700hb_font_set_scale (hb_font_t *font,
Behdad Esfahbodda975412011-04-21 15:08:01 -0400701 int x_scale,
702 int y_scale)
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400703{
Behdad Esfahbod74f1d892011-05-10 19:39:32 -0400704 if (font->immutable)
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400705 return;
706
707 font->x_scale = x_scale;
708 font->y_scale = y_scale;
709}
710
711void
Behdad Esfahbod19c0eab2010-10-04 16:45:21 -0400712hb_font_get_scale (hb_font_t *font,
Behdad Esfahbodda975412011-04-21 15:08:01 -0400713 int *x_scale,
714 int *y_scale)
Behdad Esfahbod19c0eab2010-10-04 16:45:21 -0400715{
716 if (x_scale) *x_scale = font->x_scale;
717 if (y_scale) *y_scale = font->y_scale;
718}
719
720void
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400721hb_font_set_ppem (hb_font_t *font,
722 unsigned int x_ppem,
723 unsigned int y_ppem)
724{
Behdad Esfahbod74f1d892011-05-10 19:39:32 -0400725 if (font->immutable)
Behdad Esfahbodc62b5032009-08-01 19:54:49 -0400726 return;
727
728 font->x_ppem = x_ppem;
729 font->y_ppem = y_ppem;
730}
731
Behdad Esfahbod19c0eab2010-10-04 16:45:21 -0400732void
733hb_font_get_ppem (hb_font_t *font,
734 unsigned int *x_ppem,
735 unsigned int *y_ppem)
736{
737 if (x_ppem) *x_ppem = font->x_ppem;
738 if (y_ppem) *y_ppem = font->y_ppem;
739}