Coverage Report

Created: 2025-07-07 10:01

/work/workdir/UnpackedTarball/harfbuzz/src/hb-ot-shaper-syllabic.cc
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright © 2021  Behdad Esfahbod.
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
25
#include "hb.hh"
26
27
#ifndef HB_NO_OT_SHAPE
28
29
#include "hb-ot-shaper-syllabic.hh"
30
31
32
bool
33
hb_syllabic_insert_dotted_circles (hb_font_t *font,
34
           hb_buffer_t *buffer,
35
           unsigned int broken_syllable_type,
36
           unsigned int dottedcircle_category,
37
           int repha_category,
38
           int dottedcircle_position)
39
104k
{
40
104k
  if (unlikely (buffer->flags & HB_BUFFER_FLAG_DO_NOT_INSERT_DOTTED_CIRCLE))
41
0
    return false;
42
104k
  if (likely (!(buffer->scratch_flags & HB_BUFFER_SCRATCH_FLAG_HAS_BROKEN_SYLLABLE)))
43
59.2k
  {
44
59.2k
    if (buffer->messaging ())
45
0
      (void) buffer->message (font, "skipped inserting dotted-circles because there is no broken syllables");
46
59.2k
    return false;
47
59.2k
  }
48
49
44.7k
  if (buffer->messaging () &&
50
44.7k
      !buffer->message (font, "start inserting dotted-circles"))
51
0
    return false;
52
53
44.7k
  hb_codepoint_t dottedcircle_glyph;
54
44.7k
  if (!font->get_nominal_glyph (0x25CCu, &dottedcircle_glyph))
55
0
    return false;
56
57
44.7k
  hb_glyph_info_t dottedcircle = {0};
58
44.7k
  dottedcircle.codepoint = 0x25CCu;
59
44.7k
  dottedcircle.ot_shaper_var_u8_category() = dottedcircle_category;
60
44.7k
  if (dottedcircle_position != -1)
61
0
    dottedcircle.ot_shaper_var_u8_auxiliary() = dottedcircle_position;
62
44.7k
  dottedcircle.codepoint = dottedcircle_glyph;
63
64
44.7k
  buffer->clear_output ();
65
66
44.7k
  buffer->idx = 0;
67
44.7k
  unsigned int last_syllable = 0;
68
928k
  while (buffer->idx < buffer->len && buffer->successful)
69
883k
  {
70
883k
    unsigned int syllable = buffer->cur().syllable();
71
883k
    if (unlikely (last_syllable != syllable && (syllable & 0x0F) == broken_syllable_type))
72
44.7k
    {
73
44.7k
      last_syllable = syllable;
74
75
44.7k
      hb_glyph_info_t ginfo = dottedcircle;
76
44.7k
      ginfo.cluster = buffer->cur().cluster;
77
44.7k
      ginfo.mask = buffer->cur().mask;
78
44.7k
      ginfo.syllable() = buffer->cur().syllable();
79
80
      /* Insert dottedcircle after possible Repha. */
81
44.7k
      if (repha_category != -1)
82
0
      {
83
0
  while (buffer->idx < buffer->len && buffer->successful &&
84
0
         last_syllable == buffer->cur().syllable() &&
85
0
         buffer->cur().ot_shaper_var_u8_category() == (unsigned) repha_category)
86
0
    (void) buffer->next_glyph ();
87
0
      }
88
89
44.7k
      (void) buffer->output_info (ginfo);
90
44.7k
    }
91
838k
    else
92
838k
      (void) buffer->next_glyph ();
93
883k
  }
94
44.7k
  buffer->sync ();
95
96
44.7k
  if (buffer->messaging ())
97
0
    (void) buffer->message (font, "end inserting dotted-circles");
98
99
44.7k
  return true;
100
44.7k
}
101
102
HB_INTERNAL bool
103
hb_syllabic_clear_var (const hb_ot_shape_plan_t *plan,
104
           hb_font_t *font,
105
           hb_buffer_t *buffer)
106
104k
{
107
104k
  HB_BUFFER_DEALLOCATE_VAR (buffer, syllable);
108
104k
  return false;
109
104k
}
110
111
112
#endif