• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "core/include/fxge/fx_ge.h"
8 #include "apple_int.h"
9 
10 #if _FX_OS_ == _FX_MACOSX_
11 static const struct {
12   const FX_CHAR* m_pName;
13   const FX_CHAR* m_pSubstName;
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  public:
30   virtual void* MapFont(int weight,
31                         FX_BOOL bItalic,
32                         int charset,
33                         int pitch_family,
34                         const FX_CHAR* family,
35                         int& iExact);
36 };
37 #define JAPAN_GOTHIC "Hiragino Kaku Gothic Pro W6"
38 #define JAPAN_MINCHO "Hiragino Mincho Pro W6"
GetJapanesePreference(CFX_ByteString & face,int weight,int picth_family)39 static void GetJapanesePreference(CFX_ByteString& face,
40                                   int weight,
41                                   int picth_family) {
42   if (face.Find("Gothic") >= 0) {
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 }
MapFont(int weight,FX_BOOL bItalic,int charset,int pitch_family,const FX_CHAR * cstr_face,int & iExact)52 void* CFX_MacFontInfo::MapFont(int weight,
53                                FX_BOOL bItalic,
54                                int charset,
55                                int pitch_family,
56                                const FX_CHAR* cstr_face,
57                                int& iExact) {
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       iExact = TRUE;
64       break;
65     }
66   if (iBaseFont < 12) {
67     return GetFont(face);
68   }
69   auto it = m_FontList.find(face);
70   if (it != m_FontList.end())
71     return it->second;
72 
73   if (charset == FXFONT_ANSI_CHARSET && (pitch_family & FXFONT_FF_FIXEDPITCH)) {
74     return GetFont("Courier New");
75   }
76   if (charset == FXFONT_ANSI_CHARSET || charset == FXFONT_SYMBOL_CHARSET) {
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   it = m_FontList.find(face);
93   if (it != m_FontList.end())
94     return it->second;
95 
96   return NULL;
97 }
CreateDefault(const char ** pUnused)98 IFX_SystemFontInfo* IFX_SystemFontInfo::CreateDefault(const char** pUnused) {
99   CFX_MacFontInfo* pInfo = new CFX_MacFontInfo;
100   pInfo->AddPath("~/Library/Fonts");
101   pInfo->AddPath("/Library/Fonts");
102   pInfo->AddPath("/System/Library/Fonts");
103   return pInfo;
104 }
InitPlatform()105 void CFX_GEModule::InitPlatform() {
106   m_pPlatformData = new CApplePlatform;
107   m_pFontMgr->SetSystemFontInfo(IFX_SystemFontInfo::CreateDefault(nullptr));
108 }
DestroyPlatform()109 void CFX_GEModule::DestroyPlatform() {
110   delete (CApplePlatform*)m_pPlatformData;
111   m_pPlatformData = NULL;
112 }
113 #endif
114