Commit fc5a7c58 authored by Dominik Röttsches's avatar Dominik Röttsches Committed by Commit Bot

Use DWrite backend for variable fonts when possible

In order to avoid rendering inconsistencies between static and variable
fonts on Windows, run variable fonts through Skia's DWrite backend when
the system's DWrite version supports it.

As the test, use a default typeface to probe and ask for the variation
axis parameters of the current instance. If Skia return -1, it means, it
was unable to access the API for retrieving variations axes
information. If that's the case, we need to use FreeType, otherwise use
DWrite.

While we do not have bot coverage for Windows 10 RS3 ourselves, Skia
does test DWrite variable font support, so I believe it's okay to land
that, our own bot coverage is tracked in issue 953520.

Bug: 953447
Change-Id: I9684f92004531d6bafef33aefafa3894e4c46203
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1569947Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Commit-Queue: Dominik Röttsches <drott@chromium.org>
Cr-Commit-Position: refs/heads/master@{#651797}
parent b3fed158
......@@ -757,6 +757,8 @@ jumbo_component("platform") {
"fonts/web_font_render_style.cc",
"fonts/web_font_typeface_factory.cc",
"fonts/web_font_typeface_factory.h",
"fonts/win/dwrite_font_format_support.cc",
"fonts/win/dwrite_font_format_support.h",
"fonts/win/font_cache_skia_win.cc",
"fonts/win/font_fallback_win.cc",
"fonts/win/font_fallback_win.h",
......
......@@ -13,6 +13,7 @@
#if defined(OS_WIN)
#include "third_party/blink/public/common/dwrite_rasterizer_support/dwrite_rasterizer_support.h"
#include "third_party/blink/renderer/platform/fonts/win/dwrite_font_format_support.h"
#endif
#if defined(OS_WIN) || defined(OS_MACOSX)
......@@ -92,6 +93,8 @@ bool WebFontTypefaceFactory::CreateTypeface(sk_sp<SkData> sk_data,
sk_sp<SkFontMgr> WebFontTypefaceFactory::FontManagerForVariations() {
#if defined(OS_WIN)
if (DWriteVersionSupportsVariations())
return DefaultFontManager();
return FreeTypeFontManager();
#else
#if defined(OS_MACOSX)
......
// Copyright 2019 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 "third_party/blink/renderer/platform/fonts/win/dwrite_font_format_support.h"
#include "third_party/skia/include/core/SkFontMgr.h"
#include "third_party/skia/include/core/SkFontStyle.h"
#include "third_party/skia/include/core/SkTypeface.h"
namespace blink {
bool DWriteVersionSupportsVariations() {
// We're instantiating a default typeface. The usage of legacyMakeTypeface()
// is intentional here to access a basic default font. Its implementation will
// ultimately use the first font face from the first family in the system font
// collection. Use this probe type face to ask Skia for the variation design
// position. Internally, Skia then tests whether the DWrite interfaces for
// accessing variable font information are available, in other words, if
// QueryInterface for IDWriteFontFace5 succeeds. If it doesn't it returns -1
// and we know DWrite on this system does not support OpenType variations. If
// the response is 0 or larger, it means, DWrite was able to determine if this
// is a variable font or not and Variations are supported.
static bool variations_supported = []() {
auto fm(SkFontMgr::RefDefault());
sk_sp<SkTypeface> probe_typeface =
fm->legacyMakeTypeface(nullptr, SkFontStyle());
int variation_design_position_result =
probe_typeface->getVariationDesignPosition(nullptr, 0);
return variation_design_position_result > -1;
}();
return variations_supported;
}
} // namespace blink
// Copyright 2019 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 THIRD_PARTY_BLINK_RENDERER_PLATFORM_FONTS_WIN_DWRITE_FONT_FORMAT_SUPPORT_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_FONTS_WIN_DWRITE_FONT_FORMAT_SUPPORT_H_
namespace blink {
// Return whether DirectWrite on this system supports variable fonts for
// retrieving metrics and performing rasterization.
bool DWriteVersionSupportsVariations();
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_FONTS_WIN_DWRITE_FONT_FORMAT_SUPPORT_H_
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