summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-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
12 files changed, 155 insertions, 122 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;