Commit 72e5a15d authored by Etienne Bergeron's avatar Etienne Bergeron Committed by Commit Bot

Rename GetNativeSkTypefaceIfAvailable and support it on each platform

Since Skia is used for rendering in the BrowserTest, a font should
be backed by a SkTypeface. That was not the case previously since
the class RenderTextMac was still used.

RenderTextMac got removed here:
  https://chromium-review.googlesource.com/c/chromium/src/+/1902193

Bug: 1026735
Change-Id: I23a3c4b6b0d5a36304e81e0251dc0e55f6836f54
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2028213
Commit-Queue: Etienne Bergeron <etienneb@chromium.org>
Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738239}
parent ad4973e2
......@@ -114,16 +114,10 @@ class GetFallbackFontTest
}
bool DoesFontSupportCodePoints(Font font, const base::string16& text) {
sk_sp<SkTypeface> skia_face =
font.platform_font()->GetNativeSkTypefaceIfAvailable();
sk_sp<SkTypeface> skia_face = font.platform_font()->GetNativeSkTypeface();
if (!skia_face) {
skia_face =
SkTypeface::MakeFromName(font.GetFontName().c_str(), SkFontStyle());
}
if (!skia_face) {
LOG(ERROR) << "Cannot create typeface for '" << font.GetFontName()
<< "'.";
ADD_FAILURE() << "Cannot create typeface for '" << font.GetFontName()
<< "'.";
return false;
}
......
......@@ -101,12 +101,10 @@ class GFX_EXPORT PlatformFont : public base::RefCounted<PlatformFont> {
virtual NativeFont GetNativeFont() const = 0;
#endif
// Returns the underlying Skia typeface if this PlatformFont instance is
// backed by PlatformFontSkia, returns nullptr otherwise. Used in
// RenderTextHarfBuzz for having access to the exact Skia typeface returned by
// font fallback, as we would otherwise lose the handle to the correct
// platform font instance.
virtual sk_sp<SkTypeface> GetNativeSkTypefaceIfAvailable() const = 0;
// Returns the underlying Skia typeface. Used in RenderTextHarfBuzz for having
// access to the exact Skia typeface returned by font fallback, as we would
// otherwise lose the handle to the correct platform font instance.
virtual sk_sp<SkTypeface> GetNativeSkTypeface() const = 0;
protected:
virtual ~PlatformFont() {}
......
......@@ -32,7 +32,7 @@ class PlatformFontIOS : public PlatformFont {
int GetFontSize() const override;
const FontRenderParams& GetFontRenderParams() override;
NativeFont GetNativeFont() const override;
sk_sp<SkTypeface> GetNativeSkTypefaceIfAvailable() const override;
sk_sp<SkTypeface> GetNativeSkTypeface() const override;
private:
PlatformFontIOS(const std::string& font_name,
......
......@@ -8,8 +8,10 @@
#include <cmath>
#import "base/mac/foundation_util.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "third_party/skia/include/ports/SkTypeface_mac.h"
#include "ui/gfx/font.h"
#include "ui/gfx/font_render_params.h"
#include "ui/gfx/ios/NSString+CrStringDrawing.h"
......@@ -96,8 +98,8 @@ NativeFont PlatformFontIOS::GetNativeFont() const {
size:font_size_];
}
sk_sp<SkTypeface> PlatformFontIOS::GetNativeSkTypefaceIfAvailable() const {
return nullptr;
sk_sp<SkTypeface> PlatformFontIOS::GetNativeSkTypeface() const {
return SkMakeTypefaceFromCTFont(base::mac::NSToCFCast(GetNativeFont()));
}
////////////////////////////////////////////////////////////////////////////////
......
......@@ -35,7 +35,7 @@ class PlatformFontMac : public PlatformFont {
int GetFontSize() const override;
const FontRenderParams& GetFontRenderParams() override;
NativeFont GetNativeFont() const override;
sk_sp<SkTypeface> GetNativeSkTypefaceIfAvailable() const override;
sk_sp<SkTypeface> GetNativeSkTypeface() const override;
private:
PlatformFontMac(const std::string& font_name,
......
......@@ -312,7 +312,7 @@ NativeFont PlatformFontMac::GetNativeFont() const {
return [[native_font_.get() retain] autorelease];
}
sk_sp<SkTypeface> PlatformFontMac::GetNativeSkTypefaceIfAvailable() const {
sk_sp<SkTypeface> PlatformFontMac::GetNativeSkTypeface() const {
return SkMakeTypefaceFromCTFont(base::mac::NSToCFCast(GetNativeFont()));
}
......
......@@ -304,7 +304,8 @@ const FontRenderParams& PlatformFontSkia::GetFontRenderParams() {
return font_render_params_;
}
sk_sp<SkTypeface> PlatformFontSkia::GetNativeSkTypefaceIfAvailable() const {
sk_sp<SkTypeface> PlatformFontSkia::GetNativeSkTypeface() const {
DCHECK(typeface_);
return sk_sp<SkTypeface>(typeface_);
}
......
......@@ -61,7 +61,7 @@ class GFX_EXPORT PlatformFontSkia : public PlatformFont {
std::string GetActualFontName() const override;
int GetFontSize() const override;
const FontRenderParams& GetFontRenderParams() override;
sk_sp<SkTypeface> GetNativeSkTypefaceIfAvailable() const override;
sk_sp<SkTypeface> GetNativeSkTypeface() const override;
private:
// Create a new instance of this object with the specified properties. Called
......
......@@ -894,8 +894,7 @@ bool TextRunHarfBuzz::FontParams::SetRenderParamsOverrideSkiaFaceFromFont(
const Font& fallback_font,
const FontRenderParams& new_render_params) {
PlatformFont* platform_font = fallback_font.platform_font();
sk_sp<SkTypeface> new_skia_face =
platform_font->GetNativeSkTypefaceIfAvailable();
sk_sp<SkTypeface> new_skia_face = platform_font->GetNativeSkTypeface();
// If pass-through of the Skia native handle fails for PlatformFonts other
// 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