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