Coverage Report

Created: 2026-08-14 06:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ots/src/hvar.cc
Line
Count
Source
1
// Copyright (c) 2018 The OTS Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
#include "hvar.h"
6
7
#include "variations.h"
8
9
namespace ots {
10
11
// -----------------------------------------------------------------------------
12
// OpenTypeHVAR
13
// -----------------------------------------------------------------------------
14
15
3.34k
bool OpenTypeHVAR::Parse(const uint8_t* data, size_t length) {
16
3.34k
  Buffer table(data, length);
17
18
3.34k
  uint16_t majorVersion;
19
3.34k
  uint16_t minorVersion;
20
3.34k
  uint32_t itemVariationStoreOffset;
21
3.34k
  uint32_t advanceWidthMappingOffset;
22
3.34k
  uint32_t lsbMappingOffset;
23
3.34k
  uint32_t rsbMappingOffset;
24
25
3.34k
  if (!table.ReadU16(&majorVersion) ||
26
2.64k
      !table.ReadU16(&minorVersion) ||
27
2.45k
      !table.ReadU32(&itemVariationStoreOffset) ||
28
1.71k
      !table.ReadU32(&advanceWidthMappingOffset) ||
29
1.62k
      !table.ReadU32(&lsbMappingOffset) ||
30
1.91k
      !table.ReadU32(&rsbMappingOffset)) {
31
1.91k
    return DropVariations("Failed to read table header");
32
1.91k
  }
33
34
1.43k
  if (majorVersion != 1) {
35
423
    return DropVariations("Unknown table version");
36
423
  }
37
38
1.01k
  if (itemVariationStoreOffset > length ||
39
634
      advanceWidthMappingOffset > length ||
40
583
      lsbMappingOffset > length ||
41
557
      rsbMappingOffset > length) {
42
557
    return DropVariations("Invalid subtable offset");
43
557
  }
44
45
453
  if (!ParseItemVariationStore(GetFont(), data + itemVariationStoreOffset,
46
453
                               length - itemVariationStoreOffset)) {
47
215
    return DropVariations("Failed to parse item variation store");
48
215
  }
49
50
238
  if (advanceWidthMappingOffset) {
51
202
    if (!ParseDeltaSetIndexMap(GetFont(), data + advanceWidthMappingOffset,
52
202
                               length - advanceWidthMappingOffset)) {
53
19
      return DropVariations("Failed to parse advance width mappings");
54
19
    }
55
202
  }
56
57
219
  if (lsbMappingOffset) {
58
99
    if (!ParseDeltaSetIndexMap(GetFont(), data + lsbMappingOffset,
59
99
                               length - lsbMappingOffset)) {
60
19
      return DropVariations("Failed to parse LSB mappings");
61
19
    }
62
99
  }
63
64
200
  if (rsbMappingOffset) {
65
70
    if (!ParseDeltaSetIndexMap(GetFont(), data + rsbMappingOffset,
66
70
                               length - rsbMappingOffset)) {
67
21
      return DropVariations("Failed to parse RSB mappings");
68
21
    }
69
70
  }
70
71
179
  this->m_data = data;
72
179
  this->m_length = length;
73
74
179
  return true;
75
200
}
76
77
85
bool OpenTypeHVAR::Serialize(OTSStream* out) {
78
85
  if (!out->Write(this->m_data, this->m_length)) {
79
0
    return Error("Failed to write HVAR table");
80
0
  }
81
82
85
  return true;
83
85
}
84
85
}  // namespace ots