| 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 IFGAS_Font* IFGAS_Font::LoadFont(const FX_WCHAR* pszFontFamily, | 13 IFGAS_Font* IFGAS_Font::LoadFont(const FX_WCHAR* pszFontFamily, |
| 14 uint32_t dwFontStyles, | 14 uint32_t dwFontStyles, |
| 15 uint16_t wCodePage, | 15 uint16_t wCodePage, |
| 16 IFGAS_FontMgr* pFontMgr) { | 16 IFGAS_FontMgr* pFontMgr) { |
| 17 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 17 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
| 18 if (NULL != pFontMgr) { | 18 if (pFontMgr) |
| 19 return pFontMgr->GetFontByCodePage(wCodePage, dwFontStyles, pszFontFamily); | 19 return pFontMgr->GetFontByCodePage(wCodePage, dwFontStyles, pszFontFamily); |
| 20 } | 20 return nullptr; |
| 21 return NULL; | |
| 22 #else | 21 #else |
| 23 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); | 22 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); |
| 24 if (!pFont->LoadFont(pszFontFamily, dwFontStyles, wCodePage)) { | 23 if (!pFont->LoadFont(pszFontFamily, dwFontStyles, wCodePage)) { |
| 25 pFont->Release(); | 24 pFont->Release(); |
| 26 return NULL; | 25 return nullptr; |
| 27 } | 26 } |
| 28 return pFont; | 27 return pFont; |
| 29 #endif | 28 #endif |
| 30 } | 29 } |
| 31 IFGAS_Font* IFGAS_Font::LoadFont(const uint8_t* pBuffer, | 30 IFGAS_Font* IFGAS_Font::LoadFont(const uint8_t* pBuffer, |
| 32 int32_t iLength, | 31 int32_t iLength, |
| 33 IFGAS_FontMgr* pFontMgr) { | 32 IFGAS_FontMgr* pFontMgr) { |
| 34 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 33 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
| 35 if (NULL != pFontMgr) { | 34 if (pFontMgr) |
| 36 return pFontMgr->LoadFont(pBuffer, iLength, 0, NULL); | 35 return pFontMgr->LoadFont(pBuffer, iLength, 0, nullptr); |
| 37 } | 36 return nullptr; |
| 38 return NULL; | |
| 39 #else | 37 #else |
| 40 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); | 38 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); |
| 41 if (!pFont->LoadFont(pBuffer, iLength)) { | 39 if (!pFont->LoadFont(pBuffer, iLength)) { |
| 42 pFont->Release(); | 40 pFont->Release(); |
| 43 return NULL; | 41 return nullptr; |
| 44 } | 42 } |
| 45 return pFont; | 43 return pFont; |
| 46 #endif | 44 #endif |
| 47 } | 45 } |
| 48 IFGAS_Font* IFGAS_Font::LoadFont(const FX_WCHAR* pszFileName, | 46 IFGAS_Font* IFGAS_Font::LoadFont(const FX_WCHAR* pszFileName, |
| 49 IFGAS_FontMgr* pFontMgr) { | 47 IFGAS_FontMgr* pFontMgr) { |
| 50 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 48 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
| 51 if (NULL != pFontMgr) { | 49 if (pFontMgr) |
| 52 return pFontMgr->LoadFont(pszFileName, 0, NULL); | 50 return pFontMgr->LoadFont(pszFileName, 0, nullptr); |
| 53 } | 51 return nullptr; |
| 54 return NULL; | |
| 55 #else | 52 #else |
| 56 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); | 53 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); |
| 57 if (!pFont->LoadFont(pszFileName)) { | 54 if (!pFont->LoadFont(pszFileName)) { |
| 58 pFont->Release(); | 55 pFont->Release(); |
| 59 return NULL; | 56 return nullptr; |
| 60 } | 57 } |
| 61 return pFont; | 58 return pFont; |
| 62 #endif | 59 #endif |
| 63 } | 60 } |
| 64 IFGAS_Font* IFGAS_Font::LoadFont(IFX_Stream* pFontStream, | 61 IFGAS_Font* IFGAS_Font::LoadFont(IFX_Stream* pFontStream, |
| 65 IFGAS_FontMgr* pFontMgr, | 62 IFGAS_FontMgr* pFontMgr, |
| 66 FX_BOOL bSaveStream) { | 63 FX_BOOL bSaveStream) { |
| 67 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 64 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
| 68 if (NULL != pFontMgr) { | 65 if (pFontMgr) |
| 69 return pFontMgr->LoadFont(pFontStream, 0, NULL); | 66 return pFontMgr->LoadFont(pFontStream, 0, nullptr); |
| 70 } | 67 return nullptr; |
| 71 return NULL; | |
| 72 #else | 68 #else |
| 73 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); | 69 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); |
| 74 if (!pFont->LoadFont(pFontStream, bSaveStream)) { | 70 if (!pFont->LoadFont(pFontStream, bSaveStream)) { |
| 75 pFont->Release(); | 71 pFont->Release(); |
| 76 return NULL; | 72 return nullptr; |
| 77 } | 73 } |
| 78 return pFont; | 74 return pFont; |
| 79 #endif | 75 #endif |
| 80 } | 76 } |
| 81 IFGAS_Font* IFGAS_Font::LoadFont(CFX_Font* pExtFont, | 77 IFGAS_Font* IFGAS_Font::LoadFont(CFX_Font* pExtFont, |
| 82 IFGAS_FontMgr* pFontMgr, | 78 IFGAS_FontMgr* pFontMgr, |
| 83 FX_BOOL bTakeOver) { | 79 FX_BOOL bTakeOver) { |
| 84 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); | 80 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); |
| 85 if (!pFont->LoadFont(pExtFont, bTakeOver)) { | 81 if (!pFont->LoadFont(pExtFont, bTakeOver)) { |
| 86 pFont->Release(); | 82 pFont->Release(); |
| 87 return NULL; | 83 return nullptr; |
| 88 } | 84 } |
| 89 return pFont; | 85 return pFont; |
| 90 } | 86 } |
| 91 | 87 |
| 92 CFGAS_GEFont::CFGAS_GEFont(IFGAS_FontMgr* pFontMgr) | 88 CFGAS_GEFont::CFGAS_GEFont(IFGAS_FontMgr* pFontMgr) |
| 93 : | 89 : |
| 94 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 90 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
| 95 m_bUseLogFontStyle(FALSE), | 91 m_bUseLogFontStyle(FALSE), |
| 96 m_dwLogFontStyle(0), | 92 m_dwLogFontStyle(0), |
| 97 #endif | 93 #endif |
| 98 m_pFont(NULL), | 94 m_pFont(nullptr), |
| 99 m_pFontMgr(pFontMgr), | 95 m_pFontMgr(pFontMgr), |
| 100 m_iRefCount(1), | 96 m_iRefCount(1), |
| 101 m_bExtFont(FALSE), | 97 m_bExtFont(FALSE), |
| 102 m_pStream(NULL), | 98 m_pStream(nullptr), |
| 103 m_pFileRead(NULL), | 99 m_pFileRead(nullptr), |
| 104 m_pFontEncoding(NULL), | 100 m_pFontEncoding(nullptr), |
| 105 m_pCharWidthMap(NULL), | 101 m_pCharWidthMap(nullptr), |
| 106 m_pRectArray(NULL), | 102 m_pRectArray(nullptr), |
| 107 m_pBBoxMap(NULL), | 103 m_pBBoxMap(nullptr), |
| 108 m_pProvider(NULL), | 104 m_pProvider(nullptr), |
| 109 m_wCharSet(0xFFFF) { | 105 m_wCharSet(0xFFFF) { |
| 110 } | 106 } |
| 111 | 107 |
| 112 CFGAS_GEFont::CFGAS_GEFont(const CFGAS_GEFont& src, uint32_t dwFontStyles) | 108 CFGAS_GEFont::CFGAS_GEFont(const CFGAS_GEFont& src, uint32_t dwFontStyles) |
| 113 : | 109 : |
| 114 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 110 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
| 115 m_bUseLogFontStyle(FALSE), | 111 m_bUseLogFontStyle(FALSE), |
| 116 m_dwLogFontStyle(0), | 112 m_dwLogFontStyle(0), |
| 117 #endif | 113 #endif |
| 118 m_pFont(NULL), | 114 m_pFont(nullptr), |
| 119 m_pFontMgr(src.m_pFontMgr), | 115 m_pFontMgr(src.m_pFontMgr), |
| 120 m_iRefCount(1), | 116 m_iRefCount(1), |
| 121 m_bExtFont(FALSE), | 117 m_bExtFont(FALSE), |
| 122 m_pStream(NULL), | 118 m_pStream(nullptr), |
| 123 m_pFileRead(NULL), | 119 m_pFileRead(nullptr), |
| 124 m_pFontEncoding(NULL), | 120 m_pFontEncoding(nullptr), |
| 125 m_pCharWidthMap(NULL), | 121 m_pCharWidthMap(nullptr), |
| 126 m_pRectArray(NULL), | 122 m_pRectArray(nullptr), |
| 127 m_pBBoxMap(NULL), | 123 m_pBBoxMap(nullptr), |
| 128 m_pProvider(NULL), | 124 m_pProvider(nullptr), |
| 129 m_wCharSet(0xFFFF) { | 125 m_wCharSet(0xFFFF) { |
| 130 ASSERT(src.m_pFont); | 126 ASSERT(src.m_pFont); |
| 131 m_pFont = new CFX_Font; | 127 m_pFont = new CFX_Font; |
| 132 m_pFont->LoadClone(src.m_pFont); | 128 m_pFont->LoadClone(src.m_pFont); |
| 133 CFX_SubstFont* pSubst = m_pFont->GetSubstFont(); | 129 CFX_SubstFont* pSubst = m_pFont->GetSubstFont(); |
| 134 if (!pSubst) { | 130 if (!pSubst) { |
| 135 pSubst = new CFX_SubstFont; | 131 pSubst = new CFX_SubstFont; |
| 136 m_pFont->SetSubstFont(pSubst); | 132 m_pFont->SetSubstFont(pSubst); |
| 137 } | 133 } |
| 138 pSubst->m_Weight = | 134 pSubst->m_Weight = |
| (...skipping 19 matching lines...) Expand all Loading... |
| 158 delete m_pFontEncoding; | 154 delete m_pFontEncoding; |
| 159 delete m_pCharWidthMap; | 155 delete m_pCharWidthMap; |
| 160 delete m_pRectArray; | 156 delete m_pRectArray; |
| 161 delete m_pBBoxMap; | 157 delete m_pBBoxMap; |
| 162 if (!m_bExtFont) | 158 if (!m_bExtFont) |
| 163 delete m_pFont; | 159 delete m_pFont; |
| 164 } | 160 } |
| 165 | 161 |
| 166 void CFGAS_GEFont::Release() { | 162 void CFGAS_GEFont::Release() { |
| 167 if (--m_iRefCount < 1) { | 163 if (--m_iRefCount < 1) { |
| 168 if (m_pFontMgr != NULL) { | 164 if (m_pFontMgr) |
| 169 m_pFontMgr->RemoveFont(this); | 165 m_pFontMgr->RemoveFont(this); |
| 170 } | |
| 171 delete this; | 166 delete this; |
| 172 } | 167 } |
| 173 } | 168 } |
| 174 IFGAS_Font* CFGAS_GEFont::Retain() { | 169 IFGAS_Font* CFGAS_GEFont::Retain() { |
| 175 ++m_iRefCount; | 170 ++m_iRefCount; |
| 176 return this; | 171 return this; |
| 177 } | 172 } |
| 178 FX_BOOL CFGAS_GEFont::LoadFont(const FX_WCHAR* pszFontFamily, | 173 FX_BOOL CFGAS_GEFont::LoadFont(const FX_WCHAR* pszFontFamily, |
| 179 uint32_t dwFontStyles, | 174 uint32_t dwFontStyles, |
| 180 uint16_t wCodePage) { | 175 uint16_t wCodePage) { |
| 181 if (m_pFont) { | 176 if (m_pFont) { |
| 182 return FALSE; | 177 return FALSE; |
| 183 } | 178 } |
| 184 CFX_ByteString csFontFamily; | 179 CFX_ByteString csFontFamily; |
| 185 if (pszFontFamily != NULL) { | 180 if (pszFontFamily) |
| 186 csFontFamily = CFX_ByteString::FromUnicode(pszFontFamily); | 181 csFontFamily = CFX_ByteString::FromUnicode(pszFontFamily); |
| 187 } | |
| 188 uint32_t dwFlags = 0; | 182 uint32_t dwFlags = 0; |
| 189 if (dwFontStyles & FX_FONTSTYLE_FixedPitch) { | 183 if (dwFontStyles & FX_FONTSTYLE_FixedPitch) { |
| 190 dwFlags |= FXFONT_FIXED_PITCH; | 184 dwFlags |= FXFONT_FIXED_PITCH; |
| 191 } | 185 } |
| 192 if (dwFontStyles & FX_FONTSTYLE_Serif) { | 186 if (dwFontStyles & FX_FONTSTYLE_Serif) { |
| 193 dwFlags |= FXFONT_SERIF; | 187 dwFlags |= FXFONT_SERIF; |
| 194 } | 188 } |
| 195 if (dwFontStyles & FX_FONTSTYLE_Symbolic) { | 189 if (dwFontStyles & FX_FONTSTYLE_Symbolic) { |
| 196 dwFlags |= FXFONT_SYMBOLIC; | 190 dwFlags |= FXFONT_SYMBOLIC; |
| 197 } | 191 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 216 m_wCharSet = wCharSet; | 210 m_wCharSet = wCharSet; |
| 217 m_pFont = new CFX_Font; | 211 m_pFont = new CFX_Font; |
| 218 if ((dwFlags & FXFONT_ITALIC) && (dwFlags & FXFONT_BOLD)) { | 212 if ((dwFlags & FXFONT_ITALIC) && (dwFlags & FXFONT_BOLD)) { |
| 219 csFontFamily += ",BoldItalic"; | 213 csFontFamily += ",BoldItalic"; |
| 220 } else if (dwFlags & FXFONT_BOLD) { | 214 } else if (dwFlags & FXFONT_BOLD) { |
| 221 csFontFamily += ",Bold"; | 215 csFontFamily += ",Bold"; |
| 222 } else if (dwFlags & FXFONT_ITALIC) { | 216 } else if (dwFlags & FXFONT_ITALIC) { |
| 223 csFontFamily += ",Italic"; | 217 csFontFamily += ",Italic"; |
| 224 } | 218 } |
| 225 m_pFont->LoadSubst(csFontFamily, TRUE, dwFlags, iWeight, 0, wCodePage); | 219 m_pFont->LoadSubst(csFontFamily, TRUE, dwFlags, iWeight, 0, wCodePage); |
| 226 FX_BOOL bRet = m_pFont->GetFace() != nullptr; | 220 if (!m_pFont->GetFace()) |
| 227 if (bRet) { | 221 return FALSE; |
| 228 bRet = InitFont(); | 222 |
| 229 } | 223 return InitFont(); |
| 230 return bRet; | |
| 231 } | 224 } |
| 232 FX_BOOL CFGAS_GEFont::LoadFont(const uint8_t* pBuffer, int32_t length) { | 225 FX_BOOL CFGAS_GEFont::LoadFont(const uint8_t* pBuffer, int32_t length) { |
| 233 if (m_pFont) { | 226 if (m_pFont) { |
| 234 return FALSE; | 227 return FALSE; |
| 235 } | 228 } |
| 236 m_pFont = new CFX_Font; | 229 m_pFont = new CFX_Font; |
| 237 FX_BOOL bRet = m_pFont->LoadEmbedded(pBuffer, length); | 230 FX_BOOL bRet = m_pFont->LoadEmbedded(pBuffer, length); |
| 238 if (bRet) { | 231 if (bRet) { |
| 239 bRet = InitFont(); | 232 bRet = InitFont(); |
| 240 } | 233 } |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 if (!m_pFont->GetSubstFont() || | 325 if (!m_pFont->GetSubstFont() || |
| 333 m_pFont->GetSubstFont()->m_Family.GetLength() == 0) { | 326 m_pFont->GetSubstFont()->m_Family.GetLength() == 0) { |
| 334 wsFamily = CFX_WideString::FromLocal(m_pFont->GetFamilyName().AsStringC()); | 327 wsFamily = CFX_WideString::FromLocal(m_pFont->GetFamilyName().AsStringC()); |
| 335 } else { | 328 } else { |
| 336 wsFamily = CFX_WideString::FromLocal( | 329 wsFamily = CFX_WideString::FromLocal( |
| 337 m_pFont->GetSubstFont()->m_Family.AsStringC()); | 330 m_pFont->GetSubstFont()->m_Family.AsStringC()); |
| 338 } | 331 } |
| 339 } | 332 } |
| 340 | 333 |
| 341 uint32_t CFGAS_GEFont::GetFontStyles() const { | 334 uint32_t CFGAS_GEFont::GetFontStyles() const { |
| 342 ASSERT(m_pFont != NULL); | 335 ASSERT(m_pFont); |
| 343 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 336 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
| 344 if (m_bUseLogFontStyle) { | 337 if (m_bUseLogFontStyle) { |
| 345 return m_dwLogFontStyle; | 338 return m_dwLogFontStyle; |
| 346 } | 339 } |
| 347 #endif | 340 #endif |
| 348 uint32_t dwStyles = 0; | 341 uint32_t dwStyles = 0; |
| 349 if (!m_pFont->GetSubstFont()) { | 342 if (!m_pFont->GetSubstFont()) { |
| 350 if (m_pFont->IsBold()) { | 343 if (m_pFont->IsBold()) { |
| 351 dwStyles |= FX_FONTSTYLE_Bold; | 344 dwStyles |= FX_FONTSTYLE_Bold; |
| 352 } | 345 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 365 } | 358 } |
| 366 FX_BOOL CFGAS_GEFont::GetCharWidth(FX_WCHAR wUnicode, | 359 FX_BOOL CFGAS_GEFont::GetCharWidth(FX_WCHAR wUnicode, |
| 367 int32_t& iWidth, | 360 int32_t& iWidth, |
| 368 FX_BOOL bCharCode) { | 361 FX_BOOL bCharCode) { |
| 369 return GetCharWidth(wUnicode, iWidth, TRUE, bCharCode); | 362 return GetCharWidth(wUnicode, iWidth, TRUE, bCharCode); |
| 370 } | 363 } |
| 371 FX_BOOL CFGAS_GEFont::GetCharWidth(FX_WCHAR wUnicode, | 364 FX_BOOL CFGAS_GEFont::GetCharWidth(FX_WCHAR wUnicode, |
| 372 int32_t& iWidth, | 365 int32_t& iWidth, |
| 373 FX_BOOL bRecursive, | 366 FX_BOOL bRecursive, |
| 374 FX_BOOL bCharCode) { | 367 FX_BOOL bCharCode) { |
| 375 ASSERT(m_pCharWidthMap != NULL); | |
| 376 iWidth = m_pCharWidthMap->GetAt(wUnicode, 0); | 368 iWidth = m_pCharWidthMap->GetAt(wUnicode, 0); |
| 377 if (iWidth < 1) { | 369 if (iWidth < 1) { |
| 378 if (!m_pProvider || | 370 if (!m_pProvider || |
| 379 !m_pProvider->GetCharWidth(this, wUnicode, iWidth, bCharCode)) { | 371 !m_pProvider->GetCharWidth(this, wUnicode, iWidth, bCharCode)) { |
| 380 IFGAS_Font* pFont = NULL; | 372 IFGAS_Font* pFont = nullptr; |
| 381 int32_t iGlyph = GetGlyphIndex(wUnicode, TRUE, &pFont, bCharCode); | 373 int32_t iGlyph = GetGlyphIndex(wUnicode, TRUE, &pFont, bCharCode); |
| 382 if (iGlyph != 0xFFFF && pFont != NULL) { | 374 if (iGlyph != 0xFFFF && pFont) { |
| 383 if (pFont == (IFGAS_Font*)this) { | 375 if (pFont == (IFGAS_Font*)this) { |
| 384 iWidth = m_pFont->GetGlyphWidth(iGlyph); | 376 iWidth = m_pFont->GetGlyphWidth(iGlyph); |
| 385 if (iWidth < 0) { | 377 if (iWidth < 0) { |
| 386 iWidth = -1; | 378 iWidth = -1; |
| 387 } | 379 } |
| 388 } else if (((CFGAS_GEFont*)pFont) | 380 } else if (((CFGAS_GEFont*)pFont) |
| 389 ->GetCharWidth(wUnicode, iWidth, FALSE, bCharCode)) { | 381 ->GetCharWidth(wUnicode, iWidth, FALSE, bCharCode)) { |
| 390 return TRUE; | 382 return TRUE; |
| 391 } | 383 } |
| 392 } else { | 384 } else { |
| 393 iWidth = -1; | 385 iWidth = -1; |
| 394 } | 386 } |
| 395 } | 387 } |
| 396 m_pCharWidthMap->SetAtGrow(wUnicode, (int16_t)iWidth); | 388 m_pCharWidthMap->SetAtGrow(wUnicode, (int16_t)iWidth); |
| 397 } else if (iWidth == 65535) { | 389 } else if (iWidth == 65535) { |
| 398 iWidth = -1; | 390 iWidth = -1; |
| 399 } | 391 } |
| 400 return iWidth > 0; | 392 return iWidth > 0; |
| 401 } | 393 } |
| 402 FX_BOOL CFGAS_GEFont::GetCharBBox(FX_WCHAR wUnicode, | 394 FX_BOOL CFGAS_GEFont::GetCharBBox(FX_WCHAR wUnicode, |
| 403 CFX_Rect& bbox, | 395 CFX_Rect& bbox, |
| 404 FX_BOOL bCharCode) { | 396 FX_BOOL bCharCode) { |
| 405 return GetCharBBox(wUnicode, bbox, TRUE, bCharCode); | 397 return GetCharBBox(wUnicode, bbox, TRUE, bCharCode); |
| 406 } | 398 } |
| 407 FX_BOOL CFGAS_GEFont::GetCharBBox(FX_WCHAR wUnicode, | 399 FX_BOOL CFGAS_GEFont::GetCharBBox(FX_WCHAR wUnicode, |
| 408 CFX_Rect& bbox, | 400 CFX_Rect& bbox, |
| 409 FX_BOOL bRecursive, | 401 FX_BOOL bRecursive, |
| 410 FX_BOOL bCharCode) { | 402 FX_BOOL bCharCode) { |
| 411 ASSERT(m_pRectArray != NULL); | 403 void* pRect = nullptr; |
| 412 ASSERT(m_pBBoxMap != NULL); | |
| 413 void* pRect = NULL; | |
| 414 if (!m_pBBoxMap->Lookup((void*)(uintptr_t)wUnicode, pRect)) { | 404 if (!m_pBBoxMap->Lookup((void*)(uintptr_t)wUnicode, pRect)) { |
| 415 IFGAS_Font* pFont = NULL; | 405 IFGAS_Font* pFont = nullptr; |
| 416 int32_t iGlyph = GetGlyphIndex(wUnicode, TRUE, &pFont, bCharCode); | 406 int32_t iGlyph = GetGlyphIndex(wUnicode, TRUE, &pFont, bCharCode); |
| 417 if (iGlyph != 0xFFFF && pFont != NULL) { | 407 if (iGlyph != 0xFFFF && pFont) { |
| 418 if (pFont == (IFGAS_Font*)this) { | 408 if (pFont == (IFGAS_Font*)this) { |
| 419 FX_RECT rtBBox; | 409 FX_RECT rtBBox; |
| 420 if (m_pFont->GetGlyphBBox(iGlyph, rtBBox)) { | 410 if (m_pFont->GetGlyphBBox(iGlyph, rtBBox)) { |
| 421 CFX_Rect rt; | 411 CFX_Rect rt; |
| 422 rt.Set(rtBBox.left, rtBBox.top, rtBBox.Width(), rtBBox.Height()); | 412 rt.Set(rtBBox.left, rtBBox.top, rtBBox.Width(), rtBBox.Height()); |
| 423 int32_t index = m_pRectArray->Add(rt); | 413 int32_t index = m_pRectArray->Add(rt); |
| 424 pRect = m_pRectArray->GetPtrAt(index); | 414 pRect = m_pRectArray->GetPtrAt(index); |
| 425 m_pBBoxMap->SetAt((void*)(uintptr_t)wUnicode, pRect); | 415 m_pBBoxMap->SetAt((void*)(uintptr_t)wUnicode, pRect); |
| 426 } | 416 } |
| 427 } else if (((CFGAS_GEFont*)pFont) | 417 } else if (((CFGAS_GEFont*)pFont) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 447 } | 437 } |
| 448 return bRet; | 438 return bRet; |
| 449 } | 439 } |
| 450 int32_t CFGAS_GEFont::GetItalicAngle() const { | 440 int32_t CFGAS_GEFont::GetItalicAngle() const { |
| 451 if (!m_pFont->GetSubstFont()) { | 441 if (!m_pFont->GetSubstFont()) { |
| 452 return 0; | 442 return 0; |
| 453 } | 443 } |
| 454 return m_pFont->GetSubstFont()->m_ItalicAngle; | 444 return m_pFont->GetSubstFont()->m_ItalicAngle; |
| 455 } | 445 } |
| 456 int32_t CFGAS_GEFont::GetGlyphIndex(FX_WCHAR wUnicode, FX_BOOL bCharCode) { | 446 int32_t CFGAS_GEFont::GetGlyphIndex(FX_WCHAR wUnicode, FX_BOOL bCharCode) { |
| 457 return GetGlyphIndex(wUnicode, TRUE, NULL, bCharCode); | 447 return GetGlyphIndex(wUnicode, TRUE, nullptr, bCharCode); |
| 458 } | 448 } |
| 459 int32_t CFGAS_GEFont::GetGlyphIndex(FX_WCHAR wUnicode, | 449 int32_t CFGAS_GEFont::GetGlyphIndex(FX_WCHAR wUnicode, |
| 460 FX_BOOL bRecursive, | 450 FX_BOOL bRecursive, |
| 461 IFGAS_Font** ppFont, | 451 IFGAS_Font** ppFont, |
| 462 FX_BOOL bCharCode) { | 452 FX_BOOL bCharCode) { |
| 463 ASSERT(m_pFontEncoding != NULL); | |
| 464 int32_t iGlyphIndex = m_pFontEncoding->GlyphFromCharCode(wUnicode); | 453 int32_t iGlyphIndex = m_pFontEncoding->GlyphFromCharCode(wUnicode); |
| 465 if (iGlyphIndex > 0) { | 454 if (iGlyphIndex > 0) { |
| 466 if (ppFont != NULL) { | 455 if (ppFont) |
| 467 *ppFont = (IFGAS_Font*)this; | 456 *ppFont = (IFGAS_Font*)this; |
| 468 } | |
| 469 return iGlyphIndex; | 457 return iGlyphIndex; |
| 470 } | 458 } |
| 471 const FGAS_FONTUSB* pFontUSB = FGAS_GetUnicodeBitField(wUnicode); | 459 const FGAS_FONTUSB* pFontUSB = FGAS_GetUnicodeBitField(wUnicode); |
| 472 if (pFontUSB == NULL) { | 460 if (!pFontUSB) |
| 473 return 0xFFFF; | 461 return 0xFFFF; |
| 474 } | 462 |
| 475 uint16_t wBitField = pFontUSB->wBitField; | 463 uint16_t wBitField = pFontUSB->wBitField; |
| 476 if (wBitField >= 128) { | 464 if (wBitField >= 128) { |
| 477 return 0xFFFF; | 465 return 0xFFFF; |
| 478 } | 466 } |
| 479 auto it = m_FontMapper.find(wUnicode); | 467 auto it = m_FontMapper.find(wUnicode); |
| 480 IFGAS_Font* pFont = it != m_FontMapper.end() ? it->second : nullptr; | 468 IFGAS_Font* pFont = it != m_FontMapper.end() ? it->second : nullptr; |
| 481 if (pFont && pFont != this) { | 469 if (pFont && pFont != this) { |
| 482 iGlyphIndex = | 470 iGlyphIndex = ((CFGAS_GEFont*)pFont) |
| 483 ((CFGAS_GEFont*)pFont)->GetGlyphIndex(wUnicode, FALSE, NULL, bCharCode); | 471 ->GetGlyphIndex(wUnicode, FALSE, nullptr, bCharCode); |
| 484 if (iGlyphIndex != 0xFFFF) { | 472 if (iGlyphIndex != 0xFFFF) { |
| 485 int32_t i = m_SubstFonts.Find(pFont); | 473 int32_t i = m_SubstFonts.Find(pFont); |
| 486 if (i > -1) { | 474 if (i > -1) { |
| 487 iGlyphIndex |= ((i + 1) << 24); | 475 iGlyphIndex |= ((i + 1) << 24); |
| 488 if (ppFont) | 476 if (ppFont) |
| 489 *ppFont = pFont; | 477 *ppFont = pFont; |
| 490 return iGlyphIndex; | 478 return iGlyphIndex; |
| 491 } | 479 } |
| 492 } | 480 } |
| 493 } | 481 } |
| 494 if (m_pFontMgr && bRecursive) { | 482 if (m_pFontMgr && bRecursive) { |
| 495 CFX_WideString wsFamily; | 483 CFX_WideString wsFamily; |
| 496 GetFamilyName(wsFamily); | 484 GetFamilyName(wsFamily); |
| 497 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 485 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 498 pFont = m_pFontMgr->GetDefFontByUnicode(wUnicode, GetFontStyles(), | 486 pFont = m_pFontMgr->GetDefFontByUnicode(wUnicode, GetFontStyles(), |
| 499 wsFamily.c_str()); | 487 wsFamily.c_str()); |
| 500 #else | 488 #else |
| 501 pFont = m_pFontMgr->GetFontByUnicode(wUnicode, GetFontStyles(), | 489 pFont = m_pFontMgr->GetFontByUnicode(wUnicode, GetFontStyles(), |
| 502 wsFamily.c_str()); | 490 wsFamily.c_str()); |
| 503 if (!pFont) | 491 if (!pFont) |
| 504 pFont = m_pFontMgr->GetFontByUnicode(wUnicode, GetFontStyles(), NULL); | 492 pFont = m_pFontMgr->GetFontByUnicode(wUnicode, GetFontStyles(), nullptr); |
| 505 #endif | 493 #endif |
| 506 if (pFont) { | 494 if (pFont) { |
| 507 if (pFont == this) { | 495 if (pFont == this) { |
| 508 pFont->Release(); | 496 pFont->Release(); |
| 509 return 0xFFFF; | 497 return 0xFFFF; |
| 510 } | 498 } |
| 511 m_FontMapper[wUnicode] = pFont; | 499 m_FontMapper[wUnicode] = pFont; |
| 512 int32_t i = m_SubstFonts.GetSize(); | 500 int32_t i = m_SubstFonts.GetSize(); |
| 513 m_SubstFonts.Add(pFont); | 501 m_SubstFonts.Add(pFont); |
| 514 iGlyphIndex = ((CFGAS_GEFont*)pFont) | 502 iGlyphIndex = ((CFGAS_GEFont*)pFont) |
| 515 ->GetGlyphIndex(wUnicode, FALSE, NULL, bCharCode); | 503 ->GetGlyphIndex(wUnicode, FALSE, nullptr, bCharCode); |
| 516 if (iGlyphIndex != 0xFFFF) { | 504 if (iGlyphIndex != 0xFFFF) { |
| 517 iGlyphIndex |= ((i + 1) << 24); | 505 iGlyphIndex |= ((i + 1) << 24); |
| 518 if (ppFont) | 506 if (ppFont) |
| 519 *ppFont = pFont; | 507 *ppFont = pFont; |
| 520 return iGlyphIndex; | 508 return iGlyphIndex; |
| 521 } | 509 } |
| 522 } | 510 } |
| 523 } | 511 } |
| 524 return 0xFFFF; | 512 return 0xFFFF; |
| 525 } | 513 } |
| 526 int32_t CFGAS_GEFont::GetAscent() const { | 514 int32_t CFGAS_GEFont::GetAscent() const { |
| 527 return m_pFont->GetAscent(); | 515 return m_pFont->GetAscent(); |
| 528 } | 516 } |
| 529 int32_t CFGAS_GEFont::GetDescent() const { | 517 int32_t CFGAS_GEFont::GetDescent() const { |
| 530 return m_pFont->GetDescent(); | 518 return m_pFont->GetDescent(); |
| 531 } | 519 } |
| 532 void CFGAS_GEFont::Reset() { | 520 void CFGAS_GEFont::Reset() { |
| 533 int32_t iCount = m_SubstFonts.GetSize(); | 521 int32_t iCount = m_SubstFonts.GetSize(); |
| 534 for (int32_t i = 0; i < iCount; i++) { | 522 for (int32_t i = 0; i < iCount; i++) { |
| 535 IFGAS_Font* pFont = m_SubstFonts[i]; | 523 IFGAS_Font* pFont = m_SubstFonts[i]; |
| 536 ((CFGAS_GEFont*)pFont)->Reset(); | 524 ((CFGAS_GEFont*)pFont)->Reset(); |
| 537 } | 525 } |
| 538 if (m_pCharWidthMap != NULL) { | 526 if (m_pCharWidthMap) |
| 539 m_pCharWidthMap->RemoveAll(); | 527 m_pCharWidthMap->RemoveAll(); |
| 540 } | 528 if (m_pBBoxMap) |
| 541 if (m_pBBoxMap != NULL) { | |
| 542 m_pBBoxMap->RemoveAll(); | 529 m_pBBoxMap->RemoveAll(); |
| 543 } | 530 if (m_pRectArray) |
| 544 if (m_pRectArray != NULL) { | |
| 545 m_pRectArray->RemoveAll(); | 531 m_pRectArray->RemoveAll(); |
| 546 } | |
| 547 } | 532 } |
| 548 IFGAS_Font* CFGAS_GEFont::GetSubstFont(int32_t iGlyphIndex) const { | 533 IFGAS_Font* CFGAS_GEFont::GetSubstFont(int32_t iGlyphIndex) const { |
| 549 iGlyphIndex = ((uint32_t)iGlyphIndex) >> 24; | 534 iGlyphIndex = ((uint32_t)iGlyphIndex) >> 24; |
| 550 return iGlyphIndex == 0 ? const_cast<CFGAS_GEFont*>(this) | 535 return iGlyphIndex == 0 ? const_cast<CFGAS_GEFont*>(this) |
| 551 : m_SubstFonts[iGlyphIndex - 1]; | 536 : m_SubstFonts[iGlyphIndex - 1]; |
| 552 } | 537 } |
| OLD | NEW |