summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/fpdfapi/font/cpdf_cidfont.cpp2
-rw-r--r--core/fpdfapi/font/cpdf_font.cpp2
-rw-r--r--core/fpdfapi/font/cpdf_simplefont.cpp6
-rw-r--r--core/fpdfapi/font/cpdf_truetypefont.cpp6
-rw-r--r--core/fpdfapi/font/cpdf_type1font.cpp6
-rw-r--r--core/fxge/android/cfpf_skiafontmgr.cpp18
-rw-r--r--core/fxge/android/cfx_androidfontinfo.cpp6
-rw-r--r--core/fxge/apple/fx_mac_imp.cpp6
-rw-r--r--core/fxge/cfx_folderfontinfo.cpp14
-rw-r--r--core/fxge/cfx_fontmapper.cpp172
-rw-r--r--core/fxge/fx_font.h37
-rw-r--r--core/fxge/fx_ge_linux.cpp2
-rw-r--r--fpdfsdk/fpdfedit_embeddertest.cpp13
-rw-r--r--xfa/fde/cfde_textout.cpp8
-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
18 files changed, 198 insertions, 165 deletions
diff --git a/core/fpdfapi/font/cpdf_cidfont.cpp b/core/fpdfapi/font/cpdf_cidfont.cpp
index 611afc0787..0140cc8a23 100644
--- a/core/fpdfapi/font/cpdf_cidfont.cpp
+++ b/core/fpdfapi/font/cpdf_cidfont.cpp
@@ -618,7 +618,7 @@ int CPDF_CIDFont::GlyphFromCharCode(uint32_t charcode, bool* pVertGlyph) {
#if _FX_PLATFORM_ != _FX_PLATFORM_APPLE_
return cid;
#else
- if (m_Flags & FXFONT_SYMBOLIC)
+ if (FontStyleIsSymbolic(m_Flags))
return cid;
WideString uni_str = UnicodeFromCharCode(charcode);
diff --git a/core/fpdfapi/font/cpdf_font.cpp b/core/fpdfapi/font/cpdf_font.cpp
index 9aaaa27b2e..12e5aaf3a8 100644
--- a/core/fpdfapi/font/cpdf_font.cpp
+++ b/core/fpdfapi/font/cpdf_font.cpp
@@ -375,7 +375,7 @@ void CPDF_Font::LoadPDFEncoding(CPDF_Object* pEncoding,
iBaseEncoding == PDFFONT_ENCODING_ZAPFDINGBATS) {
return;
}
- if ((m_Flags & FXFONT_SYMBOLIC) && m_BaseFont == "Symbol") {
+ if (FontStyleIsSymbolic(m_Flags) && m_BaseFont == "Symbol") {
if (!bTrueType)
iBaseEncoding = PDFFONT_ENCODING_ADOBE_SYMBOL;
return;
diff --git a/core/fpdfapi/font/cpdf_simplefont.cpp b/core/fpdfapi/font/cpdf_simplefont.cpp
index ccf514db07..92965b0948 100644
--- a/core/fpdfapi/font/cpdf_simplefont.cpp
+++ b/core/fpdfapi/font/cpdf_simplefont.cpp
@@ -134,7 +134,7 @@ bool CPDF_SimpleFont::LoadCommon() {
} else {
LoadSubstFont();
}
- if (!(m_Flags & FXFONT_SYMBOLIC))
+ if (!FontStyleIsSymbolic(m_Flags))
m_BaseEncoding = PDFFONT_ENCODING_STANDARD;
CPDF_Object* pEncoding = m_pFontDict->GetDirectObjectFor("Encoding");
LoadPDFEncoding(pEncoding, m_BaseEncoding, &m_CharNames, !!m_pFontFile,
@@ -144,7 +144,7 @@ bool CPDF_SimpleFont::LoadCommon() {
if (!m_Font.GetFace())
return true;
- if (m_Flags & FXFONT_ALLCAP) {
+ if (FontStyleIsAllCaps(m_Flags)) {
unsigned char kLowercases[][2] = {{'a', 'z'}, {0xe0, 0xf6}, {0xf8, 0xfd}};
for (size_t range = 0; range < FX_ArraySize(kLowercases); ++range) {
const auto& lower = kLowercases[range];
@@ -166,7 +166,7 @@ bool CPDF_SimpleFont::LoadCommon() {
}
void CPDF_SimpleFont::LoadSubstFont() {
- if (!m_bUseFontWidth && !(m_Flags & FXFONT_FIXED_PITCH)) {
+ if (!m_bUseFontWidth && !FontStyleIsFixedPitch(m_Flags)) {
int width = 0, i;
for (i = 0; i < 256; i++) {
if (m_CharWidth[i] == 0 || m_CharWidth[i] == 0xffff)
diff --git a/core/fpdfapi/font/cpdf_truetypefont.cpp b/core/fpdfapi/font/cpdf_truetypefont.cpp
index a0542ecba4..91c238a1b4 100644
--- a/core/fpdfapi/font/cpdf_truetypefont.cpp
+++ b/core/fpdfapi/font/cpdf_truetypefont.cpp
@@ -41,7 +41,7 @@ void CPDF_TrueTypeFont::LoadGlyphMap() {
if (m_pFontFile && m_Font.GetFace()->num_charmaps > 0 &&
(baseEncoding == PDFFONT_ENCODING_MACROMAN ||
baseEncoding == PDFFONT_ENCODING_WINANSI) &&
- (m_Flags & FXFONT_SYMBOLIC)) {
+ FontStyleIsSymbolic(m_Flags)) {
bool bSupportWin = false;
bool bSupportMac = false;
for (int i = 0; i < FXFT_Get_Face_CharmapCount(m_Font.GetFace()); i++) {
@@ -64,7 +64,7 @@ void CPDF_TrueTypeFont::LoadGlyphMap() {
if (((baseEncoding == PDFFONT_ENCODING_MACROMAN ||
baseEncoding == PDFFONT_ENCODING_WINANSI) &&
m_CharNames.empty()) ||
- (m_Flags & FXFONT_NONSYMBOLIC)) {
+ FontStyleIsNonSymbolic(m_Flags)) {
if (!FXFT_Has_Glyph_Names(m_Font.GetFace()) &&
(!m_Font.GetFace()->num_charmaps || !m_Font.GetFace()->charmaps)) {
int nStartChar = m_pFontDict->GetIntegerFor("FirstChar");
@@ -83,7 +83,7 @@ void CPDF_TrueTypeFont::LoadGlyphMap() {
bool bMacRoman = false;
bool bMSSymbol = false;
if (!bMSUnicode) {
- if (m_Flags & FXFONT_NONSYMBOLIC) {
+ if (FontStyleIsNonSymbolic(m_Flags)) {
bMacRoman = FT_UseTTCharmap(m_Font.GetFace(), 1, 0);
bMSSymbol = !bMacRoman && FT_UseTTCharmap(m_Font.GetFace(), 3, 0);
} else {
diff --git a/core/fpdfapi/font/cpdf_type1font.cpp b/core/fpdfapi/font/cpdf_type1font.cpp
index 296351fc82..9975943d9a 100644
--- a/core/fpdfapi/font/cpdf_type1font.cpp
+++ b/core/fpdfapi/font/cpdf_type1font.cpp
@@ -93,7 +93,7 @@ bool CPDF_Type1Font::Load() {
m_BaseEncoding = PDFFONT_ENCODING_ADOBE_SYMBOL;
else if (m_Base14Font == 13)
m_BaseEncoding = PDFFONT_ENCODING_ZAPFDINGBATS;
- else if (m_Flags & FXFONT_NONSYMBOLIC)
+ else if (FontStyleIsNonSymbolic(m_Flags))
m_BaseEncoding = PDFFONT_ENCODING_STANDARD;
}
return LoadCommon();
@@ -188,7 +188,7 @@ void CPDF_Type1Font::LoadGlyphMap() {
FT_UseType1Charmap(m_Font.GetFace());
#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
if (bCoreText) {
- if (m_Flags & FXFONT_SYMBOLIC) {
+ if (FontStyleIsSymbolic(m_Flags)) {
for (int charcode = 0; charcode < 256; charcode++) {
const char* name =
GetAdobeCharName(m_BaseEncoding, m_CharNames, charcode);
@@ -255,7 +255,7 @@ void CPDF_Type1Font::LoadGlyphMap() {
return;
}
#endif // _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
- if (m_Flags & FXFONT_SYMBOLIC) {
+ if (FontStyleIsSymbolic(m_Flags)) {
for (int charcode = 0; charcode < 256; charcode++) {
const char* name =
GetAdobeCharName(m_BaseEncoding, m_CharNames, charcode);
diff --git a/core/fxge/android/cfpf_skiafontmgr.cpp b/core/fxge/android/cfpf_skiafontmgr.cpp
index 214e718e0b..d8b751d9b2 100644
--- a/core/fxge/android/cfpf_skiafontmgr.cpp
+++ b/core/fxge/android/cfpf_skiafontmgr.cpp
@@ -176,11 +176,11 @@ uint32_t FPF_SKIAGetFamilyHash(const ByteStringView& bsFamily,
uint32_t dwStyle,
uint8_t uCharset) {
ByteString bsFont(bsFamily);
- if (dwStyle & FXFONT_BOLD)
+ if (FontStyleIsBold(dwStyle))
bsFont += "Bold";
- if (dwStyle & FXFONT_ITALIC)
+ if (FontStyleIsItalic(dwStyle))
bsFont += "Italic";
- if (dwStyle & FXFONT_SERIF)
+ if (FontStyleIsSerif(dwStyle))
bsFont += "Serif";
bsFont += uCharset;
return FPF_GetHashCode_StringA(bsFont.c_str(), bsFont.GetLength());
@@ -317,17 +317,17 @@ CFPF_SkiaFont* CFPF_SkiaFontMgr::CreateFont(const ByteStringView& bsFamilyname,
if (dwFaceName == dwSysFontName)
nFind += FPF_SKIAMATCHWEIGHT_NAME1;
bool bMatchedName = (nFind == FPF_SKIAMATCHWEIGHT_NAME1);
- if ((dwStyle & FXFONT_BOLD) == (pFontDes->m_dwStyle & FXFONT_BOLD))
+ if (FontStyleIsBold(dwStyle) == FontStyleIsBold(pFontDes->m_dwStyle))
nFind += FPF_SKIAMATCHWEIGHT_1;
- if ((dwStyle & FXFONT_ITALIC) == (pFontDes->m_dwStyle & FXFONT_ITALIC))
+ if (FontStyleIsItalic(dwStyle) == FontStyleIsItalic(pFontDes->m_dwStyle))
nFind += FPF_SKIAMATCHWEIGHT_1;
- if ((dwStyle & FXFONT_FIXED_PITCH) ==
- (pFontDes->m_dwStyle & FXFONT_FIXED_PITCH)) {
+ if (FontStyleIsFixedPitch(dwStyle) ==
+ FontStyleIsFixedPitch(pFontDes->m_dwStyle)) {
nFind += FPF_SKIAMATCHWEIGHT_2;
}
- if ((dwStyle & FXFONT_SERIF) == (pFontDes->m_dwStyle & FXFONT_SERIF))
+ if (FontStyleIsSerif(dwStyle) == FontStyleIsSerif(pFontDes->m_dwStyle))
nFind += FPF_SKIAMATCHWEIGHT_1;
- if ((dwStyle & FXFONT_SCRIPT) == (pFontDes->m_dwStyle & FXFONT_SCRIPT))
+ if (FontStyleIsScript(dwStyle) == FontStyleIsScript(pFontDes->m_dwStyle))
nFind += FPF_SKIAMATCHWEIGHT_2;
if (dwSubst == dwSysFontName || dwSubstSans == dwSysFontName) {
nFind += FPF_SKIAMATCHWEIGHT_NAME2;
diff --git a/core/fxge/android/cfx_androidfontinfo.cpp b/core/fxge/android/cfx_androidfontinfo.cpp
index c6c3e61866..15ac8c29b2 100644
--- a/core/fxge/android/cfx_androidfontinfo.cpp
+++ b/core/fxge/android/cfx_androidfontinfo.cpp
@@ -40,11 +40,11 @@ void* CFX_AndroidFontInfo::MapFont(int weight,
dwStyle |= FXFONT_BOLD;
if (bItalic)
dwStyle |= FXFONT_ITALIC;
- if (pitch_family & FXFONT_FF_FIXEDPITCH)
+ if (FontFamilyIsFixedPitch(pitch_family))
dwStyle |= FXFONT_FIXED_PITCH;
- if (pitch_family & FXFONT_FF_SCRIPT)
+ if (FontFamilyIsScript(pitch_family))
dwStyle |= FXFONT_SCRIPT;
- if (pitch_family & FXFONT_FF_ROMAN)
+ if (FontFamilyIsRoman(pitch_family))
dwStyle |= FXFONT_SERIF;
return m_pFontMgr->CreateFont(face, charset, dwStyle,
FPF_MATCHFONT_REPLACEANSI);
diff --git a/core/fxge/apple/fx_mac_imp.cpp b/core/fxge/apple/fx_mac_imp.cpp
index 637984797a..324f0200b9 100644
--- a/core/fxge/apple/fx_mac_imp.cpp
+++ b/core/fxge/apple/fx_mac_imp.cpp
@@ -56,8 +56,8 @@ void GetJapanesePreference(ByteString* face, int weight, int pitch_family) {
*face = JAPAN_GOTHIC;
return;
}
- *face = ((pitch_family & FXFONT_FF_ROMAN) || weight <= 400) ? JAPAN_MINCHO
- : JAPAN_GOTHIC;
+ *face = (FontFamilyIsRoman(pitch_family) || weight <= 400) ? JAPAN_MINCHO
+ : JAPAN_GOTHIC;
}
void* CFX_MacFontInfo::MapFont(int weight,
@@ -97,7 +97,7 @@ void* CFX_MacFontInfo::MapFont(int weight,
if (it != m_FontList.end())
return it->second.get();
- if (charset == FX_CHARSET_ANSI && (pitch_family & FXFONT_FF_FIXEDPITCH))
+ if (charset == FX_CHARSET_ANSI && FontFamilyIsFixedPitch(pitch_family))
return GetFont("Courier New");
if (charset == FX_CHARSET_ANSI || charset == FX_CHARSET_Symbol)
diff --git a/core/fxge/cfx_folderfontinfo.cpp b/core/fxge/cfx_folderfontinfo.cpp
index dbc8142d69..1ee9ea729a 100644
--- a/core/fxge/cfx_folderfontinfo.cpp
+++ b/core/fxge/cfx_folderfontinfo.cpp
@@ -92,18 +92,16 @@ int32_t GetSimilarValue(int weight,
int pitch_family,
uint32_t style) {
int32_t iSimilarValue = 0;
- if (!!(style & FXFONT_BOLD) == (weight > 400))
+ if (FontStyleIsBold(style) == (weight > 400))
iSimilarValue += 16;
- if (!!(style & FXFONT_ITALIC) == bItalic)
+ if (FontStyleIsItalic(style) == bItalic)
iSimilarValue += 16;
- if (!!(style & FXFONT_SERIF) == !!(pitch_family & FXFONT_FF_ROMAN))
+ if (FontStyleIsSerif(style) == FontFamilyIsRoman(pitch_family))
iSimilarValue += 16;
- if (!!(style & FXFONT_SCRIPT) == !!(pitch_family & FXFONT_FF_SCRIPT))
+ if (FontStyleIsScript(style) == FontFamilyIsScript(pitch_family))
iSimilarValue += 8;
- if (!!(style & FXFONT_FIXED_PITCH) ==
- !!(pitch_family & FXFONT_FF_FIXEDPITCH)) {
+ if (FontStyleIsFixedPitch(style) == FontFamilyIsFixedPitch(pitch_family))
iSimilarValue += 8;
- }
return iSimilarValue;
}
@@ -284,7 +282,7 @@ void* CFX_FolderFontInfo::FindFont(int weight,
const char* family,
bool bMatchName) {
FontFaceInfo* pFind = nullptr;
- if (charset == FX_CHARSET_ANSI && (pitch_family & FXFONT_FF_FIXEDPITCH))
+ if (charset == FX_CHARSET_ANSI && FontFamilyIsFixedPitch(pitch_family))
return GetFont("Courier New");
uint32_t charset_flag = GetCharset(charset);
diff --git a/core/fxge/cfx_fontmapper.cpp b/core/fxge/cfx_fontmapper.cpp
index e7d27af573..362e9bc0b4 100644
--- a/core/fxge/cfx_fontmapper.cpp
+++ b/core/fxge/cfx_fontmapper.cpp
@@ -9,6 +9,7 @@
#include <algorithm>
#include <memory>
#include <sstream>
+#include <tuple>
#include <utility>
#include <vector>
@@ -19,11 +20,6 @@
#include "third_party/base/stl_util.h"
-#define FX_FONT_STYLE_None 0x00
-#define FX_FONT_STYLE_Bold 0x01
-#define FX_FONT_STYLE_Italic 0x02
-#define FX_FONT_STYLE_BoldBold 0x04
-
namespace {
const int kNumStandardFonts = 14;
@@ -149,13 +145,6 @@ const struct AltFontFamily {
{"ForteMT", "Forte"},
};
-const struct FX_FontStyle {
- const char* style;
- int32_t len;
-} g_FontStyles[] = {
- {"Bold", 4}, {"Italic", 6}, {"BoldItalic", 10}, {"Reg", 3}, {"Regular", 7},
-};
-
const struct CODEPAGE_MAP {
uint16_t codepage;
uint8_t charset;
@@ -207,9 +196,9 @@ uint8_t GetCharsetFromCodePage(uint16_t codepage) {
return FX_CHARSET_Default;
}
-ByteString GetFontFamily(ByteString fontName, int nStyle) {
+ByteString GetFontFamily(ByteString fontName, uint32_t nStyle) {
if (fontName.Contains("Script")) {
- if ((nStyle & FX_FONT_STYLE_Bold) == FX_FONT_STYLE_Bold)
+ if (FontStyleIsBold(nStyle))
fontName = "ScriptMTBold";
else if (fontName.Contains("Palace"))
fontName = "PalaceScriptMT";
@@ -238,26 +227,38 @@ ByteString ParseStyle(const char* pStyle, int iLen, int iIndex) {
return ByteString(buf);
}
-int32_t GetStyleType(const ByteString& bsStyle, bool bReverse) {
- int32_t iLen = bsStyle.GetLength();
- if (!iLen)
- return -1;
- int iSize = FX_ArraySize(g_FontStyles);
- const FX_FontStyle* pStyle = nullptr;
- for (int i = iSize - 1; i >= 0; --i) {
- pStyle = g_FontStyles + i;
- if (!pStyle || pStyle->len > iLen)
+const struct FX_FontStyle {
+ const char* name;
+ size_t len;
+ uint32_t style;
+} g_FontStyles[] = {
+ {"Bold", 4, FXFONT_BOLD},
+ {"Italic", 6, FXFONT_ITALIC},
+ {"BoldItalic", 10, FXFONT_BOLD | FXFONT_ITALIC},
+ {"Reg", 3, FXFONT_NORMAL},
+ {"Regular", 7, FXFONT_NORMAL},
+};
+
+// <exists, index, length>
+std::tuple<bool, uint32_t, size_t> GetStyleType(const ByteString& bsStyle,
+ bool bReverse) {
+ if (bsStyle.IsEmpty())
+ return {false, FXFONT_NORMAL, 0};
+
+ for (int i = FX_ArraySize(g_FontStyles) - 1; i >= 0; --i) {
+ const FX_FontStyle* pStyle = g_FontStyles + i;
+ if (!pStyle || pStyle->len > bsStyle.GetLength())
continue;
if (bReverse) {
- if (bsStyle.Right(pStyle->len).Compare(pStyle->style) == 0)
- return i;
+ if (bsStyle.Right(pStyle->len).Compare(pStyle->name) == 0)
+ return {true, pStyle->style, pStyle->len};
} else {
- if (bsStyle.Left(pStyle->len).Compare(pStyle->style) == 0)
- return i;
+ if (bsStyle.Left(pStyle->len).Compare(pStyle->name) == 0)
+ return {true, pStyle->style, pStyle->len};
}
}
- return -1;
+ return {false, FXFONT_NORMAL, 0};
}
bool CheckSupportThirdPartFont(ByteString name, int& PitchFamily) {
@@ -269,11 +270,11 @@ bool CheckSupportThirdPartFont(ByteString name, int& PitchFamily) {
}
void UpdatePitchFamily(uint32_t flags, int& PitchFamily) {
- if (flags & FXFONT_SERIF)
+ if (FontStyleIsSerif(flags))
PitchFamily |= FXFONT_FF_ROMAN;
- if (flags & FXFONT_SCRIPT)
+ if (FontStyleIsScript(flags))
PitchFamily |= FXFONT_FF_SCRIPT;
- if (flags & FXFONT_FIXED_PITCH)
+ if (FontStyleIsFixedPitch(flags))
PitchFamily |= FXFONT_FF_FIXEDPITCH;
}
@@ -380,7 +381,7 @@ FXFT_Face CFX_FontMapper::UseInternalSubst(CFX_SubstFont* pSubstFont,
int iBaseFont,
int italic_angle,
int weight,
- int picthfamily) {
+ int pitch_family) {
if (iBaseFont < kNumStandardFonts) {
if (m_FoxitFaces[iBaseFont])
return m_FoxitFaces[iBaseFont];
@@ -395,7 +396,7 @@ FXFT_Face CFX_FontMapper::UseInternalSubst(CFX_SubstFont* pSubstFont,
pSubstFont->m_ItalicAngle = italic_angle;
if (weight)
pSubstFont->m_Weight = weight;
- if (picthfamily & FXFONT_FF_ROMAN) {
+ if (FontFamilyIsRoman(pitch_family)) {
pSubstFont->m_Weight = pSubstFont->m_Weight * 4 / 5;
pSubstFont->m_Family = "Chrome Serif";
if (m_MMFaces[1])
@@ -423,6 +424,9 @@ FXFT_Face CFX_FontMapper::FindSubstFont(const ByteString& name,
int italic_angle,
int WindowCP,
CFX_SubstFont* pSubstFont) {
+ if (weight == 0)
+ weight = FXFONT_FW_NORMAL;
+
if (!(flags & FXFONT_USEEXTERNATTR)) {
weight = FXFONT_FW_NORMAL;
italic_angle = 0;
@@ -462,13 +466,13 @@ FXFT_Face CFX_FontMapper::FindSubstFont(const ByteString& name,
}
int PitchFamily = 0;
bool bItalic = false;
- uint32_t nStyle = 0;
+ uint32_t nStyle = FXFONT_NORMAL;
bool bStyleAvail = false;
if (iBaseFont < 12) {
if ((iBaseFont % 4) == 1 || (iBaseFont % 4) == 2)
- nStyle |= FX_FONT_STYLE_Bold;
+ nStyle |= FXFONT_BOLD;
if ((iBaseFont % 4) / 2)
- nStyle |= FX_FONT_STYLE_Italic;
+ nStyle |= FXFONT_ITALIC;
if (iBaseFont < 4)
PitchFamily |= FXFONT_FF_FIXEDPITCH;
if (iBaseFont >= 8)
@@ -485,19 +489,22 @@ FXFT_Face CFX_FontMapper::FindSubstFont(const ByteString& name,
}
if (!bHasHyphen) {
int nLen = family.GetLength();
- int32_t nRet = GetStyleType(family, true);
- if (nRet > -1) {
- family = family.Left(nLen - g_FontStyles[nRet].len);
- if (nRet == 0)
- nStyle |= FX_FONT_STYLE_Bold;
- else if (nRet == 1)
- nStyle |= FX_FONT_STYLE_Italic;
- else if (nRet == 2)
- nStyle |= (FX_FONT_STYLE_Bold | FX_FONT_STYLE_Italic);
+ bool hasStyleType;
+ uint32_t styleType;
+ size_t len;
+ std::tie(hasStyleType, styleType, len) = GetStyleType(family, true);
+ if (hasStyleType) {
+ family = family.Left(nLen - len);
+ nStyle |= styleType;
}
}
UpdatePitchFamily(flags, PitchFamily);
}
+
+ int old_weight = weight;
+ if (FontStyleIsBold(nStyle))
+ weight = FXFONT_FW_BOLD;
+
if (!style.IsEmpty()) {
int nLen = style.GetLength();
const char* pStyle = style.c_str();
@@ -506,57 +513,54 @@ FXFT_Face CFX_FontMapper::FindSubstFont(const ByteString& name,
ByteString buf;
while (i < nLen) {
buf = ParseStyle(pStyle, nLen, i);
- int32_t nRet = GetStyleType(buf, false);
- if ((i && !bStyleAvail) || (!i && nRet < 0)) {
+
+ bool hasStyleType;
+ uint32_t styleType;
+ size_t len;
+ std::tie(hasStyleType, styleType, len) = GetStyleType(buf, false);
+ if ((i && !bStyleAvail) || (!i && !hasStyleType)) {
family = SubstName;
iBaseFont = kNumStandardFonts;
break;
}
- if (nRet >= 0) {
+ if (hasStyleType)
bStyleAvail = true;
+
+ if (FontStyleIsBold(styleType)) {
+ // If we're already bold, then we're double bold, use special weight.
+ if (FontStyleIsBold(nStyle)) {
+ weight = FXFONT_FW_BOLD_BOLD;
+ } else {
+ weight = FXFONT_FW_BOLD;
+ nStyle |= FXFONT_BOLD;
+ }
+
+ bFirstItem = false;
}
- if (nRet == 1) {
+ if (FontStyleIsItalic(styleType) && FontStyleIsBold(styleType)) {
+ nStyle |= FXFONT_ITALIC;
+ } else if (FontStyleIsItalic(styleType)) {
if (bFirstItem) {
- nStyle |= FX_FONT_STYLE_Italic;
+ nStyle |= FXFONT_ITALIC;
} else {
family = SubstName;
iBaseFont = kNumStandardFonts;
}
break;
}
- if (nRet == 0) {
- if (nStyle & FX_FONT_STYLE_Bold)
- nStyle |= FX_FONT_STYLE_BoldBold;
- else
- nStyle |= FX_FONT_STYLE_Bold;
- bFirstItem = false;
- } else if (nRet == 2) {
- nStyle |= FX_FONT_STYLE_Italic;
- if (nStyle & FX_FONT_STYLE_Bold)
- nStyle |= FX_FONT_STYLE_BoldBold;
- else
- nStyle |= FX_FONT_STYLE_Bold;
- bFirstItem = false;
- }
i += buf.GetLength() + 1;
}
}
- weight = weight ? weight : FXFONT_FW_NORMAL;
- int old_weight = weight;
- if (nStyle) {
- weight =
- nStyle & FX_FONT_STYLE_BoldBold
- ? 900
- : (nStyle & FX_FONT_STYLE_Bold ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL);
- }
- if (nStyle & FX_FONT_STYLE_Italic)
+ if (FontStyleIsItalic(nStyle))
bItalic = true;
+
int iExact = 0;
int Charset = FX_CHARSET_ANSI;
if (WindowCP)
Charset = GetCharsetFromCodePage(WindowCP);
- else if (iBaseFont == kNumStandardFonts && (flags & FXFONT_SYMBOLIC))
+ else if (iBaseFont == kNumStandardFonts && FontStyleIsSymbolic(flags))
Charset = FX_CHARSET_Symbol;
+
bool bCJK = (Charset == FX_CHARSET_ShiftJIS ||
Charset == FX_CHARSET_ChineseSimplified ||
Charset == FX_CHARSET_Hangul ||
@@ -594,33 +598,29 @@ FXFT_Face CFX_FontMapper::FindSubstFont(const ByteString& name,
pSubstFont->m_bSubstCJK = true;
if (nStyle)
pSubstFont->m_WeightCJK = nStyle ? weight : FXFONT_FW_NORMAL;
- if (nStyle & FX_FONT_STYLE_Italic)
+ if (FontStyleIsItalic(nStyle))
pSubstFont->m_bItalicCJK = true;
}
} else {
italic_angle = 0;
- weight =
- nStyle & FX_FONT_STYLE_BoldBold
- ? 900
- : (nStyle & FX_FONT_STYLE_Bold ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL);
}
+
if (!match.IsEmpty() || iBaseFont < kNumStandardFonts) {
if (!match.IsEmpty())
family = match;
if (iBaseFont < kNumStandardFonts) {
if (nStyle && !(iBaseFont % 4)) {
- if ((nStyle & 0x3) == 1)
+ if (FontStyleIsBold(nStyle) && FontStyleIsItalic(nStyle))
+ iBaseFont += 2;
+ else if (FontStyleIsBold(nStyle))
iBaseFont += 1;
- if ((nStyle & 0x3) == 2)
+ else if (FontStyleIsItalic(nStyle))
iBaseFont += 3;
- if ((nStyle & 0x3) == 3)
- iBaseFont += 2;
}
family = g_Base14FontNames[iBaseFont];
}
- } else {
- if (flags & FXFONT_ITALIC)
- bItalic = true;
+ } else if (FontStyleIsItalic(flags)) {
+ bItalic = true;
}
iExact = !match.IsEmpty();
void* hFont = m_pFontInfo->MapFont(weight, bItalic, Charset, PitchFamily,
diff --git a/core/fxge/fx_font.h b/core/fxge/fx_font.h
index 8f559829b6..f2550d0488 100644
--- a/core/fxge/fx_font.h
+++ b/core/fxge/fx_font.h
@@ -32,6 +32,7 @@ using CFX_TypeFace = SkTypeface;
/* Typical weight values */
#define FXFONT_FW_NORMAL 400
#define FXFONT_FW_BOLD 700
+#define FXFONT_FW_BOLD_BOLD 900
/* Font styles as defined in PDF 1.7 Table 5.20 */
#define FXFONT_NORMAL (0)
@@ -44,7 +45,6 @@ using CFX_TypeFace = SkTypeface;
#define FXFONT_ALLCAP (1 << 16)
#define FXFONT_SMALLCAP (1 << 17)
#define FXFONT_BOLD (1 << 18)
-#define FXFONT_BOLD_ITALIC (FXFONT_BOLD | FXFONT_ITALIC)
/* Other font flags */
#define FXFONT_USEEXTERNATTR 0x80000
@@ -105,4 +105,39 @@ ByteString GetNameFromTT(const uint8_t* name_table,
int PDF_GetStandardFontName(ByteString* name);
+inline bool FontStyleIsBold(uint32_t style) {
+ return !!(style & FXFONT_BOLD);
+}
+inline bool FontStyleIsItalic(uint32_t style) {
+ return !!(style & FXFONT_ITALIC);
+}
+inline bool FontStyleIsFixedPitch(uint32_t style) {
+ return !!(style & FXFONT_FIXED_PITCH);
+}
+inline bool FontStyleIsSymbolic(uint32_t style) {
+ return !!(style & FXFONT_SYMBOLIC);
+}
+inline bool FontStyleIsNonSymbolic(uint32_t style) {
+ return !!(style & FXFONT_NONSYMBOLIC);
+}
+inline bool FontStyleIsAllCaps(uint32_t style) {
+ return !!(style & FXFONT_ALLCAP);
+}
+inline bool FontStyleIsSerif(uint32_t style) {
+ return !!(style & FXFONT_SERIF);
+}
+inline bool FontStyleIsScript(uint32_t style) {
+ return !!(style & FXFONT_SCRIPT);
+}
+
+inline bool FontFamilyIsFixedPitch(uint32_t family) {
+ return !!(family & FXFONT_FF_FIXEDPITCH);
+}
+inline bool FontFamilyIsRoman(uint32_t family) {
+ return !!(family & FXFONT_FF_ROMAN);
+}
+inline bool FontFamilyIsScript(int32_t family) {
+ return !!(family & FXFONT_FF_SCRIPT);
+}
+
#endif // CORE_FXGE_FX_FONT_H_
diff --git a/core/fxge/fx_ge_linux.cpp b/core/fxge/fx_ge_linux.cpp
index 302470b386..c9d1dd128b 100644
--- a/core/fxge/fx_ge_linux.cpp
+++ b/core/fxge/fx_ge_linux.cpp
@@ -59,7 +59,7 @@ size_t GetJapanesePreference(const char* facearr,
}
return 3;
}
- if (!(pitch_family & FXFONT_FF_ROMAN) && weight > 400)
+ if (!FontFamilyIsRoman(pitch_family) && weight > 400)
return 0;
return 2;
diff --git a/fpdfsdk/fpdfedit_embeddertest.cpp b/fpdfsdk/fpdfedit_embeddertest.cpp
index 1fb0cde7f9..74e85f6795 100644
--- a/fpdfsdk/fpdfedit_embeddertest.cpp
+++ b/fpdfsdk/fpdfedit_embeddertest.cpp
@@ -47,16 +47,11 @@ class FPDFEditEmbeddertest : public EmbedderTest {
// Check that the font descriptor has the required keys according to spec
// 1.7 Table 5.19
ASSERT_TRUE(font_desc->KeyExist("Flags"));
+
int font_flags = font_desc->GetIntegerFor("Flags");
- if (bold)
- EXPECT_TRUE(font_flags & FXFONT_BOLD);
- else
- EXPECT_FALSE(font_flags & FXFONT_BOLD);
- if (italic)
- EXPECT_TRUE(font_flags & FXFONT_ITALIC);
- else
- EXPECT_FALSE(font_flags & FXFONT_ITALIC);
- EXPECT_TRUE(font_flags & FXFONT_NONSYMBOLIC);
+ EXPECT_EQ(bold, FontStyleIsBold(font_flags));
+ EXPECT_EQ(italic, FontStyleIsItalic(font_flags));
+ EXPECT_TRUE(FontStyleIsNonSymbolic(font_flags));
ASSERT_TRUE(font_desc->KeyExist("FontBBox"));
CPDF_Array* fontBBox = font_desc->GetArrayFor("FontBBox");
diff --git a/xfa/fde/cfde_textout.cpp b/xfa/fde/cfde_textout.cpp
index 2cdaeba27b..2f41525c00 100644
--- a/xfa/fde/cfde_textout.cpp
+++ b/xfa/fde/cfde_textout.cpp
@@ -42,7 +42,7 @@ bool CFDE_TextOut::DrawString(CFX_RenderDevice* device,
ASSERT(pFont && pCharPos && iCount > 0);
CFX_Font* pFxFont = pFont->GetDevFont();
- if ((pFont->GetFontStyles() & FXFONT_ITALIC) != 0 && !pFxFont->IsItalic()) {
+ if (FontStyleIsItalic(pFont->GetFontStyles()) && !pFxFont->IsItalic()) {
for (int32_t i = 0; i < iCount; ++i) {
static const float mc = 0.267949f;
float* pAM = pCharPos->m_AdjustMatrix;
@@ -56,10 +56,10 @@ bool CFDE_TextOut::DrawString(CFX_RenderDevice* device,
uint32_t dwFontStyle = pFont->GetFontStyles();
CFX_Font FxFont;
auto SubstFxFont = pdfium::MakeUnique<CFX_SubstFont>();
- SubstFxFont->m_Weight = dwFontStyle & FXFONT_BOLD ? 700 : 400;
- SubstFxFont->m_ItalicAngle = dwFontStyle & FXFONT_ITALIC ? -12 : 0;
+ SubstFxFont->m_Weight = FontStyleIsBold(dwFontStyle) ? 700 : 400;
+ SubstFxFont->m_ItalicAngle = FontStyleIsItalic(dwFontStyle) ? -12 : 0;
SubstFxFont->m_WeightCJK = SubstFxFont->m_Weight;
- SubstFxFont->m_bItalicCJK = !!(dwFontStyle & FXFONT_ITALIC);
+ SubstFxFont->m_bItalicCJK = FontStyleIsItalic(dwFontStyle);
FxFont.SetSubstFont(std::move(SubstFxFont));
#endif // _FX_PLATFORM_ != _FX_PLATFORM_WINDOWS_
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);