Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Side by Side Diff: core/src/fxge/ge/fx_ge_linux.cpp

Issue 1306883002: Added a fallback Win32 font information class for win32k lockdown. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Fixed linux font regressions. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/src/fxge/ge/fx_ge_fontmap.cpp ('k') | core/src/fxge/win32/fx_win32_device.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "../agg/include/fx_agg_driver.h" 8 #include "../agg/include/fx_agg_driver.h"
9 #include "text_int.h" 9 #include "text_int.h"
10 10
11 #if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ 11 #if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_
12 static const struct {
13 const FX_CHAR* m_pName;
14 const FX_CHAR* m_pSubstName;
15 } Base14Substs[] = {
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"},
28 };
29 class CFX_LinuxFontInfo : public CFX_FolderFontInfo { 12 class CFX_LinuxFontInfo : public CFX_FolderFontInfo {
30 public: 13 public:
31 void* MapFont(int weight, 14 void* MapFont(int weight,
32 FX_BOOL bItalic, 15 FX_BOOL bItalic,
33 int charset, 16 int charset,
34 int pitch_family, 17 int pitch_family,
35 const FX_CHAR* family, 18 const FX_CHAR* family,
36 int& iExact) override; 19 int& iExact) override;
37 FX_BOOL ParseFontCfg(const char** pUserPaths); 20 FX_BOOL ParseFontCfg(const char** pUserPaths);
38 void* FindFont(int weight,
39 FX_BOOL bItalic,
40 int charset,
41 int pitch_family,
42 const FX_CHAR* family,
43 FX_BOOL bMatchName);
44 }; 21 };
45 #define LINUX_GPNAMESIZE 6 22 #define LINUX_GPNAMESIZE 6
46 static const struct { 23 static const struct {
47 const FX_CHAR* NameArr[LINUX_GPNAMESIZE]; 24 const FX_CHAR* NameArr[LINUX_GPNAMESIZE];
48 } LinuxGpFontList[] = { 25 } LinuxGpFontList[] = {
49 {{"TakaoPGothic", "VL PGothic", "IPAPGothic", "VL Gothic", "Kochi Gothic", 26 {{"TakaoPGothic", "VL PGothic", "IPAPGothic", "VL Gothic", "Kochi Gothic",
50 "VL Gothic regular"}}, 27 "VL Gothic regular"}},
51 {{"TakaoGothic", "VL Gothic", "IPAGothic", "Kochi Gothic", NULL, 28 {{"TakaoGothic", "VL Gothic", "IPAGothic", "Kochi Gothic", NULL,
52 "VL Gothic regular"}}, 29 "VL Gothic regular"}},
53 {{"TakaoPMincho", "IPAPMincho", "VL Gothic", "Kochi Mincho", NULL, 30 {{"TakaoPMincho", "IPAPMincho", "VL Gothic", "Kochi Mincho", NULL,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 return 0; 64 return 0;
88 } 65 }
89 return 2; 66 return 2;
90 } 67 }
91 void* CFX_LinuxFontInfo::MapFont(int weight, 68 void* CFX_LinuxFontInfo::MapFont(int weight,
92 FX_BOOL bItalic, 69 FX_BOOL bItalic,
93 int charset, 70 int charset,
94 int pitch_family, 71 int pitch_family,
95 const FX_CHAR* cstr_face, 72 const FX_CHAR* cstr_face,
96 int& iExact) { 73 int& iExact) {
97 CFX_ByteString face = cstr_face; 74 void* font = GetSubstFont(cstr_face);
98 int iBaseFont; 75 if (font) {
99 for (iBaseFont = 0; iBaseFont < 12; iBaseFont++) 76 iExact = 1;
100 if (face == CFX_ByteStringC(Base14Substs[iBaseFont].m_pName)) { 77 return font;
101 face = Base14Substs[iBaseFont].m_pSubstName;
102 iExact = 1;
103 break;
104 }
105 if (iBaseFont < 12) {
106 return GetFont(face);
107 } 78 }
108 FX_BOOL bCJK = TRUE; 79 FX_BOOL bCJK = TRUE;
109 switch (charset) { 80 switch (charset) {
110 case FXFONT_SHIFTJIS_CHARSET: { 81 case FXFONT_SHIFTJIS_CHARSET: {
111 int32_t index = GetJapanesePreference(cstr_face, weight, pitch_family); 82 int32_t index = GetJapanesePreference(cstr_face, weight, pitch_family);
112 if (index < 0) { 83 if (index < 0) {
113 break; 84 break;
114 } 85 }
115 for (int32_t i = 0; i < LINUX_GPNAMESIZE; i++) { 86 for (int32_t i = 0; i < LINUX_GPNAMESIZE; i++) {
116 auto it = m_FontList.find(LinuxGpFontList[index].NameArr[i]); 87 auto it = m_FontList.find(LinuxGpFontList[index].NameArr[i]);
(...skipping 23 matching lines...) Expand all
140 auto it = m_FontList.find(g_LinuxHGFontList[i]); 111 auto it = m_FontList.find(g_LinuxHGFontList[i]);
141 if (it != m_FontList.end()) { 112 if (it != m_FontList.end()) {
142 return it->second; 113 return it->second;
143 } 114 }
144 } 115 }
145 } break; 116 } break;
146 default: 117 default:
147 bCJK = FALSE; 118 bCJK = FALSE;
148 break; 119 break;
149 } 120 }
150 if (charset == FXFONT_ANSI_CHARSET && (pitch_family & FXFONT_FF_FIXEDPITCH)) {
151 return GetFont("Courier New");
152 }
153 return FindFont(weight, bItalic, charset, pitch_family, cstr_face, !bCJK); 121 return FindFont(weight, bItalic, charset, pitch_family, cstr_face, !bCJK);
154 } 122 }
155 static FX_DWORD _LinuxGetCharset(int charset) {
156 switch (charset) {
157 case FXFONT_SHIFTJIS_CHARSET:
158 return CHARSET_FLAG_SHIFTJIS;
159 case FXFONT_GB2312_CHARSET:
160 return CHARSET_FLAG_GB;
161 case FXFONT_CHINESEBIG5_CHARSET:
162 return CHARSET_FLAG_BIG5;
163 case FXFONT_HANGEUL_CHARSET:
164 return CHARSET_FLAG_KOREAN;
165 case FXFONT_SYMBOL_CHARSET:
166 return CHARSET_FLAG_SYMBOL;
167 case FXFONT_ANSI_CHARSET:
168 return CHARSET_FLAG_ANSI;
169 default:
170 break;
171 }
172 return 0;
173 }
174 static int32_t _LinuxGetSimilarValue(int weight,
175 FX_BOOL bItalic,
176 int pitch_family,
177 FX_DWORD style) {
178 int32_t iSimilarValue = 0;
179 if ((style & FXFONT_BOLD) == (weight > 400)) {
180 iSimilarValue += 16;
181 }
182 if ((style & FXFONT_ITALIC) == bItalic) {
183 iSimilarValue += 16;
184 }
185 if ((style & FXFONT_SERIF) == (pitch_family & FXFONT_FF_ROMAN)) {
186 iSimilarValue += 16;
187 }
188 if ((style & FXFONT_SCRIPT) == (pitch_family & FXFONT_FF_SCRIPT)) {
189 iSimilarValue += 8;
190 }
191 if ((style & FXFONT_FIXED_PITCH) == (pitch_family & FXFONT_FF_FIXEDPITCH)) {
192 iSimilarValue += 8;
193 }
194 return iSimilarValue;
195 }
196 void* CFX_LinuxFontInfo::FindFont(int weight,
197 FX_BOOL bItalic,
198 int charset,
199 int pitch_family,
200 const FX_CHAR* family,
201 FX_BOOL bMatchName) {
202 CFX_FontFaceInfo* pFind = NULL;
203 FX_DWORD charset_flag = _LinuxGetCharset(charset);
204 int32_t iBestSimilar = 0;
205 for (const auto& it : m_FontList) {
206 const CFX_ByteString& bsName = it.first;
207 CFX_FontFaceInfo* pFont = it.second;
208 if (!(pFont->m_Charsets & charset_flag) &&
209 charset != FXFONT_DEFAULT_CHARSET) {
210 continue;
211 }
212 int32_t iSimilarValue = 0;
213 int32_t index = bsName.Find(family);
214 if (bMatchName && index < 0) {
215 continue;
216 }
217 if (!bMatchName && index > 0) {
218 iSimilarValue += 64;
219 }
220 iSimilarValue =
221 _LinuxGetSimilarValue(weight, bItalic, pitch_family, pFont->m_Styles);
222 if (iSimilarValue > iBestSimilar) {
223 iBestSimilar = iSimilarValue;
224 pFind = pFont;
225 }
226 }
227 return pFind;
228 }
229 IFX_SystemFontInfo* IFX_SystemFontInfo::CreateDefault(const char** pUserPaths) { 123 IFX_SystemFontInfo* IFX_SystemFontInfo::CreateDefault(const char** pUserPaths) {
230 CFX_LinuxFontInfo* pInfo = new CFX_LinuxFontInfo; 124 CFX_LinuxFontInfo* pInfo = new CFX_LinuxFontInfo;
231 if (!pInfo->ParseFontCfg(pUserPaths)) { 125 if (!pInfo->ParseFontCfg(pUserPaths)) {
232 pInfo->AddPath("/usr/share/fonts"); 126 pInfo->AddPath("/usr/share/fonts");
233 pInfo->AddPath("/usr/share/X11/fonts/Type1"); 127 pInfo->AddPath("/usr/share/X11/fonts/Type1");
234 pInfo->AddPath("/usr/share/X11/fonts/TTF"); 128 pInfo->AddPath("/usr/share/X11/fonts/TTF");
235 pInfo->AddPath("/usr/local/share/fonts"); 129 pInfo->AddPath("/usr/local/share/fonts");
236 } 130 }
237 return pInfo; 131 return pInfo;
238 } 132 }
239 FX_BOOL CFX_LinuxFontInfo::ParseFontCfg(const char** pUserPaths) { 133 FX_BOOL CFX_LinuxFontInfo::ParseFontCfg(const char** pUserPaths) {
240 if (!pUserPaths) { 134 if (!pUserPaths) {
241 return FALSE; 135 return FALSE;
242 } 136 }
243 for (const char** pPath = pUserPaths; *pPath; ++pPath) { 137 for (const char** pPath = pUserPaths; *pPath; ++pPath) {
244 AddPath(*pPath); 138 AddPath(*pPath);
245 } 139 }
246 return TRUE; 140 return TRUE;
247 } 141 }
248 void CFX_GEModule::InitPlatform() { 142 void CFX_GEModule::InitPlatform() {
249 m_pFontMgr->SetSystemFontInfo( 143 m_pFontMgr->SetSystemFontInfo(
250 IFX_SystemFontInfo::CreateDefault(m_pUserFontPaths)); 144 IFX_SystemFontInfo::CreateDefault(m_pUserFontPaths));
251 } 145 }
252 void CFX_GEModule::DestroyPlatform() {} 146 void CFX_GEModule::DestroyPlatform() {}
253 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ 147 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_
OLDNEW
« no previous file with comments | « core/src/fxge/ge/fx_ge_fontmap.cpp ('k') | core/src/fxge/win32/fx_win32_device.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698