1 /* 2 * Copyright © 2009 Red Hat, Inc. 3 * Copyright © 2011 Google, Inc. 4 * 5 * This is part of HarfBuzz, a text shaping library. 6 * 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 26 * Google Author(s): Behdad Esfahbod 27 */ 28 29 #ifndef HB_FONT_HH 30 #define HB_FONT_HH 31 32 #include "hb.hh" 33 34 #include "hb-face.hh" 35 #include "hb-shaper.hh" 36 37 38 /* 39 * hb_font_funcs_t 40 */ 41 42 #define HB_FONT_FUNCS_IMPLEMENT_CALLBACKS \ 43 HB_FONT_FUNC_IMPLEMENT (font_h_extents) \ 44 HB_FONT_FUNC_IMPLEMENT (font_v_extents) \ 45 HB_FONT_FUNC_IMPLEMENT (nominal_glyph) \ 46 HB_FONT_FUNC_IMPLEMENT (nominal_glyphs) \ 47 HB_FONT_FUNC_IMPLEMENT (variation_glyph) \ 48 HB_FONT_FUNC_IMPLEMENT (glyph_h_advance) \ 49 HB_FONT_FUNC_IMPLEMENT (glyph_v_advance) \ 50 HB_FONT_FUNC_IMPLEMENT (glyph_h_advances) \ 51 HB_FONT_FUNC_IMPLEMENT (glyph_v_advances) \ 52 HB_FONT_FUNC_IMPLEMENT (glyph_h_origin) \ 53 HB_FONT_FUNC_IMPLEMENT (glyph_v_origin) \ 54 HB_FONT_FUNC_IMPLEMENT (glyph_h_kerning) \ 55 HB_IF_NOT_DEPRECATED (HB_FONT_FUNC_IMPLEMENT (glyph_v_kerning)) \ 56 HB_FONT_FUNC_IMPLEMENT (glyph_extents) \ 57 HB_FONT_FUNC_IMPLEMENT (glyph_contour_point) \ 58 HB_FONT_FUNC_IMPLEMENT (glyph_name) \ 59 HB_FONT_FUNC_IMPLEMENT (glyph_from_name) \ 60 /* ^--- Add new callbacks here */ 61 62 struct hb_font_funcs_t 63 { 64 hb_object_header_t header; 65 66 struct { 67 #define HB_FONT_FUNC_IMPLEMENT(name) void *name; 68 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS 69 #undef HB_FONT_FUNC_IMPLEMENT 70 } user_data; 71 72 struct { 73 #define HB_FONT_FUNC_IMPLEMENT(name) hb_destroy_func_t name; 74 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS 75 #undef HB_FONT_FUNC_IMPLEMENT 76 } destroy; 77 78 /* Don't access these directly. Call font->get_*() instead. */ 79 union get_t { 80 struct get_funcs_t { 81 #define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_func_t name; 82 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS 83 #undef HB_FONT_FUNC_IMPLEMENT 84 } f; 85 void (*array[0 86 #define HB_FONT_FUNC_IMPLEMENT(name) +1 87 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS 88 #undef HB_FONT_FUNC_IMPLEMENT 89 ]) (); 90 } get; 91 }; 92 DECLARE_NULL_INSTANCE (hb_font_funcs_t); 93 94 95 /* 96 * hb_font_t 97 */ 98 99 #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INSTANTIATE_SHAPERS(shaper, font); 100 #include "hb-shaper-list.hh" 101 #undef HB_SHAPER_IMPLEMENT 102 103 struct hb_font_t 104 { 105 hb_object_header_t header; 106 107 hb_font_t *parent; 108 hb_face_t *face; 109 110 int32_t x_scale; 111 int32_t y_scale; 112 int64_t x_mult; 113 int64_t y_mult; 114 115 unsigned int x_ppem; 116 unsigned int y_ppem; 117 118 float ptem; 119 120 /* Font variation coordinates. */ 121 unsigned int num_coords; 122 int *coords; 123 float *design_coords; 124 125 hb_font_funcs_t *klass; 126 void *user_data; 127 hb_destroy_func_t destroy; 128 129 hb_shaper_object_dataset_t<hb_font_t> data; /* Various shaper data. */ 130 131 132 /* Convert from font-space to user-space */ dir_multhb_font_t133 int64_t dir_mult (hb_direction_t direction) 134 { return HB_DIRECTION_IS_VERTICAL(direction) ? y_mult : x_mult; } em_scale_xhb_font_t135 hb_position_t em_scale_x (int16_t v) { return em_mult (v, x_mult); } em_scale_yhb_font_t136 hb_position_t em_scale_y (int16_t v) { return em_mult (v, y_mult); } em_scalef_xhb_font_t137 hb_position_t em_scalef_x (float v) { return em_scalef (v, x_scale); } em_scalef_yhb_font_t138 hb_position_t em_scalef_y (float v) { return em_scalef (v, y_scale); } em_fscale_xhb_font_t139 float em_fscale_x (int16_t v) { return em_fscale (v, x_scale); } em_fscale_yhb_font_t140 float em_fscale_y (int16_t v) { return em_fscale (v, y_scale); } em_scale_dirhb_font_t141 hb_position_t em_scale_dir (int16_t v, hb_direction_t direction) 142 { return em_mult (v, dir_mult (direction)); } 143 144 /* Convert from parent-font user-space to our user-space */ parent_scale_x_distancehb_font_t145 hb_position_t parent_scale_x_distance (hb_position_t v) 146 { 147 if (unlikely (parent && parent->x_scale != x_scale)) 148 return (hb_position_t) (v * (int64_t) this->x_scale / this->parent->x_scale); 149 return v; 150 } parent_scale_y_distancehb_font_t151 hb_position_t parent_scale_y_distance (hb_position_t v) 152 { 153 if (unlikely (parent && parent->y_scale != y_scale)) 154 return (hb_position_t) (v * (int64_t) this->y_scale / this->parent->y_scale); 155 return v; 156 } parent_scale_x_positionhb_font_t157 hb_position_t parent_scale_x_position (hb_position_t v) 158 { return parent_scale_x_distance (v); } parent_scale_y_positionhb_font_t159 hb_position_t parent_scale_y_position (hb_position_t v) 160 { return parent_scale_y_distance (v); } 161 parent_scale_distancehb_font_t162 void parent_scale_distance (hb_position_t *x, hb_position_t *y) 163 { 164 *x = parent_scale_x_distance (*x); 165 *y = parent_scale_y_distance (*y); 166 } parent_scale_positionhb_font_t167 void parent_scale_position (hb_position_t *x, hb_position_t *y) 168 { 169 *x = parent_scale_x_position (*x); 170 *y = parent_scale_y_position (*y); 171 } 172 173 174 /* Public getters */ 175 176 HB_INTERNAL bool has_func (unsigned int i); 177 HB_INTERNAL bool has_func_set (unsigned int i); 178 179 /* has_* ... */ 180 #define HB_FONT_FUNC_IMPLEMENT(name) \ 181 bool \ 182 has_##name##_func () \ 183 { \ 184 hb_font_funcs_t *funcs = this->klass; \ 185 unsigned int i = offsetof (hb_font_funcs_t::get_t::get_funcs_t, name) / sizeof (funcs->get.array[0]); \ 186 return has_func (i); \ 187 } \ 188 bool \ 189 has_##name##_func_set () \ 190 { \ 191 hb_font_funcs_t *funcs = this->klass; \ 192 unsigned int i = offsetof (hb_font_funcs_t::get_t::get_funcs_t, name) / sizeof (funcs->get.array[0]); \ 193 return has_func_set (i); \ 194 } 195 HB_FONT_FUNCS_IMPLEMENT_CALLBACKS 196 #undef HB_FONT_FUNC_IMPLEMENT 197 get_font_h_extentshb_font_t198 hb_bool_t get_font_h_extents (hb_font_extents_t *extents) 199 { 200 memset (extents, 0, sizeof (*extents)); 201 return klass->get.f.font_h_extents (this, user_data, 202 extents, 203 klass->user_data.font_h_extents); 204 } get_font_v_extentshb_font_t205 hb_bool_t get_font_v_extents (hb_font_extents_t *extents) 206 { 207 memset (extents, 0, sizeof (*extents)); 208 return klass->get.f.font_v_extents (this, user_data, 209 extents, 210 klass->user_data.font_v_extents); 211 } 212 has_glyphhb_font_t213 bool has_glyph (hb_codepoint_t unicode) 214 { 215 hb_codepoint_t glyph; 216 return get_nominal_glyph (unicode, &glyph); 217 } 218 get_nominal_glyphhb_font_t219 hb_bool_t get_nominal_glyph (hb_codepoint_t unicode, 220 hb_codepoint_t *glyph, 221 hb_codepoint_t not_found = 0) 222 { 223 *glyph = not_found; 224 return klass->get.f.nominal_glyph (this, user_data, 225 unicode, glyph, 226 klass->user_data.nominal_glyph); 227 } get_nominal_glyphshb_font_t228 unsigned int get_nominal_glyphs (unsigned int count, 229 const hb_codepoint_t *first_unicode, 230 unsigned int unicode_stride, 231 hb_codepoint_t *first_glyph, 232 unsigned int glyph_stride) 233 { 234 return klass->get.f.nominal_glyphs (this, user_data, 235 count, 236 first_unicode, unicode_stride, 237 first_glyph, glyph_stride, 238 klass->user_data.nominal_glyphs); 239 } 240 get_variation_glyphhb_font_t241 hb_bool_t get_variation_glyph (hb_codepoint_t unicode, hb_codepoint_t variation_selector, 242 hb_codepoint_t *glyph, 243 hb_codepoint_t not_found = 0) 244 { 245 *glyph = not_found; 246 return klass->get.f.variation_glyph (this, user_data, 247 unicode, variation_selector, glyph, 248 klass->user_data.variation_glyph); 249 } 250 get_glyph_h_advancehb_font_t251 hb_position_t get_glyph_h_advance (hb_codepoint_t glyph) 252 { 253 return klass->get.f.glyph_h_advance (this, user_data, 254 glyph, 255 klass->user_data.glyph_h_advance); 256 } 257 get_glyph_v_advancehb_font_t258 hb_position_t get_glyph_v_advance (hb_codepoint_t glyph) 259 { 260 return klass->get.f.glyph_v_advance (this, user_data, 261 glyph, 262 klass->user_data.glyph_v_advance); 263 } 264 get_glyph_h_advanceshb_font_t265 void get_glyph_h_advances (unsigned int count, 266 const hb_codepoint_t *first_glyph, 267 unsigned int glyph_stride, 268 hb_position_t *first_advance, 269 unsigned int advance_stride) 270 { 271 return klass->get.f.glyph_h_advances (this, user_data, 272 count, 273 first_glyph, glyph_stride, 274 first_advance, advance_stride, 275 klass->user_data.glyph_h_advances); 276 } 277 get_glyph_v_advanceshb_font_t278 void get_glyph_v_advances (unsigned int count, 279 const hb_codepoint_t *first_glyph, 280 unsigned int glyph_stride, 281 hb_position_t *first_advance, 282 unsigned int advance_stride) 283 { 284 return klass->get.f.glyph_v_advances (this, user_data, 285 count, 286 first_glyph, glyph_stride, 287 first_advance, advance_stride, 288 klass->user_data.glyph_v_advances); 289 } 290 get_glyph_h_originhb_font_t291 hb_bool_t get_glyph_h_origin (hb_codepoint_t glyph, 292 hb_position_t *x, hb_position_t *y) 293 { 294 *x = *y = 0; 295 return klass->get.f.glyph_h_origin (this, user_data, 296 glyph, x, y, 297 klass->user_data.glyph_h_origin); 298 } 299 get_glyph_v_originhb_font_t300 hb_bool_t get_glyph_v_origin (hb_codepoint_t glyph, 301 hb_position_t *x, hb_position_t *y) 302 { 303 *x = *y = 0; 304 return klass->get.f.glyph_v_origin (this, user_data, 305 glyph, x, y, 306 klass->user_data.glyph_v_origin); 307 } 308 get_glyph_h_kerninghb_font_t309 hb_position_t get_glyph_h_kerning (hb_codepoint_t left_glyph, 310 hb_codepoint_t right_glyph) 311 { 312 #ifdef HB_DISABLE_DEPRECATED 313 return 0; 314 #else 315 return klass->get.f.glyph_h_kerning (this, user_data, 316 left_glyph, right_glyph, 317 klass->user_data.glyph_h_kerning); 318 #endif 319 } 320 get_glyph_v_kerninghb_font_t321 hb_position_t get_glyph_v_kerning (hb_codepoint_t top_glyph, 322 hb_codepoint_t bottom_glyph) 323 { 324 #ifdef HB_DISABLE_DEPRECATED 325 return 0; 326 #else 327 return klass->get.f.glyph_v_kerning (this, user_data, 328 top_glyph, bottom_glyph, 329 klass->user_data.glyph_v_kerning); 330 #endif 331 } 332 get_glyph_extentshb_font_t333 hb_bool_t get_glyph_extents (hb_codepoint_t glyph, 334 hb_glyph_extents_t *extents) 335 { 336 memset (extents, 0, sizeof (*extents)); 337 return klass->get.f.glyph_extents (this, user_data, 338 glyph, 339 extents, 340 klass->user_data.glyph_extents); 341 } 342 get_glyph_contour_pointhb_font_t343 hb_bool_t get_glyph_contour_point (hb_codepoint_t glyph, unsigned int point_index, 344 hb_position_t *x, hb_position_t *y) 345 { 346 *x = *y = 0; 347 return klass->get.f.glyph_contour_point (this, user_data, 348 glyph, point_index, 349 x, y, 350 klass->user_data.glyph_contour_point); 351 } 352 get_glyph_namehb_font_t353 hb_bool_t get_glyph_name (hb_codepoint_t glyph, 354 char *name, unsigned int size) 355 { 356 if (size) *name = '\0'; 357 return klass->get.f.glyph_name (this, user_data, 358 glyph, 359 name, size, 360 klass->user_data.glyph_name); 361 } 362 get_glyph_from_namehb_font_t363 hb_bool_t get_glyph_from_name (const char *name, int len, /* -1 means nul-terminated */ 364 hb_codepoint_t *glyph) 365 { 366 *glyph = 0; 367 if (len == -1) len = strlen (name); 368 return klass->get.f.glyph_from_name (this, user_data, 369 name, len, 370 glyph, 371 klass->user_data.glyph_from_name); 372 } 373 374 375 /* A bit higher-level, and with fallback */ 376 get_h_extents_with_fallbackhb_font_t377 void get_h_extents_with_fallback (hb_font_extents_t *extents) 378 { 379 if (!get_font_h_extents (extents)) 380 { 381 extents->ascender = y_scale * .8; 382 extents->descender = extents->ascender - y_scale; 383 extents->line_gap = 0; 384 } 385 } get_v_extents_with_fallbackhb_font_t386 void get_v_extents_with_fallback (hb_font_extents_t *extents) 387 { 388 if (!get_font_v_extents (extents)) 389 { 390 extents->ascender = x_scale / 2; 391 extents->descender = extents->ascender - x_scale; 392 extents->line_gap = 0; 393 } 394 } 395 get_extents_for_directionhb_font_t396 void get_extents_for_direction (hb_direction_t direction, 397 hb_font_extents_t *extents) 398 { 399 if (likely (HB_DIRECTION_IS_HORIZONTAL (direction))) 400 get_h_extents_with_fallback (extents); 401 else 402 get_v_extents_with_fallback (extents); 403 } 404 get_glyph_advance_for_directionhb_font_t405 void get_glyph_advance_for_direction (hb_codepoint_t glyph, 406 hb_direction_t direction, 407 hb_position_t *x, hb_position_t *y) 408 { 409 *x = *y = 0; 410 if (likely (HB_DIRECTION_IS_HORIZONTAL (direction))) 411 *x = get_glyph_h_advance (glyph); 412 else 413 *y = get_glyph_v_advance (glyph); 414 } get_glyph_advances_for_directionhb_font_t415 void get_glyph_advances_for_direction (hb_direction_t direction, 416 unsigned int count, 417 const hb_codepoint_t *first_glyph, 418 unsigned glyph_stride, 419 hb_position_t *first_advance, 420 unsigned advance_stride) 421 { 422 if (likely (HB_DIRECTION_IS_HORIZONTAL (direction))) 423 get_glyph_h_advances (count, first_glyph, glyph_stride, first_advance, advance_stride); 424 else 425 get_glyph_v_advances (count, first_glyph, glyph_stride, first_advance, advance_stride); 426 } 427 guess_v_origin_minus_h_originhb_font_t428 void guess_v_origin_minus_h_origin (hb_codepoint_t glyph, 429 hb_position_t *x, hb_position_t *y) 430 { 431 *x = get_glyph_h_advance (glyph) / 2; 432 433 /* TODO cache this somehow?! */ 434 hb_font_extents_t extents; 435 get_h_extents_with_fallback (&extents); 436 *y = extents.ascender; 437 } 438 get_glyph_h_origin_with_fallbackhb_font_t439 void get_glyph_h_origin_with_fallback (hb_codepoint_t glyph, 440 hb_position_t *x, hb_position_t *y) 441 { 442 if (!get_glyph_h_origin (glyph, x, y) && 443 get_glyph_v_origin (glyph, x, y)) 444 { 445 hb_position_t dx, dy; 446 guess_v_origin_minus_h_origin (glyph, &dx, &dy); 447 *x -= dx; *y -= dy; 448 } 449 } get_glyph_v_origin_with_fallbackhb_font_t450 void get_glyph_v_origin_with_fallback (hb_codepoint_t glyph, 451 hb_position_t *x, hb_position_t *y) 452 { 453 if (!get_glyph_v_origin (glyph, x, y) && 454 get_glyph_h_origin (glyph, x, y)) 455 { 456 hb_position_t dx, dy; 457 guess_v_origin_minus_h_origin (glyph, &dx, &dy); 458 *x += dx; *y += dy; 459 } 460 } 461 get_glyph_origin_for_directionhb_font_t462 void get_glyph_origin_for_direction (hb_codepoint_t glyph, 463 hb_direction_t direction, 464 hb_position_t *x, hb_position_t *y) 465 { 466 if (likely (HB_DIRECTION_IS_HORIZONTAL (direction))) 467 get_glyph_h_origin_with_fallback (glyph, x, y); 468 else 469 get_glyph_v_origin_with_fallback (glyph, x, y); 470 } 471 add_glyph_h_originhb_font_t472 void add_glyph_h_origin (hb_codepoint_t glyph, 473 hb_position_t *x, hb_position_t *y) 474 { 475 hb_position_t origin_x, origin_y; 476 477 get_glyph_h_origin_with_fallback (glyph, &origin_x, &origin_y); 478 479 *x += origin_x; 480 *y += origin_y; 481 } add_glyph_v_originhb_font_t482 void add_glyph_v_origin (hb_codepoint_t glyph, 483 hb_position_t *x, hb_position_t *y) 484 { 485 hb_position_t origin_x, origin_y; 486 487 get_glyph_v_origin_with_fallback (glyph, &origin_x, &origin_y); 488 489 *x += origin_x; 490 *y += origin_y; 491 } add_glyph_origin_for_directionhb_font_t492 void add_glyph_origin_for_direction (hb_codepoint_t glyph, 493 hb_direction_t direction, 494 hb_position_t *x, hb_position_t *y) 495 { 496 hb_position_t origin_x, origin_y; 497 498 get_glyph_origin_for_direction (glyph, direction, &origin_x, &origin_y); 499 500 *x += origin_x; 501 *y += origin_y; 502 } 503 subtract_glyph_h_originhb_font_t504 void subtract_glyph_h_origin (hb_codepoint_t glyph, 505 hb_position_t *x, hb_position_t *y) 506 { 507 hb_position_t origin_x, origin_y; 508 509 get_glyph_h_origin_with_fallback (glyph, &origin_x, &origin_y); 510 511 *x -= origin_x; 512 *y -= origin_y; 513 } subtract_glyph_v_originhb_font_t514 void subtract_glyph_v_origin (hb_codepoint_t glyph, 515 hb_position_t *x, hb_position_t *y) 516 { 517 hb_position_t origin_x, origin_y; 518 519 get_glyph_v_origin_with_fallback (glyph, &origin_x, &origin_y); 520 521 *x -= origin_x; 522 *y -= origin_y; 523 } subtract_glyph_origin_for_directionhb_font_t524 void subtract_glyph_origin_for_direction (hb_codepoint_t glyph, 525 hb_direction_t direction, 526 hb_position_t *x, hb_position_t *y) 527 { 528 hb_position_t origin_x, origin_y; 529 530 get_glyph_origin_for_direction (glyph, direction, &origin_x, &origin_y); 531 532 *x -= origin_x; 533 *y -= origin_y; 534 } 535 get_glyph_kerning_for_directionhb_font_t536 void get_glyph_kerning_for_direction (hb_codepoint_t first_glyph, hb_codepoint_t second_glyph, 537 hb_direction_t direction, 538 hb_position_t *x, hb_position_t *y) 539 { 540 if (likely (HB_DIRECTION_IS_HORIZONTAL (direction))) { 541 *y = 0; 542 *x = get_glyph_h_kerning (first_glyph, second_glyph); 543 } else { 544 *x = 0; 545 *y = get_glyph_v_kerning (first_glyph, second_glyph); 546 } 547 } 548 get_glyph_extents_for_originhb_font_t549 hb_bool_t get_glyph_extents_for_origin (hb_codepoint_t glyph, 550 hb_direction_t direction, 551 hb_glyph_extents_t *extents) 552 { 553 hb_bool_t ret = get_glyph_extents (glyph, extents); 554 555 if (ret) 556 subtract_glyph_origin_for_direction (glyph, direction, &extents->x_bearing, &extents->y_bearing); 557 558 return ret; 559 } 560 get_glyph_contour_point_for_originhb_font_t561 hb_bool_t get_glyph_contour_point_for_origin (hb_codepoint_t glyph, unsigned int point_index, 562 hb_direction_t direction, 563 hb_position_t *x, hb_position_t *y) 564 { 565 hb_bool_t ret = get_glyph_contour_point (glyph, point_index, x, y); 566 567 if (ret) 568 subtract_glyph_origin_for_direction (glyph, direction, x, y); 569 570 return ret; 571 } 572 573 /* Generates gidDDD if glyph has no name. */ 574 void glyph_to_stringhb_font_t575 glyph_to_string (hb_codepoint_t glyph, 576 char *s, unsigned int size) 577 { 578 if (get_glyph_name (glyph, s, size)) return; 579 580 if (size && snprintf (s, size, "gid%u", glyph) < 0) 581 *s = '\0'; 582 } 583 584 /* Parses gidDDD and uniUUUU strings automatically. */ 585 hb_bool_t glyph_from_stringhb_font_t586 glyph_from_string (const char *s, int len, /* -1 means nul-terminated */ 587 hb_codepoint_t *glyph) 588 { 589 if (get_glyph_from_name (s, len, glyph)) return true; 590 591 if (len == -1) len = strlen (s); 592 593 /* Straight glyph index. */ 594 if (hb_codepoint_parse (s, len, 10, glyph)) 595 return true; 596 597 if (len > 3) 598 { 599 /* gidDDD syntax for glyph indices. */ 600 if (0 == strncmp (s, "gid", 3) && 601 hb_codepoint_parse (s + 3, len - 3, 10, glyph)) 602 return true; 603 604 /* uniUUUU and other Unicode character indices. */ 605 hb_codepoint_t unichar; 606 if (0 == strncmp (s, "uni", 3) && 607 hb_codepoint_parse (s + 3, len - 3, 16, &unichar) && 608 get_nominal_glyph (unichar, glyph)) 609 return true; 610 } 611 612 return false; 613 } 614 mults_changedhb_font_t615 void mults_changed () 616 { 617 signed upem = face->get_upem (); 618 x_mult = ((int64_t) x_scale << 16) / upem; 619 y_mult = ((int64_t) y_scale << 16) / upem; 620 } 621 em_multhb_font_t622 hb_position_t em_mult (int16_t v, int64_t mult) 623 { return (hb_position_t) ((v * mult + 32768) >> 16); } em_scalefhb_font_t624 hb_position_t em_scalef (float v, int scale) 625 { return (hb_position_t) roundf (v * scale / face->get_upem ()); } em_fscalehb_font_t626 float em_fscale (int16_t v, int scale) 627 { return (float) v * scale / face->get_upem (); } 628 }; 629 DECLARE_NULL_INSTANCE (hb_font_t); 630 631 632 #endif /* HB_FONT_HH */ 633