Commit 7f6503d9 authored by Sergey Ulanov's avatar Sergey Ulanov Committed by Commit Bot

Reuse Android's gfx::GetFallbackFont() on Fuchsia

Android's implementation of GetFallbackFont() uses SkFontMgr , so it
works on Fuchsia as well. Moved it to a new font_fallback_skia.cc.
Also
1. Replaced font_render_params_fuchsia.cc and
   font_renderer_params_android.cc with font_render_params_skia.cc - the
   two implementations were almost identical.
2. Enabled test_fonts usage in gfx_unittests on Fuchsia.
3. Now all font-related unittests in gfx_unittests pass on Fuchsia.
   Updated test filter file accordingly.
4. Updated platform-specific ifdefs for some RenderText unittests to
   make them pass on Fuchsia.

Bug: 952652, 960389
Change-Id: I6bf14bfea7a1649b2ad795c0594265a6051cd7e3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1602286
Commit-Queue: Sergey Ulanov <sergeyu@chromium.org>
Reviewed-by: default avatarEtienne Bergeron <etienneb@chromium.org>
Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Cr-Commit-Position: refs/heads/master@{#658715}
parent f08481dc
# https://crbug.com/952652 - Fail due to missing fonts.
-FontListTest.FirstAvailableOrFirst
-FontListTest.Fonts_*
-FontTest.LoadArial*
-FontTest.GetActualFontNameForTesting
-PlatformFontSkiaTest.DefaultFont
-RenderTextTest.HarfBuzz_BreakRunsByEmojiVariationSelectors
-RenderTextTest.HarfBuzz_FontListFallback
-RenderTextTest.HarfBuzz_UnicodeFallback
-RenderTextTest.SetFontList
-RenderTextTest.StringSizeBoldWidth
-RenderTextTest.StringSizeRespectsFontListMetrics
-RenderTextTest.StylePropagated
-RenderTextTest.SubpixelRenderingSuppressed
-RenderTextTest.TextDoesntClip
# https://crbug.com/952652 - GpuMemoryBufferHandle Mojo struct traits.
-StructTraitsTest.GpuMemoryBufferHandle
......@@ -69,7 +69,6 @@ jumbo_component("gfx") {
"font.cc",
"font.h",
"font_fallback.h",
"font_fallback_android.cc",
"font_fallback_linux.cc",
"font_fallback_linux.h",
"font_fallback_mac.mm",
......@@ -81,7 +80,6 @@ jumbo_component("gfx") {
"font_list_impl.h",
"font_render_params.cc",
"font_render_params.h",
"font_render_params_android.cc",
"font_render_params_linux.cc",
"font_render_params_mac.cc",
"font_render_params_win.cc",
......@@ -299,6 +297,13 @@ jumbo_component("gfx") {
]
}
if (is_android || is_fuchsia) {
sources += [
"font_fallback_skia.cc",
"font_render_params_skia.cc",
]
}
if (!is_ios) {
sources += [
"bidi_line_iterator.cc",
......@@ -363,13 +368,6 @@ jumbo_component("gfx") {
} else {
sources -= [ "path_x11.cc" ]
}
if (is_fuchsia) {
sources += [
"font_fallback_fuchsia.cc",
"font_render_params_fuchsia.cc",
]
}
}
jumbo_component("color_space") {
......@@ -666,7 +664,6 @@ test("gfx_unittests") {
"color_space_unittest.cc",
"color_transform_unittest.cc",
"color_utils_unittest.cc",
"font_fallback_android_unittest.cc",
"font_fallback_linux_unittest.cc",
"font_fallback_mac_unittest.cc",
"font_list_unittest.cc",
......@@ -758,6 +755,10 @@ test("gfx_unittests") {
deps += [ "//ui/android:ui_java" ]
}
if (is_android || is_fuchsia) {
sources += [ "font_fallback_skia_unittest.cc" ]
}
if (!use_aura && !is_ios) {
sources -= [ "nine_image_painter_unittest.cc" ]
}
......@@ -809,6 +810,10 @@ test("gfx_unittests") {
sources += [ "linux/native_pixmap_dmabuf_unittest.cc" ]
deps += [ "//third_party/fontconfig" ]
}
if (is_fuchsia) {
deps += [ "//skia:test_fonts" ]
}
}
if (is_android) {
......
......@@ -19,7 +19,8 @@ class Font;
// Given a font, returns the fonts that are suitable for fallback.
GFX_EXPORT std::vector<Font> GetFallbackFonts(const Font& font);
#if defined(ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
#if defined(ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) || \
defined(OS_FUCHSIA)
// Finds a fallback font to render the specified |text| with respect to an
// initial |font|. Returns the resulting font via out param |result|. Returns
......@@ -28,7 +29,7 @@ bool GFX_EXPORT GetFallbackFont(const Font& font,
base::StringPiece16 text,
Font* result);
#endif // ANDROID || OS_MACOSX || OS_WIN
#endif // ANDROID || OS_MACOSX || OS_WIN || OS_FUCHSIA
} // namespace gfx
......
// Copyright 2017 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/font_fallback.h"
#include <string>
#include <vector>
namespace gfx {
std::vector<Font> GetFallbackFonts(const Font& font) {
// TODO(fuchsia): Stubbed while bringing up headless build, see
// https://crbug.com/743296.
return std::vector<Font>();
}
} // namespace gfx
......@@ -7,9 +7,9 @@
#include <string>
#include <vector>
#include "base/android/locale_utils.h"
#include "base/strings/utf_string_conversions.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "third_party/icu/source/common/unicode/uchar.h"
#include "third_party/icu/source/common/unicode/uscript.h"
#include "third_party/icu/source/common/unicode/utf16.h"
......@@ -17,6 +17,10 @@
#include "third_party/skia/include/core/SkTypeface.h"
#include "ui/gfx/font.h"
#if defined(OS_ANDROID)
#include "base/android/locale_utils.h"
#endif // defined(OS_ANDROID)
namespace gfx {
std::vector<Font> GetFallbackFonts(const Font& font) {
......@@ -31,8 +35,19 @@ bool GetFallbackFont(const Font& font, base::StringPiece16 text, Font* result) {
sk_sp<SkFontMgr> font_mgr(SkFontMgr::RefDefault());
const char** bcp47_locales = nullptr;
int num_bcp_locals = 0;
// TODO(sergeyu): Specify bcp47 locale on all platforms. Ideally the locale
// should be passed here through gfx::RenderText.
#if defined(OS_ANDROID)
std::string locale = base::android::GetDefaultLocaleString();
const char* bcp47_locales[] = {locale.c_str()};
const char* android_bcp47_locales[] = {locale.c_str()};
if (!locale.empty()) {
bcp47_locales = android_bcp47_locales;
num_bcp_locals = base::size(android_bcp47_locales);
}
#endif // defined(OS_ANDROID)
const int font_weight = (font.GetWeight() == Font::Weight::INVALID)
? static_cast<int>(Font::Weight::NORMAL)
......@@ -52,8 +67,7 @@ bool GetFallbackFont(const Font& font, base::StringPiece16 text, Font* result) {
U16_NEXT(text.data(), offset, text.length(), code_point);
sk_sp<SkTypeface> typeface(font_mgr->matchFamilyStyleCharacter(
font.GetFontName().c_str(), skia_style,
locale.empty() ? nullptr : bcp47_locales, locale.empty() ? 0 : 1,
font.GetFontName().c_str(), skia_style, bcp47_locales, num_bcp_locals,
code_point));
// If the typeface is not found or was already tested, skip it.
if (!typeface || !tested_typeface.insert(typeface->uniqueID()).second)
......
......@@ -14,13 +14,13 @@ namespace {
static const wchar_t* kFallbackFontTests[] = {
L"\u0540\u0541", // Armenian,
L"\u0631\u0632", // Arabic
L"\u0D21\u0D22", // Malayalam
L"\u0915\u093f", // Devanagari
L"\u5203\u5204", // CJK Unified Ideograph
};
} // namespace
TEST(FontFallbackAndroidTest, EmptyStringFallback) {
TEST(FontFallbackSkiaTest, EmptyStringFallback) {
Font base_font;
Font fallback_font;
bool result =
......@@ -28,7 +28,7 @@ TEST(FontFallbackAndroidTest, EmptyStringFallback) {
EXPECT_FALSE(result);
}
TEST(FontFallbackAndroidTest, FontFallback) {
TEST(FontFallbackSkiaTest, FontFallback) {
for (const auto* test : kFallbackFontTests) {
Font base_font;
Font fallback_font;
......
......@@ -22,7 +22,7 @@ Note that we have to support the full range from JellyBean to the latest
dessert.
*/
#if defined(OS_LINUX)
#if defined(OS_LINUX) || defined(OS_FUCHSIA)
const char kTestFontName[] = "Arimo";
#elif defined(OS_ANDROID)
const char kTestFontName[] = "sans-serif";
......@@ -30,7 +30,7 @@ const char kTestFontName[] = "sans-serif";
const char kTestFontName[] = "Arial";
#endif
#if defined(OS_LINUX)
#if defined(OS_LINUX) || defined(OS_FUCHSIA)
const char kSymbolFontName[] = "DejaVu Sans";
#elif defined(OS_ANDROID)
const char kSymbolFontName[] = "monospace";
......@@ -40,7 +40,7 @@ const char kSymbolFontName[] = "Segoe UI Symbol";
const char kSymbolFontName[] = "Symbol";
#endif
#if defined(OS_LINUX)
#if defined(OS_LINUX) || defined(OS_FUCHSIA)
const char kCJKFontName[] = "Noto Sans CJK JP";
#elif defined(OS_ANDROID)
const char kCJKFontName[] = "serif";
......
// Copyright 2017 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/font_render_params.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/no_destructor.h"
namespace gfx {
namespace {
// Returns the system's default settings.
FontRenderParams LoadDefaults() {
FontRenderParams params;
params.antialiasing = true;
params.autohinter = true;
params.use_bitmaps = true;
params.subpixel_rendering = FontRenderParams::SUBPIXEL_RENDERING_NONE;
params.subpixel_positioning = true;
params.hinting = FontRenderParams::HINTING_SLIGHT;
return params;
}
} // namespace
FontRenderParams GetFontRenderParams(const FontRenderParamsQuery& query,
std::string* family_out) {
if (family_out)
NOTIMPLEMENTED();
// Customized font rendering settings are not supported, only defaults.
static const base::NoDestructor<gfx::FontRenderParams> params(LoadDefaults());
return *params;
}
float GetFontRenderParamsDeviceScaleFactor() {
return 1.0;
}
} // namespace gfx
......@@ -1799,7 +1799,8 @@ void RenderTextHarfBuzz::ShapeRuns(
std::string preferred_fallback_family;
#if defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_MACOSX)
#if defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_MACOSX) || \
defined(OS_FUCHSIA)
Font fallback_font(primary_font);
bool fallback_found;
{
......@@ -1820,7 +1821,7 @@ void RenderTextHarfBuzz::ShapeRuns(
if (runs.empty())
return;
}
#endif // OS_ANDROID || OS_WIN || OS_MACOSX
#endif // OS_ANDROID || OS_WIN || OS_MACOSX || OS_FUCHSIA
std::vector<Font> fallback_font_list;
{
......
......@@ -2668,6 +2668,12 @@ TEST_F(RenderTextTest, StringSizeBoldWidth) {
// TODO(mboc): Add some unittests for other weights (currently not
// implemented because of test system font configuration).
RenderText* render_text = GetRenderText();
#if defined(OS_FUCHSIA)
// Increase font size to ensure that bold and regular styles differ in width.
render_text->SetFontList(FontList("Arial, 20px"));
#endif // defined(OS_FUCHSIA)
render_text->SetText(UTF8ToUTF16("Hello World"));
const int plain_width = render_text->GetStringSize().width();
......@@ -4306,8 +4312,6 @@ TEST_F(RenderTextTest, HarfBuzz_UnicodeFallback) {
// Ensure that the fallback fonts offered by GetFallbackFont() support glyphs
// for different languages.
// TODO(https://crbug.com/743296): Implements Fallback fonts on Fuchsia.
#if !defined(OS_FUCHSIA)
TEST_F(RenderTextTest, HarfBuzz_FallbackFontsSupportGlyphs) {
// The word 'test' in different languages.
static const wchar_t* kLanguageTests[] = {
......@@ -4328,13 +4332,9 @@ TEST_F(RenderTextTest, HarfBuzz_FallbackFontsSupportGlyphs) {
}
}
}
#endif // !defined(OS_FUCHSIA)
// Ensure that the fallback fonts offered by GetFallbackFont() support glyphs
// for different languages.
// TODO(https://crbug.com/743296): Implements Fallback fonts on Fuchsia.
#if !defined(OS_FUCHSIA)
TEST_F(RenderTextTest, HarfBuzz_MultiRunsSupportGlyphs) {
static const wchar_t* kLanguageTests[] = {
L"www.اختبار.com",
......@@ -4358,7 +4358,6 @@ TEST_F(RenderTextTest, HarfBuzz_MultiRunsSupportGlyphs) {
}
}
}
#endif // !defined(OS_FUCHSIA)
// Ensure that the width reported by RenderText is sufficient for drawing. Draws
// to a canvas and checks if any pixel beyond the bounding rectangle is colored.
......@@ -4419,39 +4418,23 @@ TEST_F(RenderTextTest, TextDoesntClip) {
}
{
SCOPED_TRACE("TextDoesntClip Left Side");
#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) || \
defined(OS_ANDROID) || defined(ARCH_CPU_MIPS_FAMILY)
// TODO(dschuyler): On Windows, Chrome OS, Linux, Android, and Mac
// smoothing draws to the left of text. This appears to be a preexisting
// issue that wasn't revealed by the prior unit tests. RenderText
// currently only uses origins and advances and ignores bounding boxes so
// cannot account for under- and over-hang.
// TODO(dschuyler): Smoothing draws to the left of text. This appears to
// be a preexisting issue that wasn't revealed by the prior unit tests.
// RenderText currently only uses origins and advances and ignores
// bounding boxes so cannot account for under- and over-hang.
rect_buffer.EnsureSolidRect(SK_ColorWHITE, 0, kTestSize, kTestSize - 1,
string_size.height());
#else
rect_buffer.EnsureSolidRect(SK_ColorWHITE, 0, kTestSize, kTestSize,
string_size.height());
#endif
}
{
SCOPED_TRACE("TextDoesntClip Right Side");
#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) || \
defined(OS_ANDROID) || defined(ARCH_CPU_MIPS_FAMILY)
// TODO(dschuyler): On Windows, Chrome OS, Linux, Android, and Mac
// smoothing draws to the right of text. This appears to be a preexisting
// issue that wasn't revealed by the prior unit tests. RenderText
// currently only uses origins and advances and ignores bounding boxes so
// cannot account for under- and over-hang.
// TODO(dschuyler): Smoothing draws to the right of text. This appears to
// be a preexisting issue that wasn't revealed by the prior unit tests.
// RenderText currently only uses origins and advances and ignores
// bounding boxes so cannot account for under- and over-hang.
rect_buffer.EnsureSolidRect(SK_ColorWHITE,
kTestSize + string_size.width() + 1,
kTestSize, kTestSize - 1,
string_size.height());
#else
rect_buffer.EnsureSolidRect(SK_ColorWHITE,
kTestSize + string_size.width(),
kTestSize, kTestSize,
string_size.height());
#endif
}
}
}
......@@ -4572,7 +4555,7 @@ TEST_F(RenderTextTest, SubpixelRenderingSuppressed) {
render_text->SetText(UTF8ToUTF16("x"));
DrawVisualText();
#if defined(OS_LINUX) || defined(OS_ANDROID)
#if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_FUCHSIA)
// On Linux, whether subpixel AA is supported is determined by the platform
// FontConfig. Force it into a particular style after computing runs. Other
// platforms use a known default FontRenderParams from a static local.
......@@ -4586,7 +4569,7 @@ TEST_F(RenderTextTest, SubpixelRenderingSuppressed) {
render_text->set_subpixel_rendering_suppressed(true);
DrawVisualText();
#if defined(OS_LINUX) || defined(OS_ANDROID)
#if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_FUCHSIA)
// For Linux, runs shouldn't be re-calculated, and the suppression of the
// SUBPIXEL_RENDERING_RGB set above should now take effect. But, after
// checking, apply the override anyway to be explicit that it is suppressed.
......
......@@ -26,6 +26,10 @@
#include "mojo/core/embedder/embedder.h" // nogncheck
#endif
#if defined(OS_FUCHSIA)
#include "skia/ext/test_fonts.h" // nogncheck
#endif
namespace {
class GfxTestSuite : public base::TestSuite {
......@@ -50,6 +54,10 @@ class GfxTestSuite : public base::TestSuite {
#if defined(OS_WIN)
gfx::win::InitializeDirectWrite();
#endif
#if defined(OS_FUCHSIA)
skia::ConfigureTestFont();
#endif
}
void Shutdown() override {
......
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