| 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 "core/fxge/include/cfx_substfont.h" | 9 #include "core/fxge/include/cfx_substfont.h" |
| 10 #include "core/fxge/include/cfx_unicodeencoding.h" | 10 #include "core/fxge/include/cfx_unicodeencoding.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); | 27 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); |
| 28 if (!pFont->LoadFontInternal(pszFontFamily, dwFontStyles, wCodePage)) { | 28 if (!pFont->LoadFontInternal(pszFontFamily, dwFontStyles, wCodePage)) { |
| 29 pFont->Release(); | 29 pFont->Release(); |
| 30 return nullptr; | 30 return nullptr; |
| 31 } | 31 } |
| 32 return pFont; | 32 return pFont; |
| 33 #endif | 33 #endif |
| 34 } | 34 } |
| 35 | 35 |
| 36 // static | 36 // static |
| 37 CFGAS_GEFont* CFGAS_GEFont::LoadFont(CFX_Font* pExternalFont, | 37 CFGAS_GEFont* CFGAS_GEFont::LoadFont(CFX_Font* pExtFont, |
| 38 IFGAS_FontMgr* pFontMgr) { | 38 IFGAS_FontMgr* pFontMgr) { |
| 39 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); | 39 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); |
| 40 if (!pFont->LoadFontInternal(pExternalFont)) { | 40 if (!pFont->LoadFontInternal(pExtFont)) { |
| 41 pFont->Release(); | 41 pFont->Release(); |
| 42 return nullptr; | 42 return nullptr; |
| 43 } | 43 } |
| 44 return pFont; | |
| 45 } | |
| 46 | |
| 47 // static | |
| 48 CFGAS_GEFont* CFGAS_GEFont::LoadFont(std::unique_ptr<CFX_Font> pInternalFont, | |
| 49 IFGAS_FontMgr* pFontMgr) { | |
| 50 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); | |
| 51 if (!pFont->LoadFontInternal(std::move(pInternalFont))) { | |
| 52 pFont->Release(); | |
| 53 return nullptr; | |
| 54 } | |
| 55 return pFont; | 44 return pFont; |
| 56 } | 45 } |
| 57 | 46 |
| 58 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 47 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 59 // static | 48 // static |
| 60 CFGAS_GEFont* CFGAS_GEFont::LoadFont(const uint8_t* pBuffer, | 49 CFGAS_GEFont* CFGAS_GEFont::LoadFont(const uint8_t* pBuffer, |
| 61 int32_t iLength, | 50 int32_t iLength, |
| 62 IFGAS_FontMgr* pFontMgr) { | 51 IFGAS_FontMgr* pFontMgr) { |
| 63 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); | 52 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); |
| 64 if (!pFont->LoadFontInternal(pBuffer, iLength)) { | 53 if (!pFont->LoadFontInternal(pBuffer, iLength)) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 83 | 72 |
| 84 CFGAS_GEFont::CFGAS_GEFont(IFGAS_FontMgr* pFontMgr) | 73 CFGAS_GEFont::CFGAS_GEFont(IFGAS_FontMgr* pFontMgr) |
| 85 : | 74 : |
| 86 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 75 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
| 87 m_bUseLogFontStyle(FALSE), | 76 m_bUseLogFontStyle(FALSE), |
| 88 m_dwLogFontStyle(0), | 77 m_dwLogFontStyle(0), |
| 89 #endif | 78 #endif |
| 90 m_pFont(nullptr), | 79 m_pFont(nullptr), |
| 91 m_pFontMgr(pFontMgr), | 80 m_pFontMgr(pFontMgr), |
| 92 m_iRefCount(1), | 81 m_iRefCount(1), |
| 93 m_bExternalFont(false), | 82 m_bExtFont(FALSE), |
| 94 m_pProvider(nullptr) { | 83 m_pProvider(nullptr) { |
| 95 } | 84 } |
| 96 | 85 |
| 97 CFGAS_GEFont::CFGAS_GEFont(const CFGAS_GEFont& src, uint32_t dwFontStyles) | 86 CFGAS_GEFont::CFGAS_GEFont(const CFGAS_GEFont& src, uint32_t dwFontStyles) |
| 98 : | 87 : |
| 99 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 88 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
| 100 m_bUseLogFontStyle(FALSE), | 89 m_bUseLogFontStyle(FALSE), |
| 101 m_dwLogFontStyle(0), | 90 m_dwLogFontStyle(0), |
| 102 #endif | 91 #endif |
| 103 m_pFont(nullptr), | 92 m_pFont(nullptr), |
| 104 m_pFontMgr(src.m_pFontMgr), | 93 m_pFontMgr(src.m_pFontMgr), |
| 105 m_iRefCount(1), | 94 m_iRefCount(1), |
| 106 m_bExternalFont(false), | 95 m_bExtFont(FALSE), |
| 107 m_pProvider(nullptr) { | 96 m_pProvider(nullptr) { |
| 108 ASSERT(src.m_pFont); | 97 ASSERT(src.m_pFont); |
| 109 m_pFont = new CFX_Font; | 98 m_pFont = new CFX_Font; |
| 110 m_pFont->LoadClone(src.m_pFont); | 99 m_pFont->LoadClone(src.m_pFont); |
| 111 CFX_SubstFont* pSubst = m_pFont->GetSubstFont(); | 100 CFX_SubstFont* pSubst = m_pFont->GetSubstFont(); |
| 112 if (!pSubst) { | 101 if (!pSubst) { |
| 113 pSubst = new CFX_SubstFont; | 102 pSubst = new CFX_SubstFont; |
| 114 m_pFont->SetSubstFont(std::unique_ptr<CFX_SubstFont>(pSubst)); | 103 m_pFont->SetSubstFont(std::unique_ptr<CFX_SubstFont>(pSubst)); |
| 115 } | 104 } |
| 116 pSubst->m_Weight = | 105 pSubst->m_Weight = |
| 117 (dwFontStyles & FX_FONTSTYLE_Bold) ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL; | 106 (dwFontStyles & FX_FONTSTYLE_Bold) ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL; |
| 118 if (dwFontStyles & FX_FONTSTYLE_Italic) { | 107 if (dwFontStyles & FX_FONTSTYLE_Italic) { |
| 119 pSubst->m_SubstFlags |= FXFONT_SUBST_ITALIC; | 108 pSubst->m_SubstFlags |= FXFONT_SUBST_ITALIC; |
| 120 } | 109 } |
| 121 InitFont(); | 110 InitFont(); |
| 122 } | 111 } |
| 123 | 112 |
| 124 CFGAS_GEFont::~CFGAS_GEFont() { | 113 CFGAS_GEFont::~CFGAS_GEFont() { |
| 125 for (int32_t i = 0; i < m_SubstFonts.GetSize(); i++) | 114 for (int32_t i = 0; i < m_SubstFonts.GetSize(); i++) |
| 126 m_SubstFonts[i]->Release(); | 115 m_SubstFonts[i]->Release(); |
| 127 | 116 |
| 128 m_SubstFonts.RemoveAll(); | 117 m_SubstFonts.RemoveAll(); |
| 129 m_FontMapper.clear(); | 118 m_FontMapper.clear(); |
| 130 | 119 |
| 131 if (!m_bExternalFont) | 120 if (!m_bExtFont) |
| 132 delete m_pFont; | 121 delete m_pFont; |
| 133 } | 122 } |
| 134 | 123 |
| 135 void CFGAS_GEFont::Release() { | 124 void CFGAS_GEFont::Release() { |
| 136 if (--m_iRefCount < 1) { | 125 if (--m_iRefCount < 1) { |
| 137 if (m_pFontMgr) { | 126 if (m_pFontMgr) { |
| 138 m_pFontMgr->RemoveFont(this); | 127 m_pFontMgr->RemoveFont(this); |
| 139 } | 128 } |
| 140 delete this; | 129 delete this; |
| 141 } | 130 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 | 202 |
| 214 m_pFileRead.reset(FX_CreateFileRead(pFontStream, FALSE)); | 203 m_pFileRead.reset(FX_CreateFileRead(pFontStream, FALSE)); |
| 215 m_pFont = new CFX_Font; | 204 m_pFont = new CFX_Font; |
| 216 if (m_pFont->LoadFile(m_pFileRead.get())) | 205 if (m_pFont->LoadFile(m_pFileRead.get())) |
| 217 return InitFont(); | 206 return InitFont(); |
| 218 m_pFileRead.reset(); | 207 m_pFileRead.reset(); |
| 219 return FALSE; | 208 return FALSE; |
| 220 } | 209 } |
| 221 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 210 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 222 | 211 |
| 223 FX_BOOL CFGAS_GEFont::LoadFontInternal(CFX_Font* pExternalFont) { | 212 FX_BOOL CFGAS_GEFont::LoadFontInternal(CFX_Font* pExtFont) { |
| 224 if (m_pFont || !pExternalFont) | 213 if (m_pFont || !pExtFont) { |
| 225 return FALSE; | 214 return FALSE; |
| 226 | 215 } |
| 227 m_pFont = pExternalFont; | 216 m_pFont = pExtFont; |
| 228 m_bExternalFont = true; | 217 m_bExtFont = TRUE; |
| 229 return InitFont(); | 218 return InitFont(); |
| 230 } | 219 } |
| 231 | 220 |
| 232 FX_BOOL CFGAS_GEFont::LoadFontInternal( | |
| 233 std::unique_ptr<CFX_Font> pInternalFont) { | |
| 234 if (m_pFont || !pInternalFont) | |
| 235 return FALSE; | |
| 236 | |
| 237 m_pFont = pInternalFont.release(); | |
| 238 m_bExternalFont = false; | |
| 239 return InitFont(); | |
| 240 } | |
| 241 | |
| 242 FX_BOOL CFGAS_GEFont::InitFont() { | 221 FX_BOOL CFGAS_GEFont::InitFont() { |
| 243 if (!m_pFont) | 222 if (!m_pFont) |
| 244 return FALSE; | 223 return FALSE; |
| 245 if (!m_pFontEncoding) { | 224 if (!m_pFontEncoding) { |
| 246 m_pFontEncoding.reset(FX_CreateFontEncodingEx(m_pFont)); | 225 m_pFontEncoding.reset(FX_CreateFontEncodingEx(m_pFont)); |
| 247 if (!m_pFontEncoding) | 226 if (!m_pFontEncoding) |
| 248 return FALSE; | 227 return FALSE; |
| 249 } | 228 } |
| 250 if (!m_pCharWidthMap) | 229 if (!m_pCharWidthMap) |
| 251 m_pCharWidthMap.reset(new CFX_DiscreteArrayTemplate<uint16_t>(1024)); | 230 m_pCharWidthMap.reset(new CFX_DiscreteArrayTemplate<uint16_t>(1024)); |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 } | 451 } |
| 473 if (m_pRectArray) { | 452 if (m_pRectArray) { |
| 474 m_pRectArray->RemoveAll(FALSE); | 453 m_pRectArray->RemoveAll(FALSE); |
| 475 } | 454 } |
| 476 } | 455 } |
| 477 CFGAS_GEFont* CFGAS_GEFont::GetSubstFont(int32_t iGlyphIndex) const { | 456 CFGAS_GEFont* CFGAS_GEFont::GetSubstFont(int32_t iGlyphIndex) const { |
| 478 iGlyphIndex = ((uint32_t)iGlyphIndex) >> 24; | 457 iGlyphIndex = ((uint32_t)iGlyphIndex) >> 24; |
| 479 return iGlyphIndex == 0 ? const_cast<CFGAS_GEFont*>(this) | 458 return iGlyphIndex == 0 ? const_cast<CFGAS_GEFont*>(this) |
| 480 : m_SubstFonts[iGlyphIndex - 1]; | 459 : m_SubstFonts[iGlyphIndex - 1]; |
| 481 } | 460 } |
| OLD | NEW |