Coverage Report

Created: 2026-06-14 06:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ots/src/vorg.cc
Line
Count
Source
1
// Copyright (c) 2009-2017 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 "vorg.h"
6
7
#include <vector>
8
9
// VORG - Vertical Origin Table
10
// http://www.microsoft.com/typography/otspec/vorg.htm
11
12
namespace ots {
13
14
2.23k
bool OpenTypeVORG::Parse(const uint8_t *data, size_t length) {
15
2.23k
  Buffer table(data, length);
16
17
2.23k
  uint16_t num_recs;
18
2.23k
  if (!table.ReadU16(&this->major_version) ||
19
2.15k
      !table.ReadU16(&this->minor_version) ||
20
2.12k
      !table.ReadS16(&this->default_vert_origin_y) ||
21
2.08k
      !table.ReadU16(&num_recs)) {
22
174
    return Error("Failed to read header");
23
174
  }
24
2.06k
  if (this->major_version != 1) {
25
919
    return Drop("Unsupported majorVersion: %u", this->major_version);
26
919
  }
27
1.14k
  if (this->minor_version != 0) {
28
314
    return Drop("Unsupported minorVersion: %u", this->minor_version);
29
314
  }
30
31
  // num_recs might be zero (e.g., DFHSMinchoPro5-W3-Demo.otf).
32
827
  if (!num_recs) {
33
217
    return true;
34
217
  }
35
36
610
  uint16_t last_glyph_index = 0;
37
610
  this->metrics.reserve(num_recs);
38
1.92k
  for (unsigned i = 0; i < num_recs; ++i) {
39
1.64k
    OpenTypeVORGMetrics rec;
40
41
1.64k
    if (!table.ReadU16(&rec.glyph_index) ||
42
1.63k
        !table.ReadS16(&rec.vert_origin_y)) {
43
15
      return Error("Failed to read record %d", i);
44
15
    }
45
1.62k
    if ((i != 0) && (rec.glyph_index <= last_glyph_index)) {
46
309
      return Drop("The table is not sorted");
47
309
    }
48
1.31k
    last_glyph_index = rec.glyph_index;
49
50
1.31k
    this->metrics.push_back(rec);
51
1.31k
  }
52
53
286
  return true;
54
610
}
55
56
13
bool OpenTypeVORG::Serialize(OTSStream *out) {
57
13
  const uint16_t num_metrics = static_cast<uint16_t>(this->metrics.size());
58
13
  if (num_metrics != this->metrics.size() ||
59
13
      !out->WriteU16(this->major_version) ||
60
13
      !out->WriteU16(this->minor_version) ||
61
13
      !out->WriteS16(this->default_vert_origin_y) ||
62
13
      !out->WriteU16(num_metrics)) {
63
0
    return Error("Failed to write table header");
64
0
  }
65
66
13
  for (uint16_t i = 0; i < num_metrics; ++i) {
67
0
    const OpenTypeVORGMetrics& rec = this->metrics[i];
68
0
    if (!out->WriteU16(rec.glyph_index) ||
69
0
        !out->WriteS16(rec.vert_origin_y)) {
70
0
      return Error("Failed to write record %d", i);
71
0
    }
72
0
  }
73
74
13
  return true;
75
13
}
76
77
13.9k
bool OpenTypeVORG::ShouldSerialize() {
78
13.9k
  return Table::ShouldSerialize() &&
79
         // this table is not for fonts with TT glyphs.
80
2.56k
         GetFont()->GetTable(OTS_TAG_CFF) != NULL;
81
13.9k
}
82
83
}  // namespace ots