Chromium Code Reviews| 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; |
| 201 return InitFont(); | |
| 202 } | |
| 203 | |
| 204 FX_BOOL CFGAS_GEFont::LoadFontInternal(const uint8_t* pBuffer, int32_t length) { | |
| 205 if (m_pFont) | |
| 206 return FALSE; | |
| 207 | |
| 208 m_pFont = new CFX_Font; | |
| 209 FX_BOOL bRet = m_pFont->LoadEmbedded(pBuffer, length); | |
|
dsinclair
2016/06/21 20:43:38
if (!m_pFont->LoadEmbedded(pBuffer, length))
ret
Lei Zhang
2016/06/21 20:46:36
Done.
| |
| 210 if (bRet) | |
| 208 bRet = InitFont(); | 211 bRet = InitFont(); |
| 209 } | |
| 210 return bRet; | 212 return bRet; |
| 211 } | 213 } |
| 212 | 214 |
| 213 FX_BOOL CFGAS_GEFont::LoadFontInternal(const uint8_t* pBuffer, int32_t length) { | |
| 214 if (m_pFont) { | |
| 215 return FALSE; | |
| 216 } | |
| 217 m_pFont = new CFX_Font; | |
| 218 FX_BOOL bRet = m_pFont->LoadEmbedded(pBuffer, length); | |
| 219 if (bRet) { | |
| 220 bRet = InitFont(); | |
| 221 } | |
| 222 m_wCharSet = 0xFFFF; | |
| 223 return bRet; | |
| 224 } | |
| 225 | |
| 226 FX_BOOL CFGAS_GEFont::LoadFontInternal(IFX_Stream* pFontStream, | 215 FX_BOOL CFGAS_GEFont::LoadFontInternal(IFX_Stream* pFontStream, |
| 227 FX_BOOL bSaveStream) { | 216 FX_BOOL bSaveStream) { |
| 228 if (m_pFont || m_pFileRead || !pFontStream || pFontStream->GetLength() < 1) { | 217 if (m_pFont || m_pFileRead || !pFontStream || pFontStream->GetLength() < 1) { |
| 229 return FALSE; | 218 return FALSE; |
| 230 } | 219 } |
| 231 if (bSaveStream) { | 220 if (bSaveStream) { |
| 232 m_pStream = pFontStream; | 221 m_pStream = pFontStream; |
| 233 } | 222 } |
| 234 m_pFileRead = FX_CreateFileRead(pFontStream); | 223 m_pFileRead = FX_CreateFileRead(pFontStream); |
| 235 m_pFont = new CFX_Font; | 224 m_pFont = new CFX_Font; |
| 236 FX_BOOL bRet = m_pFont->LoadFile(m_pFileRead); | 225 FX_BOOL bRet = m_pFont->LoadFile(m_pFileRead); |
| 237 if (bRet) { | 226 if (bRet) { |
| 238 bRet = InitFont(); | 227 bRet = InitFont(); |
| 239 } else { | 228 } else { |
| 240 m_pFileRead->Release(); | 229 m_pFileRead->Release(); |
| 241 m_pFileRead = nullptr; | 230 m_pFileRead = nullptr; |
| 242 } | 231 } |
| 243 m_wCharSet = 0xFFFF; | |
| 244 return bRet; | 232 return bRet; |
| 245 } | 233 } |
| 246 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 234 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 247 | 235 |
| 248 FX_BOOL CFGAS_GEFont::LoadFontInternal(CFX_Font* pExtFont) { | 236 FX_BOOL CFGAS_GEFont::LoadFontInternal(CFX_Font* pExtFont) { |
| 249 if (m_pFont || !pExtFont) { | 237 if (m_pFont || !pExtFont) { |
| 250 return FALSE; | 238 return FALSE; |
| 251 } | 239 } |
| 252 m_pFont = pExtFont; | 240 m_pFont = pExtFont; |
| 253 m_bExtFont = TRUE; | 241 m_bExtFont = TRUE; |
| 254 m_wCharSet = 0xFFFF; | |
| 255 return InitFont(); | 242 return InitFont(); |
| 256 } | 243 } |
| 257 | 244 |
| 258 FX_BOOL CFGAS_GEFont::InitFont() { | 245 FX_BOOL CFGAS_GEFont::InitFont() { |
| 259 if (!m_pFont) | 246 if (!m_pFont) |
| 260 return FALSE; | 247 return FALSE; |
| 261 if (!m_pFontEncoding) { | 248 if (!m_pFontEncoding) { |
| 262 m_pFontEncoding = FX_CreateFontEncodingEx(m_pFont); | 249 m_pFontEncoding = FX_CreateFontEncodingEx(m_pFont); |
| 263 if (!m_pFontEncoding) | 250 if (!m_pFontEncoding) |
| 264 return FALSE; | 251 return FALSE; |
| 265 } | 252 } |
| 266 if (!m_pCharWidthMap) | 253 if (!m_pCharWidthMap) |
| 267 m_pCharWidthMap = new CFX_WordDiscreteArray(1024); | 254 m_pCharWidthMap = new CFX_WordDiscreteArray(1024); |
| 268 if (!m_pRectArray) | 255 if (!m_pRectArray) |
| 269 m_pRectArray = new CFX_MassArrayTemplate<CFX_Rect>(16); | 256 m_pRectArray = new CFX_MassArrayTemplate<CFX_Rect>(16); |
| 270 if (!m_pBBoxMap) | 257 if (!m_pBBoxMap) |
| 271 m_pBBoxMap = new CFX_MapPtrToPtr(16); | 258 m_pBBoxMap = new CFX_MapPtrToPtr(16); |
| 272 | 259 |
| 273 return TRUE; | 260 return TRUE; |
| 274 } | 261 } |
| 262 | |
| 275 CFGAS_GEFont* CFGAS_GEFont::Derive(uint32_t dwFontStyles, uint16_t wCodePage) { | 263 CFGAS_GEFont* CFGAS_GEFont::Derive(uint32_t dwFontStyles, uint16_t wCodePage) { |
| 276 if (GetFontStyles() == dwFontStyles) { | 264 if (GetFontStyles() == dwFontStyles) |
| 277 return Retain(); | 265 return Retain(); |
| 278 } | |
| 279 return new CFGAS_GEFont(*this, dwFontStyles); | 266 return new CFGAS_GEFont(*this, dwFontStyles); |
| 280 } | 267 } |
| 281 uint8_t CFGAS_GEFont::GetCharSet() const { | 268 |
| 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 { | 269 void CFGAS_GEFont::GetFamilyName(CFX_WideString& wsFamily) const { |
| 291 if (!m_pFont->GetSubstFont() || | 270 if (!m_pFont->GetSubstFont() || |
| 292 m_pFont->GetSubstFont()->m_Family.GetLength() == 0) { | 271 m_pFont->GetSubstFont()->m_Family.GetLength() == 0) { |
| 293 wsFamily = CFX_WideString::FromLocal(m_pFont->GetFamilyName().AsStringC()); | 272 wsFamily = CFX_WideString::FromLocal(m_pFont->GetFamilyName().AsStringC()); |
| 294 } else { | 273 } else { |
| 295 wsFamily = CFX_WideString::FromLocal( | 274 wsFamily = CFX_WideString::FromLocal( |
| 296 m_pFont->GetSubstFont()->m_Family.AsStringC()); | 275 m_pFont->GetSubstFont()->m_Family.AsStringC()); |
| 297 } | 276 } |
| 298 } | 277 } |
| 299 | 278 |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 496 } | 475 } |
| 497 if (m_pRectArray != NULL) { | 476 if (m_pRectArray != NULL) { |
| 498 m_pRectArray->RemoveAll(); | 477 m_pRectArray->RemoveAll(); |
| 499 } | 478 } |
| 500 } | 479 } |
| 501 CFGAS_GEFont* CFGAS_GEFont::GetSubstFont(int32_t iGlyphIndex) const { | 480 CFGAS_GEFont* CFGAS_GEFont::GetSubstFont(int32_t iGlyphIndex) const { |
| 502 iGlyphIndex = ((uint32_t)iGlyphIndex) >> 24; | 481 iGlyphIndex = ((uint32_t)iGlyphIndex) >> 24; |
| 503 return iGlyphIndex == 0 ? const_cast<CFGAS_GEFont*>(this) | 482 return iGlyphIndex == 0 ? const_cast<CFGAS_GEFont*>(this) |
| 504 : m_SubstFonts[iGlyphIndex - 1]; | 483 : m_SubstFonts[iGlyphIndex - 1]; |
| 505 } | 484 } |
| OLD | NEW |