Coverage Report

Created: 2026-05-30 06:10

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.07k
bool OpenTypeVVAR::Parse(const uint8_t* data, size_t length) {
16
1.07k
  Buffer table(data, length);
17
18
1.07k
  uint16_t majorVersion;
19
1.07k
  uint16_t minorVersion;
20
1.07k
  uint32_t itemVariationStoreOffset;
21
1.07k
  uint32_t advanceHeightMappingOffset;
22
1.07k
  uint32_t tsbMappingOffset;
23
1.07k
  uint32_t bsbMappingOffset;
24
1.07k
  uint32_t vOrgMappingOffset;
25
26
1.07k
  if (!table.ReadU16(&majorVersion) ||
27
1.01k
      !table.ReadU16(&minorVersion) ||
28
973
      !table.ReadU32(&itemVariationStoreOffset) ||
29
855
      !table.ReadU32(&advanceHeightMappingOffset) ||
30
836
      !table.ReadU32(&tsbMappingOffset) ||
31
761
      !table.ReadU32(&bsbMappingOffset) ||
32
714
      !table.ReadU32(&vOrgMappingOffset)) {
33
593
    return DropVariations("Failed to read table header");
34
593
  }
35
36
482
  if (majorVersion != 1) {
37
82
    return DropVariations("Unknown table version");
38
82
  }
39
40
400
  if (itemVariationStoreOffset > length ||
41
358
      advanceHeightMappingOffset > length ||
42
290
      tsbMappingOffset > length ||
43
243
      bsbMappingOffset > length ||
44
218
      vOrgMappingOffset > length) {
45
200
    return DropVariations("Invalid subtable offset");
46
200
  }
47
48
200
  if (!ParseItemVariationStore(GetFont(), data + itemVariationStoreOffset,
49
200
                               length - itemVariationStoreOffset)) {
50
57
    return DropVariations("Failed to parse item variation store");
51
57
  }
52
53
143
  if (advanceHeightMappingOffset) {
54
142
    if (!ParseDeltaSetIndexMap(GetFont(), data + advanceHeightMappingOffset,
55
142
                               length - advanceHeightMappingOffset)) {
56
26
      return DropVariations("Failed to parse advance height mappings");
57
26
    }
58
142
  }
59
60
117
  if (tsbMappingOffset) {
61
84
    if (!ParseDeltaSetIndexMap(GetFont(), data + tsbMappingOffset,
62
84
                               length - tsbMappingOffset)) {
63
18
      return DropVariations("Failed to parse TSB mappings");
64
18
    }
65
84
  }
66
67
99
  if (bsbMappingOffset) {
68
36
    if (!ParseDeltaSetIndexMap(GetFont(), data + bsbMappingOffset,
69
36
                               length - bsbMappingOffset)) {
70
10
      return DropVariations("Failed to parse BSB mappings");
71
10
    }
72
36
  }
73
74
89
  if (vOrgMappingOffset) {
75
75
    if (!ParseDeltaSetIndexMap(GetFont(), data + vOrgMappingOffset,
76
75
                               length - vOrgMappingOffset)) {
77
16
      return DropVariations("Failed to parse vOrg mappings");
78
16
    }
79
75
  }
80
81
73
  this->m_data = data;
82
73
  this->m_length = length;
83
84
73
  return true;
85
89
}
86
87
56
bool OpenTypeVVAR::Serialize(OTSStream* out) {
88
56
  if (!out->Write(this->m_data, this->m_length)) {
89
0
    return Error("Failed to write VVAR table");
90
0
  }
91
92
56
  return true;
93
56
}
94
95
}  // namespace ots