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 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
|
// -*- related-file-name: "../../libefont/otfgsub.cc" -*-
#ifndef EFONT_OTFGSUB_HH
#define EFONT_OTFGSUB_HH
#include <efont/otf.hh>
#include <efont/otfdata.hh>
namespace Efont { namespace OpenType {
class GsubLookup;
class Substitution;
class Gsub { public:
Gsub(const Data &, const Font *, ErrorHandler * = 0) throw (Error);
// default destructor
const ScriptList &script_list() const { return _script_list; }
const FeatureList &feature_list() const { return _feature_list; }
bool chaincontext_reverse_backtrack() const { return _chaincontext_reverse_backtrack; }
int nlookups() const;
GsubLookup lookup(unsigned) const;
enum { HEADERSIZE = 10 };
private:
ScriptList _script_list;
FeatureList _feature_list;
Data _lookup_list;
bool _chaincontext_reverse_backtrack;
};
class GsubLookup { public:
GsubLookup(const Data &) throw (Error);
int type() const { return _type; }
uint16_t flags() const { return _d.u16(2); }
void mark_out_glyphs(const Gsub &gsub, Vector<bool> &gmap) const;
bool unparse_automatics(const Gsub &gsub, Vector<Substitution> &subs, const Coverage &limit) const;
bool apply(const Glyph *, int pos, int n, Substitution &) const;
enum {
HEADERSIZE = 6, RECSIZE = 2,
L_SINGLE = 1, L_MULTIPLE = 2, L_ALTERNATE = 3, L_LIGATURE = 4,
L_CONTEXT = 5, L_CHAIN = 6, L_EXTENSION = 7, L_REVCHAIN = 8
};
private:
Data _d;
int _type;
Data subtable(int i) const;
};
class GsubSingle { public:
GsubSingle(const Data &) throw (Error);
// default destructor
Coverage coverage() const throw ();
Glyph map(Glyph) const;
void mark_out_glyphs(Vector<bool> &gmap) const;
void unparse(Vector<Substitution> &subs, const Coverage &limit) const;
bool apply(const Glyph *, int pos, int n, Substitution &) const;
enum { HEADERSIZE = 6, FORMAT2_RECSIZE = 2 };
private:
Data _d;
};
class GsubMultiple { public:
GsubMultiple(const Data &) throw (Error);
// default destructor
Coverage coverage() const throw ();
bool map(Glyph, Vector<Glyph> &) const;
void mark_out_glyphs(Vector<bool> &gmap) const;
void unparse(Vector<Substitution> &, bool alternate = false) const;
bool apply(const Glyph *, int pos, int n, Substitution &, bool alternate = false) const;
enum { HEADERSIZE = 6, RECSIZE = 2,
SEQ_HEADERSIZE = 2, SEQ_RECSIZE = 2 };
private:
Data _d;
};
class GsubLigature { public:
GsubLigature(const Data &) throw (Error);
// default destructor
Coverage coverage() const throw ();
bool map(const Vector<Glyph> &, Glyph &, int &) const;
void mark_out_glyphs(Vector<bool> &gmap) const;
void unparse(Vector<Substitution> &) const;
bool apply(const Glyph *, int pos, int n, Substitution &) const;
enum { HEADERSIZE = 6, RECSIZE = 2,
SET_HEADERSIZE = 2, SET_RECSIZE = 2,
LIG_HEADERSIZE = 4, LIG_RECSIZE = 2 };
private:
Data _d;
};
class GsubContext { public:
GsubContext(const Data &) throw (Error);
// default destructor
Coverage coverage() const throw ();
void mark_out_glyphs(const Gsub &gsub, Vector<bool> &gmap) const;
bool unparse(const Gsub &gsub, Vector<Substitution> &out_subs, const Coverage &limit) const;
enum { F3_HSIZE = 6, SUBRECSIZE = 4 };
private:
Data _d;
static void f3_mark_out_glyphs(const Data &data, int nsub, int subtab_offset, const Gsub &gsub, Vector<bool> &gmap);
static bool f3_unparse(const Data &data,
int nglyph, int glyphtab_offset, const Coverage &limit,
int nsub, int subtab_offset,
const Gsub &gsub, Vector<Substitution> &outsubs,
const Substitution &prototype_sub);
friend class GsubChainContext;
};
class GsubChainContext { public:
GsubChainContext(const Data &) throw (Error);
// default destructor
Coverage coverage() const throw ();
void mark_out_glyphs(const Gsub &gsub, Vector<bool> &gmap) const;
bool unparse(const Gsub &gsub, Vector<Substitution> &subs, const Coverage &limit) const;
enum { F1_HEADERSIZE = 6, F1_RECSIZE = 2,
F1_SRS_HSIZE = 2, F1_SRS_RSIZE = 2,
F3_HSIZE = 4, F3_INPUT_HSIZE = 2, F3_LOOKAHEAD_HSIZE = 2, F3_SUBST_HSIZE = 2 };
private:
Data _d;
};
class Substitution { public:
Substitution();
Substitution(const Substitution &);
// single substitution
Substitution(Glyph in, Glyph out);
// multiple substitution
Substitution(Glyph in, const Vector<Glyph> &out, bool is_alternate = false);
// ligature substitution
Substitution(Glyph in1, Glyph in2, Glyph out);
Substitution(const Vector<Glyph> &in, Glyph out);
Substitution(int nin, const Glyph *in, Glyph out);
// space
Substitution(int nleft, int nin, int nout, int nright);
~Substitution();
Substitution &operator=(const Substitution &);
bool context_in(const Coverage &) const;
bool context_in(const GlyphSet &) const;
// types
inline operator bool() const;
bool is_noop() const;
inline bool is_single() const;
inline bool is_multiple() const;
inline bool is_alternate() const;
inline bool is_ligature() const;
inline bool is_simple_context() const;
inline bool is_single_lcontext() const;
inline bool is_single_rcontext() const;
inline bool is_lcontext() const;
inline bool is_rcontext() const;
// extract data
inline Glyph left_glyph() const;
inline int left_nglyphs() const;
inline Glyph *left_glyphptr();
inline const Glyph *left_glyphptr() const;
inline Glyph in_glyph() const;
inline Glyph in_glyph(int pos) const;
inline bool in_glyphs(Vector<Glyph> &) const;
inline int in_nglyphs() const;
inline Glyph *in_glyphptr();
inline const Glyph *in_glyphptr() const;
inline bool in_matches(int pos, Glyph) const;
inline Glyph out_glyph() const;
inline Glyph out_glyph(int pos) const;
inline bool out_glyphs(Vector<Glyph> &) const;
inline Glyph *out_glyphptr();
inline const Glyph *out_glyphptr() const;
inline int out_nglyphs() const;
inline Glyph right_glyph() const;
inline Glyph *right_glyphptr();
inline const Glyph *right_glyphptr() const;
bool all_in_glyphs(Vector<Glyph> &gs) const;
bool all_out_glyphs(Vector<Glyph> &gs) const;
// alter
void add_outer_left(Glyph);
void remove_outer_left();
Substitution in_out_append_glyph(Glyph) const;
bool out_alter(const Substitution &, int) throw ();
void add_outer_right(Glyph);
void remove_outer_right();
void unparse(StringAccum &, const Vector<PermString> * = &debug_glyph_names) const;
String unparse(const Vector<PermString> * = &debug_glyph_names) const;
private:
enum { T_NONE = 0, T_GLYPH, T_GLYPHS, T_COVERAGE };
typedef union {
Glyph gid;
Glyph *gids; // first entry is a count
Coverage *coverage;
} Substitute;
Substitute _left;
Substitute _in;
Substitute _out;
Substitute _right;
uint8_t _left_is;
uint8_t _in_is;
uint8_t _out_is;
uint8_t _right_is;
bool _alternate : 1;
static void clear(Substitute &, uint8_t &);
static void assign_space(Substitute &, uint8_t &, int);
static void assign(Substitute &, uint8_t &, Glyph);
static void assign(Substitute &, uint8_t &, int, const Glyph *);
static void assign(Substitute &, uint8_t &, const Coverage &);
static void assign(Substitute &, uint8_t &, const Substitute &, uint8_t);
static void assign_append(Substitute &, uint8_t &, const Substitute &, uint8_t, const Substitute &, uint8_t);
static void assign_append(Substitute &, uint8_t &, const Substitute &, uint8_t, Glyph);
static bool substitute_in(const Substitute &, uint8_t, const Coverage &);
static bool substitute_in(const Substitute &, uint8_t, const GlyphSet &);
static Glyph extract_glyph(const Substitute &, uint8_t) throw ();
static Glyph extract_glyph(const Substitute &, int which, uint8_t) throw ();
static bool extract_glyphs(const Substitute &, uint8_t, Vector<Glyph> &, bool coverage_ok) throw ();
static Glyph *extract_glyphptr(const Substitute &, uint8_t) throw ();
static int extract_nglyphs(const Substitute &, uint8_t, bool coverage_ok) throw ();
static bool matches(const Substitute &, uint8_t, int pos, Glyph) throw ();
static void unparse_glyphids(StringAccum &, const Substitute &, uint8_t, const Vector<PermString> *) throw ();
};
inline Substitution::Substitution()
: _left_is(T_NONE), _in_is(T_NONE), _out_is(T_NONE), _right_is(T_NONE)
{
}
/* Single 1: u16 format, offset coverage, u16 glyphdelta
Single 2: u16 format, offset coverage, u16 count, glyph subst[]
Multiple 1: u16 format, offset coverage, u16 count, offset sequence[];
sequence is: u16 count, glyph subst[]
Alternate 1: u16 format, offset coverage, u16 count, offset alternates[];
alternate is: u16 count, glyph alts[]
Ligature 1: u16 format, offset coverage, u16 count, offset sets[];
set is: u16 count, offset ligatures[];
ligature is: glyph result, u16 count, glyph components[]
*/
inline Substitution::operator bool() const
{
return !(_left_is == T_NONE && _in_is == T_NONE && _out_is == T_NONE && _right_is == T_NONE);
}
inline bool Substitution::is_single() const
{
return _left_is == T_NONE && _in_is == T_GLYPH && _out_is == T_GLYPH && _right_is == T_NONE;
}
inline bool Substitution::is_multiple() const
{
return _left_is == T_NONE && _in_is == T_GLYPH && _out_is == T_GLYPHS && _right_is == T_NONE && !_alternate;
}
inline bool Substitution::is_alternate() const
{
return _left_is == T_NONE && _in_is == T_GLYPH && _out_is == T_GLYPHS && _right_is == T_NONE && _alternate;
}
inline bool Substitution::is_ligature() const
{
return _left_is == T_NONE && _in_is == T_GLYPHS && _out_is == T_GLYPH && _right_is == T_NONE;
}
inline bool Substitution::is_simple_context() const
{
return _left_is != T_COVERAGE && (_in_is == T_GLYPH || _in_is == T_GLYPHS) && (_out_is == T_GLYPH || _out_is == T_GLYPHS) && _right_is != T_COVERAGE;
}
inline bool Substitution::is_single_lcontext() const
{
return _left_is == T_GLYPH && _in_is == T_GLYPH && _out_is == T_GLYPH && _right_is == T_NONE;
}
inline bool Substitution::is_single_rcontext() const
{
return _left_is == T_NONE && _in_is == T_GLYPH && _out_is == T_GLYPH && _right_is == T_GLYPH;
}
inline Glyph Substitution::left_glyph() const
{
return extract_glyph(_left, _left_is);
}
inline int Substitution::left_nglyphs() const
{
return extract_nglyphs(_left, _left_is, false);
}
inline Glyph Substitution::in_glyph() const
{
return extract_glyph(_in, _in_is);
}
inline Glyph Substitution::in_glyph(int which) const
{
return extract_glyph(_in, which, _in_is);
}
inline bool Substitution::in_glyphs(Vector<Glyph> &v) const
{
return extract_glyphs(_in, _in_is, v, true);
}
inline int Substitution::in_nglyphs() const
{
return extract_nglyphs(_in, _in_is, true);
}
inline bool Substitution::in_matches(int pos, Glyph g) const
{
return matches(_in, _in_is, pos, g);
}
inline Glyph Substitution::out_glyph() const
{
return extract_glyph(_out, _out_is);
}
inline Glyph Substitution::out_glyph(int which) const
{
return extract_glyph(_out, which, _out_is);
}
inline bool Substitution::out_glyphs(Vector<Glyph> &v) const
{
return extract_glyphs(_out, _out_is, v, false);
}
inline int Substitution::out_nglyphs() const
{
return extract_nglyphs(_out, _out_is, false);
}
inline Glyph Substitution::right_glyph() const
{
return extract_glyph(_right, _right_is);
}
inline const Glyph *Substitution::left_glyphptr() const
{
return extract_glyphptr(_left, _left_is);
}
inline Glyph *Substitution::left_glyphptr()
{
return extract_glyphptr(_left, _left_is);
}
inline const Glyph *Substitution::in_glyphptr() const
{
return extract_glyphptr(_in, _in_is);
}
inline Glyph *Substitution::in_glyphptr()
{
return extract_glyphptr(_in, _in_is);
}
inline const Glyph *Substitution::out_glyphptr() const
{
return extract_glyphptr(_out, _out_is);
}
inline Glyph *Substitution::out_glyphptr()
{
return extract_glyphptr(_out, _out_is);
}
inline const Glyph *Substitution::right_glyphptr() const
{
return extract_glyphptr(_right, _right_is);
}
inline Glyph *Substitution::right_glyphptr()
{
return extract_glyphptr(_right, _right_is);
}
inline StringAccum &operator<<(StringAccum &sa, const Substitution &sub)
{
sub.unparse(sa);
return sa;
}
}}
#endif
|