1 | // SPDX-License-Identifier: MIT OR MPL-2.0 OR LGPL-2.1-or-later OR GPL-2.0-or-later |
2 | // Copyright 2010, SIL International, All rights reserved. |
3 | |
4 | #pragma once |
5 | |
6 | #include <cstdlib> |
7 | #include "inc/Code.h" |
8 | |
9 | namespace graphite2 { |
10 | |
11 | class Segment; |
12 | class Face; |
13 | class Silf; |
14 | struct Rule; |
15 | struct RuleEntry; |
16 | struct State; |
17 | class FiniteStateMachine; |
18 | class Error; |
19 | class ShiftCollider; |
20 | class KernCollider; |
21 | class json; |
22 | |
23 | enum passtype; |
24 | |
25 | class Pass |
26 | { |
27 | public: |
28 | Pass(); |
29 | ~Pass(); |
30 | |
31 | bool readPass(const byte * pPass, size_t pass_length, size_t subtable_base, Face & face, |
32 | enum passtype pt, uint32 version, Error &e); |
33 | bool runGraphite(vm::Machine & m, FiniteStateMachine & fsm, bool reverse) const; |
34 | void init(Silf *silf) { m_silf = silf; } |
35 | byte collisionLoops() const { return m_numCollRuns; } |
36 | bool reverseDir() const { return m_isReverseDir; } |
37 | |
38 | CLASS_NEW_DELETE |
39 | private: |
40 | void findNDoRule(Slot* & iSlot, vm::Machine &, FiniteStateMachine& fsm) const; |
41 | int doAction(const vm::Machine::Code* codeptr, Slot * & slot_out, vm::Machine &) const; |
42 | bool testPassConstraint(vm::Machine & m) const; |
43 | bool testConstraint(const Rule & r, vm::Machine &) const; |
44 | bool readRules(const byte * rule_map, const size_t num_entries, |
45 | const byte *precontext, const uint16 * sort_key, |
46 | const uint16 * o_constraint, const byte *constraint_data, |
47 | const uint16 * o_action, const byte * action_data, |
48 | Face &, enum passtype pt, Error &e); |
49 | bool readStates(const byte * starts, const byte * states, const byte * o_rule_map, Face &, Error &e); |
50 | bool readRanges(const byte * ranges, size_t num_ranges, Error &e); |
51 | uint16 glyphToCol(const uint16 gid) const; |
52 | bool runFSM(FiniteStateMachine & fsm, Slot * slot) const; |
53 | void dumpRuleEventConsidered(const FiniteStateMachine & fsm, const RuleEntry & re) const; |
54 | void dumpRuleEventOutput(const FiniteStateMachine & fsm, const Rule & r, Slot * os) const; |
55 | void adjustSlot(int delta, Slot * & slot_out, SlotMap &) const; |
56 | bool collisionShift(Segment *seg, int dir, json * const dbgout) const; |
57 | bool collisionKern(Segment *seg, int dir, json * const dbgout) const; |
58 | bool collisionFinish(Segment *seg, GR_MAYBE_UNUSED json * const dbgout) const; |
59 | bool resolveCollisions(Segment *seg, Slot *slot, Slot *start, ShiftCollider &coll, bool isRev, |
60 | int dir, bool &moved, bool &hasCol, json * const dbgout) const; |
61 | float resolveKern(Segment *seg, Slot *slot, Slot *start, int dir, |
62 | float &ymin, float &ymax, json *const dbgout) const; |
63 | |
64 | const Silf * m_silf; |
65 | uint16 * m_cols; |
66 | Rule * m_rules; // rules |
67 | RuleEntry * m_ruleMap; |
68 | uint16 * m_startStates; // prectxt length |
69 | uint16 * m_transitions; |
70 | State * m_states; |
71 | vm::Machine::Code * m_codes; |
72 | byte * m_progs; |
73 | |
74 | byte m_numCollRuns; |
75 | byte m_kernColls; |
76 | byte m_iMaxLoop; |
77 | uint16 m_numGlyphs; |
78 | uint16 m_numRules; |
79 | uint16 m_numStates; |
80 | uint16 m_numTransition; |
81 | uint16 m_numSuccess; |
82 | uint16 m_successStart; |
83 | uint16 m_numColumns; |
84 | byte m_minPreCtxt; |
85 | byte m_maxPreCtxt; |
86 | byte m_colThreshold; |
87 | bool m_isReverseDir; |
88 | vm::Machine::Code m_cPConstraint; |
89 | |
90 | private: //defensive |
91 | Pass(const Pass&); |
92 | Pass& operator=(const Pass&); |
93 | }; |
94 | |
95 | } // namespace graphite2 |
96 | |