Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2734)

Unified Diff: core/fxge/apple/fx_mac_imp.cpp

Issue 2112213002: Clean up CFX_MacFontInfo and surrounding code. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: nit Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « core/fxge/apple/apple_int.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fxge/apple/fx_mac_imp.cpp
diff --git a/core/fxge/apple/fx_mac_imp.cpp b/core/fxge/apple/fx_mac_imp.cpp
index 489ce816cc234e46a9dd11c0cf026fca30daab1a..4ddc7db8ad56bbe1bde3e4d0fd2fd8e4c70469f8 100644
--- a/core/fxge/apple/fx_mac_imp.cpp
+++ b/core/fxge/apple/fx_mac_imp.cpp
@@ -8,10 +8,13 @@
#include "core/fxge/include/fx_ge.h"
#if _FX_OS_ == _FX_MACOSX_
-static const struct {
+
+namespace {
+
+const struct {
const FX_CHAR* m_pName;
const FX_CHAR* m_pSubstName;
-} Base14Substs[] = {
+} g_Base14Substs[] = {
{"Courier", "Courier New"},
{"Courier-Bold", "Courier New Bold"},
{"Courier-BoldOblique", "Courier New Bold Italic"},
@@ -40,21 +43,18 @@ class CFX_MacFontInfo : public CFX_FolderFontInfo {
int& iExact) override;
};
-#define JAPAN_GOTHIC "Hiragino Kaku Gothic Pro W6"
-#define JAPAN_MINCHO "Hiragino Mincho Pro W6"
-static void GetJapanesePreference(CFX_ByteString& face,
- int weight,
- int pitch_family) {
- if (face.Find("Gothic") >= 0) {
- face = JAPAN_GOTHIC;
+const char JAPAN_GOTHIC[] = "Hiragino Kaku Gothic Pro W6";
+const char JAPAN_MINCHO[] = "Hiragino Mincho Pro W6";
+
+void GetJapanesePreference(CFX_ByteString* face, int weight, int pitch_family) {
+ if (face->Find("Gothic") >= 0) {
+ *face = JAPAN_GOTHIC;
return;
}
- if (!(pitch_family & FXFONT_FF_ROMAN) && weight > 400) {
- face = JAPAN_GOTHIC;
- } else {
- face = JAPAN_MINCHO;
- }
+ *face = ((pitch_family & FXFONT_FF_ROMAN) || weight <= 400) ? JAPAN_MINCHO
+ : JAPAN_GOTHIC;
}
+
void* CFX_MacFontInfo::MapFont(int weight,
FX_BOOL bItalic,
int charset,
@@ -62,29 +62,28 @@ void* CFX_MacFontInfo::MapFont(int weight,
const FX_CHAR* cstr_face,
int& iExact) {
CFX_ByteString face = cstr_face;
- int iBaseFont;
- for (iBaseFont = 0; iBaseFont < 12; iBaseFont++)
- if (face == CFX_ByteStringC(Base14Substs[iBaseFont].m_pName)) {
- face = Base14Substs[iBaseFont].m_pSubstName;
+ for (size_t i = 0; i < FX_ArraySize(g_Base14Substs); ++i) {
+ if (face == CFX_ByteStringC(g_Base14Substs[i].m_pName)) {
+ face = g_Base14Substs[i].m_pSubstName;
iExact = TRUE;
+ return GetFont(face.c_str());
break;
Lei Zhang 2016/07/01 18:50:30 Whoops, forgot to remove the break. No worries. I
}
- if (iBaseFont < 12) {
- return GetFont(face.c_str());
}
+
auto it = m_FontList.find(face);
if (it != m_FontList.end())
return it->second;
- if (charset == FXFONT_ANSI_CHARSET && (pitch_family & FXFONT_FF_FIXEDPITCH)) {
+ if (charset == FXFONT_ANSI_CHARSET && (pitch_family & FXFONT_FF_FIXEDPITCH))
return GetFont("Courier New");
- }
- if (charset == FXFONT_ANSI_CHARSET || charset == FXFONT_SYMBOL_CHARSET) {
+
+ if (charset == FXFONT_ANSI_CHARSET || charset == FXFONT_SYMBOL_CHARSET)
return nullptr;
- }
+
switch (charset) {
case FXFONT_SHIFTJIS_CHARSET:
- GetJapanesePreference(face, weight, pitch_family);
+ GetJapanesePreference(&face, weight, pitch_family);
break;
case FXFONT_GB2312_CHARSET:
face = "STSong";
@@ -99,6 +98,8 @@ void* CFX_MacFontInfo::MapFont(int weight,
return it != m_FontList.end() ? it->second : nullptr;
}
+} // namespace
+
std::unique_ptr<IFX_SystemFontInfo> IFX_SystemFontInfo::CreateDefault(
const char** pUnused) {
CFX_MacFontInfo* pInfo(new CFX_MacFontInfo);
@@ -112,8 +113,10 @@ void CFX_GEModule::InitPlatform() {
m_pPlatformData = new CApplePlatform;
m_pFontMgr->SetSystemFontInfo(IFX_SystemFontInfo::CreateDefault(nullptr));
}
+
void CFX_GEModule::DestroyPlatform() {
- delete (CApplePlatform*)m_pPlatformData;
+ delete reinterpret_cast<CApplePlatform*>(m_pPlatformData);
m_pPlatformData = nullptr;
}
-#endif
+
+#endif // _FX_OS_ == _FX_MACOSX_
« no previous file with comments | « core/fxge/apple/apple_int.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698