Commit 08a619e0 authored by Etienne Bergeron's avatar Etienne Bergeron Committed by Commit Bot

Use system font as the default font

This CL is using the user configured font as the default font.

The users in the experiment "PlatformFontSkiaOnWindows" are using the
default skia font. The current default font while using the
PlatformFontSkia is "sans", which is mapped to the default Segeo UI
font.

Some users may change the default font and chrome should use the
configured font.

R=robliao@chromium.org, asvitkine@chromium.org

Bug: 944227, 989476
Change-Id: I3f7c6b91103f9b58388a08b212fd6484344a0079
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1733429
Commit-Queue: Etienne Bergeron <etienneb@chromium.org>
Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683830}
parent 6f134e30
...@@ -744,7 +744,7 @@ test("gfx_unittests") { ...@@ -744,7 +744,7 @@ test("gfx_unittests") {
data += [ "$root_out_dir/ui_test.pak" ] data += [ "$root_out_dir/ui_test.pak" ]
} }
if (is_linux || is_android || is_fuchsia) { if (is_linux || is_android || is_fuchsia || is_win) {
sources += [ "platform_font_skia_unittest.cc" ] sources += [ "platform_font_skia_unittest.cc" ]
} }
......
...@@ -123,6 +123,18 @@ bool PlatformFontSkia::InitDefaultFont() { ...@@ -123,6 +123,18 @@ bool PlatformFontSkia::InitDefaultFont() {
Font::Weight weight = Font::Weight::NORMAL; Font::Weight weight = Font::Weight::NORMAL;
FontRenderParams params; FontRenderParams params;
#if defined(OS_WIN)
// On windows, the system default font is retrieved by using the GDI API
// SystemParametersInfo(...) (see struct NONCLIENTMETRICS). The font
// properties need to be converted as close as possible to a skia font.
// The style must be kept (see http://crbug/989476).
gfx::Font system_font = win::GetDefaultSystemFont();
family = system_font.GetFontName();
size_pixels = system_font.GetFontSize();
style = system_font.GetStyle();
weight = system_font.GetWeight();
#endif // OS_WIN
// On Linux, SkiaFontDelegate is used to query the native toolkit (e.g. // On Linux, SkiaFontDelegate is used to query the native toolkit (e.g.
// GTK+) for the default UI font. // GTK+) for the default UI font.
const SkiaFontDelegate* delegate = SkiaFontDelegate::instance(); const SkiaFontDelegate* delegate = SkiaFontDelegate::instance();
......
...@@ -15,6 +15,10 @@ ...@@ -15,6 +15,10 @@
#include "ui/gfx/font_render_params.h" #include "ui/gfx/font_render_params.h"
#include "ui/gfx/skia_font_delegate.h" #include "ui/gfx/skia_font_delegate.h"
#if defined(OS_WIN)
#include "ui/gfx/system_fonts_win.h"
#endif
namespace gfx { namespace gfx {
// Implementation of SkiaFontDelegate used to control the default font // Implementation of SkiaFontDelegate used to control the default font
...@@ -117,4 +121,22 @@ TEST_F(PlatformFontSkiaTest, DefaultFont) { ...@@ -117,4 +121,22 @@ TEST_F(PlatformFontSkiaTest, DefaultFont) {
EXPECT_EQ(gfx::Font::Weight::BOLD, font2->GetWeight()); EXPECT_EQ(gfx::Font::Weight::BOLD, font2->GetWeight());
} }
#if defined(OS_WIN)
TEST(PlatformFontSkiaOnWindowsTest, SystemFont) {
// Ensures that the font styles are kept while creating the default font.
gfx::Font system_font = win::GetDefaultSystemFont();
gfx::Font default_font;
EXPECT_EQ(system_font.GetFontName(), default_font.GetFontName());
EXPECT_EQ(system_font.GetFontSize(), default_font.GetFontSize());
EXPECT_EQ(system_font.GetStyle(), default_font.GetStyle());
EXPECT_EQ(system_font.GetWeight(), default_font.GetWeight());
EXPECT_EQ(system_font.GetHeight(), default_font.GetHeight());
EXPECT_EQ(system_font.GetBaseline(), default_font.GetBaseline());
EXPECT_EQ(system_font.GetBaseline(), default_font.GetBaseline());
EXPECT_EQ(system_font.GetFontRenderParams(),
default_font.GetFontRenderParams());
}
#endif // OS_WIN
} // namespace gfx } // namespace gfx
...@@ -250,6 +250,13 @@ void SetAdjustFontCallback(AdjustFontCallback callback) { ...@@ -250,6 +250,13 @@ void SetAdjustFontCallback(AdjustFontCallback callback) {
SystemFonts::SetAdjustFontCallback(callback); SystemFonts::SetAdjustFontCallback(callback);
} }
const Font& GetDefaultSystemFont() {
// The message font is the closest font for a default system font from the
// structure NONCLIENTMETRICS. The lfMessageFont field contains information
// about the logical font used to display text in message boxes.
return GetSystemFont(SystemFont::kMessage);
}
const Font& GetSystemFont(SystemFont system_font) { const Font& GetSystemFont(SystemFont system_font) {
return SystemFonts::Instance()->GetFont(system_font); return SystemFonts::Instance()->GetFont(system_font);
} }
......
...@@ -34,6 +34,10 @@ GFX_EXPORT void SetGetMinimumFontSizeCallback( ...@@ -34,6 +34,10 @@ GFX_EXPORT void SetGetMinimumFontSizeCallback(
typedef void (*AdjustFontCallback)(FontAdjustment* font_adjustment); typedef void (*AdjustFontCallback)(FontAdjustment* font_adjustment);
GFX_EXPORT void SetAdjustFontCallback(AdjustFontCallback callback); GFX_EXPORT void SetAdjustFontCallback(AdjustFontCallback callback);
// Returns the specified Windows default system font. By default, this is the
// font used for message boxes (see struct NONCLIENTMETRICS).
GFX_EXPORT const Font& GetDefaultSystemFont();
// Returns the specified Windows system font, suitable for drawing on screen // Returns the specified Windows system font, suitable for drawing on screen
// elements. // elements.
GFX_EXPORT const Font& GetSystemFont(SystemFont system_font); GFX_EXPORT const Font& GetSystemFont(SystemFont system_font);
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <windows.h> #include <windows.h>
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -162,5 +163,10 @@ TEST_F(SystemFontsWinTest, GetFontFromLOGFONT_WithStyle) { ...@@ -162,5 +163,10 @@ TEST_F(SystemFontsWinTest, GetFontFromLOGFONT_WithStyle) {
EXPECT_EQ(font.GetWeight(), Font::Weight::BOLD); EXPECT_EQ(font.GetWeight(), Font::Weight::BOLD);
} }
TEST_F(SystemFontsWinTest, GetDefaultSystemFont) {
Font system_font = GetDefaultSystemFont();
EXPECT_EQ(base::WideToUTF8(kSegoeUI), system_font.GetFontName());
}
} // namespace win } // namespace win
} // namespace gfx } // namespace gfx
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment