| OLD | NEW |
| 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 // static | 13 // static |
| 14 CFGAS_GEFont* CFGAS_GEFont::LoadFont(const FX_WCHAR* pszFontFamily, | 14 CFGAS_GEFont* CFGAS_GEFont::LoadFont(const FX_WCHAR* pszFontFamily, |
| 15 uint32_t dwFontStyles, | 15 uint32_t dwFontStyles, |
| 16 uint16_t wCodePage, | 16 uint16_t wCodePage, |
| 17 IFGAS_FontMgr* pFontMgr) { | 17 IFGAS_FontMgr* pFontMgr) { |
| 18 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 18 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
| 19 if (NULL != pFontMgr) { | 19 if (pFontMgr) { |
| 20 return pFontMgr->GetFontByCodePage(wCodePage, dwFontStyles, pszFontFamily); | 20 return pFontMgr->GetFontByCodePage(wCodePage, dwFontStyles, pszFontFamily); |
| 21 } | 21 } |
| 22 return NULL; | 22 return nullptr; |
| 23 #else | 23 #else |
| 24 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); | 24 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); |
| 25 if (!pFont->LoadFontInternal(pszFontFamily, dwFontStyles, wCodePage)) { | 25 if (!pFont->LoadFontInternal(pszFontFamily, dwFontStyles, wCodePage)) { |
| 26 pFont->Release(); | 26 pFont->Release(); |
| 27 return NULL; | 27 return nullptr; |
| 28 } | 28 } |
| 29 return pFont; | 29 return pFont; |
| 30 #endif | 30 #endif |
| 31 } | 31 } |
| 32 | 32 |
| 33 // static | 33 // static |
| 34 CFGAS_GEFont* CFGAS_GEFont::LoadFont(CFX_Font* pExtFont, | 34 CFGAS_GEFont* CFGAS_GEFont::LoadFont(CFX_Font* pExtFont, |
| 35 IFGAS_FontMgr* pFontMgr) { | 35 IFGAS_FontMgr* pFontMgr) { |
| 36 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); | 36 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); |
| 37 if (!pFont->LoadFontInternal(pExtFont)) { | 37 if (!pFont->LoadFontInternal(pExtFont)) { |
| 38 pFont->Release(); | 38 pFont->Release(); |
| 39 return NULL; | 39 return nullptr; |
| 40 } | 40 } |
| 41 return pFont; | 41 return pFont; |
| 42 } | 42 } |
| 43 | 43 |
| 44 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 44 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 45 // static | 45 // static |
| 46 CFGAS_GEFont* CFGAS_GEFont::LoadFont(const uint8_t* pBuffer, | 46 CFGAS_GEFont* CFGAS_GEFont::LoadFont(const uint8_t* pBuffer, |
| 47 int32_t iLength, | 47 int32_t iLength, |
| 48 IFGAS_FontMgr* pFontMgr) { | 48 IFGAS_FontMgr* pFontMgr) { |
| 49 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); | 49 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 66 return pFont; | 66 return pFont; |
| 67 } | 67 } |
| 68 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 68 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 69 | 69 |
| 70 CFGAS_GEFont::CFGAS_GEFont(IFGAS_FontMgr* pFontMgr) | 70 CFGAS_GEFont::CFGAS_GEFont(IFGAS_FontMgr* pFontMgr) |
| 71 : | 71 : |
| 72 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 72 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
| 73 m_bUseLogFontStyle(FALSE), | 73 m_bUseLogFontStyle(FALSE), |
| 74 m_dwLogFontStyle(0), | 74 m_dwLogFontStyle(0), |
| 75 #endif | 75 #endif |
| 76 m_pFont(NULL), | 76 m_pFont(nullptr), |
| 77 m_pFontMgr(pFontMgr), | 77 m_pFontMgr(pFontMgr), |
| 78 m_iRefCount(1), | 78 m_iRefCount(1), |
| 79 m_bExtFont(FALSE), | 79 m_bExtFont(FALSE), |
| 80 m_pStream(NULL), | 80 m_pStream(nullptr), |
| 81 m_pFileRead(NULL), | 81 m_pFileRead(nullptr), |
| 82 m_pFontEncoding(NULL), | 82 m_pFontEncoding(nullptr), |
| 83 m_pCharWidthMap(NULL), | 83 m_pCharWidthMap(nullptr), |
| 84 m_pRectArray(NULL), | 84 m_pRectArray(nullptr), |
| 85 m_pBBoxMap(NULL), | 85 m_pBBoxMap(nullptr), |
| 86 m_pProvider(NULL) { | 86 m_pProvider(nullptr) { |
| 87 } | 87 } |
| 88 | 88 |
| 89 CFGAS_GEFont::CFGAS_GEFont(const CFGAS_GEFont& src, uint32_t dwFontStyles) | 89 CFGAS_GEFont::CFGAS_GEFont(const CFGAS_GEFont& src, uint32_t dwFontStyles) |
| 90 : | 90 : |
| 91 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 91 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
| 92 m_bUseLogFontStyle(FALSE), | 92 m_bUseLogFontStyle(FALSE), |
| 93 m_dwLogFontStyle(0), | 93 m_dwLogFontStyle(0), |
| 94 #endif | 94 #endif |
| 95 m_pFont(NULL), | 95 m_pFont(nullptr), |
| 96 m_pFontMgr(src.m_pFontMgr), | 96 m_pFontMgr(src.m_pFontMgr), |
| 97 m_iRefCount(1), | 97 m_iRefCount(1), |
| 98 m_bExtFont(FALSE), | 98 m_bExtFont(FALSE), |
| 99 m_pStream(NULL), | 99 m_pStream(nullptr), |
| 100 m_pFileRead(NULL), | 100 m_pFileRead(nullptr), |
| 101 m_pFontEncoding(NULL), | 101 m_pFontEncoding(nullptr), |
| 102 m_pCharWidthMap(NULL), | 102 m_pCharWidthMap(nullptr), |
| 103 m_pRectArray(NULL), | 103 m_pRectArray(nullptr), |
| 104 m_pBBoxMap(NULL), | 104 m_pBBoxMap(nullptr), |
| 105 m_pProvider(NULL) { | 105 m_pProvider(nullptr) { |
| 106 ASSERT(src.m_pFont); | 106 ASSERT(src.m_pFont); |
| 107 m_pFont = new CFX_Font; | 107 m_pFont = new CFX_Font; |
| 108 m_pFont->LoadClone(src.m_pFont); | 108 m_pFont->LoadClone(src.m_pFont); |
| 109 CFX_SubstFont* pSubst = m_pFont->GetSubstFont(); | 109 CFX_SubstFont* pSubst = m_pFont->GetSubstFont(); |
| 110 if (!pSubst) { | 110 if (!pSubst) { |
| 111 pSubst = new CFX_SubstFont; | 111 pSubst = new CFX_SubstFont; |
| 112 m_pFont->SetSubstFont(pSubst); | 112 m_pFont->SetSubstFont(pSubst); |
| 113 } | 113 } |
| 114 pSubst->m_Weight = | 114 pSubst->m_Weight = |
| 115 (dwFontStyles & FX_FONTSTYLE_Bold) ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL; | 115 (dwFontStyles & FX_FONTSTYLE_Bold) ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 134 delete m_pFontEncoding; | 134 delete m_pFontEncoding; |
| 135 delete m_pCharWidthMap; | 135 delete m_pCharWidthMap; |
| 136 delete m_pRectArray; | 136 delete m_pRectArray; |
| 137 delete m_pBBoxMap; | 137 delete m_pBBoxMap; |
| 138 if (!m_bExtFont) | 138 if (!m_bExtFont) |
| 139 delete m_pFont; | 139 delete m_pFont; |
| 140 } | 140 } |
| 141 | 141 |
| 142 void CFGAS_GEFont::Release() { | 142 void CFGAS_GEFont::Release() { |
| 143 if (--m_iRefCount < 1) { | 143 if (--m_iRefCount < 1) { |
| 144 if (m_pFontMgr != NULL) { | 144 if (m_pFontMgr) { |
| 145 m_pFontMgr->RemoveFont(this); | 145 m_pFontMgr->RemoveFont(this); |
| 146 } | 146 } |
| 147 delete this; | 147 delete this; |
| 148 } | 148 } |
| 149 } | 149 } |
| 150 CFGAS_GEFont* CFGAS_GEFont::Retain() { | 150 CFGAS_GEFont* CFGAS_GEFont::Retain() { |
| 151 ++m_iRefCount; | 151 ++m_iRefCount; |
| 152 return this; | 152 return this; |
| 153 } | 153 } |
| 154 | 154 |
| 155 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 155 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 156 FX_BOOL CFGAS_GEFont::LoadFontInternal(const FX_WCHAR* pszFontFamily, | 156 FX_BOOL CFGAS_GEFont::LoadFontInternal(const FX_WCHAR* pszFontFamily, |
| 157 uint32_t dwFontStyles, | 157 uint32_t dwFontStyles, |
| 158 uint16_t wCodePage) { | 158 uint16_t wCodePage) { |
| 159 if (m_pFont) { | 159 if (m_pFont) { |
| 160 return FALSE; | 160 return FALSE; |
| 161 } | 161 } |
| 162 CFX_ByteString csFontFamily; | 162 CFX_ByteString csFontFamily; |
| 163 if (pszFontFamily != NULL) { | 163 if (pszFontFamily) { |
| 164 csFontFamily = CFX_ByteString::FromUnicode(pszFontFamily); | 164 csFontFamily = CFX_ByteString::FromUnicode(pszFontFamily); |
| 165 } | 165 } |
| 166 uint32_t dwFlags = 0; | 166 uint32_t dwFlags = 0; |
| 167 if (dwFontStyles & FX_FONTSTYLE_FixedPitch) { | 167 if (dwFontStyles & FX_FONTSTYLE_FixedPitch) { |
| 168 dwFlags |= FXFONT_FIXED_PITCH; | 168 dwFlags |= FXFONT_FIXED_PITCH; |
| 169 } | 169 } |
| 170 if (dwFontStyles & FX_FONTSTYLE_Serif) { | 170 if (dwFontStyles & FX_FONTSTYLE_Serif) { |
| 171 dwFlags |= FXFONT_SERIF; | 171 dwFlags |= FXFONT_SERIF; |
| 172 } | 172 } |
| 173 if (dwFontStyles & FX_FONTSTYLE_Symbolic) { | 173 if (dwFontStyles & FX_FONTSTYLE_Symbolic) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 if (!m_pFont->GetSubstFont() || | 269 if (!m_pFont->GetSubstFont() || |
| 270 m_pFont->GetSubstFont()->m_Family.GetLength() == 0) { | 270 m_pFont->GetSubstFont()->m_Family.GetLength() == 0) { |
| 271 wsFamily = CFX_WideString::FromLocal(m_pFont->GetFamilyName().AsStringC()); | 271 wsFamily = CFX_WideString::FromLocal(m_pFont->GetFamilyName().AsStringC()); |
| 272 } else { | 272 } else { |
| 273 wsFamily = CFX_WideString::FromLocal( | 273 wsFamily = CFX_WideString::FromLocal( |
| 274 m_pFont->GetSubstFont()->m_Family.AsStringC()); | 274 m_pFont->GetSubstFont()->m_Family.AsStringC()); |
| 275 } | 275 } |
| 276 } | 276 } |
| 277 | 277 |
| 278 uint32_t CFGAS_GEFont::GetFontStyles() const { | 278 uint32_t CFGAS_GEFont::GetFontStyles() const { |
| 279 ASSERT(m_pFont != NULL); | 279 ASSERT(m_pFont); |
| 280 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 280 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
| 281 if (m_bUseLogFontStyle) { | 281 if (m_bUseLogFontStyle) { |
| 282 return m_dwLogFontStyle; | 282 return m_dwLogFontStyle; |
| 283 } | 283 } |
| 284 #endif | 284 #endif |
| 285 uint32_t dwStyles = 0; | 285 uint32_t dwStyles = 0; |
| 286 if (!m_pFont->GetSubstFont()) { | 286 if (!m_pFont->GetSubstFont()) { |
| 287 if (m_pFont->IsBold()) { | 287 if (m_pFont->IsBold()) { |
| 288 dwStyles |= FX_FONTSTYLE_Bold; | 288 dwStyles |= FX_FONTSTYLE_Bold; |
| 289 } | 289 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 302 } | 302 } |
| 303 FX_BOOL CFGAS_GEFont::GetCharWidth(FX_WCHAR wUnicode, | 303 FX_BOOL CFGAS_GEFont::GetCharWidth(FX_WCHAR wUnicode, |
| 304 int32_t& iWidth, | 304 int32_t& iWidth, |
| 305 FX_BOOL bCharCode) { | 305 FX_BOOL bCharCode) { |
| 306 return GetCharWidthInternal(wUnicode, iWidth, TRUE, bCharCode); | 306 return GetCharWidthInternal(wUnicode, iWidth, TRUE, bCharCode); |
| 307 } | 307 } |
| 308 FX_BOOL CFGAS_GEFont::GetCharWidthInternal(FX_WCHAR wUnicode, | 308 FX_BOOL CFGAS_GEFont::GetCharWidthInternal(FX_WCHAR wUnicode, |
| 309 int32_t& iWidth, | 309 int32_t& iWidth, |
| 310 FX_BOOL bRecursive, | 310 FX_BOOL bRecursive, |
| 311 FX_BOOL bCharCode) { | 311 FX_BOOL bCharCode) { |
| 312 ASSERT(m_pCharWidthMap != NULL); | 312 ASSERT(m_pCharWidthMap); |
| 313 iWidth = m_pCharWidthMap->GetAt(wUnicode, 0); | 313 iWidth = m_pCharWidthMap->GetAt(wUnicode, 0); |
| 314 if (iWidth < 1) { | 314 if (iWidth < 1) { |
| 315 if (!m_pProvider || | 315 if (!m_pProvider || |
| 316 !m_pProvider->GetCharWidth(this, wUnicode, iWidth, bCharCode)) { | 316 !m_pProvider->GetCharWidth(this, wUnicode, iWidth, bCharCode)) { |
| 317 CFGAS_GEFont* pFont = NULL; | 317 CFGAS_GEFont* pFont = nullptr; |
| 318 int32_t iGlyph = GetGlyphIndex(wUnicode, TRUE, &pFont, bCharCode); | 318 int32_t iGlyph = GetGlyphIndex(wUnicode, TRUE, &pFont, bCharCode); |
| 319 if (iGlyph != 0xFFFF && pFont != NULL) { | 319 if (iGlyph != 0xFFFF && pFont) { |
| 320 if (pFont == this) { | 320 if (pFont == this) { |
| 321 iWidth = m_pFont->GetGlyphWidth(iGlyph); | 321 iWidth = m_pFont->GetGlyphWidth(iGlyph); |
| 322 if (iWidth < 0) { | 322 if (iWidth < 0) { |
| 323 iWidth = -1; | 323 iWidth = -1; |
| 324 } | 324 } |
| 325 } else if (pFont->GetCharWidthInternal(wUnicode, iWidth, FALSE, | 325 } else if (pFont->GetCharWidthInternal(wUnicode, iWidth, FALSE, |
| 326 bCharCode)) { | 326 bCharCode)) { |
| 327 return TRUE; | 327 return TRUE; |
| 328 } | 328 } |
| 329 } else { | 329 } else { |
| 330 iWidth = -1; | 330 iWidth = -1; |
| 331 } | 331 } |
| 332 } | 332 } |
| 333 m_pCharWidthMap->SetAtGrow(wUnicode, (int16_t)iWidth); | 333 m_pCharWidthMap->SetAtGrow(wUnicode, (int16_t)iWidth); |
| 334 } else if (iWidth == 65535) { | 334 } else if (iWidth == 65535) { |
| 335 iWidth = -1; | 335 iWidth = -1; |
| 336 } | 336 } |
| 337 return iWidth > 0; | 337 return iWidth > 0; |
| 338 } | 338 } |
| 339 FX_BOOL CFGAS_GEFont::GetCharBBox(FX_WCHAR wUnicode, | 339 FX_BOOL CFGAS_GEFont::GetCharBBox(FX_WCHAR wUnicode, |
| 340 CFX_Rect& bbox, | 340 CFX_Rect& bbox, |
| 341 FX_BOOL bCharCode) { | 341 FX_BOOL bCharCode) { |
| 342 return GetCharBBoxInternal(wUnicode, bbox, TRUE, bCharCode); | 342 return GetCharBBoxInternal(wUnicode, bbox, TRUE, bCharCode); |
| 343 } | 343 } |
| 344 FX_BOOL CFGAS_GEFont::GetCharBBoxInternal(FX_WCHAR wUnicode, | 344 FX_BOOL CFGAS_GEFont::GetCharBBoxInternal(FX_WCHAR wUnicode, |
| 345 CFX_Rect& bbox, | 345 CFX_Rect& bbox, |
| 346 FX_BOOL bRecursive, | 346 FX_BOOL bRecursive, |
| 347 FX_BOOL bCharCode) { | 347 FX_BOOL bCharCode) { |
| 348 ASSERT(m_pRectArray != NULL); | 348 ASSERT(m_pRectArray); |
| 349 ASSERT(m_pBBoxMap != NULL); | 349 ASSERT(m_pBBoxMap); |
| 350 void* pRect = NULL; | 350 void* pRect = nullptr; |
| 351 if (!m_pBBoxMap->Lookup((void*)(uintptr_t)wUnicode, pRect)) { | 351 if (!m_pBBoxMap->Lookup((void*)(uintptr_t)wUnicode, pRect)) { |
| 352 CFGAS_GEFont* pFont = NULL; | 352 CFGAS_GEFont* pFont = nullptr; |
| 353 int32_t iGlyph = GetGlyphIndex(wUnicode, TRUE, &pFont, bCharCode); | 353 int32_t iGlyph = GetGlyphIndex(wUnicode, TRUE, &pFont, bCharCode); |
| 354 if (iGlyph != 0xFFFF && pFont != NULL) { | 354 if (iGlyph != 0xFFFF && pFont) { |
| 355 if (pFont == this) { | 355 if (pFont == this) { |
| 356 FX_RECT rtBBox; | 356 FX_RECT rtBBox; |
| 357 if (m_pFont->GetGlyphBBox(iGlyph, rtBBox)) { | 357 if (m_pFont->GetGlyphBBox(iGlyph, rtBBox)) { |
| 358 CFX_Rect rt; | 358 CFX_Rect rt; |
| 359 rt.Set(rtBBox.left, rtBBox.top, rtBBox.Width(), rtBBox.Height()); | 359 rt.Set(rtBBox.left, rtBBox.top, rtBBox.Width(), rtBBox.Height()); |
| 360 int32_t index = m_pRectArray->Add(rt); | 360 int32_t index = m_pRectArray->Add(rt); |
| 361 pRect = m_pRectArray->GetPtrAt(index); | 361 pRect = m_pRectArray->GetPtrAt(index); |
| 362 m_pBBoxMap->SetAt((void*)(uintptr_t)wUnicode, pRect); | 362 m_pBBoxMap->SetAt((void*)(uintptr_t)wUnicode, pRect); |
| 363 } | 363 } |
| 364 } else if (pFont->GetCharBBoxInternal(wUnicode, bbox, FALSE, bCharCode)) { | 364 } else if (pFont->GetCharBBoxInternal(wUnicode, bbox, FALSE, bCharCode)) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 383 } | 383 } |
| 384 return bRet; | 384 return bRet; |
| 385 } | 385 } |
| 386 int32_t CFGAS_GEFont::GetItalicAngle() const { | 386 int32_t CFGAS_GEFont::GetItalicAngle() const { |
| 387 if (!m_pFont->GetSubstFont()) { | 387 if (!m_pFont->GetSubstFont()) { |
| 388 return 0; | 388 return 0; |
| 389 } | 389 } |
| 390 return m_pFont->GetSubstFont()->m_ItalicAngle; | 390 return m_pFont->GetSubstFont()->m_ItalicAngle; |
| 391 } | 391 } |
| 392 int32_t CFGAS_GEFont::GetGlyphIndex(FX_WCHAR wUnicode, FX_BOOL bCharCode) { | 392 int32_t CFGAS_GEFont::GetGlyphIndex(FX_WCHAR wUnicode, FX_BOOL bCharCode) { |
| 393 return GetGlyphIndex(wUnicode, TRUE, NULL, bCharCode); | 393 return GetGlyphIndex(wUnicode, TRUE, nullptr, bCharCode); |
| 394 } | 394 } |
| 395 int32_t CFGAS_GEFont::GetGlyphIndex(FX_WCHAR wUnicode, | 395 int32_t CFGAS_GEFont::GetGlyphIndex(FX_WCHAR wUnicode, |
| 396 FX_BOOL bRecursive, | 396 FX_BOOL bRecursive, |
| 397 CFGAS_GEFont** ppFont, | 397 CFGAS_GEFont** ppFont, |
| 398 FX_BOOL bCharCode) { | 398 FX_BOOL bCharCode) { |
| 399 ASSERT(m_pFontEncoding != NULL); | 399 ASSERT(m_pFontEncoding); |
| 400 int32_t iGlyphIndex = m_pFontEncoding->GlyphFromCharCode(wUnicode); | 400 int32_t iGlyphIndex = m_pFontEncoding->GlyphFromCharCode(wUnicode); |
| 401 if (iGlyphIndex > 0) { | 401 if (iGlyphIndex > 0) { |
| 402 if (ppFont != NULL) { | 402 if (ppFont) { |
| 403 *ppFont = this; | 403 *ppFont = this; |
| 404 } | 404 } |
| 405 return iGlyphIndex; | 405 return iGlyphIndex; |
| 406 } | 406 } |
| 407 const FGAS_FONTUSB* pFontUSB = FGAS_GetUnicodeBitField(wUnicode); | 407 const FGAS_FONTUSB* pFontUSB = FGAS_GetUnicodeBitField(wUnicode); |
| 408 if (pFontUSB == NULL) { | 408 if (!pFontUSB) { |
| 409 return 0xFFFF; | 409 return 0xFFFF; |
| 410 } | 410 } |
| 411 uint16_t wBitField = pFontUSB->wBitField; | 411 uint16_t wBitField = pFontUSB->wBitField; |
| 412 if (wBitField >= 128) { | 412 if (wBitField >= 128) { |
| 413 return 0xFFFF; | 413 return 0xFFFF; |
| 414 } | 414 } |
| 415 auto it = m_FontMapper.find(wUnicode); | 415 auto it = m_FontMapper.find(wUnicode); |
| 416 CFGAS_GEFont* pFont = it != m_FontMapper.end() ? it->second : nullptr; | 416 CFGAS_GEFont* pFont = it != m_FontMapper.end() ? it->second : nullptr; |
| 417 if (pFont && pFont != this) { | 417 if (pFont && pFont != this) { |
| 418 iGlyphIndex = pFont->GetGlyphIndex(wUnicode, FALSE, NULL, bCharCode); | 418 iGlyphIndex = pFont->GetGlyphIndex(wUnicode, FALSE, nullptr, bCharCode); |
| 419 if (iGlyphIndex != 0xFFFF) { | 419 if (iGlyphIndex != 0xFFFF) { |
| 420 int32_t i = m_SubstFonts.Find(pFont); | 420 int32_t i = m_SubstFonts.Find(pFont); |
| 421 if (i > -1) { | 421 if (i > -1) { |
| 422 iGlyphIndex |= ((i + 1) << 24); | 422 iGlyphIndex |= ((i + 1) << 24); |
| 423 if (ppFont) | 423 if (ppFont) |
| 424 *ppFont = pFont; | 424 *ppFont = pFont; |
| 425 return iGlyphIndex; | 425 return iGlyphIndex; |
| 426 } | 426 } |
| 427 } | 427 } |
| 428 } | 428 } |
| 429 if (m_pFontMgr && bRecursive) { | 429 if (m_pFontMgr && bRecursive) { |
| 430 CFX_WideString wsFamily; | 430 CFX_WideString wsFamily; |
| 431 GetFamilyName(wsFamily); | 431 GetFamilyName(wsFamily); |
| 432 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 432 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 433 CFGAS_GEFont* pFont = m_pFontMgr->GetDefFontByUnicode( | 433 CFGAS_GEFont* pFont = m_pFontMgr->GetDefFontByUnicode( |
| 434 wUnicode, GetFontStyles(), wsFamily.c_str()); | 434 wUnicode, GetFontStyles(), wsFamily.c_str()); |
| 435 #else | 435 #else |
| 436 CFGAS_GEFont* pFont = m_pFontMgr->GetFontByUnicode( | 436 CFGAS_GEFont* pFont = m_pFontMgr->GetFontByUnicode( |
| 437 wUnicode, GetFontStyles(), wsFamily.c_str()); | 437 wUnicode, GetFontStyles(), wsFamily.c_str()); |
| 438 if (!pFont) | 438 if (!pFont) |
| 439 pFont = m_pFontMgr->GetFontByUnicode(wUnicode, GetFontStyles(), NULL); | 439 pFont = m_pFontMgr->GetFontByUnicode(wUnicode, GetFontStyles(), nullptr); |
| 440 #endif | 440 #endif |
| 441 if (pFont) { | 441 if (pFont) { |
| 442 if (pFont == this) { | 442 if (pFont == this) { |
| 443 pFont->Release(); | 443 pFont->Release(); |
| 444 return 0xFFFF; | 444 return 0xFFFF; |
| 445 } | 445 } |
| 446 m_FontMapper[wUnicode] = pFont; | 446 m_FontMapper[wUnicode] = pFont; |
| 447 int32_t i = m_SubstFonts.GetSize(); | 447 int32_t i = m_SubstFonts.GetSize(); |
| 448 m_SubstFonts.Add(pFont); | 448 m_SubstFonts.Add(pFont); |
| 449 iGlyphIndex = pFont->GetGlyphIndex(wUnicode, FALSE, NULL, bCharCode); | 449 iGlyphIndex = pFont->GetGlyphIndex(wUnicode, FALSE, nullptr, bCharCode); |
| 450 if (iGlyphIndex != 0xFFFF) { | 450 if (iGlyphIndex != 0xFFFF) { |
| 451 iGlyphIndex |= ((i + 1) << 24); | 451 iGlyphIndex |= ((i + 1) << 24); |
| 452 if (ppFont) | 452 if (ppFont) |
| 453 *ppFont = pFont; | 453 *ppFont = pFont; |
| 454 return iGlyphIndex; | 454 return iGlyphIndex; |
| 455 } | 455 } |
| 456 } | 456 } |
| 457 } | 457 } |
| 458 return 0xFFFF; | 458 return 0xFFFF; |
| 459 } | 459 } |
| 460 int32_t CFGAS_GEFont::GetAscent() const { | 460 int32_t CFGAS_GEFont::GetAscent() const { |
| 461 return m_pFont->GetAscent(); | 461 return m_pFont->GetAscent(); |
| 462 } | 462 } |
| 463 int32_t CFGAS_GEFont::GetDescent() const { | 463 int32_t CFGAS_GEFont::GetDescent() const { |
| 464 return m_pFont->GetDescent(); | 464 return m_pFont->GetDescent(); |
| 465 } | 465 } |
| 466 void CFGAS_GEFont::Reset() { | 466 void CFGAS_GEFont::Reset() { |
| 467 for (int32_t i = 0; i < m_SubstFonts.GetSize(); i++) | 467 for (int32_t i = 0; i < m_SubstFonts.GetSize(); i++) |
| 468 m_SubstFonts[i]->Reset(); | 468 m_SubstFonts[i]->Reset(); |
| 469 if (m_pCharWidthMap != NULL) { | 469 if (m_pCharWidthMap) { |
| 470 m_pCharWidthMap->RemoveAll(); | 470 m_pCharWidthMap->RemoveAll(); |
| 471 } | 471 } |
| 472 if (m_pBBoxMap != NULL) { | 472 if (m_pBBoxMap) { |
| 473 m_pBBoxMap->RemoveAll(); | 473 m_pBBoxMap->RemoveAll(); |
| 474 } | 474 } |
| 475 if (m_pRectArray != NULL) { | 475 if (m_pRectArray) { |
| 476 m_pRectArray->RemoveAll(); | 476 m_pRectArray->RemoveAll(); |
| 477 } | 477 } |
| 478 } | 478 } |
| 479 CFGAS_GEFont* CFGAS_GEFont::GetSubstFont(int32_t iGlyphIndex) const { | 479 CFGAS_GEFont* CFGAS_GEFont::GetSubstFont(int32_t iGlyphIndex) const { |
| 480 iGlyphIndex = ((uint32_t)iGlyphIndex) >> 24; | 480 iGlyphIndex = ((uint32_t)iGlyphIndex) >> 24; |
| 481 return iGlyphIndex == 0 ? const_cast<CFGAS_GEFont*>(this) | 481 return iGlyphIndex == 0 ? const_cast<CFGAS_GEFont*>(this) |
| 482 : m_SubstFonts[iGlyphIndex - 1]; | 482 : m_SubstFonts[iGlyphIndex - 1]; |
| 483 } | 483 } |
| OLD | NEW |