#include "chrome/child/pdf_child_init.h"
#include "build/build_config.h"
#if BUILDFLAG(IS_WIN)
#include "base/command_line.h"
#include "base/no_destructor.h"
#include "base/win/current_module.h"
#include "base/win/iat_patch_function.h"
#include "base/win/windows_version.h"
#include "content/public/child/child_thread.h"
#include "content/public/common/content_switches.h"
#include "sandbox/policy/mojom/sandbox.mojom.h"
#include "sandbox/policy/sandbox_type.h"
#include "sandbox/policy/switches.h"
#endif
namespace {
#if BUILDFLAG(IS_WIN)
typedef decltype(::GetFontData)* GetFontDataPtr;
GetFontDataPtr g_original_get_font_data = nullptr;
DWORD WINAPI GetFontDataPatch(HDC hdc,
DWORD table,
DWORD offset,
LPVOID buffer,
DWORD length) {
DWORD rv = g_original_get_font_data(hdc, table, offset, buffer, length);
if (rv == GDI_ERROR && hdc) {
HFONT font = static_cast<HFONT>(GetCurrentObject(hdc, OBJ_FONT));
LOGFONT logfont;
if (GetObject(font, sizeof(LOGFONT), &logfont)) {
if (content::ChildThread::Get())
content::ChildThread::Get()->PreCacheFont(logfont);
rv = g_original_get_font_data(hdc, table, offset, buffer, length);
if (content::ChildThread::Get())
content::ChildThread::Get()->ReleaseCachedFonts();
}
}
return rv;
}
#endif
}
void MaybePatchGdiGetFontData() { … }