1 // Copyright 2013 The Chromium 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 #include "content/shell/app/blink_test_platform_support.h"
12 #include "base/command_line.h"
13 #include "base/files/file_path.h"
14 #include "base/files/file_util.h"
15 #include "base/logging.h"
16 #include "base/path_service.h"
17 #include "base/strings/utf_string_conversions.h"
18 #include "content/shell/common/shell_switches.h"
19 #include "ui/gfx/win/direct_write.h"
21 #define SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(struct_name, member) \
22 offsetof(struct_name, member) + \
23 (sizeof static_cast<struct_name*>(0)->member)
24 #define NONCLIENTMETRICS_SIZE_PRE_VISTA \
25 SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(NONCLIENTMETRICS, lfMessageFont)
33 // AHEM____.TTF is copied to the directory of DumpRenderTree.exe by
35 base::FilePath base_path
;
36 PathService::Get(base::DIR_MODULE
, &base_path
);
37 base::FilePath font_path
=
38 base_path
.Append(FILE_PATH_LITERAL("/AHEM____.TTF"));
40 // We do one of two registrations:
41 // 1. For GDI font rendering via ::AddFontMemResourceEx.
42 // 2. For DirectWrite rendering by appending a command line flag that tells
43 // the sandbox policy/warmup to grant access to the given path.
44 if (gfx::win::ShouldUseDirectWrite()) {
45 // DirectWrite sandbox registration.
46 base::CommandLine
& command_line
= *base::CommandLine::ForCurrentProcess();
47 command_line
.AppendSwitchASCII(switches::kRegisterFontFiles
,
48 base::WideToUTF8(font_path
.value()));
51 std::string font_buffer
;
52 if (!base::ReadFileToString(font_path
, &font_buffer
)) {
53 std::cerr
<< "Failed to load font " << base::WideToUTF8(font_path
.value())
60 ::AddFontMemResourceEx(const_cast<char*>(font_buffer
.c_str()),
65 std::cerr
<< "Failed to register Ahem font\n";
75 bool CheckLayoutSystemDeps() {
76 std::list
<std::string
> errors
;
78 // This metric will be 17 when font size is "Normal".
79 // The size of drop-down menus depends on it.
80 if (::GetSystemMetrics(SM_CXVSCROLL
) != 17)
81 errors
.push_back("Must use normal size fonts (96 dpi).");
83 // Check that we're using the default system fonts.
84 OSVERSIONINFO version_info
= {0};
85 version_info
.dwOSVersionInfoSize
= sizeof(version_info
);
86 ::GetVersionEx(&version_info
);
87 bool is_vista_or_later
= (version_info
.dwMajorVersion
>= 6);
88 NONCLIENTMETRICS metrics
= {0};
89 metrics
.cbSize
= is_vista_or_later
? sizeof(NONCLIENTMETRICS
)
90 : NONCLIENTMETRICS_SIZE_PRE_VISTA
;
91 bool success
= !!::SystemParametersInfo(
92 SPI_GETNONCLIENTMETRICS
, metrics
.cbSize
, &metrics
, 0);
94 LOGFONTW
* system_fonts
[] =
95 {&metrics
.lfStatusFont
, &metrics
.lfMenuFont
, &metrics
.lfSmCaptionFont
};
96 const wchar_t* required_font
= is_vista_or_later
? L
"Segoe UI" : L
"Tahoma";
97 int required_font_size
= is_vista_or_later
? -12 : -11;
98 for (size_t i
= 0; i
< arraysize(system_fonts
); ++i
) {
99 if (system_fonts
[i
]->lfHeight
!= required_font_size
||
100 wcscmp(required_font
, system_fonts
[i
]->lfFaceName
)) {
101 errors
.push_back(is_vista_or_later
102 ? "Must use either the Aero or Basic theme."
103 : "Must use the default XP theme (Luna).");
108 for (std::list
<std::string
>::iterator it
= errors
.begin(); it
!= errors
.end();
110 std::cerr
<< *it
<< "\n";
112 return errors
.empty();
115 bool BlinkTestPlatformInitialize() {
119 } // namespace content