From dd0e6e1eba14c76dedd4b4e55ab47406856c9a76 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Thu, 28 Sep 2017 11:51:24 -0400 Subject: Cleanup font defines This CL removes duplicate defines between XFA and core. Several OR'd values have been coverted into individual booleans to make the code clearer. Change-Id: Ic32a71c711cffd9a0cf1136e5a22f0502e085c39 Reviewed-on: https://pdfium-review.googlesource.com/15071 Reviewed-by: Ryan Harrison Commit-Queue: dsinclair --- xfa/fgas/font/cfgas_defaultfontmanager.cpp | 9 ++-- xfa/fgas/font/cfgas_fontmgr.cpp | 74 ++++++++++++++---------------- xfa/fgas/font/cfgas_fontmgr.h | 16 +------ xfa/fgas/font/cfgas_gefont.cpp | 44 +++++++----------- xfa/fgas/font/cfgas_gefont.h | 6 +-- xfa/fgas/font/cfgas_pdffontmgr.cpp | 4 +- 6 files changed, 61 insertions(+), 92 deletions(-) (limited to 'xfa/fgas') diff --git a/xfa/fgas/font/cfgas_defaultfontmanager.cpp b/xfa/fgas/font/cfgas_defaultfontmanager.cpp index 6f39797927..322d06b384 100644 --- a/xfa/fgas/font/cfgas_defaultfontmanager.cpp +++ b/xfa/fgas/font/cfgas_defaultfontmanager.cpp @@ -24,10 +24,11 @@ RetainPtr CFGAS_DefaultFontManager::GetFont( FGAS_FontInfoByFontName(wsFontName.AsStringView()); if (pCurFont && pCurFont->pReplaceFont) { uint32_t dwStyle = 0; - if (dwFontStyles & FX_FONTSTYLE_Bold) - dwStyle |= FX_FONTSTYLE_Bold; - if (dwFontStyles & FX_FONTSTYLE_Italic) - dwStyle |= FX_FONTSTYLE_Italic; + // TODO(dsinclair): Why doesn't this check the other flags? + if (dwFontStyles & FXFONT_BOLD) + dwStyle |= FXFONT_BOLD; + if (dwFontStyles & FXFONT_ITALIC) + dwStyle |= FXFONT_ITALIC; const wchar_t* pReplace = pCurFont->pReplaceFont; int32_t iLength = wcslen(pReplace); diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp index 1809a7a52c..e2fbd19ba5 100644 --- a/xfa/fgas/font/cfgas_fontmgr.cpp +++ b/xfa/fgas/font/cfgas_fontmgr.cpp @@ -16,6 +16,7 @@ #include "core/fxge/cfx_fontmapper.h" #include "core/fxge/cfx_fontmgr.h" #include "core/fxge/cfx_gemodule.h" +#include "core/fxge/fx_font.h" #include "core/fxge/ifx_systemfontinfo.h" #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" @@ -23,7 +24,6 @@ #include "xfa/fgas/font/fgas_fontutils.h" #if _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_ - namespace { struct FX_CHARSET_MAP { @@ -86,22 +86,18 @@ uint16_t GetCodePageFromCharset(uint8_t charset) { int32_t GetSimilarityScore(FX_FONTDESCRIPTOR const* pFont, uint32_t dwFontStyles) { int32_t iValue = 0; - if ((dwFontStyles & FX_FONTSTYLE_Symbolic) == - (pFont->dwFontStyles & FX_FONTSTYLE_Symbolic)) { + if ((dwFontStyles & FXFONT_SYMBOLIC) == + (pFont->dwFontStyles & FXFONT_SYMBOLIC)) { iValue += 64; } - if ((dwFontStyles & FX_FONTSTYLE_FixedPitch) == - (pFont->dwFontStyles & FX_FONTSTYLE_FixedPitch)) { + if ((dwFontStyles & FXFONT_FIXED_PITCH) == + (pFont->dwFontStyles & FXFONT_FIXED_PITCH)) { iValue += 32; } - if ((dwFontStyles & FX_FONTSTYLE_Serif) == - (pFont->dwFontStyles & FX_FONTSTYLE_Serif)) { + if ((dwFontStyles & FXFONT_SERIF) == (pFont->dwFontStyles & FXFONT_SERIF)) iValue += 16; - } - if ((dwFontStyles & FX_FONTSTYLE_Script) == - (pFont->dwFontStyles & FX_FONTSTYLE_Script)) { + if ((dwFontStyles & FXFONT_SCRIPT) == (pFont->dwFontStyles & FXFONT_SCRIPT)) iValue += 8; - } return iValue; } @@ -110,12 +106,10 @@ const FX_FONTDESCRIPTOR* MatchDefaultFont( const std::deque& fonts) { const FX_FONTDESCRIPTOR* pBestFont = nullptr; int32_t iBestSimilar = 0; - bool bMatchStyle = (pParams->dwMatchFlags & FX_FONTMATCHPARA_MatchStyle) > 0; for (const auto& font : fonts) { - if ((font.dwFontStyles & FX_FONTSTYLE_BoldItalic) == - FX_FONTSTYLE_BoldItalic) { + if ((font.dwFontStyles & FXFONT_BOLD_ITALIC) == FXFONT_BOLD_ITALIC) continue; - } + if (pParams->pwsFamily) { if (FXSYS_wcsicmp(pParams->pwsFamily, font.wsFontFace)) continue; @@ -135,7 +129,7 @@ const FX_FONTDESCRIPTOR* MatchDefaultFont( continue; } } - if (bMatchStyle) { + if (pParams->matchParagraphStyle) { if ((font.dwFontStyles & 0x0F) == (pParams->dwFontStyles & 0x0F)) return &font; continue; @@ -155,17 +149,17 @@ const FX_FONTDESCRIPTOR* MatchDefaultFont( uint32_t GetFontHashCode(uint16_t wCodePage, uint32_t dwFontStyles) { uint32_t dwHash = wCodePage; - if (dwFontStyles & FX_FONTSTYLE_FixedPitch) + if (dwFontStyles & FXFONT_FIXED_PITCH) dwHash |= 0x00010000; - if (dwFontStyles & FX_FONTSTYLE_Serif) + if (dwFontStyles & FXFONT_SERIF) dwHash |= 0x00020000; - if (dwFontStyles & FX_FONTSTYLE_Symbolic) + if (dwFontStyles & FXFONT_SYMBOLIC) dwHash |= 0x00040000; - if (dwFontStyles & FX_FONTSTYLE_Script) + if (dwFontStyles & FXFONT_SCRIPT) dwHash |= 0x00080000; - if (dwFontStyles & FX_FONTSTYLE_Italic) + if (dwFontStyles & FXFONT_ITALIC) dwHash |= 0x00100000; - if (dwFontStyles & FX_FONTSTYLE_Bold) + if (dwFontStyles & FXFONT_BOLD) dwHash |= 0x00200000; return dwHash; } @@ -174,9 +168,9 @@ uint32_t GetFontFamilyHash(const wchar_t* pszFontFamily, uint32_t dwFontStyles, uint16_t wCodePage) { WideString wsFont(pszFontFamily); - if (dwFontStyles & FX_FONTSTYLE_Bold) + if (dwFontStyles & FXFONT_BOLD) wsFont += L"Bold"; - if (dwFontStyles & FX_FONTSTYLE_Italic) + if (dwFontStyles & FXFONT_ITALIC) wsFont += L"Italic"; wsFont += wCodePage; @@ -186,14 +180,14 @@ uint32_t GetFontFamilyHash(const wchar_t* pszFontFamily, uint32_t GetGdiFontStyles(const LOGFONTW& lf) { uint32_t dwStyles = 0; if ((lf.lfPitchAndFamily & 0x03) == FIXED_PITCH) - dwStyles |= FX_FONTSTYLE_FixedPitch; + dwStyles |= FXFONT_FIXED_PITCH; uint8_t nFamilies = lf.lfPitchAndFamily & 0xF0; if (nFamilies == FF_ROMAN) - dwStyles |= FX_FONTSTYLE_Serif; + dwStyles |= FXFONT_SERIF; if (nFamilies == FF_SCRIPT) - dwStyles |= FX_FONTSTYLE_Script; + dwStyles |= FXFONT_SCRIPT; if (lf.lfCharSet == SYMBOL_CHARSET) - dwStyles |= FX_FONTSTYLE_Symbolic; + dwStyles |= FXFONT_SYMBOLIC; return dwStyles; } @@ -399,7 +393,7 @@ void CFGAS_FontMgr::RemoveFont(const RetainPtr& pFont) { const FX_FONTDESCRIPTOR* CFGAS_FontMgr::FindFont(const wchar_t* pszFontFamily, uint32_t dwFontStyles, - uint32_t dwMatchFlags, + bool matchParagraphStyle, uint16_t wCodePage, uint32_t dwUSB, wchar_t wUnicode) { @@ -410,7 +404,7 @@ const FX_FONTDESCRIPTOR* CFGAS_FontMgr::FindFont(const wchar_t* pszFontFamily, params.wCodePage = wCodePage; params.pwsFamily = pszFontFamily; params.dwFontStyles = dwFontStyles; - params.dwMatchFlags = dwMatchFlags; + params.matchParagraphStyle = matchParagraphStyle; const FX_FONTDESCRIPTOR* pDesc = MatchDefaultFont(¶ms, m_FontFaces); if (pDesc) return pDesc; @@ -1046,15 +1040,15 @@ int32_t CFGAS_FontMgr::CalcPenalty(CFX_FontDescriptor* pInstalled, } } uint32_t dwStyleMask = pInstalled->m_dwFontStyles ^ dwFontStyles; - if (dwStyleMask & FX_FONTSTYLE_Bold) + if (dwStyleMask & FXFONT_BOLD) nPenalty += 4500; - if (dwStyleMask & FX_FONTSTYLE_FixedPitch) + if (dwStyleMask & FXFONT_FIXED_PITCH) nPenalty += 10000; - if (dwStyleMask & FX_FONTSTYLE_Italic) + if (dwStyleMask & FXFONT_ITALIC) nPenalty += 10000; - if (dwStyleMask & FX_FONTSTYLE_Serif) + if (dwStyleMask & FXFONT_SERIF) nPenalty += 500; - if (dwStyleMask & FX_FONTSTYLE_Symbolic) + if (dwStyleMask & FXFONT_SYMBOLIC) nPenalty += 0xFFFF; if (nPenalty >= 0xFFFF) return 0xFFFF; @@ -1107,8 +1101,8 @@ void CFGAS_FontMgr::RegisterFace(FXFT_Face pFace, const WideString* pFaceName) { return; auto pFont = pdfium::MakeUnique(); - pFont->m_dwFontStyles |= FXFT_Is_Face_Bold(pFace) ? FX_FONTSTYLE_Bold : 0; - pFont->m_dwFontStyles |= FXFT_Is_Face_Italic(pFace) ? FX_FONTSTYLE_Italic : 0; + pFont->m_dwFontStyles |= FXFT_Is_Face_Bold(pFace) ? FXFONT_BOLD : 0; + pFont->m_dwFontStyles |= FXFT_Is_Face_Italic(pFace) ? FXFONT_ITALIC : 0; pFont->m_dwFontStyles |= GetFlags(pFace); std::vector charsets = GetCharsets(pFace); @@ -1156,17 +1150,17 @@ void CFGAS_FontMgr::RegisterFaces( uint32_t CFGAS_FontMgr::GetFlags(FXFT_Face pFace) { uint32_t flag = 0; if (FT_IS_FIXED_WIDTH(pFace)) - flag |= FX_FONTSTYLE_FixedPitch; + flag |= FXFONT_FIXED_PITCH; TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2); if (!pOS2) return flag; if (pOS2->ulCodePageRange1 & (1 << 31)) - flag |= FX_FONTSTYLE_Symbolic; + flag |= FXFONT_SYMBOLIC; if (pOS2->panose[0] == 2) { uint8_t uSerif = pOS2->panose[1]; if ((uSerif > 1 && uSerif < 10) || uSerif > 13) - flag |= FX_FONTSTYLE_Serif; + flag |= FXFONT_SERIF; } return flag; } diff --git a/xfa/fgas/font/cfgas_fontmgr.h b/xfa/fgas/font/cfgas_fontmgr.h index b97c4b219d..f1e75bad95 100644 --- a/xfa/fgas/font/cfgas_fontmgr.h +++ b/xfa/fgas/font/cfgas_fontmgr.h @@ -23,27 +23,15 @@ #include "core/fxge/ifx_systemfontinfo.h" #include "xfa/fgas/font/cfgas_pdffontmgr.h" -#define FX_FONTSTYLE_Normal 0x00 -#define FX_FONTSTYLE_FixedPitch 0x01 -#define FX_FONTSTYLE_Serif 0x02 -#define FX_FONTSTYLE_Symbolic 0x04 -#define FX_FONTSTYLE_Script 0x08 -#define FX_FONTSTYLE_Italic 0x40 -#define FX_FONTSTYLE_Bold 0x40000 -#define FX_FONTSTYLE_BoldItalic (FX_FONTSTYLE_Bold | FX_FONTSTYLE_Italic) -#define FX_FONTSTYLE_ExactMatch 0x80000000 - class CFX_FontSourceEnum_File; class CFGAS_GEFont; #if _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_ -#define FX_FONTMATCHPARA_MatchStyle 0x01 - struct FX_FONTMATCHPARAMS { const wchar_t* pwsFamily; uint32_t dwFontStyles; uint32_t dwUSB; - uint32_t dwMatchFlags; + bool matchParagraphStyle; wchar_t wUnicode; uint16_t wCodePage; }; @@ -165,7 +153,7 @@ class CFGAS_FontMgr : public Observable { const RetainPtr& pFont); const FX_FONTDESCRIPTOR* FindFont(const wchar_t* pszFontFamily, uint32_t dwFontStyles, - uint32_t dwMatchFlags, + bool matchParagraphStyle, uint16_t wCodePage, uint32_t dwUSB, wchar_t wUnicode); diff --git a/xfa/fgas/font/cfgas_gefont.cpp b/xfa/fgas/font/cfgas_gefont.cpp index 58b1381a38..f364e6c506 100644 --- a/xfa/fgas/font/cfgas_gefont.cpp +++ b/xfa/fgas/font/cfgas_gefont.cpp @@ -85,9 +85,9 @@ CFGAS_GEFont::CFGAS_GEFont(const RetainPtr& src, m_pFont->SetSubstFont(std::unique_ptr(pSubst)); } pSubst->m_Weight = - (dwFontStyles & FX_FONTSTYLE_Bold) ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL; - if (dwFontStyles & FX_FONTSTYLE_Italic) - pSubst->m_SubstFlags |= FXFONT_SUBST_ITALIC; + (dwFontStyles & FXFONT_BOLD) ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL; + if (dwFontStyles & FXFONT_ITALIC) + pSubst->m_bFlagItalic = true; InitFont(); } @@ -105,31 +105,19 @@ bool CFGAS_GEFont::LoadFontInternal(const wchar_t* pszFontFamily, ByteString csFontFamily; if (pszFontFamily) csFontFamily = ByteString::FromUnicode(pszFontFamily); - uint32_t dwFlags = 0; - if (dwFontStyles & FX_FONTSTYLE_FixedPitch) - dwFlags |= FXFONT_FIXED_PITCH; - if (dwFontStyles & FX_FONTSTYLE_Serif) - dwFlags |= FXFONT_SERIF; - if (dwFontStyles & FX_FONTSTYLE_Symbolic) - dwFlags |= FXFONT_SYMBOLIC; - if (dwFontStyles & FX_FONTSTYLE_Script) - dwFlags |= FXFONT_SCRIPT; - if (dwFontStyles & FX_FONTSTYLE_Italic) - dwFlags |= FXFONT_ITALIC; - if (dwFontStyles & FX_FONTSTYLE_Bold) - dwFlags |= FXFONT_BOLD; - if (dwFontStyles & FX_FONTSTYLE_ExactMatch) - dwFlags |= FXFONT_EXACTMATCH; + int32_t iWeight = - (dwFontStyles & FX_FONTSTYLE_Bold) ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL; + (dwFontStyles & FXFONT_BOLD) ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL; m_pFont = new CFX_Font; - if ((dwFlags & FXFONT_ITALIC) && (dwFlags & FXFONT_BOLD)) + if ((dwFontStyles & FXFONT_ITALIC) && (dwFontStyles & FXFONT_BOLD)) csFontFamily += ",BoldItalic"; - else if (dwFlags & FXFONT_BOLD) + else if (dwFontStyles & FXFONT_BOLD) csFontFamily += ",Bold"; - else if (dwFlags & FXFONT_ITALIC) + else if (dwFontStyles & FXFONT_ITALIC) csFontFamily += ",Italic"; - m_pFont->LoadSubst(csFontFamily, true, dwFlags, iWeight, 0, wCodePage, false); + + m_pFont->LoadSubst(csFontFamily, true, dwFontStyles, iWeight, 0, wCodePage, + false); if (!m_pFont->GetFace()) return false; return InitFont(); @@ -195,14 +183,14 @@ uint32_t CFGAS_GEFont::GetFontStyles() const { auto* pSubstFont = m_pFont->GetSubstFont(); if (pSubstFont) { if (pSubstFont->m_Weight == FXFONT_FW_BOLD) - dwStyles |= FX_FONTSTYLE_Bold; - if (pSubstFont->m_SubstFlags & FXFONT_SUBST_ITALIC) - dwStyles |= FX_FONTSTYLE_Italic; + dwStyles |= FXFONT_BOLD; + if (pSubstFont->m_bFlagItalic) + dwStyles |= FXFONT_ITALIC; } else { if (m_pFont->IsBold()) - dwStyles |= FX_FONTSTYLE_Bold; + dwStyles |= FXFONT_BOLD; if (m_pFont->IsItalic()) - dwStyles |= FX_FONTSTYLE_Italic; + dwStyles |= FXFONT_ITALIC; } return dwStyles; } diff --git a/xfa/fgas/font/cfgas_gefont.h b/xfa/fgas/font/cfgas_gefont.h index a1d6b82cb6..2e63ee5367 100644 --- a/xfa/fgas/font/cfgas_gefont.h +++ b/xfa/fgas/font/cfgas_gefont.h @@ -18,8 +18,6 @@ #include "xfa/fgas/font/cfgas_fontmgr.h" #include "xfa/fgas/font/cfgas_pdffontmgr.h" -#define FXFONT_SUBST_ITALIC 0x02 - class CFGAS_FontMgr; class CFX_UnicodeEncoding; @@ -77,9 +75,9 @@ class CFGAS_GEFont : public Retainable { bool LoadFontInternal(const uint8_t* pBuffer, int32_t length); bool LoadFontInternal(const RetainPtr& pFontStream, bool bSaveStream); -#endif - bool LoadFontInternal(CFX_Font* pExternalFont); +#endif // _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_ bool LoadFontInternal(std::unique_ptr pInternalFont); + bool LoadFontInternal(CFX_Font* pExternalFont); bool InitFont(); std::pair> GetGlyphIndexAndFont( wchar_t wUnicode, diff --git a/xfa/fgas/font/cfgas_pdffontmgr.cpp b/xfa/fgas/font/cfgas_pdffontmgr.cpp index a860d05a5a..34d4ff1649 100644 --- a/xfa/fgas/font/cfgas_pdffontmgr.cpp +++ b/xfa/fgas/font/cfgas_pdffontmgr.cpp @@ -85,8 +85,8 @@ RetainPtr CFGAS_PDFFontMgr::GetFont( return it->second; ByteString bsPsName = ByteString::FromUnicode(WideString(wsFontFamily)); - bool bBold = (dwFontStyles & FX_FONTSTYLE_Bold) == FX_FONTSTYLE_Bold; - bool bItalic = (dwFontStyles & FX_FONTSTYLE_Italic) == FX_FONTSTYLE_Italic; + bool bBold = (dwFontStyles & FXFONT_BOLD) == FXFONT_BOLD; + bool bItalic = (dwFontStyles & FXFONT_ITALIC) == FXFONT_ITALIC; ByteString strFontName = PsNameToFontName(bsPsName, bBold, bItalic); RetainPtr pFont = FindFont(strFontName, bBold, bItalic, pPDFFont, bStrictMatch); -- cgit v1.2.3