Coverage Report

Created: 2026-09-28 06:53

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
1.93k
bool OpenTypeVORG::Parse(const uint8_t *data, size_t length) {
15
1.93k
  Buffer table(data, length);
16
17
1.93k
  uint16_t num_recs;
18
1.93k
  if (!table.ReadU16(&this->major_version) ||
19
1.86k
      !table.ReadU16(&this->minor_version) ||
20
1.84k
      !table.ReadS16(&this->default_vert_origin_y) ||
21
1.82k
      !table.ReadU16(&num_recs)) {
22
148
    return Error("Failed to read header");
23
148
  }
24
1.79k
  if (this->major_version != 1) {
25
837
    return Drop("Unsupported majorVersion: %u", this->major_version);
26
837
  }
27
954
  if (this->minor_version != 0) {
28
514
    return Drop("Unsupported minorVersion: %u", this->minor_version);
29
514
  }
30
31
  // num_recs might be zero (e.g., DFHSMinchoPro5-W3-Demo.otf).
32
440
  if (!num_recs) {
33
146
    return true;
34
146
  }
35
36
294
  uint16_t last_glyph_index = 0;
37
294
  this->metrics.reserve(num_recs);
38
1.08k
  for (unsigned i = 0; i < num_recs; ++i) {
39
997
    OpenTypeVORGMetrics rec;
40
41
997
    if (!table.ReadU16(&rec.glyph_index) ||
42
981
        !table.ReadS16(&rec.vert_origin_y)) {
43
24
      return Error("Failed to read record %d", i);
44
24
    }
45
973
    if ((i != 0) && (rec.glyph_index <= last_glyph_index)) {
46
181
      return Drop("The table is not sorted");
47
181
    }
48
792
    last_glyph_index = rec.glyph_index;
49
50
792
    this->metrics.push_back(rec);
51
792
  }
52
53
89
  return true;
54
294
}
55
56
17
bool OpenTypeVORG::Serialize(OTSStream *out) {
57
17
  const uint16_t num_metrics = static_cast<uint16_t>(this->metrics.size());
58
17
  if (num_metrics != this->metrics.size() ||
59
17
      !out->WriteU16(this->major_version) ||
60
17
      !out->WriteU16(this->minor_version) ||
61
17
      !out->WriteS16(this->default_vert_origin_y) ||
62
17
      !out->WriteU16(num_metrics)) {
63
0
    return Error("Failed to write table header");
64
0
  }
65
66
18
  for (uint16_t i = 0; i < num_metrics; ++i) {
67
1
    const OpenTypeVORGMetrics& rec = this->metrics[i];
68
1
    if (!out->WriteU16(rec.glyph_index) ||
69
1
        !out->WriteS16(rec.vert_origin_y)) {
70
0
      return Error("Failed to write record %d", i);
71
0
    }
72
1
  }
73
74
17
  return true;
75
17
}
76
77
10.9k
bool OpenTypeVORG::ShouldSerialize() {
78
10.9k
  return Table::ShouldSerialize() &&
79
         // this table is not for fonts with TT glyphs.
80
890
         GetFont()->GetTable(OTS_TAG_CFF) != NULL;
81
10.9k
}
82
83
}  // namespace ots