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