Coverage Report

Created: 2026-12-01 07:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/harfbuzz/src/hb-ot-layout-jstf-table.hh
Line
Count
Source
1
/*
2
 * Copyright © 2013  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
#ifndef HB_OT_LAYOUT_JSTF_TABLE_HH
28
#define HB_OT_LAYOUT_JSTF_TABLE_HH
29
30
#include "hb-open-type.hh"
31
#include "hb-ot-layout-gpos-table.hh"
32
33
34
namespace OT {
35
36
37
/*
38
 * JstfModList -- Justification Modification List Tables
39
 */
40
41
typedef IndexArray JstfModList;
42
43
44
/*
45
 * JstfMax -- Justification Maximum Table
46
 */
47
48
typedef List16OfOffset16To<PosLookup> JstfMax;
49
50
51
/*
52
 * JstfPriority -- Justification Priority Table
53
 */
54
55
struct JstfPriority
56
{
57
  bool sanitize (hb_sanitize_context_t *c) const
58
0
  {
59
0
    TRACE_SANITIZE (this);
60
0
    return_trace (c->check_struct (this) &&
61
0
      shrinkageEnableGSUB.sanitize (c, this) &&
62
0
      shrinkageDisableGSUB.sanitize (c, this) &&
63
0
      shrinkageEnableGPOS.sanitize (c, this) &&
64
0
      shrinkageDisableGPOS.sanitize (c, this) &&
65
0
      shrinkageJstfMax.sanitize (c, this) &&
66
0
      extensionEnableGSUB.sanitize (c, this) &&
67
0
      extensionDisableGSUB.sanitize (c, this) &&
68
0
      extensionEnableGPOS.sanitize (c, this) &&
69
0
      extensionDisableGPOS.sanitize (c, this) &&
70
0
      extensionJstfMax.sanitize (c, this));
71
0
  }
72
73
  protected:
74
  Offset16To<JstfModList>
75
    shrinkageEnableGSUB;  /* Offset to Shrinkage Enable GSUB
76
           * JstfModList table--from beginning of
77
           * JstfPriority table--may be NULL */
78
  Offset16To<JstfModList>
79
    shrinkageDisableGSUB; /* Offset to Shrinkage Disable GSUB
80
           * JstfModList table--from beginning of
81
           * JstfPriority table--may be NULL */
82
  Offset16To<JstfModList>
83
    shrinkageEnableGPOS;  /* Offset to Shrinkage Enable GPOS
84
           * JstfModList table--from beginning of
85
           * JstfPriority table--may be NULL */
86
  Offset16To<JstfModList>
87
    shrinkageDisableGPOS; /* Offset to Shrinkage Disable GPOS
88
           * JstfModList table--from beginning of
89
           * JstfPriority table--may be NULL */
90
  Offset16To<JstfMax>
91
    shrinkageJstfMax; /* Offset to Shrinkage JstfMax table--
92
           * from beginning of JstfPriority table
93
           * --may be NULL */
94
  Offset16To<JstfModList>
95
    extensionEnableGSUB;  /* Offset to Extension Enable GSUB
96
           * JstfModList table--from beginning of
97
           * JstfPriority table--may be NULL */
98
  Offset16To<JstfModList>
99
    extensionDisableGSUB; /* Offset to Extension Disable GSUB
100
           * JstfModList table--from beginning of
101
           * JstfPriority table--may be NULL */
102
  Offset16To<JstfModList>
103
    extensionEnableGPOS;  /* Offset to Extension Enable GPOS
104
           * JstfModList table--from beginning of
105
           * JstfPriority table--may be NULL */
106
  Offset16To<JstfModList>
107
    extensionDisableGPOS; /* Offset to Extension Disable GPOS
108
           * JstfModList table--from beginning of
109
           * JstfPriority table--may be NULL */
110
  Offset16To<JstfMax>
111
    extensionJstfMax; /* Offset to Extension JstfMax table--
112
           * from beginning of JstfPriority table
113
           * --may be NULL */
114
115
  public:
116
  DEFINE_SIZE_STATIC (20);
117
};
118
119
120
/*
121
 * JstfLangSys -- Justification Language System Table
122
 */
123
124
struct JstfLangSys : List16OfOffset16To<JstfPriority>
125
{
126
  bool sanitize (hb_sanitize_context_t *c,
127
     const Record_sanitize_closure_t * = nullptr) const
128
0
  {
129
0
    TRACE_SANITIZE (this);
130
0
    return_trace (List16OfOffset16To<JstfPriority>::sanitize (c));
131
0
  }
132
};
133
134
135
/*
136
 * ExtenderGlyphs -- Extender Glyph Table
137
 */
138
139
template <typename Types>
140
using ExtenderGlyphs = SortedArray16Of<typename Types::HBGlyphID>;
141
142
143
/*
144
 * JstfScript -- The Justification Table
145
 */
