Coverage Report

Created: 2026-03-12 06:50

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ots/src/vvar.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 "vvar.h"
6
7
#include "variations.h"
8
9
namespace ots {
10
11
// -----------------------------------------------------------------------------
12
// OpenTypeVVAR
13
// -----------------------------------------------------------------------------
14
15
1.21k
bool OpenTypeVVAR::Parse(const uint8_t* data, size_t length) {
16
1.21k
  Buffer table(data, length);
17
18
1.21k
  uint16_t majorVersion;
19
1.21k
  uint16_t minorVersion;
20
1.21k
  uint32_t itemVariationStoreOffset;
21
1.21k
  uint32_t advanceHeightMappingOffset;
22
1.21k
  uint32_t tsbMappingOffset;
23
1.21k
  uint32_t bsbMappingOffset;
24
1.21k
  uint32_t vOrgMappingOffset;
25
26
1.21k
  if (!table.ReadU16(&majorVersion) ||
27
1.09k
      !table.ReadU16(&minorVersion) ||
28
1.03k
      !table.ReadU32(&itemVariationStoreOffset) ||
29
927
      !table.ReadU32(&advanceHeightMappingOffset) ||
30
887
      !table.ReadU32(&tsbMappingOffset) ||
31
800
      !table.ReadU32(&bsbMappingOffset) ||
32
653
      !table.ReadU32(&vOrgMappingOffset)) {
33
652
    return DropVariations("Failed to read table header");
34
652
  }
35
36
567
  if (majorVersion != 1) {
37
158
    return DropVariations("Unknown table version");
38
158
  }
39
40
409
  if (itemVariationStoreOffset > length ||
41
365
      advanceHeightMappingOffset > length ||
42
325
      tsbMappingOffset > length ||
43
261
      bsbMappingOffset > length ||
44
228
      vOrgMappingOffset > length) {
45
228
    return DropVariations("Invalid subtable offset");
46
228
  }
47
48
181
  if (!ParseItemVariationStore(GetFont(), data + itemVariationStoreOffset,
49
181
                               length - itemVariationStoreOffset)) {
50
64
    return DropVariations("Failed to parse item variation store");
51
64
  }
52
53
117
  if (advanceHeightMappingOffset) {
54
116
    if (!ParseDeltaSetIndexMap(GetFont(), data + advanceHeightMappingOffset,
55
116
                               length - advanceHeightMappingOffset)) {
56
12
      return DropVariations("Failed to parse advance height mappings");
57
12
    }
58
116
  }
59
60
105
  if (tsbMappingOffset) {
61
57
    if (!ParseDeltaSetIndexMap(GetFont(), data + tsbMappingOffset,
62
57
                               length - tsbMappingOffset)) {
63
10
      return DropVariations("Failed to parse TSB mappings");
64
10
    }
65
57
  }
66
67
95
  if (bsbMappingOffset) {
68
40
    if (!ParseDeltaSetIndexMap(GetFont(), data + bsbMappingOffset,
69
40
                               length - bsbMappingOffset)) {
70
10
      return DropVariations("Failed to parse BSB mappings");
71
10
    }
72
40
  }
73
74
85
  if (vOrgMappingOffset) {
75
74
    if (!ParseDeltaSetIndexMap(GetFont(), data + vOrgMappingOffset,
76
74
                               length - vOrgMappingOffset)) {
77
16
      return DropVariations("Failed to parse vOrg mappings");
78
16
    }
79
74
  }
80
81
69
  this->m_data = data;
82
69
  this->m_length = length;
83
84
69
  return true;
85
85
}
86
87
38
bool OpenTypeVVAR::Serialize(OTSStream* out) {
88
38
  if (!out->Write(this->m_data, this->m_length)) {
89
0
    return Error("Failed to write VVAR table");
90
0
  }
91
92
38
  return true;
93
38
}
94
95
}  // namespace ots