1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/harfbuzz/src/hb-font.cc Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,1238 @@ 1.4 +/* 1.5 + * Copyright © 2009 Red Hat, Inc. 1.6 + * Copyright © 2012 Google, Inc. 1.7 + * 1.8 + * This is part of HarfBuzz, a text shaping library. 1.9 + * 1.10 + * Permission is hereby granted, without written agreement and without 1.11 + * license or royalty fees, to use, copy, modify, and distribute this 1.12 + * software and its documentation for any purpose, provided that the 1.13 + * above copyright notice and the following two paragraphs appear in 1.14 + * all copies of this software. 1.15 + * 1.16 + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR 1.17 + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 1.18 + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN 1.19 + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 1.20 + * DAMAGE. 1.21 + * 1.22 + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, 1.23 + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 1.24 + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 1.25 + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO 1.26 + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 1.27 + * 1.28 + * Red Hat Author(s): Behdad Esfahbod 1.29 + * Google Author(s): Behdad Esfahbod 1.30 + */ 1.31 + 1.32 +#include "hb-private.hh" 1.33 + 1.34 +#include "hb-ot-layout-private.hh" 1.35 + 1.36 +#include "hb-font-private.hh" 1.37 +#include "hb-open-file-private.hh" 1.38 +#include "hb-ot-head-table.hh" 1.39 +#include "hb-ot-maxp-table.hh" 1.40 + 1.41 +#include "hb-cache-private.hh" 1.42 + 1.43 +#include <string.h> 1.44 + 1.45 + 1.46 +/* 1.47 + * hb_font_funcs_t 1.48 + */ 1.49 + 1.50 +static hb_bool_t 1.51 +hb_font_get_glyph_nil (hb_font_t *font, 1.52 + void *font_data HB_UNUSED, 1.53 + hb_codepoint_t unicode, 1.54 + hb_codepoint_t variation_selector, 1.55 + hb_codepoint_t *glyph, 1.56 + void *user_data HB_UNUSED) 1.57 +{ 1.58 + if (font->parent) 1.59 + return font->parent->get_glyph (unicode, variation_selector, glyph); 1.60 + 1.61 + *glyph = 0; 1.62 + return false; 1.63 +} 1.64 + 1.65 +static hb_position_t 1.66 +hb_font_get_glyph_h_advance_nil (hb_font_t *font, 1.67 + void *font_data HB_UNUSED, 1.68 + hb_codepoint_t glyph, 1.69 + void *user_data HB_UNUSED) 1.70 +{ 1.71 + if (font->parent) 1.72 + return font->parent_scale_x_distance (font->parent->get_glyph_h_advance (glyph)); 1.73 + 1.74 + return font->x_scale; 1.75 +} 1.76 + 1.77 +static hb_position_t 1.78 +hb_font_get_glyph_v_advance_nil (hb_font_t *font, 1.79 + void *font_data HB_UNUSED, 1.80 + hb_codepoint_t glyph, 1.81 + void *user_data HB_UNUSED) 1.82 +{ 1.83 + if (font->parent) 1.84 + return font->parent_scale_y_distance (font->parent->get_glyph_v_advance (glyph)); 1.85 + 1.86 + return font->y_scale; 1.87 +} 1.88 + 1.89 +static hb_bool_t 1.90 +hb_font_get_glyph_h_origin_nil (hb_font_t *font, 1.91 + void *font_data HB_UNUSED, 1.92 + hb_codepoint_t glyph, 1.93 + hb_position_t *x, 1.94 + hb_position_t *y, 1.95 + void *user_data HB_UNUSED) 1.96 +{ 1.97 + if (font->parent) { 1.98 + hb_bool_t ret = font->parent->get_glyph_h_origin (glyph, x, y); 1.99 + if (ret) 1.100 + font->parent_scale_position (x, y); 1.101 + return ret; 1.102 + } 1.103 + 1.104 + *x = *y = 0; 1.105 + return false; 1.106 +} 1.107 + 1.108 +static hb_bool_t 1.109 +hb_font_get_glyph_v_origin_nil (hb_font_t *font, 1.110 + void *font_data HB_UNUSED, 1.111 + hb_codepoint_t glyph, 1.112 + hb_position_t *x, 1.113 + hb_position_t *y, 1.114 + void *user_data HB_UNUSED) 1.115 +{ 1.116 + if (font->parent) { 1.117 + hb_bool_t ret = font->parent->get_glyph_v_origin (glyph, x, y); 1.118 + if (ret) 1.119 + font->parent_scale_position (x, y); 1.120 + return ret; 1.121 + } 1.122 + 1.123 + *x = *y = 0; 1.124 + return false; 1.125 +} 1.126 + 1.127 +static hb_position_t 1.128 +hb_font_get_glyph_h_kerning_nil (hb_font_t *font, 1.129 + void *font_data HB_UNUSED, 1.130 + hb_codepoint_t left_glyph, 1.131 + hb_codepoint_t right_glyph, 1.132 + void *user_data HB_UNUSED) 1.133 +{ 1.134 + if (font->parent) 1.135 + return font->parent_scale_x_distance (font->parent->get_glyph_h_kerning (left_glyph, right_glyph)); 1.136 + 1.137 + return 0; 1.138 +} 1.139 + 1.140 +static hb_position_t 1.141 +hb_font_get_glyph_v_kerning_nil (hb_font_t *font, 1.142 + void *font_data HB_UNUSED, 1.143 + hb_codepoint_t top_glyph, 1.144 + hb_codepoint_t bottom_glyph, 1.145 + void *user_data HB_UNUSED) 1.146 +{ 1.147 + if (font->parent) 1.148 + return font->parent_scale_y_distance (font->parent->get_glyph_v_kerning (top_glyph, bottom_glyph)); 1.149 + 1.150 + return 0; 1.151 +} 1.152 + 1.153 +static hb_bool_t 1.154 +hb_font_get_glyph_extents_nil (hb_font_t *font, 1.155 + void *font_data HB_UNUSED, 1.156 + hb_codepoint_t glyph, 1.157 + hb_glyph_extents_t *extents, 1.158 + void *user_data HB_UNUSED) 1.159 +{ 1.160 + if (font->parent) { 1.161 + hb_bool_t ret = font->parent->get_glyph_extents (glyph, extents); 1.162 + if (ret) { 1.163 + font->parent_scale_position (&extents->x_bearing, &extents->y_bearing); 1.164 + font->parent_scale_distance (&extents->width, &extents->height); 1.165 + } 1.166 + return ret; 1.167 + } 1.168 + 1.169 + memset (extents, 0, sizeof (*extents)); 1.170 + return false; 1.171 +} 1.172 + 1.173 +static hb_bool_t 1.174 +hb_font_get_glyph_contour_point_nil (hb_font_t *font, 1.175 + void *font_data HB_UNUSED, 1.176 + hb_codepoint_t glyph, 1.177 + unsigned int point_index, 1.178 + hb_position_t *x, 1.179 + hb_position_t *y, 1.180 + void *user_data HB_UNUSED) 1.181 +{ 1.182 + if (font->parent) { 1.183 + hb_bool_t ret = font->parent->get_glyph_contour_point (glyph, point_index, x, y); 1.184 + if (ret) 1.185 + font->parent_scale_position (x, y); 1.186 + return ret; 1.187 + } 1.188 + 1.189 + *x = *y = 0; 1.190 + return false; 1.191 +} 1.192 + 1.193 +static hb_bool_t 1.194 +hb_font_get_glyph_name_nil (hb_font_t *font, 1.195 + void *font_data HB_UNUSED, 1.196 + hb_codepoint_t glyph, 1.197 + char *name, unsigned int size, 1.198 + void *user_data HB_UNUSED) 1.199 +{ 1.200 + if (font->parent) 1.201 + return font->parent->get_glyph_name (glyph, name, size); 1.202 + 1.203 + if (size) *name = '\0'; 1.204 + return false; 1.205 +} 1.206 + 1.207 +static hb_bool_t 1.208 +hb_font_get_glyph_from_name_nil (hb_font_t *font, 1.209 + void *font_data HB_UNUSED, 1.210 + const char *name, int len, /* -1 means nul-terminated */ 1.211 + hb_codepoint_t *glyph, 1.212 + void *user_data HB_UNUSED) 1.213 +{ 1.214 + if (font->parent) 1.215 + return font->parent->get_glyph_from_name (name, len, glyph); 1.216 + 1.217 + *glyph = 0; 1.218 + return false; 1.219 +} 1.220 + 1.221 + 1.222 +static const hb_font_funcs_t _hb_font_funcs_nil = { 1.223 + HB_OBJECT_HEADER_STATIC, 1.224 + 1.225 + true, /* immutable */ 1.226 + 1.227 + { 1.228 +#define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_nil, 1.229 + HB_FONT_FUNCS_IMPLEMENT_CALLBACKS 1.230 +#undef HB_FONT_FUNC_IMPLEMENT 1.231 + } 1.232 +}; 1.233 + 1.234 + 1.235 +/** 1.236 + * hb_font_funcs_create: (Xconstructor) 1.237 + * 1.238 + * 1.239 + * 1.240 + * Return value: (transfer full): 1.241 + * 1.242 + * Since: 1.0 1.243 + **/ 1.244 +hb_font_funcs_t * 1.245 +hb_font_funcs_create (void) 1.246 +{ 1.247 + hb_font_funcs_t *ffuncs; 1.248 + 1.249 + if (!(ffuncs = hb_object_create<hb_font_funcs_t> ())) 1.250 + return hb_font_funcs_get_empty (); 1.251 + 1.252 + ffuncs->get = _hb_font_funcs_nil.get; 1.253 + 1.254 + return ffuncs; 1.255 +} 1.256 + 1.257 +/** 1.258 + * hb_font_funcs_get_empty: 1.259 + * 1.260 + * 1.261 + * 1.262 + * Return value: (transfer full): 1.263 + * 1.264 + * Since: 1.0 1.265 + **/ 1.266 +hb_font_funcs_t * 1.267 +hb_font_funcs_get_empty (void) 1.268 +{ 1.269 + return const_cast<hb_font_funcs_t *> (&_hb_font_funcs_nil); 1.270 +} 1.271 + 1.272 +/** 1.273 + * hb_font_funcs_reference: (skip) 1.274 + * @ffuncs: font functions. 1.275 + * 1.276 + * 1.277 + * 1.278 + * Return value: 1.279 + * 1.280 + * Since: 1.0 1.281 + **/ 1.282 +hb_font_funcs_t * 1.283 +hb_font_funcs_reference (hb_font_funcs_t *ffuncs) 1.284 +{ 1.285 + return hb_object_reference (ffuncs); 1.286 +} 1.287 + 1.288 +/** 1.289 + * hb_font_funcs_destroy: (skip) 1.290 + * @ffuncs: font functions. 1.291 + * 1.292 + * 1.293 + * 1.294 + * Since: 1.0 1.295 + **/ 1.296 +void 1.297 +hb_font_funcs_destroy (hb_font_funcs_t *ffuncs) 1.298 +{ 1.299 + if (!hb_object_destroy (ffuncs)) return; 1.300 + 1.301 +#define HB_FONT_FUNC_IMPLEMENT(name) if (ffuncs->destroy.name) \ 1.302 + ffuncs->destroy.name (ffuncs->user_data.name); 1.303 + HB_FONT_FUNCS_IMPLEMENT_CALLBACKS 1.304 +#undef HB_FONT_FUNC_IMPLEMENT 1.305 + 1.306 + free (ffuncs); 1.307 +} 1.308 + 1.309 +/** 1.310 + * hb_font_funcs_set_user_data: (skip) 1.311 + * @ffuncs: font functions. 1.312 + * @key: 1.313 + * @data: 1.314 + * @destroy: 1.315 + * @replace: 1.316 + * 1.317 + * 1.318 + * 1.319 + * Return value: 1.320 + * 1.321 + * Since: 1.0 1.322 + **/ 1.323 +hb_bool_t 1.324 +hb_font_funcs_set_user_data (hb_font_funcs_t *ffuncs, 1.325 + hb_user_data_key_t *key, 1.326 + void * data, 1.327 + hb_destroy_func_t destroy, 1.328 + hb_bool_t replace) 1.329 +{ 1.330 + return hb_object_set_user_data (ffuncs, key, data, destroy, replace); 1.331 +} 1.332 + 1.333 +/** 1.334 + * hb_font_funcs_get_user_data: (skip) 1.335 + * @ffuncs: font functions. 1.336 + * @key: 1.337 + * 1.338 + * 1.339 + * 1.340 + * Return value: (transfer none): 1.341 + * 1.342 + * Since: 1.0 1.343 + **/ 1.344 +void * 1.345 +hb_font_funcs_get_user_data (hb_font_funcs_t *ffuncs, 1.346 + hb_user_data_key_t *key) 1.347 +{ 1.348 + return hb_object_get_user_data (ffuncs, key); 1.349 +} 1.350 + 1.351 + 1.352 +/** 1.353 + * hb_font_funcs_make_immutable: 1.354 + * @ffuncs: font functions. 1.355 + * 1.356 + * 1.357 + * 1.358 + * Since: 1.0 1.359 + **/ 1.360 +void 1.361 +hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs) 1.362 +{ 1.363 + if (hb_object_is_inert (ffuncs)) 1.364 + return; 1.365 + 1.366 + ffuncs->immutable = true; 1.367 +} 1.368 + 1.369 +/** 1.370 + * hb_font_funcs_is_immutable: 1.371 + * @ffuncs: font functions. 1.372 + * 1.373 + * 1.374 + * 1.375 + * Return value: 1.376 + * 1.377 + * Since: 1.0 1.378 + **/ 1.379 +hb_bool_t 1.380 +hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs) 1.381 +{ 1.382 + return ffuncs->immutable; 1.383 +} 1.384 + 1.385 + 1.386 +#define HB_FONT_FUNC_IMPLEMENT(name) \ 1.387 + \ 1.388 +void \ 1.389 +hb_font_funcs_set_##name##_func (hb_font_funcs_t *ffuncs, \ 1.390 + hb_font_get_##name##_func_t func, \ 1.391 + void *user_data, \ 1.392 + hb_destroy_func_t destroy) \ 1.393 +{ \ 1.394 + if (ffuncs->immutable) { \ 1.395 + if (destroy) \ 1.396 + destroy (user_data); \ 1.397 + return; \ 1.398 + } \ 1.399 + \ 1.400 + if (ffuncs->destroy.name) \ 1.401 + ffuncs->destroy.name (ffuncs->user_data.name); \ 1.402 + \ 1.403 + if (func) { \ 1.404 + ffuncs->get.name = func; \ 1.405 + ffuncs->user_data.name = user_data; \ 1.406 + ffuncs->destroy.name = destroy; \ 1.407 + } else { \ 1.408 + ffuncs->get.name = hb_font_get_##name##_nil; \ 1.409 + ffuncs->user_data.name = NULL; \ 1.410 + ffuncs->destroy.name = NULL; \ 1.411 + } \ 1.412 +} 1.413 + 1.414 +HB_FONT_FUNCS_IMPLEMENT_CALLBACKS 1.415 +#undef HB_FONT_FUNC_IMPLEMENT 1.416 + 1.417 + 1.418 +/* Public getters */ 1.419 + 1.420 +/** 1.421 + * hb_font_get_glyph: 1.422 + * @font: a font. 1.423 + * @unicode: 1.424 + * @variation_selector: 1.425 + * @glyph: (out): 1.426 + * 1.427 + * 1.428 + * 1.429 + * Return value: 1.430 + * 1.431 + * Since: 1.0 1.432 + **/ 1.433 +hb_bool_t 1.434 +hb_font_get_glyph (hb_font_t *font, 1.435 + hb_codepoint_t unicode, hb_codepoint_t variation_selector, 1.436 + hb_codepoint_t *glyph) 1.437 +{ 1.438 + return font->get_glyph (unicode, variation_selector, glyph); 1.439 +} 1.440 + 1.441 +/** 1.442 + * hb_font_get_glyph_h_advance: 1.443 + * @font: a font. 1.444 + * @glyph: 1.445 + * 1.446 + * 1.447 + * 1.448 + * Return value: 1.449 + * 1.450 + * Since: 1.0 1.451 + **/ 1.452 +hb_position_t 1.453 +hb_font_get_glyph_h_advance (hb_font_t *font, 1.454 + hb_codepoint_t glyph) 1.455 +{ 1.456 + return font->get_glyph_h_advance (glyph); 1.457 +} 1.458 + 1.459 +/** 1.460 + * hb_font_get_glyph_v_advance: 1.461 + * @font: a font. 1.462 + * @glyph: 1.463 + * 1.464 + * 1.465 + * 1.466 + * Return value: 1.467 + * 1.468 + * Since: 1.0 1.469 + **/ 1.470 +hb_position_t 1.471 +hb_font_get_glyph_v_advance (hb_font_t *font, 1.472 + hb_codepoint_t glyph) 1.473 +{ 1.474 + return font->get_glyph_v_advance (glyph); 1.475 +} 1.476 + 1.477 +/** 1.478 + * hb_font_get_glyph_h_origin: 1.479 + * @font: a font. 1.480 + * @glyph: 1.481 + * @x: (out): 1.482 + * @y: (out): 1.483 + * 1.484 + * 1.485 + * 1.486 + * Return value: 1.487 + * 1.488 + * Since: 1.0 1.489 + **/ 1.490 +hb_bool_t 1.491 +hb_font_get_glyph_h_origin (hb_font_t *font, 1.492 + hb_codepoint_t glyph, 1.493 + hb_position_t *x, hb_position_t *y) 1.494 +{ 1.495 + return font->get_glyph_h_origin (glyph, x, y); 1.496 +} 1.497 + 1.498 +/** 1.499 + * hb_font_get_glyph_v_origin: 1.500 + * @font: a font. 1.501 + * @glyph: 1.502 + * @x: (out): 1.503 + * @y: (out): 1.504 + * 1.505 + * 1.506 + * 1.507 + * Return value: 1.508 + * 1.509 + * Since: 1.0 1.510 + **/ 1.511 +hb_bool_t 1.512 +hb_font_get_glyph_v_origin (hb_font_t *font, 1.513 + hb_codepoint_t glyph, 1.514 + hb_position_t *x, hb_position_t *y) 1.515 +{ 1.516 + return font->get_glyph_v_origin (glyph, x, y); 1.517 +} 1.518 + 1.519 +/** 1.520 + * hb_font_get_glyph_h_kerning: 1.521 + * @font: a font. 1.522 + * @left_glyph: 1.523 + * @right_glyph: 1.524 + * 1.525 + * 1.526 + * 1.527 + * Return value: 1.528 + * 1.529 + * Since: 1.0 1.530 + **/ 1.531 +hb_position_t 1.532 +hb_font_get_glyph_h_kerning (hb_font_t *font, 1.533 + hb_codepoint_t left_glyph, hb_codepoint_t right_glyph) 1.534 +{ 1.535 + return font->get_glyph_h_kerning (left_glyph, right_glyph); 1.536 +} 1.537 + 1.538 +/** 1.539 + * hb_font_get_glyph_v_kerning: 1.540 + * @font: a font. 1.541 + * @top_glyph: 1.542 + * @bottom_glyph: 1.543 + * 1.544 + * 1.545 + * 1.546 + * Return value: 1.547 + * 1.548 + * Since: 1.0 1.549 + **/ 1.550 +hb_position_t 1.551 +hb_font_get_glyph_v_kerning (hb_font_t *font, 1.552 + hb_codepoint_t top_glyph, hb_codepoint_t bottom_glyph) 1.553 +{ 1.554 + return font->get_glyph_v_kerning (top_glyph, bottom_glyph); 1.555 +} 1.556 + 1.557 +/** 1.558 + * hb_font_get_glyph_extents: 1.559 + * @font: a font. 1.560 + * @glyph: 1.561 + * @extents: (out): 1.562 + * 1.563 + * 1.564 + * 1.565 + * Return value: 1.566 + * 1.567 + * Since: 1.0 1.568 + **/ 1.569 +hb_bool_t 1.570 +hb_font_get_glyph_extents (hb_font_t *font, 1.571 + hb_codepoint_t glyph, 1.572 + hb_glyph_extents_t *extents) 1.573 +{ 1.574 + return font->get_glyph_extents (glyph, extents); 1.575 +} 1.576 + 1.577 +/** 1.578 + * hb_font_get_glyph_contour_point: 1.579 + * @font: a font. 1.580 + * @glyph: 1.581 + * @point_index: 1.582 + * @x: (out): 1.583 + * @y: (out): 1.584 + * 1.585 + * 1.586 + * 1.587 + * Return value: 1.588 + * 1.589 + * Since: 1.0 1.590 + **/ 1.591 +hb_bool_t 1.592 +hb_font_get_glyph_contour_point (hb_font_t *font, 1.593 + hb_codepoint_t glyph, unsigned int point_index, 1.594 + hb_position_t *x, hb_position_t *y) 1.595 +{ 1.596 + return font->get_glyph_contour_point (glyph, point_index, x, y); 1.597 +} 1.598 + 1.599 +/** 1.600 + * hb_font_get_glyph_name: 1.601 + * @font: a font. 1.602 + * @glyph: 1.603 + * @name: (array length=size): 1.604 + * @size: 1.605 + * 1.606 + * 1.607 + * 1.608 + * Return value: 1.609 + * 1.610 + * Since: 1.0 1.611 + **/ 1.612 +hb_bool_t 1.613 +hb_font_get_glyph_name (hb_font_t *font, 1.614 + hb_codepoint_t glyph, 1.615 + char *name, unsigned int size) 1.616 +{ 1.617 + return font->get_glyph_name (glyph, name, size); 1.618 +} 1.619 + 1.620 +/** 1.621 + * hb_font_get_glyph_from_name: 1.622 + * @font: a font. 1.623 + * @name: (array length=len): 1.624 + * @len: 1.625 + * @glyph: (out): 1.626 + * 1.627 + * 1.628 + * 1.629 + * Return value: 1.630 + * 1.631 + * Since: 1.0 1.632 + **/ 1.633 +hb_bool_t 1.634 +hb_font_get_glyph_from_name (hb_font_t *font, 1.635 + const char *name, int len, /* -1 means nul-terminated */ 1.636 + hb_codepoint_t *glyph) 1.637 +{ 1.638 + return font->get_glyph_from_name (name, len, glyph); 1.639 +} 1.640 + 1.641 + 1.642 +/* A bit higher-level, and with fallback */ 1.643 + 1.644 +/** 1.645 + * hb_font_get_glyph_advance_for_direction: 1.646 + * @font: a font. 1.647 + * @glyph: 1.648 + * @direction: 1.649 + * @x: (out): 1.650 + * @y: (out): 1.651 + * 1.652 + * 1.653 + * 1.654 + * Since: 1.0 1.655 + **/ 1.656 +void 1.657 +hb_font_get_glyph_advance_for_direction (hb_font_t *font, 1.658 + hb_codepoint_t glyph, 1.659 + hb_direction_t direction, 1.660 + hb_position_t *x, hb_position_t *y) 1.661 +{ 1.662 + return font->get_glyph_advance_for_direction (glyph, direction, x, y); 1.663 +} 1.664 + 1.665 +/** 1.666 + * hb_font_get_glyph_origin_for_direction: 1.667 + * @font: a font. 1.668 + * @glyph: 1.669 + * @direction: 1.670 + * @x: (out): 1.671 + * @y: (out): 1.672 + * 1.673 + * 1.674 + * 1.675 + * Since: 1.0 1.676 + **/ 1.677 +void 1.678 +hb_font_get_glyph_origin_for_direction (hb_font_t *font, 1.679 + hb_codepoint_t glyph, 1.680 + hb_direction_t direction, 1.681 + hb_position_t *x, hb_position_t *y) 1.682 +{ 1.683 + return font->get_glyph_origin_for_direction (glyph, direction, x, y); 1.684 +} 1.685 + 1.686 +/** 1.687 + * hb_font_add_glyph_origin_for_direction: 1.688 + * @font: a font. 1.689 + * @glyph: 1.690 + * @direction: 1.691 + * @x: (out): 1.692 + * @y: (out): 1.693 + * 1.694 + * 1.695 + * 1.696 + * Since: 1.0 1.697 + **/ 1.698 +void 1.699 +hb_font_add_glyph_origin_for_direction (hb_font_t *font, 1.700 + hb_codepoint_t glyph, 1.701 + hb_direction_t direction, 1.702 + hb_position_t *x, hb_position_t *y) 1.703 +{ 1.704 + return font->add_glyph_origin_for_direction (glyph, direction, x, y); 1.705 +} 1.706 + 1.707 +/** 1.708 + * hb_font_subtract_glyph_origin_for_direction: 1.709 + * @font: a font. 1.710 + * @glyph: 1.711 + * @direction: 1.712 + * @x: (out): 1.713 + * @y: (out): 1.714 + * 1.715 + * 1.716 + * 1.717 + * Since: 1.0 1.718 + **/ 1.719 +void 1.720 +hb_font_subtract_glyph_origin_for_direction (hb_font_t *font, 1.721 + hb_codepoint_t glyph, 1.722 + hb_direction_t direction, 1.723 + hb_position_t *x, hb_position_t *y) 1.724 +{ 1.725 + return font->subtract_glyph_origin_for_direction (glyph, direction, x, y); 1.726 +} 1.727 + 1.728 +/** 1.729 + * hb_font_get_glyph_kerning_for_direction: 1.730 + * @font: a font. 1.731 + * @first_glyph: 1.732 + * @second_glyph: 1.733 + * @direction: 1.734 + * @x: (out): 1.735 + * @y: (out): 1.736 + * 1.737 + * 1.738 + * 1.739 + * Since: 1.0 1.740 + **/ 1.741 +void 1.742 +hb_font_get_glyph_kerning_for_direction (hb_font_t *font, 1.743 + hb_codepoint_t first_glyph, hb_codepoint_t second_glyph, 1.744 + hb_direction_t direction, 1.745 + hb_position_t *x, hb_position_t *y) 1.746 +{ 1.747 + return font->get_glyph_kerning_for_direction (first_glyph, second_glyph, direction, x, y); 1.748 +} 1.749 + 1.750 +/** 1.751 + * hb_font_get_glyph_extents_for_origin: 1.752 + * @font: a font. 1.753 + * @glyph: 1.754 + * @direction: 1.755 + * @extents: (out): 1.756 + * 1.757 + * 1.758 + * 1.759 + * Return value: 1.760 + * 1.761 + * Since: 1.0 1.762 + **/ 1.763 +hb_bool_t 1.764 +hb_font_get_glyph_extents_for_origin (hb_font_t *font, 1.765 + hb_codepoint_t glyph, 1.766 + hb_direction_t direction, 1.767 + hb_glyph_extents_t *extents) 1.768 +{ 1.769 + return font->get_glyph_extents_for_origin (glyph, direction, extents); 1.770 +} 1.771 + 1.772 +/** 1.773 + * hb_font_get_glyph_contour_point_for_origin: 1.774 + * @font: a font. 1.775 + * @glyph: 1.776 + * @point_index: 1.777 + * @direction: 1.778 + * @x: (out): 1.779 + * @y: (out): 1.780 + * 1.781 + * 1.782 + * 1.783 + * Return value: 1.784 + * 1.785 + * Since: 1.0 1.786 + **/ 1.787 +hb_bool_t 1.788 +hb_font_get_glyph_contour_point_for_origin (hb_font_t *font, 1.789 + hb_codepoint_t glyph, unsigned int point_index, 1.790 + hb_direction_t direction, 1.791 + hb_position_t *x, hb_position_t *y) 1.792 +{ 1.793 + return font->get_glyph_contour_point_for_origin (glyph, point_index, direction, x, y); 1.794 +} 1.795 + 1.796 +/* Generates gidDDD if glyph has no name. */ 1.797 +/** 1.798 + * hb_font_glyph_to_string: 1.799 + * @font: a font. 1.800 + * @glyph: 1.801 + * @s: (array length=size): 1.802 + * @size: 1.803 + * 1.804 + * 1.805 + * 1.806 + * Since: 1.0 1.807 + **/ 1.808 +void 1.809 +hb_font_glyph_to_string (hb_font_t *font, 1.810 + hb_codepoint_t glyph, 1.811 + char *s, unsigned int size) 1.812 +{ 1.813 + font->glyph_to_string (glyph, s, size); 1.814 +} 1.815 + 1.816 +/* Parses gidDDD and uniUUUU strings automatically. */ 1.817 +/** 1.818 + * hb_font_glyph_from_string: 1.819 + * @font: a font. 1.820 + * @s: (array length=len): 1.821 + * @len: 1.822 + * @glyph: (out): 1.823 + * 1.824 + * 1.825 + * 1.826 + * Return value: 1.827 + * 1.828 + * Since: 1.0 1.829 + **/ 1.830 +hb_bool_t 1.831 +hb_font_glyph_from_string (hb_font_t *font, 1.832 + const char *s, int len, /* -1 means nul-terminated */ 1.833 + hb_codepoint_t *glyph) 1.834 +{ 1.835 + return font->glyph_from_string (s, len, glyph); 1.836 +} 1.837 + 1.838 + 1.839 +/* 1.840 + * hb_font_t 1.841 + */ 1.842 + 1.843 +/** 1.844 + * hb_font_create: (Xconstructor) 1.845 + * @face: a face. 1.846 + * 1.847 + * 1.848 + * 1.849 + * Return value: (transfer full): 1.850 + * 1.851 + * Since: 1.0 1.852 + **/ 1.853 +hb_font_t * 1.854 +hb_font_create (hb_face_t *face) 1.855 +{ 1.856 + hb_font_t *font; 1.857 + 1.858 + if (unlikely (!face)) 1.859 + face = hb_face_get_empty (); 1.860 + if (unlikely (hb_object_is_inert (face))) 1.861 + return hb_font_get_empty (); 1.862 + if (!(font = hb_object_create<hb_font_t> ())) 1.863 + return hb_font_get_empty (); 1.864 + 1.865 + hb_face_make_immutable (face); 1.866 + font->face = hb_face_reference (face); 1.867 + font->klass = hb_font_funcs_get_empty (); 1.868 + 1.869 + return font; 1.870 +} 1.871 + 1.872 +/** 1.873 + * hb_font_create_sub_font: 1.874 + * @parent: parent font. 1.875 + * 1.876 + * 1.877 + * 1.878 + * Return value: (transfer full): 1.879 + * 1.880 + * Since: 1.0 1.881 + **/ 1.882 +hb_font_t * 1.883 +hb_font_create_sub_font (hb_font_t *parent) 1.884 +{ 1.885 + if (unlikely (!parent)) 1.886 + return hb_font_get_empty (); 1.887 + 1.888 + hb_font_t *font = hb_font_create (parent->face); 1.889 + 1.890 + if (unlikely (hb_object_is_inert (font))) 1.891 + return font; 1.892 + 1.893 + hb_font_make_immutable (parent); 1.894 + font->parent = hb_font_reference (parent); 1.895 + 1.896 + font->x_scale = parent->x_scale; 1.897 + font->y_scale = parent->y_scale; 1.898 + font->x_ppem = parent->x_ppem; 1.899 + font->y_ppem = parent->y_ppem; 1.900 + 1.901 + return font; 1.902 +} 1.903 + 1.904 +/** 1.905 + * hb_font_get_empty: 1.906 + * 1.907 + * 1.908 + * 1.909 + * Return value: (transfer full) 1.910 + * 1.911 + * Since: 1.0 1.912 + **/ 1.913 +hb_font_t * 1.914 +hb_font_get_empty (void) 1.915 +{ 1.916 + static const hb_font_t _hb_font_nil = { 1.917 + HB_OBJECT_HEADER_STATIC, 1.918 + 1.919 + true, /* immutable */ 1.920 + 1.921 + NULL, /* parent */ 1.922 + const_cast<hb_face_t *> (&_hb_face_nil), 1.923 + 1.924 + 0, /* x_scale */ 1.925 + 0, /* y_scale */ 1.926 + 1.927 + 0, /* x_ppem */ 1.928 + 0, /* y_ppem */ 1.929 + 1.930 + const_cast<hb_font_funcs_t *> (&_hb_font_funcs_nil), /* klass */ 1.931 + NULL, /* user_data */ 1.932 + NULL, /* destroy */ 1.933 + 1.934 + { 1.935 +#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID, 1.936 +#include "hb-shaper-list.hh" 1.937 +#undef HB_SHAPER_IMPLEMENT 1.938 + } 1.939 + }; 1.940 + 1.941 + return const_cast<hb_font_t *> (&_hb_font_nil); 1.942 +} 1.943 + 1.944 +/** 1.945 + * hb_font_reference: (skip) 1.946 + * @font: a font. 1.947 + * 1.948 + * 1.949 + * 1.950 + * Return value: (transfer full): 1.951 + * 1.952 + * Since: 1.0 1.953 + **/ 1.954 +hb_font_t * 1.955 +hb_font_reference (hb_font_t *font) 1.956 +{ 1.957 + return hb_object_reference (font); 1.958 +} 1.959 + 1.960 +/** 1.961 + * hb_font_destroy: (skip) 1.962 + * @font: a font. 1.963 + * 1.964 + * 1.965 + * 1.966 + * Since: 1.0 1.967 + **/ 1.968 +void 1.969 +hb_font_destroy (hb_font_t *font) 1.970 +{ 1.971 + if (!hb_object_destroy (font)) return; 1.972 + 1.973 +#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_DESTROY(shaper, font); 1.974 +#include "hb-shaper-list.hh" 1.975 +#undef HB_SHAPER_IMPLEMENT 1.976 + 1.977 + if (font->destroy) 1.978 + font->destroy (font->user_data); 1.979 + 1.980 + hb_font_destroy (font->parent); 1.981 + hb_face_destroy (font->face); 1.982 + hb_font_funcs_destroy (font->klass); 1.983 + 1.984 + free (font); 1.985 +} 1.986 + 1.987 +/** 1.988 + * hb_font_set_user_data: (skip) 1.989 + * @font: a font. 1.990 + * @key: 1.991 + * @data: 1.992 + * @destroy: 1.993 + * @replace: 1.994 + * 1.995 + * 1.996 + * 1.997 + * Return value: 1.998 + * 1.999 + * Since: 1.0 1.1000 + **/ 1.1001 +hb_bool_t 1.1002 +hb_font_set_user_data (hb_font_t *font, 1.1003 + hb_user_data_key_t *key, 1.1004 + void * data, 1.1005 + hb_destroy_func_t destroy, 1.1006 + hb_bool_t replace) 1.1007 +{ 1.1008 + return hb_object_set_user_data (font, key, data, destroy, replace); 1.1009 +} 1.1010 + 1.1011 +/** 1.1012 + * hb_font_get_user_data: (skip) 1.1013 + * @font: a font. 1.1014 + * @key: 1.1015 + * 1.1016 + * 1.1017 + * 1.1018 + * Return value: (transfer none): 1.1019 + * 1.1020 + * Since: 1.0 1.1021 + **/ 1.1022 +void * 1.1023 +hb_font_get_user_data (hb_font_t *font, 1.1024 + hb_user_data_key_t *key) 1.1025 +{ 1.1026 + return hb_object_get_user_data (font, key); 1.1027 +} 1.1028 + 1.1029 +/** 1.1030 + * hb_font_make_immutable: 1.1031 + * @font: a font. 1.1032 + * 1.1033 + * 1.1034 + * 1.1035 + * Since: 1.0 1.1036 + **/ 1.1037 +void 1.1038 +hb_font_make_immutable (hb_font_t *font) 1.1039 +{ 1.1040 + if (hb_object_is_inert (font)) 1.1041 + return; 1.1042 + 1.1043 + font->immutable = true; 1.1044 +} 1.1045 + 1.1046 +/** 1.1047 + * hb_font_is_immutable: 1.1048 + * @font: a font. 1.1049 + * 1.1050 + * 1.1051 + * 1.1052 + * Return value: 1.1053 + * 1.1054 + * Since: 1.0 1.1055 + **/ 1.1056 +hb_bool_t 1.1057 +hb_font_is_immutable (hb_font_t *font) 1.1058 +{ 1.1059 + return font->immutable; 1.1060 +} 1.1061 + 1.1062 +/** 1.1063 + * hb_font_get_parent: 1.1064 + * @font: a font. 1.1065 + * 1.1066 + * 1.1067 + * 1.1068 + * Return value: (transfer none): 1.1069 + * 1.1070 + * Since: 1.0 1.1071 + **/ 1.1072 +hb_font_t * 1.1073 +hb_font_get_parent (hb_font_t *font) 1.1074 +{ 1.1075 + return font->parent; 1.1076 +} 1.1077 + 1.1078 +/** 1.1079 + * hb_font_get_face: 1.1080 + * @font: a font. 1.1081 + * 1.1082 + * 1.1083 + * 1.1084 + * Return value: (transfer none): 1.1085 + * 1.1086 + * Since: 1.0 1.1087 + **/ 1.1088 +hb_face_t * 1.1089 +hb_font_get_face (hb_font_t *font) 1.1090 +{ 1.1091 + return font->face; 1.1092 +} 1.1093 + 1.1094 + 1.1095 +/** 1.1096 + * hb_font_set_funcs: 1.1097 + * @font: a font. 1.1098 + * @klass: (closure font_data) (destroy destroy) (scope notified): 1.1099 + * @font_data: 1.1100 + * @destroy: 1.1101 + * 1.1102 + * 1.1103 + * 1.1104 + * Since: 1.0 1.1105 + **/ 1.1106 +void 1.1107 +hb_font_set_funcs (hb_font_t *font, 1.1108 + hb_font_funcs_t *klass, 1.1109 + void *font_data, 1.1110 + hb_destroy_func_t destroy) 1.1111 +{ 1.1112 + if (font->immutable) { 1.1113 + if (destroy) 1.1114 + destroy (font_data); 1.1115 + return; 1.1116 + } 1.1117 + 1.1118 + if (font->destroy) 1.1119 + font->destroy (font->user_data); 1.1120 + 1.1121 + if (!klass) 1.1122 + klass = hb_font_funcs_get_empty (); 1.1123 + 1.1124 + hb_font_funcs_reference (klass); 1.1125 + hb_font_funcs_destroy (font->klass); 1.1126 + font->klass = klass; 1.1127 + font->user_data = font_data; 1.1128 + font->destroy = destroy; 1.1129 +} 1.1130 + 1.1131 +/** 1.1132 + * hb_font_set_funcs_data: 1.1133 + * @font: a font. 1.1134 + * @font_data: (destroy destroy) (scope notified): 1.1135 + * @destroy: 1.1136 + * 1.1137 + * 1.1138 + * 1.1139 + * Since: 1.0 1.1140 + **/ 1.1141 +void 1.1142 +hb_font_set_funcs_data (hb_font_t *font, 1.1143 + void *font_data, 1.1144 + hb_destroy_func_t destroy) 1.1145 +{ 1.1146 + /* Destroy user_data? */ 1.1147 + if (font->immutable) { 1.1148 + if (destroy) 1.1149 + destroy (font_data); 1.1150 + return; 1.1151 + } 1.1152 + 1.1153 + if (font->destroy) 1.1154 + font->destroy (font->user_data); 1.1155 + 1.1156 + font->user_data = font_data; 1.1157 + font->destroy = destroy; 1.1158 +} 1.1159 + 1.1160 + 1.1161 +/** 1.1162 + * hb_font_set_scale: 1.1163 + * @font: a font. 1.1164 + * @x_scale: 1.1165 + * @y_scale: 1.1166 + * 1.1167 + * 1.1168 + * 1.1169 + * Since: 1.0 1.1170 + **/ 1.1171 +void 1.1172 +hb_font_set_scale (hb_font_t *font, 1.1173 + int x_scale, 1.1174 + int y_scale) 1.1175 +{ 1.1176 + if (font->immutable) 1.1177 + return; 1.1178 + 1.1179 + font->x_scale = x_scale; 1.1180 + font->y_scale = y_scale; 1.1181 +} 1.1182 + 1.1183 +/** 1.1184 + * hb_font_get_scale: 1.1185 + * @font: a font. 1.1186 + * @x_scale: (out): 1.1187 + * @y_scale: (out): 1.1188 + * 1.1189 + * 1.1190 + * 1.1191 + * Since: 1.0 1.1192 + **/ 1.1193 +void 1.1194 +hb_font_get_scale (hb_font_t *font, 1.1195 + int *x_scale, 1.1196 + int *y_scale) 1.1197 +{ 1.1198 + if (x_scale) *x_scale = font->x_scale; 1.1199 + if (y_scale) *y_scale = font->y_scale; 1.1200 +} 1.1201 + 1.1202 +/** 1.1203 + * hb_font_set_ppem: 1.1204 + * @font: a font. 1.1205 + * @x_ppem: 1.1206 + * @y_ppem: 1.1207 + * 1.1208 + * 1.1209 + * 1.1210 + * Since: 1.0 1.1211 + **/ 1.1212 +void 1.1213 +hb_font_set_ppem (hb_font_t *font, 1.1214 + unsigned int x_ppem, 1.1215 + unsigned int y_ppem) 1.1216 +{ 1.1217 + if (font->immutable) 1.1218 + return; 1.1219 + 1.1220 + font->x_ppem = x_ppem; 1.1221 + font->y_ppem = y_ppem; 1.1222 +} 1.1223 + 1.1224 +/** 1.1225 + * hb_font_get_ppem: 1.1226 + * @font: a font. 1.1227 + * @x_ppem: (out): 1.1228 + * @y_ppem: (out): 1.1229 + * 1.1230 + * 1.1231 + * 1.1232 + * Since: 1.0 1.1233 + **/ 1.1234 +void 1.1235 +hb_font_get_ppem (hb_font_t *font, 1.1236 + unsigned int *x_ppem, 1.1237 + unsigned int *y_ppem) 1.1238 +{ 1.1239 + if (x_ppem) *x_ppem = font->x_ppem; 1.1240 + if (y_ppem) *y_ppem = font->y_ppem; 1.1241 +}