hb-ot-shape-fallback.cc (19677B)
1 /* 2 * Copyright © 2011,2012 Google, Inc. 3 * 4 * This is part of HarfBuzz, a text shaping library. 5 * 6 * Permission is hereby granted, without written agreement and without 7 * license or royalty fees, to use, copy, modify, and distribute this 8 * software and its documentation for any purpose, provided that the 9 * above copyright notice and the following two paragraphs appear in 10 * all copies of this software. 11 * 12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR 13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN 15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 16 * DAMAGE. 17 * 18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, 19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO 22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 23 * 24 * Google Author(s): Behdad Esfahbod 25 */ 26 27 #include "hb.hh" 28 29 #ifndef HB_NO_OT_SHAPE 30 31 #include "hb-ot-shape-fallback.hh" 32 #include "hb-kern.hh" 33 34 static unsigned int 35 recategorize_combining_class (hb_codepoint_t u, 36 unsigned int klass) 37 { 38 if (klass >= 200) 39 return klass; 40 41 /* Thai / Lao need some per-character work. */ 42 if ((u & ~0xFF) == 0x0E00u) 43 { 44 if (unlikely (klass == 0)) 45 { 46 switch (u) 47 { 48 case 0x0E31u: 49 case 0x0E34u: 50 case 0x0E35u: 51 case 0x0E36u: 52 case 0x0E37u: 53 case 0x0E47u: 54 case 0x0E4Cu: 55 case 0x0E4Du: 56 case 0x0E4Eu: 57 klass = HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT; 58 break; 59 60 case 0x0EB1u: 61 case 0x0EB4u: 62 case 0x0EB5u: 63 case 0x0EB6u: 64 case 0x0EB7u: 65 case 0x0EBBu: 66 case 0x0ECCu: 67 case 0x0ECDu: 68 klass = HB_UNICODE_COMBINING_CLASS_ABOVE; 69 break; 70 71 case 0x0EBCu: 72 klass = HB_UNICODE_COMBINING_CLASS_BELOW; 73 break; 74 } 75 } else { 76 /* Thai virama is below-right */ 77 if (u == 0x0E3Au) 78 klass = HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT; 79 } 80 } 81 82 switch (klass) 83 { 84 85 /* Hebrew */ 86 87 case HB_MODIFIED_COMBINING_CLASS_CCC10: /* sheva */ 88 case HB_MODIFIED_COMBINING_CLASS_CCC11: /* hataf segol */ 89 case HB_MODIFIED_COMBINING_CLASS_CCC12: /* hataf patah */ 90 case HB_MODIFIED_COMBINING_CLASS_CCC13: /* hataf qamats */ 91 case HB_MODIFIED_COMBINING_CLASS_CCC14: /* hiriq */ 92 case HB_MODIFIED_COMBINING_CLASS_CCC15: /* tsere */ 93 case HB_MODIFIED_COMBINING_CLASS_CCC16: /* segol */ 94 case HB_MODIFIED_COMBINING_CLASS_CCC17: /* patah */ 95 case HB_MODIFIED_COMBINING_CLASS_CCC18: /* qamats & qamats qatan */ 96 case HB_MODIFIED_COMBINING_CLASS_CCC20: /* qubuts */ 97 case HB_MODIFIED_COMBINING_CLASS_CCC22: /* meteg */ 98 return HB_UNICODE_COMBINING_CLASS_BELOW; 99 100 case HB_MODIFIED_COMBINING_CLASS_CCC23: /* rafe */ 101 return HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE; 102 103 case HB_MODIFIED_COMBINING_CLASS_CCC24: /* shin dot */ 104 return HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT; 105 106 case HB_MODIFIED_COMBINING_CLASS_CCC25: /* sin dot */ 107 case HB_MODIFIED_COMBINING_CLASS_CCC19: /* holam & holam haser for vav */ 108 return HB_UNICODE_COMBINING_CLASS_ABOVE_LEFT; 109 110 case HB_MODIFIED_COMBINING_CLASS_CCC26: /* point varika */ 111 return HB_UNICODE_COMBINING_CLASS_ABOVE; 112 113 case HB_MODIFIED_COMBINING_CLASS_CCC21: /* dagesh */ 114 break; 115 116 117 /* Arabic and Syriac */ 118 119 case HB_MODIFIED_COMBINING_CLASS_CCC27: /* fathatan */ 120 case HB_MODIFIED_COMBINING_CLASS_CCC28: /* dammatan */ 121 case HB_MODIFIED_COMBINING_CLASS_CCC30: /* fatha */ 122 case HB_MODIFIED_COMBINING_CLASS_CCC31: /* damma */ 123 case HB_MODIFIED_COMBINING_CLASS_CCC33: /* shadda */ 124 case HB_MODIFIED_COMBINING_CLASS_CCC34: /* sukun */ 125 case HB_MODIFIED_COMBINING_CLASS_CCC35: /* superscript alef */ 126 case HB_MODIFIED_COMBINING_CLASS_CCC36: /* superscript alaph */ 127 return HB_UNICODE_COMBINING_CLASS_ABOVE; 128 129 case HB_MODIFIED_COMBINING_CLASS_CCC29: /* kasratan */ 130 case HB_MODIFIED_COMBINING_CLASS_CCC32: /* kasra */ 131 return HB_UNICODE_COMBINING_CLASS_BELOW; 132 133 134 /* Thai */ 135 136 case HB_MODIFIED_COMBINING_CLASS_CCC103: /* sara u / sara uu */ 137 return HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT; 138 139 case HB_MODIFIED_COMBINING_CLASS_CCC107: /* mai */ 140 return HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT; 141 142 143 /* Lao */ 144 145 case HB_MODIFIED_COMBINING_CLASS_CCC118: /* sign u / sign uu */ 146 return HB_UNICODE_COMBINING_CLASS_BELOW; 147 148 case HB_MODIFIED_COMBINING_CLASS_CCC122: /* mai */ 149 return HB_UNICODE_COMBINING_CLASS_ABOVE; 150 151 152 /* Tibetan */ 153 154 case HB_MODIFIED_COMBINING_CLASS_CCC129: /* sign aa */ 155 return HB_UNICODE_COMBINING_CLASS_BELOW; 156 157 case HB_MODIFIED_COMBINING_CLASS_CCC130: /* sign i*/ 158 return HB_UNICODE_COMBINING_CLASS_ABOVE; 159 160 case HB_MODIFIED_COMBINING_CLASS_CCC132: /* sign u */ 161 return HB_UNICODE_COMBINING_CLASS_BELOW; 162 163 } 164 165 return klass; 166 } 167 168 void 169 _hb_ot_shape_fallback_mark_position_recategorize_marks (const hb_ot_shape_plan_t *plan HB_UNUSED, 170 hb_font_t *font HB_UNUSED, 171 hb_buffer_t *buffer) 172 { 173 #ifdef HB_NO_OT_SHAPE_FALLBACK 174 return; 175 #endif 176 177 unsigned int count = buffer->len; 178 hb_glyph_info_t *info = buffer->info; 179 for (unsigned int i = 0; i < count; i++) 180 if (_hb_glyph_info_get_general_category (&info[i]) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK) { 181 unsigned int combining_class = _hb_glyph_info_get_modified_combining_class (&info[i]); 182 combining_class = recategorize_combining_class (info[i].codepoint, combining_class); 183 _hb_glyph_info_set_modified_combining_class (&info[i], combining_class); 184 } 185 } 186 187 188 static void 189 zero_mark_advances (hb_buffer_t *buffer, 190 unsigned int start, 191 unsigned int end, 192 bool adjust_offsets_when_zeroing) 193 { 194 hb_glyph_info_t *info = buffer->info; 195 for (unsigned int i = start; i < end; i++) 196 if (_hb_glyph_info_get_general_category (&info[i]) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK) 197 { 198 if (adjust_offsets_when_zeroing) 199 { 200 buffer->pos[i].x_offset -= buffer->pos[i].x_advance; 201 buffer->pos[i].y_offset -= buffer->pos[i].y_advance; 202 } 203 buffer->pos[i].x_advance = 0; 204 buffer->pos[i].y_advance = 0; 205 } 206 } 207 208 static inline void 209 position_mark (const hb_ot_shape_plan_t *plan HB_UNUSED, 210 hb_font_t *font, 211 hb_buffer_t *buffer, 212 hb_glyph_extents_t &base_extents, 213 unsigned int i, 214 unsigned int combining_class) 215 { 216 hb_glyph_extents_t mark_extents; 217 if (!font->get_glyph_extents (buffer->info[i].codepoint, &mark_extents)) 218 return; 219 220 hb_position_t y_gap = font->y_scale / 16; 221 222 hb_glyph_position_t &pos = buffer->pos[i]; 223 pos.x_offset = pos.y_offset = 0; 224 225 226 /* We don't position LEFT and RIGHT marks. */ 227 228 /* X positioning */ 229 switch (combining_class) 230 { 231 case HB_UNICODE_COMBINING_CLASS_DOUBLE_BELOW: 232 case HB_UNICODE_COMBINING_CLASS_DOUBLE_ABOVE: 233 if (buffer->props.direction == HB_DIRECTION_LTR) { 234 pos.x_offset += base_extents.x_bearing + base_extents.width - mark_extents.width / 2 - mark_extents.x_bearing; 235 break; 236 } else if (buffer->props.direction == HB_DIRECTION_RTL) { 237 pos.x_offset += base_extents.x_bearing - mark_extents.width / 2 - mark_extents.x_bearing; 238 break; 239 } 240 HB_FALLTHROUGH; 241 242 default: 243 case HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW: 244 case HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE: 245 case HB_UNICODE_COMBINING_CLASS_BELOW: 246 case HB_UNICODE_COMBINING_CLASS_ABOVE: 247 /* Center align. */ 248 pos.x_offset += base_extents.x_bearing + (base_extents.width - mark_extents.width) / 2 - mark_extents.x_bearing; 249 break; 250 251 case HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW_LEFT: 252 case HB_UNICODE_COMBINING_CLASS_BELOW_LEFT: 253 case HB_UNICODE_COMBINING_CLASS_ABOVE_LEFT: 254 /* Left align. */ 255 pos.x_offset += base_extents.x_bearing - mark_extents.x_bearing; 256 break; 257 258 case HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE_RIGHT: 259 case HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT: 260 case HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT: 261 /* Right align. */ 262 pos.x_offset += base_extents.x_bearing + base_extents.width - mark_extents.width - mark_extents.x_bearing; 263 break; 264 } 265 266 /* Y positioning */ 267 switch (combining_class) 268 { 269 case HB_UNICODE_COMBINING_CLASS_DOUBLE_BELOW: 270 case HB_UNICODE_COMBINING_CLASS_BELOW_LEFT: 271 case HB_UNICODE_COMBINING_CLASS_BELOW: 272 case HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT: 273 /* Add gap, fall-through. */ 274 base_extents.height -= y_gap; 275 HB_FALLTHROUGH; 276 277 case HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW_LEFT: 278 case HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW: 279 pos.y_offset = base_extents.y_bearing + base_extents.height - mark_extents.y_bearing; 280 /* Never shift up "below" marks. */ 281 if ((y_gap > 0) == (pos.y_offset > 0)) 282 { 283 base_extents.height -= pos.y_offset; 284 pos.y_offset = 0; 285 } 286 base_extents.height += mark_extents.height; 287 break; 288 289 case HB_UNICODE_COMBINING_CLASS_DOUBLE_ABOVE: 290 case HB_UNICODE_COMBINING_CLASS_ABOVE_LEFT: 291 case HB_UNICODE_COMBINING_CLASS_ABOVE: 292 case HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT: 293 /* Add gap, fall-through. */ 294 base_extents.y_bearing += y_gap; 295 base_extents.height -= y_gap; 296 HB_FALLTHROUGH; 297 298 case HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE: 299 case HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE_RIGHT: 300 pos.y_offset = base_extents.y_bearing - (mark_extents.y_bearing + mark_extents.height); 301 /* Don't shift down "above" marks too much. */ 302 if ((y_gap > 0) != (pos.y_offset > 0)) 303 { 304 int correction = -pos.y_offset / 2; 305 base_extents.y_bearing += correction; 306 base_extents.height -= correction; 307 pos.y_offset += correction; 308 } 309 base_extents.y_bearing -= mark_extents.height; 310 base_extents.height += mark_extents.height; 311 break; 312 } 313 } 314 315 static inline void 316 position_around_base (const hb_ot_shape_plan_t *plan, 317 hb_font_t *font, 318 hb_buffer_t *buffer, 319 unsigned int base, 320 unsigned int end, 321 bool adjust_offsets_when_zeroing) 322 { 323 hb_direction_t horiz_dir = HB_DIRECTION_INVALID; 324 325 buffer->unsafe_to_break (base, end); 326 327 hb_glyph_extents_t base_extents; 328 if (!font->get_glyph_extents (buffer->info[base].codepoint, 329 &base_extents)) 330 { 331 /* If extents don't work, zero marks and go home. */ 332 zero_mark_advances (buffer, base + 1, end, adjust_offsets_when_zeroing); 333 return; 334 } 335 base_extents.y_bearing += buffer->pos[base].y_offset; 336 /* Use horizontal advance for horizontal positioning. 337 * Generally a better idea. Also works for zero-ink glyphs. See: 338 * https://github.com/harfbuzz/harfbuzz/issues/1532 */ 339 base_extents.x_bearing = 0; 340 base_extents.width = font->get_glyph_h_advance (buffer->info[base].codepoint); 341 342 unsigned int lig_id = _hb_glyph_info_get_lig_id (&buffer->info[base]); 343 /* Use integer for num_lig_components such that it doesn't convert to unsigned 344 * when we divide or multiply by it. */ 345 int num_lig_components = _hb_glyph_info_get_lig_num_comps (&buffer->info[base]); 346 347 hb_position_t x_offset = 0, y_offset = 0; 348 if (HB_DIRECTION_IS_FORWARD (buffer->props.direction)) { 349 x_offset -= buffer->pos[base].x_advance; 350 y_offset -= buffer->pos[base].y_advance; 351 } 352 353 hb_glyph_extents_t component_extents = base_extents; 354 int last_lig_component = -1; 355 unsigned int last_combining_class = 255; 356 hb_glyph_extents_t cluster_extents = base_extents; /* Initialization is just to shut gcc up. */ 357 hb_glyph_info_t *info = buffer->info; 358 for (unsigned int i = base + 1; i < end; i++) 359 if (_hb_glyph_info_get_modified_combining_class (&info[i])) 360 { 361 if (num_lig_components > 1) { 362 unsigned int this_lig_id = _hb_glyph_info_get_lig_id (&info[i]); 363 int this_lig_component = _hb_glyph_info_get_lig_comp (&info[i]) - 1; 364 /* Conditions for attaching to the last component. */ 365 if (!lig_id || lig_id != this_lig_id || this_lig_component >= num_lig_components) 366 this_lig_component = num_lig_components - 1; 367 if (last_lig_component != this_lig_component) 368 { 369 last_lig_component = this_lig_component; 370 last_combining_class = 255; 371 component_extents = base_extents; 372 if (unlikely (horiz_dir == HB_DIRECTION_INVALID)) { 373 if (HB_DIRECTION_IS_HORIZONTAL (plan->props.direction)) 374 horiz_dir = plan->props.direction; 375 else 376 horiz_dir = hb_script_get_horizontal_direction (plan->props.script); 377 } 378 if (horiz_dir == HB_DIRECTION_LTR) 379 component_extents.x_bearing += (this_lig_component * component_extents.width) / num_lig_components; 380 else 381 component_extents.x_bearing += ((num_lig_components - 1 - this_lig_component) * component_extents.width) / num_lig_components; 382 component_extents.width /= num_lig_components; 383 } 384 } 385 386 unsigned int this_combining_class = _hb_glyph_info_get_modified_combining_class (&info[i]); 387 if (last_combining_class != this_combining_class) 388 { 389 last_combining_class = this_combining_class; 390 cluster_extents = component_extents; 391 } 392 393 position_mark (plan, font, buffer, cluster_extents, i, this_combining_class); 394 395 buffer->pos[i].x_advance = 0; 396 buffer->pos[i].y_advance = 0; 397 buffer->pos[i].x_offset += x_offset; 398 buffer->pos[i].y_offset += y_offset; 399 400 } else { 401 if (HB_DIRECTION_IS_FORWARD (buffer->props.direction)) { 402 x_offset -= buffer->pos[i].x_advance; 403 y_offset -= buffer->pos[i].y_advance; 404 } else { 405 x_offset += buffer->pos[i].x_advance; 406 y_offset += buffer->pos[i].y_advance; 407 } 408 } 409 } 410 411 static inline void 412 position_cluster_impl (const hb_ot_shape_plan_t *plan, 413 hb_font_t *font, 414 hb_buffer_t *buffer, 415 unsigned int start, 416 unsigned int end, 417 bool adjust_offsets_when_zeroing) 418 { 419 /* Find the base glyph */ 420 hb_glyph_info_t *info = buffer->info; 421 for (unsigned int i = start; i < end; i++) 422 if (!_hb_glyph_info_is_unicode_mark (&info[i])) 423 { 424 /* Find mark glyphs */ 425 unsigned int j; 426 for (j = i + 1; j < end; j++) 427 { 428 if (_hb_glyph_info_is_hidden (&info[j]) || 429 _hb_glyph_info_is_default_ignorable (&info[j])) 430 continue; 431 if (!_hb_glyph_info_is_unicode_mark (&info[j])) 432 break; 433 } 434 435 position_around_base (plan, font, buffer, i, j, adjust_offsets_when_zeroing); 436 437 i = j - 1; 438 } 439 } 440 441 static HB_ALWAYS_INLINE void 442 position_cluster (const hb_ot_shape_plan_t *plan, 443 hb_font_t *font, 444 hb_buffer_t *buffer, 445 unsigned int start, 446 unsigned int end, 447 bool adjust_offsets_when_zeroing) 448 { 449 if (end - start < 2) 450 return; 451 452 position_cluster_impl (plan, font, buffer, start, end, adjust_offsets_when_zeroing); 453 } 454 455 void 456 _hb_ot_shape_fallback_mark_position (const hb_ot_shape_plan_t *plan, 457 hb_font_t *font, 458 hb_buffer_t *buffer, 459 bool adjust_offsets_when_zeroing) 460 { 461 #ifdef HB_NO_OT_SHAPE_FALLBACK 462 return; 463 #endif 464 465 if (!buffer->message (font, "start fallback mark")) 466 return; 467 468 _hb_buffer_assert_gsubgpos_vars (buffer); 469 470 unsigned int start = 0; 471 unsigned int count = buffer->len; 472 hb_glyph_info_t *info = buffer->info; 473 for (unsigned int i = 1; i < count; i++) 474 if (likely (!_hb_glyph_info_is_unicode_mark (&info[i]) && 475 !_hb_glyph_info_is_hidden (&info[i]) && 476 !_hb_glyph_info_is_default_ignorable (&info[i]))) { 477 position_cluster (plan, font, buffer, start, i, adjust_offsets_when_zeroing); 478 start = i; 479 } 480 position_cluster (plan, font, buffer, start, count, adjust_offsets_when_zeroing); 481 482 (void) buffer->message (font, "end fallback mark"); 483 } 484 485 486 #ifndef HB_DISABLE_DEPRECATED 487 struct hb_ot_shape_fallback_kern_driver_t 488 { 489 hb_ot_shape_fallback_kern_driver_t (hb_font_t *font_, 490 hb_buffer_t *buffer) : 491 font (font_), direction (buffer->props.direction) {} 492 493 hb_position_t get_kerning (hb_codepoint_t first, hb_codepoint_t second) const 494 { 495 hb_position_t kern = 0; 496 font->get_glyph_kerning_for_direction (first, second, 497 direction, 498 &kern, &kern); 499 return kern; 500 } 501 502 hb_font_t *font; 503 hb_direction_t direction; 504 }; 505 #endif 506 507 /* Performs font-assisted kerning. */ 508 void 509 _hb_ot_shape_fallback_kern (const hb_ot_shape_plan_t *plan, 510 hb_font_t *font, 511 hb_buffer_t *buffer) 512 { 513 #ifdef HB_NO_OT_SHAPE_FALLBACK 514 return; 515 #endif 516 517 #ifndef HB_DISABLE_DEPRECATED 518 if (HB_DIRECTION_IS_HORIZONTAL (buffer->props.direction) ? 519 !font->has_glyph_h_kerning_func () : 520 !font->has_glyph_v_kerning_func ()) 521 return; 522 523 if (!buffer->message (font, "start fallback kern")) 524 return; 525 526 bool reverse = HB_DIRECTION_IS_BACKWARD (buffer->props.direction); 527 528 if (reverse) 529 buffer->reverse (); 530 531 hb_ot_shape_fallback_kern_driver_t driver (font, buffer); 532 OT::hb_kern_machine_t<hb_ot_shape_fallback_kern_driver_t> machine (driver); 533 machine.kern (font, buffer, plan->kern_mask, false); 534 535 if (reverse) 536 buffer->reverse (); 537 538 (void) buffer->message (font, "end fallback kern"); 539 #endif 540 } 541 542 543 /* Adjusts width of various spaces. */ 544 void 545 _hb_ot_shape_fallback_spaces (const hb_ot_shape_plan_t *plan HB_UNUSED, 546 hb_font_t *font, 547 hb_buffer_t *buffer) 548 { 549 hb_glyph_info_t *info = buffer->info; 550 hb_glyph_position_t *pos = buffer->pos; 551 bool horizontal = HB_DIRECTION_IS_HORIZONTAL (buffer->props.direction); 552 unsigned int count = buffer->len; 553 for (unsigned int i = 0; i < count; i++) 554 if (_hb_glyph_info_is_unicode_space (&info[i]) && !_hb_glyph_info_ligated (&info[i])) 555 { 556 /* If font had no ASCII space and we used the invisible glyph, give it a 1/4 EM default advance. */ 557 if (buffer->invisible && info[i].codepoint == buffer->invisible) 558 { 559 if (horizontal) 560 pos[i].x_advance = +font->x_scale / 4; 561 else 562 pos[i].y_advance = -font->y_scale / 4; 563 } 564 565 hb_unicode_funcs_t::space_t space_type = _hb_glyph_info_get_unicode_space_fallback_type (&info[i]); 566 hb_codepoint_t glyph; 567 typedef hb_unicode_funcs_t t; 568 switch (space_type) 569 { 570 case t::NOT_SPACE: /* Shouldn't happen. */ 571 case t::SPACE: 572 break; 573 574 case t::SPACE_EM: 575 case t::SPACE_EM_2: 576 case t::SPACE_EM_3: 577 case t::SPACE_EM_4: 578 case t::SPACE_EM_5: 579 case t::SPACE_EM_6: 580 case t::SPACE_EM_16: 581 if (horizontal) 582 pos[i].x_advance = +(font->x_scale + ((int) space_type)/2) / (int) space_type; 583 else 584 pos[i].y_advance = -(font->y_scale + ((int) space_type)/2) / (int) space_type; 585 break; 586 587 case t::SPACE_4_EM_18: 588 if (horizontal) 589 pos[i].x_advance = (int64_t) +font->x_scale * 4 / 18; 590 else 591 pos[i].y_advance = (int64_t) -font->y_scale * 4 / 18; 592 break; 593 594 case t::SPACE_FIGURE: 595 for (char u = '0'; u <= '9'; u++) 596 if (font->get_nominal_glyph (u, &glyph)) 597 { 598 if (horizontal) 599 pos[i].x_advance = font->get_glyph_h_advance (glyph); 600 else 601 pos[i].y_advance = font->get_glyph_v_advance (glyph); 602 break; 603 } 604 break; 605 606 case t::SPACE_PUNCTUATION: 607 if (font->get_nominal_glyph ('.', &glyph) || 608 font->get_nominal_glyph (',', &glyph)) 609 { 610 if (horizontal) 611 pos[i].x_advance = font->get_glyph_h_advance (glyph); 612 else 613 pos[i].y_advance = font->get_glyph_v_advance (glyph); 614 } 615 break; 616 617 case t::SPACE_NARROW: 618 /* Half-space? 619 * Unicode doc https://unicode.org/charts/PDF/U2000.pdf says ~1/4 or 1/5 of EM. 620 * However, in my testing, many fonts have their regular space being about that 621 * size. To me, a percentage of the space width makes more sense. Half is as 622 * good as any. */ 623 if (horizontal) 624 pos[i].x_advance /= 2; 625 else 626 pos[i].y_advance /= 2; 627 break; 628 } 629 } 630 } 631 632 633 #endif