summaryrefslogtreecommitdiffstats
path: root/gfx/ots/src/glat.h
blob: 04c9c1cce529f55045a6a2f7e22797278d677511 (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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// Copyright (c) 2009-2017 The OTS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef OTS_GLAT_H_
#define OTS_GLAT_H_

#include <vector>

#include "ots.h"
#include "graphite.h"

namespace ots {

// -----------------------------------------------------------------------------
// OpenTypeGLAT_Basic Interface
// -----------------------------------------------------------------------------

class OpenTypeGLAT_Basic : public Table {
 public:
  explicit OpenTypeGLAT_Basic(Font* font, uint32_t tag)
      : Table(font, tag, tag) { }

  virtual bool Parse(const uint8_t* data, size_t length) = 0;
  virtual bool Serialize(OTSStream* out) = 0;
};

// -----------------------------------------------------------------------------
// OpenTypeGLAT_v1
// -----------------------------------------------------------------------------

class OpenTypeGLAT_v1 : public OpenTypeGLAT_Basic {
 public:
  explicit OpenTypeGLAT_v1(Font* font, uint32_t tag)
      : OpenTypeGLAT_Basic(font, tag) { }

  bool Parse(const uint8_t* data, size_t length);
  bool Serialize(OTSStream* out);

 private:
  struct GlatEntry : public TablePart<OpenTypeGLAT_v1> {
    explicit GlatEntry(OpenTypeGLAT_v1* parent)
        : TablePart<OpenTypeGLAT_v1>(parent) { }
    bool ParsePart(Buffer& table);
    bool SerializePart(OTSStream* out) const;
    uint8_t attNum;
    uint8_t num;
    std::vector<int16_t> attributes;
  };
  uint32_t version;
  std::vector<GlatEntry> entries;
};

// -----------------------------------------------------------------------------
// OpenTypeGLAT_v2
// -----------------------------------------------------------------------------

class OpenTypeGLAT_v2 : public OpenTypeGLAT_Basic {
 public:
  explicit OpenTypeGLAT_v2(Font* font, uint32_t tag)
      : OpenTypeGLAT_Basic(font, tag) { }

  bool Parse(const uint8_t* data, size_t length);
  bool Serialize(OTSStream* out);

 private:
 struct GlatEntry : public TablePart<OpenTypeGLAT_v2> {
   explicit GlatEntry(OpenTypeGLAT_v2* parent)
      : TablePart<OpenTypeGLAT_v2>(parent) { }
   bool ParsePart(Buffer& table);
   bool SerializePart(OTSStream* out) const;
   int16_t attNum;
   int16_t num;
   std::vector<int16_t> attributes;
  };
  uint32_t version;
  std::vector<GlatEntry> entries;
};

// -----------------------------------------------------------------------------
// OpenTypeGLAT_v3
// -----------------------------------------------------------------------------

class OpenTypeGLAT_v3 : public OpenTypeGLAT_Basic {
 public:
  explicit OpenTypeGLAT_v3(Font* font, uint32_t tag)
     : OpenTypeGLAT_Basic(font, tag) { }

  bool Parse(const uint8_t* data, size_t length) {
    return this->Parse(data, length, false);
  }
  bool Serialize(OTSStream* out);

 private:
  bool Parse(const uint8_t* data, size_t length, bool prevent_decompression);
  struct GlyphAttrs : public TablePart<OpenTypeGLAT_v3> {
    explicit GlyphAttrs(OpenTypeGLAT_v3* parent)
      : TablePart<OpenTypeGLAT_v3>(parent), octabox(parent) { }
    bool ParsePart(Buffer& table) { return false; }
    bool ParsePart(Buffer& table, const size_t size);
    bool SerializePart(OTSStream* out) const;
    struct OctaboxMetrics : public TablePart<OpenTypeGLAT_v3> {
      explicit OctaboxMetrics(OpenTypeGLAT_v3* parent)
          : TablePart<OpenTypeGLAT_v3>(parent) { }
      bool ParsePart(Buffer& table);
      bool SerializePart(OTSStream* out) const;
      struct SubboxEntry : public TablePart<OpenTypeGLAT_v3> {
        explicit SubboxEntry(OpenTypeGLAT_v3* parent)
            : TablePart<OpenTypeGLAT_v3>(parent) { }
        bool ParsePart(Buffer& table);
        bool SerializePart(OTSStream* out) const;
        uint8_t left;
        uint8_t right;
        uint8_t bottom;
        uint8_t top;
        uint8_t diag_pos_min;
        uint8_t diag_pos_max;
        uint8_t diag_neg_min;
        uint8_t diag_neg_max;
      };
      uint16_t subbox_bitmap;
      uint8_t diag_neg_min;
      uint8_t diag_neg_max;
      uint8_t diag_pos_min;
      uint8_t diag_pos_max;
      std::vector<SubboxEntry> subboxes;
    };
    struct GlatEntry : public TablePart<OpenTypeGLAT_v3> {
      explicit GlatEntry(OpenTypeGLAT_v3* parent)
          : TablePart<OpenTypeGLAT_v3>(parent) { }
      bool ParsePart(Buffer& table);
      bool SerializePart(OTSStream* out) const;
      int16_t attNum;
      int16_t num;
      std::vector<int16_t> attributes;
     };
    OctaboxMetrics octabox;
    std::vector<GlatEntry> entries;
  };
  uint32_t version;
  uint32_t compHead;  // compression header
  static const uint32_t SCHEME = 0xF8000000;
  static const uint32_t FULL_SIZE = 0x07FFFFFF;
  static const uint32_t RESERVED = 0x07FFFFFE;
  static const uint32_t OCTABOXES = 0x00000001;
  std::vector<GlyphAttrs> entries;
};

// -----------------------------------------------------------------------------
// OpenTypeGLAT
// -----------------------------------------------------------------------------

class OpenTypeGLAT : public Table {
 public:
  explicit OpenTypeGLAT(Font* font, uint32_t tag)
      : Table(font, tag, tag), font(font), tag(tag) { }
  OpenTypeGLAT(const OpenTypeGLAT& other) = delete;
  OpenTypeGLAT& operator=(const OpenTypeGLAT& other) = delete;
  ~OpenTypeGLAT() { delete handler; }

  bool Parse(const uint8_t* data, size_t length);
  bool Serialize(OTSStream* out);

 private:
  Font* font;
  uint32_t tag;
  OpenTypeGLAT_Basic* handler = nullptr;
};

}  // namespace ots

#endif  // OTS_GLAT_H_