Debian Codegraph @

texk/lcdf-typetools/lcdf-typetools-src/include/efont/pairop.hh

raw
1 // -*- related-file-name: "../../libefont/pairop.cc" -*-
2 #ifndef PAIROP_HH
3 #define PAIROP_HH
4 #include <efont/encoding.hh> /* get GlyphIndex */
5 namespace Efont {
6
7 enum PairOpDefs {
8
9 opNoop = -1,
10 opLigature = -2,
11
12 opLigSimple = 0,
13 opLigSaveLeft = 1,
14 opLigSaveRight = 2,
15 opLigPast1 = 4,
16 opLigPast2 = 8,
17
18 opAllblock = 0
19
20 };
21
22
23 typedef int PairOpIndex;
24
25
26 class PairOp { public:
27
28 PairOp() { }
29 inline PairOp(GlyphIndex l, GlyphIndex r, int v, PairOpIndex nl);
30 inline PairOp(GlyphIndex l, GlyphIndex r, GlyphIndex x, int kind, PairOpIndex nl);
31
32 void noopify() { _val = opNoop; }
33 void set_value(int val) { _val = val; }
34
35 inline void set_next(PairOpIndex);
36
37 bool is_lig() const { return _val <= opLigature; }
38 bool is_kern() const { return _val >= 0; }
39 bool is_noop() const { return _val == opNoop; }
40 int lig_kind() const { assert(is_lig()); return -_val+opLigature; }
41
42 GlyphIndex left() const { return _left; }
43 GlyphIndex right() const { return _right; }
44 GlyphIndex result() const { assert(is_lig()); return _result; }
45 int value() const { return _val; }
46 PairOpIndex next_left() const { return _next_left; }
47
48 private:
49
50 GlyphIndex _left;
51 GlyphIndex _right;
52 GlyphIndex _result;
53 int _val;
54
55 PairOpIndex _next_left;
56
57 };
58
59
60 class PairProgram { public:
61
62 PairProgram() : _reversed(false) { }
63 PairProgram(const PairProgram &);
64
65 void reserve_glyphs(int);
66
67 PairOpIndex find_left(GlyphIndex gi) const { return _left_map[gi]; }
68 PairOpIndex find(GlyphIndex leftgi, GlyphIndex rightgi) const;
69
70 int op_count() const { return _op.size(); }
71 const PairOp &op(PairOpIndex i) const { return _op[i]; }
72
73 // Return true if it's a duplicate.
74 bool add_kern(GlyphIndex, GlyphIndex, int);
75 bool add_lig(GlyphIndex, GlyphIndex, GlyphIndex, int kind = opLigSimple);
76
77 void set_reversed(bool r) { _reversed = r; }
78 void unreverse();
79 void optimize();
80
81 void print() const;
82
83 private:
84
85 bool _reversed;
86 Vector<PairOpIndex> _left_map;
87 Vector<PairOp> _op;
88
89 inline const char *print_name(GlyphIndex) const;
90
91 PairProgram &operator=(const PairProgram &) { assert(0); return *this; }
92
93 };
94
95
96 inline PairOp::PairOp(GlyphIndex l, GlyphIndex r, int v, PairOpIndex nl)
97 : _left(l), _right(r), _result(), _val(v), _next_left(nl)
98 {
99 }
100
101 inline PairOp::PairOp(GlyphIndex l, GlyphIndex r, GlyphIndex x, int kind,
102 PairOpIndex nl)
103 : _left(l), _right(r), _result(x), _val(opLigature - kind), _next_left(nl)
104 {
105 }
106
107 inline void PairOp::set_next(PairOpIndex nl)
108 {
109 _next_left = nl;
110 }
111
112 }
113 #endif