Line data Source code
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 : #include "inc/Main.h"
29 : #include "inc/FeatureVal.h"
30 :
31 : namespace graphite2 {
32 :
33 : // Forward declarations for implmentation types
34 : class FeatureMap;
35 : class Face;
36 :
37 :
38 : class FeatureSetting
39 : {
40 : public:
41 0 : FeatureSetting(int16 theValue, uint16 labelId) : m_label(labelId), m_value(theValue) {};
42 0 : uint16 label() const { return m_label; }
43 0 : int16 value() const { return m_value; }
44 :
45 : CLASS_NEW_DELETE;
46 : private:
47 : FeatureSetting(const FeatureSetting & fs) : m_label(fs.m_label), m_value(fs.m_value) {};
48 :
49 : uint16 m_label;
50 : int16 m_value;
51 : };
52 :
53 : class FeatureRef
54 : {
55 : typedef uint32 chunk_t;
56 : static const uint8 SIZEOF_CHUNK = sizeof(chunk_t)*8;
57 :
58 : public:
59 : FeatureRef();
60 : FeatureRef(const Face & face, unsigned short & bits_offset, uint32 max_val,
61 : uint32 name, uint16 uiName, uint16 flags,
62 : FeatureSetting *settings, uint16 num_set) throw();
63 : ~FeatureRef() throw();
64 :
65 : bool applyValToFeature(uint32 val, Features& pDest) const; //defined in GrFaceImp.h
66 : void maskFeature(Features & pDest) const {
67 : if (m_index < pDest.size()) //defensive
68 : pDest[m_index] |= m_mask;
69 : }
70 :
71 : uint32 getFeatureVal(const Features& feats) const; //defined in GrFaceImp.h
72 :
73 0 : uint32 getId() const { return m_id; }
74 0 : uint16 getNameId() const { return m_nameid; }
75 0 : uint16 getNumSettings() const { return m_numSet; }
76 0 : uint16 getSettingName(uint16 index) const { return m_nameValues[index].label(); }
77 0 : int16 getSettingValue(uint16 index) const { return m_nameValues[index].value(); }
78 0 : uint32 maxVal() const { return m_max; }
79 0 : const Face* getFace() const { return m_pFace;}
80 : const FeatureMap* getFeatureMap() const;// { return m_pFace;}
81 :
82 0 : CLASS_NEW_DELETE;
83 : private:
84 : FeatureRef(const FeatureRef & rhs);
85 :
86 : const Face * m_pFace; //not NULL
87 : FeatureSetting * m_nameValues; // array of name table ids for feature values
88 : chunk_t m_mask, // bit mask to get the value from the vector
89 : m_max; // max value the value can take
90 : uint32 m_id; // feature identifier/name
91 : uint16 m_nameid, // Name table id for feature name
92 : m_flags, // feature flags (unused at the moment but read from the font)
93 : m_numSet; // number of values (number of entries in m_nameValues)
94 : byte m_bits, // how many bits to shift the value into place
95 : m_index; // index into the array to find the ulong to mask
96 :
97 : private: //unimplemented
98 : FeatureRef& operator=(const FeatureRef&);
99 : };
100 :
101 :
102 : inline
103 0 : FeatureRef::FeatureRef()
104 : : m_pFace(0), m_nameValues(0),
105 : m_mask(0), m_max(0), m_id(0),
106 : m_nameid(0), m_flags(0), m_numSet(0),
107 0 : m_bits(0), m_index(0)
108 : {
109 0 : }
110 :
111 :
112 : class NameAndFeatureRef
113 : {
114 : public:
115 0 : NameAndFeatureRef(uint32 name = 0) : m_name(name) , m_pFRef(NULL){}
116 0 : NameAndFeatureRef(const FeatureRef* p/*not NULL*/) : m_name(p->getId()), m_pFRef(p) {}
117 :
118 0 : bool operator<(const NameAndFeatureRef& rhs) const //orders by m_name
119 0 : { return m_name<rhs.m_name; }
120 :
121 0 : CLASS_NEW_DELETE
122 :
123 : uint32 m_name;
124 : const FeatureRef* m_pFRef;
125 : };
126 :
127 : class FeatureMap
128 : {
129 : public:
130 0 : FeatureMap() : m_numFeats(0), m_feats(NULL), m_pNamedFeats(NULL) {}
131 0 : ~FeatureMap() { delete [] m_feats; delete[] m_pNamedFeats; }
132 :
133 : bool readFeats(const Face & face);
134 : const FeatureRef *findFeatureRef(uint32 name) const;
135 0 : FeatureRef *feature(uint16 index) const { return m_feats + index; }
136 : //GrFeatureRef *featureRef(byte index) { return index < m_numFeats ? m_feats + index : NULL; }
137 0 : const FeatureRef *featureRef(byte index) const { return index < m_numFeats ? m_feats + index : NULL; }
138 : FeatureVal* cloneFeatures(uint32 langname/*0 means default*/) const; //call destroy_Features when done.
139 0 : uint16 numFeats() const { return m_numFeats; };
140 : CLASS_NEW_DELETE
141 : private:
142 : friend class SillMap;
143 : uint16 m_numFeats;
144 :
145 : FeatureRef *m_feats;
146 : NameAndFeatureRef* m_pNamedFeats; //owned
147 : FeatureVal m_defaultFeatures; //owned
148 :
149 : private: //defensive on m_feats, m_pNamedFeats, and m_defaultFeatures
150 : FeatureMap(const FeatureMap&);
151 : FeatureMap& operator=(const FeatureMap&);
152 : };
153 :
154 :
155 : class SillMap
156 : {
157 : private:
158 : class LangFeaturePair
159 : {
160 : LangFeaturePair(const LangFeaturePair &);
161 : LangFeaturePair & operator = (const LangFeaturePair &);
162 :
163 : public:
164 0 : LangFeaturePair() : m_lang(0), m_pFeatures(0) {}
165 0 : ~LangFeaturePair() { delete m_pFeatures; }
166 :
167 : uint32 m_lang;
168 : Features* m_pFeatures; //owns
169 0 : CLASS_NEW_DELETE
170 : };
171 : public:
172 0 : SillMap() : m_langFeats(NULL), m_numLanguages(0) {}
173 0 : ~SillMap() { delete[] m_langFeats; }
174 : bool readFace(const Face & face);
175 : bool readSill(const Face & face);
176 : FeatureVal* cloneFeatures(uint32 langname/*0 means default*/) const; //call destroy_Features when done.
177 0 : uint16 numLanguages() const { return m_numLanguages; };
178 0 : uint32 getLangName(uint16 index) const { return (index < m_numLanguages)? m_langFeats[index].m_lang : 0; };
179 :
180 0 : const FeatureMap & theFeatureMap() const { return m_FeatureMap; };
181 : private:
182 : FeatureMap m_FeatureMap; //of face
183 : LangFeaturePair * m_langFeats;
184 : uint16 m_numLanguages;
185 :
186 : private: //defensive on m_langFeats
187 : SillMap(const SillMap&);
188 : SillMap& operator=(const SillMap&);
189 : };
190 :
191 : } // namespace graphite2
192 :
193 : struct gr_feature_ref : public graphite2::FeatureRef {};
|