Coverage Report

Created: 2025-10-13 06:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ots/src/name.h
Line
Count
Source
1
// Copyright (c) 2011-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
#ifndef OTS_NAME_H_
6
#define OTS_NAME_H_
7
8
#include <new>
9
#include <string>
10
#include <utility>
11
#include <vector>
12
#include <unordered_set>
13
14
#include "ots.h"
15
16
namespace ots {
17
18
struct NameRecord {
19
3.31M
  NameRecord() {
20
3.31M
  }
21
22
  NameRecord(uint16_t platformID, uint16_t encodingID,
23
             uint16_t languageID, uint16_t nameID)
24
187k
    : platform_id(platformID),
25
187k
      encoding_id(encodingID),
26
187k
      language_id(languageID),
27
187k
      name_id(nameID) {
28
187k
  }
29
30
  uint16_t platform_id;
31
  uint16_t encoding_id;
32
  uint16_t language_id;
33
  uint16_t name_id;
34
  std::string text;
35
36
15.8M
  bool operator<(const NameRecord& rhs) const {
37
15.8M
    if (platform_id < rhs.platform_id) return true;
38
14.2M
    if (platform_id > rhs.platform_id) return false;
39
13.0M
    if (encoding_id < rhs.encoding_id) return true;
40
12.1M
    if (encoding_id > rhs.encoding_id) return false;
41
11.4M
    if (language_id < rhs.language_id) return true;
42
9.93M
    if (language_id > rhs.language_id) return false;
43
9.01M
    return name_id < rhs.name_id;
44
9.93M
  }
45
};
46
47
class OpenTypeNAME : public Table {
48
 public:
49
  explicit OpenTypeNAME(Font *font, uint32_t tag)
50
21.7k
      : Table(font, tag, tag) { }
51
52
  bool Parse(const uint8_t *data, size_t length);
53
  bool Serialize(OTSStream *out);
54
  bool IsValidNameId(uint16_t nameID, bool addIfMissing = false);
55
  bool IsTrickyFont() const;
56
57
 private:
58
  std::vector<NameRecord> names;
59
  std::vector<std::string> lang_tags;
60
  std::unordered_set<uint16_t> name_ids;
61
};
62
63
}  // namespace ots
64
65
#endif  // OTS_NAME_H_