gfx/harfbuzz/src/hb-font.cc

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

michael@0 1 /*
michael@0 2 * Copyright © 2009 Red Hat, Inc.
michael@0 3 * Copyright © 2012 Google, Inc.
michael@0 4 *
michael@0 5 * This is part of HarfBuzz, a text shaping library.
michael@0 6 *
michael@0 7 * Permission is hereby granted, without written agreement and without
michael@0 8 * license or royalty fees, to use, copy, modify, and distribute this
michael@0 9 * software and its documentation for any purpose, provided that the
michael@0 10 * above copyright notice and the following two paragraphs appear in
michael@0 11 * all copies of this software.
michael@0 12 *
michael@0 13 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
michael@0 14 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
michael@0 15 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
michael@0 16 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
michael@0 17 * DAMAGE.
michael@0 18 *
michael@0 19 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
michael@0 20 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
michael@0 21 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
michael@0 22 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
michael@0 23 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
michael@0 24 *
michael@0 25 * Red Hat Author(s): Behdad Esfahbod
michael@0 26 * Google Author(s): Behdad Esfahbod
michael@0 27 */
michael@0 28
michael@0 29 #include "hb-private.hh"
michael@0 30
michael@0 31 #include "hb-ot-layout-private.hh"
michael@0 32
michael@0 33 #include "hb-font-private.hh"
michael@0 34 #include "hb-open-file-private.hh"
michael@0 35 #include "hb-ot-head-table.hh"
michael@0 36 #include "hb-ot-maxp-table.hh"
michael@0 37
michael@0 38 #include "hb-cache-private.hh"
michael@0 39
michael@0 40 #include <string.h>
michael@0 41
michael@0 42
michael@0 43 /*
michael@0 44 * hb_font_funcs_t
michael@0 45 */
michael@0 46
michael@0 47 static hb_bool_t
michael@0 48 hb_font_get_glyph_nil (hb_font_t *font,
michael@0 49 void *font_data HB_UNUSED,
michael@0 50 hb_codepoint_t unicode,
michael@0 51 hb_codepoint_t variation_selector,
michael@0 52 hb_codepoint_t *glyph,
michael@0 53 void *user_data HB_UNUSED)
michael@0 54 {
michael@0 55 if (font->parent)
michael@0 56 return font->parent->get_glyph (unicode, variation_selector, glyph);
michael@0 57
michael@0 58 *glyph = 0;
michael@0 59 return false;
michael@0 60 }
michael@0 61
michael@0 62 static hb_position_t
michael@0 63 hb_font_get_glyph_h_advance_nil (hb_font_t *font,
michael@0 64 void *font_data HB_UNUSED,
michael@0 65 hb_codepoint_t glyph,
michael@0 66 void *user_data HB_UNUSED)
michael@0 67 {
michael@0 68 if (font->parent)
michael@0 69 return font->parent_scale_x_distance (font->parent->get_glyph_h_advance (glyph));
michael@0 70
michael@0 71 return font->x_scale;
michael@0 72 }
michael@0 73
michael@0 74 static hb_position_t
michael@0 75 hb_font_get_glyph_v_advance_nil (hb_font_t *font,
michael@0 76 void *font_data HB_UNUSED,
michael@0 77 hb_codepoint_t glyph,
michael@0 78 void *user_data HB_UNUSED)
michael@0 79 {
michael@0 80 if (font->parent)
michael@0 81 return font->parent_scale_y_distance (font->parent->get_glyph_v_advance (glyph));
michael@0 82
michael@0 83 return font->y_scale;
michael@0 84 }
michael@0 85
michael@0 86 static hb_bool_t
michael@0 87 hb_font_get_glyph_h_origin_nil (hb_font_t *font,
michael@0 88 void *font_data HB_UNUSED,
michael@0 89 hb_codepoint_t glyph,
michael@0 90 hb_position_t *x,
michael@0 91 hb_position_t *y,
michael@0 92 void *user_data HB_UNUSED)
michael@0 93 {
michael@0 94 if (font->parent) {
michael@0 95 hb_bool_t ret = font->parent->get_glyph_h_origin (glyph, x, y);
michael@0 96 if (ret)
michael@0 97 font->parent_scale_position (x, y);
michael@0 98 return ret;
michael@0 99 }
michael@0 100
michael@0 101 *x = *y = 0;
michael@0 102 return false;
michael@0 103 }
michael@0 104
michael@0 105 static hb_bool_t
michael@0 106 hb_font_get_glyph_v_origin_nil (hb_font_t *font,
michael@0 107 void *font_data HB_UNUSED,
michael@0 108 hb_codepoint_t glyph,
michael@0 109 hb_position_t *x,
michael@0 110 hb_position_t *y,
michael@0 111 void *user_data HB_UNUSED)
michael@0 112 {
michael@0 113 if (font->parent) {
michael@0 114 hb_bool_t ret = font->parent->get_glyph_v_origin (glyph, x, y);
michael@0 115 if (ret)
michael@0 116 font->parent_scale_position (x, y);
michael@0 117 return ret;
michael@0 118 }
michael@0 119
michael@0 120 *x = *y = 0;
michael@0 121 return false;
michael@0 122 }
michael@0 123
michael@0 124 static hb_position_t
michael@0 125 hb_font_get_glyph_h_kerning_nil (hb_font_t *font,
michael@0 126 void *font_data HB_UNUSED,
michael@0 127 hb_codepoint_t left_glyph,
michael@0 128 hb_codepoint_t right_glyph,
michael@0 129 void *user_data HB_UNUSED)
michael@0 130 {
michael@0 131 if (font->parent)
michael@0 132 return font->parent_scale_x_distance (font->parent->get_glyph_h_kerning (left_glyph, right_glyph));
michael@0 133
michael@0 134 return 0;
michael@0 135 }
michael@0 136
michael@0 137 static hb_position_t
michael@0 138 hb_font_get_glyph_v_kerning_nil (hb_font_t *font,
michael@0 139 void *font_data HB_UNUSED,
michael@0 140 hb_codepoint_t top_glyph,
michael@0 141 hb_codepoint_t bottom_glyph,
michael@0 142 void *user_data HB_UNUSED)
michael@0 143 {
michael@0 144 if (font->parent)
michael@0 145 return font->parent_scale_y_distance (font->parent->get_glyph_v_kerning (top_glyph, bottom_glyph));
michael@0 146
michael@0 147 return 0;
michael@0 148 }
michael@0 149
michael@0 150 static hb_bool_t
michael@0 151 hb_font_get_glyph_extents_nil (hb_font_t *font,
michael@0 152 void *font_data HB_UNUSED,
michael@0 153 hb_codepoint_t glyph,
michael@0 154 hb_glyph_extents_t *extents,
michael@0 155 void *user_data HB_UNUSED)
michael@0 156 {
michael@0 157 if (font->parent) {
michael@0 158 hb_bool_t ret = font->parent->get_glyph_extents (glyph, extents);
michael@0 159 if (ret) {
michael@0 160 font->parent_scale_position (&extents->x_bearing, &extents->y_bearing);
michael@0 161 font->parent_scale_distance (&extents->width, &extents->height);
michael@0 162 }
michael@0 163 return ret;
michael@0 164 }
michael@0 165
michael@0 166 memset (extents, 0, sizeof (*extents));
michael@0 167 return false;
michael@0 168 }
michael@0 169
michael@0 170 static hb_bool_t
michael@0 171 hb_font_get_glyph_contour_point_nil (hb_font_t *font,
michael@0 172 void *font_data HB_UNUSED,
michael@0 173 hb_codepoint_t glyph,
michael@0 174 unsigned int point_index,
michael@0 175 hb_position_t *x,
michael@0 176 hb_position_t *y,
michael@0 177 void *user_data HB_UNUSED)
michael@0 178 {
michael@0 179 if (font->parent) {
michael@0 180 hb_bool_t ret = font->parent->get_glyph_contour_point (glyph, point_index, x, y);
michael@0 181 if (ret)
michael@0 182 font->parent_scale_position (x, y);
michael@0 183 return ret;
michael@0 184 }
michael@0 185
michael@0 186 *x = *y = 0;
michael@0 187 return false;
michael@0 188 }
michael@0 189
michael@0 190 static hb_bool_t
michael@0 191 hb_font_get_glyph_name_nil (hb_font_t *font,
michael@0 192 void *font_data HB_UNUSED,
michael@0 193 hb_codepoint_t glyph,
michael@0 194 char *name, unsigned int size,
michael@0 195 void *user_data HB_UNUSED)
michael@0 196 {
michael@0 197 if (font->parent)
michael@0 198 return font->parent->get_glyph_name (glyph, name, size);
michael@0 199
michael@0 200 if (size) *name = '\0';
michael@0 201 return false;
michael@0 202 }
michael@0 203
michael@0 204 static hb_bool_t
michael@0 205 hb_font_get_glyph_from_name_nil (hb_font_t *font,
michael@0 206 void *font_data HB_UNUSED,
michael@0 207 const char *name, int len, /* -1 means nul-terminated */
michael@0 208 hb_codepoint_t *glyph,
michael@0 209 void *user_data HB_UNUSED)
michael@0 210 {
michael@0 211 if (font->parent)
michael@0 212 return font->parent->get_glyph_from_name (name, len, glyph);
michael@0 213
michael@0 214 *glyph = 0;
michael@0 215 return false;
michael@0 216 }
michael@0 217
michael@0 218
michael@0 219 static const hb_font_funcs_t _hb_font_funcs_nil = {
michael@0 220 HB_OBJECT_HEADER_STATIC,
michael@0 221
michael@0 222 true, /* immutable */
michael@0 223
michael@0 224 {
michael@0 225 #define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_nil,
michael@0 226 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
michael@0 227 #undef HB_FONT_FUNC_IMPLEMENT
michael@0 228 }
michael@0 229 };
michael@0 230
michael@0 231
michael@0 232 /**
michael@0 233 * hb_font_funcs_create: (Xconstructor)
michael@0 234 *
michael@0 235 *
michael@0 236 *
michael@0 237 * Return value: (transfer full):
michael@0 238 *
michael@0 239 * Since: 1.0
michael@0 240 **/
michael@0 241 hb_font_funcs_t *
michael@0 242 hb_font_funcs_create (void)
michael@0 243 {
michael@0 244 hb_font_funcs_t *ffuncs;
michael@0 245
michael@0 246 if (!(ffuncs = hb_object_create<hb_font_funcs_t> ()))
michael@0 247 return hb_font_funcs_get_empty ();
michael@0 248
michael@0 249 ffuncs->get = _hb_font_funcs_nil.get;
michael@0 250
michael@0 251 return ffuncs;
michael@0 252 }
michael@0 253
michael@0 254 /**
michael@0 255 * hb_font_funcs_get_empty:
michael@0 256 *
michael@0 257 *
michael@0 258 *
michael@0 259 * Return value: (transfer full):
michael@0 260 *
michael@0 261 * Since: 1.0
michael@0 262 **/
michael@0 263 hb_font_funcs_t *
michael@0 264 hb_font_funcs_get_empty (void)
michael@0 265 {
michael@0 266 return const_cast<hb_font_funcs_t *> (&_hb_font_funcs_nil);
michael@0 267 }
michael@0 268
michael@0 269 /**
michael@0 270 * hb_font_funcs_reference: (skip)
michael@0 271 * @ffuncs: font functions.
michael@0 272 *
michael@0 273 *
michael@0 274 *
michael@0 275 * Return value:
michael@0 276 *
michael@0 277 * Since: 1.0
michael@0 278 **/
michael@0 279 hb_font_funcs_t *
michael@0 280 hb_font_funcs_reference (hb_font_funcs_t *ffuncs)
michael@0 281 {
michael@0 282 return hb_object_reference (ffuncs);
michael@0 283 }
michael@0 284
michael@0 285 /**
michael@0 286 * hb_font_funcs_destroy: (skip)
michael@0 287 * @ffuncs: font functions.
michael@0 288 *
michael@0 289 *
michael@0 290 *
michael@0 291 * Since: 1.0
michael@0 292 **/
michael@0 293 void
michael@0 294 hb_font_funcs_destroy (hb_font_funcs_t *ffuncs)
michael@0 295 {
michael@0 296 if (!hb_object_destroy (ffuncs)) return;
michael@0 297
michael@0 298 #define HB_FONT_FUNC_IMPLEMENT(name) if (ffuncs->destroy.name) \
michael@0 299 ffuncs->destroy.name (ffuncs->user_data.name);
michael@0 300 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
michael@0 301 #undef HB_FONT_FUNC_IMPLEMENT
michael@0 302
michael@0 303 free (ffuncs);
michael@0 304 }
michael@0 305
michael@0 306 /**
michael@0 307 * hb_font_funcs_set_user_data: (skip)
michael@0 308 * @ffuncs: font functions.
michael@0 309 * @key:
michael@0 310 * @data:
michael@0 311 * @destroy:
michael@0 312 * @replace:
michael@0 313 *
michael@0 314 *
michael@0 315 *
michael@0 316 * Return value:
michael@0 317 *
michael@0 318 * Since: 1.0
michael@0 319 **/
michael@0 320 hb_bool_t
michael@0 321 hb_font_funcs_set_user_data (hb_font_funcs_t *ffuncs,
michael@0 322 hb_user_data_key_t *key,
michael@0 323 void * data,
michael@0 324 hb_destroy_func_t destroy,
michael@0 325 hb_bool_t replace)
michael@0 326 {
michael@0 327 return hb_object_set_user_data (ffuncs, key, data, destroy, replace);
michael@0 328 }
michael@0 329
michael@0 330 /**
michael@0 331 * hb_font_funcs_get_user_data: (skip)
michael@0 332 * @ffuncs: font functions.
michael@0 333 * @key:
michael@0 334 *
michael@0 335 *
michael@0 336 *
michael@0 337 * Return value: (transfer none):
michael@0 338 *
michael@0 339 * Since: 1.0
michael@0 340 **/
michael@0 341 void *
michael@0 342 hb_font_funcs_get_user_data (hb_font_funcs_t *ffuncs,
michael@0 343 hb_user_data_key_t *key)
michael@0 344 {
michael@0 345 return hb_object_get_user_data (ffuncs, key);
michael@0 346 }
michael@0 347
michael@0 348
michael@0 349 /**
michael@0 350 * hb_font_funcs_make_immutable:
michael@0 351 * @ffuncs: font functions.
michael@0 352 *
michael@0 353 *
michael@0 354 *
michael@0 355 * Since: 1.0
michael@0 356 **/
michael@0 357 void
michael@0 358 hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs)
michael@0 359 {
michael@0 360 if (hb_object_is_inert (ffuncs))
michael@0 361 return;
michael@0 362
michael@0 363 ffuncs->immutable = true;
michael@0 364 }
michael@0 365
michael@0 366 /**
michael@0 367 * hb_font_funcs_is_immutable:
michael@0 368 * @ffuncs: font functions.
michael@0 369 *
michael@0 370 *
michael@0 371 *
michael@0 372 * Return value:
michael@0 373 *
michael@0 374 * Since: 1.0
michael@0 375 **/
michael@0 376 hb_bool_t
michael@0 377 hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs)
michael@0 378 {
michael@0 379 return ffuncs->immutable;
michael@0 380 }
michael@0 381
michael@0 382
michael@0 383 #define HB_FONT_FUNC_IMPLEMENT(name) \
michael@0 384 \
michael@0 385 void \
michael@0 386 hb_font_funcs_set_##name##_func (hb_font_funcs_t *ffuncs, \
michael@0 387 hb_font_get_##name##_func_t func, \
michael@0 388 void *user_data, \
michael@0 389 hb_destroy_func_t destroy) \
michael@0 390 { \
michael@0 391 if (ffuncs->immutable) { \
michael@0 392 if (destroy) \
michael@0 393 destroy (user_data); \
michael@0 394 return; \
michael@0 395 } \
michael@0 396 \
michael@0 397 if (ffuncs->destroy.name) \
michael@0 398 ffuncs->destroy.name (ffuncs->user_data.name); \
michael@0 399 \
michael@0 400 if (func) { \
michael@0 401 ffuncs->get.name = func; \
michael@0 402 ffuncs->user_data.name = user_data; \
michael@0 403 ffuncs->destroy.name = destroy; \
michael@0 404 } else { \
michael@0 405 ffuncs->get.name = hb_font_get_##name##_nil; \
michael@0 406 ffuncs->user_data.name = NULL; \
michael@0 407 ffuncs->destroy.name = NULL; \
michael@0 408 } \
michael@0 409 }
michael@0 410
michael@0 411 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS
michael@0 412 #undef HB_FONT_FUNC_IMPLEMENT
michael@0 413
michael@0 414
michael@0 415 /* Public getters */
michael@0 416
michael@0 417 /**
michael@0 418 * hb_font_get_glyph:
michael@0 419 * @font: a font.
michael@0 420 * @unicode:
michael@0 421 * @variation_selector:
michael@0 422 * @glyph: (out):
michael@0 423 *
michael@0 424 *
michael@0 425 *
michael@0 426 * Return value:
michael@0 427 *
michael@0 428 * Since: 1.0
michael@0 429 **/
michael@0 430 hb_bool_t
michael@0 431 hb_font_get_glyph (hb_font_t *font,
michael@0 432 hb_codepoint_t unicode, hb_codepoint_t variation_selector,
michael@0 433 hb_codepoint_t *glyph)
michael@0 434 {
michael@0 435 return font->get_glyph (unicode, variation_selector, glyph);
michael@0 436 }
michael@0 437
michael@0 438 /**
michael@0 439 * hb_font_get_glyph_h_advance:
michael@0 440 * @font: a font.
michael@0 441 * @glyph:
michael@0 442 *
michael@0 443 *
michael@0 444 *
michael@0 445 * Return value:
michael@0 446 *
michael@0 447 * Since: 1.0
michael@0 448 **/
michael@0 449 hb_position_t
michael@0 450 hb_font_get_glyph_h_advance (hb_font_t *font,
michael@0 451 hb_codepoint_t glyph)
michael@0 452 {
michael@0 453 return font->get_glyph_h_advance (glyph);
michael@0 454 }
michael@0 455
michael@0 456 /**
michael@0 457 * hb_font_get_glyph_v_advance:
michael@0 458 * @font: a font.
michael@0 459 * @glyph:
michael@0 460 *
michael@0 461 *
michael@0 462 *
michael@0 463 * Return value:
michael@0 464 *
michael@0 465 * Since: 1.0
michael@0 466 **/
michael@0 467 hb_position_t
michael@0 468 hb_font_get_glyph_v_advance (hb_font_t *font,
michael@0 469 hb_codepoint_t glyph)
michael@0 470 {
michael@0 471 return font->get_glyph_v_advance (glyph);
michael@0 472 }
michael@0 473
michael@0 474 /**
michael@0 475 * hb_font_get_glyph_h_origin:
michael@0 476 * @font: a font.
michael@0 477 * @glyph:
michael@0 478 * @x: (out):
michael@0 479 * @y: (out):
michael@0 480 *
michael@0 481 *
michael@0 482 *
michael@0 483 * Return value:
michael@0 484 *
michael@0 485 * Since: 1.0
michael@0 486 **/
michael@0 487 hb_bool_t
michael@0 488 hb_font_get_glyph_h_origin (hb_font_t *font,
michael@0 489 hb_codepoint_t glyph,
michael@0 490 hb_position_t *x, hb_position_t *y)
michael@0 491 {
michael@0 492 return font->get_glyph_h_origin (glyph, x, y);
michael@0 493 }
michael@0 494
michael@0 495 /**
michael@0 496 * hb_font_get_glyph_v_origin:
michael@0 497 * @font: a font.
michael@0 498 * @glyph:
michael@0 499 * @x: (out):
michael@0 500 * @y: (out):
michael@0 501 *
michael@0 502 *
michael@0 503 *
michael@0 504 * Return value:
michael@0 505 *
michael@0 506 * Since: 1.0
michael@0 507 **/
michael@0 508 hb_bool_t
michael@0 509 hb_font_get_glyph_v_origin (hb_font_t *font,
michael@0 510 hb_codepoint_t glyph,
michael@0 511 hb_position_t *x, hb_position_t *y)
michael@0 512 {
michael@0 513 return font->get_glyph_v_origin (glyph, x, y);
michael@0 514 }
michael@0 515
michael@0 516 /**
michael@0 517 * hb_font_get_glyph_h_kerning:
michael@0 518 * @font: a font.
michael@0 519 * @left_glyph:
michael@0 520 * @right_glyph:
michael@0 521 *
michael@0 522 *
michael@0 523 *
michael@0 524 * Return value:
michael@0 525 *
michael@0 526 * Since: 1.0
michael@0 527 **/
michael@0 528 hb_position_t
michael@0 529 hb_font_get_glyph_h_kerning (hb_font_t *font,
michael@0 530 hb_codepoint_t left_glyph, hb_codepoint_t right_glyph)
michael@0 531 {
michael@0 532 return font->get_glyph_h_kerning (left_glyph, right_glyph);
michael@0 533 }
michael@0 534
michael@0 535 /**
michael@0 536 * hb_font_get_glyph_v_kerning:
michael@0 537 * @font: a font.
michael@0 538 * @top_glyph:
michael@0 539 * @bottom_glyph:
michael@0 540 *
michael@0 541 *
michael@0 542 *
michael@0 543 * Return value:
michael@0 544 *
michael@0 545 * Since: 1.0
michael@0 546 **/
michael@0 547 hb_position_t
michael@0 548 hb_font_get_glyph_v_kerning (hb_font_t *font,
michael@0 549 hb_codepoint_t top_glyph, hb_codepoint_t bottom_glyph)
michael@0 550 {
michael@0 551 return font->get_glyph_v_kerning (top_glyph, bottom_glyph);
michael@0 552 }
michael@0 553
michael@0 554 /**
michael@0 555 * hb_font_get_glyph_extents:
michael@0 556 * @font: a font.
michael@0 557 * @glyph:
michael@0 558 * @extents: (out):
michael@0 559 *
michael@0 560 *
michael@0 561 *
michael@0 562 * Return value:
michael@0 563 *
michael@0 564 * Since: 1.0
michael@0 565 **/
michael@0 566 hb_bool_t
michael@0 567 hb_font_get_glyph_extents (hb_font_t *font,
michael@0 568 hb_codepoint_t glyph,
michael@0 569 hb_glyph_extents_t *extents)
michael@0 570 {
michael@0 571 return font->get_glyph_extents (glyph, extents);
michael@0 572 }
michael@0 573
michael@0 574 /**
michael@0 575 * hb_font_get_glyph_contour_point:
michael@0 576 * @font: a font.
michael@0 577 * @glyph:
michael@0 578 * @point_index:
michael@0 579 * @x: (out):
michael@0 580 * @y: (out):
michael@0 581 *
michael@0 582 *
michael@0 583 *
michael@0 584 * Return value:
michael@0 585 *
michael@0 586 * Since: 1.0
michael@0 587 **/
michael@0 588 hb_bool_t
michael@0 589 hb_font_get_glyph_contour_point (hb_font_t *font,
michael@0 590 hb_codepoint_t glyph, unsigned int point_index,
michael@0 591 hb_position_t *x, hb_position_t *y)
michael@0 592 {
michael@0 593 return font->get_glyph_contour_point (glyph, point_index, x, y);
michael@0 594 }
michael@0 595
michael@0 596 /**
michael@0 597 * hb_font_get_glyph_name:
michael@0 598 * @font: a font.
michael@0 599 * @glyph:
michael@0 600 * @name: (array length=size):
michael@0 601 * @size:
michael@0 602 *
michael@0 603 *
michael@0 604 *
michael@0 605 * Return value:
michael@0 606 *
michael@0 607 * Since: 1.0
michael@0 608 **/
michael@0 609 hb_bool_t
michael@0 610 hb_font_get_glyph_name (hb_font_t *font,
michael@0 611 hb_codepoint_t glyph,
michael@0 612 char *name, unsigned int size)
michael@0 613 {
michael@0 614 return font->get_glyph_name (glyph, name, size);
michael@0 615 }
michael@0 616
michael@0 617 /**
michael@0 618 * hb_font_get_glyph_from_name:
michael@0 619 * @font: a font.
michael@0 620 * @name: (array length=len):
michael@0 621 * @len:
michael@0 622 * @glyph: (out):
michael@0 623 *
michael@0 624 *
michael@0 625 *
michael@0 626 * Return value:
michael@0 627 *
michael@0 628 * Since: 1.0
michael@0 629 **/
michael@0 630 hb_bool_t
michael@0 631 hb_font_get_glyph_from_name (hb_font_t *font,
michael@0 632 const char *name, int len, /* -1 means nul-terminated */
michael@0 633 hb_codepoint_t *glyph)
michael@0 634 {
michael@0 635 return font->get_glyph_from_name (name, len, glyph);
michael@0 636 }
michael@0 637
michael@0 638
michael@0 639 /* A bit higher-level, and with fallback */
michael@0 640
michael@0 641 /**
michael@0 642 * hb_font_get_glyph_advance_for_direction:
michael@0 643 * @font: a font.
michael@0 644 * @glyph:
michael@0 645 * @direction:
michael@0 646 * @x: (out):
michael@0 647 * @y: (out):
michael@0 648 *
michael@0 649 *
michael@0 650 *
michael@0 651 * Since: 1.0
michael@0 652 **/
michael@0 653 void
michael@0 654 hb_font_get_glyph_advance_for_direction (hb_font_t *font,
michael@0 655 hb_codepoint_t glyph,
michael@0 656 hb_direction_t direction,
michael@0 657 hb_position_t *x, hb_position_t *y)
michael@0 658 {
michael@0 659 return font->get_glyph_advance_for_direction (glyph, direction, x, y);
michael@0 660 }
michael@0 661
michael@0 662 /**
michael@0 663 * hb_font_get_glyph_origin_for_direction:
michael@0 664 * @font: a font.
michael@0 665 * @glyph:
michael@0 666 * @direction:
michael@0 667 * @x: (out):
michael@0 668 * @y: (out):
michael@0 669 *
michael@0 670 *
michael@0 671 *
michael@0 672 * Since: 1.0
michael@0 673 **/
michael@0 674 void
michael@0 675 hb_font_get_glyph_origin_for_direction (hb_font_t *font,
michael@0 676 hb_codepoint_t glyph,
michael@0 677 hb_direction_t direction,
michael@0 678 hb_position_t *x, hb_position_t *y)
michael@0 679 {
michael@0 680 return font->get_glyph_origin_for_direction (glyph, direction, x, y);
michael@0 681 }
michael@0 682
michael@0 683 /**
michael@0 684 * hb_font_add_glyph_origin_for_direction:
michael@0 685 * @font: a font.
michael@0 686 * @glyph:
michael@0 687 * @direction:
michael@0 688 * @x: (out):
michael@0 689 * @y: (out):
michael@0 690 *
michael@0 691 *
michael@0 692 *
michael@0 693 * Since: 1.0
michael@0 694 **/
michael@0 695 void
michael@0 696 hb_font_add_glyph_origin_for_direction (hb_font_t *font,
michael@0 697 hb_codepoint_t glyph,
michael@0 698 hb_direction_t direction,
michael@0 699 hb_position_t *x, hb_position_t *y)
michael@0 700 {
michael@0 701 return font->add_glyph_origin_for_direction (glyph, direction, x, y);
michael@0 702 }
michael@0 703
michael@0 704 /**
michael@0 705 * hb_font_subtract_glyph_origin_for_direction:
michael@0 706 * @font: a font.
michael@0 707 * @glyph:
michael@0 708 * @direction:
michael@0 709 * @x: (out):
michael@0 710 * @y: (out):
michael@0 711 *
michael@0 712 *
michael@0 713 *
michael@0 714 * Since: 1.0
michael@0 715 **/
michael@0 716 void
michael@0 717 hb_font_subtract_glyph_origin_for_direction (hb_font_t *font,
michael@0 718 hb_codepoint_t glyph,
michael@0 719 hb_direction_t direction,
michael@0 720 hb_position_t *x, hb_position_t *y)
michael@0 721 {
michael@0 722 return font->subtract_glyph_origin_for_direction (glyph, direction, x, y);
michael@0 723 }
michael@0 724
michael@0 725 /**
michael@0 726 * hb_font_get_glyph_kerning_for_direction:
michael@0 727 * @font: a font.
michael@0 728 * @first_glyph:
michael@0 729 * @second_glyph:
michael@0 730 * @direction:
michael@0 731 * @x: (out):
michael@0 732 * @y: (out):
michael@0 733 *
michael@0 734 *
michael@0 735 *
michael@0 736 * Since: 1.0
michael@0 737 **/
michael@0 738 void
michael@0 739 hb_font_get_glyph_kerning_for_direction (hb_font_t *font,
michael@0 740 hb_codepoint_t first_glyph, hb_codepoint_t second_glyph,
michael@0 741 hb_direction_t direction,
michael@0 742 hb_position_t *x, hb_position_t *y)
michael@0 743 {
michael@0 744 return font->get_glyph_kerning_for_direction (first_glyph, second_glyph, direction, x, y);
michael@0 745 }
michael@0 746
michael@0 747 /**
michael@0 748 * hb_font_get_glyph_extents_for_origin:
michael@0 749 * @font: a font.
michael@0 750 * @glyph:
michael@0 751 * @direction:
michael@0 752 * @extents: (out):
michael@0 753 *
michael@0 754 *
michael@0 755 *
michael@0 756 * Return value:
michael@0 757 *
michael@0 758 * Since: 1.0
michael@0 759 **/
michael@0 760 hb_bool_t
michael@0 761 hb_font_get_glyph_extents_for_origin (hb_font_t *font,
michael@0 762 hb_codepoint_t glyph,
michael@0 763 hb_direction_t direction,
michael@0 764 hb_glyph_extents_t *extents)
michael@0 765 {
michael@0 766 return font->get_glyph_extents_for_origin (glyph, direction, extents);
michael@0 767 }
michael@0 768
michael@0 769 /**
michael@0 770 * hb_font_get_glyph_contour_point_for_origin:
michael@0 771 * @font: a font.
michael@0 772 * @glyph:
michael@0 773 * @point_index:
michael@0 774 * @direction:
michael@0 775 * @x: (out):
michael@0 776 * @y: (out):
michael@0 777 *
michael@0 778 *
michael@0 779 *
michael@0 780 * Return value:
michael@0 781 *
michael@0 782 * Since: 1.0
michael@0 783 **/
michael@0 784 hb_bool_t
michael@0 785 hb_font_get_glyph_contour_point_for_origin (hb_font_t *font,
michael@0 786 hb_codepoint_t glyph, unsigned int point_index,
michael@0 787 hb_direction_t direction,
michael@0 788 hb_position_t *x, hb_position_t *y)
michael@0 789 {
michael@0 790 return font->get_glyph_contour_point_for_origin (glyph, point_index, direction, x, y);
michael@0 791 }
michael@0 792
michael@0 793 /* Generates gidDDD if glyph has no name. */
michael@0 794 /**
michael@0 795 * hb_font_glyph_to_string:
michael@0 796 * @font: a font.
michael@0 797 * @glyph:
michael@0 798 * @s: (array length=size):
michael@0 799 * @size:
michael@0 800 *
michael@0 801 *
michael@0 802 *
michael@0 803 * Since: 1.0
michael@0 804 **/
michael@0 805 void
michael@0 806 hb_font_glyph_to_string (hb_font_t *font,
michael@0 807 hb_codepoint_t glyph,
michael@0 808 char *s, unsigned int size)
michael@0 809 {
michael@0 810 font->glyph_to_string (glyph, s, size);
michael@0 811 }
michael@0 812
michael@0 813 /* Parses gidDDD and uniUUUU strings automatically. */
michael@0 814 /**
michael@0 815 * hb_font_glyph_from_string:
michael@0 816 * @font: a font.
michael@0 817 * @s: (array length=len):
michael@0 818 * @len:
michael@0 819 * @glyph: (out):
michael@0 820 *
michael@0 821 *
michael@0 822 *
michael@0 823 * Return value:
michael@0 824 *
michael@0 825 * Since: 1.0
michael@0 826 **/
michael@0 827 hb_bool_t
michael@0 828 hb_font_glyph_from_string (hb_font_t *font,
michael@0 829 const char *s, int len, /* -1 means nul-terminated */
michael@0 830 hb_codepoint_t *glyph)
michael@0 831 {
michael@0 832 return font->glyph_from_string (s, len, glyph);
michael@0 833 }
michael@0 834
michael@0 835
michael@0 836 /*
michael@0 837 * hb_font_t
michael@0 838 */
michael@0 839
michael@0 840 /**
michael@0 841 * hb_font_create: (Xconstructor)
michael@0 842 * @face: a face.
michael@0 843 *
michael@0 844 *
michael@0 845 *
michael@0 846 * Return value: (transfer full):
michael@0 847 *
michael@0 848 * Since: 1.0
michael@0 849 **/
michael@0 850 hb_font_t *
michael@0 851 hb_font_create (hb_face_t *face)
michael@0 852 {
michael@0 853 hb_font_t *font;
michael@0 854
michael@0 855 if (unlikely (!face))
michael@0 856 face = hb_face_get_empty ();
michael@0 857 if (unlikely (hb_object_is_inert (face)))
michael@0 858 return hb_font_get_empty ();
michael@0 859 if (!(font = hb_object_create<hb_font_t> ()))
michael@0 860 return hb_font_get_empty ();
michael@0 861
michael@0 862 hb_face_make_immutable (face);
michael@0 863 font->face = hb_face_reference (face);
michael@0 864 font->klass = hb_font_funcs_get_empty ();
michael@0 865
michael@0 866 return font;
michael@0 867 }
michael@0 868
michael@0 869 /**
michael@0 870 * hb_font_create_sub_font:
michael@0 871 * @parent: parent font.
michael@0 872 *
michael@0 873 *
michael@0 874 *
michael@0 875 * Return value: (transfer full):
michael@0 876 *
michael@0 877 * Since: 1.0
michael@0 878 **/
michael@0 879 hb_font_t *
michael@0 880 hb_font_create_sub_font (hb_font_t *parent)
michael@0 881 {
michael@0 882 if (unlikely (!parent))
michael@0 883 return hb_font_get_empty ();
michael@0 884
michael@0 885 hb_font_t *font = hb_font_create (parent->face);
michael@0 886
michael@0 887 if (unlikely (hb_object_is_inert (font)))
michael@0 888 return font;
michael@0 889
michael@0 890 hb_font_make_immutable (parent);
michael@0 891 font->parent = hb_font_reference (parent);
michael@0 892
michael@0 893 font->x_scale = parent->x_scale;
michael@0 894 font->y_scale = parent->y_scale;
michael@0 895 font->x_ppem = parent->x_ppem;
michael@0 896 font->y_ppem = parent->y_ppem;
michael@0 897
michael@0 898 return font;
michael@0 899 }
michael@0 900
michael@0 901 /**
michael@0 902 * hb_font_get_empty:
michael@0 903 *
michael@0 904 *
michael@0 905 *
michael@0 906 * Return value: (transfer full)
michael@0 907 *
michael@0 908 * Since: 1.0
michael@0 909 **/
michael@0 910 hb_font_t *
michael@0 911 hb_font_get_empty (void)
michael@0 912 {
michael@0 913 static const hb_font_t _hb_font_nil = {
michael@0 914 HB_OBJECT_HEADER_STATIC,
michael@0 915
michael@0 916 true, /* immutable */
michael@0 917
michael@0 918 NULL, /* parent */
michael@0 919 const_cast<hb_face_t *> (&_hb_face_nil),
michael@0 920
michael@0 921 0, /* x_scale */
michael@0 922 0, /* y_scale */
michael@0 923
michael@0 924 0, /* x_ppem */
michael@0 925 0, /* y_ppem */
michael@0 926
michael@0 927 const_cast<hb_font_funcs_t *> (&_hb_font_funcs_nil), /* klass */
michael@0 928 NULL, /* user_data */
michael@0 929 NULL, /* destroy */
michael@0 930
michael@0 931 {
michael@0 932 #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID,
michael@0 933 #include "hb-shaper-list.hh"
michael@0 934 #undef HB_SHAPER_IMPLEMENT
michael@0 935 }
michael@0 936 };
michael@0 937
michael@0 938 return const_cast<hb_font_t *> (&_hb_font_nil);
michael@0 939 }
michael@0 940
michael@0 941 /**
michael@0 942 * hb_font_reference: (skip)
michael@0 943 * @font: a font.
michael@0 944 *
michael@0 945 *
michael@0 946 *
michael@0 947 * Return value: (transfer full):
michael@0 948 *
michael@0 949 * Since: 1.0
michael@0 950 **/
michael@0 951 hb_font_t *
michael@0 952 hb_font_reference (hb_font_t *font)
michael@0 953 {
michael@0 954 return hb_object_reference (font);
michael@0 955 }
michael@0 956
michael@0 957 /**
michael@0 958 * hb_font_destroy: (skip)
michael@0 959 * @font: a font.
michael@0 960 *
michael@0 961 *
michael@0 962 *
michael@0 963 * Since: 1.0
michael@0 964 **/
michael@0 965 void
michael@0 966 hb_font_destroy (hb_font_t *font)
michael@0 967 {
michael@0 968 if (!hb_object_destroy (font)) return;
michael@0 969
michael@0 970 #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_DESTROY(shaper, font);
michael@0 971 #include "hb-shaper-list.hh"
michael@0 972 #undef HB_SHAPER_IMPLEMENT
michael@0 973
michael@0 974 if (font->destroy)
michael@0 975 font->destroy (font->user_data);
michael@0 976
michael@0 977 hb_font_destroy (font->parent);
michael@0 978 hb_face_destroy (font->face);
michael@0 979 hb_font_funcs_destroy (font->klass);
michael@0 980
michael@0 981 free (font);
michael@0 982 }
michael@0 983
michael@0 984 /**
michael@0 985 * hb_font_set_user_data: (skip)
michael@0 986 * @font: a font.
michael@0 987 * @key:
michael@0 988 * @data:
michael@0 989 * @destroy:
michael@0 990 * @replace:
michael@0 991 *
michael@0 992 *
michael@0 993 *
michael@0 994 * Return value:
michael@0 995 *
michael@0 996 * Since: 1.0
michael@0 997 **/
michael@0 998 hb_bool_t
michael@0 999 hb_font_set_user_data (hb_font_t *font,
michael@0 1000 hb_user_data_key_t *key,
michael@0 1001 void * data,
michael@0 1002 hb_destroy_func_t destroy,
michael@0 1003 hb_bool_t replace)
michael@0 1004 {
michael@0 1005 return hb_object_set_user_data (font, key, data, destroy, replace);
michael@0 1006 }
michael@0 1007
michael@0 1008 /**
michael@0 1009 * hb_font_get_user_data: (skip)
michael@0 1010 * @font: a font.
michael@0 1011 * @key:
michael@0 1012 *
michael@0 1013 *
michael@0 1014 *
michael@0 1015 * Return value: (transfer none):
michael@0 1016 *
michael@0 1017 * Since: 1.0
michael@0 1018 **/
michael@0 1019 void *
michael@0 1020 hb_font_get_user_data (hb_font_t *font,
michael@0 1021 hb_user_data_key_t *key)
michael@0 1022 {
michael@0 1023 return hb_object_get_user_data (font, key);
michael@0 1024 }
michael@0 1025
michael@0 1026 /**
michael@0 1027 * hb_font_make_immutable:
michael@0 1028 * @font: a font.
michael@0 1029 *
michael@0 1030 *
michael@0 1031 *
michael@0 1032 * Since: 1.0
michael@0 1033 **/
michael@0 1034 void
michael@0 1035 hb_font_make_immutable (hb_font_t *font)
michael@0 1036 {
michael@0 1037 if (hb_object_is_inert (font))
michael@0 1038 return;
michael@0 1039
michael@0 1040 font->immutable = true;
michael@0 1041 }
michael@0 1042
michael@0 1043 /**
michael@0 1044 * hb_font_is_immutable:
michael@0 1045 * @font: a font.
michael@0 1046 *
michael@0 1047 *
michael@0 1048 *
michael@0 1049 * Return value:
michael@0 1050 *
michael@0 1051 * Since: 1.0
michael@0 1052 **/
michael@0 1053 hb_bool_t
michael@0 1054 hb_font_is_immutable (hb_font_t *font)
michael@0 1055 {
michael@0 1056 return font->immutable;
michael@0 1057 }
michael@0 1058
michael@0 1059 /**
michael@0 1060 * hb_font_get_parent:
michael@0 1061 * @font: a font.
michael@0 1062 *
michael@0 1063 *
michael@0 1064 *
michael@0 1065 * Return value: (transfer none):
michael@0 1066 *
michael@0 1067 * Since: 1.0
michael@0 1068 **/
michael@0 1069 hb_font_t *
michael@0 1070 hb_font_get_parent (hb_font_t *font)
michael@0 1071 {
michael@0 1072 return font->parent;
michael@0 1073 }
michael@0 1074
michael@0 1075 /**
michael@0 1076 * hb_font_get_face:
michael@0 1077 * @font: a font.
michael@0 1078 *
michael@0 1079 *
michael@0 1080 *
michael@0 1081 * Return value: (transfer none):
michael@0 1082 *
michael@0 1083 * Since: 1.0
michael@0 1084 **/
michael@0 1085 hb_face_t *
michael@0 1086 hb_font_get_face (hb_font_t *font)
michael@0 1087 {
michael@0 1088 return font->face;
michael@0 1089 }
michael@0 1090
michael@0 1091
michael@0 1092 /**
michael@0 1093 * hb_font_set_funcs:
michael@0 1094 * @font: a font.
michael@0 1095 * @klass: (closure font_data) (destroy destroy) (scope notified):
michael@0 1096 * @font_data:
michael@0 1097 * @destroy:
michael@0 1098 *
michael@0 1099 *
michael@0 1100 *
michael@0 1101 * Since: 1.0
michael@0 1102 **/
michael@0 1103 void
michael@0 1104 hb_font_set_funcs (hb_font_t *font,
michael@0 1105 hb_font_funcs_t *klass,
michael@0 1106 void *font_data,
michael@0 1107 hb_destroy_func_t destroy)
michael@0 1108 {
michael@0 1109 if (font->immutable) {
michael@0 1110 if (destroy)
michael@0 1111 destroy (font_data);
michael@0 1112 return;
michael@0 1113 }
michael@0 1114
michael@0 1115 if (font->destroy)
michael@0 1116 font->destroy (font->user_data);
michael@0 1117
michael@0 1118 if (!klass)
michael@0 1119 klass = hb_font_funcs_get_empty ();
michael@0 1120
michael@0 1121 hb_font_funcs_reference (klass);
michael@0 1122 hb_font_funcs_destroy (font->klass);
michael@0 1123 font->klass = klass;
michael@0 1124 font->user_data = font_data;
michael@0 1125 font->destroy = destroy;
michael@0 1126 }
michael@0 1127
michael@0 1128 /**
michael@0 1129 * hb_font_set_funcs_data:
michael@0 1130 * @font: a font.
michael@0 1131 * @font_data: (destroy destroy) (scope notified):
michael@0 1132 * @destroy:
michael@0 1133 *
michael@0 1134 *
michael@0 1135 *
michael@0 1136 * Since: 1.0
michael@0 1137 **/
michael@0 1138 void
michael@0 1139 hb_font_set_funcs_data (hb_font_t *font,
michael@0 1140 void *font_data,
michael@0 1141 hb_destroy_func_t destroy)
michael@0 1142 {
michael@0 1143 /* Destroy user_data? */
michael@0 1144 if (font->immutable) {
michael@0 1145 if (destroy)
michael@0 1146 destroy (font_data);
michael@0 1147 return;
michael@0 1148 }
michael@0 1149
michael@0 1150 if (font->destroy)
michael@0 1151 font->destroy (font->user_data);
michael@0 1152
michael@0 1153 font->user_data = font_data;
michael@0 1154 font->destroy = destroy;
michael@0 1155 }
michael@0 1156
michael@0 1157
michael@0 1158 /**
michael@0 1159 * hb_font_set_scale:
michael@0 1160 * @font: a font.
michael@0 1161 * @x_scale:
michael@0 1162 * @y_scale:
michael@0 1163 *
michael@0 1164 *
michael@0 1165 *
michael@0 1166 * Since: 1.0
michael@0 1167 **/
michael@0 1168 void
michael@0 1169 hb_font_set_scale (hb_font_t *font,
michael@0 1170 int x_scale,
michael@0 1171 int y_scale)
michael@0 1172 {
michael@0 1173 if (font->immutable)
michael@0 1174 return;
michael@0 1175
michael@0 1176 font->x_scale = x_scale;
michael@0 1177 font->y_scale = y_scale;
michael@0 1178 }
michael@0 1179
michael@0 1180 /**
michael@0 1181 * hb_font_get_scale:
michael@0 1182 * @font: a font.
michael@0 1183 * @x_scale: (out):
michael@0 1184 * @y_scale: (out):
michael@0 1185 *
michael@0 1186 *
michael@0 1187 *
michael@0 1188 * Since: 1.0
michael@0 1189 **/
michael@0 1190 void
michael@0 1191 hb_font_get_scale (hb_font_t *font,
michael@0 1192 int *x_scale,
michael@0 1193 int *y_scale)
michael@0 1194 {
michael@0 1195 if (x_scale) *x_scale = font->x_scale;
michael@0 1196 if (y_scale) *y_scale = font->y_scale;
michael@0 1197 }
michael@0 1198
michael@0 1199 /**
michael@0 1200 * hb_font_set_ppem:
michael@0 1201 * @font: a font.
michael@0 1202 * @x_ppem:
michael@0 1203 * @y_ppem:
michael@0 1204 *
michael@0 1205 *
michael@0 1206 *
michael@0 1207 * Since: 1.0
michael@0 1208 **/
michael@0 1209 void
michael@0 1210 hb_font_set_ppem (hb_font_t *font,
michael@0 1211 unsigned int x_ppem,
michael@0 1212 unsigned int y_ppem)
michael@0 1213 {
michael@0 1214 if (font->immutable)
michael@0 1215 return;
michael@0 1216
michael@0 1217 font->x_ppem = x_ppem;
michael@0 1218 font->y_ppem = y_ppem;
michael@0 1219 }
michael@0 1220
michael@0 1221 /**
michael@0 1222 * hb_font_get_ppem:
michael@0 1223 * @font: a font.
michael@0 1224 * @x_ppem: (out):
michael@0 1225 * @y_ppem: (out):
michael@0 1226 *
michael@0 1227 *
michael@0 1228 *
michael@0 1229 * Since: 1.0
michael@0 1230 **/
michael@0 1231 void
michael@0 1232 hb_font_get_ppem (hb_font_t *font,
michael@0 1233 unsigned int *x_ppem,
michael@0 1234 unsigned int *y_ppem)
michael@0 1235 {
michael@0 1236 if (x_ppem) *x_ppem = font->x_ppem;
michael@0 1237 if (y_ppem) *y_ppem = font->y_ppem;
michael@0 1238 }

mercurial