| 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 | 11 |
| 12 IFX_Font* IFX_Font::LoadFont(const FX_WCHAR* pszFontFamily, | 12 IFX_Font* IFX_Font::LoadFont(const FX_WCHAR* pszFontFamily, |
| 13 FX_DWORD dwFontStyles, | 13 uint32_t dwFontStyles, |
| 14 uint16_t wCodePage, | 14 uint16_t wCodePage, |
| 15 IFX_FontMgr* pFontMgr) { | 15 IFX_FontMgr* pFontMgr) { |
| 16 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 16 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
| 17 if (NULL != pFontMgr) { | 17 if (NULL != pFontMgr) { |
| 18 return pFontMgr->GetFontByCodePage(wCodePage, dwFontStyles, pszFontFamily); | 18 return pFontMgr->GetFontByCodePage(wCodePage, dwFontStyles, pszFontFamily); |
| 19 } | 19 } |
| 20 return NULL; | 20 return NULL; |
| 21 #else | 21 #else |
| 22 CFX_GEFont* pFont = new CFX_GEFont(pFontMgr); | 22 CFX_GEFont* pFont = new CFX_GEFont(pFontMgr); |
| 23 if (!pFont->LoadFont(pszFontFamily, dwFontStyles, wCodePage)) { | 23 if (!pFont->LoadFont(pszFontFamily, dwFontStyles, wCodePage)) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 m_pFontEncoding(NULL), | 102 m_pFontEncoding(NULL), |
| 103 m_pCharWidthMap(NULL), | 103 m_pCharWidthMap(NULL), |
| 104 m_pRectArray(NULL), | 104 m_pRectArray(NULL), |
| 105 m_pBBoxMap(NULL), | 105 m_pBBoxMap(NULL), |
| 106 m_pProvider(NULL), | 106 m_pProvider(NULL), |
| 107 m_wCharSet(0xFFFF), | 107 m_wCharSet(0xFFFF), |
| 108 m_SubstFonts(), | 108 m_SubstFonts(), |
| 109 m_FontMapper(16) { | 109 m_FontMapper(16) { |
| 110 } | 110 } |
| 111 | 111 |
| 112 CFX_GEFont::CFX_GEFont(const CFX_GEFont& src, FX_DWORD dwFontStyles) | 112 CFX_GEFont::CFX_GEFont(const CFX_GEFont& src, uint32_t dwFontStyles) |
| 113 : | 113 : |
| 114 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 114 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
| 115 m_bUseLogFontStyle(FALSE), | 115 m_bUseLogFontStyle(FALSE), |
| 116 m_dwLogFontStyle(0), | 116 m_dwLogFontStyle(0), |
| 117 #endif | 117 #endif |
| 118 m_pFont(NULL), | 118 m_pFont(NULL), |
| 119 m_pFontMgr(src.m_pFontMgr), | 119 m_pFontMgr(src.m_pFontMgr), |
| 120 m_iRefCount(1), | 120 m_iRefCount(1), |
| 121 m_bExtFont(FALSE), | 121 m_bExtFont(FALSE), |
| 122 m_pStream(NULL), | 122 m_pStream(NULL), |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 m_pFontMgr->RemoveFont(this); | 181 m_pFontMgr->RemoveFont(this); |
| 182 } | 182 } |
| 183 delete this; | 183 delete this; |
| 184 } | 184 } |
| 185 } | 185 } |
| 186 IFX_Font* CFX_GEFont::Retain() { | 186 IFX_Font* CFX_GEFont::Retain() { |
| 187 ++m_iRefCount; | 187 ++m_iRefCount; |
| 188 return this; | 188 return this; |
| 189 } | 189 } |
| 190 FX_BOOL CFX_GEFont::LoadFont(const FX_WCHAR* pszFontFamily, | 190 FX_BOOL CFX_GEFont::LoadFont(const FX_WCHAR* pszFontFamily, |
| 191 FX_DWORD dwFontStyles, | 191 uint32_t dwFontStyles, |
| 192 uint16_t wCodePage) { | 192 uint16_t wCodePage) { |
| 193 if (m_pFont) { | 193 if (m_pFont) { |
| 194 return FALSE; | 194 return FALSE; |
| 195 } | 195 } |
| 196 CFX_ByteString csFontFamily; | 196 CFX_ByteString csFontFamily; |
| 197 if (pszFontFamily != NULL) { | 197 if (pszFontFamily != NULL) { |
| 198 csFontFamily = CFX_ByteString::FromUnicode(pszFontFamily); | 198 csFontFamily = CFX_ByteString::FromUnicode(pszFontFamily); |
| 199 } | 199 } |
| 200 FX_DWORD dwFlags = 0; | 200 uint32_t dwFlags = 0; |
| 201 if (dwFontStyles & FX_FONTSTYLE_FixedPitch) { | 201 if (dwFontStyles & FX_FONTSTYLE_FixedPitch) { |
| 202 dwFlags |= FXFONT_FIXED_PITCH; | 202 dwFlags |= FXFONT_FIXED_PITCH; |
| 203 } | 203 } |
| 204 if (dwFontStyles & FX_FONTSTYLE_Serif) { | 204 if (dwFontStyles & FX_FONTSTYLE_Serif) { |
| 205 dwFlags |= FXFONT_SERIF; | 205 dwFlags |= FXFONT_SERIF; |
| 206 } | 206 } |
| 207 if (dwFontStyles & FX_FONTSTYLE_Symbolic) { | 207 if (dwFontStyles & FX_FONTSTYLE_Symbolic) { |
| 208 dwFlags |= FXFONT_SYMBOLIC; | 208 dwFlags |= FXFONT_SYMBOLIC; |
| 209 } | 209 } |
| 210 if (dwFontStyles & FX_FONTSTYLE_Script) { | 210 if (dwFontStyles & FX_FONTSTYLE_Script) { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 m_pCharWidthMap = new CFX_WordDiscreteArray(1024); | 322 m_pCharWidthMap = new CFX_WordDiscreteArray(1024); |
| 323 } | 323 } |
| 324 if (!m_pRectArray) { | 324 if (!m_pRectArray) { |
| 325 m_pRectArray = new CFX_RectMassArray(16); | 325 m_pRectArray = new CFX_RectMassArray(16); |
| 326 } | 326 } |
| 327 if (!m_pBBoxMap) { | 327 if (!m_pBBoxMap) { |
| 328 m_pBBoxMap = new CFX_MapPtrToPtr(16); | 328 m_pBBoxMap = new CFX_MapPtrToPtr(16); |
| 329 } | 329 } |
| 330 return TRUE; | 330 return TRUE; |
| 331 } | 331 } |
| 332 IFX_Font* CFX_GEFont::Derive(FX_DWORD dwFontStyles, uint16_t wCodePage) { | 332 IFX_Font* CFX_GEFont::Derive(uint32_t dwFontStyles, uint16_t wCodePage) { |
| 333 if (GetFontStyles() == dwFontStyles) { | 333 if (GetFontStyles() == dwFontStyles) { |
| 334 return Retain(); | 334 return Retain(); |
| 335 } | 335 } |
| 336 return new CFX_GEFont(*this, dwFontStyles); | 336 return new CFX_GEFont(*this, dwFontStyles); |
| 337 } | 337 } |
| 338 uint8_t CFX_GEFont::GetCharSet() const { | 338 uint8_t CFX_GEFont::GetCharSet() const { |
| 339 if (m_wCharSet != 0xFFFF) { | 339 if (m_wCharSet != 0xFFFF) { |
| 340 return (uint8_t)m_wCharSet; | 340 return (uint8_t)m_wCharSet; |
| 341 } | 341 } |
| 342 if (!m_pFont->GetSubstFont()) { | 342 if (!m_pFont->GetSubstFont()) { |
| 343 return FX_CHARSET_Default; | 343 return FX_CHARSET_Default; |
| 344 } | 344 } |
| 345 return m_pFont->GetSubstFont()->m_Charset; | 345 return m_pFont->GetSubstFont()->m_Charset; |
| 346 } | 346 } |
| 347 void CFX_GEFont::GetFamilyName(CFX_WideString& wsFamily) const { | 347 void CFX_GEFont::GetFamilyName(CFX_WideString& wsFamily) const { |
| 348 if (!m_pFont->GetSubstFont() || | 348 if (!m_pFont->GetSubstFont() || |
| 349 m_pFont->GetSubstFont()->m_Family.GetLength() == 0) { | 349 m_pFont->GetSubstFont()->m_Family.GetLength() == 0) { |
| 350 wsFamily = CFX_WideString::FromLocal(m_pFont->GetFamilyName()); | 350 wsFamily = CFX_WideString::FromLocal(m_pFont->GetFamilyName()); |
| 351 } else { | 351 } else { |
| 352 wsFamily = CFX_WideString::FromLocal(m_pFont->GetSubstFont()->m_Family); | 352 wsFamily = CFX_WideString::FromLocal(m_pFont->GetSubstFont()->m_Family); |
| 353 } | 353 } |
| 354 } | 354 } |
| 355 void CFX_GEFont::GetPsName(CFX_WideString& wsName) const { | 355 void CFX_GEFont::GetPsName(CFX_WideString& wsName) const { |
| 356 wsName = m_pFont->GetPsName(); | 356 wsName = m_pFont->GetPsName(); |
| 357 } | 357 } |
| 358 FX_DWORD CFX_GEFont::GetFontStyles() const { | 358 uint32_t CFX_GEFont::GetFontStyles() const { |
| 359 FXSYS_assert(m_pFont != NULL); | 359 FXSYS_assert(m_pFont != NULL); |
| 360 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 360 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
| 361 if (m_bUseLogFontStyle) { | 361 if (m_bUseLogFontStyle) { |
| 362 return m_dwLogFontStyle; | 362 return m_dwLogFontStyle; |
| 363 } | 363 } |
| 364 #endif | 364 #endif |
| 365 FX_DWORD dwStyles = 0; | 365 uint32_t dwStyles = 0; |
| 366 if (!m_pFont->GetSubstFont()) { | 366 if (!m_pFont->GetSubstFont()) { |
| 367 if (m_pFont->IsBold()) { | 367 if (m_pFont->IsBold()) { |
| 368 dwStyles |= FX_FONTSTYLE_Bold; | 368 dwStyles |= FX_FONTSTYLE_Bold; |
| 369 } | 369 } |
| 370 if (m_pFont->IsItalic()) { | 370 if (m_pFont->IsItalic()) { |
| 371 dwStyles |= FX_FONTSTYLE_Italic; | 371 dwStyles |= FX_FONTSTYLE_Italic; |
| 372 } | 372 } |
| 373 } else { | 373 } else { |
| 374 if (m_pFont->GetSubstFont()->m_Weight == FXFONT_FW_BOLD) { | 374 if (m_pFont->GetSubstFont()->m_Weight == FXFONT_FW_BOLD) { |
| 375 dwStyles |= FX_FONTSTYLE_Bold; | 375 dwStyles |= FX_FONTSTYLE_Bold; |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 m_pCharWidthMap->RemoveAll(); | 559 m_pCharWidthMap->RemoveAll(); |
| 560 } | 560 } |
| 561 if (m_pBBoxMap != NULL) { | 561 if (m_pBBoxMap != NULL) { |
| 562 m_pBBoxMap->RemoveAll(); | 562 m_pBBoxMap->RemoveAll(); |
| 563 } | 563 } |
| 564 if (m_pRectArray != NULL) { | 564 if (m_pRectArray != NULL) { |
| 565 m_pRectArray->RemoveAll(); | 565 m_pRectArray->RemoveAll(); |
| 566 } | 566 } |
| 567 } | 567 } |
| 568 IFX_Font* CFX_GEFont::GetSubstFont(int32_t iGlyphIndex) const { | 568 IFX_Font* CFX_GEFont::GetSubstFont(int32_t iGlyphIndex) const { |
| 569 iGlyphIndex = ((FX_DWORD)iGlyphIndex) >> 24; | 569 iGlyphIndex = ((uint32_t)iGlyphIndex) >> 24; |
| 570 return iGlyphIndex == 0 ? (IFX_Font*)this | 570 return iGlyphIndex == 0 ? (IFX_Font*)this |
| 571 : (IFX_Font*)m_SubstFonts[iGlyphIndex - 1]; | 571 : (IFX_Font*)m_SubstFonts[iGlyphIndex - 1]; |
| 572 } | 572 } |
| OLD | NEW |