Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Side by Side Diff: xfa/fgas/font/fgas_gefont.cpp

Issue 2037563002: Replace IFGAS_Font with underlying concrete type (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: rebase Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fgas/font/fgas_gefont.h ('k') | xfa/fgas/font/fgas_stdfontmgr.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "xfa/fgas/font/fgas_gefont.h" 7 #include "xfa/fgas/font/fgas_gefont.h"
8 8
9 #include "xfa/fgas/crt/fgas_codepage.h" 9 #include "xfa/fgas/crt/fgas_codepage.h"
10 #include "xfa/fgas/font/fgas_fontutils.h" 10 #include "xfa/fgas/font/fgas_fontutils.h"
11 #include "xfa/fxfa/include/xfa_fontmgr.h" 11 #include "xfa/fxfa/include/xfa_fontmgr.h"
12 12
13 IFGAS_Font* IFGAS_Font::LoadFont(const FX_WCHAR* pszFontFamily, 13 // static
14 uint32_t dwFontStyles, 14 CFGAS_GEFont* CFGAS_GEFont::LoadFont(const FX_WCHAR* pszFontFamily,
15 uint16_t wCodePage, 15 uint32_t dwFontStyles,
16 IFGAS_FontMgr* pFontMgr) { 16 uint16_t wCodePage,
17 IFGAS_FontMgr* pFontMgr) {
17 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ 18 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
18 if (NULL != pFontMgr) { 19 if (NULL != pFontMgr) {
19 return pFontMgr->GetFontByCodePage(wCodePage, dwFontStyles, pszFontFamily); 20 return pFontMgr->GetFontByCodePage(wCodePage, dwFontStyles, pszFontFamily);
20 } 21 }
21 return NULL; 22 return NULL;
22 #else 23 #else
23 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); 24 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr);
24 if (!pFont->LoadFont(pszFontFamily, dwFontStyles, wCodePage)) { 25 if (!pFont->LoadFont(pszFontFamily, dwFontStyles, wCodePage)) {
25 pFont->Release(); 26 pFont->Release();
26 return NULL; 27 return NULL;
27 } 28 }
28 return pFont; 29 return pFont;
29 #endif 30 #endif
30 } 31 }
31 IFGAS_Font* IFGAS_Font::LoadFont(const uint8_t* pBuffer, 32
32 int32_t iLength, 33 // static
33 IFGAS_FontMgr* pFontMgr) { 34 CFGAS_GEFont* CFGAS_GEFont::LoadFont(CFX_Font* pExtFont,
34 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ 35 IFGAS_FontMgr* pFontMgr,
35 if (NULL != pFontMgr) { 36 FX_BOOL bTakeOver) {
36 return pFontMgr->LoadFont(pBuffer, iLength, 0, NULL);
37 }
38 return NULL;
39 #else
40 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr);
41 if (!pFont->LoadFont(pBuffer, iLength)) {
42 pFont->Release();
43 return NULL;
44 }
45 return pFont;
46 #endif
47 }
48 IFGAS_Font* IFGAS_Font::LoadFont(const FX_WCHAR* pszFileName,
49 IFGAS_FontMgr* pFontMgr) {
50 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
51 if (NULL != pFontMgr) {
52 return pFontMgr->LoadFont(pszFileName, 0, NULL);
53 }
54 return NULL;
55 #else
56 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr);
57 if (!pFont->LoadFont(pszFileName)) {
58 pFont->Release();
59 return NULL;
60 }
61 return pFont;
62 #endif
63 }
64 IFGAS_Font* IFGAS_Font::LoadFont(IFX_Stream* pFontStream,
65 IFGAS_FontMgr* pFontMgr,
66 FX_BOOL bSaveStream) {
67 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
68 if (NULL != pFontMgr) {
69 return pFontMgr->LoadFont(pFontStream, 0, NULL);
70 }
71 return NULL;
72 #else
73 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr);
74 if (!pFont->LoadFont(pFontStream, bSaveStream)) {
75 pFont->Release();
76 return NULL;
77 }
78 return pFont;
79 #endif
80 }
81 IFGAS_Font* IFGAS_Font::LoadFont(CFX_Font* pExtFont,
82 IFGAS_FontMgr* pFontMgr,
83 FX_BOOL bTakeOver) {
84 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); 37 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr);
85 if (!pFont->LoadFont(pExtFont, bTakeOver)) { 38 if (!pFont->LoadFont(pExtFont, bTakeOver)) {
86 pFont->Release(); 39 pFont->Release();
87 return NULL; 40 return NULL;
88 } 41 }
89 return pFont; 42 return pFont;
90 } 43 }
91 44
45 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
46 // static
47 CFGAS_GEFont* CFGAS_GEFont::LoadFont(const uint8_t* pBuffer,
48 int32_t iLength,
49 IFGAS_FontMgr* pFontMgr) {
50 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr);
51 if (!pFont->LoadFont(pBuffer, iLength)) {
52 pFont->Release();
53 return nullptr;
54 }
55 return pFont;
56 }
57
58 // static
59 CFGAS_GEFont* CFGAS_GEFont::LoadFont(const FX_WCHAR* pszFileName) {
60 CFGAS_GEFont* pFont = new CFGAS_GEFont(nullptr);
61 if (!pFont->LoadFontInternal(pszFileName)) {
62 pFont->Release();
63 return nullptr;
64 }
65 return pFont;
66 }
67
68 // static
69 CFGAS_GEFont* CFGAS_GEFont::LoadFont(IFX_Stream* pFontStream,
70 IFGAS_FontMgr* pFontMgr,
71 FX_BOOL bSaveStream) {
72 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr);
73 if (!pFont->LoadFont(pFontStream, bSaveStream)) {
74 pFont->Release();
75 return nullptr;
76 }
77 return pFont;
78 }
79 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
80
92 CFGAS_GEFont::CFGAS_GEFont(IFGAS_FontMgr* pFontMgr) 81 CFGAS_GEFont::CFGAS_GEFont(IFGAS_FontMgr* pFontMgr)
93 : 82 :
94 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ 83 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
95 m_bUseLogFontStyle(FALSE), 84 m_bUseLogFontStyle(FALSE),
96 m_dwLogFontStyle(0), 85 m_dwLogFontStyle(0),
97 #endif 86 #endif
98 m_pFont(NULL), 87 m_pFont(NULL),
99 m_pFontMgr(pFontMgr), 88 m_pFontMgr(pFontMgr),
100 m_iRefCount(1), 89 m_iRefCount(1),
101 m_bExtFont(FALSE), 90 m_bExtFont(FALSE),
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 } 153 }
165 154
166 void CFGAS_GEFont::Release() { 155 void CFGAS_GEFont::Release() {
167 if (--m_iRefCount < 1) { 156 if (--m_iRefCount < 1) {
168 if (m_pFontMgr != NULL) { 157 if (m_pFontMgr != NULL) {
169 m_pFontMgr->RemoveFont(this); 158 m_pFontMgr->RemoveFont(this);
170 } 159 }
171 delete this; 160 delete this;
172 } 161 }
173 } 162 }
174 IFGAS_Font* CFGAS_GEFont::Retain() { 163 CFGAS_GEFont* CFGAS_GEFont::Retain() {
175 ++m_iRefCount; 164 ++m_iRefCount;
176 return this; 165 return this;
177 } 166 }
167
168 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
178 FX_BOOL CFGAS_GEFont::LoadFont(const FX_WCHAR* pszFontFamily, 169 FX_BOOL CFGAS_GEFont::LoadFont(const FX_WCHAR* pszFontFamily,
179 uint32_t dwFontStyles, 170 uint32_t dwFontStyles,
180 uint16_t wCodePage) { 171 uint16_t wCodePage) {
181 if (m_pFont) { 172 if (m_pFont) {
182 return FALSE; 173 return FALSE;
183 } 174 }
184 CFX_ByteString csFontFamily; 175 CFX_ByteString csFontFamily;
185 if (pszFontFamily != NULL) { 176 if (pszFontFamily != NULL) {
186 csFontFamily = CFX_ByteString::FromUnicode(pszFontFamily); 177 csFontFamily = CFX_ByteString::FromUnicode(pszFontFamily);
187 } 178 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 } else if (dwFlags & FXFONT_ITALIC) { 213 } else if (dwFlags & FXFONT_ITALIC) {
223 csFontFamily += ",Italic"; 214 csFontFamily += ",Italic";
224 } 215 }
225 m_pFont->LoadSubst(csFontFamily, TRUE, dwFlags, iWeight, 0, wCodePage); 216 m_pFont->LoadSubst(csFontFamily, TRUE, dwFlags, iWeight, 0, wCodePage);
226 FX_BOOL bRet = m_pFont->GetFace() != nullptr; 217 FX_BOOL bRet = m_pFont->GetFace() != nullptr;
227 if (bRet) { 218 if (bRet) {
228 bRet = InitFont(); 219 bRet = InitFont();
229 } 220 }
230 return bRet; 221 return bRet;
231 } 222 }
223
232 FX_BOOL CFGAS_GEFont::LoadFont(const uint8_t* pBuffer, int32_t length) { 224 FX_BOOL CFGAS_GEFont::LoadFont(const uint8_t* pBuffer, int32_t length) {
233 if (m_pFont) { 225 if (m_pFont) {
234 return FALSE; 226 return FALSE;
235 } 227 }
236 m_pFont = new CFX_Font; 228 m_pFont = new CFX_Font;
237 FX_BOOL bRet = m_pFont->LoadEmbedded(pBuffer, length); 229 FX_BOOL bRet = m_pFont->LoadEmbedded(pBuffer, length);
238 if (bRet) { 230 if (bRet) {
239 bRet = InitFont(); 231 bRet = InitFont();
240 } 232 }
241 m_wCharSet = 0xFFFF; 233 m_wCharSet = 0xFFFF;
242 return bRet; 234 return bRet;
243 } 235 }
244 FX_BOOL CFGAS_GEFont::LoadFont(const FX_WCHAR* pszFileName) { 236
237 FX_BOOL CFGAS_GEFont::LoadFontInternal(const FX_WCHAR* pszFileName) {
245 if (m_pFont || m_pStream || m_pFileRead) { 238 if (m_pFont || m_pStream || m_pFileRead) {
246 return FALSE; 239 return FALSE;
247 } 240 }
248 m_pStream = IFX_Stream::CreateStream( 241 m_pStream = IFX_Stream::CreateStream(
249 pszFileName, FX_STREAMACCESS_Binary | FX_STREAMACCESS_Read); 242 pszFileName, FX_STREAMACCESS_Binary | FX_STREAMACCESS_Read);
250 m_pFileRead = FX_CreateFileRead(m_pStream); 243 m_pFileRead = FX_CreateFileRead(m_pStream);
251 FX_BOOL bRet = FALSE; 244 FX_BOOL bRet = FALSE;
252 if (m_pStream && m_pFileRead) { 245 if (m_pStream && m_pFileRead) {
253 m_pFont = new CFX_Font; 246 m_pFont = new CFX_Font;
254 bRet = m_pFont->LoadFile(m_pFileRead); 247 bRet = m_pFont->LoadFile(m_pFileRead);
255 if (bRet) { 248 if (bRet) {
256 bRet = InitFont(); 249 bRet = InitFont();
257 } else { 250 } else {
258 m_pFileRead->Release(); 251 m_pFileRead->Release();
259 m_pFileRead = nullptr; 252 m_pFileRead = nullptr;
260 } 253 }
261 } 254 }
262 m_wCharSet = 0xFFFF; 255 m_wCharSet = 0xFFFF;
263 return bRet; 256 return bRet;
264 } 257 }
258
265 FX_BOOL CFGAS_GEFont::LoadFont(IFX_Stream* pFontStream, FX_BOOL bSaveStream) { 259 FX_BOOL CFGAS_GEFont::LoadFont(IFX_Stream* pFontStream, FX_BOOL bSaveStream) {
266 if (m_pFont || m_pFileRead || !pFontStream || pFontStream->GetLength() < 1) { 260 if (m_pFont || m_pFileRead || !pFontStream || pFontStream->GetLength() < 1) {
267 return FALSE; 261 return FALSE;
268 } 262 }
269 if (bSaveStream) { 263 if (bSaveStream) {
270 m_pStream = pFontStream; 264 m_pStream = pFontStream;
271 } 265 }
272 m_pFileRead = FX_CreateFileRead(pFontStream); 266 m_pFileRead = FX_CreateFileRead(pFontStream);
273 m_pFont = new CFX_Font; 267 m_pFont = new CFX_Font;
274 FX_BOOL bRet = m_pFont->LoadFile(m_pFileRead); 268 FX_BOOL bRet = m_pFont->LoadFile(m_pFileRead);
275 if (bRet) { 269 if (bRet) {
276 bRet = InitFont(); 270 bRet = InitFont();
277 } else { 271 } else {
278 m_pFileRead->Release(); 272 m_pFileRead->Release();
279 m_pFileRead = nullptr; 273 m_pFileRead = nullptr;
280 } 274 }
281 m_wCharSet = 0xFFFF; 275 m_wCharSet = 0xFFFF;
282 return bRet; 276 return bRet;
283 } 277 }
278 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
279
284 FX_BOOL CFGAS_GEFont::LoadFont(CFX_Font* pExtFont, FX_BOOL bTakeOver) { 280 FX_BOOL CFGAS_GEFont::LoadFont(CFX_Font* pExtFont, FX_BOOL bTakeOver) {
285 if (m_pFont || !pExtFont) { 281 if (m_pFont || !pExtFont) {
286 return FALSE; 282 return FALSE;
287 } 283 }
288 m_pFont = pExtFont; 284 m_pFont = pExtFont;
289 FX_BOOL bRet = !!m_pFont; 285 FX_BOOL bRet = !!m_pFont;
290 if (bRet) { 286 if (bRet) {
291 m_bExtFont = !bTakeOver; 287 m_bExtFont = !bTakeOver;
292 bRet = InitFont(); 288 bRet = InitFont();
293 } else { 289 } else {
294 m_bExtFont = TRUE; 290 m_bExtFont = TRUE;
295 } 291 }
296 m_wCharSet = 0xFFFF; 292 m_wCharSet = 0xFFFF;
297 return bRet; 293 return bRet;
298 } 294 }
295
299 FX_BOOL CFGAS_GEFont::InitFont() { 296 FX_BOOL CFGAS_GEFont::InitFont() {
300 if (!m_pFont) 297 if (!m_pFont)
301 return FALSE; 298 return FALSE;
302 if (!m_pFontEncoding) { 299 if (!m_pFontEncoding) {
303 m_pFontEncoding = FX_CreateFontEncodingEx(m_pFont); 300 m_pFontEncoding = FX_CreateFontEncodingEx(m_pFont);
304 if (!m_pFontEncoding) 301 if (!m_pFontEncoding)
305 return FALSE; 302 return FALSE;
306 } 303 }
307 if (!m_pCharWidthMap) 304 if (!m_pCharWidthMap)
308 m_pCharWidthMap = new CFX_WordDiscreteArray(1024); 305 m_pCharWidthMap = new CFX_WordDiscreteArray(1024);
309 if (!m_pRectArray) 306 if (!m_pRectArray)
310 m_pRectArray = new CFX_MassArrayTemplate<CFX_Rect>(16); 307 m_pRectArray = new CFX_MassArrayTemplate<CFX_Rect>(16);
311 if (!m_pBBoxMap) 308 if (!m_pBBoxMap)
312 m_pBBoxMap = new CFX_MapPtrToPtr(16); 309 m_pBBoxMap = new CFX_MapPtrToPtr(16);
313 310
314 return TRUE; 311 return TRUE;
315 } 312 }
316 IFGAS_Font* CFGAS_GEFont::Derive(uint32_t dwFontStyles, uint16_t wCodePage) { 313 CFGAS_GEFont* CFGAS_GEFont::Derive(uint32_t dwFontStyles, uint16_t wCodePage) {
317 if (GetFontStyles() == dwFontStyles) { 314 if (GetFontStyles() == dwFontStyles) {
318 return Retain(); 315 return Retain();
319 } 316 }
320 return new CFGAS_GEFont(*this, dwFontStyles); 317 return new CFGAS_GEFont(*this, dwFontStyles);
321 } 318 }
322 uint8_t CFGAS_GEFont::GetCharSet() const { 319 uint8_t CFGAS_GEFont::GetCharSet() const {
323 if (m_wCharSet != 0xFFFF) { 320 if (m_wCharSet != 0xFFFF) {
324 return (uint8_t)m_wCharSet; 321 return (uint8_t)m_wCharSet;
325 } 322 }
326 if (!m_pFont->GetSubstFont()) { 323 if (!m_pFont->GetSubstFont()) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 } 356 }
360 if (m_pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_ITALIC) { 357 if (m_pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_ITALIC) {
361 dwStyles |= FX_FONTSTYLE_Italic; 358 dwStyles |= FX_FONTSTYLE_Italic;
362 } 359 }
363 } 360 }
364 return dwStyles; 361 return dwStyles;
365 } 362 }
366 FX_BOOL CFGAS_GEFont::GetCharWidth(FX_WCHAR wUnicode, 363 FX_BOOL CFGAS_GEFont::GetCharWidth(FX_WCHAR wUnicode,
367 int32_t& iWidth, 364 int32_t& iWidth,
368 FX_BOOL bCharCode) { 365 FX_BOOL bCharCode) {
369 return GetCharWidth(wUnicode, iWidth, TRUE, bCharCode); 366 return GetCharWidthInternal(wUnicode, iWidth, TRUE, bCharCode);
370 } 367 }
371 FX_BOOL CFGAS_GEFont::GetCharWidth(FX_WCHAR wUnicode, 368 FX_BOOL CFGAS_GEFont::GetCharWidthInternal(FX_WCHAR wUnicode,
372 int32_t& iWidth, 369 int32_t& iWidth,
373 FX_BOOL bRecursive, 370 FX_BOOL bRecursive,
374 FX_BOOL bCharCode) { 371 FX_BOOL bCharCode) {
375 ASSERT(m_pCharWidthMap != NULL); 372 ASSERT(m_pCharWidthMap != NULL);
376 iWidth = m_pCharWidthMap->GetAt(wUnicode, 0); 373 iWidth = m_pCharWidthMap->GetAt(wUnicode, 0);
377 if (iWidth < 1) { 374 if (iWidth < 1) {
378 if (!m_pProvider || 375 if (!m_pProvider ||
379 !m_pProvider->GetCharWidth(this, wUnicode, iWidth, bCharCode)) { 376 !m_pProvider->GetCharWidth(this, wUnicode, iWidth, bCharCode)) {
380 IFGAS_Font* pFont = NULL; 377 CFGAS_GEFont* pFont = NULL;
381 int32_t iGlyph = GetGlyphIndex(wUnicode, TRUE, &pFont, bCharCode); 378 int32_t iGlyph = GetGlyphIndex(wUnicode, TRUE, &pFont, bCharCode);
382 if (iGlyph != 0xFFFF && pFont != NULL) { 379 if (iGlyph != 0xFFFF && pFont != NULL) {
383 if (pFont == (IFGAS_Font*)this) { 380 if (pFont == this) {
384 iWidth = m_pFont->GetGlyphWidth(iGlyph); 381 iWidth = m_pFont->GetGlyphWidth(iGlyph);
385 if (iWidth < 0) { 382 if (iWidth < 0) {
386 iWidth = -1; 383 iWidth = -1;
387 } 384 }
388 } else if (((CFGAS_GEFont*)pFont) 385 } else if (pFont->GetCharWidthInternal(wUnicode, iWidth, FALSE,
389 ->GetCharWidth(wUnicode, iWidth, FALSE, bCharCode)) { 386 bCharCode)) {
390 return TRUE; 387 return TRUE;
391 } 388 }
392 } else { 389 } else {
393 iWidth = -1; 390 iWidth = -1;
394 } 391 }
395 } 392 }
396 m_pCharWidthMap->SetAtGrow(wUnicode, (int16_t)iWidth); 393 m_pCharWidthMap->SetAtGrow(wUnicode, (int16_t)iWidth);
397 } else if (iWidth == 65535) { 394 } else if (iWidth == 65535) {
398 iWidth = -1; 395 iWidth = -1;
399 } 396 }
400 return iWidth > 0; 397 return iWidth > 0;
401 } 398 }
402 FX_BOOL CFGAS_GEFont::GetCharBBox(FX_WCHAR wUnicode, 399 FX_BOOL CFGAS_GEFont::GetCharBBox(FX_WCHAR wUnicode,
403 CFX_Rect& bbox, 400 CFX_Rect& bbox,
404 FX_BOOL bCharCode) { 401 FX_BOOL bCharCode) {
405 return GetCharBBox(wUnicode, bbox, TRUE, bCharCode); 402 return GetCharBBoxInternal(wUnicode, bbox, TRUE, bCharCode);
406 } 403 }
407 FX_BOOL CFGAS_GEFont::GetCharBBox(FX_WCHAR wUnicode, 404 FX_BOOL CFGAS_GEFont::GetCharBBoxInternal(FX_WCHAR wUnicode,
408 CFX_Rect& bbox, 405 CFX_Rect& bbox,
409 FX_BOOL bRecursive, 406 FX_BOOL bRecursive,
410 FX_BOOL bCharCode) { 407 FX_BOOL bCharCode) {
411 ASSERT(m_pRectArray != NULL); 408 ASSERT(m_pRectArray != NULL);
412 ASSERT(m_pBBoxMap != NULL); 409 ASSERT(m_pBBoxMap != NULL);
413 void* pRect = NULL; 410 void* pRect = NULL;
414 if (!m_pBBoxMap->Lookup((void*)(uintptr_t)wUnicode, pRect)) { 411 if (!m_pBBoxMap->Lookup((void*)(uintptr_t)wUnicode, pRect)) {
415 IFGAS_Font* pFont = NULL; 412 CFGAS_GEFont* pFont = NULL;
416 int32_t iGlyph = GetGlyphIndex(wUnicode, TRUE, &pFont, bCharCode); 413 int32_t iGlyph = GetGlyphIndex(wUnicode, TRUE, &pFont, bCharCode);
417 if (iGlyph != 0xFFFF && pFont != NULL) { 414 if (iGlyph != 0xFFFF && pFont != NULL) {
418 if (pFont == (IFGAS_Font*)this) { 415 if (pFont == this) {
419 FX_RECT rtBBox; 416 FX_RECT rtBBox;
420 if (m_pFont->GetGlyphBBox(iGlyph, rtBBox)) { 417 if (m_pFont->GetGlyphBBox(iGlyph, rtBBox)) {
421 CFX_Rect rt; 418 CFX_Rect rt;
422 rt.Set(rtBBox.left, rtBBox.top, rtBBox.Width(), rtBBox.Height()); 419 rt.Set(rtBBox.left, rtBBox.top, rtBBox.Width(), rtBBox.Height());
423 int32_t index = m_pRectArray->Add(rt); 420 int32_t index = m_pRectArray->Add(rt);
424 pRect = m_pRectArray->GetPtrAt(index); 421 pRect = m_pRectArray->GetPtrAt(index);
425 m_pBBoxMap->SetAt((void*)(uintptr_t)wUnicode, pRect); 422 m_pBBoxMap->SetAt((void*)(uintptr_t)wUnicode, pRect);
426 } 423 }
427 } else if (((CFGAS_GEFont*)pFont) 424 } else if (pFont->GetCharBBoxInternal(wUnicode, bbox, FALSE, bCharCode)) {
428 ->GetCharBBox(wUnicode, bbox, FALSE, bCharCode)) {
429 return TRUE; 425 return TRUE;
430 } 426 }
431 } 427 }
432 } 428 }
433 if (!pRect) 429 if (!pRect)
434 return FALSE; 430 return FALSE;
435 431
436 bbox = *static_cast<const CFX_Rect*>(pRect); 432 bbox = *static_cast<const CFX_Rect*>(pRect);
437 return TRUE; 433 return TRUE;
438 } 434 }
(...skipping 12 matching lines...) Expand all
451 if (!m_pFont->GetSubstFont()) { 447 if (!m_pFont->GetSubstFont()) {
452 return 0; 448 return 0;
453 } 449 }
454 return m_pFont->GetSubstFont()->m_ItalicAngle; 450 return m_pFont->GetSubstFont()->m_ItalicAngle;
455 } 451 }
456 int32_t CFGAS_GEFont::GetGlyphIndex(FX_WCHAR wUnicode, FX_BOOL bCharCode) { 452 int32_t CFGAS_GEFont::GetGlyphIndex(FX_WCHAR wUnicode, FX_BOOL bCharCode) {
457 return GetGlyphIndex(wUnicode, TRUE, NULL, bCharCode); 453 return GetGlyphIndex(wUnicode, TRUE, NULL, bCharCode);
458 } 454 }
459 int32_t CFGAS_GEFont::GetGlyphIndex(FX_WCHAR wUnicode, 455 int32_t CFGAS_GEFont::GetGlyphIndex(FX_WCHAR wUnicode,
460 FX_BOOL bRecursive, 456 FX_BOOL bRecursive,
461 IFGAS_Font** ppFont, 457 CFGAS_GEFont** ppFont,
462 FX_BOOL bCharCode) { 458 FX_BOOL bCharCode) {
463 ASSERT(m_pFontEncoding != NULL); 459 ASSERT(m_pFontEncoding != NULL);
464 int32_t iGlyphIndex = m_pFontEncoding->GlyphFromCharCode(wUnicode); 460 int32_t iGlyphIndex = m_pFontEncoding->GlyphFromCharCode(wUnicode);
465 if (iGlyphIndex > 0) { 461 if (iGlyphIndex > 0) {
466 if (ppFont != NULL) { 462 if (ppFont != NULL) {
467 *ppFont = (IFGAS_Font*)this; 463 *ppFont = this;
468 } 464 }
469 return iGlyphIndex; 465 return iGlyphIndex;
470 } 466 }
471 const FGAS_FONTUSB* pFontUSB = FGAS_GetUnicodeBitField(wUnicode); 467 const FGAS_FONTUSB* pFontUSB = FGAS_GetUnicodeBitField(wUnicode);
472 if (pFontUSB == NULL) { 468 if (pFontUSB == NULL) {
473 return 0xFFFF; 469 return 0xFFFF;
474 } 470 }
475 uint16_t wBitField = pFontUSB->wBitField; 471 uint16_t wBitField = pFontUSB->wBitField;
476 if (wBitField >= 128) { 472 if (wBitField >= 128) {
477 return 0xFFFF; 473 return 0xFFFF;
478 } 474 }
479 auto it = m_FontMapper.find(wUnicode); 475 auto it = m_FontMapper.find(wUnicode);
480 IFGAS_Font* pFont = it != m_FontMapper.end() ? it->second : nullptr; 476 CFGAS_GEFont* pFont = it != m_FontMapper.end() ? it->second : nullptr;
481 if (pFont && pFont != this) { 477 if (pFont && pFont != this) {
482 iGlyphIndex = 478 iGlyphIndex = pFont->GetGlyphIndex(wUnicode, FALSE, NULL, bCharCode);
483 ((CFGAS_GEFont*)pFont)->GetGlyphIndex(wUnicode, FALSE, NULL, bCharCode);
484 if (iGlyphIndex != 0xFFFF) { 479 if (iGlyphIndex != 0xFFFF) {
485 int32_t i = m_SubstFonts.Find(pFont); 480 int32_t i = m_SubstFonts.Find(pFont);
486 if (i > -1) { 481 if (i > -1) {
487 iGlyphIndex |= ((i + 1) << 24); 482 iGlyphIndex |= ((i + 1) << 24);
488 if (ppFont) 483 if (ppFont)
489 *ppFont = pFont; 484 *ppFont = pFont;
490 return iGlyphIndex; 485 return iGlyphIndex;
491 } 486 }
492 } 487 }
493 } 488 }
494 if (m_pFontMgr && bRecursive) { 489 if (m_pFontMgr && bRecursive) {
495 CFX_WideString wsFamily; 490 CFX_WideString wsFamily;
496 GetFamilyName(wsFamily); 491 GetFamilyName(wsFamily);
497 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 492 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
498 pFont = m_pFontMgr->GetDefFontByUnicode(wUnicode, GetFontStyles(), 493 CFGAS_GEFont* pFont = m_pFontMgr->GetDefFontByUnicode(
499 wsFamily.c_str()); 494 wUnicode, GetFontStyles(), wsFamily.c_str());
500 #else 495 #else
501 pFont = m_pFontMgr->GetFontByUnicode(wUnicode, GetFontStyles(), 496 CFGAS_GEFont* pFont = m_pFontMgr->GetFontByUnicode(
502 wsFamily.c_str()); 497 wUnicode, GetFontStyles(), wsFamily.c_str());
503 if (!pFont) 498 if (!pFont)
504 pFont = m_pFontMgr->GetFontByUnicode(wUnicode, GetFontStyles(), NULL); 499 pFont = m_pFontMgr->GetFontByUnicode(wUnicode, GetFontStyles(), NULL);
505 #endif 500 #endif
506 if (pFont) { 501 if (pFont) {
507 if (pFont == this) { 502 if (pFont == this) {
508 pFont->Release(); 503 pFont->Release();
509 return 0xFFFF; 504 return 0xFFFF;
510 } 505 }
511 m_FontMapper[wUnicode] = pFont; 506 m_FontMapper[wUnicode] = pFont;
512 int32_t i = m_SubstFonts.GetSize(); 507 int32_t i = m_SubstFonts.GetSize();
513 m_SubstFonts.Add(pFont); 508 m_SubstFonts.Add(pFont);
514 iGlyphIndex = ((CFGAS_GEFont*)pFont) 509 iGlyphIndex = pFont->GetGlyphIndex(wUnicode, FALSE, NULL, bCharCode);
515 ->GetGlyphIndex(wUnicode, FALSE, NULL, bCharCode);
516 if (iGlyphIndex != 0xFFFF) { 510 if (iGlyphIndex != 0xFFFF) {
517 iGlyphIndex |= ((i + 1) << 24); 511 iGlyphIndex |= ((i + 1) << 24);
518 if (ppFont) 512 if (ppFont)
519 *ppFont = pFont; 513 *ppFont = pFont;
520 return iGlyphIndex; 514 return iGlyphIndex;
521 } 515 }
522 } 516 }
523 } 517 }
524 return 0xFFFF; 518 return 0xFFFF;
525 } 519 }
526 int32_t CFGAS_GEFont::GetAscent() const { 520 int32_t CFGAS_GEFont::GetAscent() const {
527 return m_pFont->GetAscent(); 521 return m_pFont->GetAscent();
528 } 522 }
529 int32_t CFGAS_GEFont::GetDescent() const { 523 int32_t CFGAS_GEFont::GetDescent() const {
530 return m_pFont->GetDescent(); 524 return m_pFont->GetDescent();
531 } 525 }
532 void CFGAS_GEFont::Reset() { 526 void CFGAS_GEFont::Reset() {
533 int32_t iCount = m_SubstFonts.GetSize(); 527 for (int32_t i = 0; i < m_SubstFonts.GetSize(); i++)
534 for (int32_t i = 0; i < iCount; i++) { 528 m_SubstFonts[i]->Reset();
535 IFGAS_Font* pFont = m_SubstFonts[i];
536 ((CFGAS_GEFont*)pFont)->Reset();
537 }
538 if (m_pCharWidthMap != NULL) { 529 if (m_pCharWidthMap != NULL) {
539 m_pCharWidthMap->RemoveAll(); 530 m_pCharWidthMap->RemoveAll();
540 } 531 }
541 if (m_pBBoxMap != NULL) { 532 if (m_pBBoxMap != NULL) {
542 m_pBBoxMap->RemoveAll(); 533 m_pBBoxMap->RemoveAll();
543 } 534 }
544 if (m_pRectArray != NULL) { 535 if (m_pRectArray != NULL) {
545 m_pRectArray->RemoveAll(); 536 m_pRectArray->RemoveAll();
546 } 537 }
547 } 538 }
548 IFGAS_Font* CFGAS_GEFont::GetSubstFont(int32_t iGlyphIndex) const { 539 CFGAS_GEFont* CFGAS_GEFont::GetSubstFont(int32_t iGlyphIndex) const {
549 iGlyphIndex = ((uint32_t)iGlyphIndex) >> 24; 540 iGlyphIndex = ((uint32_t)iGlyphIndex) >> 24;
550 return iGlyphIndex == 0 ? const_cast<CFGAS_GEFont*>(this) 541 return iGlyphIndex == 0 ? const_cast<CFGAS_GEFont*>(this)
551 : m_SubstFonts[iGlyphIndex - 1]; 542 : m_SubstFonts[iGlyphIndex - 1];
552 } 543 }
OLDNEW
« no previous file with comments | « xfa/fgas/font/fgas_gefont.h ('k') | xfa/fgas/font/fgas_stdfontmgr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698