forked from primejyothi/glyphRen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fontClass.cc
265 lines (230 loc) · 5.7 KB
/
fontClass.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#include <iostream>
#include "fontClass.hpp"
#include "jlog.hpp"
//! \file fontClass.cc
//! \brief fontClass implementation
// Ligature methods ////////////////////
//! set method for form
void Ligature::setForm (string inForm)
{
form = inForm;
}
//! get method for form
string Ligature::getForm (void)
{
return form;
}
//! add glyph name to the list
void Ligature::addGlypToList (string glyphName)
{
glyphNames.push_back (glyphName);
}
//! Get the size of the glyph name list.
unsigned int Ligature::getGlypListSize (void)
{
return glyphNames.size ();
}
//! \fn int Ligature::getNthglyphName (unsigned int idx, string& out)
//! \brief Get the nth name from the glyphName list.
//! \param [in] idx index of the element starting from 0
//! \param [out] out The name of glyph
//! \returns SUCCESS if operation is successful
//! \returns FAIL if operation is failure or index is out of bound.
int Ligature::getNthglyphName (unsigned int idx, string& out)
{
if (idx > this->getGlypListSize ())
{
jERR ("getNthglyphName: Index out of bound");
return FAIL;
}
out = glyphNames[idx];
return SUCCESS;
}
//! Display the Ligature data
void Ligature::displayData ()
{
jTRACE ("Form : " << getForm ());
for (unsigned int i = 0; i < glyphNames.size (); i++)
{
jTRACE ("Glyphname : " << glyphNames[i]);
}
}
//! Display the Ligature data
void Ligature::displayGlyphs ()
{
string t;
for (unsigned int i = 0; i < glyphNames.size (); i++)
{
t.append (glyphNames[i]);
t.append (" ");
}
jTRACE (t);
}
void Ligature::clearGlypName (void)
{
glyphNames.clear ();
}
Ligature& Ligature::returnLigature (void)
{
return (*this);
}
// FontChar methods ////////////////////
//! set method for startPos
void FontChar::setStartPos (int pos)
{
startPos = pos;
}
//! get method for startPos
int FontChar::getStartPos (void)
{
return startPos;
}
//! Set method for curName
void FontChar::setCurName (string name)
{
curName = name;
}
//! Get method for curName
string FontChar::getCurName (void)
{
return curName;
}
//! Set method for unicodeVal
void FontChar::setUnicodeVal (int val)
{
unicodeVal = val;
}
//! Get method for unicodeVal
int FontChar::getUnicodeVal (void)
{
return unicodeVal;
}
//! Add ligature to the ligature vector
void FontChar::addLigature (Ligature lg)
{
this->ligatureList.push_back (lg);
}
//! Method to clear the data
void FontChar::clearData (void)
{
setStartPos (0);
setCurName ("");
setUnicodeVal (0);
for (unsigned int i = 0; i < ligatureList.size (); i++)
{
ligatureList[i].clearGlypName ();
}
ligatureList.clear ();
}
//! Set method for new name
void FontChar::setNewName (string name)
{
jTRACE ("Setting new name to [" << name << "]");
newName = name;
}
//! Get method for new name
string FontChar::getNewName (void)
{
return newName;
}
//! Display method for FontChars
void FontChar::displayData (void)
{
jTRACE ("========== FontChar ==========");
jTRACE ("Glyph Name : " << getCurName ());
// jTRACE ("New Name : " << getNewName ());
jTRACE ("Start Pos : " << getStartPos ());
jTRACE ("Unicodeval : " << getUnicodeVal ());
jTRACE ("Ligatures : ");
jTRACE ("Ligature # : " << ligatureList.size ());
for (unsigned int i = 0; i < ligatureList.size (); i++)
{
ligatureList[i].displayData ();
}
jTRACE ("==============================\n");;
}
//! Display glyph info in a different format
void FontChar::displayGlyphs (void)
{
jTRACE (getCurName () << ": ");
for (unsigned int i = 0; i < ligatureList.size (); i++)
{
ligatureList[i].displayGlyphs ();
}
jTRACE ("");
}
//! Load the glyph name to the map.
//! \fn int FontChar::loadMap (map<string, string>& nameMap)
//! \brief Load the glyphs from the FontChar to a map.
//! This map will be used to rename the ligatures. The old value of the
//! ligature will be the key and the value would be the new name.
//! \param [out] nameMap The map that contain old glyph
//! name and new name.
int FontChar::loadMap (map<string, string>& nameMap)
{
for (unsigned int i = 0; i < ligatureList.size (); i++)
{
for (unsigned int j = 0; j < ligatureList[i].getGlypListSize(); j++)
{
string glyph;
ligatureList[i].getNthglyphName(j, glyph);
nameMap[glyph] = "";
}
}
return SUCCESS;
}
//! Get the ligature count;
int FontChar::getLigatureCount (void)
{
return ligatureList.size ();
}
//! \fn Ligature& FontChar::getLigature (unsigned int pos)
//! Get the reference of the Nth Ligature.
//! \param pos [in] Position of the Ligature in the vector.
//! \returns Reference to the requested Ligature.
//! \returns An object dynamically allocated with Form set to "InvalidObject"
//! if pos is out of range. The caller has to check for the InvalidObject"
//! and free the dynamically allocated object.
//! \note Returns a dynamically allocated object if the pos is out of range.
//! The calling function has to check for this and free the dynamically
//! allocated object if applicable.
Ligature& FontChar::getLigature (unsigned int pos)
{
if (pos >= ligatureList.size())
{
Ligature *t = new Ligature();
t->setForm ("InvalidObject");
return (t->returnLigature ());
}
return (ligatureList[pos].returnLigature());
}
// CharRefData methods ////////////////////
//! Set method for codePtVal
int CharRefData::setCodeptVal (int val)
{
codePtVal = val;
return SUCCESS;
}
//! Get method for codePtVal
int CharRefData::getCodeptVal (void)
{
return codePtVal;
}
//! Set method for charName
int CharRefData::setCharName (string name)
{
charName = name;
return SUCCESS;
}
//! Get method for charName
string CharRefData::getCharName (void)
{
return (charName);
}
//! Display the CharRefData info
void CharRefData::displayData (void)
{
jTRACE ("========== CharRefData ==========");
jTRACE ("Char Name : " << getCharName ());
jTRACE ("CodePtVal : " << getCodeptVal ());
}