Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "core/fxge/apple/apple_int.h" | 7 #include "core/fxge/apple/apple_int.h" |
| 8 #include "core/fxge/include/fx_ge.h" | 8 #include "core/fxge/include/fx_ge.h" |
| 9 | 9 |
| 10 #if _FX_OS_ == _FX_MACOSX_ | 10 #if _FX_OS_ == _FX_MACOSX_ |
| 11 static const struct { | 11 |
| 12 namespace { | |
| 13 | |
| 14 const struct { | |
| 12 const FX_CHAR* m_pName; | 15 const FX_CHAR* m_pName; |
| 13 const FX_CHAR* m_pSubstName; | 16 const FX_CHAR* m_pSubstName; |
| 14 } Base14Substs[] = { | 17 } g_Base14Substs[] = { |
| 15 {"Courier", "Courier New"}, | 18 {"Courier", "Courier New"}, |
| 16 {"Courier-Bold", "Courier New Bold"}, | 19 {"Courier-Bold", "Courier New Bold"}, |
| 17 {"Courier-BoldOblique", "Courier New Bold Italic"}, | 20 {"Courier-BoldOblique", "Courier New Bold Italic"}, |
| 18 {"Courier-Oblique", "Courier New Italic"}, | 21 {"Courier-Oblique", "Courier New Italic"}, |
| 19 {"Helvetica", "Arial"}, | 22 {"Helvetica", "Arial"}, |
| 20 {"Helvetica-Bold", "Arial Bold"}, | 23 {"Helvetica-Bold", "Arial Bold"}, |
| 21 {"Helvetica-BoldOblique", "Arial Bold Italic"}, | 24 {"Helvetica-BoldOblique", "Arial Bold Italic"}, |
| 22 {"Helvetica-Oblique", "Arial Italic"}, | 25 {"Helvetica-Oblique", "Arial Italic"}, |
| 23 {"Times-Roman", "Times New Roman"}, | 26 {"Times-Roman", "Times New Roman"}, |
| 24 {"Times-Bold", "Times New Roman Bold"}, | 27 {"Times-Bold", "Times New Roman Bold"}, |
| 25 {"Times-BoldItalic", "Times New Roman Bold Italic"}, | 28 {"Times-BoldItalic", "Times New Roman Bold Italic"}, |
| 26 {"Times-Italic", "Times New Roman Italic"}, | 29 {"Times-Italic", "Times New Roman Italic"}, |
| 27 }; | 30 }; |
| 28 | 31 |
| 29 class CFX_MacFontInfo : public CFX_FolderFontInfo { | 32 class CFX_MacFontInfo : public CFX_FolderFontInfo { |
| 30 public: | 33 public: |
| 31 CFX_MacFontInfo() {} | 34 CFX_MacFontInfo() {} |
| 32 ~CFX_MacFontInfo() override {} | 35 ~CFX_MacFontInfo() override {} |
| 33 | 36 |
| 34 // CFX_FolderFontInfo | 37 // CFX_FolderFontInfo |
| 35 void* MapFont(int weight, | 38 void* MapFont(int weight, |
| 36 FX_BOOL bItalic, | 39 FX_BOOL bItalic, |
| 37 int charset, | 40 int charset, |
| 38 int pitch_family, | 41 int pitch_family, |
| 39 const FX_CHAR* family, | 42 const FX_CHAR* family, |
| 40 int& iExact) override; | 43 int& iExact) override; |
| 41 }; | 44 }; |
| 42 | 45 |
| 43 #define JAPAN_GOTHIC "Hiragino Kaku Gothic Pro W6" | 46 const char JAPAN_GOTHIC[] = "Hiragino Kaku Gothic Pro W6"; |
| 44 #define JAPAN_MINCHO "Hiragino Mincho Pro W6" | 47 const char JAPAN_MINCHO[] = "Hiragino Mincho Pro W6"; |
| 45 static void GetJapanesePreference(CFX_ByteString& face, | 48 |
| 46 int weight, | 49 void GetJapanesePreference(CFX_ByteString* face, int weight, int pitch_family) { |
| 47 int pitch_family) { | 50 if (face->Find("Gothic") >= 0) { |
| 48 if (face.Find("Gothic") >= 0) { | 51 *face = JAPAN_GOTHIC; |
| 49 face = JAPAN_GOTHIC; | |
| 50 return; | 52 return; |
| 51 } | 53 } |
| 52 if (!(pitch_family & FXFONT_FF_ROMAN) && weight > 400) { | 54 *face = ((pitch_family & FXFONT_FF_ROMAN) || weight <= 400) ? JAPAN_MINCHO |
| 53 face = JAPAN_GOTHIC; | 55 : JAPAN_GOTHIC; |
| 54 } else { | |
| 55 face = JAPAN_MINCHO; | |
| 56 } | |
| 57 } | 56 } |
| 57 | |
| 58 void* CFX_MacFontInfo::MapFont(int weight, | 58 void* CFX_MacFontInfo::MapFont(int weight, |
| 59 FX_BOOL bItalic, | 59 FX_BOOL bItalic, |
| 60 int charset, | 60 int charset, |
| 61 int pitch_family, | 61 int pitch_family, |
| 62 const FX_CHAR* cstr_face, | 62 const FX_CHAR* cstr_face, |
| 63 int& iExact) { | 63 int& iExact) { |
| 64 CFX_ByteString face = cstr_face; | 64 CFX_ByteString face = cstr_face; |
| 65 int iBaseFont; | 65 for (size_t i = 0; i < FX_ArraySize(g_Base14Substs); ++i) { |
| 66 for (iBaseFont = 0; iBaseFont < 12; iBaseFont++) | 66 if (face == CFX_ByteStringC(g_Base14Substs[i].m_pName)) { |
| 67 if (face == CFX_ByteStringC(Base14Substs[iBaseFont].m_pName)) { | 67 face = g_Base14Substs[i].m_pSubstName; |
| 68 face = Base14Substs[iBaseFont].m_pSubstName; | |
| 69 iExact = TRUE; | 68 iExact = TRUE; |
| 69 return GetFont(face.c_str()); | |
| 70 break; | 70 break; |
|
Lei Zhang
2016/07/01 18:50:30
Whoops, forgot to remove the break. No worries. I
| |
| 71 } | 71 } |
| 72 if (iBaseFont < 12) { | |
| 73 return GetFont(face.c_str()); | |
| 74 } | 72 } |
| 73 | |
| 75 auto it = m_FontList.find(face); | 74 auto it = m_FontList.find(face); |
| 76 if (it != m_FontList.end()) | 75 if (it != m_FontList.end()) |
| 77 return it->second; | 76 return it->second; |
| 78 | 77 |
| 79 if (charset == FXFONT_ANSI_CHARSET && (pitch_family & FXFONT_FF_FIXEDPITCH)) { | 78 if (charset == FXFONT_ANSI_CHARSET && (pitch_family & FXFONT_FF_FIXEDPITCH)) |
| 80 return GetFont("Courier New"); | 79 return GetFont("Courier New"); |
| 81 } | 80 |
| 82 if (charset == FXFONT_ANSI_CHARSET || charset == FXFONT_SYMBOL_CHARSET) { | 81 if (charset == FXFONT_ANSI_CHARSET || charset == FXFONT_SYMBOL_CHARSET) |
| 83 return nullptr; | 82 return nullptr; |
| 84 } | 83 |
| 85 switch (charset) { | 84 switch (charset) { |
| 86 case FXFONT_SHIFTJIS_CHARSET: | 85 case FXFONT_SHIFTJIS_CHARSET: |
| 87 GetJapanesePreference(face, weight, pitch_family); | 86 GetJapanesePreference(&face, weight, pitch_family); |
| 88 break; | 87 break; |
| 89 case FXFONT_GB2312_CHARSET: | 88 case FXFONT_GB2312_CHARSET: |
| 90 face = "STSong"; | 89 face = "STSong"; |
| 91 break; | 90 break; |
| 92 case FXFONT_HANGEUL_CHARSET: | 91 case FXFONT_HANGEUL_CHARSET: |
| 93 face = "AppleMyungjo"; | 92 face = "AppleMyungjo"; |
| 94 break; | 93 break; |
| 95 case FXFONT_CHINESEBIG5_CHARSET: | 94 case FXFONT_CHINESEBIG5_CHARSET: |
| 96 face = "LiSong Pro Light"; | 95 face = "LiSong Pro Light"; |
| 97 } | 96 } |
| 98 it = m_FontList.find(face); | 97 it = m_FontList.find(face); |
| 99 return it != m_FontList.end() ? it->second : nullptr; | 98 return it != m_FontList.end() ? it->second : nullptr; |
| 100 } | 99 } |
| 101 | 100 |
| 101 } // namespace | |
| 102 | |
| 102 std::unique_ptr<IFX_SystemFontInfo> IFX_SystemFontInfo::CreateDefault( | 103 std::unique_ptr<IFX_SystemFontInfo> IFX_SystemFontInfo::CreateDefault( |
| 103 const char** pUnused) { | 104 const char** pUnused) { |
| 104 CFX_MacFontInfo* pInfo(new CFX_MacFontInfo); | 105 CFX_MacFontInfo* pInfo(new CFX_MacFontInfo); |
| 105 pInfo->AddPath("~/Library/Fonts"); | 106 pInfo->AddPath("~/Library/Fonts"); |
| 106 pInfo->AddPath("/Library/Fonts"); | 107 pInfo->AddPath("/Library/Fonts"); |
| 107 pInfo->AddPath("/System/Library/Fonts"); | 108 pInfo->AddPath("/System/Library/Fonts"); |
| 108 return std::unique_ptr<CFX_MacFontInfo>(pInfo); | 109 return std::unique_ptr<CFX_MacFontInfo>(pInfo); |
| 109 } | 110 } |
| 110 | 111 |
| 111 void CFX_GEModule::InitPlatform() { | 112 void CFX_GEModule::InitPlatform() { |
| 112 m_pPlatformData = new CApplePlatform; | 113 m_pPlatformData = new CApplePlatform; |
| 113 m_pFontMgr->SetSystemFontInfo(IFX_SystemFontInfo::CreateDefault(nullptr)); | 114 m_pFontMgr->SetSystemFontInfo(IFX_SystemFontInfo::CreateDefault(nullptr)); |
| 114 } | 115 } |
| 116 | |
| 115 void CFX_GEModule::DestroyPlatform() { | 117 void CFX_GEModule::DestroyPlatform() { |
| 116 delete (CApplePlatform*)m_pPlatformData; | 118 delete reinterpret_cast<CApplePlatform*>(m_pPlatformData); |
| 117 m_pPlatformData = nullptr; | 119 m_pPlatformData = nullptr; |
| 118 } | 120 } |
| 119 #endif | 121 |
| 122 #endif // _FX_OS_ == _FX_MACOSX_ | |
| OLD | NEW |