w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

FeatureMap.h
Go to the documentation of this file.
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  FeatureSetting(int16 theValue, uint16 labelId) : m_label(labelId), m_value(theValue) {};
42  uint16 label() const { return m_label; }
43  int16 value() const { return m_value; }
44 
46 private:
48 
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  enum flags_t : uint16 {
60  HIDDEN = 0x0800
61  };
62  FeatureRef() throw();
63  FeatureRef(const Face & face, unsigned short & bits_offset, uint32 max_val,
64  uint32 name, uint16 uiName, flags_t flags,
65  FeatureSetting *settings, uint16 num_set) throw();
66  ~FeatureRef() throw();
67 
68  bool applyValToFeature(uint32 val, Features& pDest) const; //defined in GrFaceImp.h
69  void maskFeature(Features & pDest) const {
70  if (m_index < pDest.size()) //defensive
71  pDest[m_index] |= m_mask;
72  }
73 
74  uint32 getFeatureVal(const Features& feats) const; //defined in GrFaceImp.h
75 
76  uint32 getId() const { return m_id; }
77  uint16 getNameId() const { return m_nameid; }
78  uint16 getNumSettings() const { return m_numSet; }
81  flags_t getFlags() const { return m_flags; }
82  uint32 maxVal() const { return m_max; }
83  const Face & getFace() const { assert(m_face); return *m_face;}
84  const FeatureMap* getFeatureMap() const;// { return m_pFace;}
85 
87 private:
88  FeatureRef(const FeatureRef & rhs);
89 
90  const Face * m_face;
91  FeatureSetting * m_nameValues; // array of name table ids for feature values
92  chunk_t m_mask, // bit mask to get the value from the vector
93  m_max; // max value the value can take
94  uint32 m_id; // feature identifier/name
95  uint16 m_nameid, // Name table id for feature name
96  m_numSet; // number of values (number of entries in m_nameValues)
97  flags_t m_flags; // feature flags see FeatureRef::flags_t.
98  byte m_bits, // how many bits to shift the value into place
99  m_index; // index into the array to find the ulong to mask
100 
101 private: //unimplemented
103 };
104 
105 inline
106 FeatureRef::FeatureRef() throw()
107 : m_face(0),
108  m_nameValues(0),
109  m_mask(0), m_max(0),
110  m_id(0), m_nameid(0), m_numSet(0),
111  m_flags(flags_t(0)),
112  m_bits(0), m_index(0)
113 {
114 }
115 
116 
117 class NameAndFeatureRef
118 {
119  public:
121  NameAndFeatureRef(FeatureRef const & p) : m_name(p.getId()), m_pFRef(&p) {}
122 
123  bool operator<(const NameAndFeatureRef& rhs) const //orders by m_name
124  { return m_name<rhs.m_name; }
125 
127 
128  uint32 m_name;
129  const FeatureRef* m_pFRef;
130 };
131 
132 class FeatureMap
133 {
134 public:
136  ~FeatureMap() { delete[] m_feats; delete[] m_pNamedFeats; }
137 
138  bool readFeats(const Face & face);
140  FeatureRef *feature(uint16 index) const { return m_feats + index; }
141  //GrFeatureRef *featureRef(byte index) { return index < m_numFeats ? m_feats + index : NULL; }
142  const FeatureRef *featureRef(byte index) const { return index < m_numFeats ? m_feats + index : NULL; }
143  FeatureVal* cloneFeatures(uint32 langname/*0 means default*/) const; //call destroy_Features when done.
144  uint16 numFeats() const { return m_numFeats; };
146 private:
147 friend class SillMap;
149 
153 
154 private: //defensive on m_feats, m_pNamedFeats, and m_defaultFeatures
157 };
158 
159 
160 class SillMap
161 {
162 private:
163  class LangFeaturePair
164  {
167 
168  public:
171 
172  uint32 m_lang;
173  Features* m_pFeatures; //owns
175  };
176 public:
178  ~SillMap() { delete[] m_langFeats; }
179  bool readFace(const Face & face);
180  bool readSill(const Face & face);
181  FeatureVal* cloneFeatures(uint32 langname/*0 means default*/) const; //call destroy_Features when done.
182  uint16 numLanguages() const { return m_numLanguages; };
184 
185  const FeatureMap & theFeatureMap() const { return m_FeatureMap; };
186 private:
187  FeatureMap m_FeatureMap; //of face
188  LangFeaturePair * m_langFeats;
190 
191 private: //defensive on m_langFeats
192  SillMap(const SillMap&);
194 };
195 
196 } // namespace graphite2
197 
198 struct gr_feature_ref : public graphite2::FeatureRef {};
#define name
FeatureMap(const FeatureMap &)
FeatureMap & operator=(const FeatureMap &)
const FeatureRef * featureRef(byte index) const
Definition: FeatureMap.h:142
bool readFeats(const Face &face)
uint16 numFeats() const
Definition: FeatureMap.h:144
FeatureVal m_defaultFeatures
Definition: FeatureMap.h:152
FeatureRef * feature(uint16 index) const
Definition: FeatureMap.h:140
FeatureVal * cloneFeatures(uint32 langname) const
const FeatureRef * findFeatureRef(uint32 name) const
NameAndFeatureRef * m_pNamedFeats
Definition: FeatureMap.h:151
FeatureRef * m_feats
Definition: FeatureMap.h:150
uint16 getNumSettings() const
Definition: FeatureMap.h:78
uint32 getId() const
Definition: FeatureMap.h:76
const Face & getFace() const
Definition: FeatureMap.h:83
FeatureSetting * m_nameValues
Definition: FeatureMap.h:91
flags_t getFlags() const
Definition: FeatureMap.h:81
FeatureRef(const FeatureRef &rhs)
const FeatureMap * getFeatureMap() const
int16 getSettingValue(uint16 index) const
Definition: FeatureMap.h:80
uint16 getNameId() const
Definition: FeatureMap.h:77
void maskFeature(Features &pDest) const
Definition: FeatureMap.h:69
uint32 maxVal() const
Definition: FeatureMap.h:82
uint16 getSettingName(uint16 index) const
Definition: FeatureMap.h:79
static const uint8 SIZEOF_CHUNK
Definition: FeatureMap.h:56
uint32 getFeatureVal(const Features &feats) const
bool applyValToFeature(uint32 val, Features &pDest) const
Definition: FeatureMap.cpp:270
FeatureRef & operator=(const FeatureRef &)
const Face * m_face
Definition: FeatureMap.h:90
FeatureSetting(int16 theValue, uint16 labelId)
Definition: FeatureMap.h:41
uint16 label() const
Definition: FeatureMap.h:42
FeatureSetting(const FeatureSetting &fs)
Definition: FeatureMap.h:47
CLASS_NEW_DELETE uint32 m_name
Definition: FeatureMap.h:128
NameAndFeatureRef(uint32 name=0)
Definition: FeatureMap.h:120
NameAndFeatureRef(FeatureRef const &p)
Definition: FeatureMap.h:121
bool operator<(const NameAndFeatureRef &rhs) const
Definition: FeatureMap.h:123
const FeatureRef * m_pFRef
Definition: FeatureMap.h:129
LangFeaturePair & operator=(const LangFeaturePair &)
LangFeaturePair(const LangFeaturePair &)
FeatureMap m_FeatureMap
Definition: FeatureMap.h:185
bool readSill(const Face &face)
uint16 numLanguages() const
Definition: FeatureMap.h:182
bool readFace(const Face &face)
FeatureVal * cloneFeatures(uint32 langname) const
SillMap & operator=(const SillMap &)
SillMap(const SillMap &)
const FeatureMap & theFeatureMap() const
Definition: FeatureMap.h:185
LangFeaturePair * m_langFeats
Definition: FeatureMap.h:188
uint32 getLangName(uint16 index) const
Definition: FeatureMap.h:183
assert(pcxLoadImage24((char *)((void *) 0), fp, pinfo, hdr))
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p
Definition: afcover.h:72
FT_Face face
Definition: cffdrivr.c:659
#define const
Definition: ftzconf.h:91
Definition: bits.h:30
gr_int16 int16
Definition: Main.h:43
gr_uint8 uint8
Definition: Main.h:38
gr_uint16 uint16
Definition: Main.h:40
gr_uint32 uint32
Definition: Main.h:41
#define index(s, c)
Definition: plain2.h:351
#define flags
#define CLASS_NEW_DELETE
Definition: Main.h:159
Definition: mendex.h:20
Definition: strexpr.c:21
#define langname