Lines 31-45
Link Here
|
31 |
|
31 |
|
32 |
FileFont::FileFont() |
32 |
FileFont::FileFont() |
33 |
: Font(), |
33 |
: Font(), |
34 |
m_file(NULL), |
34 |
m_pfile(NULL), |
35 |
m_pTableCache(NULL), |
35 |
m_pTableCache(NULL), |
36 |
m_ascent(0), |
36 |
m_mAscent(0), |
37 |
m_descent(0), |
37 |
m_mDescent(0), |
38 |
m_emSquare(0), |
38 |
m_mEmSquare(0), |
39 |
m_pointSize(0), |
39 |
m_pointSize(0), |
40 |
m_dpiX(FUDGE_FACTOR), |
40 |
m_dpiX(FUDGE_FACTOR), |
41 |
m_dpiY(FUDGE_FACTOR), |
41 |
m_dpiY(FUDGE_FACTOR), |
42 |
m_isValid(false), |
42 |
m_fIsValid(false), |
43 |
m_pHeader(NULL), |
43 |
m_pHeader(NULL), |
44 |
m_pTableDir(NULL), |
44 |
m_pTableDir(NULL), |
45 |
m_xScale(1.0f), |
45 |
m_xScale(1.0f), |
Lines 55-75
Link Here
|
55 |
FileFont::FileFont(FILE * file, float pointSize, |
55 |
FileFont::FileFont(FILE * file, float pointSize, |
56 |
unsigned int dpiX, unsigned int dpiY) |
56 |
unsigned int dpiX, unsigned int dpiY) |
57 |
: Font(), |
57 |
: Font(), |
58 |
m_file(file), |
58 |
m_pfile(file), |
59 |
m_pTableCache(NULL), |
59 |
m_pTableCache(NULL), |
60 |
m_ascent(0), |
60 |
m_mAscent(0), |
61 |
m_descent(0), |
61 |
m_mDescent(0), |
62 |
m_emSquare(0), |
62 |
m_mEmSquare(0), |
63 |
m_pointSize(pointSize), |
63 |
m_pointSize(pointSize), |
64 |
m_dpiX(dpiX), |
64 |
m_dpiX(dpiX), |
65 |
m_dpiY(dpiY), |
65 |
m_dpiY(dpiY), |
66 |
m_isValid(false), |
66 |
m_fIsValid(false), |
67 |
m_pHeader(NULL), |
67 |
m_pHeader(NULL), |
68 |
m_pTableDir(NULL), |
68 |
m_pTableDir(NULL), |
69 |
m_xScale(1.0f), |
69 |
m_xScale(1.0f), |
70 |
m_yScale(1.0f) |
70 |
m_yScale(1.0f) |
71 |
{ |
71 |
{ |
72 |
Assert(m_file); // shouldn't be null |
72 |
Assert(m_pfile); // shouldn't be null |
73 |
initializeFromFace(); |
73 |
initializeFromFace(); |
74 |
|
74 |
|
75 |
} |
75 |
} |
Lines 77-98
Link Here
|
77 |
FileFont::FileFont(char * fileName, float pointSize, |
77 |
FileFont::FileFont(char * fileName, float pointSize, |
78 |
unsigned int dpiX, unsigned int dpiY) |
78 |
unsigned int dpiX, unsigned int dpiY) |
79 |
: Font(), |
79 |
: Font(), |
80 |
m_file(NULL), |
80 |
m_pfile(NULL), |
81 |
m_pTableCache(NULL), |
81 |
m_pTableCache(NULL), |
82 |
m_ascent(0), |
82 |
m_mAscent(0), |
83 |
m_descent(0), |
83 |
m_mDescent(0), |
84 |
m_emSquare(0), |
84 |
m_mEmSquare(0), |
85 |
m_pointSize(pointSize), |
85 |
m_pointSize(pointSize), |
86 |
m_dpiX(dpiX), |
86 |
m_dpiX(dpiX), |
87 |
m_dpiY(dpiY), |
87 |
m_dpiY(dpiY), |
88 |
m_isValid(false), |
88 |
m_fIsValid(false), |
89 |
m_pHeader(NULL), |
89 |
m_pHeader(NULL), |
90 |
m_pTableDir(NULL), |
90 |
m_pTableDir(NULL), |
91 |
m_xScale(1.0f), |
91 |
m_xScale(1.0f), |
92 |
m_yScale(1.0f) |
92 |
m_yScale(1.0f) |
93 |
{ |
93 |
{ |
94 |
Assert(fileName); // shouldn't be null but we play safe anyway |
94 |
Assert(fileName); // shouldn't be null but we play safe anyway |
95 |
m_file = fopen(fileName, "rb"); |
95 |
m_pfile = fopen(fileName, "rb"); |
96 |
|
96 |
|
97 |
initializeFromFace(); |
97 |
initializeFromFace(); |
98 |
} |
98 |
} |
Lines 100-121
Link Here
|
100 |
FileFont::FileFont(std::string fileName, float pointSize, |
100 |
FileFont::FileFont(std::string fileName, float pointSize, |
101 |
unsigned int dpiX, unsigned int dpiY) |
101 |
unsigned int dpiX, unsigned int dpiY) |
102 |
: Font(), |
102 |
: Font(), |
103 |
m_file(NULL), |
103 |
m_pfile(NULL), |
104 |
m_pTableCache(NULL), |
104 |
m_pTableCache(NULL), |
105 |
m_ascent(0), |
105 |
m_mAscent(0), |
106 |
m_descent(0), |
106 |
m_mDescent(0), |
107 |
m_emSquare(0), |
107 |
m_mEmSquare(0), |
108 |
m_pointSize(pointSize), |
108 |
m_pointSize(pointSize), |
109 |
m_dpiX(dpiX), |
109 |
m_dpiX(dpiX), |
110 |
m_dpiY(dpiY), |
110 |
m_dpiY(dpiY), |
111 |
m_isValid(false), |
111 |
m_fIsValid(false), |
112 |
m_pHeader(NULL), |
112 |
m_pHeader(NULL), |
113 |
m_pTableDir(NULL), |
113 |
m_pTableDir(NULL), |
114 |
m_xScale(1.0f), |
114 |
m_xScale(1.0f), |
115 |
m_yScale(1.0f) |
115 |
m_yScale(1.0f) |
116 |
{ |
116 |
{ |
117 |
Assert(fileName.length()); // shouldn't be null but we play safe anyway |
117 |
Assert(fileName.length()); // shouldn't be null but we play safe anyway |
118 |
m_file = fopen(fileName.c_str(), "rb"); |
118 |
m_pfile = fopen(fileName.c_str(), "rb"); |
119 |
|
119 |
|
120 |
initializeFromFace(); |
120 |
initializeFromFace(); |
121 |
} |
121 |
} |
Lines 131-192
Link Here
|
131 |
m_clrFore = (unsigned long)kclrBlack; |
131 |
m_clrFore = (unsigned long)kclrBlack; |
132 |
m_clrBack = (unsigned long)kclrTransparent; |
132 |
m_clrBack = (unsigned long)kclrTransparent; |
133 |
|
133 |
|
134 |
if (m_file) |
134 |
if (m_pfile) |
135 |
{ |
135 |
{ |
136 |
size_t lOffset; |
136 |
size_t lOffset; |
137 |
size_t lSize; |
137 |
size_t lSize; |
138 |
TtfUtil::GetHeaderInfo(lOffset, lSize); |
138 |
TtfUtil::GetHeaderInfo(lOffset, lSize); |
139 |
m_pHeader = new byte [lSize]; |
139 |
m_pHeader = new byte [lSize]; |
140 |
m_isValid = true; |
140 |
m_fIsValid = true; |
141 |
if (!m_pHeader) |
141 |
if (!m_pHeader) |
142 |
{ |
142 |
{ |
143 |
m_isValid = false; |
143 |
m_fIsValid = false; |
144 |
return; |
144 |
return; |
145 |
} |
145 |
} |
146 |
m_isValid = (fseek(m_file, lOffset, SEEK_SET) == 0); |
146 |
m_fIsValid = (fseek(m_pfile, lOffset, SEEK_SET) == 0); |
147 |
size_t bytesRead = fread(m_pHeader, 1, lSize, m_file); |
147 |
size_t bytesRead = fread(m_pHeader, 1, lSize, m_pfile); |
148 |
Assert(static_cast<int>(bytesRead) == lSize); |
148 |
Assert(static_cast<int>(bytesRead) == lSize); |
149 |
m_isValid = TtfUtil::CheckHeader(m_pHeader); |
149 |
m_fIsValid = TtfUtil::CheckHeader(m_pHeader); |
150 |
|
150 |
|
151 |
if (!m_isValid) return; |
151 |
if (!m_fIsValid) return; |
152 |
m_isValid = TtfUtil::GetTableDirInfo(m_pHeader, lOffset, lSize); |
152 |
m_fIsValid = TtfUtil::GetTableDirInfo(m_pHeader, lOffset, lSize); |
153 |
m_pTableDir = new byte[lSize]; |
153 |
m_pTableDir = new byte[lSize]; |
154 |
if (!m_pTableDir) |
154 |
if (!m_pTableDir) |
155 |
{ |
155 |
{ |
156 |
m_isValid = false; |
156 |
m_fIsValid = false; |
157 |
return; |
157 |
return; |
158 |
} |
158 |
} |
159 |
// if lOffset hasn't changed this isn't needed |
159 |
// if lOffset hasn't changed this isn't needed |
160 |
fseek(m_file, lOffset, SEEK_SET); |
160 |
fseek(m_pfile, lOffset, SEEK_SET); |
161 |
bytesRead = fread(m_pTableDir, 1, lSize, m_file); |
161 |
bytesRead = fread(m_pTableDir, 1, lSize, m_pfile); |
162 |
Assert(static_cast<int>(bytesRead) == lSize); |
162 |
Assert(static_cast<int>(bytesRead) == lSize); |
163 |
|
163 |
|
164 |
// now read head tables |
164 |
// now read head tables |
165 |
m_isValid = TtfUtil::GetTableInfo(ktiOs2, m_pHeader, m_pTableDir, |
165 |
m_fIsValid = TtfUtil::GetTableInfo(ktiOs2, m_pHeader, m_pTableDir, |
166 |
lOffset, lSize); |
166 |
lOffset, lSize); |
167 |
if (!m_isValid) |
167 |
if (!m_fIsValid) |
168 |
{ |
168 |
{ |
169 |
return; |
169 |
return; |
170 |
} |
170 |
} |
171 |
byte * pTable = readTable(ktiOs2, lSize); |
171 |
byte * pTable = readTable(ktiOs2, lSize); |
172 |
// get ascent, descent, style while we have the OS2 table loaded |
172 |
// get ascent, descent, style while we have the OS2 table loaded |
173 |
if (!m_isValid || !pTable) |
173 |
if (!m_fIsValid || !pTable) |
174 |
{ |
174 |
{ |
175 |
return; |
175 |
return; |
176 |
} |
176 |
} |
177 |
m_isValid = TtfUtil::FontOs2Style(pTable, m_fBold, m_fItalic); |
177 |
m_fIsValid = TtfUtil::FontOs2Style(pTable, m_fBold, m_fItalic); |
178 |
m_ascent = static_cast<float>(TtfUtil::FontAscent(pTable)); |
178 |
m_mAscent = static_cast<float>(TtfUtil::FontAscent(pTable)); |
179 |
m_descent = static_cast<float>(TtfUtil::FontDescent(pTable)); |
179 |
m_mDescent = static_cast<float>(TtfUtil::FontDescent(pTable)); |
180 |
|
180 |
|
181 |
pTable = readTable(ktiName, lSize); |
181 |
pTable = readTable(ktiName, lSize); |
182 |
if (!m_isValid || !pTable) |
182 |
if (!m_fIsValid || !pTable) |
183 |
{ |
183 |
{ |
184 |
return; |
184 |
return; |
185 |
} |
185 |
} |
186 |
if (!TtfUtil::Get31EngFamilyInfo(pTable, lOffset, lSize)) |
186 |
if (!TtfUtil::Get31EngFamilyInfo(pTable, lOffset, lSize)) |
187 |
{ |
187 |
{ |
188 |
// not English name |
188 |
// not English name |
189 |
m_isValid = false; |
189 |
m_fIsValid = false; |
190 |
return; |
190 |
return; |
191 |
} |
191 |
} |
192 |
Assert(lSize %2 == 0);// should be utf16 |
192 |
Assert(lSize %2 == 0);// should be utf16 |
Lines 204-231
Link Here
|
204 |
{ |
204 |
{ |
205 |
utf32 cch32; |
205 |
utf32 cch32; |
206 |
U16_NEXT(rgchwFace, c16, cchw, cch32); |
206 |
U16_NEXT(rgchwFace, c16, cchw, cch32); |
207 |
m_faceName.push_back(cch32); |
207 |
m_stuFaceName.push_back(cch32); |
208 |
} |
208 |
} |
209 |
// } |
209 |
// } |
210 |
#else |
210 |
#else |
211 |
// else |
211 |
// else |
212 |
// { |
212 |
// { |
213 |
m_faceName.assign(rgchwFace); |
213 |
m_stuFaceName.assign(rgchwFace); |
214 |
// } |
214 |
// } |
215 |
#endif |
215 |
#endif |
216 |
pTable = readTable(ktiHead, lSize); |
216 |
pTable = readTable(ktiHead, lSize); |
217 |
if (!m_isValid || !pTable) |
217 |
if (!m_fIsValid || !pTable) |
218 |
{ |
218 |
{ |
219 |
return; |
219 |
return; |
220 |
} |
220 |
} |
221 |
m_emSquare = static_cast<float>(TtfUtil::DesignUnits(pTable)); |
221 |
m_mEmSquare = static_cast<float>(TtfUtil::DesignUnits(pTable)); |
222 |
// can now set the scale |
222 |
// can now set the scale |
223 |
m_xScale = scaleFromDpi(m_dpiX); |
223 |
m_xScale = scaleFromDpi(m_dpiX); |
224 |
m_yScale = scaleFromDpi(m_dpiY); |
224 |
m_yScale = scaleFromDpi(m_dpiY); |
225 |
} |
225 |
} |
226 |
else |
226 |
else |
227 |
{ |
227 |
{ |
228 |
m_isValid = false; |
228 |
m_fIsValid = false; |
229 |
} |
229 |
} |
230 |
} |
230 |
} |
231 |
|
231 |
|
Lines 249-255
Link Here
|
249 |
lOffset, lSize); |
249 |
lOffset, lSize); |
250 |
if (!isValid) |
250 |
if (!isValid) |
251 |
return NULL; |
251 |
return NULL; |
252 |
fseek(m_file, lOffset, SEEK_SET); |
252 |
fseek(m_pfile, lOffset, SEEK_SET); |
253 |
// only allocate if needed |
253 |
// only allocate if needed |
254 |
pTable = m_pTableCache->allocateTable(tableId, lSize); |
254 |
pTable = m_pTableCache->allocateTable(tableId, lSize); |
255 |
|
255 |
|
Lines 258-264
Link Here
|
258 |
isValid = false; |
258 |
isValid = false; |
259 |
return NULL; |
259 |
return NULL; |
260 |
} |
260 |
} |
261 |
size_t bytesRead = fread(pTable, 1, lSize, m_file); |
261 |
size_t bytesRead = fread(pTable, 1, lSize, m_pfile); |
262 |
isValid = (static_cast<int>(bytesRead) == lSize); |
262 |
isValid = (static_cast<int>(bytesRead) == lSize); |
263 |
if (isValid) |
263 |
if (isValid) |
264 |
{ |
264 |
{ |
Lines 287-300
Link Here
|
287 |
delete [] m_pTableDir; |
287 |
delete [] m_pTableDir; |
288 |
delete m_pTableCache; |
288 |
delete m_pTableCache; |
289 |
m_pTableCache = NULL; |
289 |
m_pTableCache = NULL; |
290 |
if (m_file) fclose(m_file); |
290 |
if (m_pfile) fclose(m_pfile); |
291 |
} |
291 |
} |
292 |
} |
292 |
} |
293 |
else |
293 |
else |
294 |
{ |
294 |
{ |
295 |
delete [] m_pHeader; |
295 |
delete [] m_pHeader; |
296 |
delete [] m_pTableDir; |
296 |
delete [] m_pTableDir; |
297 |
if (m_file) fclose(m_file); |
297 |
if (m_pfile) fclose(m_pfile); |
298 |
} |
298 |
} |
299 |
// note the DecFontCount(); is done in the Font base class |
299 |
// note the DecFontCount(); is done in the Font base class |
300 |
} |
300 |
} |
Lines 313-326
Link Here
|
313 |
FileFont::FileFont(const FileFont & font, float pointSize, |
313 |
FileFont::FileFont(const FileFont & font, float pointSize, |
314 |
unsigned int dpiX, unsigned int dpiY) |
314 |
unsigned int dpiX, unsigned int dpiY) |
315 |
: Font(font), |
315 |
: Font(font), |
316 |
m_file(font.m_file), |
316 |
m_pfile(font.m_pfile), |
317 |
m_ascent(font.m_ascent), |
317 |
m_mAscent(font.m_mAscent), |
318 |
m_descent(font.m_descent), |
318 |
m_mDescent(font.m_mDescent), |
319 |
m_emSquare(font.m_emSquare), |
319 |
m_mEmSquare(font.m_mEmSquare), |
320 |
m_pointSize(font.m_pointSize), |
320 |
m_pointSize(font.m_pointSize), |
321 |
m_dpiX(font.m_dpiX), |
321 |
m_dpiX(font.m_dpiX), |
322 |
m_dpiY(font.m_dpiY), |
322 |
m_dpiY(font.m_dpiY), |
323 |
m_isValid(font.m_isValid), |
323 |
m_fIsValid(font.m_fIsValid), |
324 |
m_pHeader(font.m_pHeader), |
324 |
m_pHeader(font.m_pHeader), |
325 |
m_pTableDir(font.m_pTableDir), |
325 |
m_pTableDir(font.m_pTableDir), |
326 |
m_xScale(font.m_xScale), |
326 |
m_xScale(font.m_xScale), |
Lines 343-349
Link Here
|
343 |
// colors are not used |
343 |
// colors are not used |
344 |
m_clrFore = font.m_clrFore; |
344 |
m_clrFore = font.m_clrFore; |
345 |
m_clrBack = font.m_clrBack; |
345 |
m_clrBack = font.m_clrBack; |
346 |
m_faceName.assign(font.m_faceName); |
346 |
m_stuFaceName.assign(font.m_stuFaceName); |
347 |
|
347 |
|
348 |
m_pTableCache = font.m_pTableCache; |
348 |
m_pTableCache = font.m_pTableCache; |
349 |
// use the same table cache between instances |
349 |
// use the same table cache between instances |
Lines 398-406
Link Here
|
398 |
void FileFont::getFontMetrics(float * pAscent, float * pDescent, |
398 |
void FileFont::getFontMetrics(float * pAscent, float * pDescent, |
399 |
float * pEmSquare) |
399 |
float * pEmSquare) |
400 |
{ |
400 |
{ |
401 |
if (pEmSquare) *pEmSquare = m_emSquare * m_xScale; |
401 |
if (pEmSquare) *pEmSquare = m_mEmSquare * m_xScale; |
402 |
if (pAscent) *pAscent = m_ascent * m_yScale; |
402 |
if (pAscent) *pAscent = m_mAscent * m_yScale; |
403 |
if (pDescent) *pDescent = m_descent * m_yScale; |
403 |
if (pDescent) *pDescent = m_mDescent * m_yScale; |
404 |
} |
404 |
} |
405 |
|
405 |
|
406 |
|
406 |
|
Lines 419-425
Link Here
|
419 |
bool FileFont::fontHasGraphiteTables() |
419 |
bool FileFont::fontHasGraphiteTables() |
420 |
{ |
420 |
{ |
421 |
size_t tableSize; |
421 |
size_t tableSize; |
422 |
bool isGraphiteFont = m_isValid; |
422 |
bool isGraphiteFont = m_fIsValid; |
423 |
isGraphiteFont &= (readTable(ktiSilf, tableSize) != NULL); |
423 |
isGraphiteFont &= (readTable(ktiSilf, tableSize) != NULL); |
424 |
return isGraphiteFont; |
424 |
return isGraphiteFont; |
425 |
} |
425 |
} |