Convert FX_CHARSET to an enum type.
This is complicated because charsets are exposed as ints in the public
API, so some structs and functions must remain using ints.
Change-Id: I8136dc3a79f35483e87840e73d617594019fe4bf
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/83330
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_docpagedata.cpp b/core/fpdfapi/page/cpdf_docpagedata.cpp
index 1781055..609fe22 100644
--- a/core/fpdfapi/page/cpdf_docpagedata.cpp
+++ b/core/fpdfapi/page/cpdf_docpagedata.cpp
@@ -468,7 +468,7 @@
}
RetainPtr<CPDF_Font> CPDF_DocPageData::AddFont(std::unique_ptr<CFX_Font> pFont,
- int charset) {
+ FX_Charset charset) {
if (!pFont)
return nullptr;
@@ -477,7 +477,7 @@
basefont.Replace(" ", "");
int flags =
CalculateFlags(pFont->IsBold(), pFont->IsItalic(), pFont->IsFixedWidth(),
- false, false, charset == FX_CHARSET_Symbol);
+ false, false, charset == FX_Charset::kSymbol);
CPDF_Dictionary* pBaseDict = GetDocument()->NewIndirect<CPDF_Dictionary>();
pBaseDict->SetNewFor<CPDF_Name>("Type", "Font");
@@ -490,8 +490,8 @@
int char_width = pFont->GetGlyphWidth(glyph_index);
pWidths->AppendNew<CPDF_Number>(char_width);
}
- if (charset == FX_CHARSET_ANSI || charset == FX_CHARSET_Default ||
- charset == FX_CHARSET_Symbol) {
+ if (charset == FX_Charset::kANSI || charset == FX_Charset::kDefault ||
+ charset == FX_Charset::kSymbol) {
pBaseDict->SetNewFor<CPDF_Name>("Encoding", "WinAnsiEncoding");
for (int charcode = 128; charcode <= 255; charcode++) {
int glyph_index = pEncoding->GlyphFromCharCode(charcode);
@@ -567,13 +567,15 @@
LPBYTE tm_buf = FX_Alloc(BYTE, tm_size);
OUTLINETEXTMETRIC* ptm = reinterpret_cast<OUTLINETEXTMETRIC*>(tm_buf);
GetOutlineTextMetrics(hDC, tm_size, ptm);
- int flags = CalculateFlags(false, pLogFont->lfItalic != 0,
- (pLogFont->lfPitchAndFamily & 3) == FIXED_PITCH,
- (pLogFont->lfPitchAndFamily & 0xf8) == FF_ROMAN,
- (pLogFont->lfPitchAndFamily & 0xf8) == FF_SCRIPT,
- pLogFont->lfCharSet == FX_CHARSET_Symbol);
+ int flags = CalculateFlags(
+ false, pLogFont->lfItalic != 0,
+ (pLogFont->lfPitchAndFamily & 3) == FIXED_PITCH,
+ (pLogFont->lfPitchAndFamily & 0xf8) == FF_ROMAN,
+ (pLogFont->lfPitchAndFamily & 0xf8) == FF_SCRIPT,
+ pLogFont->lfCharSet == static_cast<int>(FX_Charset::kSymbol));
- const bool bCJK = FX_CharSetIsCJK(pLogFont->lfCharSet);
+ const FX_Charset eCharset = FX_GetCharsetFromInt(pLogFont->lfCharSet);
+ const bool bCJK = FX_CharSetIsCJK(eCharset);
ByteString basefont;
if (bCJK)
basefont = GetPSNameFromTT(hDC);
@@ -593,12 +595,11 @@
pBaseDict->SetNewFor<CPDF_Name>("Type", "Font");
CPDF_Dictionary* pFontDict = pBaseDict;
if (!bCJK) {
- if (pLogFont->lfCharSet == FX_CHARSET_ANSI ||
- pLogFont->lfCharSet == FX_CHARSET_Default ||
- pLogFont->lfCharSet == FX_CHARSET_Symbol) {
+ if (eCharset == FX_Charset::kANSI || eCharset == FX_Charset::kDefault ||
+ eCharset == FX_Charset::kSymbol) {
pBaseDict->SetNewFor<CPDF_Name>("Encoding", "WinAnsiEncoding");
} else {
- CalculateEncodingDict(pLogFont->lfCharSet, pBaseDict);
+ CalculateEncodingDict(eCharset, pBaseDict);
}
int char_widths[224];
GetCharWidth(hDC, 32, 255, char_widths);
@@ -609,7 +610,7 @@
pLogFont->lfItalic != 0, basefont, std::move(pWidths));
} else {
pFontDict =
- ProcessbCJK(pBaseDict, pLogFont->lfCharSet, basefont,
+ ProcessbCJK(pBaseDict, eCharset, basefont,
[&hDC](wchar_t start, wchar_t end, CPDF_Array* widthArr) {
InsertWidthArray(hDC, start, end, widthArr);
});
@@ -632,7 +633,7 @@
}
#endif // defined(OS_WIN)
-size_t CPDF_DocPageData::CalculateEncodingDict(int charset,
+size_t CPDF_DocPageData::CalculateEncodingDict(FX_Charset charset,
CPDF_Dictionary* pBaseDict) {
size_t i;
for (i = 0; i < pdfium::size(g_FX_CharsetUnicodes); ++i) {
@@ -661,7 +662,7 @@
CPDF_Dictionary* CPDF_DocPageData::ProcessbCJK(
CPDF_Dictionary* pBaseDict,
- int charset,
+ FX_Charset charset,
ByteString basefont,
std::function<void(wchar_t, wchar_t, CPDF_Array*)> Insert) {
CPDF_Dictionary* pFontDict = GetDocument()->NewIndirect<CPDF_Dictionary>();
@@ -670,14 +671,14 @@
int supplement = 0;
CPDF_Array* pWidthArray = pFontDict->SetNewFor<CPDF_Array>("W");
switch (charset) {
- case FX_CHARSET_ChineseTraditional:
+ case FX_Charset::kChineseTraditional:
cmap = "ETenms-B5-H";
ordering = "CNS1";
supplement = 4;
pWidthArray->AppendNew<CPDF_Number>(1);
Insert(0x20, 0x7e, pWidthArray);
break;
- case FX_CHARSET_ChineseSimplified:
+ case FX_Charset::kChineseSimplified:
cmap = "GBK-EUC-H";
ordering = "GB1";
supplement = 2;
@@ -686,14 +687,14 @@
pWidthArray->AppendNew<CPDF_Number>(814);
Insert(0x21, 0x7e, pWidthArray);
break;
- case FX_CHARSET_Hangul:
+ case FX_Charset::kHangul:
cmap = "KSCms-UHC-H";
ordering = "Korea1";
supplement = 2;
pWidthArray->AppendNew<CPDF_Number>(1);
Insert(0x20, 0x7e, pWidthArray);
break;
- case FX_CHARSET_ShiftJIS:
+ case FX_Charset::kShiftJIS:
cmap = "90ms-RKSJ-H";
ordering = "Japan1";
supplement = 5;
@@ -706,6 +707,8 @@
pWidthArray->AppendNew<CPDF_Number>(631);
Insert(0x7e, 0x7e, pWidthArray);
break;
+ default:
+ break;
}
pBaseDict->SetNewFor<CPDF_Name>("Subtype", "Type0");
pBaseDict->SetNewFor<CPDF_Name>("BaseFont", basefont);
diff --git a/core/fpdfapi/page/cpdf_docpagedata.h b/core/fpdfapi/page/cpdf_docpagedata.h
index 5fbcd0a..2772199 100644
--- a/core/fpdfapi/page/cpdf_docpagedata.h
+++ b/core/fpdfapi/page/cpdf_docpagedata.h
@@ -14,6 +14,7 @@
#include "core/fpdfapi/font/cpdf_font.h"
#include "core/fpdfapi/page/cpdf_colorspace.h"
#include "core/fpdfapi/parser/cpdf_document.h"
+#include "core/fxcrt/fx_codepage_forward.h"
#include "core/fxcrt/fx_coordinates.h"
#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/observed_ptr.h"
@@ -51,7 +52,8 @@
bool IsForceClear() const { return m_bForceClear; }
- RetainPtr<CPDF_Font> AddFont(std::unique_ptr<CFX_Font> pFont, int charset);
+ RetainPtr<CPDF_Font> AddFont(std::unique_ptr<CFX_Font> pFont,
+ FX_Charset charset);
RetainPtr<CPDF_Font> GetFont(CPDF_Dictionary* pFontDict);
RetainPtr<CPDF_Font> AddStandardFont(const ByteString& fontName,
const CPDF_FontEncoding* pEncoding);
@@ -95,10 +97,10 @@
std::set<const CPDF_Object*>* pVisited,
std::set<const CPDF_Object*>* pVisitedInternal);
- size_t CalculateEncodingDict(int charset, CPDF_Dictionary* pBaseDict);
+ size_t CalculateEncodingDict(FX_Charset charset, CPDF_Dictionary* pBaseDict);
CPDF_Dictionary* ProcessbCJK(
CPDF_Dictionary* pBaseDict,
- int charset,
+ FX_Charset charset,
ByteString basefont,
std::function<void(wchar_t, wchar_t, CPDF_Array*)> Insert);
diff --git a/core/fpdfdoc/cpdf_bafontmap.cpp b/core/fpdfdoc/cpdf_bafontmap.cpp
index 174e937..57b4968 100644
--- a/core/fpdfdoc/cpdf_bafontmap.cpp
+++ b/core/fpdfdoc/cpdf_bafontmap.cpp
@@ -42,7 +42,7 @@
RetainPtr<CPDF_Font> AddNativeTrueTypeFontToPDF(CPDF_Document* pDoc,
ByteString sFontFaceName,
- uint8_t nCharset) {
+ FX_Charset nCharset) {
if (!pDoc)
return nullptr;
@@ -64,7 +64,7 @@
CPDF_Dictionary* pAnnotDict,
const ByteString& sAPType)
: m_pDocument(pDocument), m_pAnnotDict(pAnnotDict), m_sAPType(sAPType) {
- int32_t nCharset = FX_CHARSET_Default;
+ FX_Charset nCharset = FX_Charset::kDefault;
m_pDefaultFont = GetAnnotDefaultFont(&m_sDefaultFontName);
if (m_pDefaultFont) {
const CFX_SubstFont* pSubstFont = m_pDefaultFont->GetSubstFont();
@@ -74,16 +74,16 @@
m_sDefaultFontName == "Wingdings2" ||
m_sDefaultFontName == "Wingdings3" ||
m_sDefaultFontName == "Webdings") {
- nCharset = FX_CHARSET_Symbol;
+ nCharset = FX_Charset::kSymbol;
} else {
- nCharset = FX_CHARSET_ANSI;
+ nCharset = FX_Charset::kANSI;
}
AddFontData(m_pDefaultFont, m_sDefaultFontName, nCharset);
AddFontToAnnotDict(m_pDefaultFont, m_sDefaultFontName);
}
- if (nCharset != FX_CHARSET_ANSI)
- GetFontIndex(CFX_Font::kDefaultAnsiFontName, FX_CHARSET_ANSI, false);
+ if (nCharset != FX_Charset::kANSI)
+ GetFontIndex(CFX_Font::kDefaultAnsiFontName, FX_Charset::kANSI, false);
}
CPDF_BAFontMap::~CPDF_BAFontMap() = default;
@@ -101,7 +101,7 @@
}
int32_t CPDF_BAFontMap::GetWordFontIndex(uint16_t word,
- int32_t nCharset,
+ FX_Charset nCharset,
int32_t nFontIndex) {
if (nFontIndex > 0) {
if (KnowWord(nFontIndex, word))
@@ -109,8 +109,9 @@
} else {
if (!m_Data.empty()) {
const Data* pData = m_Data.front().get();
- if (nCharset == FX_CHARSET_Default ||
- pData->nCharset == FX_CHARSET_Symbol || nCharset == pData->nCharset) {
+ if (nCharset == FX_Charset::kDefault ||
+ pData->nCharset == FX_Charset::kSymbol ||
+ nCharset == pData->nCharset) {
if (KnowWord(0, word))
return 0;
}
@@ -124,7 +125,7 @@
return nNewFontIndex;
}
nNewFontIndex = GetFontIndex(CFX_Font::kUniversalDefaultFontName,
- FX_CHARSET_Default, false);
+ FX_Charset::kDefault, false);
if (nNewFontIndex >= 0) {
if (KnowWord(nNewFontIndex, word))
return nNewFontIndex;
@@ -146,24 +147,25 @@
return word < 0xFF ? word : -1;
}
-int32_t CPDF_BAFontMap::CharSetFromUnicode(uint16_t word, int32_t nOldCharset) {
+FX_Charset CPDF_BAFontMap::CharSetFromUnicode(uint16_t word,
+ FX_Charset nOldCharset) {
// to avoid CJK Font to show ASCII
if (word < 0x7F)
- return FX_CHARSET_ANSI;
+ return FX_Charset::kANSI;
// follow the old charset
- if (nOldCharset != FX_CHARSET_Default)
+ if (nOldCharset != FX_Charset::kDefault)
return nOldCharset;
return CFX_Font::GetCharSetFromUnicode(word);
}
-int32_t CPDF_BAFontMap::GetNativeCharset() {
+FX_Charset CPDF_BAFontMap::GetNativeCharset() {
return FX_GetCharsetFromCodePage(FX_GetACP());
}
RetainPtr<CPDF_Font> CPDF_BAFontMap::FindFontSameCharset(ByteString* sFontAlias,
- int32_t nCharset) {
+ FX_Charset nCharset) {
if (m_pAnnotDict->GetNameFor(pdfium::annotation::kSubtype) != "Widget")
return nullptr;
@@ -185,7 +187,7 @@
RetainPtr<CPDF_Font> CPDF_BAFontMap::FindResFontSameCharset(
const CPDF_Dictionary* pResDict,
ByteString* sFontAlias,
- int32_t nCharset) {
+ FX_Charset nCharset) {
if (!pResDict)
return nullptr;
@@ -325,7 +327,7 @@
}
int32_t CPDF_BAFontMap::GetFontIndex(const ByteString& sFontName,
- int32_t nCharset,
+ FX_Charset nCharset,
bool bFind) {
int32_t nFontIndex = FindFont(EncodeFontAlias(sFontName, nCharset), nCharset);
if (nFontIndex >= 0)
@@ -345,7 +347,7 @@
int32_t CPDF_BAFontMap::AddFontData(const RetainPtr<CPDF_Font>& pFont,
const ByteString& sFontAlias,
- int32_t nCharset) {
+ FX_Charset nCharset) {
auto pNewData = std::make_unique<Data>();
pNewData->pFont = pFont;
pNewData->sFontName = sFontAlias;
@@ -355,7 +357,7 @@
}
ByteString CPDF_BAFontMap::EncodeFontAlias(const ByteString& sFontName,
- int32_t nCharset) {
+ FX_Charset nCharset) {
ByteString sRet = sFontName;
sRet.Remove(' ');
sRet += ByteString::Format("_%02X", nCharset);
@@ -363,10 +365,10 @@
}
int32_t CPDF_BAFontMap::FindFont(const ByteString& sFontName,
- int32_t nCharset) {
+ FX_Charset nCharset) {
int32_t i = 0;
for (const auto& pData : m_Data) {
- if ((nCharset == FX_CHARSET_Default || nCharset == pData->nCharset) &&
+ if ((nCharset == FX_Charset::kDefault || nCharset == pData->nCharset) &&
(sFontName.IsEmpty() || pData->sFontName == sFontName)) {
return i;
}
@@ -375,8 +377,8 @@
return -1;
}
-ByteString CPDF_BAFontMap::GetNativeFontName(int32_t nCharset) {
- if (nCharset == FX_CHARSET_Default)
+ByteString CPDF_BAFontMap::GetNativeFontName(FX_Charset nCharset) {
+ if (nCharset == FX_Charset::kDefault)
nCharset = GetNativeCharset();
ByteString sFontName = CFX_Font::GetDefaultFontNameByCharset(nCharset);
@@ -386,7 +388,7 @@
return sFontName;
}
-ByteString CPDF_BAFontMap::GetCachedNativeFontName(int32_t nCharset) {
+ByteString CPDF_BAFontMap::GetCachedNativeFontName(FX_Charset nCharset) {
for (const auto& pData : m_NativeFont) {
if (pData && pData->nCharset == nCharset)
return pData->sFontName;
@@ -404,7 +406,7 @@
}
RetainPtr<CPDF_Font> CPDF_BAFontMap::AddFontToDocument(ByteString sFontName,
- uint8_t nCharset) {
+ FX_Charset nCharset) {
if (CFX_FontMapper::IsStandardFontName(sFontName))
return AddStandardFont(sFontName);
@@ -421,11 +423,11 @@
}
RetainPtr<CPDF_Font> CPDF_BAFontMap::AddSystemFont(ByteString sFontName,
- uint8_t nCharset) {
+ FX_Charset nCharset) {
if (sFontName.IsEmpty())
sFontName = GetNativeFontName(nCharset);
- if (nCharset == FX_CHARSET_Default)
+ if (nCharset == FX_Charset::kDefault)
nCharset = GetNativeCharset();
return AddNativeTrueTypeFontToPDF(m_pDocument.Get(), sFontName, nCharset);
diff --git a/core/fpdfdoc/cpdf_bafontmap.h b/core/fpdfdoc/cpdf_bafontmap.h
index c28bce0..beabbea 100644
--- a/core/fpdfdoc/cpdf_bafontmap.h
+++ b/core/fpdfdoc/cpdf_bafontmap.h
@@ -20,43 +20,43 @@
class CPDF_BAFontMap final : public IPVT_FontMap {
public:
- static int32_t GetNativeCharset();
+ static FX_Charset GetNativeCharset();
CPDF_BAFontMap(CPDF_Document* pDocument,
CPDF_Dictionary* pAnnotDict,
const ByteString& sAPType);
~CPDF_BAFontMap() override;
- // IPVT_FontMap
+ // IPVT_FontMap:
RetainPtr<CPDF_Font> GetPDFFont(int32_t nFontIndex) override;
ByteString GetPDFFontAlias(int32_t nFontIndex) override;
int32_t GetWordFontIndex(uint16_t word,
- int32_t nCharset,
+ FX_Charset nCharset,
int32_t nFontIndex) override;
int32_t CharCodeFromUnicode(int32_t nFontIndex, uint16_t word) override;
- int32_t CharSetFromUnicode(uint16_t word, int32_t nOldCharset) override;
+ FX_Charset CharSetFromUnicode(uint16_t word, FX_Charset nOldCharset) override;
private:
struct Data {
Data();
~Data();
+ FX_Charset nCharset;
RetainPtr<CPDF_Font> pFont;
- int32_t nCharset;
ByteString sFontName;
};
struct Native {
- int32_t nCharset;
+ FX_Charset nCharset;
ByteString sFontName;
};
void Initialize();
RetainPtr<CPDF_Font> FindFontSameCharset(ByteString* sFontAlias,
- int32_t nCharset);
+ FX_Charset nCharset);
RetainPtr<CPDF_Font> FindResFontSameCharset(const CPDF_Dictionary* pResDict,
ByteString* sFontAlias,
- int32_t nCharset);
+ FX_Charset nCharset);
RetainPtr<CPDF_Font> GetAnnotDefaultFont(ByteString* sAlias);
void AddFontToAnnotDict(const RetainPtr<CPDF_Font>& pFont,
const ByteString& sAlias);
@@ -64,21 +64,21 @@
bool KnowWord(int32_t nFontIndex, uint16_t word);
int32_t GetFontIndex(const ByteString& sFontName,
- int32_t nCharset,
+ FX_Charset nCharset,
bool bFind);
int32_t AddFontData(const RetainPtr<CPDF_Font>& pFont,
const ByteString& sFontAlias,
- int32_t nCharset);
+ FX_Charset nCharset);
- ByteString EncodeFontAlias(const ByteString& sFontName, int32_t nCharset);
+ ByteString EncodeFontAlias(const ByteString& sFontName, FX_Charset nCharset);
- int32_t FindFont(const ByteString& sFontName, int32_t nCharset);
- ByteString GetNativeFontName(int32_t nCharset);
- ByteString GetCachedNativeFontName(int32_t nCharset);
+ int32_t FindFont(const ByteString& sFontName, FX_Charset nCharset);
+ ByteString GetNativeFontName(FX_Charset nCharset);
+ ByteString GetCachedNativeFontName(FX_Charset nCharset);
RetainPtr<CPDF_Font> AddFontToDocument(ByteString sFontName,
- uint8_t nCharset);
+ FX_Charset nCharset);
RetainPtr<CPDF_Font> AddStandardFont(ByteString sFontName);
- RetainPtr<CPDF_Font> AddSystemFont(ByteString sFontName, uint8_t nCharset);
+ RetainPtr<CPDF_Font> AddSystemFont(ByteString sFontName, FX_Charset nCharset);
std::vector<std::unique_ptr<Data>> m_Data;
std::vector<std::unique_ptr<Native>> m_NativeFont;
diff --git a/core/fpdfdoc/cpdf_interactiveform.cpp b/core/fpdfdoc/cpdf_interactiveform.cpp
index 8c6e89b..a9a6731 100644
--- a/core/fpdfdoc/cpdf_interactiveform.cpp
+++ b/core/fpdfdoc/cpdf_interactiveform.cpp
@@ -56,9 +56,11 @@
return 0;
}
-bool RetrieveSpecificFont(uint8_t charSet, LPCSTR pcsFontName, LOGFONTA& lf) {
+bool RetrieveSpecificFont(FX_Charset charSet,
+ LPCSTR pcsFontName,
+ LOGFONTA& lf) {
memset(&lf, 0, sizeof(LOGFONTA));
- lf.lfCharSet = charSet;
+ lf.lfCharSet = static_cast<int>(charSet);
lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
if (pcsFontName) {
// TODO(dsinclair): Should this be strncpy?
@@ -79,11 +81,11 @@
}
#endif // defined(OS_WIN)
-ByteString GetNativeFontName(uint8_t charSet, void* pLogFont) {
+ByteString GetNativeFontName(FX_Charset charSet, void* pLogFont) {
ByteString csFontName;
#if defined(OS_WIN)
LOGFONTA lf = {};
- if (charSet == FX_CHARSET_ANSI) {
+ if (charSet == FX_Charset::kANSI) {
csFontName = CFX_Font::kDefaultAnsiFontName;
return csFontName;
}
@@ -150,7 +152,8 @@
return pPageData->AddStandardFont(CFX_Font::kDefaultAnsiFontName, &encoding);
}
-RetainPtr<CPDF_Font> AddNativeFont(uint8_t charSet, CPDF_Document* pDocument) {
+RetainPtr<CPDF_Font> AddNativeFont(FX_Charset charSet,
+ CPDF_Document* pDocument) {
DCHECK(pDocument);
#if defined(OS_WIN)
@@ -265,7 +268,7 @@
pFont->GetFontDict()->GetObjNum());
}
-uint8_t GetNativeCharSet() {
+FX_Charset GetNativeCharSet() {
return FX_GetCharsetFromCodePage(FX_GetACP());
}
@@ -281,12 +284,12 @@
ByteString csDA;
if (!pFormDict->KeyExist("DR")) {
ByteString csBaseName;
- uint8_t charSet = GetNativeCharSet();
+ FX_Charset charSet = GetNativeCharSet();
RetainPtr<CPDF_Font> pFont = AddStandardFont(pDocument);
if (pFont)
AddFont(pFormDict, pDocument, pFont, &csBaseName);
- if (charSet != FX_CHARSET_ANSI) {
+ if (charSet != FX_Charset::kANSI) {
ByteString csFontName = GetNativeFontName(charSet, nullptr);
if (!pFont || csFontName != CFX_Font::kDefaultAnsiFontName) {
pFont = AddNativeFont(charSet, pDocument);
@@ -309,7 +312,7 @@
RetainPtr<CPDF_Font> GetNativeFont(CPDF_Dictionary* pFormDict,
CPDF_Document* pDocument,
- uint8_t charSet,
+ FX_Charset charSet,
ByteString* csNameTag) {
CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR");
if (!pDR)
@@ -338,7 +341,7 @@
if (!pSubst)
continue;
- if (pSubst->m_Charset == static_cast<int>(charSet)) {
+ if (pSubst->m_Charset == charSet) {
*csNameTag = csKey;
return pFind;
}
@@ -587,7 +590,7 @@
InitDict(pFormDict, pDocument);
DCHECK(pFormDict);
- uint8_t charSet = GetNativeCharSet();
+ FX_Charset charSet = GetNativeCharSet();
ByteString csTemp;
RetainPtr<CPDF_Font> pFont =
GetNativeFont(pFormDict, pDocument, charSet, &csTemp);
diff --git a/core/fpdfdoc/cpvt_fontmap.cpp b/core/fpdfdoc/cpvt_fontmap.cpp
index 87b905c..c095200 100644
--- a/core/fpdfdoc/cpvt_fontmap.cpp
+++ b/core/fpdfdoc/cpvt_fontmap.cpp
@@ -83,7 +83,7 @@
}
int32_t CPVT_FontMap::GetWordFontIndex(uint16_t word,
- int32_t charset,
+ FX_Charset charset,
int32_t nFontIndex) {
NOTREACHED();
return 0;
@@ -94,7 +94,8 @@
return 0;
}
-int32_t CPVT_FontMap::CharSetFromUnicode(uint16_t word, int32_t nOldCharset) {
+FX_Charset CPVT_FontMap::CharSetFromUnicode(uint16_t word,
+ FX_Charset nOldCharset) {
NOTREACHED();
- return FX_CHARSET_ANSI;
+ return FX_Charset::kANSI;
}
diff --git a/core/fpdfdoc/cpvt_fontmap.h b/core/fpdfdoc/cpvt_fontmap.h
index 93429b6..d5dddb5 100644
--- a/core/fpdfdoc/cpvt_fontmap.h
+++ b/core/fpdfdoc/cpvt_fontmap.h
@@ -30,10 +30,10 @@
RetainPtr<CPDF_Font> GetPDFFont(int32_t nFontIndex) override;
ByteString GetPDFFontAlias(int32_t nFontIndex) override;
int32_t GetWordFontIndex(uint16_t word,
- int32_t charset,
+ FX_Charset charset,
int32_t nFontIndex) override;
int32_t CharCodeFromUnicode(int32_t nFontIndex, uint16_t word) override;
- int32_t CharSetFromUnicode(uint16_t word, int32_t nOldCharset) override;
+ FX_Charset CharSetFromUnicode(uint16_t word, FX_Charset nOldCharset) override;
static RetainPtr<CPDF_Font> GetAnnotSysPDFFont(CPDF_Document* pDoc,
CPDF_Dictionary* pResDict,
diff --git a/core/fpdfdoc/cpvt_variabletext.cpp b/core/fpdfdoc/cpvt_variabletext.cpp
index e8f6f31..83c3cb8 100644
--- a/core/fpdfdoc/cpvt_variabletext.cpp
+++ b/core/fpdfdoc/cpvt_variabletext.cpp
@@ -62,7 +62,7 @@
}
int32_t CPVT_VariableText::Provider::GetWordFontIndex(uint16_t word,
- int32_t charset,
+ FX_Charset charset,
int32_t nFontIndex) {
if (RetainPtr<CPDF_Font> pDefFont = m_pFontMap->GetPDFFont(0)) {
if (pDefFont->CharCodeFromUnicode(word) != CPDF_Font::kInvalidCharCode)
@@ -191,7 +191,7 @@
CPVT_WordPlace CPVT_VariableText::InsertWord(const CPVT_WordPlace& place,
uint16_t word,
- int32_t charset) {
+ FX_Charset charset) {
int32_t nTotalWords = GetTotalWords();
if (m_nLimitChar > 0 && nTotalWords >= m_nLimitChar)
return place;
@@ -295,7 +295,7 @@
word = 0x20;
FALLTHROUGH;
default:
- wp = InsertWord(wp, word, FX_CHARSET_Default);
+ wp = InsertWord(wp, word, FX_Charset::kDefault);
break;
}
nCharCount++;
@@ -854,7 +854,7 @@
}
int32_t CPVT_VariableText::GetWordFontIndex(uint16_t word,
- int32_t charset,
+ FX_Charset charset,
int32_t nFontIndex) {
return m_pVTProvider
? m_pVTProvider->GetWordFontIndex(word, charset, nFontIndex)
diff --git a/core/fpdfdoc/cpvt_variabletext.h b/core/fpdfdoc/cpvt_variabletext.h
index b3995c9..65a3c4c 100644
--- a/core/fpdfdoc/cpvt_variabletext.h
+++ b/core/fpdfdoc/cpvt_variabletext.h
@@ -15,6 +15,7 @@
#include "core/fpdfdoc/cpvt_lineinfo.h"
#include "core/fpdfdoc/cpvt_wordplace.h"
#include "core/fpdfdoc/cpvt_wordrange.h"
+#include "core/fxcrt/fx_codepage_forward.h"
#include "core/fxcrt/fx_coordinates.h"
#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/fx_system.h"
@@ -54,7 +55,7 @@
virtual int32_t GetTypeAscent(int32_t nFontIndex);
virtual int32_t GetTypeDescent(int32_t nFontIndex);
virtual int32_t GetWordFontIndex(uint16_t word,
- int32_t charset,
+ FX_Charset charset,
int32_t nFontIndex);
virtual int32_t GetDefaultFontIndex();
@@ -92,7 +93,7 @@
void SetText(const WideString& text);
CPVT_WordPlace InsertWord(const CPVT_WordPlace& place,
uint16_t word,
- int32_t charset);
+ FX_Charset charset);
CPVT_WordPlace InsertSection(const CPVT_WordPlace& place);
CPVT_WordPlace DeleteWords(const CPVT_WordRange& PlaceRange);
CPVT_WordPlace DeleteWord(const CPVT_WordPlace& place);
@@ -161,7 +162,9 @@
private:
int GetCharWidth(int32_t nFontIndex, uint16_t Word, uint16_t SubWord) const;
- int32_t GetWordFontIndex(uint16_t word, int32_t charset, int32_t nFontIndex);
+ int32_t GetWordFontIndex(uint16_t word,
+ FX_Charset charset,
+ int32_t nFontIndex);
CPVT_WordPlace AddSection(const CPVT_WordPlace& place);
CPVT_WordPlace AddLine(const CPVT_WordPlace& place,
diff --git a/core/fpdfdoc/cpvt_word.h b/core/fpdfdoc/cpvt_word.h
index ad0ba74..ca56f95 100644
--- a/core/fpdfdoc/cpvt_word.h
+++ b/core/fpdfdoc/cpvt_word.h
@@ -8,6 +8,7 @@
#define CORE_FPDFDOC_CPVT_WORD_H_
#include "core/fpdfdoc/cpvt_wordplace.h"
+#include "core/fxcrt/fx_codepage.h"
#include "core/fxcrt/fx_system.h"
class CPVT_Word {
@@ -15,7 +16,7 @@
CPVT_Word();
uint16_t Word;
- int32_t nCharset;
+ FX_Charset nCharset;
CPVT_WordPlace WordPlace;
CFX_PointF ptWord;
float fAscent;
@@ -27,7 +28,7 @@
inline CPVT_Word::CPVT_Word()
: Word(0),
- nCharset(0),
+ nCharset(FX_Charset::kANSI),
fAscent(0.0f),
fDescent(0.0f),
fWidth(0.0f),
diff --git a/core/fpdfdoc/cpvt_wordinfo.cpp b/core/fpdfdoc/cpvt_wordinfo.cpp
index dbbd52d..6e2507c 100644
--- a/core/fpdfdoc/cpvt_wordinfo.cpp
+++ b/core/fpdfdoc/cpvt_wordinfo.cpp
@@ -10,13 +10,15 @@
CPVT_WordInfo::CPVT_WordInfo()
: Word(0),
- nCharset(FX_CHARSET_ANSI),
+ nCharset(FX_Charset::kANSI),
fWordX(0.0f),
fWordY(0.0f),
fWordTail(0.0f),
nFontIndex(-1) {}
-CPVT_WordInfo::CPVT_WordInfo(uint16_t word, int32_t charset, int32_t fontIndex)
+CPVT_WordInfo::CPVT_WordInfo(uint16_t word,
+ FX_Charset charset,
+ int32_t fontIndex)
: Word(word),
nCharset(charset),
fWordX(0.0f),
@@ -26,7 +28,7 @@
CPVT_WordInfo::CPVT_WordInfo(const CPVT_WordInfo& word)
: Word(0),
- nCharset(FX_CHARSET_ANSI),
+ nCharset(FX_Charset::kANSI),
fWordX(0.0f),
fWordY(0.0f),
fWordTail(0.0f),
diff --git a/core/fpdfdoc/cpvt_wordinfo.h b/core/fpdfdoc/cpvt_wordinfo.h
index e272dc9..14a0bd5 100644
--- a/core/fpdfdoc/cpvt_wordinfo.h
+++ b/core/fpdfdoc/cpvt_wordinfo.h
@@ -9,16 +9,18 @@
#include <stdint.h>
+#include "core/fxcrt/fx_codepage_forward.h"
+
struct CPVT_WordInfo {
CPVT_WordInfo();
- CPVT_WordInfo(uint16_t word, int32_t charset, int32_t fontIndex);
+ CPVT_WordInfo(uint16_t word, FX_Charset charset, int32_t fontIndex);
CPVT_WordInfo(const CPVT_WordInfo& word);
~CPVT_WordInfo();
CPVT_WordInfo& operator=(const CPVT_WordInfo& word);
uint16_t Word;
- int32_t nCharset;
+ FX_Charset nCharset;
float fWordX;
float fWordY;
float fWordTail;
diff --git a/core/fpdfdoc/ipvt_fontmap.h b/core/fpdfdoc/ipvt_fontmap.h
index e818356..472cba2 100644
--- a/core/fpdfdoc/ipvt_fontmap.h
+++ b/core/fpdfdoc/ipvt_fontmap.h
@@ -9,6 +9,7 @@
#include <stdint.h>
+#include "core/fxcrt/fx_codepage_forward.h"
#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/retain_ptr.h"
@@ -21,10 +22,11 @@
virtual RetainPtr<CPDF_Font> GetPDFFont(int32_t nFontIndex) = 0;
virtual ByteString GetPDFFontAlias(int32_t nFontIndex) = 0;
virtual int32_t GetWordFontIndex(uint16_t word,
- int32_t charset,
+ FX_Charset charset,
int32_t nFontIndex) = 0;
virtual int32_t CharCodeFromUnicode(int32_t nFontIndex, uint16_t word) = 0;
- virtual int32_t CharSetFromUnicode(uint16_t word, int32_t nOldCharset) = 0;
+ virtual FX_Charset CharSetFromUnicode(uint16_t word,
+ FX_Charset nOldCharset) = 0;
};
#endif // CORE_FPDFDOC_IPVT_FONTMAP_H_
diff --git a/core/fxcrt/fx_codepage.cpp b/core/fxcrt/fx_codepage.cpp
index 993853b..f4a22ba 100644
--- a/core/fxcrt/fx_codepage.cpp
+++ b/core/fxcrt/fx_codepage.cpp
@@ -163,55 +163,55 @@
};
struct FX_CHARSET_MAP {
- uint16_t charset;
+ FX_Charset charset;
FX_CodePage codepage;
};
const FX_CHARSET_MAP g_FXCharset2CodePageTable[] = {
- {FX_CHARSET_ANSI, FX_CodePage::kMSWin_WesternEuropean},
- {FX_CHARSET_Default, FX_CodePage::kDefANSI},
- {FX_CHARSET_Symbol, FX_CodePage::kSymbol},
- {FX_CHARSET_MAC_Roman, FX_CodePage::kMAC_Roman},
- {FX_CHARSET_MAC_ShiftJIS, FX_CodePage::kMAC_ShiftJIS},
- {FX_CHARSET_MAC_Korean, FX_CodePage::kMAC_Korean},
- {FX_CHARSET_MAC_ChineseSimplified, FX_CodePage::kMAC_ChineseSimplified},
- {FX_CHARSET_MAC_ChineseTraditional, FX_CodePage::kMAC_ChineseTraditional},
- {FX_CHARSET_MAC_Hebrew, FX_CodePage::kMAC_Hebrew},
- {FX_CHARSET_MAC_Arabic, FX_CodePage::kMAC_Arabic},
- {FX_CHARSET_MAC_Greek, FX_CodePage::kMAC_Greek},
- {FX_CHARSET_MAC_Turkish, FX_CodePage::kMAC_Turkish},
- {FX_CHARSET_MAC_Thai, FX_CodePage::kMAC_Thai},
- {FX_CHARSET_MAC_EasternEuropean, FX_CodePage::kMAC_EasternEuropean},
- {FX_CHARSET_MAC_Cyrillic, FX_CodePage::kMAC_Cyrillic},
- {FX_CHARSET_ShiftJIS, FX_CodePage::kShiftJIS},
- {FX_CHARSET_Hangul, FX_CodePage::kHangul},
- {FX_CHARSET_Johab, FX_CodePage::kJohab},
- {FX_CHARSET_ChineseSimplified, FX_CodePage::kChineseSimplified},
- {FX_CHARSET_ChineseTraditional, FX_CodePage::kChineseTraditional},
- {FX_CHARSET_MSWin_Greek, FX_CodePage::kMSWin_Greek},
- {FX_CHARSET_MSWin_Turkish, FX_CodePage::kMSWin_Turkish},
- {FX_CHARSET_MSWin_Vietnamese, FX_CodePage::kMSWin_Vietnamese},
- {FX_CHARSET_MSWin_Hebrew, FX_CodePage::kMSWin_Hebrew},
- {FX_CHARSET_MSWin_Arabic, FX_CodePage::kMSWin_Arabic},
- {FX_CHARSET_MSWin_Baltic, FX_CodePage::kMSWin_Baltic},
- {FX_CHARSET_MSWin_Cyrillic, FX_CodePage::kMSWin_Cyrillic},
- {FX_CHARSET_Thai, FX_CodePage::kMSDOS_Thai},
- {FX_CHARSET_MSWin_EasternEuropean, FX_CodePage::kMSWin_EasternEuropean},
- {FX_CHARSET_US, FX_CodePage::kMSDOS_US},
- {FX_CHARSET_OEM, FX_CodePage::kMSDOS_WesternEuropean},
+ {FX_Charset::kANSI, FX_CodePage::kMSWin_WesternEuropean},
+ {FX_Charset::kDefault, FX_CodePage::kDefANSI},
+ {FX_Charset::kSymbol, FX_CodePage::kSymbol},
+ {FX_Charset::kMAC_Roman, FX_CodePage::kMAC_Roman},
+ {FX_Charset::kMAC_ShiftJIS, FX_CodePage::kMAC_ShiftJIS},
+ {FX_Charset::kMAC_Korean, FX_CodePage::kMAC_Korean},
+ {FX_Charset::kMAC_ChineseSimplified, FX_CodePage::kMAC_ChineseSimplified},
+ {FX_Charset::kMAC_ChineseTraditional, FX_CodePage::kMAC_ChineseTraditional},
+ {FX_Charset::kMAC_Hebrew, FX_CodePage::kMAC_Hebrew},
+ {FX_Charset::kMAC_Arabic, FX_CodePage::kMAC_Arabic},
+ {FX_Charset::kMAC_Greek, FX_CodePage::kMAC_Greek},
+ {FX_Charset::kMAC_Turkish, FX_CodePage::kMAC_Turkish},
+ {FX_Charset::kMAC_Thai, FX_CodePage::kMAC_Thai},
+ {FX_Charset::kMAC_EasternEuropean, FX_CodePage::kMAC_EasternEuropean},
+ {FX_Charset::kMAC_Cyrillic, FX_CodePage::kMAC_Cyrillic},
+ {FX_Charset::kShiftJIS, FX_CodePage::kShiftJIS},
+ {FX_Charset::kHangul, FX_CodePage::kHangul},
+ {FX_Charset::kJohab, FX_CodePage::kJohab},
+ {FX_Charset::kChineseSimplified, FX_CodePage::kChineseSimplified},
+ {FX_Charset::kChineseTraditional, FX_CodePage::kChineseTraditional},
+ {FX_Charset::kMSWin_Greek, FX_CodePage::kMSWin_Greek},
+ {FX_Charset::kMSWin_Turkish, FX_CodePage::kMSWin_Turkish},
+ {FX_Charset::kMSWin_Vietnamese, FX_CodePage::kMSWin_Vietnamese},
+ {FX_Charset::kMSWin_Hebrew, FX_CodePage::kMSWin_Hebrew},
+ {FX_Charset::kMSWin_Arabic, FX_CodePage::kMSWin_Arabic},
+ {FX_Charset::kMSWin_Baltic, FX_CodePage::kMSWin_Baltic},
+ {FX_Charset::kMSWin_Cyrillic, FX_CodePage::kMSWin_Cyrillic},
+ {FX_Charset::kThai, FX_CodePage::kMSDOS_Thai},
+ {FX_Charset::kMSWin_EasternEuropean, FX_CodePage::kMSWin_EasternEuropean},
+ {FX_Charset::kUS, FX_CodePage::kMSDOS_US},
+ {FX_Charset::kOEM, FX_CodePage::kMSDOS_WesternEuropean},
};
} // namespace
const FX_CharsetUnicodes g_FX_CharsetUnicodes[8] = {
- {FX_CHARSET_Thai, g_FX_MSDOSThaiUnicodes},
- {FX_CHARSET_MSWin_EasternEuropean, g_FX_MSWinEasternEuropeanUnicodes},
- {FX_CHARSET_MSWin_Cyrillic, g_FX_MSWinCyrillicUnicodes},
- {FX_CHARSET_MSWin_Greek, g_FX_MSWinGreekUnicodes},
- {FX_CHARSET_MSWin_Turkish, g_FX_MSWinTurkishUnicodes},
- {FX_CHARSET_MSWin_Hebrew, g_FX_MSWinHebrewUnicodes},
- {FX_CHARSET_MSWin_Arabic, g_FX_MSWinArabicUnicodes},
- {FX_CHARSET_MSWin_Baltic, g_FX_MSWinBalticUnicodes},
+ {FX_Charset::kThai, g_FX_MSDOSThaiUnicodes},
+ {FX_Charset::kMSWin_EasternEuropean, g_FX_MSWinEasternEuropeanUnicodes},
+ {FX_Charset::kMSWin_Cyrillic, g_FX_MSWinCyrillicUnicodes},
+ {FX_Charset::kMSWin_Greek, g_FX_MSWinGreekUnicodes},
+ {FX_Charset::kMSWin_Turkish, g_FX_MSWinTurkishUnicodes},
+ {FX_Charset::kMSWin_Hebrew, g_FX_MSWinHebrewUnicodes},
+ {FX_Charset::kMSWin_Arabic, g_FX_MSWinArabicUnicodes},
+ {FX_Charset::kMSWin_Baltic, g_FX_MSWinBalticUnicodes},
};
FX_CodePage FX_GetACP() {
@@ -222,13 +222,13 @@
#endif
}
-FX_CodePage FX_GetCodePageFromCharset(uint8_t charset) {
- auto* result =
- std::lower_bound(std::begin(g_FXCharset2CodePageTable),
- std::end(g_FXCharset2CodePageTable), charset,
- [](const FX_CHARSET_MAP& iter, const uint16_t& charset) {
- return iter.charset < charset;
- });
+FX_CodePage FX_GetCodePageFromCharset(FX_Charset charset) {
+ auto* result = std::lower_bound(
+ std::begin(g_FXCharset2CodePageTable),
+ std::end(g_FXCharset2CodePageTable), charset,
+ [](const FX_CHARSET_MAP& iter, const FX_Charset& charset) {
+ return iter.charset < charset;
+ });
if (result != std::end(g_FXCharset2CodePageTable) &&
result->charset == charset) {
return result->codepage;
@@ -236,18 +236,58 @@
return FX_CodePage::kFailure;
}
-uint8_t FX_GetCharsetFromCodePage(FX_CodePage codepage) {
+FX_Charset FX_GetCharsetFromCodePage(FX_CodePage codepage) {
for (const auto& it : g_FXCharset2CodePageTable) {
if (it.codepage == codepage)
return it.charset;
}
- return FX_CHARSET_ANSI;
+ return FX_Charset::kANSI;
}
-bool FX_CharSetIsCJK(uint8_t uCharset) {
- return (uCharset == FX_CHARSET_ChineseSimplified) ||
- (uCharset == FX_CHARSET_ChineseTraditional) ||
- (uCharset == FX_CHARSET_Hangul) || (uCharset == FX_CHARSET_ShiftJIS);
+FX_Charset FX_GetCharsetFromInt(int value) {
+ switch (value) {
+ case static_cast<int>(FX_Charset::kANSI):
+ case static_cast<int>(FX_Charset::kDefault):
+ case static_cast<int>(FX_Charset::kSymbol):
+ case static_cast<int>(FX_Charset::kMAC_Roman):
+ case static_cast<int>(FX_Charset::kMAC_ShiftJIS):
+ case static_cast<int>(FX_Charset::kMAC_Korean):
+ case static_cast<int>(FX_Charset::kMAC_ChineseSimplified):
+ case static_cast<int>(FX_Charset::kMAC_ChineseTraditional):
+ case static_cast<int>(FX_Charset::kMAC_Hebrew):
+ case static_cast<int>(FX_Charset::kMAC_Arabic):
+ case static_cast<int>(FX_Charset::kMAC_Greek):
+ case static_cast<int>(FX_Charset::kMAC_Turkish):
+ case static_cast<int>(FX_Charset::kMAC_Thai):
+ case static_cast<int>(FX_Charset::kMAC_EasternEuropean):
+ case static_cast<int>(FX_Charset::kMAC_Cyrillic):
+ case static_cast<int>(FX_Charset::kShiftJIS):
+ case static_cast<int>(FX_Charset::kHangul):
+ case static_cast<int>(FX_Charset::kJohab):
+ case static_cast<int>(FX_Charset::kChineseSimplified):
+ case static_cast<int>(FX_Charset::kChineseTraditional):
+ case static_cast<int>(FX_Charset::kMSWin_Greek):
+ case static_cast<int>(FX_Charset::kMSWin_Turkish):
+ case static_cast<int>(FX_Charset::kMSWin_Vietnamese):
+ case static_cast<int>(FX_Charset::kMSWin_Hebrew):
+ case static_cast<int>(FX_Charset::kMSWin_Arabic):
+ case static_cast<int>(FX_Charset::kMSWin_Baltic):
+ case static_cast<int>(FX_Charset::kMSWin_Cyrillic):
+ case static_cast<int>(FX_Charset::kThai):
+ case static_cast<int>(FX_Charset::kMSWin_EasternEuropean):
+ case static_cast<int>(FX_Charset::kUS):
+ case static_cast<int>(FX_Charset::kOEM):
+ return static_cast<FX_Charset>(value);
+ default:
+ return FX_Charset::kANSI;
+ }
+}
+
+bool FX_CharSetIsCJK(FX_Charset uCharset) {
+ return (uCharset == FX_Charset::kChineseSimplified) ||
+ (uCharset == FX_Charset::kChineseTraditional) ||
+ (uCharset == FX_Charset::kHangul) ||
+ (uCharset == FX_Charset::kShiftJIS);
}
int FX_WideCharToMultiByte(FX_CodePage codepage,
diff --git a/core/fxcrt/fx_codepage.h b/core/fxcrt/fx_codepage.h
index ae4ecf0..e8f7d18 100644
--- a/core/fxcrt/fx_codepage.h
+++ b/core/fxcrt/fx_codepage.h
@@ -64,50 +64,53 @@
kFailure = 65535,
};
-#define FX_CHARSET_ANSI 0
-#define FX_CHARSET_Default 1
-#define FX_CHARSET_Symbol 2
-#define FX_CHARSET_MAC_Roman 77
-#define FX_CHARSET_MAC_ShiftJIS 78
-#define FX_CHARSET_MAC_Korean 79
-#define FX_CHARSET_MAC_ChineseSimplified 80
-#define FX_CHARSET_MAC_ChineseTraditional 81
-#define FX_CHARSET_MAC_Hebrew 83
-#define FX_CHARSET_MAC_Arabic 84
-#define FX_CHARSET_MAC_Greek 85
-#define FX_CHARSET_MAC_Turkish 86
-#define FX_CHARSET_MAC_Thai 87
-#define FX_CHARSET_MAC_EasternEuropean 88
-#define FX_CHARSET_MAC_Cyrillic 89
-#define FX_CHARSET_ShiftJIS 128
-#define FX_CHARSET_Hangul 129
-#define FX_CHARSET_Johab 130
-#define FX_CHARSET_ChineseSimplified 134
-#define FX_CHARSET_ChineseTraditional 136
-#define FX_CHARSET_MSWin_Greek 161
-#define FX_CHARSET_MSWin_Turkish 162
-#define FX_CHARSET_MSWin_Vietnamese 163
-#define FX_CHARSET_MSWin_Hebrew 177
-#define FX_CHARSET_MSWin_Arabic 178
-#define FX_CHARSET_MSWin_Baltic 186
-#define FX_CHARSET_MSWin_Cyrillic 204
-#define FX_CHARSET_Thai 222
-#define FX_CHARSET_MSWin_EasternEuropean 238
-#define FX_CHARSET_US 254
-#define FX_CHARSET_OEM 255
+enum class FX_Charset : uint8_t {
+ kANSI = 0,
+ kDefault = 1,
+ kSymbol = 2,
+ kMAC_Roman = 77,
+ kMAC_ShiftJIS = 78,
+ kMAC_Korean = 79,
+ kMAC_ChineseSimplified = 80,
+ kMAC_ChineseTraditional = 81,
+ kMAC_Hebrew = 83,
+ kMAC_Arabic = 84,
+ kMAC_Greek = 85,
+ kMAC_Turkish = 86,
+ kMAC_Thai = 87,
+ kMAC_EasternEuropean = 88,
+ kMAC_Cyrillic = 89,
+ kShiftJIS = 128,
+ kHangul = 129,
+ kJohab = 130,
+ kChineseSimplified = 134,
+ kChineseTraditional = 136,
+ kMSWin_Greek = 161,
+ kMSWin_Turkish = 162,
+ kMSWin_Vietnamese = 163,
+ kMSWin_Hebrew = 177,
+ kMSWin_Arabic = 178,
+ kMSWin_Baltic = 186,
+ kMSWin_Cyrillic = 204,
+ kThai = 222,
+ kMSWin_EasternEuropean = 238,
+ kUS = 254,
+ kOEM = 255,
+};
// Hi-bytes to unicode codepoint mapping for various code pages.
struct FX_CharsetUnicodes {
- uint8_t m_Charset;
+ FX_Charset m_Charset;
const uint16_t* m_pUnicodes; // Raw, POD struct.
};
extern const FX_CharsetUnicodes g_FX_CharsetUnicodes[8];
FX_CodePage FX_GetACP();
-FX_CodePage FX_GetCodePageFromCharset(uint8_t charset);
-uint8_t FX_GetCharsetFromCodePage(FX_CodePage codepage);
-bool FX_CharSetIsCJK(uint8_t uCharset);
+FX_CodePage FX_GetCodePageFromCharset(FX_Charset charset);
+FX_Charset FX_GetCharsetFromCodePage(FX_CodePage codepage);
+FX_Charset FX_GetCharsetFromInt(int value);
+bool FX_CharSetIsCJK(FX_Charset uCharset);
int FX_WideCharToMultiByte(FX_CodePage codepage,
uint32_t dwFlags,
const wchar_t* wstr,
diff --git a/core/fxcrt/fx_codepage_forward.h b/core/fxcrt/fx_codepage_forward.h
index e941d0a..b8c6322 100644
--- a/core/fxcrt/fx_codepage_forward.h
+++ b/core/fxcrt/fx_codepage_forward.h
@@ -11,6 +11,7 @@
// Incomplete definitions of large enumerated type for headers that don't
// need the specifics.
+enum class FX_Charset : uint8_t;
enum class FX_CodePage : uint16_t;
#endif // CORE_FXCRT_FX_CODEPAGE_FORWARD_H_
diff --git a/core/fxge/android/cfpf_skiafont.cpp b/core/fxge/android/cfpf_skiafont.cpp
index 6358b41..df1139e 100644
--- a/core/fxge/android/cfpf_skiafont.cpp
+++ b/core/fxge/android/cfpf_skiafont.cpp
@@ -8,6 +8,7 @@
#include <algorithm>
+#include "core/fxcrt/fx_codepage.h"
#include "core/fxcrt/fx_coordinates.h"
#include "core/fxcrt/fx_system.h"
#include "core/fxge/android/cfpf_skiafontmgr.h"
@@ -20,7 +21,7 @@
CFPF_SkiaFont::CFPF_SkiaFont(CFPF_SkiaFontMgr* pFontMgr,
const CFPF_SkiaPathFont* pFont,
uint32_t dwStyle,
- uint8_t uCharset)
+ FX_Charset uCharset)
: m_pFontMgr(pFontMgr),
m_pFont(pFont),
m_Face(m_pFontMgr->GetFontFace(m_pFont->path(), m_pFont->face_index())),
diff --git a/core/fxge/android/cfpf_skiafont.h b/core/fxge/android/cfpf_skiafont.h
index c24d9fc..8f008d1 100644
--- a/core/fxge/android/cfpf_skiafont.h
+++ b/core/fxge/android/cfpf_skiafont.h
@@ -7,6 +7,7 @@
#ifndef CORE_FXGE_ANDROID_CFPF_SKIAFONT_H_
#define CORE_FXGE_ANDROID_CFPF_SKIAFONT_H_
+#include "core/fxcrt/fx_codepage_forward.h"
#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/fx_system.h"
#include "core/fxcrt/retain_ptr.h"
@@ -24,7 +25,7 @@
CFPF_SkiaFont(CFPF_SkiaFontMgr* pFontMgr,
const CFPF_SkiaPathFont* pFont,
uint32_t dwStyle,
- uint8_t uCharset);
+ FX_Charset uCharset);
~CFPF_SkiaFont();
bool IsValid() const { return !!m_Face; }
@@ -32,7 +33,7 @@
ByteString GetFamilyName();
ByteString GetPsName();
uint32_t GetFontStyle() const { return m_dwStyle; }
- uint8_t GetCharset() const { return m_uCharset; }
+ FX_Charset GetCharset() const { return m_uCharset; }
int32_t GetGlyphIndex(wchar_t wUnicode);
int32_t GetGlyphWidth(int32_t iGlyphIndex);
int32_t GetAscent() const;
@@ -49,7 +50,7 @@
UnownedPtr<const CFPF_SkiaPathFont> const m_pFont;
RetainPtr<CFX_Face> const m_Face;
const uint32_t m_dwStyle;
- const uint8_t m_uCharset;
+ const FX_Charset m_uCharset;
};
#endif // CORE_FXGE_ANDROID_CFPF_SKIAFONT_H_
diff --git a/core/fxge/android/cfpf_skiafontmgr.cpp b/core/fxge/android/cfpf_skiafontmgr.cpp
index d6f593b..6d5d323 100644
--- a/core/fxge/android/cfpf_skiafontmgr.cpp
+++ b/core/fxge/android/cfpf_skiafontmgr.cpp
@@ -99,37 +99,37 @@
FPF_SKIACHARSET_OEM = 1 << 18,
};
-uint32_t FPF_SkiaGetCharset(uint8_t uCharset) {
+uint32_t FPF_SkiaGetCharset(FX_Charset uCharset) {
switch (uCharset) {
- case FX_CHARSET_ANSI:
+ case FX_Charset::kANSI:
return FPF_SKIACHARSET_Ansi;
- case FX_CHARSET_Default:
+ case FX_Charset::kDefault:
return FPF_SKIACHARSET_Default;
- case FX_CHARSET_Symbol:
+ case FX_Charset::kSymbol:
return FPF_SKIACHARSET_Symbol;
- case FX_CHARSET_ShiftJIS:
+ case FX_Charset::kShiftJIS:
return FPF_SKIACHARSET_ShiftJIS;
- case FX_CHARSET_Hangul:
+ case FX_Charset::kHangul:
return FPF_SKIACHARSET_Korean;
- case FX_CHARSET_ChineseSimplified:
+ case FX_Charset::kChineseSimplified:
return FPF_SKIACHARSET_GB2312;
- case FX_CHARSET_ChineseTraditional:
+ case FX_Charset::kChineseTraditional:
return FPF_SKIACHARSET_BIG5;
- case FX_CHARSET_MSWin_Greek:
+ case FX_Charset::kMSWin_Greek:
return FPF_SKIACHARSET_Greek;
- case FX_CHARSET_MSWin_Turkish:
+ case FX_Charset::kMSWin_Turkish:
return FPF_SKIACHARSET_Turkish;
- case FX_CHARSET_MSWin_Hebrew:
+ case FX_Charset::kMSWin_Hebrew:
return FPF_SKIACHARSET_Hebrew;
- case FX_CHARSET_MSWin_Arabic:
+ case FX_Charset::kMSWin_Arabic:
return FPF_SKIACHARSET_Arabic;
- case FX_CHARSET_MSWin_Baltic:
+ case FX_Charset::kMSWin_Baltic:
return FPF_SKIACHARSET_Baltic;
- case FX_CHARSET_MSWin_Cyrillic:
+ case FX_Charset::kMSWin_Cyrillic:
return FPF_SKIACHARSET_Cyrillic;
- case FX_CHARSET_Thai:
+ case FX_Charset::kThai:
return FPF_SKIACHARSET_Thai;
- case FX_CHARSET_MSWin_EasternEuropean:
+ case FX_Charset::kMSWin_EasternEuropean:
return FPF_SKIACHARSET_EeasternEuropean;
}
return FPF_SKIACHARSET_Default;
@@ -150,7 +150,7 @@
uint32_t FPF_SKIAGetFamilyHash(ByteStringView bsFamily,
uint32_t dwStyle,
- uint8_t uCharset) {
+ FX_Charset uCharset) {
ByteString bsFont(bsFamily);
if (FontStyleIsForceBold(dwStyle))
bsFont += "Bold";
@@ -158,11 +158,11 @@
bsFont += "Italic";
if (FontStyleIsSerif(dwStyle))
bsFont += "Serif";
- bsFont += uCharset;
+ bsFont += static_cast<uint8_t>(uCharset);
return FPF_GetHashCode_StringA(bsFont.c_str(), bsFont.GetLength());
}
-bool FPF_SkiaIsCJK(uint8_t uCharset) {
+bool FPF_SkiaIsCJK(FX_Charset uCharset) {
return FX_CharSetIsCJK(uCharset);
}
@@ -255,7 +255,7 @@
}
CFPF_SkiaFont* CFPF_SkiaFontMgr::CreateFont(ByteStringView bsFamilyname,
- uint8_t uCharset,
+ FX_Charset uCharset,
uint32_t dwStyle) {
uint32_t dwHash = FPF_SKIAGetFamilyHash(bsFamilyname, dwStyle, uCharset);
auto family_iter = m_FamilyFonts.find(dwHash);
@@ -268,11 +268,11 @@
uint32_t dwSubstSans = FPF_SkiaGetSubstFont(dwFaceName, g_SkiaSansFontMap,
pdfium::size(g_SkiaSansFontMap));
bool bMaybeSymbol = FPF_SkiaMaybeSymbol(bsFamilyname);
- if (uCharset != FX_CHARSET_MSWin_Arabic &&
+ if (uCharset != FX_Charset::kMSWin_Arabic &&
FPF_SkiaMaybeArabic(bsFamilyname)) {
- uCharset = FX_CHARSET_MSWin_Arabic;
- } else if (uCharset == FX_CHARSET_ANSI) {
- uCharset = FX_CHARSET_Default;
+ uCharset = FX_Charset::kMSWin_Arabic;
+ } else if (uCharset == FX_Charset::kANSI) {
+ uCharset = FX_Charset::kDefault;
}
int32_t nExpectVal = FPF_SKIAMATCHWEIGHT_NAME1 + FPF_SKIAMATCHWEIGHT_1 * 3 +
FPF_SKIAMATCHWEIGHT_2 * 2;
@@ -304,7 +304,7 @@
nFind += FPF_SKIAMATCHWEIGHT_NAME2;
bMatchedName = true;
}
- if (uCharset == FX_CHARSET_Default || bMaybeSymbol) {
+ if (uCharset == FX_Charset::kDefault || bMaybeSymbol) {
if (nFind > nMax && bMatchedName) {
nMax = nFind;
pBestFont = font.get();
diff --git a/core/fxge/android/cfpf_skiafontmgr.h b/core/fxge/android/cfpf_skiafontmgr.h
index 4d5c788..7db4f48 100644
--- a/core/fxge/android/cfpf_skiafontmgr.h
+++ b/core/fxge/android/cfpf_skiafontmgr.h
@@ -11,6 +11,7 @@
#include <memory>
#include <vector>
+#include "core/fxcrt/fx_codepage_forward.h"
#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/retain_ptr.h"
#include "core/fxge/cfx_face.h"
@@ -26,7 +27,7 @@
void LoadSystemFonts();
CFPF_SkiaFont* CreateFont(ByteStringView bsFamilyname,
- uint8_t uCharset,
+ FX_Charset uCharset,
uint32_t dwStyle);
bool InitFTLibrary();
diff --git a/core/fxge/android/cfx_androidfontinfo.cpp b/core/fxge/android/cfx_androidfontinfo.cpp
index dc25f1e..17912db 100644
--- a/core/fxge/android/cfx_androidfontinfo.cpp
+++ b/core/fxge/android/cfx_androidfontinfo.cpp
@@ -31,7 +31,7 @@
void* CFX_AndroidFontInfo::MapFont(int weight,
bool bItalic,
- int charset,
+ FX_Charset charset,
int pitch_family,
const char* face) {
if (!m_pFontMgr)
@@ -71,7 +71,7 @@
return true;
}
-bool CFX_AndroidFontInfo::GetFontCharset(void* hFont, int* charset) {
+bool CFX_AndroidFontInfo::GetFontCharset(void* hFont, FX_Charset* charset) {
if (!hFont)
return false;
diff --git a/core/fxge/android/cfx_androidfontinfo.h b/core/fxge/android/cfx_androidfontinfo.h
index c8b6d24..9e68e66 100644
--- a/core/fxge/android/cfx_androidfontinfo.h
+++ b/core/fxge/android/cfx_androidfontinfo.h
@@ -26,7 +26,7 @@
bool EnumFontList(CFX_FontMapper* pMapper) override;
void* MapFont(int weight,
bool bItalic,
- int charset,
+ FX_Charset charset,
int pitch_family,
const char* face) override;
void* GetFont(const char* face) override;
@@ -34,7 +34,7 @@
uint32_t table,
pdfium::span<uint8_t> buffer) override;
bool GetFaceName(void* hFont, ByteString* name) override;
- bool GetFontCharset(void* hFont, int* charset) override;
+ bool GetFontCharset(void* hFont, FX_Charset* charset) override;
void DeleteFont(void* hFont) override;
private:
diff --git a/core/fxge/apple/fx_apple_platform.cpp b/core/fxge/apple/fx_apple_platform.cpp
index f9a1097..0021cac 100644
--- a/core/fxge/apple/fx_apple_platform.cpp
+++ b/core/fxge/apple/fx_apple_platform.cpp
@@ -43,7 +43,7 @@
// CFX_FolderFontInfo
void* MapFont(int weight,
bool bItalic,
- int charset,
+ FX_Charset charset,
int pitch_family,
const char* family) override;
@@ -64,7 +64,7 @@
void* CFX_MacFontInfo::MapFont(int weight,
bool bItalic,
- int charset,
+ FX_Charset charset,
int pitch_family,
const char* cstr_face) {
ByteString face = cstr_face;
@@ -97,23 +97,23 @@
if (it != m_FontList.end())
return it->second.get();
- if (charset == FX_CHARSET_ANSI && FontFamilyIsFixedPitch(pitch_family))
+ if (charset == FX_Charset::kANSI && FontFamilyIsFixedPitch(pitch_family))
return GetFont("Courier New");
- if (charset == FX_CHARSET_ANSI || charset == FX_CHARSET_Symbol)
+ if (charset == FX_Charset::kANSI || charset == FX_Charset::kSymbol)
return nullptr;
switch (charset) {
- case FX_CHARSET_ShiftJIS:
+ case FX_Charset::kShiftJIS:
GetJapanesePreference(&face, weight, pitch_family);
break;
- case FX_CHARSET_ChineseSimplified:
+ case FX_Charset::kChineseSimplified:
face = "STSong";
break;
- case FX_CHARSET_Hangul:
+ case FX_Charset::kHangul:
face = "AppleMyungjo";
break;
- case FX_CHARSET_ChineseTraditional:
+ case FX_Charset::kChineseTraditional:
face = "LiSong Pro Light";
}
it = m_FontList.find(face);
diff --git a/core/fxge/cfx_folderfontinfo.cpp b/core/fxge/cfx_folderfontinfo.cpp
index e4812ef..d4fd9e2 100644
--- a/core/fxge/cfx_folderfontinfo.cpp
+++ b/core/fxge/cfx_folderfontinfo.cpp
@@ -100,19 +100,19 @@
return ByteString();
}
-uint32_t GetCharset(int charset) {
+uint32_t GetCharset(FX_Charset charset) {
switch (charset) {
- case FX_CHARSET_ShiftJIS:
+ case FX_Charset::kShiftJIS:
return CHARSET_FLAG_SHIFTJIS;
- case FX_CHARSET_ChineseSimplified:
+ case FX_Charset::kChineseSimplified:
return CHARSET_FLAG_GB;
- case FX_CHARSET_ChineseTraditional:
+ case FX_Charset::kChineseTraditional:
return CHARSET_FLAG_BIG5;
- case FX_CHARSET_Hangul:
+ case FX_Charset::kHangul:
return CHARSET_FLAG_KOREAN;
- case FX_CHARSET_Symbol:
+ case FX_Charset::kSymbol:
return CHARSET_FLAG_SYMBOL;
- case FX_CHARSET_ANSI:
+ case FX_Charset::kANSI:
return CHARSET_FLAG_ANSI;
default:
break;
@@ -268,27 +268,27 @@
const uint8_t* p = os2.raw_str() + 78;
uint32_t codepages = FXSYS_UINT32_GET_MSBFIRST(p);
if (codepages & (1U << 17)) {
- m_pMapper->AddInstalledFont(facename, FX_CHARSET_ShiftJIS);
+ m_pMapper->AddInstalledFont(facename, FX_Charset::kShiftJIS);
pInfo->m_Charsets |= CHARSET_FLAG_SHIFTJIS;
}
if (codepages & (1U << 18)) {
- m_pMapper->AddInstalledFont(facename, FX_CHARSET_ChineseSimplified);
+ m_pMapper->AddInstalledFont(facename, FX_Charset::kChineseSimplified);
pInfo->m_Charsets |= CHARSET_FLAG_GB;
}
if (codepages & (1U << 20)) {
- m_pMapper->AddInstalledFont(facename, FX_CHARSET_ChineseTraditional);
+ m_pMapper->AddInstalledFont(facename, FX_Charset::kChineseTraditional);
pInfo->m_Charsets |= CHARSET_FLAG_BIG5;
}
if ((codepages & (1U << 19)) || (codepages & (1U << 21))) {
- m_pMapper->AddInstalledFont(facename, FX_CHARSET_Hangul);
+ m_pMapper->AddInstalledFont(facename, FX_Charset::kHangul);
pInfo->m_Charsets |= CHARSET_FLAG_KOREAN;
}
if (codepages & (1U << 31)) {
- m_pMapper->AddInstalledFont(facename, FX_CHARSET_Symbol);
+ m_pMapper->AddInstalledFont(facename, FX_Charset::kSymbol);
pInfo->m_Charsets |= CHARSET_FLAG_SYMBOL;
}
}
- m_pMapper->AddInstalledFont(facename, FX_CHARSET_ANSI);
+ m_pMapper->AddInstalledFont(facename, FX_Charset::kANSI);
pInfo->m_Charsets |= CHARSET_FLAG_ANSI;
pInfo->m_Styles = 0;
if (style.Contains("Bold"))
@@ -312,12 +312,12 @@
void* CFX_FolderFontInfo::FindFont(int weight,
bool bItalic,
- int charset,
+ FX_Charset charset,
int pitch_family,
const char* family,
bool bMatchName) {
FontFaceInfo* pFind = nullptr;
- if (charset == FX_CHARSET_ANSI && FontFamilyIsFixedPitch(pitch_family))
+ if (charset == FX_Charset::kANSI && FontFamilyIsFixedPitch(pitch_family))
return GetFont("Courier New");
ByteStringView bsFamily(family);
@@ -326,7 +326,7 @@
for (const auto& it : m_FontList) {
const ByteString& bsName = it.first;
FontFaceInfo* pFont = it.second.get();
- if (!(pFont->m_Charsets & charset_flag) && charset != FX_CHARSET_Default)
+ if (!(pFont->m_Charsets & charset_flag) && charset != FX_Charset::kDefault)
continue;
if (bMatchName && !FindFamilyNameMatch(bsFamily, bsName))
@@ -345,7 +345,7 @@
void* CFX_FolderFontInfo::MapFont(int weight,
bool bItalic,
- int charset,
+ FX_Charset charset,
int pitch_family,
const char* family) {
return nullptr;
@@ -404,7 +404,7 @@
return true;
}
-bool CFX_FolderFontInfo::GetFontCharset(void* hFont, int* charset) {
+bool CFX_FolderFontInfo::GetFontCharset(void* hFont, FX_Charset* charset) {
return false;
}
diff --git a/core/fxge/cfx_folderfontinfo.h b/core/fxge/cfx_folderfontinfo.h
index 05e8fb7..1c3875d 100644
--- a/core/fxge/cfx_folderfontinfo.h
+++ b/core/fxge/cfx_folderfontinfo.h
@@ -11,6 +11,7 @@
#include <memory>
#include <vector>
+#include "core/fxcrt/fx_codepage_forward.h"
#include "core/fxcrt/unowned_ptr.h"
#include "core/fxge/cfx_fontmapper.h"
#include "core/fxge/systemfontinfo_iface.h"
@@ -29,11 +30,11 @@
void AddPath(const ByteString& path);
- // IFX_SytemFontInfo:
+ // SystemFontInfoIface:
bool EnumFontList(CFX_FontMapper* pMapper) override;
void* MapFont(int weight,
bool bItalic,
- int charset,
+ FX_Charset charset,
int pitch_family,
const char* family) override;
void* GetFont(const char* face) override;
@@ -42,7 +43,7 @@
pdfium::span<uint8_t> buffer) override;
void DeleteFont(void* hFont) override;
bool GetFaceName(void* hFont, ByteString* name) override;
- bool GetFontCharset(void* hFont, int* charset) override;
+ bool GetFontCharset(void* hFont, FX_Charset* charset) override;
protected:
friend class CFX_FolderFontInfoTest;
@@ -73,7 +74,7 @@
void* GetSubstFont(const ByteString& face);
void* FindFont(int weight,
bool bItalic,
- int charset,
+ FX_Charset charset,
int pitch_family,
const char* family,
bool bMatchName);
diff --git a/core/fxge/cfx_folderfontinfo_unittest.cpp b/core/fxge/cfx_folderfontinfo_unittest.cpp
index 2d38bc4..e416e06 100644
--- a/core/fxge/cfx_folderfontinfo_unittest.cpp
+++ b/core/fxge/cfx_folderfontinfo_unittest.cpp
@@ -43,7 +43,7 @@
void* FindFont(int weight,
bool bItalic,
- int charset,
+ FX_Charset charset,
int pitch_family,
const char* family,
bool bMatchName) {
@@ -69,57 +69,57 @@
TEST_F(CFX_FolderFontInfoTest, TestFindFont) {
// Find "Symbol" font
- void* font = FindFont(/*weight=*/0, /*bItalic=*/false, FX_CHARSET_Symbol,
+ void* font = FindFont(/*weight=*/0, /*bItalic=*/false, FX_Charset::kSymbol,
FXFONT_FF_ROMAN, kSymbol, /*bMatchName=*/true);
ASSERT_TRUE(font);
EXPECT_EQ(GetFaceName(font), kSymbol);
// Find "Calibri" font that is not present in the installed fonts
- EXPECT_FALSE(FindFont(/*weight=*/0, /*bItalic=*/false, FX_CHARSET_Symbol,
+ EXPECT_FALSE(FindFont(/*weight=*/0, /*bItalic=*/false, FX_Charset::kSymbol,
FXFONT_FF_ROMAN, kCalibri, /*bMatchName=*/true));
// Find the closest matching font to "Bookshelf" font that is present in the
// installed fonts
- font = FindFont(/*weight=*/0, /*bItalic=*/false, FX_CHARSET_Symbol,
+ font = FindFont(/*weight=*/0, /*bItalic=*/false, FX_Charset::kSymbol,
FXFONT_FF_ROMAN, kBookshelf, /*bMatchName=*/true);
ASSERT_TRUE(font);
EXPECT_EQ(GetFaceName(font), kBookshelfSymbol7);
// Find "Book" font is expected to fail, because none of the installed fonts
// is in the same font family.
- EXPECT_FALSE(FindFont(/*weight=*/0, /*bItalic=*/false, FX_CHARSET_Symbol,
+ EXPECT_FALSE(FindFont(/*weight=*/0, /*bItalic=*/false, FX_Charset::kSymbol,
FXFONT_FF_ROMAN, kBook, /*bMatchName=*/true));
// Find the closest matching font for "Tofu" in the installed fonts, which
// has "," following the string "Tofu".
- font = FindFont(/*weight=*/0, /*bItalic=*/false, FX_CHARSET_Symbol,
+ font = FindFont(/*weight=*/0, /*bItalic=*/false, FX_Charset::kSymbol,
FXFONT_FF_ROMAN, kTofu, /*bMatchName=*/true);
ASSERT_TRUE(font);
EXPECT_EQ(GetFaceName(font), kTofuBold);
// Find the closest matching font for "Lato" in the installed fonts, which
// has a space character following the string "Lato".
- font = FindFont(/*weight=*/0, /*bItalic=*/false, FX_CHARSET_ANSI,
+ font = FindFont(/*weight=*/0, /*bItalic=*/false, FX_Charset::kANSI,
FXFONT_FF_ROMAN, kLato, /*bMatchName=*/true);
ASSERT_TRUE(font);
EXPECT_EQ(GetFaceName(font), kLatoUltraBold);
// Find the closest matching font for "Oxygen" in the installed fonts,
// which has "-" following the string "Oxygen".
- font = FindFont(/*weight=*/0, /*bItalic=*/false, FX_CHARSET_ANSI,
+ font = FindFont(/*weight=*/0, /*bItalic=*/false, FX_Charset::kANSI,
FXFONT_FF_ROMAN, kOxygen, /*bMatchName=*/true);
ASSERT_TRUE(font);
EXPECT_EQ(GetFaceName(font), kOxygenSansSansBold);
// Find the closest matching font for "Oxygen-Sans" in the installed fonts,
// to test matching a family name with "-".
- font = FindFont(/*weight=*/0, /*bItalic=*/false, FX_CHARSET_ANSI,
+ font = FindFont(/*weight=*/0, /*bItalic=*/false, FX_Charset::kANSI,
FXFONT_FF_ROMAN, kOxygenSans, /*bMatchName=*/true);
ASSERT_TRUE(font);
EXPECT_EQ(GetFaceName(font), kOxygenSansSansBold);
// Find "Symbol" font when name matching is false
- font = FindFont(/*weight=*/0, /*bItalic=*/false, FX_CHARSET_Symbol,
+ font = FindFont(/*weight=*/0, /*bItalic=*/false, FX_Charset::kSymbol,
FXFONT_FF_ROMAN, kSymbol, /*bMatchName=*/false);
ASSERT_TRUE(font);
EXPECT_EQ(GetFaceName(font), kBookshelfSymbol7);
diff --git a/core/fxge/cfx_font.cpp b/core/fxge/cfx_font.cpp
index df2bab1..4f0e029 100644
--- a/core/fxge/cfx_font.cpp
+++ b/core/fxge/cfx_font.cpp
@@ -203,18 +203,18 @@
} // namespace
const CFX_Font::CharsetFontMap CFX_Font::kDefaultTTFMap[] = {
- {FX_CHARSET_ANSI, kDefaultAnsiFontName},
- {FX_CHARSET_ChineseSimplified, "SimSun"},
- {FX_CHARSET_ChineseTraditional, "MingLiU"},
- {FX_CHARSET_ShiftJIS, "MS Gothic"},
- {FX_CHARSET_Hangul, "Batang"},
- {FX_CHARSET_MSWin_Cyrillic, "Arial"},
+ {static_cast<int>(FX_Charset::kANSI), kDefaultAnsiFontName},
+ {static_cast<int>(FX_Charset::kChineseSimplified), "SimSun"},
+ {static_cast<int>(FX_Charset::kChineseTraditional), "MingLiU"},
+ {static_cast<int>(FX_Charset::kShiftJIS), "MS Gothic"},
+ {static_cast<int>(FX_Charset::kHangul), "Batang"},
+ {static_cast<int>(FX_Charset::kMSWin_Cyrillic), "Arial"},
#if defined(OS_WIN)
- {FX_CHARSET_MSWin_EasternEuropean, "Tahoma"},
+ {static_cast<int>(FX_Charset::kMSWin_EasternEuropean), "Tahoma"},
#else
- {FX_CHARSET_MSWin_EasternEuropean, "Arial"},
+ {static_cast<int>(FX_Charset::kMSWin_EasternEuropean), "Arial"},
#endif
- {FX_CHARSET_MSWin_Arabic, "Arial"},
+ {static_cast<int>(FX_Charset::kMSWin_Arabic), "Arial"},
{-1, nullptr}};
// static
@@ -227,63 +227,63 @@
const char CFX_Font::kUniversalDefaultFontName[] = "Arial Unicode MS";
// static
-ByteString CFX_Font::GetDefaultFontNameByCharset(uint8_t nCharset) {
+ByteString CFX_Font::GetDefaultFontNameByCharset(FX_Charset nCharset) {
for (size_t i = 0; i < pdfium::size(kDefaultTTFMap) - 1; ++i) {
- if (nCharset == static_cast<uint8_t>(kDefaultTTFMap[i].charset))
+ if (static_cast<int>(nCharset) == kDefaultTTFMap[i].charset)
return kDefaultTTFMap[i].fontname;
}
return kUniversalDefaultFontName;
}
// static
-uint8_t CFX_Font::GetCharSetFromUnicode(uint16_t word) {
+FX_Charset CFX_Font::GetCharSetFromUnicode(uint16_t word) {
// to avoid CJK Font to show ASCII
if (word < 0x7F)
- return FX_CHARSET_ANSI;
+ return FX_Charset::kANSI;
// find new charset
if ((word >= 0x4E00 && word <= 0x9FA5) ||
(word >= 0xE7C7 && word <= 0xE7F3) ||
(word >= 0x3000 && word <= 0x303F) ||
(word >= 0x2000 && word <= 0x206F)) {
- return FX_CHARSET_ChineseSimplified;
+ return FX_Charset::kChineseSimplified;
}
if (((word >= 0x3040) && (word <= 0x309F)) ||
((word >= 0x30A0) && (word <= 0x30FF)) ||
((word >= 0x31F0) && (word <= 0x31FF)) ||
((word >= 0xFF00) && (word <= 0xFFEF))) {
- return FX_CHARSET_ShiftJIS;
+ return FX_Charset::kShiftJIS;
}
if (((word >= 0xAC00) && (word <= 0xD7AF)) ||
((word >= 0x1100) && (word <= 0x11FF)) ||
((word >= 0x3130) && (word <= 0x318F))) {
- return FX_CHARSET_Hangul;
+ return FX_Charset::kHangul;
}
if (word >= 0x0E00 && word <= 0x0E7F)
- return FX_CHARSET_Thai;
+ return FX_Charset::kThai;
if ((word >= 0x0370 && word <= 0x03FF) || (word >= 0x1F00 && word <= 0x1FFF))
- return FX_CHARSET_MSWin_Greek;
+ return FX_Charset::kMSWin_Greek;
if ((word >= 0x0600 && word <= 0x06FF) || (word >= 0xFB50 && word <= 0xFEFC))
- return FX_CHARSET_MSWin_Arabic;
+ return FX_Charset::kMSWin_Arabic;
if (word >= 0x0590 && word <= 0x05FF)
- return FX_CHARSET_MSWin_Hebrew;
+ return FX_Charset::kMSWin_Hebrew;
if (word >= 0x0400 && word <= 0x04FF)
- return FX_CHARSET_MSWin_Cyrillic;
+ return FX_Charset::kMSWin_Cyrillic;
if (word >= 0x0100 && word <= 0x024F)
- return FX_CHARSET_MSWin_EasternEuropean;
+ return FX_Charset::kMSWin_EasternEuropean;
if (word >= 0x1E00 && word <= 0x1EFF)
- return FX_CHARSET_MSWin_Vietnamese;
+ return FX_Charset::kMSWin_Vietnamese;
- return FX_CHARSET_ANSI;
+ return FX_Charset::kANSI;
}
CFX_Font::CFX_Font() = default;
@@ -668,7 +668,7 @@
uint32_t index = std::min<uint32_t>((m_pSubstFont->m_Weight - 400) / 10,
kWeightPowArraySize - 1);
int level;
- if (m_pSubstFont->m_Charset == FX_CHARSET_ShiftJIS)
+ if (m_pSubstFont->m_Charset == FX_Charset::kShiftJIS)
level = kWeightPowShiftJis[index] * 65536 / 36655;
else
level = kWeightPow[index];
@@ -717,11 +717,11 @@
}
// static
-int CFX_Font::GetWeightLevel(int charset, size_t index) {
+int CFX_Font::GetWeightLevel(FX_Charset charset, size_t index) {
if (index >= kWeightPowArraySize)
return -1;
- if (charset == FX_CHARSET_ShiftJIS)
+ if (charset == FX_Charset::kShiftJIS)
return kWeightPowShiftJis[index];
return kWeightPow11[index];
}
diff --git a/core/fxge/cfx_font.h b/core/fxge/cfx_font.h
index 57177e4..b3f2b16 100644
--- a/core/fxge/cfx_font.h
+++ b/core/fxge/cfx_font.h
@@ -36,7 +36,7 @@
public:
// This struct should be the same as FPDF_CharsetFontMap.
struct CharsetFontMap {
- int charset; // Character Set Enum value, see FX_CHARSET_XXX.
+ int charset; // Character Set Enum value, see FX_Charset::kXXX.
const char* fontname; // Name of default font to use with that charset.
};
@@ -52,13 +52,13 @@
static const char kUniversalDefaultFontName[];
// Returns negative values on failure.
- static int GetWeightLevel(int charset, size_t index);
+ static int GetWeightLevel(FX_Charset charset, size_t index);
// |angle| is typically negative.
static int GetSkewFromAngle(int angle);
- static ByteString GetDefaultFontNameByCharset(uint8_t nCharset);
- static uint8_t GetCharSetFromUnicode(uint16_t word);
+ static ByteString GetDefaultFontNameByCharset(FX_Charset nCharset);
+ static FX_Charset GetCharSetFromUnicode(uint16_t word);
CFX_Font();
~CFX_Font();
diff --git a/core/fxge/cfx_fontmapper.cpp b/core/fxge/cfx_fontmapper.cpp
index db28c20..fdb633d 100644
--- a/core/fxge/cfx_fontmapper.cpp
+++ b/core/fxge/cfx_fontmapper.cpp
@@ -314,7 +314,8 @@
return bytes_read == size ? GetNameFromTT(buffer, 6) : ByteString();
}
-void CFX_FontMapper::AddInstalledFont(const ByteString& name, int charset) {
+void CFX_FontMapper::AddInstalledFont(const ByteString& name,
+ FX_Charset charset) {
if (!m_pFontInfo)
return;
@@ -329,7 +330,7 @@
if (bLocalized) {
void* hFont = m_pFontInfo->GetFont(name.c_str());
if (!hFont) {
- hFont = m_pFontInfo->MapFont(0, 0, FX_CHARSET_Default, 0, name.c_str());
+ hFont = m_pFontInfo->MapFont(0, 0, FX_Charset::kDefault, 0, name.c_str());
if (!hFont)
return;
}
@@ -425,12 +426,12 @@
GetStandardFontName(&SubstName);
if (SubstName == "Symbol" && !bTrueType) {
pSubstFont->m_Family = "Chrome Symbol";
- pSubstFont->m_Charset = FX_CHARSET_Symbol;
+ pSubstFont->m_Charset = FX_Charset::kSymbol;
return UseInternalSubst(pSubstFont, 12, italic_angle, weight, 0);
}
if (SubstName == "ZapfDingbats") {
pSubstFont->m_Family = "Chrome Dingbats";
- pSubstFont->m_Charset = FX_CHARSET_Symbol;
+ pSubstFont->m_Charset = FX_Charset::kSymbol;
return UseInternalSubst(pSubstFont, 13, italic_angle, weight, 0);
}
int iBaseFont = 0;
@@ -545,11 +546,11 @@
PitchFamily);
}
- int Charset = FX_CHARSET_ANSI;
+ FX_Charset Charset = FX_Charset::kANSI;
if (code_page != FX_CodePage::kDefANSI)
Charset = FX_GetCharsetFromCodePage(code_page);
else if (iBaseFont == kNumStandardFonts && FontStyleIsSymbolic(flags))
- Charset = FX_CHARSET_Symbol;
+ Charset = FX_Charset::kSymbol;
const bool bCJK = FX_CharSetIsCJK(Charset);
bool bItalic = FontStyleIsItalic(nStyle);
@@ -615,11 +616,11 @@
PitchFamily);
}
} else {
- if (Charset == FX_CHARSET_Symbol) {
+ if (Charset == FX_Charset::kSymbol) {
#if defined(OS_APPLE) || defined(OS_ANDROID)
if (SubstName == "Symbol") {
pSubstFont->m_Family = "Chrome Symbol";
- pSubstFont->m_Charset = FX_CHARSET_Symbol;
+ pSubstFont->m_Charset = FX_Charset::kSymbol;
return UseInternalSubst(pSubstFont, 12, italic_angle, old_weight,
PitchFamily);
}
@@ -628,7 +629,7 @@
weight, italic_angle, FX_CodePage::kDefANSI,
pSubstFont);
}
- if (Charset == FX_CHARSET_ANSI) {
+ if (Charset == FX_Charset::kANSI) {
return UseInternalSubst(pSubstFont, iBaseFont, italic_angle, old_weight,
PitchFamily);
}
@@ -649,7 +650,7 @@
return nullptr;
m_pFontInfo->GetFaceName(hFont, &SubstName);
- if (Charset == FX_CHARSET_Default)
+ if (Charset == FX_Charset::kDefault)
m_pFontInfo->GetFontCharset(hFont, &Charset);
uint32_t ttc_size = m_pFontInfo->GetFontData(hFont, kTableTTCF, {});
uint32_t font_size = m_pFontInfo->GetFontData(hFont, 0, {});
@@ -733,7 +734,7 @@
if (!m_pFontInfo)
return nullptr;
- void* hFont = m_pFontInfo->MapFont(0, 0, FX_CHARSET_Default, 0,
+ void* hFont = m_pFontInfo->MapFont(0, 0, FX_Charset::kDefault, 0,
GetFaceName(index).c_str());
if (!hFont)
return nullptr;
diff --git a/core/fxge/cfx_fontmapper.h b/core/fxge/cfx_fontmapper.h
index cd200c7..7d0ea7b 100644
--- a/core/fxge/cfx_fontmapper.h
+++ b/core/fxge/cfx_fontmapper.h
@@ -57,7 +57,7 @@
}
void SetSystemFontInfo(std::unique_ptr<SystemFontInfoIface> pFontInfo);
- void AddInstalledFont(const ByteString& name, int charset);
+ void AddInstalledFont(const ByteString& name, FX_Charset charset);
void LoadInstalledFonts();
RetainPtr<CFX_Face> FindSubstFont(const ByteString& face_name,
diff --git a/core/fxge/cfx_substfont.h b/core/fxge/cfx_substfont.h
index 46ecc0a..214ea3b 100644
--- a/core/fxge/cfx_substfont.h
+++ b/core/fxge/cfx_substfont.h
@@ -19,7 +19,7 @@
void UseChromeSerif();
ByteString m_Family;
- int m_Charset = FX_CHARSET_ANSI;
+ FX_Charset m_Charset = FX_Charset::kANSI;
int m_Weight = 0;
int m_ItalicAngle = 0;
int m_WeightCJK = 0;
diff --git a/core/fxge/cfx_unicodeencoding.cpp b/core/fxge/cfx_unicodeencoding.cpp
index 2e07cc1..94734f8 100644
--- a/core/fxge/cfx_unicodeencoding.cpp
+++ b/core/fxge/cfx_unicodeencoding.cpp
@@ -26,7 +26,7 @@
return FT_Get_Char_Index(face, charcode);
if (m_pFont->GetSubstFont() &&
- m_pFont->GetSubstFont()->m_Charset == FX_CHARSET_Symbol) {
+ m_pFont->GetSubstFont()->m_Charset == FX_Charset::kSymbol) {
uint32_t index = 0;
if (FT_Select_Charmap(face, FT_ENCODING_MS_SYMBOL) == 0)
index = FT_Get_Char_Index(face, charcode);
diff --git a/core/fxge/linux/fx_linux_impl.cpp b/core/fxge/linux/fx_linux_impl.cpp
index 5744612..b160060 100644
--- a/core/fxge/linux/fx_linux_impl.cpp
+++ b/core/fxge/linux/fx_linux_impl.cpp
@@ -83,10 +83,10 @@
CFX_LinuxFontInfo() = default;
~CFX_LinuxFontInfo() override = default;
- // CFX_LinuxFontInfo:
+ // CFX_FolderFontInfo:
void* MapFont(int weight,
bool bItalic,
- int charset,
+ FX_Charset charset,
int pitch_family,
const char* family) override;
@@ -95,7 +95,7 @@
void* CFX_LinuxFontInfo::MapFont(int weight,
bool bItalic,
- int charset,
+ FX_Charset charset,
int pitch_family,
const char* family) {
void* font = GetSubstFont(family);
@@ -104,7 +104,7 @@
bool bCJK = true;
switch (charset) {
- case FX_CHARSET_ShiftJIS: {
+ case FX_Charset::kShiftJIS: {
uint8_t index = GetJapanesePreference(family, weight, pitch_family);
DCHECK(index < pdfium::size(g_LinuxJpFontList));
for (const char* name : g_LinuxJpFontList[index]) {
@@ -114,7 +114,7 @@
}
break;
}
- case FX_CHARSET_ChineseSimplified: {
+ case FX_Charset::kChineseSimplified: {
for (const char* name : g_LinuxGbFontList) {
auto it = m_FontList.find(name);
if (it != m_FontList.end())
@@ -122,7 +122,7 @@
}
break;
}
- case FX_CHARSET_ChineseTraditional: {
+ case FX_Charset::kChineseTraditional: {
for (const char* name : g_LinuxB5FontList) {
auto it = m_FontList.find(name);
if (it != m_FontList.end())
@@ -130,7 +130,7 @@
}
break;
}
- case FX_CHARSET_Hangul: {
+ case FX_Charset::kHangul: {
for (const char* name : g_LinuxHGFontList) {
auto it = m_FontList.find(name);
if (it != m_FontList.end())
diff --git a/core/fxge/systemfontinfo_iface.h b/core/fxge/systemfontinfo_iface.h
index 0aaff5e..222872b 100644
--- a/core/fxge/systemfontinfo_iface.h
+++ b/core/fxge/systemfontinfo_iface.h
@@ -7,6 +7,7 @@
#ifndef CORE_FXGE_SYSTEMFONTINFO_IFACE_H_
#define CORE_FXGE_SYSTEMFONTINFO_IFACE_H_
+#include "core/fxcrt/fx_codepage_forward.h"
#include "core/fxge/cfx_fontmapper.h"
#include "third_party/base/span.h"
@@ -20,7 +21,7 @@
virtual bool EnumFontList(CFX_FontMapper* pMapper) = 0;
virtual void* MapFont(int weight,
bool bItalic,
- int charset,
+ FX_Charset charset,
int pitch_family,
const char* face) = 0;
virtual void* GetFont(const char* face) = 0;
@@ -28,7 +29,7 @@
uint32_t table,
pdfium::span<uint8_t> buffer) = 0;
virtual bool GetFaceName(void* hFont, ByteString* name) = 0;
- virtual bool GetFontCharset(void* hFont, int* charset) = 0;
+ virtual bool GetFontCharset(void* hFont, FX_Charset* charset) = 0;
virtual void DeleteFont(void* hFont) = 0;
};
diff --git a/core/fxge/win32/cwin32_platform.cpp b/core/fxge/win32/cwin32_platform.cpp
index 743133c..d8e853e 100644
--- a/core/fxge/win32/cwin32_platform.cpp
+++ b/core/fxge/win32/cwin32_platform.cpp
@@ -71,7 +71,7 @@
// CFX_FolderFontInfo:
void* MapFont(int weight,
bool bItalic,
- int charset,
+ FX_Charset charset,
int pitch_family,
const char* family) override;
};
@@ -85,7 +85,7 @@
bool EnumFontList(CFX_FontMapper* pMapper) override;
void* MapFont(int weight,
bool bItalic,
- int charset,
+ FX_Charset charset,
int pitch_family,
const char* face) override;
void* GetFont(const char* face) override { return nullptr; }
@@ -93,7 +93,7 @@
uint32_t table,
pdfium::span<uint8_t> buffer) override;
bool GetFaceName(void* hFont, ByteString* name) override;
- bool GetFontCharset(void* hFont, int* charset) override;
+ bool GetFontCharset(void* hFont, FX_Charset* charset) override;
void DeleteFont(void* hFont) override;
bool IsOpenTypeFromDiv(const LOGFONTA* plf);
@@ -176,7 +176,7 @@
return;
if (name == m_LastFamily) {
- m_pMapper->AddInstalledFont(name, plf->lfCharSet);
+ m_pMapper->AddInstalledFont(name, FX_GetCharsetFromInt(plf->lfCharSet));
return;
}
if (!(font_type & TRUETYPE_FONTTYPE)) {
@@ -184,7 +184,7 @@
return;
}
- m_pMapper->AddInstalledFont(name, plf->lfCharSet);
+ m_pMapper->AddInstalledFont(name, FX_GetCharsetFromInt(plf->lfCharSet));
m_LastFamily = name;
}
@@ -192,7 +192,7 @@
m_pMapper = pMapper;
LOGFONTA lf;
memset(&lf, 0, sizeof(LOGFONTA));
- lf.lfCharSet = FX_CHARSET_Default;
+ lf.lfCharSet = static_cast<int>(FX_Charset::kDefault);
lf.lfFaceName[0] = 0;
lf.lfPitchAndFamily = 0;
EnumFontFamiliesExA(m_hDC, &lf, (FONTENUMPROCA)FontEnumProc, (uintptr_t)this,
@@ -219,7 +219,7 @@
void* CFX_Win32FallbackFontInfo::MapFont(int weight,
bool bItalic,
- int charset,
+ FX_Charset charset,
int pitch_family,
const char* cstr_face) {
void* font = GetSubstFont(cstr_face);
@@ -228,10 +228,10 @@
bool bCJK = true;
switch (charset) {
- case FX_CHARSET_ShiftJIS:
- case FX_CHARSET_ChineseSimplified:
- case FX_CHARSET_ChineseTraditional:
- case FX_CHARSET_Hangul:
+ case FX_Charset::kShiftJIS:
+ case FX_Charset::kChineseSimplified:
+ case FX_Charset::kChineseTraditional:
+ case FX_Charset::kHangul:
break;
default:
bCJK = false;
@@ -309,7 +309,7 @@
void* CFX_Win32FontInfo::MapFont(int weight,
bool bItalic,
- int charset,
+ FX_Charset charset,
int pitch_family,
const char* cstr_face) {
ByteString face = cstr_face;
@@ -322,23 +322,23 @@
break;
}
}
- if (charset == FX_CHARSET_ANSI || charset == FX_CHARSET_Symbol)
- charset = FX_CHARSET_Default;
+ if (charset == FX_Charset::kANSI || charset == FX_Charset::kSymbol)
+ charset = FX_Charset::kDefault;
int subst_pitch_family = pitch_family;
switch (charset) {
- case FX_CHARSET_ShiftJIS:
+ case FX_Charset::kShiftJIS:
subst_pitch_family = FF_ROMAN;
break;
- case FX_CHARSET_ChineseTraditional:
- case FX_CHARSET_Hangul:
- case FX_CHARSET_ChineseSimplified:
+ case FX_Charset::kChineseTraditional:
+ case FX_Charset::kHangul:
+ case FX_Charset::kChineseSimplified:
subst_pitch_family = 0;
break;
}
- HFONT hFont =
- ::CreateFontA(-10, 0, 0, 0, weight, bItalic, 0, 0, charset,
- OUT_TT_ONLY_PRECIS, 0, 0, subst_pitch_family, face.c_str());
+ HFONT hFont = ::CreateFontA(-10, 0, 0, 0, weight, bItalic, 0, 0,
+ static_cast<int>(charset), OUT_TT_ONLY_PRECIS, 0,
+ 0, subst_pitch_family, face.c_str());
char facebuf[100];
HFONT hOldFont = (HFONT)::SelectObject(m_hDC, hFont);
::GetTextFaceA(m_hDC, 100, facebuf);
@@ -359,20 +359,20 @@
return hFont;
}
::DeleteObject(hFont);
- if (charset == FX_CHARSET_Default)
+ if (charset == FX_Charset::kDefault)
return nullptr;
switch (charset) {
- case FX_CHARSET_ShiftJIS:
+ case FX_Charset::kShiftJIS:
GetJapanesePreference(face, weight, pitch_family);
break;
- case FX_CHARSET_ChineseSimplified:
+ case FX_Charset::kChineseSimplified:
GetGBPreference(face, weight, pitch_family);
break;
- case FX_CHARSET_Hangul:
+ case FX_Charset::kHangul:
face = "Gulim";
break;
- case FX_CHARSET_ChineseTraditional:
+ case FX_Charset::kChineseTraditional:
if (face.Contains("MSung")) {
face = "MingLiU";
} else {
@@ -380,9 +380,9 @@
}
break;
}
- hFont =
- ::CreateFontA(-10, 0, 0, 0, weight, bItalic, 0, 0, charset,
- OUT_TT_ONLY_PRECIS, 0, 0, subst_pitch_family, face.c_str());
+ hFont = ::CreateFontA(-10, 0, 0, 0, weight, bItalic, 0, 0,
+ static_cast<int>(charset), OUT_TT_ONLY_PRECIS, 0, 0,
+ subst_pitch_family, face.c_str());
return hFont;
}
@@ -415,12 +415,12 @@
return true;
}
-bool CFX_Win32FontInfo::GetFontCharset(void* hFont, int* charset) {
+bool CFX_Win32FontInfo::GetFontCharset(void* hFont, FX_Charset* charset) {
TEXTMETRIC tm;
HFONT hOldFont = (HFONT)::SelectObject(m_hDC, (HFONT)hFont);
::GetTextMetrics(m_hDC, &tm);
::SelectObject(m_hDC, hOldFont);
- *charset = tm.tmCharSet;
+ *charset = FX_GetCharsetFromInt(tm.tmCharSet);
return true;
}
diff --git a/fpdfsdk/formfiller/cffl_combobox.cpp b/fpdfsdk/formfiller/cffl_combobox.cpp
index fa40a5f..412f1a1 100644
--- a/fpdfsdk/formfiller/cffl_combobox.cpp
+++ b/fpdfsdk/formfiller/cffl_combobox.cpp
@@ -238,7 +238,7 @@
#endif // PDF_ENABLE_XFA
void CFFL_ComboBox::OnSetFocus(CPWL_Edit* pEdit) {
- pEdit->SetCharSet(FX_CHARSET_ChineseSimplified);
+ pEdit->SetCharSet(FX_Charset::kChineseSimplified);
pEdit->SetReadyToInput();
WideString wsText = pEdit->GetText();
diff --git a/fpdfsdk/formfiller/cffl_textfield.cpp b/fpdfsdk/formfiller/cffl_textfield.cpp
index de6e70c..13605d5 100644
--- a/fpdfsdk/formfiller/cffl_textfield.cpp
+++ b/fpdfsdk/formfiller/cffl_textfield.cpp
@@ -243,7 +243,7 @@
#endif // PDF_ENABLE_XFA
void CFFL_TextField::OnSetFocus(CPWL_Edit* pEdit) {
- pEdit->SetCharSet(FX_CHARSET_ChineseSimplified);
+ pEdit->SetCharSet(FX_Charset::kChineseSimplified);
pEdit->SetReadyToInput();
WideString wsText = pEdit->GetText();
diff --git a/fpdfsdk/fpdf_sysfontinfo.cpp b/fpdfsdk/fpdf_sysfontinfo.cpp
index 7d7a19c..caf4761 100644
--- a/fpdfsdk/fpdf_sysfontinfo.cpp
+++ b/fpdfsdk/fpdf_sysfontinfo.cpp
@@ -19,24 +19,31 @@
#include "core/fxge/fx_font.h"
#include "core/fxge/systemfontinfo_iface.h"
-static_assert(FXFONT_ANSI_CHARSET == FX_CHARSET_ANSI, "Charset must match");
-static_assert(FXFONT_DEFAULT_CHARSET == FX_CHARSET_Default,
+static_assert(FXFONT_ANSI_CHARSET == static_cast<int>(FX_Charset::kANSI),
"Charset must match");
-static_assert(FXFONT_SYMBOL_CHARSET == FX_CHARSET_Symbol, "Charset must match");
-static_assert(FXFONT_SHIFTJIS_CHARSET == FX_CHARSET_ShiftJIS,
+static_assert(FXFONT_DEFAULT_CHARSET == static_cast<int>(FX_Charset::kDefault),
"Charset must match");
-static_assert(FXFONT_HANGEUL_CHARSET == FX_CHARSET_Hangul,
+static_assert(FXFONT_SYMBOL_CHARSET == static_cast<int>(FX_Charset::kSymbol),
"Charset must match");
-static_assert(FXFONT_GB2312_CHARSET == FX_CHARSET_ChineseSimplified,
+static_assert(FXFONT_SHIFTJIS_CHARSET ==
+ static_cast<int>(FX_Charset::kShiftJIS),
"Charset must match");
-static_assert(FXFONT_CHINESEBIG5_CHARSET == FX_CHARSET_ChineseTraditional,
+static_assert(FXFONT_HANGEUL_CHARSET == static_cast<int>(FX_Charset::kHangul),
"Charset must match");
-static_assert(FXFONT_ARABIC_CHARSET == FX_CHARSET_MSWin_Arabic,
+static_assert(FXFONT_GB2312_CHARSET ==
+ static_cast<int>(FX_Charset::kChineseSimplified),
"Charset must match");
-static_assert(FXFONT_CYRILLIC_CHARSET == FX_CHARSET_MSWin_Cyrillic,
+static_assert(FXFONT_CHINESEBIG5_CHARSET ==
+ static_cast<int>(FX_Charset::kChineseTraditional),
+ "Charset must match");
+static_assert(FXFONT_ARABIC_CHARSET ==
+ static_cast<int>(FX_Charset::kMSWin_Arabic),
+ "Charset must match");
+static_assert(FXFONT_CYRILLIC_CHARSET ==
+ static_cast<int>(FX_Charset::kMSWin_Cyrillic),
"Charset must match");
static_assert(FXFONT_EASTERNEUROPEAN_CHARSET ==
- FX_CHARSET_MSWin_EasternEuropean,
+ static_cast<int>(FX_Charset::kMSWin_EasternEuropean),
"Charset must match");
static_assert(offsetof(CFX_Font::CharsetFontMap, charset) ==
offsetof(FPDF_CharsetFontMap, charset),
@@ -65,15 +72,15 @@
void* MapFont(int weight,
bool bItalic,
- int charset,
+ FX_Charset charset,
int pitch_family,
const char* family) override {
if (!m_pInfo->MapFont)
return nullptr;
int iExact;
- return m_pInfo->MapFont(m_pInfo, weight, bItalic, charset, pitch_family,
- family, &iExact);
+ return m_pInfo->MapFont(m_pInfo, weight, bItalic, static_cast<int>(charset),
+ pitch_family, family, &iExact);
}
void* GetFont(const char* family) override {
@@ -104,11 +111,11 @@
return true;
}
- bool GetFontCharset(void* hFont, int* charset) override {
+ bool GetFontCharset(void* hFont, FX_Charset* charset) override {
if (!m_pInfo->GetFontCharset)
return false;
- *charset = m_pInfo->GetFontCharset(m_pInfo, hFont);
+ *charset = FX_GetCharsetFromInt(m_pInfo->GetFontCharset(m_pInfo, hFont));
return true;
}
@@ -125,7 +132,7 @@
const char* face,
int charset) {
CFX_FontMapper* pMapper = static_cast<CFX_FontMapper*>(mapper);
- pMapper->AddInstalledFont(face, charset);
+ pMapper->AddInstalledFont(face, FX_GetCharsetFromInt(charset));
}
FPDF_EXPORT void FPDF_CALLCONV
@@ -163,8 +170,8 @@
const char* family,
int* bExact) {
auto* pDefault = static_cast<FPDF_SYSFONTINFO_DEFAULT*>(pThis);
- return pDefault->m_pFontInfo->MapFont(weight, !!bItalic, charset,
- pitch_family, family);
+ return pDefault->m_pFontInfo->MapFont(
+ weight, !!bItalic, FX_GetCharsetFromInt(charset), pitch_family, family);
}
void* DefaultGetFont(struct _FPDF_SYSFONTINFO* pThis, const char* family) {
@@ -198,11 +205,11 @@
}
static int DefaultGetFontCharset(struct _FPDF_SYSFONTINFO* pThis, void* hFont) {
- int charset;
+ FX_Charset charset;
auto* pDefault = static_cast<FPDF_SYSFONTINFO_DEFAULT*>(pThis);
if (!pDefault->m_pFontInfo->GetFontCharset(hFont, &charset))
return 0;
- return charset;
+ return static_cast<int>(charset);
}
static void DefaultDeleteFont(struct _FPDF_SYSFONTINFO* pThis, void* hFont) {
diff --git a/fpdfsdk/pwl/cpwl_edit.cpp b/fpdfsdk/pwl/cpwl_edit.cpp
index 23a6e6f..f7861d1 100644
--- a/fpdfsdk/pwl/cpwl_edit.cpp
+++ b/fpdfsdk/pwl/cpwl_edit.cpp
@@ -253,7 +253,7 @@
if (!SetCaret(false, CFX_PointF(), CFX_PointF()))
return;
- SetCharSet(FX_CHARSET_ANSI);
+ SetCharSet(FX_Charset::kANSI);
m_bFocus = false;
}
@@ -450,9 +450,9 @@
return false;
if (IPVT_FontMap* pFontMap = GetFontMap()) {
- int32_t nOldCharSet = GetCharSet();
- int32_t nNewCharSet =
- pFontMap->CharSetFromUnicode(nChar, FX_CHARSET_Default);
+ FX_Charset nOldCharSet = GetCharSet();
+ FX_Charset nNewCharSet =
+ pFontMap->CharSetFromUnicode(nChar, FX_Charset::kDefault);
if (nOldCharSet != nNewCharSet) {
SetCharSet(nNewCharSet);
}
@@ -827,7 +827,7 @@
void CPWL_Edit::PasteText() {}
-void CPWL_Edit::InsertWord(uint16_t word, int32_t nCharset) {
+void CPWL_Edit::InsertWord(uint16_t word, FX_Charset nCharset) {
if (!IsReadOnly())
m_pEditImpl->InsertWord(word, nCharset);
}
diff --git a/fpdfsdk/pwl/cpwl_edit.h b/fpdfsdk/pwl/cpwl_edit.h
index a8ba98c..5f78226 100644
--- a/fpdfsdk/pwl/cpwl_edit.h
+++ b/fpdfsdk/pwl/cpwl_edit.h
@@ -75,8 +75,8 @@
CFX_PointF GetScrollPos() const;
void SetScrollPos(const CFX_PointF& point);
- void SetCharSet(uint8_t nCharSet) { m_nCharSet = nCharSet; }
- uint8_t GetCharSet() const { return m_nCharSet; }
+ void SetCharSet(FX_Charset nCharSet) { m_nCharSet = nCharSet; }
+ FX_Charset GetCharSet() const { return m_nCharSet; }
void SetReadyToInput();
void SetAlignFormatVerticalCenter();
@@ -114,7 +114,7 @@
void CopyText();
void PasteText();
- void InsertWord(uint16_t word, int32_t nCharset);
+ void InsertWord(uint16_t word, FX_Charset nCharset);
void InsertReturn();
bool IsWndHorV() const;
void Delete();
@@ -130,7 +130,7 @@
bool m_bMouseDown = false;
bool m_bFocus = false;
- uint8_t m_nCharSet = FX_CHARSET_Default;
+ FX_Charset m_nCharSet = FX_Charset::kDefault;
CFX_FloatRect m_rcOldWindow;
std::unique_ptr<CPWL_EditImpl> const m_pEditImpl;
UnownedPtr<CPWL_Caret> m_pCaret;
diff --git a/fpdfsdk/pwl/cpwl_edit_impl.cpp b/fpdfsdk/pwl/cpwl_edit_impl.cpp
index f54692f..c4583c7 100644
--- a/fpdfsdk/pwl/cpwl_edit_impl.cpp
+++ b/fpdfsdk/pwl/cpwl_edit_impl.cpp
@@ -103,7 +103,7 @@
// CPVT_VariableText::Provider:
int GetCharWidth(int32_t nFontIndex, uint16_t word) override;
int32_t GetWordFontIndex(uint16_t word,
- int32_t charset,
+ FX_Charset charset,
int32_t nFontIndex) override;
};
@@ -127,7 +127,7 @@
}
int32_t CPWL_EditImpl::Provider::GetWordFontIndex(uint16_t word,
- int32_t charset,
+ FX_Charset charset,
int32_t nFontIndex) {
return GetFontMap()->GetWordFontIndex(word, charset, nFontIndex);
}
@@ -242,7 +242,7 @@
const CPVT_WordPlace& wpOldPlace,
const CPVT_WordPlace& wpNewPlace,
uint16_t word,
- int32_t charset);
+ FX_Charset charset);
~UndoInsertWord() override;
// UndoItemIface:
@@ -255,14 +255,14 @@
CPVT_WordPlace m_wpOld;
CPVT_WordPlace m_wpNew;
uint16_t m_Word;
- int32_t m_nCharset;
+ FX_Charset m_nCharset;
};
CPWL_EditImpl::UndoInsertWord::UndoInsertWord(CPWL_EditImpl* pEdit,
const CPVT_WordPlace& wpOldPlace,
const CPVT_WordPlace& wpNewPlace,
uint16_t word,
- int32_t charset)
+ FX_Charset charset)
: m_pEdit(pEdit),
m_wpOld(wpOldPlace),
m_wpNew(wpNewPlace),
@@ -378,7 +378,7 @@
const CPVT_WordPlace& wpOldPlace,
const CPVT_WordPlace& wpNewPlace,
uint16_t word,
- int32_t charset);
+ FX_Charset charset);
~UndoBackspace() override;
// UndoItemIface:
@@ -391,14 +391,14 @@
CPVT_WordPlace m_wpOld;
CPVT_WordPlace m_wpNew;
uint16_t m_Word;
- int32_t m_nCharset;
+ FX_Charset m_nCharset;
};
CPWL_EditImpl::UndoBackspace::UndoBackspace(CPWL_EditImpl* pEdit,
const CPVT_WordPlace& wpOldPlace,
const CPVT_WordPlace& wpNewPlace,
uint16_t word,
- int32_t charset)
+ FX_Charset charset)
: m_pEdit(pEdit),
m_wpOld(wpOldPlace),
m_wpNew(wpNewPlace),
@@ -432,7 +432,7 @@
const CPVT_WordPlace& wpOldPlace,
const CPVT_WordPlace& wpNewPlace,
uint16_t word,
- int32_t charset,
+ FX_Charset charset,
bool bSecEnd);
~UndoDelete() override;
@@ -446,7 +446,7 @@
CPVT_WordPlace m_wpOld;
CPVT_WordPlace m_wpNew;
uint16_t m_Word;
- int32_t m_nCharset;
+ FX_Charset m_nCharset;
bool m_bSecEnd;
};
@@ -454,7 +454,7 @@
const CPVT_WordPlace& wpOldPlace,
const CPVT_WordPlace& wpNewPlace,
uint16_t word,
- int32_t charset,
+ FX_Charset charset,
bool bSecEnd)
: m_pEdit(pEdit),
m_wpOld(wpOldPlace),
@@ -521,7 +521,7 @@
int CPWL_EditImpl::UndoClear::Undo() {
m_pEdit->SelectNone();
m_pEdit->SetCaret(m_wrSel.BeginPos);
- m_pEdit->InsertText(m_swText, FX_CHARSET_Default, false);
+ m_pEdit->InsertText(m_swText, FX_Charset::kDefault, false);
m_pEdit->SetSelection(m_wrSel.BeginPos, m_wrSel.EndPos);
return 0;
}
@@ -533,7 +533,7 @@
const CPVT_WordPlace& wpOldPlace,
const CPVT_WordPlace& wpNewPlace,
const WideString& swText,
- int32_t charset);
+ FX_Charset charset);
~UndoInsertText() override;
// UndoItemIface:
@@ -546,14 +546,14 @@
CPVT_WordPlace m_wpOld;
CPVT_WordPlace m_wpNew;
WideString m_swText;
- int32_t m_nCharset;
+ FX_Charset m_nCharset;
};
CPWL_EditImpl::UndoInsertText::UndoInsertText(CPWL_EditImpl* pEdit,
const CPVT_WordPlace& wpOldPlace,
const CPVT_WordPlace& wpNewPlace,
const WideString& swText,
- int32_t charset)
+ FX_Charset charset)
: m_pEdit(pEdit),
m_wpOld(wpOldPlace),
m_wpNew(wpNewPlace),
@@ -901,10 +901,10 @@
void CPWL_EditImpl::SetText(const WideString& sText) {
Clear();
- DoInsertText(CPVT_WordPlace(0, 0, -1), sText, FX_CHARSET_Default);
+ DoInsertText(CPVT_WordPlace(0, 0, -1), sText, FX_Charset::kDefault);
}
-bool CPWL_EditImpl::InsertWord(uint16_t word, int32_t charset) {
+bool CPWL_EditImpl::InsertWord(uint16_t word, FX_Charset charset) {
return InsertWord(word, charset, true);
}
@@ -924,7 +924,7 @@
return Clear(true);
}
-bool CPWL_EditImpl::InsertText(const WideString& sText, int32_t charset) {
+bool CPWL_EditImpl::InsertText(const WideString& sText, FX_Charset charset) {
return InsertText(sText, charset, true);
}
@@ -1616,7 +1616,9 @@
}
}
-bool CPWL_EditImpl::InsertWord(uint16_t word, int32_t charset, bool bAddUndo) {
+bool CPWL_EditImpl::InsertWord(uint16_t word,
+ FX_Charset charset,
+ bool bAddUndo) {
if (IsTextOverflow() || !m_pVT->IsValid())
return false;
@@ -1748,7 +1750,7 @@
}
bool CPWL_EditImpl::InsertText(const WideString& sText,
- int32_t charset,
+ FX_Charset charset,
bool bAddUndo) {
if (IsTextOverflow())
return false;
@@ -1781,7 +1783,7 @@
void CPWL_EditImpl::ReplaceSelection(const WideString& text) {
AddEditUndoItem(std::make_unique<UndoReplaceSelection>(this, false));
ClearSelection();
- InsertText(text, FX_CHARSET_Default);
+ InsertText(text, FX_Charset::kDefault);
AddEditUndoItem(std::make_unique<UndoReplaceSelection>(this, true));
}
@@ -1883,7 +1885,7 @@
CPVT_WordPlace CPWL_EditImpl::DoInsertText(const CPVT_WordPlace& place,
const WideString& sText,
- int32_t charset) {
+ FX_Charset charset) {
CPVT_WordPlace wp = place;
if (m_pVT->IsValid()) {
@@ -1912,8 +1914,8 @@
return wp;
}
-int32_t CPWL_EditImpl::GetCharSetFromUnicode(uint16_t word,
- int32_t nOldCharset) {
+FX_Charset CPWL_EditImpl::GetCharSetFromUnicode(uint16_t word,
+ FX_Charset nOldCharset) {
if (IPVT_FontMap* pFontMap = GetFontMap())
return pFontMap->CharSetFromUnicode(word, nOldCharset);
return nOldCharset;
diff --git a/fpdfsdk/pwl/cpwl_edit_impl.h b/fpdfsdk/pwl/cpwl_edit_impl.h
index ee0b4d7..049359e 100644
--- a/fpdfsdk/pwl/cpwl_edit_impl.h
+++ b/fpdfsdk/pwl/cpwl_edit_impl.h
@@ -14,6 +14,7 @@
#include "core/fpdfdoc/cpvt_variabletext.h"
#include "core/fpdfdoc/cpvt_wordrange.h"
+#include "core/fxcrt/fx_codepage_forward.h"
#include "core/fxcrt/unowned_ptr.h"
#include "core/fxge/dib/fx_dib.h"
@@ -94,12 +95,12 @@
void OnVK_HOME(bool bShift, bool bCtrl);
void OnVK_END(bool bShift, bool bCtrl);
void SetText(const WideString& sText);
- bool InsertWord(uint16_t word, int32_t charset);
+ bool InsertWord(uint16_t word, FX_Charset charset);
bool InsertReturn();
bool Backspace();
bool Delete();
bool ClearSelection();
- bool InsertText(const WideString& sText, int32_t charset);
+ bool InsertText(const WideString& sText, FX_Charset charset);
void ReplaceSelection(const WideString& text);
bool Redo();
bool Undo();
@@ -226,22 +227,17 @@
class UndoReplaceSelection;
bool IsTextOverflow() const;
-
bool Clear();
-
CPVT_WordPlace DoInsertText(const CPVT_WordPlace& place,
const WideString& sText,
- int32_t charset);
- int32_t GetCharSetFromUnicode(uint16_t word, int32_t nOldCharset);
-
+ FX_Charset charset);
+ FX_Charset GetCharSetFromUnicode(uint16_t word, FX_Charset nOldCharset);
int32_t GetTotalLines() const;
-
void SetSelection(const CPVT_WordPlace& begin, const CPVT_WordPlace& end);
-
bool Delete(bool bAddUndo);
bool Clear(bool bAddUndo);
- bool InsertText(const WideString& sText, int32_t charset, bool bAddUndo);
- bool InsertWord(uint16_t word, int32_t charset, bool bAddUndo);
+ bool InsertText(const WideString& sText, FX_Charset charset, bool bAddUndo);
+ bool InsertWord(uint16_t word, FX_Charset charset, bool bAddUndo);
bool InsertReturn(bool bAddUndo);
bool Backspace(bool bAddUndo);
void SetCaret(const CPVT_WordPlace& place);
diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp
index 6b2aef9..be4a8f9 100644
--- a/xfa/fgas/font/cfgas_fontmgr.cpp
+++ b/xfa/fgas/font/cfgas_fontmgr.cpp
@@ -84,10 +84,10 @@
if (pParams->pwsFamily) {
if (FXSYS_wcsicmp(pParams->pwsFamily, font.wsFontFace))
continue;
- if (font.uCharSet == FX_CHARSET_Symbol)
+ if (font.uCharSet == FX_Charset::kSymbol)
return &font;
}
- if (font.uCharSet == FX_CHARSET_Symbol)
+ if (font.uCharSet == FX_Charset::kSymbol)
continue;
if (pParams->wCodePage != FX_CodePage::kFailure) {
if (FX_GetCodePageFromCharset(font.uCharSet) != pParams->wCodePage)
@@ -143,7 +143,7 @@
return 1;
FX_FONTDESCRIPTOR font;
memset(&font, 0, sizeof(FX_FONTDESCRIPTOR));
- font.uCharSet = lf.lfCharSet;
+ font.uCharSet = FX_GetCharsetFromInt(lf.lfCharSet);
font.dwFontStyles = GetGdiFontStyles(lf);
FXSYS_wcsncpy(font.wsFontFace, (const wchar_t*)lf.lfFaceName, 31);
font.wsFontFace[31] = 0;
diff --git a/xfa/fgas/font/cfgas_fontmgr.h b/xfa/fgas/font/cfgas_fontmgr.h
index 6e17c15..8cab66d 100644
--- a/xfa/fgas/font/cfgas_fontmgr.h
+++ b/xfa/fgas/font/cfgas_fontmgr.h
@@ -49,7 +49,7 @@
struct FX_FONTDESCRIPTOR {
wchar_t wsFontFace[32];
uint32_t dwFontStyles;
- uint8_t uCharSet;
+ FX_Charset uCharSet;
FX_FONTSIGNATURE FontSignature;
};