Commit c8dfb92a authored by Etienne Bergeron's avatar Etienne Bergeron Committed by Commit Bot

Remove the deprecated class PlatformFontWin

The PlatformFontWin is deprecated and was replaced
by the usage of PlatformFontSkia on Windows.

The feature PlatformFontSkiaOnWindows is activated by default.

This CL is removing the feature and the code.

Bug: 944227
Change-Id: I644321594b4ef6f33e29dfbc36d507d0c695a1ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1924979
Commit-Queue: Etienne Bergeron <etienneb@chromium.org>
Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Cr-Commit-Position: refs/heads/master@{#722503}
parent 0e228573
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#include "base/win/win_util.h" #include "base/win/win_util.h"
#include "base/win/windows_version.h" #include "base/win/windows_version.h"
#include "ui/display/win/dpi.h" #include "ui/display/win/dpi.h"
#include "ui/gfx/platform_font_win.h"
#include "ui/gfx/system_fonts_win.h" #include "ui/gfx/system_fonts_win.h"
#endif #endif
...@@ -161,11 +160,7 @@ TEST_F(LayoutProviderTest, MAYBE_LegacyFontSizeConstants) { ...@@ -161,11 +160,7 @@ TEST_F(LayoutProviderTest, MAYBE_LegacyFontSizeConstants) {
#endif #endif
#if defined(OS_WIN) #if defined(OS_WIN)
if (base::FeatureList::IsEnabled(gfx::kPlatformFontSkiaOnWindows)) { EXPECT_EQ(7, title_font.GetExpectedTextWidth(1));
EXPECT_EQ(7, title_font.GetExpectedTextWidth(1));
} else {
EXPECT_EQ(8, title_font.GetExpectedTextWidth(1));
}
#else #else
EXPECT_EQ(8, title_font.GetExpectedTextWidth(1)); EXPECT_EQ(8, title_font.GetExpectedTextWidth(1));
#endif #endif
......
...@@ -196,8 +196,6 @@ jumbo_component("gfx") { ...@@ -196,8 +196,6 @@ jumbo_component("gfx") {
"font_render_params_win.cc", "font_render_params_win.cc",
"path_win.cc", "path_win.cc",
"path_win.h", "path_win.h",
"platform_font_win.cc",
"platform_font_win.h",
"system_fonts_win.cc", "system_fonts_win.cc",
"system_fonts_win.h", "system_fonts_win.h",
"win/crash_id_helper.cc", "win/crash_id_helper.cc",
...@@ -787,10 +785,7 @@ test("gfx_unittests") { ...@@ -787,10 +785,7 @@ test("gfx_unittests") {
} }
if (is_win) { if (is_win) {
sources += [ sources += [ "system_fonts_win_unittest.cc" ]
"platform_font_win_unittest.cc",
"system_fonts_win_unittest.cc",
]
} }
if (is_linux || is_android || is_fuchsia || is_win) { if (is_linux || is_android || is_fuchsia || is_win) {
......
...@@ -43,11 +43,9 @@ class GFX_EXPORT PlatformFont : public base::RefCounted<PlatformFont> { ...@@ -43,11 +43,9 @@ class GFX_EXPORT PlatformFont : public base::RefCounted<PlatformFont> {
// Creates a PlatformFont instance from the provided SkTypeface, ideally by // Creates a PlatformFont instance from the provided SkTypeface, ideally by
// just wrapping it without triggering a new font match. Implemented for // just wrapping it without triggering a new font match. Implemented for
// PlatformFontWin and PlatformFontSkia, where only the latter provides true // PlatformFontSkia which provides true wrapping of the provided SkTypeface.
// wrapping of the provided SkTypeface, while PlatformFontWin creates a // The FontRenderParams can be provided or they will be determined by using
// PlatformFont object by extracting the family name and falls back to // gfx::GetFontRenderParams(...) otherwise.
// CreateFromNameAndSize(). The FontRenderParams can be provided or they
// will be determined by using gfx::GetFontRenderParams(...) otherwise.
static PlatformFont* CreateFromSkTypeface( static PlatformFont* CreateFromSkTypeface(
sk_sp<SkTypeface> typeface, sk_sp<SkTypeface> typeface,
int font_size, int font_size,
......
...@@ -443,7 +443,6 @@ void PlatformFontSkia::ComputeMetricsIfNecessary() { ...@@ -443,7 +443,6 @@ void PlatformFontSkia::ComputeMetricsIfNecessary() {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// PlatformFont, public: // PlatformFont, public:
#if !defined(OS_WIN)
// static // static
PlatformFont* PlatformFont::CreateDefault() { PlatformFont* PlatformFont::CreateDefault() {
return new PlatformFontSkia; return new PlatformFontSkia;
...@@ -464,6 +463,5 @@ PlatformFont* PlatformFont::CreateFromSkTypeface( ...@@ -464,6 +463,5 @@ PlatformFont* PlatformFont::CreateFromSkTypeface(
TRACE_EVENT0("fonts", "PlatformFont::CreateFromSkTypeface"); TRACE_EVENT0("fonts", "PlatformFont::CreateFromSkTypeface");
return new PlatformFontSkia(typeface, font_size_pixels, params); return new PlatformFontSkia(typeface, font_size_pixels, params);
} }
#endif // !defined(OS_WIN)
} // namespace gfx } // namespace gfx
...@@ -121,6 +121,17 @@ TEST_F(PlatformFontSkiaTest, DefaultFont) { ...@@ -121,6 +121,17 @@ TEST_F(PlatformFontSkiaTest, DefaultFont) {
EXPECT_EQ(gfx::Font::Weight::BOLD, font2->GetWeight()); EXPECT_EQ(gfx::Font::Weight::BOLD, font2->GetWeight());
} }
TEST(PlatformFontSkiaRenderParamsTest, DefaultFontRenderParams) {
scoped_refptr<PlatformFontSkia> default_font(new PlatformFontSkia());
scoped_refptr<PlatformFontSkia> named_font(new PlatformFontSkia(
default_font->GetFontName(), default_font->GetFontSize()));
// Ensures that both constructors are producing fonts with the same render
// params.
EXPECT_EQ(default_font->GetFontRenderParams(),
named_font->GetFontRenderParams());
}
#if defined(OS_WIN) #if defined(OS_WIN)
TEST(PlatformFontSkiaOnWindowsTest, SystemFont) { TEST(PlatformFontSkiaOnWindowsTest, SystemFont) {
// Ensures that the font styles are kept while creating the default font. // Ensures that the font styles are kept while creating the default font.
......
This diff is collapsed.
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_GFX_PLATFORM_FONT_WIN_H_
#define UI_GFX_PLATFORM_FONT_WIN_H_
#include <windows.h>
#include <string>
#include "base/compiler_specific.h"
#include "base/feature_list.h"
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "third_party/skia/include/core/SkTypeface.h"
#include "ui/gfx/gfx_export.h"
#include "ui/gfx/platform_font.h"
struct IDWriteFactory;
struct IDWriteFont;
namespace gfx {
// Deprecation of PlatformFontWin (See http://crbug.com/944227).
extern GFX_EXPORT const base::Feature kPlatformFontSkiaOnWindows;
class GFX_EXPORT PlatformFontWin : public PlatformFont {
public:
PlatformFontWin();
PlatformFontWin(const std::string& font_name, int font_size);
// Wraps the provided SkTypeface without triggering a font rematch.
PlatformFontWin(sk_sp<SkTypeface> typeface,
int font_size_pixels,
const base::Optional<FontRenderParams>& params);
// Dialog units to pixels conversion.
// See http://support.microsoft.com/kb/145994 for details.
int horizontal_dlus_to_pixels(int dlus) const {
return dlus * font_ref_->GetDluBaseX() / 4;
}
int vertical_dlus_to_pixels(int dlus) const {
return dlus * font_ref_->height() / 8;
}
// Returns the font name for the system locale. Some fonts, particularly
// East Asian fonts, have different names per locale. If the localized font
// name could not be retrieved, returns GetFontName().
std::string GetLocalizedFontName() const;
// Overridden from PlatformFont:
Font DeriveFont(int size_delta,
int style,
Font::Weight weight) const override;
int GetHeight() override;
Font::Weight GetWeight() const override;
int GetBaseline() override;
int GetCapHeight() override;
int GetExpectedTextWidth(int length) override;
int GetStyle() const override;
const std::string& GetFontName() const override;
std::string GetActualFontName() const override;
int GetFontSize() const override;
const FontRenderParams& GetFontRenderParams() override;
sk_sp<SkTypeface> GetNativeSkTypefaceIfAvailable() const override;
NativeFont GetNativeFont() const;
// Called once during initialization if we should be retrieving font metrics
// from skia and DirectWrite.
static void SetDirectWriteFactory(IDWriteFactory* factory);
private:
FRIEND_TEST_ALL_PREFIXES(PlatformFontWinTest, Metrics_SkiaVersusGDI);
FRIEND_TEST_ALL_PREFIXES(PlatformFontWinTest, DirectWriteFontSubstitution);
explicit PlatformFontWin(NativeFont native_font);
~PlatformFontWin() override;
// Chrome text drawing bottoms out in the Windows GDI functions that take an
// HFONT (an opaque handle into Windows). To avoid lots of GDI object
// allocation and destruction, Font indirectly refers to the HFONT by way of
// an HFontRef. That is, every Font has an HFontRef, which has an HFONT.
//
// HFontRef is reference counted. Upon deletion, it deletes the HFONT.
// By making HFontRef maintain the reference to the HFONT, multiple
// HFontRefs can share the same HFONT, and Font can provide value semantics.
class GFX_EXPORT HFontRef : public base::RefCounted<HFontRef> {
public:
// This constructor takes control of the HFONT, and will delete it when
// the HFontRef is deleted.
HFontRef(HFONT hfont,
int font_size,
int height,
int baseline,
int cap_height,
int ave_char_width,
Font::Weight weight,
int style);
// Accessors
HFONT hfont() const { return hfont_; }
int height() const { return height_; }
int baseline() const { return baseline_; }
int cap_height() const { return cap_height_; }
int ave_char_width() const { return ave_char_width_; }
Font::Weight weight() const { return weight_; }
int style() const { return style_; }
const std::string& font_name() const { return font_name_; }
int font_size() const { return font_size_; }
int requested_font_size() const { return requested_font_size_; }
// Returns the average character width in dialog units.
int GetDluBaseX();
// Helper to return the average character width using the text extent
// technique mentioned here. http://support.microsoft.com/kb/125681.
static int GetAverageCharWidthInDialogUnits(HFONT gdi_font);
private:
friend class base::RefCounted<HFontRef>;
FRIEND_TEST_ALL_PREFIXES(PlatformFontWinTest, Metrics_SkiaVersusGDI);
FRIEND_TEST_ALL_PREFIXES(PlatformFontWinTest, DirectWriteFontSubstitution);
~HFontRef();
const HFONT hfont_;
const int font_size_;
const int height_;
const int baseline_;
const int cap_height_;
const int ave_char_width_;
const Font::Weight weight_;
const int style_;
// Average character width in dialog units. This is queried lazily from the
// system, with an initial value of -1 meaning it hasn't yet been queried.
int dlu_base_x_;
std::string font_name_;
// If the requested font size is not possible for the font, |font_size_|
// will be different than |requested_font_size_|. This is stored separately
// so that code that increases the font size in a loop will not cause the
// loop to get stuck on the same size.
int requested_font_size_;
DISALLOW_COPY_AND_ASSIGN(HFontRef);
};
// Initializes this object with a copy of the specified HFONT.
void InitWithCopyOfHFONT(HFONT hfont);
// Initializes this object with the specified font name and size.
void InitWithFontNameAndSize(const std::string& font_name,
int font_size);
// Returns the GDI metrics for the font passed in.
static void GetTextMetricsForFont(HDC hdc,
HFONT font,
TEXTMETRIC* text_metrics);
// Returns the base font ref. This should ONLY be invoked on the
// UI thread.
static HFontRef* GetBaseFontRef();
// Creates and returns a new HFontRef from the specified HFONT.
static HFontRef* CreateHFontRef(HFONT font);
// Creates and returns a new HFontRef from the specified HFONT. Uses provided
// |font_metrics| instead of calculating new one.
static HFontRef* CreateHFontRefFromGDI(HFONT font,
const TEXTMETRIC& font_metrics);
// Creates and returns a new HFontRef from the specified HFONT using metrics
// from skia. Currently this is only used if we use DirectWrite for font
// metrics.
// |gdi_font| : Handle to the GDI font created via CreateFontIndirect.
// |font_metrics| : The GDI font metrics retrieved via the GetTextMetrics
// API. This is currently used to calculate the correct height of the font
// in case we get a font created with a positive height.
// A positive height represents the cell height (ascent + descent).
// A negative height represents the character Em height which is cell
// height minus the internal leading value.
static PlatformFontWin::HFontRef* CreateHFontRefFromSkia(
HFONT gdi_font,
const TEXTMETRIC& font_metrics);
// Takes control of a native font (e.g. from CreateFontIndirect()) and wraps
// it in a Font object to manage its lifespan. Note that |hfont| may not be
// valid after the call; use the returned Font object instead.
static Font HFontToFont(HFONT hfont);
// Creates a new PlatformFontWin with the specified HFontRef. Used when
// constructing a Font from a HFONT we don't want to copy.
explicit PlatformFontWin(HFontRef* hfont_ref);
// Reference to the base font all fonts are derived from.
static HFontRef* base_font_ref_;
// Indirect reference to the HFontRef, which references the underlying HFONT.
scoped_refptr<HFontRef> font_ref_;
// An optional typeface when the font is constructed from a typeface.
sk_sp<SkTypeface> typeface_;
DISALLOW_COPY_AND_ASSIGN(PlatformFontWin);
};
// Returns the family name for the |IDWriteFont| interface passed in.
// The family name is returned in the |family_name| parameter.
// Returns S_OK on success.
HRESULT GetFamilyNameFromDirectWriteFont(IDWriteFont* dwrite_font,
base::string16* family_name);
} // namespace gfx
#endif // UI_GFX_PLATFORM_FONT_WIN_H_
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/gfx/platform_font_win.h"
#include <memory.h>
#include <string.h>
#include <windows.h>
#include "base/logging.h"
#include "base/memory/ref_counted.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "base/win/scoped_hdc.h"
#include "base/win/scoped_select_object.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkFontMgr.h"
#include "ui/gfx/font.h"
#include "ui/gfx/font_render_params.h"
#include "ui/gfx/platform_font_skia.h"
#include "ui/gfx/win/scoped_set_map_mode.h"
namespace gfx {
// Test whether font metrics retrieved by DirectWrite (skia) and GDI match as
// per assumptions mentioned below:-
// 1. Font size is the same
// 2. The difference between GDI and DirectWrite for font height, baseline,
// and cap height is at most 1. For smaller font sizes under 12, GDI
// font heights/baselines/cap height are equal/larger by 1 point. For larger
// font sizes DirectWrite font heights/baselines/cap height are equal/larger
// by 1 point.
TEST(PlatformFontWinTest, Metrics_SkiaVersusGDI) {
// Describes the font being tested.
struct FontInfo {
base::string16 font_name;
int font_size;
};
FontInfo fonts[] = {
{base::ASCIIToUTF16("Arial"), 6},
{base::ASCIIToUTF16("Arial"), 8},
{base::ASCIIToUTF16("Arial"), 10},
{base::ASCIIToUTF16("Arial"), 12},
{base::ASCIIToUTF16("Arial"), 16},
{base::ASCIIToUTF16("Symbol"), 6},
{base::ASCIIToUTF16("Symbol"), 10},
{base::ASCIIToUTF16("Symbol"), 12},
{base::ASCIIToUTF16("Tahoma"), 10},
{base::ASCIIToUTF16("Tahoma"), 16},
{base::ASCIIToUTF16("Segoe UI"), 6},
{base::ASCIIToUTF16("Segoe UI"), 8},
{base::ASCIIToUTF16("Segoe UI"), 20},
};
base::win::ScopedGetDC screen_dc(NULL);
gfx::ScopedSetMapMode mode(screen_dc, MM_TEXT);
for (const FontInfo& font : fonts) {
LOGFONT font_info = {0};
font_info.lfHeight = -font.font_size;
font_info.lfWeight = FW_NORMAL;
wcscpy_s(font_info.lfFaceName, font.font_name.length() + 1,
font.font_name.c_str());
HFONT hFont = CreateFontIndirect(&font_info);
TEXTMETRIC font_metrics;
PlatformFontWin::GetTextMetricsForFont(screen_dc, hFont, &font_metrics);
scoped_refptr<PlatformFontWin::HFontRef> h_font_gdi(
PlatformFontWin::CreateHFontRefFromGDI(hFont, font_metrics));
scoped_refptr<PlatformFontWin::HFontRef> h_font_skia(
PlatformFontWin::CreateHFontRefFromSkia(hFont, font_metrics));
EXPECT_EQ(h_font_gdi->font_size(), h_font_skia->font_size());
EXPECT_EQ(h_font_gdi->style(), h_font_skia->style());
EXPECT_EQ(h_font_gdi->font_name(), h_font_skia->font_name());
EXPECT_EQ(h_font_gdi->ave_char_width(), h_font_skia->ave_char_width());
EXPECT_LE(abs(h_font_gdi->cap_height() - h_font_skia->cap_height()), 1);
EXPECT_LE(abs(h_font_gdi->baseline() - h_font_skia->baseline()), 1);
EXPECT_LE(abs(h_font_gdi->height() - h_font_skia->height()), 1);
}
}
// Test if DirectWrite font fallback works correctly, i.e. whether DirectWrite
// fonts handle the font names in the
// HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontSubstitutes key
// correctly. The expectation is that the actual font created should be the
// one specified by the value for the substituted font. For e.g. MS Shell Dlg
// should create Microsoft Sans Serif, etc.
// For random fonts which are not substitutes, DirectWrite should fallback
// to Arial on a properly configured machine.
TEST(PlatformFontWinTest, DirectWriteFontSubstitution) {
// Describes the font being tested.
struct FontInfo {
base::string16 font_name;
std::string expected_font_name;
};
FontInfo fonts[] = {
{base::ASCIIToUTF16("MS Shell Dlg"), "Microsoft Sans Serif"},
{base::ASCIIToUTF16("MS Shell Dlg 2"), "Tahoma"},
{base::ASCIIToUTF16("FooBar"), "Arial"},
};
base::win::ScopedGetDC screen_dc(NULL);
gfx::ScopedSetMapMode mode(screen_dc, MM_TEXT);
for (const FontInfo& font : fonts) {
LOGFONT font_info = {0};
font_info.lfHeight = -10;
font_info.lfWeight = FW_NORMAL;
wcscpy_s(font_info.lfFaceName, font.font_name.length() + 1,
font.font_name.c_str());
HFONT hFont = CreateFontIndirect(&font_info);
TEXTMETRIC font_metrics;
PlatformFontWin::GetTextMetricsForFont(screen_dc, hFont, &font_metrics);
scoped_refptr<PlatformFontWin::HFontRef> h_font_skia(
PlatformFontWin::CreateHFontRefFromSkia(hFont, font_metrics));
EXPECT_EQ(font.expected_font_name, h_font_skia->font_name());
}
}
// TODO(etienneb): Move this test to platform_font_skia_unittest when the
// font migration to skia font is completed.
TEST(PlatformFontWinTest, DefaultFontRenderParams) {
scoped_refptr<PlatformFontSkia> default_font(new PlatformFontSkia());
scoped_refptr<PlatformFontSkia> named_font(new PlatformFontSkia(
default_font->GetFontName(), default_font->GetFontSize()));
// Ensures that both constructors are producing fonts with the same render
// params.
EXPECT_EQ(default_font->GetFontRenderParams(),
named_font->GetFontRenderParams());
}
TEST(PlatformFontWinTest, SkiaTypefaceConstructor) {
gfx::Font default_font;
// The PlatformFontWin constructor doesn't create a skia typeface.
if (!base::FeatureList::IsEnabled(kPlatformFontSkiaOnWindows)) {
EXPECT_EQ(default_font.platform_font()->GetNativeSkTypefaceIfAvailable(),
nullptr);
}
sk_sp<SkFontMgr> font_mgr = SkFontMgr::RefDefault();
sk_sp<SkTypeface> typeface(
font_mgr->matchFamilyStyle("Segoe UI", SkFontStyle()));
ASSERT_TRUE(typeface);
gfx::Font fallback_font(new PlatformFontWin(typeface, 13, base::nullopt));
EXPECT_EQ(fallback_font.platform_font()->GetNativeSkTypefaceIfAvailable(),
typeface);
}
} // 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