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

Use the font typeface when available instead of rematch

The font fallback is returning a specific typeface. The
specific typeface should be used when available to avoid
a font family match (which may leads to a different font
being used).

As an example, on Fuchsia the script Bengali is using the
'Mukti Narrow' which is not getting match correctly. That
makes the script being broken. We are not seeing a
regression since the expensive fallbacks algorithm is
catching the broken cases.

see:
  https://chromium-review.googlesource.com/c/chromium/src/+/1824104
  http://crbug.com/1003829

Bug: 1008407, 1018321
Change-Id: I668382707e24ecc267a82531ad2a77c23283b2b3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1884657Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Commit-Queue: Etienne Bergeron <etienneb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710065}
parent 7e518f33
...@@ -124,11 +124,8 @@ class GFX_EXPORT Font { ...@@ -124,11 +124,8 @@ class GFX_EXPORT Font {
NativeFont GetNativeFont() const; NativeFont GetNativeFont() const;
#endif #endif
#if defined(OS_WIN) // Raw access to the underlying platform font implementation.
// Raw access to the underlying platform font implementation. Can be
// static_cast to a known implementation type if needed.
PlatformFont* platform_font() const { return platform_font_.get(); } PlatformFont* platform_font() const { return platform_font_.get(); }
#endif
private: private:
// Wrapped platform font implementation. // Wrapped platform font implementation.
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "third_party/icu/source/common/unicode/uscript.h" #include "third_party/icu/source/common/unicode/uscript.h"
#include "third_party/icu/source/common/unicode/utf16.h" #include "third_party/icu/source/common/unicode/utf16.h"
#include "third_party/skia/include/core/SkTypeface.h" #include "third_party/skia/include/core/SkTypeface.h"
#include "ui/gfx/platform_font.h"
#include "ui/gfx/test/font_fallback_test_data.h" #include "ui/gfx/test/font_fallback_test_data.h"
#if defined(OS_WIN) #if defined(OS_WIN)
...@@ -105,7 +106,12 @@ class GetFallbackFontTest ...@@ -105,7 +106,12 @@ class GetFallbackFontTest
bool DoesFontSupportCodePoints(Font font, const base::string16& text) { bool DoesFontSupportCodePoints(Font font, const base::string16& text) {
sk_sp<SkTypeface> skia_face = sk_sp<SkTypeface> skia_face =
SkTypeface::MakeFromName(font.GetFontName().c_str(), SkFontStyle()); font.platform_font()->GetNativeSkTypefaceIfAvailable();
if (!skia_face) {
// Performs a family match when the typeface is not available.
skia_face =
SkTypeface::MakeFromName(font.GetFontName().c_str(), SkFontStyle());
}
size_t i = 0; size_t i = 0;
const SkGlyphID kUnsupportedGlyph = 0; const SkGlyphID kUnsupportedGlyph = 0;
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include "ui/gfx/font_render_params.h" #include "ui/gfx/font_render_params.h"
#include "ui/gfx/geometry/safe_integer_conversions.h" #include "ui/gfx/geometry/safe_integer_conversions.h"
#include "ui/gfx/harfbuzz_font_skia.h" #include "ui/gfx/harfbuzz_font_skia.h"
#include "ui/gfx/platform_font.h"
#include "ui/gfx/range/range_f.h" #include "ui/gfx/range/range_f.h"
#include "ui/gfx/skia_util.h" #include "ui/gfx/skia_util.h"
#include "ui/gfx/switches.h" #include "ui/gfx/switches.h"
...@@ -54,10 +55,6 @@ ...@@ -54,10 +55,6 @@
#include "base/android/locale_utils.h" #include "base/android/locale_utils.h"
#endif // defined(OS_ANDROID) #endif // defined(OS_ANDROID)
#if defined(OS_WIN)
#include "ui/gfx/platform_font.h"
#endif
#include <hb.h> #include <hb.h>
namespace gfx { namespace gfx {
...@@ -828,15 +825,9 @@ bool TextRunHarfBuzz::FontParams::SetRenderParamsRematchFont( ...@@ -828,15 +825,9 @@ bool TextRunHarfBuzz::FontParams::SetRenderParamsRematchFont(
bool TextRunHarfBuzz::FontParams::SetRenderParamsOverrideSkiaFaceFromFont( bool TextRunHarfBuzz::FontParams::SetRenderParamsOverrideSkiaFaceFromFont(
const Font& fallback_font, const Font& fallback_font,
const FontRenderParams& new_render_params) { const FontRenderParams& new_render_params) {
sk_sp<SkTypeface> new_skia_face;
#if defined(OS_WIN)
// TODO(https://crbug.com/1008407): Extend this to additional platforms that
// use PlatformFontSkia.
PlatformFont* platform_font = fallback_font.platform_font(); PlatformFont* platform_font = fallback_font.platform_font();
if (platform_font) { sk_sp<SkTypeface> new_skia_face =
new_skia_face = platform_font->GetNativeSkTypefaceIfAvailable(); platform_font->GetNativeSkTypefaceIfAvailable();
}
#endif
// If pass-through of the Skia native handle fails for PlatformFonts other // If pass-through of the Skia native handle fails for PlatformFonts other
// than PlatformFontSkia, perform rematching. // than PlatformFontSkia, perform rematching.
......
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