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.
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
7 #include "../../../include/fxge/fx_ge.h"
8 #include "../agg/include/fx_agg_driver.h"
10 #if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_
13 FX_LPCSTR m_pSubstName;
16 {"Courier", "Courier New"},
17 {"Courier-Bold", "Courier New Bold"},
18 {"Courier-BoldOblique", "Courier New Bold Italic"},
19 {"Courier-Oblique", "Courier New Italic"},
20 {"Helvetica", "Arial"},
21 {"Helvetica-Bold", "Arial Bold"},
22 {"Helvetica-BoldOblique", "Arial Bold Italic"},
23 {"Helvetica-Oblique", "Arial Italic"},
24 {"Times-Roman", "Times New Roman"},
25 {"Times-Bold", "Times New Roman Bold"},
26 {"Times-BoldItalic", "Times New Roman Bold Italic"},
27 {"Times-Italic", "Times New Roman Italic"},
29 class CFX_LinuxFontInfo : public CFX_FolderFontInfo
32 virtual void* MapFont(int weight, FX_BOOL bItalic, int charset, int pitch_family, FX_LPCSTR family, FX_BOOL& bExact);
33 FX_BOOL ParseFontCfg();
34 void* FindFont(int weight, FX_BOOL bItalic, int charset, int pitch_family, FX_LPCSTR family, FX_BOOL bMatchName);
36 #define LINUX_GPNAMESIZE 6
38 FX_LPCSTR NameArr[LINUX_GPNAMESIZE];
41 {{"TakaoPGothic", "VL PGothic", "IPAPGothic", "VL Gothic", "Kochi Gothic", "VL Gothic regular"}},
42 {{"TakaoGothic", "VL Gothic", "IPAGothic", "Kochi Gothic", NULL, "VL Gothic regular"}},
43 {{"TakaoPMincho", "IPAPMincho", "VL Gothic", "Kochi Mincho", NULL, "VL Gothic regular"}},
44 {{"TakaoMincho", "IPAMincho", "VL Gothic", "Kochi Mincho", NULL, "VL Gothic regular"}},
46 static const FX_LPCSTR g_LinuxGbFontList[] = {
47 "AR PL UMing CN Light",
48 "WenQuanYi Micro Hei",
51 static const FX_LPCSTR g_LinuxB5FontList[] = {
52 "AR PL UMing TW Light",
53 "WenQuanYi Micro Hei",
56 static const FX_LPCSTR g_LinuxHGFontList[] = {
59 static int32_t GetJapanesePreference(FX_LPCSTR facearr, int weight, int picth_family)
61 CFX_ByteString face = facearr;
62 if (face.Find("Gothic") >= 0 || face.Find("\x83\x53\x83\x56\x83\x62\x83\x4e") >= 0) {
63 if (face.Find("PGothic") >= 0 || face.Find("\x82\x6f\x83\x53\x83\x56\x83\x62\x83\x4e") >= 0) {
68 } else if (face.Find("Mincho") >= 0 || face.Find("\x96\xbe\x92\xa9") >= 0) {
69 if (face.Find("PMincho") >= 0 || face.Find("\x82\x6f\x96\xbe\x92\xa9") >= 0) {
75 if (!(picth_family & FXFONT_FF_ROMAN) && weight > 400) {
80 void* CFX_LinuxFontInfo::MapFont(int weight, FX_BOOL bItalic, int charset, int pitch_family, FX_LPCSTR cstr_face, FX_BOOL& bExact)
82 CFX_ByteString face = cstr_face;
84 for (iBaseFont = 0; iBaseFont < 12; iBaseFont ++)
85 if (face == CFX_ByteStringC(Base14Substs[iBaseFont].m_pName)) {
86 face = Base14Substs[iBaseFont].m_pSubstName;
96 case FXFONT_SHIFTJIS_CHARSET: {
97 int32_t index = GetJapanesePreference(cstr_face, weight, pitch_family);
101 for (int32_t i = 0; i < LINUX_GPNAMESIZE; i++)
102 if (m_FontList.Lookup(LinuxGpFontList[index].NameArr[i], p)) {
107 case FXFONT_GB2312_CHARSET: {
108 static int32_t s_gbCount = sizeof(g_LinuxGbFontList) / sizeof(FX_LPCSTR);
109 for (int32_t i = 0; i < s_gbCount; i++)
110 if (m_FontList.Lookup(g_LinuxGbFontList[i], p)) {
115 case FXFONT_CHINESEBIG5_CHARSET: {
116 static int32_t s_b5Count = sizeof(g_LinuxB5FontList) / sizeof(FX_LPCSTR);
117 for (int32_t i = 0; i < s_b5Count; i++)
118 if (m_FontList.Lookup(g_LinuxB5FontList[i], p)) {
123 case FXFONT_HANGEUL_CHARSET: {
124 static int32_t s_hgCount = sizeof(g_LinuxHGFontList) / sizeof(FX_LPCSTR);
125 for (int32_t i = 0; i < s_hgCount; i++)
126 if (m_FontList.Lookup(g_LinuxHGFontList[i], p)) {
135 if (charset == FXFONT_ANSI_CHARSET && (pitch_family & FXFONT_FF_FIXEDPITCH)) {
136 return GetFont("Courier New");
138 return FindFont(weight, bItalic, charset, pitch_family, cstr_face, !bCJK);
140 static FX_DWORD _LinuxGetCharset(int charset)
143 case FXFONT_SHIFTJIS_CHARSET:
144 return CHARSET_FLAG_SHIFTJIS;
145 case FXFONT_GB2312_CHARSET:
146 return CHARSET_FLAG_GB;
147 case FXFONT_CHINESEBIG5_CHARSET:
148 return CHARSET_FLAG_BIG5;
149 case FXFONT_HANGEUL_CHARSET:
150 return CHARSET_FLAG_KOREAN;
151 case FXFONT_SYMBOL_CHARSET:
152 return CHARSET_FLAG_SYMBOL;
153 case FXFONT_ANSI_CHARSET:
154 return CHARSET_FLAG_ANSI;
160 static int32_t _LinuxGetSimilarValue(int weight, FX_BOOL bItalic, int pitch_family, FX_DWORD style)
162 int32_t iSimilarValue = 0;
163 if ((style & FXFONT_BOLD) == (weight > 400)) {
166 if ((style & FXFONT_ITALIC) == bItalic) {
169 if ((style & FXFONT_SERIF) == (pitch_family & FXFONT_FF_ROMAN)) {
172 if ((style & FXFONT_SCRIPT) == (pitch_family & FXFONT_FF_SCRIPT)) {
175 if ((style & FXFONT_FIXED_PITCH) == (pitch_family & FXFONT_FF_FIXEDPITCH)) {
178 return iSimilarValue;
180 void* CFX_LinuxFontInfo::FindFont(int weight, FX_BOOL bItalic, int charset, int pitch_family, FX_LPCSTR family, FX_BOOL bMatchName)
182 CFontFaceInfo* pFind = NULL;
183 FX_DWORD charset_flag = _LinuxGetCharset(charset);
184 int32_t iBestSimilar = 0;
185 FX_POSITION pos = m_FontList.GetStartPosition();
187 CFX_ByteString bsName;
188 CFontFaceInfo* pFont = NULL;
189 m_FontList.GetNextAssoc(pos, bsName, (FX_LPVOID&)pFont);
190 if (!(pFont->m_Charsets & charset_flag) && charset != FXFONT_DEFAULT_CHARSET) {
193 int32_t iSimilarValue = 0;
194 int32_t index = bsName.Find(family);
195 if (bMatchName && index < 0) {
198 if (!bMatchName && index > 0) {
201 iSimilarValue = _LinuxGetSimilarValue(weight, bItalic, pitch_family, pFont->m_Styles);
202 if (iSimilarValue > iBestSimilar) {
203 iBestSimilar = iSimilarValue;
209 IFX_SystemFontInfo* IFX_SystemFontInfo::CreateDefault()
211 CFX_LinuxFontInfo* pInfo = new CFX_LinuxFontInfo;
212 if (!pInfo->ParseFontCfg()) {
213 pInfo->AddPath("/usr/share/fonts");
214 pInfo->AddPath("/usr/share/X11/fonts/Type1");
215 pInfo->AddPath("/usr/share/X11/fonts/TTF");
216 pInfo->AddPath("/usr/local/share/fonts");
220 FX_BOOL CFX_LinuxFontInfo::ParseFontCfg()
224 void CFX_GEModule::InitPlatform()
226 m_pFontMgr->SetSystemFontInfo(IFX_SystemFontInfo::CreateDefault());
228 void CFX_GEModule::DestroyPlatform()