|
1 /* GRAPHITE2 LICENSING |
|
2 |
|
3 Copyright 2010, SIL International |
|
4 All rights reserved. |
|
5 |
|
6 This library is free software; you can redistribute it and/or modify |
|
7 it under the terms of the GNU Lesser General Public License as published |
|
8 by the Free Software Foundation; either version 2.1 of License, or |
|
9 (at your option) any later version. |
|
10 |
|
11 This program is distributed in the hope that it will be useful, |
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 Lesser General Public License for more details. |
|
15 |
|
16 You should also have received a copy of the GNU Lesser General Public |
|
17 License along with this library in the file named "LICENSE". |
|
18 If not, write to the Free Software Foundation, 51 Franklin Street, |
|
19 Suite 500, Boston, MA 02110-1335, USA or visit their web page on the |
|
20 internet at http://www.fsf.org/licenses/lgpl.html. |
|
21 |
|
22 Alternatively, the contents of this file may be used under the terms of the |
|
23 Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public |
|
24 License, as published by the Free Software Foundation, either version 2 |
|
25 of the License or (at your option) any later version. |
|
26 */ |
|
27 #pragma once |
|
28 |
|
29 #include <cstdlib> |
|
30 #include "inc/Code.h" |
|
31 |
|
32 namespace graphite2 { |
|
33 |
|
34 class Segment; |
|
35 class Face; |
|
36 class Silf; |
|
37 struct Rule; |
|
38 struct RuleEntry; |
|
39 struct State; |
|
40 class FiniteStateMachine; |
|
41 class Error; |
|
42 |
|
43 class Pass |
|
44 { |
|
45 public: |
|
46 Pass(); |
|
47 ~Pass(); |
|
48 |
|
49 bool readPass(const byte * pPass, size_t pass_length, size_t subtable_base, Face & face, Error &e); |
|
50 void runGraphite(vm::Machine & m, FiniteStateMachine & fsm) const; |
|
51 void init(Silf *silf) { m_silf = silf; } |
|
52 byte spaceContextuals() const { return (m_flags & 0x0E) >> 1; } |
|
53 |
|
54 CLASS_NEW_DELETE |
|
55 private: |
|
56 void findNDoRule(Slot* & iSlot, vm::Machine &, FiniteStateMachine& fsm) const; |
|
57 int doAction(const vm::Machine::Code* codeptr, Slot * & slot_out, vm::Machine &) const; |
|
58 bool testPassConstraint(vm::Machine & m) const; |
|
59 bool testConstraint(const Rule & r, vm::Machine &) const; |
|
60 bool readRules(const byte * rule_map, const size_t num_entries, |
|
61 const byte *precontext, const uint16 * sort_key, |
|
62 const uint16 * o_constraint, const byte *constraint_data, |
|
63 const uint16 * o_action, const byte * action_data, |
|
64 Face &, Error &e); |
|
65 bool readStates(const byte * starts, const byte * states, const byte * o_rule_map, Face &, Error &e); |
|
66 bool readRanges(const byte * ranges, size_t num_ranges, Error &e); |
|
67 uint16 glyphToCol(const uint16 gid) const; |
|
68 bool runFSM(FiniteStateMachine & fsm, Slot * slot) const; |
|
69 void dumpRuleEventConsidered(const FiniteStateMachine & fsm, const RuleEntry & re) const; |
|
70 void dumpRuleEventOutput(const FiniteStateMachine & fsm, const Rule & r, Slot * os) const; |
|
71 void adjustSlot(int delta, Slot * & slot_out, SlotMap &) const; |
|
72 const Silf* m_silf; |
|
73 uint16 * m_cols; |
|
74 Rule * m_rules; // rules |
|
75 RuleEntry * m_ruleMap; |
|
76 uint16 * m_startStates; // prectxt length |
|
77 uint16 * m_transitions; |
|
78 State * m_states; |
|
79 |
|
80 byte m_flags; |
|
81 byte m_iMaxLoop; |
|
82 uint16 m_numGlyphs; |
|
83 uint16 m_numRules; |
|
84 uint16 m_numStates; |
|
85 uint16 m_numTransition; |
|
86 uint16 m_numSuccess; |
|
87 uint16 m_successStart; |
|
88 uint16 m_numColumns; |
|
89 byte m_minPreCtxt; |
|
90 byte m_maxPreCtxt; |
|
91 vm::Machine::Code m_cPConstraint; |
|
92 |
|
93 private: //defensive |
|
94 Pass(const Pass&); |
|
95 Pass& operator=(const Pass&); |
|
96 }; |
|
97 |
|
98 } // namespace graphite2 |