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,
auto* font_selector = GetDocument()->GetStyleEngine().GetFontSelector();
FontDescription description =
FontStyleResolver::ComputeFont(*parsed_style, font_selector);
font = Font(description);
font.Update(font_selector);
font = Font(description, font_selector);
return true;
}
......
......@@ -97,8 +97,7 @@ bool FontFaceSetWorker::ResolveFontStyle(const String& font_string,
FontDescription description = FontStyleResolver::ComputeFont(
*parsed_style, GetWorker()->GetFontSelector());
font = Font(description);
font.Update(GetWorker()->GetFontSelector());
font = Font(description, GetWorker()->GetFontSelector());
return true;
}
......
......@@ -319,8 +319,7 @@ void FontBuilder::UpdateAdjustedSize(FontDescription& font_description,
// FontDescription::EffectiveFontSize.
font_description.SetAdjustedSize(font_description.ComputedSize());
Font font(font_description);
font.Update(font_selector);
Font font(font_description, font_selector);
const SimpleFontData* font_data = font.PrimaryFont();
......
......@@ -18,8 +18,7 @@ FontDescription FontStyleResolver::ComputeFont(
FontBuilder builder(nullptr);
FontDescription fontDescription;
Font font(fontDescription);
font.Update(font_selector);
Font font(fontDescription, font_selector);
CSSToLengthConversionData::FontSizes fontSizes(10, 10, &font, 1);
CSSToLengthConversionData::ViewportSize viewportSize(0, 0);
CSSToLengthConversionData conversionData(nullptr, fontSizes, viewportSize, 1);
......
......@@ -187,8 +187,7 @@ void LayoutTextCombine::UpdateFontStyleForCombinedText() {
kQuarterWidth};
for (size_t i = 0; i < base::size(kWidthVariants); ++i) {
description.SetWidthVariant(kWidthVariants[i]);
Font compressed_font = Font(description);
compressed_font.Update(font_selector);
Font compressed_font(description, font_selector);
float run_width = compressed_font.Width(run);
if (run_width <= em_width) {
combined_text_width_ = run_width;
......
......@@ -414,8 +414,8 @@ void LayoutSVGInlineText::ComputeNewScaledFontForStyle(
FontDescription font_description = unscaled_font_description;
font_description.SetComputedSize(scaled_font_size);
scaled_font = Font(font_description);
scaled_font.Update(document.GetStyleEngine().GetFontSelector());
scaled_font =
Font(font_description, document.GetStyleEngine().GetFontSelector());
}
PhysicalRect LayoutSVGInlineText::VisualRectInDocument(
......
......@@ -125,7 +125,7 @@ void CanvasRenderingContext2DState::FontsNeedUpdate(
DCHECK_EQ(font_selector, font_.GetFontSelector());
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
// update above changed anything and the filter uses font-dependent units.
resolved_filter_.reset();
......@@ -256,8 +256,7 @@ void CanvasRenderingContext2DState::ClipPath(
void CanvasRenderingContext2DState::SetFont(
const FontDescription& font_description,
FontSelector* selector) {
font_ = Font(font_description);
font_.Update(selector);
font_ = Font(font_description, selector);
realized_font_ = true;
if (selector)
selector->RegisterForInvalidationCallbacks(this);
......
......@@ -52,6 +52,11 @@ Font::Font() = default;
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::operator=(const Font& other) {
......@@ -87,7 +92,7 @@ void Font::Update(FontSelector* font_selector) const {
// in trouble). Still, this is pretty disgusting, and could eventually be
// rectified by using RefPtrs for Fonts themselves.
if (!font_fallback_list_)
font_fallback_list_ = FontFallbackList::Create();
font_fallback_list_ = FontFallbackList::Create(nullptr);
font_fallback_list_->Invalidate(font_selector);
}
......
......@@ -65,7 +65,8 @@ class PLATFORM_EXPORT Font {
public:
Font();
Font(const FontDescription&);
explicit Font(const FontDescription&);
Font(const FontDescription&, FontSelector*);
~Font();
Font(const Font&);
......@@ -244,7 +245,7 @@ class PLATFORM_EXPORT Font {
private:
FontFallbackList* EnsureFontFallbackList() const {
if (!font_fallback_list_)
font_fallback_list_ = FontFallbackList::Create();
font_fallback_list_ = FontFallbackList::Create(nullptr);
return font_fallback_list_.get();
}
......
......@@ -39,10 +39,10 @@
namespace blink {
FontFallbackList::FontFallbackList()
FontFallbackList::FontFallbackList(FontSelector* font_selector)
: cached_primary_simple_font_data_(nullptr),
font_selector_(nullptr),
font_selector_version_(0),
font_selector_(font_selector),
font_selector_version_(font_selector ? font_selector->Version() : 0),
family_index_(0),
generation_(FontCache::GetFontCache()->Generation()),
has_loading_fallback_(false),
......
......@@ -43,8 +43,8 @@ class PLATFORM_EXPORT FontFallbackList : public RefCounted<FontFallbackList> {
USING_FAST_MALLOC(FontFallbackList);
public:
static scoped_refptr<FontFallbackList> Create() {
return base::AdoptRef(new FontFallbackList());
static scoped_refptr<FontFallbackList> Create(FontSelector* font_selector) {
return base::AdoptRef(new FontFallbackList(font_selector));
}
~FontFallbackList() { ReleaseFontData(); }
......@@ -100,7 +100,7 @@ class PLATFORM_EXPORT FontFallbackList : public RefCounted<FontFallbackList> {
}
private:
FontFallbackList();
explicit FontFallbackList(FontSelector* font_selector);
scoped_refptr<FontData> GetFontData(const FontDescription&, int& family_index) const;
......
......@@ -95,9 +95,7 @@ Font CreateTestFont(const AtomicString& family_name,
if (ligatures)
font_description.SetVariantLigatures(*ligatures);
Font font(font_description);
font.Update(TestFontSelector::Create(font_path));
return font;
return Font(font_description, TestFontSelector::Create(font_path));
}
} // 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