From 08e707273ef50c3a2365ff976e96e761800016d3 Mon Sep 17 00:00:00 2001 From: thestig Date: Fri, 1 Jul 2016 10:24:51 -0700 Subject: Clean up CFX_MacFontInfo and surrounding code. Review-Url: https://codereview.chromium.org/2112213002 --- core/fxge/apple/fx_mac_imp.cpp | 57 ++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 27 deletions(-) (limited to '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 489ce816cc..4ddc7db8ad 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; } - 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::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(m_pPlatformData); m_pPlatformData = nullptr; } -#endif + +#endif // _FX_OS_ == _FX_MACOSX_ -- cgit v1.2.3