146
147
template <typename Types>
148
struct JstfScript
149
{
150
  unsigned int get_lang_sys_count () const
151
0
  { return langSys.len; }
Unexecuted instantiation: OT::JstfScript<OT::Layout::MediumTypes>::get_lang_sys_count() const
Unexecuted instantiation: OT::JstfScript<OT::Layout::SmallTypes>::get_lang_sys_count() const
152
  const Tag& get_lang_sys_tag (unsigned int i) const
153
  { return langSys.get_tag (i); }
154
  unsigned int get_lang_sys_tags (unsigned int start_offset,
155
          unsigned int *lang_sys_count /* IN/OUT */,
156
          hb_tag_t     *lang_sys_tags /* OUT */) const
157
  { return langSys.get_tags (start_offset, lang_sys_count, lang_sys_tags); }
158
  const JstfLangSys& get_lang_sys (unsigned int i) const
159
  {
160
    if (i == Index::NOT_FOUND_INDEX) return get_default_lang_sys ();
161
    return this+langSys[i].offset;
162
  }
163
  bool find_lang_sys_index (hb_tag_t tag, unsigned int *index) const
164
  { return langSys.find_index (tag, index); }
165
166
  bool has_default_lang_sys () const               { return defaultLangSys != 0; }
167
  const JstfLangSys& get_default_lang_sys () const { return this+defaultLangSys; }
168
169
  unsigned get_extender_glyphs (unsigned        start_offset,
170
        unsigned       *glyphs_count /* IN/OUT.  May be NULL */,
171
        hb_codepoint_t *glyphs       /* OUT.     May be NULL */) const
172
0
  {
173
0
    const ExtenderGlyphs<Types> &extenders = this+extenderGlyphs;
174
0
    if (glyphs_count && glyphs)
175
0
    {
176
0
      + extenders.as_array ().sub_array (start_offset, glyphs_count)
177
0
      | hb_sink (hb_array (glyphs, *glyphs_count))
178
0
      ;
179
0
    }
180
0
    return extenders.len;
181
0
  }
Unexecuted instantiation: OT::JstfScript<OT::Layout::MediumTypes>::get_extender_glyphs(unsigned int, unsigned int*, unsigned int*) const
Unexecuted instantiation: OT::JstfScript<OT::Layout::SmallTypes>::get_extender_glyphs(unsigned int, unsigned int*, unsigned int*) const
182
183
  bool sanitize (hb_sanitize_context_t *c,
184
     const Record_sanitize_closure_t * = nullptr) const
185
0
  {
186
0
    TRACE_SANITIZE (this);
187
0
    return_trace (extenderGlyphs.sanitize (c, this) &&
188
0
      defaultLangSys.sanitize (c, this) &&
189
0
      langSys.sanitize (c, this));
190
0
  }
Unexecuted instantiation: OT::JstfScript<OT::Layout::SmallTypes>::sanitize(hb_sanitize_context_t*, OT::Record_sanitize_closure_t const*) const
Unexecuted instantiation: OT::JstfScript<OT::Layout::MediumTypes>::sanitize(hb_sanitize_context_t*, OT::Record_sanitize_closure_t const*) const
191
192
  protected:
193
  typename Types::template LOffsetTo<ExtenderGlyphs<Types>>
194
    extenderGlyphs; /* Offset to ExtenderGlyph table--from beginning
195
         * of JstfScript table-may be NULL */
196
  typename Types::template LOffsetTo<JstfLangSys>
197
    defaultLangSys; /* Offset to DefaultJstfLangSys table--from
198
         * beginning of JstfScript table--may be Null */
199
  RecordArrayOf<JstfLangSys>
200
    langSys;  /* Array of JstfLangSysRecords--listed
201
         * alphabetically by LangSysTag */
202
  public:
203
  DEFINE_SIZE_ARRAY (2 * Types::LOffset::static_size + 2, langSys);
204
};
205
206
template <typename Types>
207
struct JstfScriptRecord
208
{
209
0
  int cmp (hb_tag_t a) const { return tag.cmp (a); }
Unexecuted instantiation: OT::JstfScriptRecord<OT::Layout::MediumTypes>::cmp(unsigned int) const
Unexecuted instantiation: OT::JstfScriptRecord<OT::Layout::SmallTypes>::cmp(unsigned int) const
210
211
  bool sanitize (hb_sanitize_context_t *c, const void *base) const
212
0
  {
213
0
    TRACE_SANITIZE (this);
214
0
    const Record_sanitize_closure_t closure = {tag, base};
215
0
    return_trace (c->check_struct (this) &&
216
0
      offset.sanitize (c, base, &closure));
217
0
  }
Unexecuted instantiation: OT::JstfScriptRecord<OT::Layout::SmallTypes>::sanitize(hb_sanitize_context_t*, void const*) const
Unexecuted instantiation: OT::JstfScriptRecord<OT::Layout::MediumTypes>::sanitize(hb_sanitize_context_t*, void const*) const
218
219
  Tag   tag;    /* 4-byte JstfScript identification tag */
220
  typename Types::template LOffsetTo<JstfScript<Types>>
221
    offset;   /* Offset from beginning of JSTF header */
222
  public:
223
  DEFINE_SIZE_STATIC (4 + Types::LOffset::static_size);
224
};
225
226
template <typename Types>
227
struct JstfScriptList : SortedArray16Of<JstfScriptRecord<Types>>
228
{
229
  const Tag& get_tag (unsigned int i) const
230
  { return (*this)[i].tag; }
231
  unsigned int get_tags (unsigned int start_offset,
232
       unsigned int *script_count /* IN/OUT */,
233
       hb_tag_t     *script_tags /* OUT */) const
234
  {
235
    if (script_count)
236
    {
237
      + this->as_array ().sub_array (start_offset, script_count)
238
      | hb_map (&JstfScriptRecord<Types>::tag)
239
      | hb_sink (hb_array (script_tags, *script_count))
240
      ;
241
    }
242
    return this->len;
243
  }
244
  const JstfScript<Types> &find_script (const void *base, hb_tag_t tag) const
245
0
  { return base+this->bsearch (tag).offset; }
Unexecuted instantiation: OT::JstfScriptList<OT::Layout::MediumTypes>::find_script(void const*, unsigned int) const
Unexecuted instantiation: OT::JstfScriptList<OT::Layout::SmallTypes>::find_script(void const*, unsigned int) const
246
};
247
248
249
/*
250
 * JSTF -- Justification
251
 * https://docs.microsoft.com/en-us/typography/opentype/spec/jstf
252
 */
