summaryrefslogtreecommitdiff
path: root/xfa/fgas
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-09-28 15:59:42 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-09-28 20:40:36 +0000
commit10e1f05a9e644cd954792bcd40ef787551cbd209 (patch)
treed203254a0a2c856a9b8ba5a0445a883c7072dd77 /xfa/fgas
parentdd0e6e1eba14c76dedd4b4e55ab47406856c9a76 (diff)
downloadpdfium-10e1f05a9e644cd954792bcd40ef787551cbd209.tar.xz
Cleanup font defines
Use methods to match font information; cleanup some font code. Change-Id: Ib99c1e466e56723cb5d264d49e1caf9bbbc0daed Reviewed-on: https://pdfium-review.googlesource.com/15072 Reviewed-by: Ryan Harrison <rharrison@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fgas')
-rw-r--r--xfa/fgas/font/cfgas_defaultfontmanager.cpp4
-rw-r--r--xfa/fgas/font/cfgas_fontmgr.cpp43
-rw-r--r--xfa/fgas/font/cfgas_gefont.cpp14
-rw-r--r--xfa/fgas/font/cfgas_pdffontmgr.cpp4
4 files changed, 35 insertions, 30 deletions
diff --git a/xfa/fgas/font/cfgas_defaultfontmanager.cpp b/xfa/fgas/font/cfgas_defaultfontmanager.cpp
index 322d06b384..4d0ff20583 100644
--- a/xfa/fgas/font/cfgas_defaultfontmanager.cpp
+++ b/xfa/fgas/font/cfgas_defaultfontmanager.cpp
@@ -25,9 +25,9 @@ RetainPtr<CFGAS_GEFont> CFGAS_DefaultFontManager::GetFont(
if (pCurFont && pCurFont->pReplaceFont) {
uint32_t dwStyle = 0;
// TODO(dsinclair): Why doesn't this check the other flags?
- if (dwFontStyles & FXFONT_BOLD)
+ if (FontStyleIsBold(dwFontStyles))
dwStyle |= FXFONT_BOLD;
- if (dwFontStyles & FXFONT_ITALIC)
+ if (FontStyleIsItalic(dwFontStyles))
dwStyle |= FXFONT_ITALIC;
const wchar_t* pReplace = pCurFont->pReplaceFont;
diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp
index e2fbd19ba5..6215766666 100644
--- a/xfa/fgas/font/cfgas_fontmgr.cpp
+++ b/xfa/fgas/font/cfgas_fontmgr.cpp
@@ -24,6 +24,7 @@
#include "xfa/fgas/font/fgas_fontutils.h"
#if _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
+
namespace {
struct FX_CHARSET_MAP {
@@ -86,17 +87,17 @@ uint16_t GetCodePageFromCharset(uint8_t charset) {
int32_t GetSimilarityScore(FX_FONTDESCRIPTOR const* pFont,
uint32_t dwFontStyles) {
int32_t iValue = 0;
- if ((dwFontStyles & FXFONT_SYMBOLIC) ==
- (pFont->dwFontStyles & FXFONT_SYMBOLIC)) {
+ if (FontStyleIsSymbolic(dwFontStyles) ==
+ FontStyleIsSymbolic(pFont->dwFontStyles)) {
iValue += 64;
}
- if ((dwFontStyles & FXFONT_FIXED_PITCH) ==
- (pFont->dwFontStyles & FXFONT_FIXED_PITCH)) {
+ if (FontStyleIsFixedPitch(dwFontStyles) ==
+ FontStyleIsFixedPitch(pFont->dwFontStyles)) {
iValue += 32;
}
- if ((dwFontStyles & FXFONT_SERIF) == (pFont->dwFontStyles & FXFONT_SERIF))
+ if (FontStyleIsSerif(dwFontStyles) == FontStyleIsSerif(pFont->dwFontStyles))
iValue += 16;
- if ((dwFontStyles & FXFONT_SCRIPT) == (pFont->dwFontStyles & FXFONT_SCRIPT))
+ if (FontStyleIsScript(dwFontStyles) == FontStyleIsScript(pFont->dwFontStyles))
iValue += 8;
return iValue;
}
@@ -107,8 +108,10 @@ const FX_FONTDESCRIPTOR* MatchDefaultFont(
const FX_FONTDESCRIPTOR* pBestFont = nullptr;
int32_t iBestSimilar = 0;
for (const auto& font : fonts) {
- if ((font.dwFontStyles & FXFONT_BOLD_ITALIC) == FXFONT_BOLD_ITALIC)
+ if (FontStyleIsBold(font.dwFontStyles) &&
+ FontStyleIsItalic(font.dwFontStyles)) {
continue;
+ }
if (pParams->pwsFamily) {
if (FXSYS_wcsicmp(pParams->pwsFamily, font.wsFontFace))
@@ -149,17 +152,17 @@ const FX_FONTDESCRIPTOR* MatchDefaultFont(
uint32_t GetFontHashCode(uint16_t wCodePage, uint32_t dwFontStyles) {
uint32_t dwHash = wCodePage;
- if (dwFontStyles & FXFONT_FIXED_PITCH)
+ if (FontStyleIsFixedPitch(dwFontStyles))
dwHash |= 0x00010000;
- if (dwFontStyles & FXFONT_SERIF)
+ if (FontStyleIsSerif(dwFontStyles))
dwHash |= 0x00020000;
- if (dwFontStyles & FXFONT_SYMBOLIC)
+ if (FontStyleIsSymbolic(dwFontStyles))
dwHash |= 0x00040000;
- if (dwFontStyles & FXFONT_SCRIPT)
+ if (FontStyleIsScript(dwFontStyles))
dwHash |= 0x00080000;
- if (dwFontStyles & FXFONT_ITALIC)
+ if (FontStyleIsItalic(dwFontStyles))
dwHash |= 0x00100000;
- if (dwFontStyles & FXFONT_BOLD)
+ if (FontStyleIsBold(dwFontStyles))
dwHash |= 0x00200000;
return dwHash;
}
@@ -168,9 +171,9 @@ uint32_t GetFontFamilyHash(const wchar_t* pszFontFamily,
uint32_t dwFontStyles,
uint16_t wCodePage) {
WideString wsFont(pszFontFamily);
- if (dwFontStyles & FXFONT_BOLD)
+ if (FontStyleIsBold(dwFontStyles))
wsFont += L"Bold";
- if (dwFontStyles & FXFONT_ITALIC)
+ if (FontStyleIsItalic(dwFontStyles))
wsFont += L"Italic";
wsFont += wCodePage;
@@ -1040,15 +1043,15 @@ int32_t CFGAS_FontMgr::CalcPenalty(CFX_FontDescriptor* pInstalled,
}
}
uint32_t dwStyleMask = pInstalled->m_dwFontStyles ^ dwFontStyles;
- if (dwStyleMask & FXFONT_BOLD)
+ if (FontStyleIsBold(dwStyleMask))
nPenalty += 4500;
- if (dwStyleMask & FXFONT_FIXED_PITCH)
+ if (FontStyleIsFixedPitch(dwStyleMask))
nPenalty += 10000;
- if (dwStyleMask & FXFONT_ITALIC)
+ if (FontStyleIsItalic(dwStyleMask))
nPenalty += 10000;
- if (dwStyleMask & FXFONT_SERIF)
+ if (FontStyleIsSerif(dwStyleMask))
nPenalty += 500;
- if (dwStyleMask & FXFONT_SYMBOLIC)
+ if (FontStyleIsSymbolic(dwStyleMask))
nPenalty += 0xFFFF;
if (nPenalty >= 0xFFFF)
return 0xFFFF;
diff --git a/xfa/fgas/font/cfgas_gefont.cpp b/xfa/fgas/font/cfgas_gefont.cpp
index f364e6c506..43d019f0f5 100644
--- a/xfa/fgas/font/cfgas_gefont.cpp
+++ b/xfa/fgas/font/cfgas_gefont.cpp
@@ -79,15 +79,17 @@ CFGAS_GEFont::CFGAS_GEFont(const RetainPtr<CFGAS_GEFont>& src,
ASSERT(m_pSrcFont->m_pFont);
m_pFont = new CFX_Font;
m_pFont->LoadClone(m_pSrcFont->m_pFont);
+
CFX_SubstFont* pSubst = m_pFont->GetSubstFont();
if (!pSubst) {
pSubst = new CFX_SubstFont;
m_pFont->SetSubstFont(std::unique_ptr<CFX_SubstFont>(pSubst));
}
pSubst->m_Weight =
- (dwFontStyles & FXFONT_BOLD) ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL;
- if (dwFontStyles & FXFONT_ITALIC)
+ FontStyleIsBold(dwFontStyles) ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL;
+ if (FontStyleIsItalic(dwFontStyles))
pSubst->m_bFlagItalic = true;
+
InitFont();
}
@@ -107,13 +109,13 @@ bool CFGAS_GEFont::LoadFontInternal(const wchar_t* pszFontFamily,
csFontFamily = ByteString::FromUnicode(pszFontFamily);
int32_t iWeight =
- (dwFontStyles & FXFONT_BOLD) ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL;
+ FontStyleIsBold(dwFontStyles) ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL;
m_pFont = new CFX_Font;
- if ((dwFontStyles & FXFONT_ITALIC) && (dwFontStyles & FXFONT_BOLD))
+ if (FontStyleIsItalic(dwFontStyles) && FontStyleIsBold(dwFontStyles))
csFontFamily += ",BoldItalic";
- else if (dwFontStyles & FXFONT_BOLD)
+ else if (FontStyleIsBold(dwFontStyles))
csFontFamily += ",Bold";
- else if (dwFontStyles & FXFONT_ITALIC)
+ else if (FontStyleIsItalic(dwFontStyles))
csFontFamily += ",Italic";
m_pFont->LoadSubst(csFontFamily, true, dwFontStyles, iWeight, 0, wCodePage,
diff --git a/xfa/fgas/font/cfgas_pdffontmgr.cpp b/xfa/fgas/font/cfgas_pdffontmgr.cpp
index 34d4ff1649..2b3f54b6a1 100644
--- a/xfa/fgas/font/cfgas_pdffontmgr.cpp
+++ b/xfa/fgas/font/cfgas_pdffontmgr.cpp
@@ -85,8 +85,8 @@ RetainPtr<CFGAS_GEFont> CFGAS_PDFFontMgr::GetFont(
return it->second;
ByteString bsPsName = ByteString::FromUnicode(WideString(wsFontFamily));
- bool bBold = (dwFontStyles & FXFONT_BOLD) == FXFONT_BOLD;
- bool bItalic = (dwFontStyles & FXFONT_ITALIC) == FXFONT_ITALIC;
+ bool bBold = FontStyleIsBold(dwFontStyles);
+ bool bItalic = FontStyleIsItalic(dwFontStyles);
ByteString strFontName = PsNameToFontName(bsPsName, bBold, bItalic);
RetainPtr<CFGAS_GEFont> pFont =
FindFont(strFontName, bBold, bItalic, pPDFFont, bStrictMatch);