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_
10 static const struct {
11     FX_LPCSTR	m_pName;
12     FX_LPCSTR	m_pSubstName;
13 }
14 Base14Substs[] = {
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 class CFX_MacFontInfo : public CFX_FolderFontInfo
29 {
30 public:
31     virtual void*		MapFont(int weight, FX_BOOL bItalic, int charset, int pitch_family, FX_LPCSTR family, FX_BOOL& bExact);
32 };
33 #define JAPAN_GOTHIC "Hiragino Kaku Gothic Pro W6"
34 #define JAPAN_MINCHO "Hiragino Mincho Pro W6"
GetJapanesePreference(CFX_ByteString & face,int weight,int picth_family)35 static void GetJapanesePreference(CFX_ByteString& face, int weight, int picth_family)
36 {
37     if (face.Find("Gothic") >= 0) {
38         face = JAPAN_GOTHIC;
39         return;
40     }
41     if (!(picth_family & FXFONT_FF_ROMAN) && weight > 400) {
42         face = JAPAN_GOTHIC;
43     } else {
44         face = JAPAN_MINCHO;
45     }
46 }
MapFont(int weight,FX_BOOL bItalic,int charset,int pitch_family,FX_LPCSTR cstr_face,FX_BOOL & bExact)47 void* CFX_MacFontInfo::MapFont(int weight, FX_BOOL bItalic, int charset, int pitch_family, FX_LPCSTR cstr_face, FX_BOOL& bExact)
48 {
49     CFX_ByteString face = cstr_face;
50     int iBaseFont;
51     for (iBaseFont = 0; iBaseFont < 12; iBaseFont ++)
52         if (face == CFX_ByteStringC(Base14Substs[iBaseFont].m_pName)) {
53             face = Base14Substs[iBaseFont].m_pSubstName;
54             bExact = TRUE;
55             break;
56         }
57     if (iBaseFont < 12) {
58         return GetFont(face);
59     }
60     FX_LPVOID p;
61     if (m_FontList.Lookup(face, p)) {
62         return p;
63     }
64     if (charset == FXFONT_ANSI_CHARSET && (pitch_family & FXFONT_FF_FIXEDPITCH)) {
65         return GetFont("Courier New");
66     }
67     if (charset == FXFONT_ANSI_CHARSET || charset == FXFONT_SYMBOL_CHARSET) {
68         return NULL;
69     }
70     switch (charset) {
71         case FXFONT_SHIFTJIS_CHARSET:
72             GetJapanesePreference(face, weight, pitch_family);
73             break;
74         case FXFONT_GB2312_CHARSET:
75             face = "STSong";
76             break;
77         case FXFONT_HANGEUL_CHARSET:
78             face = "AppleMyungjo";
79             break;
80         case FXFONT_CHINESEBIG5_CHARSET:
81             face = "LiSong Pro Light";
82     }
83     if (m_FontList.Lookup(face, p)) {
84         return p;
85     }
86     return NULL;
87 }
CreateDefault()88 IFX_SystemFontInfo* IFX_SystemFontInfo::CreateDefault()
89 {
90     CFX_MacFontInfo* pInfo = new CFX_MacFontInfo;
91     pInfo->AddPath("~/Library/Fonts");
92     pInfo->AddPath("/Library/Fonts");
93     pInfo->AddPath("/System/Library/Fonts");
94     return pInfo;
95 }
InitPlatform()96 void CFX_GEModule::InitPlatform()
97 {
98     m_pPlatformData = new CApplePlatform;
99     m_pFontMgr->SetSystemFontInfo(IFX_SystemFontInfo::CreateDefault());
100 }
DestroyPlatform()101 void CFX_GEModule::DestroyPlatform()
102 {
103     if (m_pPlatformData) {
104         delete (CApplePlatform *) m_pPlatformData;
105     }
106     m_pPlatformData = NULL;
107 }
108 #endif
109