Commit 1f326209 authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

Introduce a proper constructor of Font with a FontSelector

This patch introduces a new Font constructor, so that Font can set its
FontSelector during construction, instead of setting it later with the
deprecated Update() function.

Bug: 1049295
Change-Id: I6255ec14da7c3822ecfc9decd0fbf92322f2ccbe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2107687
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Reviewed-by: default avatarDominik Röttsches <drott@chromium.org>
Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Reviewed-by: default avatarFernando Serboncini <fserb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751442}
parent 695f9d45
...@@ -157,8 +157,7 @@ bool FontFaceSetDocument::ResolveFontStyle(const String& font_string, ...@@ -157,8 +157,7 @@ bool FontFaceSetDocument::ResolveFontStyle(const String& font_string,
auto* font_selector = GetDocument()->GetStyleEngine().GetFontSelector(); auto* font_selector = GetDocument()->GetStyleEngine().GetFontSelector();
FontDescription description = FontDescription description =
FontStyleResolver::ComputeFont(*parsed_style, font_selector); FontStyleResolver::ComputeFont(*parsed_style, font_selector);
font = Font(description); font = Font(description, font_selector);
font.Update(font_selector);
return true; return true;
} }
......
...@@ -97,8 +97,7 @@ bool FontFaceSetWorker::ResolveFontStyle(const String& font_string, ...@@ -97,8 +97,7 @@ bool FontFaceSetWorker::ResolveFontStyle(const String& font_string,
FontDescription description = FontStyleResolver::ComputeFont( FontDescription description = FontStyleResolver::ComputeFont(
*parsed_style, GetWorker()->GetFontSelector()); *parsed_style, GetWorker()->GetFontSelector());
font = Font(description); font = Font(description, GetWorker()->GetFontSelector());
font.Update(GetWorker()->GetFontSelector());
return true; return true;
} }
......
...@@ -319,8 +319,7 @@ void FontBuilder::UpdateAdjustedSize(FontDescription& font_description, ...@@ -319,8 +319,7 @@ void FontBuilder::UpdateAdjustedSize(FontDescription& font_description,
// FontDescription::EffectiveFontSize. // FontDescription::EffectiveFontSize.
font_description.SetAdjustedSize(font_description.ComputedSize()); font_description.SetAdjustedSize(font_description.ComputedSize());
Font font(font_description); Font font(font_description, font_selector);
font.Update(font_selector);
const SimpleFontData* font_data = font.PrimaryFont(); const SimpleFontData* font_data = font.PrimaryFont();
......
...@@ -18,8 +18,7 @@ FontDescription FontStyleResolver::ComputeFont( ...@@ -18,8 +18,7 @@ FontDescription FontStyleResolver::ComputeFont(
FontBuilder builder(nullptr); FontBuilder builder(nullptr);
FontDescription fontDescription; FontDescription fontDescription;
Font font(fontDescription); Font font(fontDescription, font_selector);
font.Update(font_selector);
CSSToLengthConversionData::FontSizes fontSizes(10, 10, &font, 1); CSSToLengthConversionData::FontSizes fontSizes(10, 10, &font, 1);
CSSToLengthConversionData::ViewportSize viewportSize(0, 0); CSSToLengthConversionData::ViewportSize viewportSize(0, 0);
CSSToLengthConversionData conversionData(nullptr, fontSizes, viewportSize, 1); CSSToLengthConversionData conversionData(nullptr, fontSizes, viewportSize, 1);
......
...@@ -187,8 +187,7 @@ void LayoutTextCombine::UpdateFontStyleForCombinedText() { ...@@ -187,8 +187,7 @@ void LayoutTextCombine::UpdateFontStyleForCombinedText() {
kQuarterWidth}; kQuarterWidth};
for (size_t i = 0; i < base::size(kWidthVariants); ++i) { for (size_t i = 0; i < base::size(kWidthVariants); ++i) {
description.SetWidthVariant(kWidthVariants[i]); description.SetWidthVariant(kWidthVariants[i]);
Font compressed_font = Font(description); Font compressed_font(description, font_selector);
compressed_font.Update(font_selector);
float run_width = compressed_font.Width(run); float run_width = compressed_font.Width(run);
if (run_width <= em_width) { if (run_width <= em_width) {
combined_text_width_ = run_width; combined_text_width_ = run_width;
......
...@@ -414,8 +414,8 @@ void LayoutSVGInlineText::ComputeNewScaledFontForStyle( ...@@ -414,8 +414,8 @@ void LayoutSVGInlineText::ComputeNewScaledFontForStyle(
FontDescription font_description = unscaled_font_description; FontDescription font_description = unscaled_font_description;
font_description.SetComputedSize(scaled_font_size); font_description.SetComputedSize(scaled_font_size);
scaled_font = Font(font_description); scaled_font =
scaled_font.Update(document.GetStyleEngine().GetFontSelector()); Font(font_description, document.GetStyleEngine().GetFontSelector());
} }
PhysicalRect LayoutSVGInlineText::VisualRectInDocument( PhysicalRect LayoutSVGInlineText::VisualRectInDocument(
......
...@@ -125,7 +125,7 @@ void CanvasRenderingContext2DState::FontsNeedUpdate( ...@@ -125,7 +125,7 @@ void CanvasRenderingContext2DState::FontsNeedUpdate(
DCHECK_EQ(font_selector, font_.GetFontSelector()); DCHECK_EQ(font_selector, font_.GetFontSelector());
DCHECK(realized_font_); DCHECK(realized_font_);
font_.Update(font_selector); font_ = Font(font_.GetFontDescription(), font_selector);
// FIXME: We only really need to invalidate the resolved filter if the font // FIXME: We only really need to invalidate the resolved filter if the font
// update above changed anything and the filter uses font-dependent units. // update above changed anything and the filter uses font-dependent units.
resolved_filter_.reset(); resolved_filter_.reset();
...@@ -256,8 +256,7 @@ void CanvasRenderingContext2DState::ClipPath( ...@@ -256,8 +256,7 @@ void CanvasRenderingContext2DState::ClipPath(
void CanvasRenderingContext2DState::SetFont( void CanvasRenderingContext2DState::SetFont(
const FontDescription& font_description, const FontDescription& font_description,
FontSelector* selector) { FontSelector* selector) {
font_ = Font(font_description); font_ = Font(font_description, selector);
font_.Update(selector);
realized_font_ = true; realized_font_ = true;
if (selector) if (selector)
selector->RegisterForInvalidationCallbacks(this); selector->RegisterForInvalidationCallbacks(this);
......
...@@ -52,6 +52,11 @@ Font::Font() = default; ...@@ -52,6 +52,11 @@ Font::Font() = default;
Font::Font(const FontDescription& fd) : font_description_(fd) {} Font::Font(const FontDescription& fd) : font_description_(fd) {}
Font::Font(const FontDescription& font_description, FontSelector* font_selector)
: font_description_(font_description),
font_fallback_list_(
font_selector ? FontFallbackList::Create(font_selector) : nullptr) {}
Font::Font(const Font& other) = default; Font::Font(const Font& other) = default;
Font& Font::operator=(const Font& other) { Font& Font::operator=(const Font& other) {
...@@ -87,7 +92,7 @@ void Font::Update(FontSelector* font_selector) const { ...@@ -87,7 +92,7 @@ void Font::Update(FontSelector* font_selector) const {
// in trouble). Still, this is pretty disgusting, and could eventually be // in trouble). Still, this is pretty disgusting, and could eventually be
// rectified by using RefPtrs for Fonts themselves. // rectified by using RefPtrs for Fonts themselves.
if (!font_fallback_list_) if (!font_fallback_list_)
font_fallback_list_ = FontFallbackList::Create(); font_fallback_list_ = FontFallbackList::Create(nullptr);
font_fallback_list_->Invalidate(font_selector); font_fallback_list_->Invalidate(font_selector);
} }
......
...@@ -65,7 +65,8 @@ class PLATFORM_EXPORT Font { ...@@ -65,7 +65,8 @@ class PLATFORM_EXPORT Font {
public: public:
Font(); Font();
Font(const FontDescription&); explicit Font(const FontDescription&);
Font(const FontDescription&, FontSelector*);
~Font(); ~Font();
Font(const Font&); Font(const Font&);
...@@ -244,7 +245,7 @@ class PLATFORM_EXPORT Font { ...@@ -244,7 +245,7 @@ class PLATFORM_EXPORT Font {
private: private:
FontFallbackList* EnsureFontFallbackList() const { FontFallbackList* EnsureFontFallbackList() const {
if (!font_fallback_list_) if (!font_fallback_list_)
font_fallback_list_ = FontFallbackList::Create(); font_fallback_list_ = FontFallbackList::Create(nullptr);
return font_fallback_list_.get(); return font_fallback_list_.get();
} }
......
...@@ -39,10 +39,10 @@ ...@@ -39,10 +39,10 @@
namespace blink { namespace blink {
FontFallbackList::FontFallbackList() FontFallbackList::FontFallbackList(FontSelector* font_selector)
: cached_primary_simple_font_data_(nullptr), : cached_primary_simple_font_data_(nullptr),
font_selector_(nullptr), font_selector_(font_selector),
font_selector_version_(0), font_selector_version_(font_selector ? font_selector->Version() : 0),
family_index_(0), family_index_(0),
generation_(FontCache::GetFontCache()->Generation()), generation_(FontCache::GetFontCache()->Generation()),
has_loading_fallback_(false), has_loading_fallback_(false),
......
...@@ -43,8 +43,8 @@ class PLATFORM_EXPORT FontFallbackList : public RefCounted<FontFallbackList> { ...@@ -43,8 +43,8 @@ class PLATFORM_EXPORT FontFallbackList : public RefCounted<FontFallbackList> {
USING_FAST_MALLOC(FontFallbackList); USING_FAST_MALLOC(FontFallbackList);
public: public:
static scoped_refptr<FontFallbackList> Create() { static scoped_refptr<FontFallbackList> Create(FontSelector* font_selector) {
return base::AdoptRef(new FontFallbackList()); return base::AdoptRef(new FontFallbackList(font_selector));
} }
~FontFallbackList() { ReleaseFontData(); } ~FontFallbackList() { ReleaseFontData(); }
...@@ -100,7 +100,7 @@ class PLATFORM_EXPORT FontFallbackList : public RefCounted<FontFallbackList> { ...@@ -100,7 +100,7 @@ class PLATFORM_EXPORT FontFallbackList : public RefCounted<FontFallbackList> {
} }
private: private:
FontFallbackList(); explicit FontFallbackList(FontSelector* font_selector);
scoped_refptr<FontData> GetFontData(const FontDescription&, int& family_index) const; scoped_refptr<FontData> GetFontData(const FontDescription&, int& family_index) const;
......
...@@ -95,9 +95,7 @@ Font CreateTestFont(const AtomicString& family_name, ...@@ -95,9 +95,7 @@ Font CreateTestFont(const AtomicString& family_name,
if (ligatures) if (ligatures)
font_description.SetVariantLigatures(*ligatures); font_description.SetVariantLigatures(*ligatures);
Font font(font_description); return Font(font_description, TestFontSelector::Create(font_path));
font.Update(TestFontSelector::Create(font_path));
return font;
} }
} // namespace test } // namespace test
......
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