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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
// -*- related-file-name: "../../libefont/otfgpos.cc" -*-
#ifndef EFONT_OTFGPOS_HH
#define EFONT_OTFGPOS_HH
#include <efont/otf.hh>
#include <efont/otfdata.hh>
namespace Efont { namespace OpenType {
class GposLookup;
class Positioning;
class Gpos { public:
Gpos(const Data &, ErrorHandler * = 0) throw (Error);
// default destructor
const ScriptList &script_list() const { return _script_list; }
const FeatureList &feature_list() const { return _feature_list; }
int nlookups() const;
GposLookup lookup(unsigned) const;
enum { HEADERSIZE = 10 };
private:
ScriptList _script_list;
FeatureList _feature_list;
Data _lookup_list;
};
class GposLookup { public:
GposLookup(const Data &) throw (Error);
int type() const { return _d.u16(0); }
uint16_t flags() const { return _d.u16(2); }
bool unparse_automatics(Vector<Positioning> &, ErrorHandler * = 0) const;
enum {
HEADERSIZE = 6, RECSIZE = 2,
L_SINGLE = 1, L_PAIR = 2, L_CURSIVE = 3, L_MARKTOBASE = 4,
L_MARKTOLIGATURE = 5, L_MARKTOMARK = 6, L_CONTEXT = 7,
L_CHAIN = 8
};
private:
Data _d;
};
class GposValue { public:
static inline int size(uint16_t format);
static inline int16_t xplacement(uint16_t format, const Data &);
static inline int16_t yplacement(uint16_t format, const Data &);
static inline int16_t xadvance(uint16_t format, const Data &);
static inline int16_t yadvance(uint16_t format, const Data &);
enum {
F_XPLACEMENT = 0x0001,
F_YPLACEMENT = 0x0002,
F_XADVANCE = 0x0004,
F_YADVANCE = 0x0008,
F_XPLACEMENT_DEVICE = 0x0010,
F_YPLACEMENT_DEVICE = 0x0020,
F_XADVANCE_DEVICE = 0x0040,
F_YADVANCE_DEVICE = 0x0080
};
private:
static const int nibble_bitcount_x2[];
};
class GposSingle { public:
GposSingle(const Data &) throw (Error);
// default destructor
Coverage coverage() const throw ();
void unparse(Vector<Positioning> &) const;
enum { F2_HEADERSIZE = 8 };
private:
Data _d;
};
class GposPair { public:
GposPair(const Data &) throw (Error);
// default destructor
Coverage coverage() const throw ();
void unparse(Vector<Positioning> &) const;
enum { F1_HEADERSIZE = 10, F1_RECSIZE = 2,
PAIRSET_HEADERSIZE = 2, PAIRVALUE_HEADERSIZE = 2,
F2_HEADERSIZE = 16 };
private:
Data _d;
};
struct Position {
Glyph g;
int pdx, pdy; // placement
int adx, ady; // advance
inline Position();
inline Position(Glyph, uint16_t format, const Data &);
inline Position(uint16_t format, const Data &);
inline Position(Glyph, const Position &);
bool empty() const { return pdx == 0 && pdy == 0 && adx == 0 && ady == 0; }
operator bool() const { return !empty(); }
bool h_empty() const { return pdx == 0 && pdy == 0 && adx == 0; }
bool placed() const { return pdx != 0 || pdy != 0; }
void unparse(StringAccum &, const Vector<PermString> * = 0) const;
String unparse(const Vector<PermString> * = 0) const;
};
class Positioning { public:
Positioning();
// single positioning
inline Positioning(const Position &);
// pair positioning
inline Positioning(const Position &, const Position &);
bool context_in(const Coverage &) const;
bool context_in(const GlyphSet &) const;
// types
inline operator bool() const;
inline bool is_single() const;
inline bool is_pair() const;
inline bool is_pairkern() const;
// extract data
const Position &left() const { return _left; }
Glyph left_glyph() const { return _left.g; }
const Position &right() const { return _right; }
Glyph right_glyph() const { return _right.g; }
void unparse(StringAccum &, const Vector<PermString> * = 0) const;
String unparse(const Vector<PermString> * = 0) const;
private:
Position _left;
Position _right;
};
inline int GposValue::size(uint16_t format)
{
return (nibble_bitcount_x2[format & 15] + nibble_bitcount_x2[(format>>4) & 15]);
}
inline int16_t GposValue::xplacement(uint16_t format, const Data &d)
{
if (format & F_XPLACEMENT)
return d.s16(0);
else
return 0;
}
inline int16_t GposValue::yplacement(uint16_t format, const Data &d)
{
if (format & F_YPLACEMENT)
return d.s16((format & F_XPLACEMENT ? 2 : 0));
else
return 0;
}
inline int16_t GposValue::xadvance(uint16_t format, const Data &d)
{
if (format & F_XADVANCE)
return d.s16(nibble_bitcount_x2[format & (F_XADVANCE - 1)]);
else
return 0;
}
inline int16_t GposValue::yadvance(uint16_t format, const Data &d)
{
if (format & F_YADVANCE)
return d.s16(nibble_bitcount_x2[format & (F_YADVANCE - 1)]);
else
return 0;
}
inline Position::Position()
: g(0)
{
}
inline Position::Position(Glyph g_, uint16_t format, const Data &value)
: g(g_),
pdx(GposValue::xplacement(format, value)), pdy(GposValue::yplacement(format, value)),
adx(GposValue::xadvance(format, value)), ady(GposValue::yadvance(format, value))
{
}
inline Position::Position(uint16_t format, const Data &value)
: g(0),
pdx(GposValue::xplacement(format, value)), pdy(GposValue::yplacement(format, value)),
adx(GposValue::xadvance(format, value)), ady(GposValue::yadvance(format, value))
{
}
inline Position::Position(Glyph g_, const Position &p)
: g(g_), pdx(p.pdx), pdy(p.pdy), adx(p.adx), ady(p.ady)
{
}
inline Positioning::Positioning(const Position &left)
: _left(left)
{
}
inline Positioning::Positioning(const Position &left, const Position &right)
: _left(left), _right(right)
{
}
inline Positioning::operator bool() const
{
return _left.g != 0;
}
inline bool Positioning::is_single() const
{
return _left.g != 0 && _right.g == 0;
}
inline bool Positioning::is_pair() const
{
return _left.g != 0 && _right.g != 0;
}
inline bool Positioning::is_pairkern() const
{
return _left.g != 0 && !_left.placed() && _right.g != 0 && _right.h_empty();
}
}}
#endif
|