Coverage Report

Created: 2021-08-22 09:07

/src/skia/third_party/externals/harfbuzz/src/hb-ot-var-mvar-table.hh
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright © 2017  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_VAR_MVAR_TABLE_HH
28
#define HB_OT_VAR_MVAR_TABLE_HH
29
30
#include "hb-ot-layout-common.hh"
31
32
33
namespace OT {
34
35
36
struct VariationValueRecord
37
{
38
  bool sanitize (hb_sanitize_context_t *c) const
39
0
  {
40
0
    TRACE_SANITIZE (this);
41
0
    return_trace (c->check_struct (this));
42
0
  }
43
44
  public:
45
  Tag   valueTag; /* Four-byte tag identifying a font-wide measure. */
46
  HBUINT32    varIdx;   /* Outer/inner index into VariationStore item. */
47
48
  public:
49
  DEFINE_SIZE_STATIC (8);
50
};
51
52
53
/*
54
 * MVAR -- Metrics Variations
55
 * https://docs.microsoft.com/en-us/typography/opentype/spec/mvar
56
 */
57
#define HB_OT_TAG_MVAR HB_TAG('M','V','A','R')
58
59
struct MVAR
60
{
61
  static constexpr hb_tag_t tableTag = HB_OT_TAG_MVAR;
62
63
  bool sanitize (hb_sanitize_context_t *c) const
64
0
  {
65
0
    TRACE_SANITIZE (this);
66
0
    return_trace (version.sanitize (c) &&
67
0
      likely (version.major == 1) &&
68
0
      c->check_struct (this) &&
69
0
      valueRecordSize >= VariationValueRecord::static_size &&
70
0
      varStore.sanitize (c, this) &&
71
0
      c->check_range (valuesZ.arrayZ,
72
0
          valueRecordCount,
73
0
          valueRecordSize));
74
0
  }
75
76
  float get_var (hb_tag_t tag,
77
     const int *coords, unsigned int coord_count) const
78
0
  {
79
0
    const VariationValueRecord *record;
80
0
    record = (VariationValueRecord *) hb_bsearch (tag,
81
0
              (const VariationValueRecord *)
82
0
                (const HBUINT8 *) valuesZ,
83
0
              valueRecordCount, valueRecordSize,
84
0
              tag_compare);
85
0
    if (!record)
86
0
      return 0.;
87
88
0
    return (this+varStore).get_delta (record->varIdx, coords, coord_count);
89
0
  }
90
91
protected:
92
  static int tag_compare (const void *pa, const void *pb)
93
0
  {
94
0
    const hb_tag_t *a = (const hb_tag_t *) pa;
95
0
    const Tag *b = (const Tag *) pb;
96
0
    return b->cmp (*a);
97
0
  }
98
99
  protected:
100
  FixedVersion<>version;  /* Version of the metrics variation table
101
         * initially set to 0x00010000u */
102
  HBUINT16  reserved; /* Not used; set to 0. */
103
  HBUINT16  valueRecordSize;/* The size in bytes of each value record —
104
         * must be greater than zero. */
105
  HBUINT16  valueRecordCount;/* The number of value records — may be zero. */
106
  Offset16To<VariationStore>
107
    varStore; /* Offset to item variation store table. */
108
  UnsizedArrayOf<HBUINT8>
109
    valuesZ;  /* Array of value records. The records must be
110
         * in binary order of their valueTag field. */
111
112
  public:
113
  DEFINE_SIZE_ARRAY (12, valuesZ);
114
};
115
116
} /* namespace OT */
117
118
119
#endif /* HB_OT_VAR_MVAR_TABLE_HH */