| 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 "../../../include/fxge/fx_ge.h" | 7 #include "../../../include/fxge/fx_ge.h" |
| 8 #include "apple_int.h" | 8 #include "apple_int.h" |
| 9 #if _FX_OS_ == _FX_MACOSX_ | 9 #if _FX_OS_ == _FX_MACOSX_ |
| 10 static const struct { | 10 static const struct { |
| 11 FX_LPCSTR» m_pName; | 11 FX_LPCSTR m_pName; |
| 12 FX_LPCSTR» m_pSubstName; | 12 FX_LPCSTR m_pSubstName; |
| 13 } | 13 } Base14Substs[] = { |
| 14 Base14Substs[] = { | 14 { "Courier", "Courier New" }, |
| 15 {"Courier", "Courier New"}, | 15 { "Courier-Bold", "Courier New Bold" }, |
| 16 {"Courier-Bold", "Courier New Bold"}, | 16 { "Courier-BoldOblique", "Courier New Bold Italic" }, |
| 17 {"Courier-BoldOblique", "Courier New Bold Italic"}, | 17 { "Courier-Oblique", "Courier New Italic" }, |
| 18 {"Courier-Oblique", "Courier New Italic"}, | 18 { "Helvetica", "Arial" }, |
| 19 {"Helvetica", "Arial"}, | 19 { "Helvetica-Bold", "Arial Bold" }, |
| 20 {"Helvetica-Bold", "Arial Bold"}, | 20 { "Helvetica-BoldOblique", "Arial Bold Italic" }, |
| 21 {"Helvetica-BoldOblique", "Arial Bold Italic"}, | 21 { "Helvetica-Oblique", "Arial Italic" }, |
| 22 {"Helvetica-Oblique", "Arial Italic"}, | 22 { "Times-Roman", "Times New Roman" }, |
| 23 {"Times-Roman", "Times New Roman"}, | 23 { "Times-Bold", "Times New Roman Bold" }, |
| 24 {"Times-Bold", "Times New Roman Bold"}, | 24 { "Times-BoldItalic", "Times New Roman Bold Italic" }, |
| 25 {"Times-BoldItalic", "Times New Roman Bold Italic"}, | 25 { "Times-Italic", "Times New Roman Italic" }, |
| 26 {"Times-Italic", "Times New Roman Italic"}, | 26 }; |
| 27 }; | |
| 28 #if !defined(_FPDFAPI_MINI_) | 27 #if !defined(_FPDFAPI_MINI_) |
| 29 class CFX_MacFontInfo : public CFX_FolderFontInfo | 28 class CFX_MacFontInfo : public CFX_FolderFontInfo { |
| 30 { | 29 public: |
| 31 public: | 30 virtual void* MapFont(int weight, |
| 32 virtual void*» » MapFont(int weight, FX_BOOL bItalic, int charset
, int pitch_family, FX_LPCSTR family, FX_BOOL& bExact); | 31 FX_BOOL bItalic, |
| 32 int charset, |
| 33 int pitch_family, |
| 34 FX_LPCSTR family, |
| 35 FX_BOOL& bExact); |
| 33 }; | 36 }; |
| 34 #define JAPAN_GOTHIC "Hiragino Kaku Gothic Pro W6" | 37 #define JAPAN_GOTHIC "Hiragino Kaku Gothic Pro W6" |
| 35 #define JAPAN_MINCHO "Hiragino Mincho Pro W6" | 38 #define JAPAN_MINCHO "Hiragino Mincho Pro W6" |
| 36 static void GetJapanesePreference(CFX_ByteString& face, int weight, int picth_fa
mily) | 39 static void GetJapanesePreference(CFX_ByteString& face, |
| 37 { | 40 int weight, |
| 38 if (face.Find("Gothic") >= 0) { | 41 int picth_family) { |
| 39 face = JAPAN_GOTHIC; | 42 if (face.Find("Gothic") >= 0) { |
| 40 return; | 43 face = JAPAN_GOTHIC; |
| 44 return; |
| 45 } |
| 46 if (!(picth_family & FXFONT_FF_ROMAN) && weight > 400) { |
| 47 face = JAPAN_GOTHIC; |
| 48 } else { |
| 49 face = JAPAN_MINCHO; |
| 50 } |
| 51 } |
| 52 void* CFX_MacFontInfo::MapFont(int weight, |
| 53 FX_BOOL bItalic, |
| 54 int charset, |
| 55 int pitch_family, |
| 56 FX_LPCSTR cstr_face, |
| 57 FX_BOOL& bExact) { |
| 58 CFX_ByteString face = cstr_face; |
| 59 int iBaseFont; |
| 60 for (iBaseFont = 0; iBaseFont < 12; iBaseFont++) |
| 61 if (face == CFX_ByteStringC(Base14Substs[iBaseFont].m_pName)) { |
| 62 face = Base14Substs[iBaseFont].m_pSubstName; |
| 63 bExact = TRUE; |
| 64 break; |
| 41 } | 65 } |
| 42 if (!(picth_family & FXFONT_FF_ROMAN) && weight > 400) { | 66 if (iBaseFont < 12) { |
| 43 face = JAPAN_GOTHIC; | 67 return GetFont(face); |
| 44 } else { | 68 } |
| 45 face = JAPAN_MINCHO; | 69 FX_LPVOID p; |
| 46 } | 70 if (m_FontList.Lookup(face, p)) { |
| 47 } | 71 return p; |
| 48 void* CFX_MacFontInfo::MapFont(int weight, FX_BOOL bItalic, int charset, int pit
ch_family, FX_LPCSTR cstr_face, FX_BOOL& bExact) | 72 } |
| 49 { | 73 if (charset == FXFONT_ANSI_CHARSET && (pitch_family & FXFONT_FF_FIXEDPITCH)) { |
| 50 CFX_ByteString face = cstr_face; | 74 return GetFont("Courier New"); |
| 51 int iBaseFont; | 75 } |
| 52 for (iBaseFont = 0; iBaseFont < 12; iBaseFont ++) | 76 if (charset == FXFONT_ANSI_CHARSET || charset == FXFONT_SYMBOL_CHARSET) { |
| 53 if (face == CFX_ByteStringC(Base14Substs[iBaseFont].m_pName)) { | |
| 54 face = Base14Substs[iBaseFont].m_pSubstName; | |
| 55 bExact = TRUE; | |
| 56 break; | |
| 57 } | |
| 58 if (iBaseFont < 12) { | |
| 59 return GetFont(face); | |
| 60 } | |
| 61 FX_LPVOID p; | |
| 62 if (m_FontList.Lookup(face, p)) { | |
| 63 return p; | |
| 64 } | |
| 65 if (charset == FXFONT_ANSI_CHARSET && (pitch_family & FXFONT_FF_FIXEDPITCH))
{ | |
| 66 return GetFont("Courier New"); | |
| 67 } | |
| 68 if (charset == FXFONT_ANSI_CHARSET || charset == FXFONT_SYMBOL_CHARSET) { | |
| 69 return NULL; | |
| 70 } | |
| 71 switch (charset) { | |
| 72 case FXFONT_SHIFTJIS_CHARSET: | |
| 73 GetJapanesePreference(face, weight, pitch_family); | |
| 74 break; | |
| 75 case FXFONT_GB2312_CHARSET: | |
| 76 face = "STSong"; | |
| 77 break; | |
| 78 case FXFONT_HANGEUL_CHARSET: | |
| 79 face = "AppleMyungjo"; | |
| 80 break; | |
| 81 case FXFONT_CHINESEBIG5_CHARSET: | |
| 82 face = "LiSong Pro Light"; | |
| 83 } | |
| 84 if (m_FontList.Lookup(face, p)) { | |
| 85 return p; | |
| 86 } | |
| 87 return NULL; | 77 return NULL; |
| 78 } |
| 79 switch (charset) { |
| 80 case FXFONT_SHIFTJIS_CHARSET: |
| 81 GetJapanesePreference(face, weight, pitch_family); |
| 82 break; |
| 83 case FXFONT_GB2312_CHARSET: |
| 84 face = "STSong"; |
| 85 break; |
| 86 case FXFONT_HANGEUL_CHARSET: |
| 87 face = "AppleMyungjo"; |
| 88 break; |
| 89 case FXFONT_CHINESEBIG5_CHARSET: |
| 90 face = "LiSong Pro Light"; |
| 91 } |
| 92 if (m_FontList.Lookup(face, p)) { |
| 93 return p; |
| 94 } |
| 95 return NULL; |
| 88 } | 96 } |
| 89 #endif | 97 #endif |
| 90 IFX_SystemFontInfo* IFX_SystemFontInfo::CreateDefault() | 98 IFX_SystemFontInfo* IFX_SystemFontInfo::CreateDefault() { |
| 91 { | |
| 92 #if !defined(_FPDFAPI_MINI_) | 99 #if !defined(_FPDFAPI_MINI_) |
| 93 CFX_MacFontInfo* pInfo = FX_NEW CFX_MacFontInfo; | 100 CFX_MacFontInfo* pInfo = FX_NEW CFX_MacFontInfo; |
| 94 if (!pInfo) { | 101 if (!pInfo) { |
| 95 return NULL; | 102 return NULL; |
| 96 } | 103 } |
| 97 pInfo->AddPath("~/Library/Fonts"); | 104 pInfo->AddPath("~/Library/Fonts"); |
| 98 pInfo->AddPath("/Library/Fonts"); | 105 pInfo->AddPath("/Library/Fonts"); |
| 99 pInfo->AddPath("/System/Library/Fonts"); | 106 pInfo->AddPath("/System/Library/Fonts"); |
| 100 return pInfo; | 107 return pInfo; |
| 101 #else | 108 #else |
| 102 return NULL; | 109 return NULL; |
| 103 #endif | 110 #endif |
| 104 } | 111 } |
| 105 void CFX_GEModule::InitPlatform() | 112 void CFX_GEModule::InitPlatform() { |
| 106 { | 113 m_pPlatformData = FX_NEW CApplePlatform; |
| 107 m_pPlatformData = FX_NEW CApplePlatform; | 114 m_pFontMgr->SetSystemFontInfo(IFX_SystemFontInfo::CreateDefault()); |
| 108 m_pFontMgr->SetSystemFontInfo(IFX_SystemFontInfo::CreateDefault()); | |
| 109 } | 115 } |
| 110 void CFX_GEModule::DestroyPlatform() | 116 void CFX_GEModule::DestroyPlatform() { |
| 111 { | 117 if (m_pPlatformData) { |
| 112 if (m_pPlatformData) { | 118 delete (CApplePlatform*)m_pPlatformData; |
| 113 delete (CApplePlatform *) m_pPlatformData; | 119 } |
| 114 } | 120 m_pPlatformData = NULL; |
| 115 m_pPlatformData = NULL; | |
| 116 } | 121 } |
| 117 #endif | 122 #endif |
| OLD | NEW |