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

Side by Side Diff: core/src/fxge/win32/fx_win32_device.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_linux.cpp ('k') | no next file » | 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 8
9 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_DESKTOP_ 9 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_DESKTOP_
10 #include <crtdbg.h> 10 #include <crtdbg.h>
11 11
12 #include "../../../include/fxcodec/fx_codec.h" 12 #include "../../../include/fxcodec/fx_codec.h"
13 #include "../../../include/fxge/fx_freetype.h" 13 #include "../../../include/fxge/fx_freetype.h"
14 #include "../../../include/fxge/fx_ge_win32.h" 14 #include "../../../include/fxge/fx_ge_win32.h"
15 #include "../agg/include/fx_agg_driver.h" 15 #include "../agg/include/fx_agg_driver.h"
16 #include "../dib/dib_int.h" 16 #include "../dib/dib_int.h"
17 #include "../ge/text_int.h" 17 #include "../ge/text_int.h"
18 #include "dwrite_int.h" 18 #include "dwrite_int.h"
19 #include "win32_int.h" 19 #include "win32_int.h"
20 20
21 class CFX_Win32FallbackFontInfo final : public CFX_FolderFontInfo {
22 public:
23 void* MapFont(int weight,
24 FX_BOOL bItalic,
25 int charset,
26 int pitch_family,
27 const FX_CHAR* family,
28 int& iExact) override;
29 };
21 class CFX_Win32FontInfo final : public IFX_SystemFontInfo { 30 class CFX_Win32FontInfo final : public IFX_SystemFontInfo {
22 public: 31 public:
23 CFX_Win32FontInfo(); 32 CFX_Win32FontInfo();
24 ~CFX_Win32FontInfo() override; 33 ~CFX_Win32FontInfo() override;
25 34
26 // IFX_SystemFontInfo 35 // IFX_SystemFontInfo
27 void Release() override; 36 void Release() override;
28 FX_BOOL EnumFontList(CFX_FontMapper* pMapper) override; 37 FX_BOOL EnumFontList(CFX_FontMapper* pMapper) override;
29 void* MapFont(int weight, 38 void* MapFont(int weight,
30 FX_BOOL bItalic, 39 FX_BOOL bItalic,
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 if (thisname[0] == ' ') { 201 if (thisname[0] == ' ') {
193 if (thisname.Mid(1, name.GetLength()) == name) { 202 if (thisname.Mid(1, name.GetLength()) == name) {
194 return m_pMapper->m_InstalledTTFonts[i + 1]; 203 return m_pMapper->m_InstalledTTFonts[i + 1];
195 } 204 }
196 } else if (thisname.Left(name.GetLength()) == name) { 205 } else if (thisname.Left(name.GetLength()) == name) {
197 return m_pMapper->m_InstalledTTFonts[i]; 206 return m_pMapper->m_InstalledTTFonts[i];
198 } 207 }
199 } 208 }
200 return CFX_ByteString(); 209 return CFX_ByteString();
201 } 210 }
211 void* CFX_Win32FallbackFontInfo::MapFont(int weight,
212 FX_BOOL bItalic,
213 int charset,
214 int pitch_family,
215 const FX_CHAR* cstr_face,
216 int& iExact) {
217 void* font = GetSubstFont(cstr_face);
218 if (font) {
219 iExact = 1;
220 return font;
221 }
222 FX_BOOL bCJK = TRUE;
223 switch (charset) {
224 case FXFONT_SHIFTJIS_CHARSET:
225 case FXFONT_GB2312_CHARSET:
226 case FXFONT_CHINESEBIG5_CHARSET:
227 case FXFONT_HANGEUL_CHARSET:
228 default:
229 bCJK = FALSE;
230 break;
231 }
232 return FindFont(weight, bItalic, charset, pitch_family, cstr_face, !bCJK);
233 }
202 struct _FontNameMap { 234 struct _FontNameMap {
203 const FX_CHAR* m_pSubFontName; 235 const FX_CHAR* m_pSubFontName;
204 const FX_CHAR* m_pSrcFontName; 236 const FX_CHAR* m_pSrcFontName;
205 }; 237 };
206 const _FontNameMap g_JpFontNameMap[] = { 238 const _FontNameMap g_JpFontNameMap[] = {
207 {"MS Mincho", "Heiseimin-W3"}, 239 {"MS Mincho", "Heiseimin-W3"},
208 {"MS Gothic", "Jun101-Light"}, 240 {"MS Gothic", "Jun101-Light"},
209 }; 241 };
210 extern "C" { 242 extern "C" {
211 static int compareString(const void* key, const void* element) { 243 static int compareString(const void* key, const void* element) {
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 } 431 }
400 FX_BOOL CFX_Win32FontInfo::GetFontCharset(void* hFont, int& charset) { 432 FX_BOOL CFX_Win32FontInfo::GetFontCharset(void* hFont, int& charset) {
401 TEXTMETRIC tm; 433 TEXTMETRIC tm;
402 HFONT hOldFont = (HFONT)::SelectObject(m_hDC, (HFONT)hFont); 434 HFONT hOldFont = (HFONT)::SelectObject(m_hDC, (HFONT)hFont);
403 ::GetTextMetrics(m_hDC, &tm); 435 ::GetTextMetrics(m_hDC, &tm);
404 ::SelectObject(m_hDC, hOldFont); 436 ::SelectObject(m_hDC, hOldFont);
405 charset = tm.tmCharSet; 437 charset = tm.tmCharSet;
406 return TRUE; 438 return TRUE;
407 } 439 }
408 IFX_SystemFontInfo* IFX_SystemFontInfo::CreateDefault(const char** pUnused) { 440 IFX_SystemFontInfo* IFX_SystemFontInfo::CreateDefault(const char** pUnused) {
409 return new CFX_Win32FontInfo; 441 HDC hdc = ::GetDC(NULL);
442 if (hdc) {
443 ::ReleaseDC(NULL, hdc);
444 return new CFX_Win32FontInfo;
445 }
446 // If GDI is disabled then GetDC for the desktop will fail. Select the
447 // fallback font information class if GDI is disabled.
448 CFX_Win32FallbackFontInfo* pInfoFallback = new CFX_Win32FallbackFontInfo;
449 // Construct the font path manually, SHGetKnownFolderPath won't work under
450 // a restrictive sandbox.
451 CHAR windows_path[MAX_PATH] = {};
452 DWORD path_len = ::GetWindowsDirectoryA(windows_path, MAX_PATH);
453 if (path_len > 0 && path_len < MAX_PATH) {
454 CFX_ByteString fonts_path(windows_path);
455 fonts_path += "\\Fonts";
456 pInfoFallback->AddPath(fonts_path);
457 }
458 return pInfoFallback;
410 } 459 }
411 void CFX_GEModule::InitPlatform() { 460 void CFX_GEModule::InitPlatform() {
412 CWin32Platform* pPlatformData = new CWin32Platform; 461 CWin32Platform* pPlatformData = new CWin32Platform;
413 OSVERSIONINFO ver; 462 OSVERSIONINFO ver;
414 ver.dwOSVersionInfoSize = sizeof(ver); 463 ver.dwOSVersionInfoSize = sizeof(ver);
415 GetVersionEx(&ver); 464 GetVersionEx(&ver);
416 pPlatformData->m_bHalfTone = ver.dwMajorVersion >= 5; 465 pPlatformData->m_bHalfTone = ver.dwMajorVersion >= 5;
417 pPlatformData->m_GdiplusExt.Load(); 466 pPlatformData->m_GdiplusExt.Load();
418 m_pPlatformData = pPlatformData; 467 m_pPlatformData = pPlatformData;
419 m_pFontMgr->SetSystemFontInfo(IFX_SystemFontInfo::CreateDefault(nullptr)); 468 m_pFontMgr->SetSystemFontInfo(IFX_SystemFontInfo::CreateDefault(nullptr));
(...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after
1309 SelectObject(m_hDC, m_hOldBitmap); 1358 SelectObject(m_hDC, m_hOldBitmap);
1310 DeleteDC(m_hDC); 1359 DeleteDC(m_hDC);
1311 } 1360 }
1312 if (m_hBitmap) { 1361 if (m_hBitmap) {
1313 DeleteObject(m_hBitmap); 1362 DeleteObject(m_hBitmap);
1314 } 1363 }
1315 delete GetBitmap(); 1364 delete GetBitmap();
1316 } 1365 }
1317 1366
1318 #endif // _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_ 1367 #endif // _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_
OLDNEW
« no previous file with comments | « core/src/fxge/ge/fx_ge_linux.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698