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 "graphite2/Font.h"
7#include "inc/Main.h"
8#include "inc/Pass.h"
9
10namespace graphite2 {
11
12class Face;
13class Segment;
14class FeatureVal;
15class VMScratch;
16class Error;
17
18class Pseudo
19{
20public:
21 uint32 uid;
22 uint32 gid;
23 CLASS_NEW_DELETE;
24};
25
26class Justinfo
27{
28public:
29 Justinfo(uint8 stretch, uint8 shrink, uint8 step, uint8 weight) :
30 m_astretch(stretch), m_ashrink(shrink), m_astep(step),
31 m_aweight(weight) {};
32 uint8 attrStretch() const { return m_astretch; }
33 uint8 attrShrink() const { return m_ashrink; }
34 uint8 attrStep() const { return m_astep; }
35 uint8 attrWeight() const { return m_aweight; }
36
37private:
38 uint8 m_astretch;
39 uint8 m_ashrink;
40 uint8 m_astep;
41 uint8 m_aweight;
42};
43
44class Silf
45{
46 // Prevent copying
47 Silf(const Silf&);
48 Silf& operator=(const Silf&);
49
50public:
51 Silf() throw();
52 ~Silf() throw();
53
54 bool readGraphite(const byte * const pSilf, size_t lSilf, Face &face, uint32 version);
55 bool runGraphite(Segment *seg, uint8 firstPass=0, uint8 lastPass=0, int dobidi = 0) const;
56 uint16 findClassIndex(uint16 cid, uint16 gid) const;
57 uint16 getClassGlyph(uint16 cid, unsigned int index) const;
58 uint16 findPseudo(uint32 uid) const;
59 uint8 numUser() const { return m_aUser; }
60 uint8 aPseudo() const { return m_aPseudo; }
61 uint8 aBreak() const { return m_aBreak; }
62 uint8 aMirror() const {return m_aMirror; }
63 uint8 aPassBits() const { return m_aPassBits; }
64 uint8 aBidi() const { return m_aBidi; }
65 uint8 aCollision() const { return m_aCollision; }
66 uint8 substitutionPass() const { return m_sPass; }
67 uint8 positionPass() const { return m_pPass; }
68 uint8 justificationPass() const { return m_jPass; }
69 uint8 bidiPass() const { return m_bPass; }
70 uint8 numPasses() const { return m_numPasses; }
71 uint8 maxCompPerLig() const { return m_iMaxComp; }
72 uint16 numClasses() const { return m_nClass; }
73 byte flags() const { return m_flags; }
74 byte dir() const { return m_dir; }
75 uint8 numJustLevels() const { return m_numJusts; }
76 Justinfo *justAttrs() const { return m_justs; }
77 uint16 endLineGlyphid() const { return m_gEndLine; }
78 const gr_faceinfo *silfInfo() const { return &m_silfinfo; }
79
80 CLASS_NEW_DELETE;
81
82private:
83 size_t readClassMap(const byte *p, size_t data_len, uint32 version, Error &e);
84 template<typename T> inline uint32 readClassOffsets(const byte *&p, size_t data_len, Error &e);
85
86 Pass * m_passes;
87 Pseudo * m_pseudos;
88 uint32 * m_classOffsets;
89 uint16 * m_classData;
90 Justinfo * m_justs;
91 uint8 m_numPasses;
92 uint8 m_numJusts;
93 uint8 m_sPass, m_pPass, m_jPass, m_bPass,
94 m_flags, m_dir;
95
96 uint8 m_aPseudo, m_aBreak, m_aUser, m_aBidi, m_aMirror, m_aPassBits,
97 m_iMaxComp, m_aCollision;
98 uint16 m_aLig, m_numPseudo, m_nClass, m_nLinear,
99 m_gEndLine;
100 gr_faceinfo m_silfinfo;
101
102 void releaseBuffers() throw();
103};
104
105} // namespace graphite2
106