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" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 m_pFont(NULL), | 76 m_pFont(NULL), |
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(NULL), |
81 m_pFileRead(NULL), | 81 m_pFileRead(NULL), |
82 m_pFontEncoding(NULL), | 82 m_pFontEncoding(NULL), |
83 m_pCharWidthMap(NULL), | 83 m_pCharWidthMap(NULL), |
84 m_pRectArray(NULL), | 84 m_pRectArray(NULL), |
85 m_pBBoxMap(NULL), | 85 m_pBBoxMap(NULL), |
86 m_pProvider(NULL), | 86 m_pProvider(NULL) { |
87 m_wCharSet(0xFFFF) { | |
88 } | 87 } |
89 | 88 |
90 CFGAS_GEFont::CFGAS_GEFont(const CFGAS_GEFont& src, uint32_t dwFontStyles) | 89 CFGAS_GEFont::CFGAS_GEFont(const CFGAS_GEFont& src, uint32_t dwFontStyles) |
91 : | 90 : |
92 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 91 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
93 m_bUseLogFontStyle(FALSE), | 92 m_bUseLogFontStyle(FALSE), |
94 m_dwLogFontStyle(0), | 93 m_dwLogFontStyle(0), |
95 #endif | 94 #endif |
96 m_pFont(NULL), | 95 m_pFont(NULL), |
97 m_pFontMgr(src.m_pFontMgr), | 96 m_pFontMgr(src.m_pFontMgr), |
98 m_iRefCount(1), | 97 m_iRefCount(1), |
99 m_bExtFont(FALSE), | 98 m_bExtFont(FALSE), |
100 m_pStream(NULL), | 99 m_pStream(NULL), |
101 m_pFileRead(NULL), | 100 m_pFileRead(NULL), |
102 m_pFontEncoding(NULL), | 101 m_pFontEncoding(NULL), |
103 m_pCharWidthMap(NULL), | 102 m_pCharWidthMap(NULL), |
104 m_pRectArray(NULL), | 103 m_pRectArray(NULL), |
105 m_pBBoxMap(NULL), | 104 m_pBBoxMap(NULL), |
106 m_pProvider(NULL), | 105 m_pProvider(NULL) { |
107 m_wCharSet(0xFFFF) { | |
108 ASSERT(src.m_pFont); | 106 ASSERT(src.m_pFont); |
109 m_pFont = new CFX_Font; | 107 m_pFont = new CFX_Font; |
110 m_pFont->LoadClone(src.m_pFont); | 108 m_pFont->LoadClone(src.m_pFont); |
111 CFX_SubstFont* pSubst = m_pFont->GetSubstFont(); | 109 CFX_SubstFont* pSubst = m_pFont->GetSubstFont(); |
112 if (!pSubst) { | 110 if (!pSubst) { |
113 pSubst = new CFX_SubstFont; | 111 pSubst = new CFX_SubstFont; |
114 m_pFont->SetSubstFont(pSubst); | 112 m_pFont->SetSubstFont(pSubst); |
115 } | 113 } |
116 pSubst->m_Weight = | 114 pSubst->m_Weight = |
117 (dwFontStyles & FX_FONTSTYLE_Bold) ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL; | 115 (dwFontStyles & FX_FONTSTYLE_Bold) ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 dwFlags |= FXFONT_ITALIC; | 180 dwFlags |= FXFONT_ITALIC; |
183 } | 181 } |
184 if (dwFontStyles & FX_FONTSTYLE_Bold) { | 182 if (dwFontStyles & FX_FONTSTYLE_Bold) { |
185 dwFlags |= FXFONT_BOLD; | 183 dwFlags |= FXFONT_BOLD; |
186 } | 184 } |
187 if (dwFontStyles & FX_FONTSTYLE_ExactMatch) { | 185 if (dwFontStyles & FX_FONTSTYLE_ExactMatch) { |
188 dwFlags |= FXFONT_EXACTMATCH; | 186 dwFlags |= FXFONT_EXACTMATCH; |
189 } | 187 } |
190 int32_t iWeight = | 188 int32_t iWeight = |
191 (dwFontStyles & FX_FONTSTYLE_Bold) ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL; | 189 (dwFontStyles & FX_FONTSTYLE_Bold) ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL; |
192 uint16_t wCharSet = FX_GetCharsetFromCodePage(wCodePage); | |
193 if (wCharSet == 0xFFFF) { | |
194 wCharSet = FXSYS_GetACP(); | |
195 } | |
196 m_wCharSet = wCharSet; | |
197 m_pFont = new CFX_Font; | 190 m_pFont = new CFX_Font; |
198 if ((dwFlags & FXFONT_ITALIC) && (dwFlags & FXFONT_BOLD)) { | 191 if ((dwFlags & FXFONT_ITALIC) && (dwFlags & FXFONT_BOLD)) { |
199 csFontFamily += ",BoldItalic"; | 192 csFontFamily += ",BoldItalic"; |
200 } else if (dwFlags & FXFONT_BOLD) { | 193 } else if (dwFlags & FXFONT_BOLD) { |
201 csFontFamily += ",Bold"; | 194 csFontFamily += ",Bold"; |
202 } else if (dwFlags & FXFONT_ITALIC) { | 195 } else if (dwFlags & FXFONT_ITALIC) { |
203 csFontFamily += ",Italic"; | 196 csFontFamily += ",Italic"; |
204 } | 197 } |
205 m_pFont->LoadSubst(csFontFamily, TRUE, dwFlags, iWeight, 0, wCodePage); | 198 m_pFont->LoadSubst(csFontFamily, TRUE, dwFlags, iWeight, 0, wCodePage); |
206 FX_BOOL bRet = m_pFont->GetFace() != nullptr; | 199 if (!m_pFont->GetFace()) |
207 if (bRet) { | 200 return false; |
208 bRet = InitFont(); | 201 return InitFont(); |
209 } | |
210 return bRet; | |
211 } | 202 } |
212 | 203 |
213 FX_BOOL CFGAS_GEFont::LoadFontInternal(const uint8_t* pBuffer, int32_t length) { | 204 FX_BOOL CFGAS_GEFont::LoadFontInternal(const uint8_t* pBuffer, int32_t length) { |
214 if (m_pFont) { | 205 if (m_pFont) |
215 return FALSE; | 206 return FALSE; |
216 } | 207 |
217 m_pFont = new CFX_Font; | 208 m_pFont = new CFX_Font; |
218 FX_BOOL bRet = m_pFont->LoadEmbedded(pBuffer, length); | 209 if (!m_pFont->LoadEmbedded(pBuffer, length)) |
219 if (bRet) { | 210 return FALSE; |
220 bRet = InitFont(); | 211 return InitFont(); |
221 } | |
222 m_wCharSet = 0xFFFF; | |
223 return bRet; | |
224 } | 212 } |
225 | 213 |
226 FX_BOOL CFGAS_GEFont::LoadFontInternal(IFX_Stream* pFontStream, | 214 FX_BOOL CFGAS_GEFont::LoadFontInternal(IFX_Stream* pFontStream, |
227 FX_BOOL bSaveStream) { | 215 FX_BOOL bSaveStream) { |
228 if (m_pFont || m_pFileRead || !pFontStream || pFontStream->GetLength() < 1) { | 216 if (m_pFont || m_pFileRead || !pFontStream || pFontStream->GetLength() < 1) { |
229 return FALSE; | 217 return FALSE; |
230 } | 218 } |
231 if (bSaveStream) { | 219 if (bSaveStream) { |
232 m_pStream = pFontStream; | 220 m_pStream = pFontStream; |
233 } | 221 } |
234 m_pFileRead = FX_CreateFileRead(pFontStream); | 222 m_pFileRead = FX_CreateFileRead(pFontStream); |
235 m_pFont = new CFX_Font; | 223 m_pFont = new CFX_Font; |
236 FX_BOOL bRet = m_pFont->LoadFile(m_pFileRead); | 224 FX_BOOL bRet = m_pFont->LoadFile(m_pFileRead); |
237 if (bRet) { | 225 if (bRet) { |
238 bRet = InitFont(); | 226 bRet = InitFont(); |
239 } else { | 227 } else { |
240 m_pFileRead->Release(); | 228 m_pFileRead->Release(); |
241 m_pFileRead = nullptr; | 229 m_pFileRead = nullptr; |
242 } | 230 } |
243 m_wCharSet = 0xFFFF; | |
244 return bRet; | 231 return bRet; |
245 } | 232 } |
246 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 233 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
247 | 234 |
248 FX_BOOL CFGAS_GEFont::LoadFontInternal(CFX_Font* pExtFont) { | 235 FX_BOOL CFGAS_GEFont::LoadFontInternal(CFX_Font* pExtFont) { |
249 if (m_pFont || !pExtFont) { | 236 if (m_pFont || !pExtFont) { |
250 return FALSE; | 237 return FALSE; |
251 } | 238 } |
252 m_pFont = pExtFont; | 239 m_pFont = pExtFont; |
253 m_bExtFont = TRUE; | 240 m_bExtFont = TRUE; |
254 m_wCharSet = 0xFFFF; | |
255 return InitFont(); | 241 return InitFont(); |
256 } | 242 } |
257 | 243 |
258 FX_BOOL CFGAS_GEFont::InitFont() { | 244 FX_BOOL CFGAS_GEFont::InitFont() { |
259 if (!m_pFont) | 245 if (!m_pFont) |
260 return FALSE; | 246 return FALSE; |
261 if (!m_pFontEncoding) { | 247 if (!m_pFontEncoding) { |
262 m_pFontEncoding = FX_CreateFontEncodingEx(m_pFont); | 248 m_pFontEncoding = FX_CreateFontEncodingEx(m_pFont); |
263 if (!m_pFontEncoding) | 249 if (!m_pFontEncoding) |
264 return FALSE; | 250 return FALSE; |
265 } | 251 } |
266 if (!m_pCharWidthMap) | 252 if (!m_pCharWidthMap) |
267 m_pCharWidthMap = new CFX_WordDiscreteArray(1024); | 253 m_pCharWidthMap = new CFX_WordDiscreteArray(1024); |
268 if (!m_pRectArray) | 254 if (!m_pRectArray) |
269 m_pRectArray = new CFX_MassArrayTemplate<CFX_Rect>(16); | 255 m_pRectArray = new CFX_MassArrayTemplate<CFX_Rect>(16); |
270 if (!m_pBBoxMap) | 256 if (!m_pBBoxMap) |
271 m_pBBoxMap = new CFX_MapPtrToPtr(16); | 257 m_pBBoxMap = new CFX_MapPtrToPtr(16); |
272 | 258 |
273 return TRUE; | 259 return TRUE; |
274 } | 260 } |
| 261 |
275 CFGAS_GEFont* CFGAS_GEFont::Derive(uint32_t dwFontStyles, uint16_t wCodePage) { | 262 CFGAS_GEFont* CFGAS_GEFont::Derive(uint32_t dwFontStyles, uint16_t wCodePage) { |
276 if (GetFontStyles() == dwFontStyles) { | 263 if (GetFontStyles() == dwFontStyles) |
277 return Retain(); | 264 return Retain(); |
278 } | |
279 return new CFGAS_GEFont(*this, dwFontStyles); | 265 return new CFGAS_GEFont(*this, dwFontStyles); |
280 } | 266 } |
281 uint8_t CFGAS_GEFont::GetCharSet() const { | 267 |
282 if (m_wCharSet != 0xFFFF) { | |
283 return (uint8_t)m_wCharSet; | |
284 } | |
285 if (!m_pFont->GetSubstFont()) { | |
286 return FX_CHARSET_Default; | |
287 } | |
288 return m_pFont->GetSubstFont()->m_Charset; | |
289 } | |
290 void CFGAS_GEFont::GetFamilyName(CFX_WideString& wsFamily) const { | 268 void CFGAS_GEFont::GetFamilyName(CFX_WideString& wsFamily) const { |
291 if (!m_pFont->GetSubstFont() || | 269 if (!m_pFont->GetSubstFont() || |
292 m_pFont->GetSubstFont()->m_Family.GetLength() == 0) { | 270 m_pFont->GetSubstFont()->m_Family.GetLength() == 0) { |
293 wsFamily = CFX_WideString::FromLocal(m_pFont->GetFamilyName().AsStringC()); | 271 wsFamily = CFX_WideString::FromLocal(m_pFont->GetFamilyName().AsStringC()); |
294 } else { | 272 } else { |
295 wsFamily = CFX_WideString::FromLocal( | 273 wsFamily = CFX_WideString::FromLocal( |
296 m_pFont->GetSubstFont()->m_Family.AsStringC()); | 274 m_pFont->GetSubstFont()->m_Family.AsStringC()); |
297 } | 275 } |
298 } | 276 } |
299 | 277 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 } | 474 } |
497 if (m_pRectArray != NULL) { | 475 if (m_pRectArray != NULL) { |
498 m_pRectArray->RemoveAll(); | 476 m_pRectArray->RemoveAll(); |
499 } | 477 } |
500 } | 478 } |
501 CFGAS_GEFont* CFGAS_GEFont::GetSubstFont(int32_t iGlyphIndex) const { | 479 CFGAS_GEFont* CFGAS_GEFont::GetSubstFont(int32_t iGlyphIndex) const { |
502 iGlyphIndex = ((uint32_t)iGlyphIndex) >> 24; | 480 iGlyphIndex = ((uint32_t)iGlyphIndex) >> 24; |
503 return iGlyphIndex == 0 ? const_cast<CFGAS_GEFont*>(this) | 481 return iGlyphIndex == 0 ? const_cast<CFGAS_GEFont*>(this) |
504 : m_SubstFonts[iGlyphIndex - 1]; | 482 : m_SubstFonts[iGlyphIndex - 1]; |
505 } | 483 } |
OLD | NEW |