Convert to kConstants in fxge/ and fxcodec/ files.
Change-Id: I59f142c3484e51e932231078aa2baea310e5a3ef
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/83753
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxcodec/jbig2/JBig2_ArithIntDecoder.cpp b/core/fxcodec/jbig2/JBig2_ArithIntDecoder.cpp
index 89478f6..c162c6c 100644
--- a/core/fxcodec/jbig2/JBig2_ArithIntDecoder.cpp
+++ b/core/fxcodec/jbig2/JBig2_ArithIntDecoder.cpp
@@ -17,10 +17,12 @@
return (val << 1) | bitwise_or_val;
}
-const struct ArithIntDecodeData {
+struct ArithIntDecodeData {
int nNeedBits;
int nValue;
-} g_ArithIntDecodeData[] = {
+};
+
+constexpr ArithIntDecodeData kArithIntDecodeData[] = {
{2, 0}, {4, 4}, {6, 20}, {8, 84}, {12, 340}, {32, 4436},
};
@@ -28,7 +30,7 @@
std::vector<JBig2ArithCtx>* context,
int* prev,
size_t depth) {
- static const size_t kDepthEnd = pdfium::size(g_ArithIntDecodeData) - 1;
+ static const size_t kDepthEnd = pdfium::size(kArithIntDecodeData) - 1;
if (depth == kDepthEnd)
return kDepthEnd;
@@ -61,14 +63,14 @@
RecursiveDecode(pArithDecoder, &m_IAx, &PREV, 0);
int nTemp = 0;
- for (int i = 0; i < g_ArithIntDecodeData[nDecodeDataIndex].nNeedBits; ++i) {
+ for (int i = 0; i < kArithIntDecodeData[nDecodeDataIndex].nNeedBits; ++i) {
int D = pArithDecoder->Decode(&m_IAx[PREV]);
PREV = ShiftOr(PREV, D);
if (PREV >= 256)
PREV = (PREV & 511) | 256;
nTemp = ShiftOr(nTemp, D);
}
- FX_SAFE_INT32 safeValue = g_ArithIntDecodeData[nDecodeDataIndex].nValue;
+ FX_SAFE_INT32 safeValue = kArithIntDecodeData[nDecodeDataIndex].nValue;
safeValue += nTemp;
// Value does not fit in int.
diff --git a/core/fxge/android/cfpf_skiafontmgr.cpp b/core/fxge/android/cfpf_skiafontmgr.cpp
index 6d5d323..f2f72da 100644
--- a/core/fxge/android/cfpf_skiafontmgr.cpp
+++ b/core/fxge/android/cfpf_skiafontmgr.cpp
@@ -32,7 +32,7 @@
uint32_t dwSubSt;
};
-const FPF_SKIAFONTMAP g_SkiaFontmap[] = {
+const FPF_SKIAFONTMAP kSkiaFontmap[] = {
{0x58c5083, 0xc8d2e345}, {0x5dfade2, 0xe1633081},
{0x684317d, 0xe1633081}, {0x14ee2d13, 0xc8d2e345},
{0x3918fe2d, 0xbbeeec72}, {0x3b98b31c, 0xe1633081},
@@ -46,7 +46,7 @@
{0xfb4ce0de, 0xe1633081},
};
-const FPF_SKIAFONTMAP g_SkiaSansFontMap[] = {
+const FPF_SKIAFONTMAP kSkiaSansFontMap[] = {
{0x58c5083, 0xd5b8d10f}, {0x14ee2d13, 0xd5b8d10f},
{0x779ce19d, 0xd5b8d10f}, {0xcb7a04c8, 0xd5b8d10f},
{0xfb4ce0de, 0xd5b8d10f},
@@ -178,7 +178,7 @@
return bsName.Contains("arabic");
}
-const uint32_t g_FPFSkiaFontCharsets[] = {
+const uint32_t kFPFSkiaFontCharsets[] = {
FPF_SKIACHARSET_Ansi,
FPF_SKIACHARSET_EeasternEuropean,
FPF_SKIACHARSET_Cyrillic,
@@ -218,7 +218,7 @@
if (pOS2) {
for (int32_t i = 0; i < 32; i++) {
if (pOS2->ulCodePageRange1 & (1 << i))
- dwCharset |= g_FPFSkiaFontCharsets[i];
+ dwCharset |= kFPFSkiaFontCharsets[i];
}
}
dwCharset |= FPF_SKIACHARSET_Default;
@@ -263,10 +263,10 @@
return family_iter->second.get();
uint32_t dwFaceName = FPF_SKIANormalizeFontName(bsFamilyname);
- uint32_t dwSubst = FPF_SkiaGetSubstFont(dwFaceName, g_SkiaFontmap,
- pdfium::size(g_SkiaFontmap));
- uint32_t dwSubstSans = FPF_SkiaGetSubstFont(dwFaceName, g_SkiaSansFontMap,
- pdfium::size(g_SkiaSansFontMap));
+ uint32_t dwSubst = FPF_SkiaGetSubstFont(dwFaceName, kSkiaFontmap,
+ pdfium::size(kSkiaFontmap));
+ uint32_t dwSubstSans = FPF_SkiaGetSubstFont(dwFaceName, kSkiaSansFontMap,
+ pdfium::size(kSkiaSansFontMap));
bool bMaybeSymbol = FPF_SkiaMaybeSymbol(bsFamilyname);
if (uCharset != FX_Charset::kMSWin_Arabic &&
FPF_SkiaMaybeArabic(bsFamilyname)) {
diff --git a/core/fxge/apple/fx_apple_platform.cpp b/core/fxge/apple/fx_apple_platform.cpp
index d3bd980..6f3e89c 100644
--- a/core/fxge/apple/fx_apple_platform.cpp
+++ b/core/fxge/apple/fx_apple_platform.cpp
@@ -17,10 +17,12 @@
namespace {
-const struct {
+struct Substs {
const char* m_pName;
const char* m_pSubstName;
-} g_Base14Substs[] = {
+};
+
+constexpr Substs kBase14Substs[] = {
{"Courier", "Courier New"},
{"Courier-Bold", "Courier New Bold"},
{"Courier-BoldOblique", "Courier New Bold Italic"},
@@ -68,7 +70,7 @@
FX_Charset charset,
int pitch_family,
const ByteString& face) {
- for (const auto& sub : g_Base14Substs) {
+ for (const auto& sub : kBase14Substs) {
if (face == ByteStringView(sub.m_pName))
return GetFont(sub.m_pSubstName);
}
diff --git a/core/fxge/cfx_fontmapper.cpp b/core/fxge/cfx_fontmapper.cpp
index 2230030..24ca860 100644
--- a/core/fxge/cfx_fontmapper.cpp
+++ b/core/fxge/cfx_fontmapper.cpp
@@ -210,11 +210,13 @@
return ByteString(buf);
}
-const struct FX_FontStyle {
+struct FX_FontStyle {
const char* name;
size_t len;
uint32_t style;
-} g_FontStyles[] = {
+};
+
+const FX_FontStyle kFontStyles[] = {
{"Bold", 4, FXFONT_FORCE_BOLD},
{"Italic", 6, FXFONT_ITALIC},
{"BoldItalic", 10, FXFONT_FORCE_BOLD | FXFONT_ITALIC},
@@ -228,8 +230,8 @@
if (bsStyle.IsEmpty())
return std::make_tuple(false, FXFONT_NORMAL, 0);
- for (int i = pdfium::size(g_FontStyles) - 1; i >= 0; --i) {
- const FX_FontStyle* pStyle = g_FontStyles + i;
+ for (int i = pdfium::size(kFontStyles) - 1; i >= 0; --i) {
+ const FX_FontStyle* pStyle = kFontStyles + i;
if (!pStyle || pStyle->len > bsStyle.GetLength())
continue;
diff --git a/core/fxge/win32/cwin32_platform.cpp b/core/fxge/win32/cwin32_platform.cpp
index 8977d34..44c6f1e 100644
--- a/core/fxge/win32/cwin32_platform.cpp
+++ b/core/fxge/win32/cwin32_platform.cpp
@@ -17,19 +17,23 @@
namespace {
-const struct {
+struct Variant {
const char* m_pFaceName;
const char* m_pVariantName; // Note: UTF-16LE terminator required.
-} g_VariantNames[] = {
+};
+
+constexpr Variant kVariantNames[] = {
{"DFKai-SB", "\x19\x6A\x77\x69\xD4\x9A\x00\x00"},
};
-const struct {
+struct Substs {
const char* m_pName;
const char* m_pWinName;
bool m_bBold;
bool m_bItalic;
-} g_Base14Substs[] = {
+};
+
+constexpr Substs kBase14Substs[] = {
{"Courier", "Courier New", false, false},
{"Courier-Bold", "Courier New", true, false},
{"Courier-BoldOblique", "Courier New", true, true},
@@ -48,15 +52,16 @@
const char* m_pSubFontName;
const char* m_pSrcFontName;
};
-const FontNameMap g_JpFontNameMap[] = {
+
+constexpr FontNameMap kJpFontNameMap[] = {
{"MS Mincho", "Heiseimin-W3"},
{"MS Gothic", "Jun101-Light"},
};
bool GetSubFontName(ByteString* name) {
- for (size_t i = 0; i < pdfium::size(g_JpFontNameMap); ++i) {
- if (!FXSYS_stricmp(name->c_str(), g_JpFontNameMap[i].m_pSrcFontName)) {
- *name = g_JpFontNameMap[i].m_pSubFontName;
+ for (size_t i = 0; i < pdfium::size(kJpFontNameMap); ++i) {
+ if (!FXSYS_stricmp(name->c_str(), kJpFontNameMap[i].m_pSrcFontName)) {
+ *name = kJpFontNameMap[i].m_pSubFontName;
return true;
}
}
@@ -314,10 +319,10 @@
const ByteString& face) {
ByteString new_face = face;
for (int iBaseFont = 0; iBaseFont < 12; iBaseFont++) {
- if (new_face == ByteStringView(g_Base14Substs[iBaseFont].m_pName)) {
- new_face = g_Base14Substs[iBaseFont].m_pWinName;
- weight = g_Base14Substs[iBaseFont].m_bBold ? FW_BOLD : FW_NORMAL;
- bItalic = g_Base14Substs[iBaseFont].m_bItalic;
+ if (new_face == ByteStringView(kBase14Substs[iBaseFont].m_pName)) {
+ new_face = kBase14Substs[iBaseFont].m_pWinName;
+ weight = kBase14Substs[iBaseFont].m_bBold ? FW_BOLD : FW_NORMAL;
+ bItalic = kBase14Substs[iBaseFont].m_bItalic;
break;
}
}
@@ -346,12 +351,12 @@
return hFont;
WideString wsFace = WideString::FromDefANSI(facebuf);
- for (size_t i = 0; i < pdfium::size(g_VariantNames); ++i) {
- if (new_face != g_VariantNames[i].m_pFaceName)
+ for (size_t i = 0; i < pdfium::size(kVariantNames); ++i) {
+ if (new_face != kVariantNames[i].m_pFaceName)
continue;
const unsigned short* pName = reinterpret_cast<const unsigned short*>(
- g_VariantNames[i].m_pVariantName);
+ kVariantNames[i].m_pVariantName);
size_t len = WideString::WStringLength(pName);
WideString wsName = WideString::FromUTF16LE(pName, len);
if (wsFace == wsName)