1// Copyright 2014 PDFium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7#include "../../../include/fxge/fx_ge.h" 8#include "apple_int.h" 9#if _FX_OS_ == _FX_MACOSX_ 10static const struct { 11 FX_LPCSTR m_pName; 12 FX_LPCSTR m_pSubstName; 13} 14Base14Substs[] = { 15 {"Courier", "Courier New"}, 16 {"Courier-Bold", "Courier New Bold"}, 17 {"Courier-BoldOblique", "Courier New Bold Italic"}, 18 {"Courier-Oblique", "Courier New Italic"}, 19 {"Helvetica", "Arial"}, 20 {"Helvetica-Bold", "Arial Bold"}, 21 {"Helvetica-BoldOblique", "Arial Bold Italic"}, 22 {"Helvetica-Oblique", "Arial Italic"}, 23 {"Times-Roman", "Times New Roman"}, 24 {"Times-Bold", "Times New Roman Bold"}, 25 {"Times-BoldItalic", "Times New Roman Bold Italic"}, 26 {"Times-Italic", "Times New Roman Italic"}, 27}; 28#if !defined(_FPDFAPI_MINI_) 29class CFX_MacFontInfo : public CFX_FolderFontInfo 30{ 31public: 32 virtual void* MapFont(int weight, FX_BOOL bItalic, int charset, int pitch_family, FX_LPCSTR family, FX_BOOL& bExact); 33}; 34#define JAPAN_GOTHIC "Hiragino Kaku Gothic Pro W6" 35#define JAPAN_MINCHO "Hiragino Mincho Pro W6" 36static void GetJapanesePreference(CFX_ByteString& face, int weight, int picth_family) 37{ 38 if (face.Find("Gothic") >= 0) { 39 face = JAPAN_GOTHIC; 40 return; 41 } 42 if (!(picth_family & FXFONT_FF_ROMAN) && weight > 400) { 43 face = JAPAN_GOTHIC; 44 } else { 45 face = JAPAN_MINCHO; 46 } 47} 48void* CFX_MacFontInfo::MapFont(int weight, FX_BOOL bItalic, int charset, int pitch_family, FX_LPCSTR cstr_face, FX_BOOL& bExact) 49{ 50 CFX_ByteString face = cstr_face; 51 int iBaseFont; 52 for (iBaseFont = 0; iBaseFont < 12; iBaseFont ++) 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; 88} 89#endif 90IFX_SystemFontInfo* IFX_SystemFontInfo::CreateDefault() 91{ 92#if !defined(_FPDFAPI_MINI_) 93 CFX_MacFontInfo* pInfo = FX_NEW CFX_MacFontInfo; 94 if (!pInfo) { 95 return NULL; 96 } 97 pInfo->AddPath("~/Library/Fonts"); 98 pInfo->AddPath("/Library/Fonts"); 99 pInfo->AddPath("/System/Library/Fonts"); 100 return pInfo; 101#else 102 return NULL; 103#endif 104} 105void CFX_GEModule::InitPlatform() 106{ 107 m_pPlatformData = FX_NEW CApplePlatform; 108 m_pFontMgr->SetSystemFontInfo(IFX_SystemFontInfo::CreateDefault()); 109} 110void CFX_GEModule::DestroyPlatform() 111{ 112 if (m_pPlatformData) { 113 delete (CApplePlatform *) m_pPlatformData; 114 } 115 m_pPlatformData = NULL; 116} 117#endif 118