summaryrefslogtreecommitdiff
path: root/sfntly/tag.h
blob: 87d28378f1680fb56937e3880974b9dc719041af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
 * Copyright 2011 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SFNTLY_CPP_SRC_SFNTLY_TAG_H_
#define SFNTLY_CPP_SRC_SFNTLY_TAG_H_

#include <cstddef>

#include "sfntly/port/type.h"

namespace sfntly {

// Font identification tags used for tables, features, etc.
// Tag names are consistent with the OpenType and sfnt specs.
struct Tag {
  static const int32_t ttcf;

  // Table Type Tags
  // required tables
  static const int32_t cmap;
  static const int32_t head;
  static const int32_t hhea;
  static const int32_t hmtx;
  static const int32_t maxp;
  static const int32_t name;
  static const int32_t OS_2;
  static const int32_t post;

  // TrueType outline tables
  static const int32_t cvt;
  static const int32_t fpgm;
  static const int32_t glyf;
  static const int32_t loca;
  static const int32_t prep;

  // PostScript outline tables
  static const int32_t CFF;
  static const int32_t VORG;

  // bitmap glyph outlines
  static const int32_t EBDT;
  static const int32_t EBLC;
  static const int32_t EBSC;

  // advanced typographic features
  static const int32_t BASE;
  static const int32_t GDEF;
  static const int32_t GPOS;
  static const int32_t GSUB;
  static const int32_t JSTF;

  // other
  static const int32_t DSIG;
  static const int32_t gasp;
  static const int32_t hdmx;
  static const int32_t kern;
  static const int32_t LTSH;
  static const int32_t PCLT;
  static const int32_t VDMX;
  static const int32_t vhea;
  static const int32_t vmtx;

  // AAT tables
  static const int32_t bsln;
  static const int32_t feat;
  static const int32_t lcar;
  static const int32_t morx;
  static const int32_t opbd;
  static const int32_t prop;

  // Graphite tables
  static const int32_t Feat;
  static const int32_t Glat;
  static const int32_t Gloc;
  static const int32_t Sile;
  static const int32_t Silf;

  // Bitmap font tables
  static const int32_t bhed;
  static const int32_t bdat;
  static const int32_t bloc;
};

// Create integer tag value for human readable tag name.
inline int32_t GenerateTag(int32_t a, int32_t b, int32_t c, int32_t d) {
  return (a << 24) | (b << 16) | (c << 8) | d;
}

// Translate tag to human readable string.
// The Caller must delete[] the returned value.
inline char* TagToString(int32_t tag) {
  char *name = new char[5];
  name[0] = static_cast<char>((tag & 0xff000000) >> 24);
  name[1] = static_cast<char>((tag & 0x00ff0000) >> 16);
  name[2] = static_cast<char>((tag & 0x0000ff00) >> 8);
  name[3] = static_cast<char>(tag & 0x000000ff);
  name[4] = 0;
  return name;
}

// Note: For Java, these two orderings are in Font class.  Moved here to avoid
//       VC++ bug of not populating correct values.
extern const int32_t CFF_TABLE_ORDERING[];
extern const size_t CFF_TABLE_ORDERING_SIZE;
extern const int32_t TRUE_TYPE_TABLE_ORDERING[];
extern const size_t TRUE_TYPE_TABLE_ORDERING_SIZE;

}  // namespace sfntly

#endif  // SFNTLY_CPP_SRC_SFNTLY_TAG_H_