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

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: Fix Windows 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
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 IFX_Font* IFX_Font::LoadFont(const FX_WCHAR* pszFontFamily, 13 // static
14 uint32_t dwFontStyles, 14 CFX_GEFont* CFX_GEFont::LoadFont(const FX_WCHAR* pszFontFamily,
15 uint16_t wCodePage, 15 uint32_t dwFontStyles,
16 IFX_FontMgr* pFontMgr) { 16 uint16_t wCodePage,
17 IFX_FontMgr* pFontMgr) {
17 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ 18 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
18 if (NULL != pFontMgr) { 19 if (NULL != pFontMgr) {
dsinclair 2016/06/02 17:37:38 nit: if (pFontMgr)
Lei Zhang 2016/06/07 01:17:16 I have a separate set of CLs to kill off NULLs.
19 return pFontMgr->GetFontByCodePage(wCodePage, dwFontStyles, pszFontFamily); 20 return pFontMgr->GetFontByCodePage(wCodePage, dwFontStyles, pszFontFamily);
20 } 21 }
21 return NULL; 22 return NULL;
dsinclair 2016/06/02 17:37:39 nit: nullptr's in various places
22 #else 23 #else
23 CFX_GEFont* pFont = new CFX_GEFont(pFontMgr); 24 CFX_GEFont* pFont = new CFX_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 IFX_Font* IFX_Font::LoadFont(const uint8_t* pBuffer, 32
32 int32_t iLength, 33 // static
33 IFX_FontMgr* pFontMgr) { 34 CFX_GEFont* CFX_GEFont::LoadFont(CFX_Font* pExtFont,
34 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ 35 IFX_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 CFX_GEFont* pFont = new CFX_GEFont(pFontMgr);
41 if (!pFont->LoadFont(pBuffer, iLength)) {
42 pFont->Release();
43 return NULL;
44 }
45 return pFont;
46 #endif
47 }
48 IFX_Font* IFX_Font::LoadFont(const FX_WCHAR* pszFileName,
49 IFX_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 CFX_GEFont* pFont = new CFX_GEFont(pFontMgr);
57 if (!pFont->LoadFont(pszFileName)) {
58 pFont->Release();
59 return NULL;
60 }
61 return pFont;
62 #endif
63 }
64 IFX_Font* IFX_Font::LoadFont(IFX_Stream* pFontStream,
65 IFX_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 CFX_GEFont* pFont = new CFX_GEFont(pFontMgr);
74 if (!pFont->LoadFont(pFontStream, bSaveStream)) {
75 pFont->Release();
76 return NULL;
77 }
78 return pFont;
79 #endif
80 }
81 IFX_Font* IFX_Font::LoadFont(CFX_Font* pExtFont,
82 IFX_FontMgr* pFontMgr,
83 FX_BOOL bTakeOver) {
84 CFX_GEFont* pFont = new CFX_GEFont(pFontMgr); 37 CFX_GEFont* pFont = new CFX_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 }
44
45 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
46 // static
47 CFX_GEFont* CFX_GEFont::LoadFont(const uint8_t* pBuffer,
48 int32_t iLength,
49 IFX_FontMgr* pFontMgr) {
50 CFX_GEFont* pFont = new CFX_GEFont(pFontMgr);
51 if (!pFont->LoadFont(pBuffer, iLength)) {
52 pFont->Release();
53 return nullptr;
54 }
55 return pFont;
56 }
57
58 // static
59 CFX_GEFont* CFX_GEFont::LoadFont(const FX_WCHAR* pszFileName) {
60 CFX_GEFont* pFont = new CFX_GEFont(nullptr);
61 if (!pFont->LoadFontInternal(pszFileName)) {
62 pFont->Release();
63 return nullptr;
64 }
65 return pFont;
66 }
67
68 // static
69 CFX_GEFont* CFX_GEFont::LoadFont(IFX_Stream* pFontStream,
70 IFX_FontMgr* pFontMgr,
71 FX_BOOL bSaveStream) {
72 CFX_GEFont* pFont = new CFX_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
91 CFX_GEFont::CFX_GEFont(IFX_FontMgr* pFontMgr) 81 CFX_GEFont::CFX_GEFont(IFX_FontMgr* pFontMgr)
92 : 82 :
93 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ 83 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
94 m_bUseLogFontStyle(FALSE), 84 m_bUseLogFontStyle(FALSE),
95 m_dwLogFontStyle(0), 85 m_dwLogFontStyle(0),
96 #endif 86 #endif
97 m_pFont(NULL), 87 m_pFont(NULL),
98 m_pFontMgr(pFontMgr), 88 m_pFontMgr(pFontMgr),
99 m_iRefCount(1), 89 m_iRefCount(1),
100 m_bExtFont(FALSE), 90 m_bExtFont(FALSE),
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 } 153 }
164 154
165 void CFX_GEFont::Release() { 155 void CFX_GEFont::Release() {
166 if (--m_iRefCount < 1) { 156 if (--m_iRefCount < 1) {
167 if (m_pFontMgr != NULL) { 157 if (m_pFontMgr != NULL) {
168 m_pFontMgr->RemoveFont(this); 158 m_pFontMgr->RemoveFont(this);
169 } 159 }
170 delete this; 160 delete this;
171 } 161 }
172 } 162 }
173 IFX_Font* CFX_GEFont::Retain() { 163 CFX_GEFont* CFX_GEFont::Retain() {
174 ++m_iRefCount; 164 ++m_iRefCount;
175 return this; 165 return this;
176 } 166 }
167
168 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
177 FX_BOOL CFX_GEFont::LoadFont(const FX_WCHAR* pszFontFamily, 169 FX_BOOL CFX_GEFont::LoadFont(const FX_WCHAR* pszFontFamily,
178 uint32_t dwFontStyles, 170 uint32_t dwFontStyles,
179 uint16_t wCodePage) { 171 uint16_t wCodePage) {
180 if (m_pFont) { 172 if (m_pFont) {
181 return FALSE; 173 return FALSE;
182 } 174 }
183 CFX_ByteString csFontFamily; 175 CFX_ByteString csFontFamily;
184 if (pszFontFamily != NULL) { 176 if (pszFontFamily != NULL) {
185 csFontFamily = CFX_ByteString::FromUnicode(pszFontFamily); 177 csFontFamily = CFX_ByteString::FromUnicode(pszFontFamily);
186 } 178 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 } else if (dwFlags & FXFONT_ITALIC) { 213 } else if (dwFlags & FXFONT_ITALIC) {
222 csFontFamily += ",Italic"; 214 csFontFamily += ",Italic";
223 } 215 }
224 m_pFont->LoadSubst(csFontFamily, TRUE, dwFlags, iWeight, 0, wCodePage); 216 m_pFont->LoadSubst(csFontFamily, TRUE, dwFlags, iWeight, 0, wCodePage);
225 FX_BOOL bRet = m_pFont->GetFace() != nullptr; 217 FX_BOOL bRet = m_pFont->GetFace() != nullptr;
226 if (bRet) { 218 if (bRet) {
227 bRet = InitFont(); 219 bRet = InitFont();
228 } 220 }
229 return bRet; 221 return bRet;
230 } 222 }
223
231 FX_BOOL CFX_GEFont::LoadFont(const uint8_t* pBuffer, int32_t length) { 224 FX_BOOL CFX_GEFont::LoadFont(const uint8_t* pBuffer, int32_t length) {
232 if (m_pFont) { 225 if (m_pFont) {
233 return FALSE; 226 return FALSE;
234 } 227 }
235 m_pFont = new CFX_Font; 228 m_pFont = new CFX_Font;
236 FX_BOOL bRet = m_pFont->LoadEmbedded(pBuffer, length); 229 FX_BOOL bRet = m_pFont->LoadEmbedded(pBuffer, length);
237 if (bRet) { 230 if (bRet) {
238 bRet = InitFont(); 231 bRet = InitFont();
239 } 232 }
240 m_wCharSet = 0xFFFF; 233 m_wCharSet = 0xFFFF;
241 return bRet; 234 return bRet;
242 } 235 }
243 FX_BOOL CFX_GEFont::LoadFont(const FX_WCHAR* pszFileName) { 236
237 FX_BOOL CFX_GEFont::LoadFontInternal(const FX_WCHAR* pszFileName) {
244 if (m_pFont || m_pStream || m_pFileRead) { 238 if (m_pFont || m_pStream || m_pFileRead) {
245 return FALSE; 239 return FALSE;
246 } 240 }
247 m_pStream = IFX_Stream::CreateStream( 241 m_pStream = IFX_Stream::CreateStream(
248 pszFileName, FX_STREAMACCESS_Binary | FX_STREAMACCESS_Read); 242 pszFileName, FX_STREAMACCESS_Binary | FX_STREAMACCESS_Read);
249 m_pFileRead = FX_CreateFileRead(m_pStream); 243 m_pFileRead = FX_CreateFileRead(m_pStream);
250 FX_BOOL bRet = FALSE; 244 FX_BOOL bRet = FALSE;
251 if (m_pStream && m_pFileRead) { 245 if (m_pStream && m_pFileRead) {
252 m_pFont = new CFX_Font; 246 m_pFont = new CFX_Font;
253 bRet = m_pFont->LoadFile(m_pFileRead); 247 bRet = m_pFont->LoadFile(m_pFileRead);
254 if (bRet) { 248 if (bRet) {
255 bRet = InitFont(); 249 bRet = InitFont();
256 } else { 250 } else {
257 m_pFileRead->Release(); 251 m_pFileRead->Release();
258 m_pFileRead = nullptr; 252 m_pFileRead = nullptr;
259 } 253 }
260 } 254 }
261 m_wCharSet = 0xFFFF; 255 m_wCharSet = 0xFFFF;
262 return bRet; 256 return bRet;
263 } 257 }
258
264 FX_BOOL CFX_GEFont::LoadFont(IFX_Stream* pFontStream, FX_BOOL bSaveStream) { 259 FX_BOOL CFX_GEFont::LoadFont(IFX_Stream* pFontStream, FX_BOOL bSaveStream) {
265 if (m_pFont || m_pFileRead || !pFontStream || pFontStream->GetLength() < 1) { 260 if (m_pFont || m_pFileRead || !pFontStream || pFontStream->GetLength() < 1) {
266 return FALSE; 261 return FALSE;
267 } 262 }
268 if (bSaveStream) { 263 if (bSaveStream) {
269 m_pStream = pFontStream; 264 m_pStream = pFontStream;
270 } 265 }
271 m_pFileRead = FX_CreateFileRead(pFontStream); 266 m_pFileRead = FX_CreateFileRead(pFontStream);
272 m_pFont = new CFX_Font; 267 m_pFont = new CFX_Font;
273 FX_BOOL bRet = m_pFont->LoadFile(m_pFileRead); 268 FX_BOOL bRet = m_pFont->LoadFile(m_pFileRead);
274 if (bRet) { 269 if (bRet) {
275 bRet = InitFont(); 270 bRet = InitFont();
276 } else { 271 } else {
277 m_pFileRead->Release(); 272 m_pFileRead->Release();
278 m_pFileRead = nullptr; 273 m_pFileRead = nullptr;
279 } 274 }
280 m_wCharSet = 0xFFFF; 275 m_wCharSet = 0xFFFF;
281 return bRet; 276 return bRet;
282 } 277 }
278 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
279
283 FX_BOOL CFX_GEFont::LoadFont(CFX_Font* pExtFont, FX_BOOL bTakeOver) { 280 FX_BOOL CFX_GEFont::LoadFont(CFX_Font* pExtFont, FX_BOOL bTakeOver) {
284 if (m_pFont || !pExtFont) { 281 if (m_pFont || !pExtFont) {
285 return FALSE; 282 return FALSE;
286 } 283 }
287 m_pFont = pExtFont; 284 m_pFont = pExtFont;
288 FX_BOOL bRet = !!m_pFont; 285 FX_BOOL bRet = !!m_pFont;
289 if (bRet) { 286 if (bRet) {
290 m_bExtFont = !bTakeOver; 287 m_bExtFont = !bTakeOver;
291 bRet = InitFont(); 288 bRet = InitFont();
292 } else { 289 } else {
293 m_bExtFont = TRUE; 290 m_bExtFont = TRUE;
294 } 291 }
295 m_wCharSet = 0xFFFF; 292 m_wCharSet = 0xFFFF;
296 return bRet; 293 return bRet;
297 } 294 }
295
298 FX_BOOL CFX_GEFont::InitFont() { 296 FX_BOOL CFX_GEFont::InitFont() {
299 if (!m_pFont) 297 if (!m_pFont)
300 return FALSE; 298 return FALSE;
301 if (!m_pFontEncoding) { 299 if (!m_pFontEncoding) {
302 m_pFontEncoding = FX_CreateFontEncodingEx(m_pFont); 300 m_pFontEncoding = FX_CreateFontEncodingEx(m_pFont);
303 if (!m_pFontEncoding) 301 if (!m_pFontEncoding)
304 return FALSE; 302 return FALSE;
305 } 303 }
306 if (!m_pCharWidthMap) 304 if (!m_pCharWidthMap)
307 m_pCharWidthMap = new CFX_WordDiscreteArray(1024); 305 m_pCharWidthMap = new CFX_WordDiscreteArray(1024);
308 if (!m_pRectArray) 306 if (!m_pRectArray)
309 m_pRectArray = new CFX_MassArrayTemplate<CFX_Rect>(16); 307 m_pRectArray = new CFX_MassArrayTemplate<CFX_Rect>(16);
310 if (!m_pBBoxMap) 308 if (!m_pBBoxMap)
311 m_pBBoxMap = new CFX_MapPtrToPtr(16); 309 m_pBBoxMap = new CFX_MapPtrToPtr(16);
312 310
313 return TRUE; 311 return TRUE;
314 } 312 }
315 IFX_Font* CFX_GEFont::Derive(uint32_t dwFontStyles, uint16_t wCodePage) { 313 CFX_GEFont* CFX_GEFont::Derive(uint32_t dwFontStyles, uint16_t wCodePage) {
316 if (GetFontStyles() == dwFontStyles) { 314 if (GetFontStyles() == dwFontStyles) {
317 return Retain(); 315 return Retain();
318 } 316 }
319 return new CFX_GEFont(*this, dwFontStyles); 317 return new CFX_GEFont(*this, dwFontStyles);
320 } 318 }
321 uint8_t CFX_GEFont::GetCharSet() const { 319 uint8_t CFX_GEFont::GetCharSet() const {
322 if (m_wCharSet != 0xFFFF) { 320 if (m_wCharSet != 0xFFFF) {
323 return (uint8_t)m_wCharSet; 321 return (uint8_t)m_wCharSet;
324 } 322 }
325 if (!m_pFont->GetSubstFont()) { 323 if (!m_pFont->GetSubstFont()) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 } 356 }
359 if (m_pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_ITALIC) { 357 if (m_pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_ITALIC) {
360 dwStyles |= FX_FONTSTYLE_Italic; 358 dwStyles |= FX_FONTSTYLE_Italic;
361 } 359 }
362 } 360 }
363 return dwStyles; 361 return dwStyles;
364 } 362 }
365 FX_BOOL CFX_GEFont::GetCharWidth(FX_WCHAR wUnicode, 363 FX_BOOL CFX_GEFont::GetCharWidth(FX_WCHAR wUnicode,
366 int32_t& iWidth, 364 int32_t& iWidth,
367 FX_BOOL bCharCode) { 365 FX_BOOL bCharCode) {
368 return GetCharWidth(wUnicode, iWidth, TRUE, bCharCode); 366 return GetCharWidthInternal(wUnicode, iWidth, TRUE, bCharCode);
369 } 367 }
370 FX_BOOL CFX_GEFont::GetCharWidth(FX_WCHAR wUnicode, 368 FX_BOOL CFX_GEFont::GetCharWidthInternal(FX_WCHAR wUnicode,
371 int32_t& iWidth, 369 int32_t& iWidth,
372 FX_BOOL bRecursive, 370 FX_BOOL bRecursive,
373 FX_BOOL bCharCode) { 371 FX_BOOL bCharCode) {
374 ASSERT(m_pCharWidthMap != NULL); 372 ASSERT(m_pCharWidthMap != NULL);
375 iWidth = m_pCharWidthMap->GetAt(wUnicode, 0); 373 iWidth = m_pCharWidthMap->GetAt(wUnicode, 0);
376 if (iWidth < 1) { 374 if (iWidth < 1) {
377 if (!m_pProvider || 375 if (!m_pProvider ||
378 !m_pProvider->GetCharWidth(this, wUnicode, iWidth, bCharCode)) { 376 !m_pProvider->GetCharWidth(this, wUnicode, iWidth, bCharCode)) {
379 IFX_Font* pFont = NULL; 377 CFX_GEFont* pFont = NULL;
380 int32_t iGlyph = GetGlyphIndex(wUnicode, TRUE, &pFont, bCharCode); 378 int32_t iGlyph = GetGlyphIndex(wUnicode, TRUE, &pFont, bCharCode);
381 if (iGlyph != 0xFFFF && pFont != NULL) { 379 if (iGlyph != 0xFFFF && pFont != NULL) {
382 if (pFont == (IFX_Font*)this) { 380 if (pFont == this) {
383 iWidth = m_pFont->GetGlyphWidth(iGlyph); 381 iWidth = m_pFont->GetGlyphWidth(iGlyph);
384 if (iWidth < 0) { 382 if (iWidth < 0) {
385 iWidth = -1; 383 iWidth = -1;
386 } 384 }
387 } else if (((CFX_GEFont*)pFont) 385 } else if (pFont->GetCharWidthInternal(wUnicode, iWidth, FALSE,
388 ->GetCharWidth(wUnicode, iWidth, FALSE, bCharCode)) { 386 bCharCode)) {
389 return TRUE; 387 return TRUE;
390 } 388 }
391 } else { 389 } else {
392 iWidth = -1; 390 iWidth = -1;
393 } 391 }
394 } 392 }
395 m_pCharWidthMap->SetAtGrow(wUnicode, (int16_t)iWidth); 393 m_pCharWidthMap->SetAtGrow(wUnicode, (int16_t)iWidth);
396 } else if (iWidth == 65535) { 394 } else if (iWidth == 65535) {
397 iWidth = -1; 395 iWidth = -1;
398 } 396 }
399 return iWidth > 0; 397 return iWidth > 0;
400 } 398 }
401 FX_BOOL CFX_GEFont::GetCharBBox(FX_WCHAR wUnicode, 399 FX_BOOL CFX_GEFont::GetCharBBox(FX_WCHAR wUnicode,
402 CFX_Rect& bbox, 400 CFX_Rect& bbox,
403 FX_BOOL bCharCode) { 401 FX_BOOL bCharCode) {
404 return GetCharBBox(wUnicode, bbox, TRUE, bCharCode); 402 return GetCharBBoxInternal(wUnicode, bbox, TRUE, bCharCode);
405 } 403 }
406 FX_BOOL CFX_GEFont::GetCharBBox(FX_WCHAR wUnicode, 404 FX_BOOL CFX_GEFont::GetCharBBoxInternal(FX_WCHAR wUnicode,
407 CFX_Rect& bbox, 405 CFX_Rect& bbox,
408 FX_BOOL bRecursive, 406 FX_BOOL bRecursive,
409 FX_BOOL bCharCode) { 407 FX_BOOL bCharCode) {
410 ASSERT(m_pRectArray != NULL); 408 ASSERT(m_pRectArray != NULL);
411 ASSERT(m_pBBoxMap != NULL); 409 ASSERT(m_pBBoxMap != NULL);
412 void* pRect = NULL; 410 void* pRect = NULL;
413 if (!m_pBBoxMap->Lookup((void*)(uintptr_t)wUnicode, pRect)) { 411 if (!m_pBBoxMap->Lookup((void*)(uintptr_t)wUnicode, pRect)) {
414 IFX_Font* pFont = NULL; 412 CFX_GEFont* pFont = NULL;
415 int32_t iGlyph = GetGlyphIndex(wUnicode, TRUE, &pFont, bCharCode); 413 int32_t iGlyph = GetGlyphIndex(wUnicode, TRUE, &pFont, bCharCode);
416 if (iGlyph != 0xFFFF && pFont != NULL) { 414 if (iGlyph != 0xFFFF && pFont != NULL) {
417 if (pFont == (IFX_Font*)this) { 415 if (pFont == this) {
418 FX_RECT rtBBox; 416 FX_RECT rtBBox;
419 if (m_pFont->GetGlyphBBox(iGlyph, rtBBox)) { 417 if (m_pFont->GetGlyphBBox(iGlyph, rtBBox)) {
420 CFX_Rect rt; 418 CFX_Rect rt;
421 rt.Set(rtBBox.left, rtBBox.top, rtBBox.Width(), rtBBox.Height()); 419 rt.Set(rtBBox.left, rtBBox.top, rtBBox.Width(), rtBBox.Height());
422 int32_t index = m_pRectArray->Add(rt); 420 int32_t index = m_pRectArray->Add(rt);
423 pRect = m_pRectArray->GetPtrAt(index); 421 pRect = m_pRectArray->GetPtrAt(index);
424 m_pBBoxMap->SetAt((void*)(uintptr_t)wUnicode, pRect); 422 m_pBBoxMap->SetAt((void*)(uintptr_t)wUnicode, pRect);
425 } 423 }
426 } else if (((CFX_GEFont*)pFont) 424 } else if (pFont->GetCharBBoxInternal(wUnicode, bbox, FALSE, bCharCode)) {
427 ->GetCharBBox(wUnicode, bbox, FALSE, bCharCode)) {
428 return TRUE; 425 return TRUE;
429 } 426 }
430 } 427 }
431 } 428 }
432 if (!pRect) 429 if (!pRect)
433 return FALSE; 430 return FALSE;
434 431
435 bbox = *static_cast<const CFX_Rect*>(pRect); 432 bbox = *static_cast<const CFX_Rect*>(pRect);
436 return TRUE; 433 return TRUE;
437 } 434 }
(...skipping 12 matching lines...) Expand all
450 if (!m_pFont->GetSubstFont()) { 447 if (!m_pFont->GetSubstFont()) {
451 return 0; 448 return 0;
452 } 449 }
453 return m_pFont->GetSubstFont()->m_ItalicAngle; 450 return m_pFont->GetSubstFont()->m_ItalicAngle;
454 } 451 }
455 int32_t CFX_GEFont::GetGlyphIndex(FX_WCHAR wUnicode, FX_BOOL bCharCode) { 452 int32_t CFX_GEFont::GetGlyphIndex(FX_WCHAR wUnicode, FX_BOOL bCharCode) {
456 return GetGlyphIndex(wUnicode, TRUE, NULL, bCharCode); 453 return GetGlyphIndex(wUnicode, TRUE, NULL, bCharCode);
457 } 454 }
458 int32_t CFX_GEFont::GetGlyphIndex(FX_WCHAR wUnicode, 455 int32_t CFX_GEFont::GetGlyphIndex(FX_WCHAR wUnicode,
459 FX_BOOL bRecursive, 456 FX_BOOL bRecursive,
460 IFX_Font** ppFont, 457 CFX_GEFont** ppFont,
461 FX_BOOL bCharCode) { 458 FX_BOOL bCharCode) {
462 ASSERT(m_pFontEncoding != NULL); 459 ASSERT(m_pFontEncoding != NULL);
463 int32_t iGlyphIndex = m_pFontEncoding->GlyphFromCharCode(wUnicode); 460 int32_t iGlyphIndex = m_pFontEncoding->GlyphFromCharCode(wUnicode);
464 if (iGlyphIndex > 0) { 461 if (iGlyphIndex > 0) {
465 if (ppFont != NULL) { 462 if (ppFont != NULL) {
466 *ppFont = (IFX_Font*)this; 463 *ppFont = this;
467 } 464 }
468 return iGlyphIndex; 465 return iGlyphIndex;
469 } 466 }
470 const FGAS_FONTUSB* pFontUSB = FGAS_GetUnicodeBitField(wUnicode); 467 const FGAS_FONTUSB* pFontUSB = FGAS_GetUnicodeBitField(wUnicode);
471 if (pFontUSB == NULL) { 468 if (pFontUSB == NULL) {
472 return 0xFFFF; 469 return 0xFFFF;
473 } 470 }
474 uint16_t wBitField = pFontUSB->wBitField; 471 uint16_t wBitField = pFontUSB->wBitField;
475 if (wBitField >= 128) { 472 if (wBitField >= 128) {
476 return 0xFFFF; 473 return 0xFFFF;
477 } 474 }
478 auto it = m_FontMapper.find(wUnicode); 475 auto it = m_FontMapper.find(wUnicode);
479 IFX_Font* pFont = it != m_FontMapper.end() ? it->second : nullptr; 476 CFX_GEFont* pFont = it != m_FontMapper.end() ? it->second : nullptr;
480 if (pFont && pFont != this) { 477 if (pFont && pFont != this) {
481 iGlyphIndex = 478 iGlyphIndex = pFont->GetGlyphIndex(wUnicode, FALSE, NULL, bCharCode);
482 ((CFX_GEFont*)pFont)->GetGlyphIndex(wUnicode, FALSE, NULL, bCharCode);
483 if (iGlyphIndex != 0xFFFF) { 479 if (iGlyphIndex != 0xFFFF) {
484 int32_t i = m_SubstFonts.Find(pFont); 480 int32_t i = m_SubstFonts.Find(pFont);
485 if (i > -1) { 481 if (i > -1) {
486 iGlyphIndex |= ((i + 1) << 24); 482 iGlyphIndex |= ((i + 1) << 24);
487 if (ppFont) 483 if (ppFont)
488 *ppFont = pFont; 484 *ppFont = pFont;
489 return iGlyphIndex; 485 return iGlyphIndex;
490 } 486 }
491 } 487 }
492 } 488 }
493 if (m_pFontMgr && bRecursive) { 489 if (m_pFontMgr && bRecursive) {
494 CFX_WideString wsFamily; 490 CFX_WideString wsFamily;
495 GetFamilyName(wsFamily); 491 GetFamilyName(wsFamily);
496 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 492 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
497 IFX_Font* pFont = m_pFontMgr->GetDefFontByUnicode(wUnicode, GetFontStyles(), 493 CFX_GEFont* pFont = m_pFontMgr->GetDefFontByUnicode(
498 wsFamily.c_str()); 494 wUnicode, GetFontStyles(), wsFamily.c_str());
499 #else 495 #else
500 IFX_Font* pFont = m_pFontMgr->GetFontByUnicode(wUnicode, GetFontStyles(), 496 CFX_GEFont* pFont = m_pFontMgr->GetFontByUnicode(wUnicode, GetFontStyles(),
501 wsFamily.c_str()); 497 wsFamily.c_str());
502 if (!pFont) 498 if (!pFont)
503 pFont = m_pFontMgr->GetFontByUnicode(wUnicode, GetFontStyles(), NULL); 499 pFont = m_pFontMgr->GetFontByUnicode(wUnicode, GetFontStyles(), NULL);
504 #endif 500 #endif
505 if (pFont) { 501 if (pFont) {
506 if (pFont == this) { 502 if (pFont == this) {
507 pFont->Release(); 503 pFont->Release();
508 return 0xFFFF; 504 return 0xFFFF;
509 } 505 }
510 m_FontMapper[wUnicode] = pFont; 506 m_FontMapper[wUnicode] = pFont;
511 int32_t i = m_SubstFonts.GetSize(); 507 int32_t i = m_SubstFonts.GetSize();
512 m_SubstFonts.Add(pFont); 508 m_SubstFonts.Add(pFont);
513 iGlyphIndex = 509 iGlyphIndex = pFont->GetGlyphIndex(wUnicode, FALSE, NULL, bCharCode);
514 ((CFX_GEFont*)pFont)->GetGlyphIndex(wUnicode, FALSE, NULL, bCharCode);
515 if (iGlyphIndex != 0xFFFF) { 510 if (iGlyphIndex != 0xFFFF) {
516 iGlyphIndex |= ((i + 1) << 24); 511 iGlyphIndex |= ((i + 1) << 24);
517 if (ppFont) 512 if (ppFont)
518 *ppFont = pFont; 513 *ppFont = pFont;
519 return iGlyphIndex; 514 return iGlyphIndex;
520 } 515 }
521 } 516 }
522 } 517 }
523 return 0xFFFF; 518 return 0xFFFF;
524 } 519 }
525 int32_t CFX_GEFont::GetAscent() const { 520 int32_t CFX_GEFont::GetAscent() const {
526 return m_pFont->GetAscent(); 521 return m_pFont->GetAscent();
527 } 522 }
528 int32_t CFX_GEFont::GetDescent() const { 523 int32_t CFX_GEFont::GetDescent() const {
529 return m_pFont->GetDescent(); 524 return m_pFont->GetDescent();
530 } 525 }
531 void CFX_GEFont::Reset() { 526 void CFX_GEFont::Reset() {
532 int32_t iCount = m_SubstFonts.GetSize(); 527 for (int32_t i = 0; i < m_SubstFonts.GetSize(); i++)
533 for (int32_t i = 0; i < iCount; i++) { 528 m_SubstFonts[i]->Reset();
534 IFX_Font* pFont = m_SubstFonts[i];
535 ((CFX_GEFont*)pFont)->Reset();
536 }
537 if (m_pCharWidthMap != NULL) { 529 if (m_pCharWidthMap != NULL) {
538 m_pCharWidthMap->RemoveAll(); 530 m_pCharWidthMap->RemoveAll();
539 } 531 }
540 if (m_pBBoxMap != NULL) { 532 if (m_pBBoxMap != NULL) {
541 m_pBBoxMap->RemoveAll(); 533 m_pBBoxMap->RemoveAll();
542 } 534 }
543 if (m_pRectArray != NULL) { 535 if (m_pRectArray != NULL) {
544 m_pRectArray->RemoveAll(); 536 m_pRectArray->RemoveAll();
545 } 537 }
546 } 538 }
547 IFX_Font* CFX_GEFont::GetSubstFont(int32_t iGlyphIndex) const { 539 CFX_GEFont* CFX_GEFont::GetSubstFont(int32_t iGlyphIndex) const {
548 iGlyphIndex = ((uint32_t)iGlyphIndex) >> 24; 540 iGlyphIndex = ((uint32_t)iGlyphIndex) >> 24;
549 return iGlyphIndex == 0 ? const_cast<CFX_GEFont*>(this) 541 return iGlyphIndex == 0 ? const_cast<CFX_GEFont*>(this)
550 : m_SubstFonts[iGlyphIndex - 1]; 542 : m_SubstFonts[iGlyphIndex - 1];
551 } 543 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698