Coverage Report

Created: 2024-08-27 12:11

/src/harfbuzz/src/hb-ot-shape-fallback.cc
Line
Count
Source (jump to first uncovered line)
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
0
{
38
0
  if (klass >= 200)
39
0
    return klass;
40
41
  /* Thai / Lao need some per-character work. */
42
0
  if ((u & ~0xFF) == 0x0E00u)
43
0
  {
44
0
    if (unlikely (klass == 0))
45
0
    {
46
0
      switch (u)
47
0
      {
48
0
  case 0x0E31u:
49
0
  case 0x0E34u:
50
0
  case 0x0E35u:
51
0
  case 0x0E36u:
52
0
  case 0x0E37u:
53
0
  case 0x0E47u:
54
0
  case 0x0E4Cu:
55
0
  case 0x0E4Du:
56
0
  case 0x0E4Eu:
57
0
    klass = HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT;
58
0
    break;
59
60
0
  case 0x0EB1u:
61
0
  case 0x0EB4u:
62
0
  case 0x0EB5u:
63
0
  case 0x0EB6u:
64
0
  case 0x0EB7u:
65
0
  case 0x0EBBu:
66
0
  case 0x0ECCu:
67
0
  case 0x0ECDu:
68
0
    klass = HB_UNICODE_COMBINING_CLASS_ABOVE;
69
0
    break;
70
71
0
  case 0x0EBCu:
72
0
    klass = HB_UNICODE_COMBINING_CLASS_BELOW;
73
0
    break;
74
0
      }
75
0
    } else {
76
      /* Thai virama is below-right */
77
0
      if (u == 0x0E3Au)
78
0
  klass = HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT;
79
0
    }
80
0
  }
81
82
0
  switch (klass)
83
0
  {
84
85
    /* Hebrew */
86
87
0
    case HB_MODIFIED_COMBINING_CLASS_CCC10: /* sheva */
88
0
    case HB_MODIFIED_COMBINING_CLASS_CCC11: /* hataf segol */
89
0
    case HB_MODIFIED_COMBINING_CLASS_CCC12: /* hataf patah */
90
0
    case HB_MODIFIED_COMBINING_CLASS_CCC13: /* hataf qamats */
91
0
    case HB_MODIFIED_COMBINING_CLASS_CCC14: /* hiriq */
92
0
    case HB_MODIFIED_COMBINING_CLASS_CCC15: /* tsere */
93
0
    case HB_MODIFIED_COMBINING_CLASS_CCC16: /* segol */
94
0
    case HB_MODIFIED_COMBINING_CLASS_CCC17: /* patah */
95
0
    case HB_MODIFIED_COMBINING_CLASS_CCC18: /* qamats & qamats qatan */
96
0
    case HB_MODIFIED_COMBINING_CLASS_CCC20: /* qubuts */
97
0
    case HB_MODIFIED_COMBINING_CLASS_CCC22: /* meteg */
98
0
      return HB_UNICODE_COMBINING_CLASS_BELOW;
99
100
0
    case HB_MODIFIED_COMBINING_CLASS_CCC23: /* rafe */
101
0
      return HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE;
102
103
0
    case HB_MODIFIED_COMBINING_CLASS_CCC24: /* shin dot */
104
0
      return HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT;
105
106
0
    case HB_MODIFIED_COMBINING_CLASS_CCC25: /* sin dot */
107
0
    case HB_MODIFIED_COMBINING_CLASS_CCC19: /* holam & holam haser for vav */
108
0
      return HB_UNICODE_COMBINING_CLASS_ABOVE_LEFT;
109
110
0
    case HB_MODIFIED_COMBINING_CLASS_CCC26: /* point varika */
111
0
      return HB_UNICODE_COMBINING_CLASS_ABOVE;
112
113
0
    case HB_MODIFIED_COMBINING_CLASS_CCC21: /* dagesh */
114
0
      break;
115
116
117
    /* Arabic and Syriac */
118
119
0
    case HB_MODIFIED_COMBINING_CLASS_CCC27: /* fathatan */
120
0
    case HB_MODIFIED_COMBINING_CLASS_CCC28: /* dammatan */
121
0
    case HB_MODIFIED_COMBINING_CLASS_CCC30: /* fatha */
122
0
    case HB_MODIFIED_COMBINING_CLASS_CCC31: /* damma */
123
0
    case HB_MODIFIED_COMBINING_CLASS_CCC33: /* shadda */
124
0
    case HB_MODIFIED_COMBINING_CLASS_CCC34: /* sukun */
125
0
    case HB_MODIFIED_COMBINING_CLASS_CCC35: /* superscript alef */
126
0
    case HB_MODIFIED_COMBINING_CLASS_CCC36: /* superscript alaph */
127
0
      return HB_UNICODE_COMBINING_CLASS_ABOVE;
128
129
0
    case HB_MODIFIED_COMBINING_CLASS_CCC29: /* kasratan */
130
0
    case HB_MODIFIED_COMBINING_CLASS_CCC32: /* kasra */
131
0
      return HB_UNICODE_COMBINING_CLASS_BELOW;
132
133
134
    /* Thai */
135
136
0
    case HB_MODIFIED_COMBINING_CLASS_CCC103: /* sara u / sara uu */
137
0
      return HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT;
138
139
0
    case HB_MODIFIED_COMBINING_CLASS_CCC107: /* mai */
140
0
      return HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT;
141
142
143
    /* Lao */
144
145
0
    case HB_MODIFIED_COMBINING_CLASS_CCC118: /* sign u / sign uu */
146
0
      return HB_UNICODE_COMBINING_CLASS_BELOW;
147
148
0
    case HB_MODIFIED_COMBINING_CLASS_CCC122: /* mai */
149
0
      return HB_UNICODE_COMBINING_CLASS_ABOVE;
150
151
152
    /* Tibetan */
153
154
0
    case HB_MODIFIED_COMBINING_CLASS_CCC129: /* sign aa */
155
0
      return HB_UNICODE_COMBINING_CLASS_BELOW;
156
157
0
    case HB_MODIFIED_COMBINING_CLASS_CCC130: /* sign i*/
158
0
      return HB_UNICODE_COMBINING_CLASS_ABOVE;
159
160
0
    case HB_MODIFIED_COMBINING_CLASS_CCC132: /* sign u */
161
0
      return HB_UNICODE_COMBINING_CLASS_BELOW;
162
163
0
  }
164
165
0
  return klass;
166
0
}
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
0
{
173
#ifdef HB_NO_OT_SHAPE_FALLBACK
174
  return;
175
#endif
176
177
0
  unsigned int count = buffer->len;
178
0
  hb_glyph_info_t *info = buffer->info;
179
0
  for (unsigned int i = 0; i < count; i++)
180
0
    if (_hb_glyph_info_get_general_category (&info[i]) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK) {
181
0
      unsigned int combining_class = _hb_glyph_info_get_modified_combining_class (&info[i]);
182
0
      combining_class = recategorize_combining_class (info[i].codepoint, combining_class);
183
0
      _hb_glyph_info_set_modified_combining_class (&info[i], combining_class);
184
0
    }
185
0
}
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
0
{
194
0
  hb_glyph_info_t *info = buffer->info;
195
0
  for (unsigned int i = start; i < end; i++)
196
0
    if (_hb_glyph_info_get_general_category (&info[i]) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK)
197
0
    {
198
0
      if (adjust_offsets_when_zeroing)
199
0
      {
200
0
  buffer->pos[i].x_offset -= buffer->pos[i].x_advance;
201
0
  buffer->pos[i].y_offset -= buffer->pos[i].y_advance;
202
0
      }
203
0
      buffer->pos[i].x_advance = 0;
204
0
      buffer->pos[i].y_advance = 0;
205
0
    }
206
0
}
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
0
{
216
0
  hb_glyph_extents_t mark_extents;
217
0
  if (!font->get_glyph_extents (buffer->info[i].codepoint, &mark_extents))
218
0
    return;
219
220
0
  hb_position_t y_gap = font->y_scale / 16;
221
222
0
  hb_glyph_position_t &pos = buffer->pos[i];
223
0
  pos.x_offset = pos.y_offset = 0;
224
225
226
  /* We don't position LEFT and RIGHT marks. */
227
228
  /* X positioning */
229
0
  switch (combining_class)
230
0
  {
231
0
    case HB_UNICODE_COMBINING_CLASS_DOUBLE_BELOW:
232
0
    case HB_UNICODE_COMBINING_CLASS_DOUBLE_ABOVE:
233
0
      if (buffer->props.direction == HB_DIRECTION_LTR) {
234
0
  pos.x_offset += base_extents.x_bearing + base_extents.width - mark_extents.width / 2 - mark_extents.x_bearing;
235
0
  break;
236
0
      } else if (buffer->props.direction == HB_DIRECTION_RTL) {
237
0
  pos.x_offset += base_extents.x_bearing - mark_extents.width / 2 - mark_extents.x_bearing;
238
0
  break;
239
0
      }
240
0
      HB_FALLTHROUGH;
241
242
0
    default:
243
0
    case HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW:
244
0
    case HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE:
245
0
    case HB_UNICODE_COMBINING_CLASS_BELOW:
246
0
    case HB_UNICODE_COMBINING_CLASS_ABOVE:
247
      /* Center align. */
248
0
      pos.x_offset += base_extents.x_bearing + (base_extents.width - mark_extents.width) / 2 - mark_extents.x_bearing;
249
0
      break;
250
251
0
    case HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW_LEFT:
252
0
    case HB_UNICODE_COMBINING_CLASS_BELOW_LEFT:
253
0
    case HB_UNICODE_COMBINING_CLASS_ABOVE_LEFT:
254
      /* Left align. */
255
0
      pos.x_offset += base_extents.x_bearing - mark_extents.x_bearing;
256
0
      break;
257
258
0
    case HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE_RIGHT:
259
0
    case HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT:
260
0
    case HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT:
261
      /* Right align. */
262
0
      pos.x_offset += base_extents.x_bearing + base_extents.width - mark_extents.width - mark_extents.x_bearing;
263
0
      break;
264
0
  }
265
266
  /* Y positioning */
267
0
  switch (combining_class)
268
0
  {
269
0
    case HB_UNICODE_COMBINING_CLASS_DOUBLE_BELOW:
270
0
    case HB_UNICODE_COMBINING_CLASS_BELOW_LEFT:
271
0
    case HB_UNICODE_COMBINING_CLASS_BELOW:
272
0
    case HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT:
273
      /* Add gap, fall-through. */
274
0
      base_extents.height -= y_gap;
275
0
      HB_FALLTHROUGH;
276
277
0
    case HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW_LEFT:
278
0
    case HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW:
279
0
      pos.y_offset = base_extents.y_bearing + base_extents.height - mark_extents.y_bearing;
280
      /* Never shift up "below" marks. */
281
0
      if ((y_gap > 0) == (pos.y_offset > 0))
282
0
      {
283
0
  base_extents.height -= pos.y_offset;
284
0
  pos.y_offset = 0;
285
0
      }
286
0
      base_extents.height += mark_extents.height;
287
0
      break;
288
289
0
    case HB_UNICODE_COMBINING_CLASS_DOUBLE_ABOVE:
290
0
    case HB_UNICODE_COMBINING_CLASS_ABOVE_LEFT:
291
0
    case HB_UNICODE_COMBINING_CLASS_ABOVE:
292
0
    case HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT:
293
      /* Add gap, fall-through. */
294
0
      base_extents.y_bearing += y_gap;
295
0
      base_extents.height -= y_gap;
296
0
      HB_FALLTHROUGH;
297
298
0
    case HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE:
299
0
    case HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE_RIGHT:
300
0
      pos.y_offset = base_extents.y_bearing - (mark_extents.y_bearing + mark_extents.height);
301
      /* Don't shift down "above" marks too much. */
302
0
      if ((y_gap > 0) != (pos.y_offset > 0))
303
0
      {
304
0
  int correction = -pos.y_offset / 2;
305
0
  base_extents.y_bearing += correction;
306
0
  base_extents.height -= correction;
307
0
  pos.y_offset += correction;
308
0
      }
309
0
      base_extents.y_bearing -= mark_extents.height;
310
0
      base_extents.height += mark_extents.height;
311
0
      break;
312
0
  }
313
0
}
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
0
{
323
0
  hb_direction_t horiz_dir = HB_DIRECTION_INVALID;
324
325
0
  buffer->unsafe_to_break (base, end);
326
327
0
  hb_glyph_extents_t base_extents;
328
0
  if (!font->get_glyph_extents (buffer->info[base].codepoint,
329
0
        &base_extents))
330
0
  {
331
    /* If extents don't work, zero marks and go home. */
332
0
    zero_mark_advances (buffer, base + 1, end, adjust_offsets_when_zeroing);
333
0
    return;
334
0
  }
335
0
  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
0
  base_extents.x_bearing = 0;
340
0
  base_extents.width = font->get_glyph_h_advance (buffer->info[base].codepoint);
341
342
0
  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
0
  int num_lig_components = _hb_glyph_info_get_lig_num_comps (&buffer->info[base]);
346
347
0
  hb_position_t x_offset = 0, y_offset = 0;
348
0
  if (HB_DIRECTION_IS_FORWARD (buffer->props.direction)) {
349
0
    x_offset -= buffer->pos[base].x_advance;
350
0
    y_offset -= buffer->pos[base].y_advance;
351
0
  }
352
353
0
  hb_glyph_extents_t component_extents = base_extents;
354
0
  int last_lig_component = -1;
355
0
  unsigned int last_combining_class = 255;
356
0
  hb_glyph_extents_t cluster_extents = base_extents; /* Initialization is just to shut gcc up. */
357
0
  hb_glyph_info_t *info = buffer->info;
358
0
  for (unsigned int i = base + 1; i < end; i++)
359
0
    if (_hb_glyph_info_get_modified_combining_class (&info[i]))
360
0
    {
361
0
      if (num_lig_components > 1) {
362
0
  unsigned int this_lig_id = _hb_glyph_info_get_lig_id (&info[i]);
363
0
  int this_lig_component = _hb_glyph_info_get_lig_comp (&info[i]) - 1;
364
  /* Conditions for attaching to the last component. */
365
0
  if (!lig_id || lig_id != this_lig_id || this_lig_component >= num_lig_components)
366
0
    this_lig_component = num_lig_components - 1;
367
0
  if (last_lig_component != this_lig_component)
368
0
  {
369
0
    last_lig_component = this_lig_component;
370
0
    last_combining_class = 255;
371
0
    component_extents = base_extents;
372
0
    if (unlikely (horiz_dir == HB_DIRECTION_INVALID)) {
373
0
      if (HB_DIRECTION_IS_HORIZONTAL (plan->props.direction))
374
0
        horiz_dir = plan->props.direction;
375
0
      else
376
0
        horiz_dir = hb_script_get_horizontal_direction (plan->props.script);
377
0
    }
378
0
    if (horiz_dir == HB_DIRECTION_LTR)
379
0
      component_extents.x_bearing += (this_lig_component * component_extents.width) / num_lig_components;
380
0
    else
381
0
      component_extents.x_bearing += ((num_lig_components - 1 - this_lig_component) * component_extents.width) / num_lig_components;
382
0
    component_extents.width /= num_lig_components;
383
0
  }
384
0
      }
385
386
0
      unsigned int this_combining_class = _hb_glyph_info_get_modified_combining_class (&info[i]);
387
0
      if (last_combining_class != this_combining_class)
388
0
      {
389
0
  last_combining_class = this_combining_class;
390
0
  cluster_extents = component_extents;
391
0
      }
392
393
0
      position_mark (plan, font, buffer, cluster_extents, i, this_combining_class);
394
395
0
      buffer->pos[i].x_advance = 0;
396
0
      buffer->pos[i].y_advance = 0;
397
0
      buffer->pos[i].x_offset += x_offset;
398
0
      buffer->pos[i].y_offset += y_offset;
399
400
0
    } else {
401
0
      if (HB_DIRECTION_IS_FORWARD (buffer->props.direction)) {
402
0
  x_offset -= buffer->pos[i].x_advance;
403
0
  y_offset -= buffer->pos[i].y_advance;
404
0
      } else {
405
0
  x_offset += buffer->pos[i].x_advance;
406
0
  y_offset += buffer->pos[i].y_advance;
407
0
      }
408
0
    }
409
0
}
410
411
static inline void
412
position_cluster (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
0
{
419
0
  if (end - start < 2)
420
0
    return;
421
422
  /* Find the base glyph */
423
0
  hb_glyph_info_t *info = buffer->info;
424
0
  for (unsigned int i = start; i < end; i++)
425
0
    if (!_hb_glyph_info_is_unicode_mark (&info[i]))
426
0
    {
427
      /* Find mark glyphs */
428
0
      unsigned int j;
429
0
      for (j = i + 1; j < end; j++)
430
0
  if (!_hb_glyph_info_is_unicode_mark (&info[j]))
431
0
    break;
432
433
0
      position_around_base (plan, font, buffer, i, j, adjust_offsets_when_zeroing);
434
435
0
      i = j - 1;
436
0
    }
437
0
}
438
439
void
440
_hb_ot_shape_fallback_mark_position (const hb_ot_shape_plan_t *plan,
441
             hb_font_t *font,
442
             hb_buffer_t  *buffer,
443
             bool adjust_offsets_when_zeroing)
444
0
{
445
#ifdef HB_NO_OT_SHAPE_FALLBACK
446
  return;
447
#endif
448
449
0
  if (!buffer->message (font, "start fallback mark"))
450
0
    return;
451
452
0
  _hb_buffer_assert_gsubgpos_vars (buffer);
453
454
0
  unsigned int start = 0;
455
0
  unsigned int count = buffer->len;
456
0
  hb_glyph_info_t *info = buffer->info;
457
0
  for (unsigned int i = 1; i < count; i++)
458
0
    if (likely (!_hb_glyph_info_is_unicode_mark (&info[i]))) {
459
0
      position_cluster (plan, font, buffer, start, i, adjust_offsets_when_zeroing);
460
0
      start = i;
461
0
    }
462
0
  position_cluster (plan, font, buffer, start, count, adjust_offsets_when_zeroing);
463
464
0
  (void) buffer->message (font, "end fallback mark");
465
0
}
466
467
468
#ifndef HB_DISABLE_DEPRECATED
469
struct hb_ot_shape_fallback_kern_driver_t
470
{
471
  hb_ot_shape_fallback_kern_driver_t (hb_font_t   *font_,
472
              hb_buffer_t *buffer) :
473
0
    font (font_), direction (buffer->props.direction) {}
474
475
  hb_position_t get_kerning (hb_codepoint_t first, hb_codepoint_t second) const
476
0
  {
477
0
    hb_position_t kern = 0;
478
0
    font->get_glyph_kerning_for_direction (first, second,
479
0
             direction,
480
0
             &kern, &kern);
481
0
    return kern;
482
0
  }
483
484
  hb_font_t *font;
485
  hb_direction_t direction;
486
};
487
#endif
488
489
/* Performs font-assisted kerning. */
490
void
491
_hb_ot_shape_fallback_kern (const hb_ot_shape_plan_t *plan,
492
          hb_font_t *font,
493
          hb_buffer_t *buffer)
494
0
{
495
#ifdef HB_NO_OT_SHAPE_FALLBACK
496
  return;
497
#endif
498
499
0
#ifndef HB_DISABLE_DEPRECATED
500
0
  if (HB_DIRECTION_IS_HORIZONTAL (buffer->props.direction) ?
501
0
      !font->has_glyph_h_kerning_func () :
502
0
      !font->has_glyph_v_kerning_func ())
503
0
    return;
504
505
0
  if (!buffer->message (font, "start fallback kern"))
506
0
    return;
507
508
0
  bool reverse = HB_DIRECTION_IS_BACKWARD (buffer->props.direction);
509
510
0
  if (reverse)
511
0
    buffer->reverse ();
512
513
0
  hb_ot_shape_fallback_kern_driver_t driver (font, buffer);
514
0
  OT::hb_kern_machine_t<hb_ot_shape_fallback_kern_driver_t> machine (driver);
515
0
  machine.kern (font, buffer, plan->kern_mask, false);
516
517
0
  if (reverse)
518
0
    buffer->reverse ();
519
520
0
  (void) buffer->message (font, "end fallback kern");
521
0
#endif
522
0
}
523
524
525
/* Adjusts width of various spaces. */
526
void
527
_hb_ot_shape_fallback_spaces (const hb_ot_shape_plan_t *plan HB_UNUSED,
528
            hb_font_t *font,
529
            hb_buffer_t  *buffer)
530
0
{
531
0
  hb_glyph_info_t *info = buffer->info;
532
0
  hb_glyph_position_t *pos = buffer->pos;
533
0
  bool horizontal = HB_DIRECTION_IS_HORIZONTAL (buffer->props.direction);
534
0
  unsigned int count = buffer->len;
535
0
  for (unsigned int i = 0; i < count; i++)
536
0
    if (_hb_glyph_info_is_unicode_space (&info[i]) && !_hb_glyph_info_ligated (&info[i]))
537
0
    {
538
      /* If font had no ASCII space and we used the invisible glyph, give it a 1/4 EM default advance. */
539
0
      if (buffer->invisible && info[i].codepoint == buffer->invisible)
540
0
      {
541
0
        if (horizontal)
542
0
    pos[i].x_advance = +font->x_scale / 4;
543
0
        else
544
0
    pos[i].y_advance = -font->y_scale / 4;
545
0
      }
546
547
0
      hb_unicode_funcs_t::space_t space_type = _hb_glyph_info_get_unicode_space_fallback_type (&info[i]);
548
0
      hb_codepoint_t glyph;
549
0
      typedef hb_unicode_funcs_t t;
550
0
      switch (space_type)
551
0
      {
552
0
  case t::NOT_SPACE: /* Shouldn't happen. */
553
0
  case t::SPACE:
554
0
    break;
555
556
0
  case t::SPACE_EM:
557
0
  case t::SPACE_EM_2:
558
0
  case t::SPACE_EM_3:
559
0
  case t::SPACE_EM_4:
560
0
  case t::SPACE_EM_5:
561
0
  case t::SPACE_EM_6:
562
0
  case t::SPACE_EM_16:
563
0
    if (horizontal)
564
0
      pos[i].x_advance = +(font->x_scale + ((int) space_type)/2) / (int) space_type;
565
0
    else
566
0
      pos[i].y_advance = -(font->y_scale + ((int) space_type)/2) / (int) space_type;
567
0
    break;
568
569
0
  case t::SPACE_4_EM_18:
570
0
    if (horizontal)
571
0
      pos[i].x_advance = (int64_t) +font->x_scale * 4 / 18;
572
0
    else
573
0
      pos[i].y_advance = (int64_t) -font->y_scale * 4 / 18;
574
0
    break;
575
576
0
  case t::SPACE_FIGURE:
577
0
    for (char u = '0'; u <= '9'; u++)
578
0
      if (font->get_nominal_glyph (u, &glyph))
579
0
      {
580
0
        if (horizontal)
581
0
    pos[i].x_advance = font->get_glyph_h_advance (glyph);
582
0
        else
583
0
    pos[i].y_advance = font->get_glyph_v_advance (glyph);
584
0
        break;
585
0
      }
586
0
    break;
587
588
0
  case t::SPACE_PUNCTUATION:
589
0
    if (font->get_nominal_glyph ('.', &glyph) ||
590
0
        font->get_nominal_glyph (',', &glyph))
591
0
    {
592
0
      if (horizontal)
593
0
        pos[i].x_advance = font->get_glyph_h_advance (glyph);
594
0
      else
595
0
        pos[i].y_advance = font->get_glyph_v_advance (glyph);
596
0
    }
597
0
    break;
598
599
0
  case t::SPACE_NARROW:
600
    /* Half-space?
601
     * Unicode doc https://unicode.org/charts/PDF/U2000.pdf says ~1/4 or 1/5 of EM.
602
     * However, in my testing, many fonts have their regular space being about that
603
     * size.  To me, a percentage of the space width makes more sense.  Half is as
604
     * good as any. */
605
0
    if (horizontal)
606
0
      pos[i].x_advance /= 2;
607
0
    else
608
0
      pos[i].y_advance /= 2;
609
0
    break;
610
0
      }
611
0
    }
612
0
}
613
614
615
#endif