summaryrefslogtreecommitdiff
path: root/core/src/fxge/win32/fx_win32_device.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-10-05 12:57:17 -0700
committerTom Sepez <tsepez@chromium.org>2015-10-05 12:57:17 -0700
commitd7ba833df5c9dc70cb94dba2d0aae1339b345ae4 (patch)
tree58bcf8ed6c54fbc63a5173593f52fbef2baa4eb0 /core/src/fxge/win32/fx_win32_device.cpp
parentfd12ec5584d9a17f310a2c0c408a438ef3b1ce63 (diff)
downloadpdfium-d7ba833df5c9dc70cb94dba2d0aae1339b345ae4.tar.xz
Original patch by forshaw.
Added a fallback Win32 font information class for win32k lockdown. This is to support running PDFIUM within the Win32k lockdown by removing dependancies on USER32/GDI for the font information code. It falls back to using a freetype/directory enumeration implementation if it detects the win32k system calls have been disabled by policy. BUG=523278 R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1306883002 .
Diffstat (limited to 'core/src/fxge/win32/fx_win32_device.cpp')
-rw-r--r--core/src/fxge/win32/fx_win32_device.cpp51
1 files changed, 50 insertions, 1 deletions
diff --git a/core/src/fxge/win32/fx_win32_device.cpp b/core/src/fxge/win32/fx_win32_device.cpp
index 2db35f7f68..a40e79bde7 100644
--- a/core/src/fxge/win32/fx_win32_device.cpp
+++ b/core/src/fxge/win32/fx_win32_device.cpp
@@ -18,6 +18,15 @@
#include "dwrite_int.h"
#include "win32_int.h"
+class CFX_Win32FallbackFontInfo final : public CFX_FolderFontInfo {
+ public:
+ void* MapFont(int weight,
+ FX_BOOL bItalic,
+ int charset,
+ int pitch_family,
+ const FX_CHAR* family,
+ int& iExact) override;
+};
class CFX_Win32FontInfo final : public IFX_SystemFontInfo {
public:
CFX_Win32FontInfo();
@@ -199,6 +208,29 @@ CFX_ByteString CFX_Win32FontInfo::FindFont(const CFX_ByteString& name) {
}
return CFX_ByteString();
}
+void* CFX_Win32FallbackFontInfo::MapFont(int weight,
+ FX_BOOL bItalic,
+ int charset,
+ int pitch_family,
+ const FX_CHAR* cstr_face,
+ int& iExact) {
+ void* font = GetSubstFont(cstr_face);
+ if (font) {
+ iExact = 1;
+ return font;
+ }
+ FX_BOOL bCJK = TRUE;
+ switch (charset) {
+ case FXFONT_SHIFTJIS_CHARSET:
+ case FXFONT_GB2312_CHARSET:
+ case FXFONT_CHINESEBIG5_CHARSET:
+ case FXFONT_HANGEUL_CHARSET:
+ default:
+ bCJK = FALSE;
+ break;
+ }
+ return FindFont(weight, bItalic, charset, pitch_family, cstr_face, !bCJK);
+}
struct _FontNameMap {
const FX_CHAR* m_pSubFontName;
const FX_CHAR* m_pSrcFontName;
@@ -406,7 +438,24 @@ FX_BOOL CFX_Win32FontInfo::GetFontCharset(void* hFont, int& charset) {
return TRUE;
}
IFX_SystemFontInfo* IFX_SystemFontInfo::CreateDefault(const char** pUnused) {
- return new CFX_Win32FontInfo;
+ HDC hdc = ::GetDC(NULL);
+ if (hdc) {
+ ::ReleaseDC(NULL, hdc);
+ return new CFX_Win32FontInfo;
+ }
+ // If GDI is disabled then GetDC for the desktop will fail. Select the
+ // fallback font information class if GDI is disabled.
+ CFX_Win32FallbackFontInfo* pInfoFallback = new CFX_Win32FallbackFontInfo;
+ // Construct the font path manually, SHGetKnownFolderPath won't work under
+ // a restrictive sandbox.
+ CHAR windows_path[MAX_PATH] = {};
+ DWORD path_len = ::GetWindowsDirectoryA(windows_path, MAX_PATH);
+ if (path_len > 0 && path_len < MAX_PATH) {
+ CFX_ByteString fonts_path(windows_path);
+ fonts_path += "\\Fonts";
+ pInfoFallback->AddPath(fonts_path);
+ }
+ return pInfoFallback;
}
void CFX_GEModule::InitPlatform() {
CWin32Platform* pPlatformData = new CWin32Platform;