253
254
struct JSTF
255
{
256
  static constexpr hb_tag_t tableTag = HB_OT_TAG_JSTF;
257
258
  unsigned int get_script_count () const
259
0
  {
260
0
#ifndef HB_NO_BEYOND_64K
261
0
    if (has_script_list2 ()) return get_script_list2 ().len;
262
0
#endif
263
0
    return scriptList.len;
264
0
  }
265
  unsigned get_lang_sys_count (hb_tag_t script) const
266
0
  {
267
0
#ifndef HB_NO_BEYOND_64K
268
0
    if (has_script_list2 ())
269
0
      return get_script_list2 ().find_script (this, script).get_lang_sys_count ();
270
0
#endif
271
0
    return scriptList.find_script (this, script).get_lang_sys_count ();
272
0
  }
273
274
  unsigned get_extender_glyphs (hb_tag_t        script,
275
        unsigned        start_offset,
276
        unsigned       *glyphs_count /* IN/OUT.  May be NULL */,
277
        hb_codepoint_t *glyphs       /* OUT.     May be NULL */) const
278
0
  {
279
0
#ifndef HB_NO_BEYOND_64K
280
0
    if (has_script_list2 ())
281
0
      return get_script_list2 ().find_script (this, script).get_extender_glyphs (start_offset, glyphs_count, glyphs);
282
0
#endif
283
0
    return scriptList.find_script (this, script).get_extender_glyphs (start_offset, glyphs_count, glyphs);
284
0
  }
285
286
  bool sanitize (hb_sanitize_context_t *c) const
287
0
  {
288
0
    TRACE_SANITIZE (this);
289
0
    if (unlikely (!version.sanitize (c) ||
290
0
      !hb_barrier () ||
291
0
      version.major != 1 ||
292
0
      !scriptList.sanitize (c, this)))
293
0
      return_trace (false);
294
0
#ifndef HB_NO_BEYOND_64K
295
0
    if (unlikely (version.minor >= 1 && !get_script_list2 ().sanitize (c, this)))
296
0
      return_trace (false);
297
0
#endif
298
0
    return_trace (true);
299
0
  }
300
301
  private:
302
#ifndef HB_NO_BEYOND_64K
303
  bool has_script_list2 () const
304
0
  { return version.minor >= 1 && get_script_list2 ().len; }
305
  const JstfScriptList<Layout::MediumTypes>& get_script_list2 () const
306
0
  { return StructAfter<JstfScriptList<Layout::MediumTypes>> (scriptList); }
307
#endif
308
309
  protected:
310
  FixedVersion<>version;  /* Version of the JSTF table--initially set
311
         * to 0x00010000u */
312
  JstfScriptList<Layout::SmallTypes>
313
    scriptList; /* Array of JstfScripts--listed
314
         * alphabetically by ScriptTag */
315
#ifndef HB_NO_BEYOND_64K
316
/*JstfScriptList<Layout::MediumTypes>
317
    scriptList2;*//* Array of JstfScript2s--listed
318
         * alphabetically by ScriptTag.
319
         * Present only if minorVersion is 1 or greater. */
320
#endif
321
  public:
322
  DEFINE_SIZE_ARRAY (6, scriptList);
323
};
324
325
326
} /* namespace OT */
327
328
329
#endif /* HB_OT_LAYOUT_JSTF_TABLE_HH */