Index: xfa/fgas/font/fgas_gefont.cpp |
diff --git a/xfa/fgas/font/fgas_gefont.cpp b/xfa/fgas/font/fgas_gefont.cpp |
index 803bede6e5942639f55941410d1b4cb5e647d827..f2709f2cd64f1e9b0a97353b420c9906ce0387f9 100644 |
--- a/xfa/fgas/font/fgas_gefont.cpp |
+++ b/xfa/fgas/font/fgas_gefont.cpp |
@@ -10,10 +10,11 @@ |
#include "xfa/fgas/font/fgas_fontutils.h" |
#include "xfa/fxfa/include/xfa_fontmgr.h" |
-IFX_Font* IFX_Font::LoadFont(const FX_WCHAR* pszFontFamily, |
- uint32_t dwFontStyles, |
- uint16_t wCodePage, |
- IFX_FontMgr* pFontMgr) { |
+// static |
+CFX_GEFont* CFX_GEFont::LoadFont(const FX_WCHAR* pszFontFamily, |
+ uint32_t dwFontStyles, |
+ uint16_t wCodePage, |
+ IFX_FontMgr* pFontMgr) { |
#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
if (NULL != pFontMgr) { |
dsinclair
2016/06/02 17:37:38
nit: if (pFontMgr)
Lei Zhang
2016/06/07 01:17:16
I have a separate set of CLs to kill off NULLs.
|
return pFontMgr->GetFontByCodePage(wCodePage, dwFontStyles, pszFontFamily); |
@@ -28,66 +29,55 @@ IFX_Font* IFX_Font::LoadFont(const FX_WCHAR* pszFontFamily, |
return pFont; |
#endif |
} |
-IFX_Font* IFX_Font::LoadFont(const uint8_t* pBuffer, |
- int32_t iLength, |
- IFX_FontMgr* pFontMgr) { |
-#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
- if (NULL != pFontMgr) { |
- return pFontMgr->LoadFont(pBuffer, iLength, 0, NULL); |
- } |
- return NULL; |
-#else |
+ |
+// static |
+CFX_GEFont* CFX_GEFont::LoadFont(CFX_Font* pExtFont, |
+ IFX_FontMgr* pFontMgr, |
+ FX_BOOL bTakeOver) { |
CFX_GEFont* pFont = new CFX_GEFont(pFontMgr); |
- if (!pFont->LoadFont(pBuffer, iLength)) { |
+ if (!pFont->LoadFont(pExtFont, bTakeOver)) { |
pFont->Release(); |
return NULL; |
} |
return pFont; |
-#endif |
} |
-IFX_Font* IFX_Font::LoadFont(const FX_WCHAR* pszFileName, |
- IFX_FontMgr* pFontMgr) { |
-#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
- if (NULL != pFontMgr) { |
- return pFontMgr->LoadFont(pszFileName, 0, NULL); |
- } |
- return NULL; |
-#else |
+ |
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
+// static |
+CFX_GEFont* CFX_GEFont::LoadFont(const uint8_t* pBuffer, |
+ int32_t iLength, |
+ IFX_FontMgr* pFontMgr) { |
CFX_GEFont* pFont = new CFX_GEFont(pFontMgr); |
- if (!pFont->LoadFont(pszFileName)) { |
+ if (!pFont->LoadFont(pBuffer, iLength)) { |
pFont->Release(); |
- return NULL; |
+ return nullptr; |
} |
return pFont; |
-#endif |
} |
-IFX_Font* IFX_Font::LoadFont(IFX_Stream* pFontStream, |
- IFX_FontMgr* pFontMgr, |
- FX_BOOL bSaveStream) { |
-#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
- if (NULL != pFontMgr) { |
- return pFontMgr->LoadFont(pFontStream, 0, NULL); |
- } |
- return NULL; |
-#else |
- CFX_GEFont* pFont = new CFX_GEFont(pFontMgr); |
- if (!pFont->LoadFont(pFontStream, bSaveStream)) { |
+ |
+// static |
+CFX_GEFont* CFX_GEFont::LoadFont(const FX_WCHAR* pszFileName) { |
+ CFX_GEFont* pFont = new CFX_GEFont(nullptr); |
+ if (!pFont->LoadFontInternal(pszFileName)) { |
pFont->Release(); |
- return NULL; |
+ return nullptr; |
} |
return pFont; |
-#endif |
} |
-IFX_Font* IFX_Font::LoadFont(CFX_Font* pExtFont, |
- IFX_FontMgr* pFontMgr, |
- FX_BOOL bTakeOver) { |
+ |
+// static |
+CFX_GEFont* CFX_GEFont::LoadFont(IFX_Stream* pFontStream, |
+ IFX_FontMgr* pFontMgr, |
+ FX_BOOL bSaveStream) { |
CFX_GEFont* pFont = new CFX_GEFont(pFontMgr); |
- if (!pFont->LoadFont(pExtFont, bTakeOver)) { |
+ if (!pFont->LoadFont(pFontStream, bSaveStream)) { |
pFont->Release(); |
- return NULL; |
+ return nullptr; |
} |
return pFont; |
} |
+#endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
+ |
CFX_GEFont::CFX_GEFont(IFX_FontMgr* pFontMgr) |
: |
#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
@@ -170,10 +160,12 @@ void CFX_GEFont::Release() { |
delete this; |
} |
} |
-IFX_Font* CFX_GEFont::Retain() { |
+CFX_GEFont* CFX_GEFont::Retain() { |
++m_iRefCount; |
return this; |
} |
+ |
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
FX_BOOL CFX_GEFont::LoadFont(const FX_WCHAR* pszFontFamily, |
uint32_t dwFontStyles, |
uint16_t wCodePage) { |
@@ -228,6 +220,7 @@ FX_BOOL CFX_GEFont::LoadFont(const FX_WCHAR* pszFontFamily, |
} |
return bRet; |
} |
+ |
FX_BOOL CFX_GEFont::LoadFont(const uint8_t* pBuffer, int32_t length) { |
if (m_pFont) { |
return FALSE; |
@@ -240,7 +233,8 @@ FX_BOOL CFX_GEFont::LoadFont(const uint8_t* pBuffer, int32_t length) { |
m_wCharSet = 0xFFFF; |
return bRet; |
} |
-FX_BOOL CFX_GEFont::LoadFont(const FX_WCHAR* pszFileName) { |
+ |
+FX_BOOL CFX_GEFont::LoadFontInternal(const FX_WCHAR* pszFileName) { |
if (m_pFont || m_pStream || m_pFileRead) { |
return FALSE; |
} |
@@ -261,6 +255,7 @@ FX_BOOL CFX_GEFont::LoadFont(const FX_WCHAR* pszFileName) { |
m_wCharSet = 0xFFFF; |
return bRet; |
} |
+ |
FX_BOOL CFX_GEFont::LoadFont(IFX_Stream* pFontStream, FX_BOOL bSaveStream) { |
if (m_pFont || m_pFileRead || !pFontStream || pFontStream->GetLength() < 1) { |
return FALSE; |
@@ -280,6 +275,8 @@ FX_BOOL CFX_GEFont::LoadFont(IFX_Stream* pFontStream, FX_BOOL bSaveStream) { |
m_wCharSet = 0xFFFF; |
return bRet; |
} |
+#endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
+ |
FX_BOOL CFX_GEFont::LoadFont(CFX_Font* pExtFont, FX_BOOL bTakeOver) { |
if (m_pFont || !pExtFont) { |
return FALSE; |
@@ -295,6 +292,7 @@ FX_BOOL CFX_GEFont::LoadFont(CFX_Font* pExtFont, FX_BOOL bTakeOver) { |
m_wCharSet = 0xFFFF; |
return bRet; |
} |
+ |
FX_BOOL CFX_GEFont::InitFont() { |
if (!m_pFont) |
return FALSE; |
@@ -312,7 +310,7 @@ FX_BOOL CFX_GEFont::InitFont() { |
return TRUE; |
} |
-IFX_Font* CFX_GEFont::Derive(uint32_t dwFontStyles, uint16_t wCodePage) { |
+CFX_GEFont* CFX_GEFont::Derive(uint32_t dwFontStyles, uint16_t wCodePage) { |
if (GetFontStyles() == dwFontStyles) { |
return Retain(); |
} |
@@ -365,27 +363,27 @@ uint32_t CFX_GEFont::GetFontStyles() const { |
FX_BOOL CFX_GEFont::GetCharWidth(FX_WCHAR wUnicode, |
int32_t& iWidth, |
FX_BOOL bCharCode) { |
- return GetCharWidth(wUnicode, iWidth, TRUE, bCharCode); |
+ return GetCharWidthInternal(wUnicode, iWidth, TRUE, bCharCode); |
} |
-FX_BOOL CFX_GEFont::GetCharWidth(FX_WCHAR wUnicode, |
- int32_t& iWidth, |
- FX_BOOL bRecursive, |
- FX_BOOL bCharCode) { |
+FX_BOOL CFX_GEFont::GetCharWidthInternal(FX_WCHAR wUnicode, |
+ int32_t& iWidth, |
+ FX_BOOL bRecursive, |
+ FX_BOOL bCharCode) { |
ASSERT(m_pCharWidthMap != NULL); |
iWidth = m_pCharWidthMap->GetAt(wUnicode, 0); |
if (iWidth < 1) { |
if (!m_pProvider || |
!m_pProvider->GetCharWidth(this, wUnicode, iWidth, bCharCode)) { |
- IFX_Font* pFont = NULL; |
+ CFX_GEFont* pFont = NULL; |
int32_t iGlyph = GetGlyphIndex(wUnicode, TRUE, &pFont, bCharCode); |
if (iGlyph != 0xFFFF && pFont != NULL) { |
- if (pFont == (IFX_Font*)this) { |
+ if (pFont == this) { |
iWidth = m_pFont->GetGlyphWidth(iGlyph); |
if (iWidth < 0) { |
iWidth = -1; |
} |
- } else if (((CFX_GEFont*)pFont) |
- ->GetCharWidth(wUnicode, iWidth, FALSE, bCharCode)) { |
+ } else if (pFont->GetCharWidthInternal(wUnicode, iWidth, FALSE, |
+ bCharCode)) { |
return TRUE; |
} |
} else { |
@@ -401,20 +399,20 @@ FX_BOOL CFX_GEFont::GetCharWidth(FX_WCHAR wUnicode, |
FX_BOOL CFX_GEFont::GetCharBBox(FX_WCHAR wUnicode, |
CFX_Rect& bbox, |
FX_BOOL bCharCode) { |
- return GetCharBBox(wUnicode, bbox, TRUE, bCharCode); |
+ return GetCharBBoxInternal(wUnicode, bbox, TRUE, bCharCode); |
} |
-FX_BOOL CFX_GEFont::GetCharBBox(FX_WCHAR wUnicode, |
- CFX_Rect& bbox, |
- FX_BOOL bRecursive, |
- FX_BOOL bCharCode) { |
+FX_BOOL CFX_GEFont::GetCharBBoxInternal(FX_WCHAR wUnicode, |
+ CFX_Rect& bbox, |
+ FX_BOOL bRecursive, |
+ FX_BOOL bCharCode) { |
ASSERT(m_pRectArray != NULL); |
ASSERT(m_pBBoxMap != NULL); |
void* pRect = NULL; |
if (!m_pBBoxMap->Lookup((void*)(uintptr_t)wUnicode, pRect)) { |
- IFX_Font* pFont = NULL; |
+ CFX_GEFont* pFont = NULL; |
int32_t iGlyph = GetGlyphIndex(wUnicode, TRUE, &pFont, bCharCode); |
if (iGlyph != 0xFFFF && pFont != NULL) { |
- if (pFont == (IFX_Font*)this) { |
+ if (pFont == this) { |
FX_RECT rtBBox; |
if (m_pFont->GetGlyphBBox(iGlyph, rtBBox)) { |
CFX_Rect rt; |
@@ -423,8 +421,7 @@ FX_BOOL CFX_GEFont::GetCharBBox(FX_WCHAR wUnicode, |
pRect = m_pRectArray->GetPtrAt(index); |
m_pBBoxMap->SetAt((void*)(uintptr_t)wUnicode, pRect); |
} |
- } else if (((CFX_GEFont*)pFont) |
- ->GetCharBBox(wUnicode, bbox, FALSE, bCharCode)) { |
+ } else if (pFont->GetCharBBoxInternal(wUnicode, bbox, FALSE, bCharCode)) { |
return TRUE; |
} |
} |
@@ -457,13 +454,13 @@ int32_t CFX_GEFont::GetGlyphIndex(FX_WCHAR wUnicode, FX_BOOL bCharCode) { |
} |
int32_t CFX_GEFont::GetGlyphIndex(FX_WCHAR wUnicode, |
FX_BOOL bRecursive, |
- IFX_Font** ppFont, |
+ CFX_GEFont** ppFont, |
FX_BOOL bCharCode) { |
ASSERT(m_pFontEncoding != NULL); |
int32_t iGlyphIndex = m_pFontEncoding->GlyphFromCharCode(wUnicode); |
if (iGlyphIndex > 0) { |
if (ppFont != NULL) { |
- *ppFont = (IFX_Font*)this; |
+ *ppFont = this; |
} |
return iGlyphIndex; |
} |
@@ -476,10 +473,9 @@ int32_t CFX_GEFont::GetGlyphIndex(FX_WCHAR wUnicode, |
return 0xFFFF; |
} |
auto it = m_FontMapper.find(wUnicode); |
- IFX_Font* pFont = it != m_FontMapper.end() ? it->second : nullptr; |
+ CFX_GEFont* pFont = it != m_FontMapper.end() ? it->second : nullptr; |
if (pFont && pFont != this) { |
- iGlyphIndex = |
- ((CFX_GEFont*)pFont)->GetGlyphIndex(wUnicode, FALSE, NULL, bCharCode); |
+ iGlyphIndex = pFont->GetGlyphIndex(wUnicode, FALSE, NULL, bCharCode); |
if (iGlyphIndex != 0xFFFF) { |
int32_t i = m_SubstFonts.Find(pFont); |
if (i > -1) { |
@@ -494,11 +490,11 @@ int32_t CFX_GEFont::GetGlyphIndex(FX_WCHAR wUnicode, |
CFX_WideString wsFamily; |
GetFamilyName(wsFamily); |
#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
- IFX_Font* pFont = m_pFontMgr->GetDefFontByUnicode(wUnicode, GetFontStyles(), |
- wsFamily.c_str()); |
+ CFX_GEFont* pFont = m_pFontMgr->GetDefFontByUnicode( |
+ wUnicode, GetFontStyles(), wsFamily.c_str()); |
#else |
- IFX_Font* pFont = m_pFontMgr->GetFontByUnicode(wUnicode, GetFontStyles(), |
- wsFamily.c_str()); |
+ CFX_GEFont* pFont = m_pFontMgr->GetFontByUnicode(wUnicode, GetFontStyles(), |
+ wsFamily.c_str()); |
if (!pFont) |
pFont = m_pFontMgr->GetFontByUnicode(wUnicode, GetFontStyles(), NULL); |
#endif |
@@ -510,8 +506,7 @@ int32_t CFX_GEFont::GetGlyphIndex(FX_WCHAR wUnicode, |
m_FontMapper[wUnicode] = pFont; |
int32_t i = m_SubstFonts.GetSize(); |
m_SubstFonts.Add(pFont); |
- iGlyphIndex = |
- ((CFX_GEFont*)pFont)->GetGlyphIndex(wUnicode, FALSE, NULL, bCharCode); |
+ iGlyphIndex = pFont->GetGlyphIndex(wUnicode, FALSE, NULL, bCharCode); |
if (iGlyphIndex != 0xFFFF) { |
iGlyphIndex |= ((i + 1) << 24); |
if (ppFont) |
@@ -529,11 +524,8 @@ int32_t CFX_GEFont::GetDescent() const { |
return m_pFont->GetDescent(); |
} |
void CFX_GEFont::Reset() { |
- int32_t iCount = m_SubstFonts.GetSize(); |
- for (int32_t i = 0; i < iCount; i++) { |
- IFX_Font* pFont = m_SubstFonts[i]; |
- ((CFX_GEFont*)pFont)->Reset(); |
- } |
+ for (int32_t i = 0; i < m_SubstFonts.GetSize(); i++) |
+ m_SubstFonts[i]->Reset(); |
if (m_pCharWidthMap != NULL) { |
m_pCharWidthMap->RemoveAll(); |
} |
@@ -544,7 +536,7 @@ void CFX_GEFont::Reset() { |
m_pRectArray->RemoveAll(); |
} |
} |
-IFX_Font* CFX_GEFont::GetSubstFont(int32_t iGlyphIndex) const { |
+CFX_GEFont* CFX_GEFont::GetSubstFont(int32_t iGlyphIndex) const { |
iGlyphIndex = ((uint32_t)iGlyphIndex) >> 24; |
return iGlyphIndex == 0 ? const_cast<CFX_GEFont*>(this) |
: m_SubstFonts[iGlyphIndex - 1]; |