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* pExtFont, | 37 CFGAS_GEFont* CFGAS_GEFont::LoadFont(CFX_Font* pExternalFont, |
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(pExtFont)) { | 40 if (!pFont->LoadFontInternal(pExternalFont)) { |
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 } |
44 return pFont; | 55 return pFont; |
45 } | 56 } |
46 | 57 |
47 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 58 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
48 // static | 59 // static |
49 CFGAS_GEFont* CFGAS_GEFont::LoadFont(const uint8_t* pBuffer, | 60 CFGAS_GEFont* CFGAS_GEFont::LoadFont(const uint8_t* pBuffer, |
50 int32_t iLength, | 61 int32_t iLength, |
51 IFGAS_FontMgr* pFontMgr) { | 62 IFGAS_FontMgr* pFontMgr) { |
52 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); | 63 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); |
53 if (!pFont->LoadFontInternal(pBuffer, iLength)) { | 64 if (!pFont->LoadFontInternal(pBuffer, iLength)) { |
(...skipping 19 matching lines...) Expand all Loading... |
73 CFGAS_GEFont::CFGAS_GEFont(IFGAS_FontMgr* pFontMgr) | 84 CFGAS_GEFont::CFGAS_GEFont(IFGAS_FontMgr* pFontMgr) |
74 : | 85 : |
75 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 86 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
76 m_bUseLogFontStyle(FALSE), | 87 m_bUseLogFontStyle(FALSE), |
77 m_dwLogFontStyle(0), | 88 m_dwLogFontStyle(0), |
78 #endif | 89 #endif |
79 m_pFont(nullptr), | 90 m_pFont(nullptr), |
80 m_pSrcFont(nullptr), | 91 m_pSrcFont(nullptr), |
81 m_pFontMgr(pFontMgr), | 92 m_pFontMgr(pFontMgr), |
82 m_iRefCount(1), | 93 m_iRefCount(1), |
83 m_bExtFont(FALSE), | 94 m_bExternalFont(false), |
84 m_pProvider(nullptr) { | 95 m_pProvider(nullptr) { |
85 } | 96 } |
86 | 97 |
87 CFGAS_GEFont::CFGAS_GEFont(CFGAS_GEFont* src, uint32_t dwFontStyles) | 98 CFGAS_GEFont::CFGAS_GEFont(CFGAS_GEFont* src, uint32_t dwFontStyles) |
88 : | 99 : |
89 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 100 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
90 m_bUseLogFontStyle(FALSE), | 101 m_bUseLogFontStyle(FALSE), |
91 m_dwLogFontStyle(0), | 102 m_dwLogFontStyle(0), |
92 #endif | 103 #endif |
93 m_pFont(nullptr), | 104 m_pFont(nullptr), |
94 m_pSrcFont(src), | 105 m_pSrcFont(src), |
95 m_pFontMgr(src->m_pFontMgr), | 106 m_pFontMgr(src->m_pFontMgr), |
96 m_iRefCount(1), | 107 m_iRefCount(1), |
97 m_bExtFont(FALSE), | 108 m_bExternalFont(false), |
98 m_pProvider(nullptr) { | 109 m_pProvider(nullptr) { |
99 ASSERT(m_pSrcFont->m_pFont); | 110 ASSERT(m_pSrcFont->m_pFont); |
100 m_pSrcFont->Retain(); | 111 m_pSrcFont->Retain(); |
101 m_pFont = new CFX_Font; | 112 m_pFont = new CFX_Font; |
102 m_pFont->LoadClone(m_pSrcFont->m_pFont); | 113 m_pFont->LoadClone(m_pSrcFont->m_pFont); |
103 CFX_SubstFont* pSubst = m_pFont->GetSubstFont(); | 114 CFX_SubstFont* pSubst = m_pFont->GetSubstFont(); |
104 if (!pSubst) { | 115 if (!pSubst) { |
105 pSubst = new CFX_SubstFont; | 116 pSubst = new CFX_SubstFont; |
106 m_pFont->SetSubstFont(std::unique_ptr<CFX_SubstFont>(pSubst)); | 117 m_pFont->SetSubstFont(std::unique_ptr<CFX_SubstFont>(pSubst)); |
107 } | 118 } |
108 pSubst->m_Weight = | 119 pSubst->m_Weight = |
109 (dwFontStyles & FX_FONTSTYLE_Bold) ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL; | 120 (dwFontStyles & FX_FONTSTYLE_Bold) ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL; |
110 if (dwFontStyles & FX_FONTSTYLE_Italic) { | 121 if (dwFontStyles & FX_FONTSTYLE_Italic) { |
111 pSubst->m_SubstFlags |= FXFONT_SUBST_ITALIC; | 122 pSubst->m_SubstFlags |= FXFONT_SUBST_ITALIC; |
112 } | 123 } |
113 InitFont(); | 124 InitFont(); |
114 } | 125 } |
115 | 126 |
116 CFGAS_GEFont::~CFGAS_GEFont() { | 127 CFGAS_GEFont::~CFGAS_GEFont() { |
117 for (int32_t i = 0; i < m_SubstFonts.GetSize(); i++) | 128 for (int32_t i = 0; i < m_SubstFonts.GetSize(); i++) |
118 m_SubstFonts[i]->Release(); | 129 m_SubstFonts[i]->Release(); |
119 | 130 |
120 m_SubstFonts.RemoveAll(); | 131 m_SubstFonts.RemoveAll(); |
121 m_FontMapper.clear(); | 132 m_FontMapper.clear(); |
122 | 133 |
123 if (!m_bExtFont) | 134 if (!m_bExternalFont) |
124 delete m_pFont; | 135 delete m_pFont; |
125 | 136 |
126 // If it is a shallow copy of another source font, | 137 // If it is a shallow copy of another source font, |
127 // decrease the refcount of the source font. | 138 // decrease the refcount of the source font. |
128 if (m_pSrcFont) | 139 if (m_pSrcFont) |
129 m_pSrcFont->Release(); | 140 m_pSrcFont->Release(); |
130 } | 141 } |
131 | 142 |
132 void CFGAS_GEFont::Release() { | 143 void CFGAS_GEFont::Release() { |
133 if (--m_iRefCount < 1) { | 144 if (--m_iRefCount < 1) { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 | 221 |
211 m_pFileRead.reset(FX_CreateFileRead(pFontStream, FALSE)); | 222 m_pFileRead.reset(FX_CreateFileRead(pFontStream, FALSE)); |
212 m_pFont = new CFX_Font; | 223 m_pFont = new CFX_Font; |
213 if (m_pFont->LoadFile(m_pFileRead.get())) | 224 if (m_pFont->LoadFile(m_pFileRead.get())) |
214 return InitFont(); | 225 return InitFont(); |
215 m_pFileRead.reset(); | 226 m_pFileRead.reset(); |
216 return FALSE; | 227 return FALSE; |
217 } | 228 } |
218 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 229 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
219 | 230 |
220 FX_BOOL CFGAS_GEFont::LoadFontInternal(CFX_Font* pExtFont) { | 231 FX_BOOL CFGAS_GEFont::LoadFontInternal(CFX_Font* pExternalFont) { |
221 if (m_pFont || !pExtFont) { | 232 if (m_pFont || !pExternalFont) |
222 return FALSE; | 233 return FALSE; |
223 } | 234 |
224 m_pFont = pExtFont; | 235 m_pFont = pExternalFont; |
225 m_bExtFont = TRUE; | 236 m_bExternalFont = true; |
226 return InitFont(); | 237 return InitFont(); |
227 } | 238 } |
228 | 239 |
| 240 FX_BOOL CFGAS_GEFont::LoadFontInternal( |
| 241 std::unique_ptr<CFX_Font> pInternalFont) { |
| 242 if (m_pFont || !pInternalFont) |
| 243 return FALSE; |
| 244 |
| 245 m_pFont = pInternalFont.release(); |
| 246 m_bExternalFont = false; |
| 247 return InitFont(); |
| 248 } |
| 249 |
229 FX_BOOL CFGAS_GEFont::InitFont() { | 250 FX_BOOL CFGAS_GEFont::InitFont() { |
230 if (!m_pFont) | 251 if (!m_pFont) |
231 return FALSE; | 252 return FALSE; |
232 if (!m_pFontEncoding) { | 253 if (!m_pFontEncoding) { |
233 m_pFontEncoding.reset(FX_CreateFontEncodingEx(m_pFont)); | 254 m_pFontEncoding.reset(FX_CreateFontEncodingEx(m_pFont)); |
234 if (!m_pFontEncoding) | 255 if (!m_pFontEncoding) |
235 return FALSE; | 256 return FALSE; |
236 } | 257 } |
237 if (!m_pCharWidthMap) | 258 if (!m_pCharWidthMap) |
238 m_pCharWidthMap.reset(new CFX_DiscreteArrayTemplate<uint16_t>(1024)); | 259 m_pCharWidthMap.reset(new CFX_DiscreteArrayTemplate<uint16_t>(1024)); |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 } | 480 } |
460 if (m_pRectArray) { | 481 if (m_pRectArray) { |
461 m_pRectArray->RemoveAll(FALSE); | 482 m_pRectArray->RemoveAll(FALSE); |
462 } | 483 } |
463 } | 484 } |
464 CFGAS_GEFont* CFGAS_GEFont::GetSubstFont(int32_t iGlyphIndex) const { | 485 CFGAS_GEFont* CFGAS_GEFont::GetSubstFont(int32_t iGlyphIndex) const { |
465 iGlyphIndex = ((uint32_t)iGlyphIndex) >> 24; | 486 iGlyphIndex = ((uint32_t)iGlyphIndex) >> 24; |
466 return iGlyphIndex == 0 ? const_cast<CFGAS_GEFont*>(this) | 487 return iGlyphIndex == 0 ? const_cast<CFGAS_GEFont*>(this) |
467 : m_SubstFonts[iGlyphIndex - 1]; | 488 : m_SubstFonts[iGlyphIndex - 1]; |
468 } | 489 } |
OLD | NEW |