From 22bb52e95b92d15919450ab3a360355be287463e Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Thu, 5 Dec 2019 17:56:59 -0800 Subject: [PATCH] Get baselines from cached default metrics if the text is empty Change-Id: Ic04251d60d6d36f80c3e569312495190ba375d85 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/258488 Reviewed-by: Julia Lavrova Commit-Queue: Jason Simmons --- modules/skparagraph/src/ParagraphImpl.cpp | 22 +++++++++------------- modules/skparagraph/src/ParagraphImpl.h | 5 ++++- modules/skparagraph/src/TextWrapper.cpp | 3 +-- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/modules/skparagraph/src/ParagraphImpl.cpp b/modules/skparagraph/src/ParagraphImpl.cpp index 26d128ea40..7d4f08b15f 100644 --- a/modules/skparagraph/src/ParagraphImpl.cpp +++ b/modules/skparagraph/src/ParagraphImpl.cpp @@ -132,6 +132,7 @@ void ParagraphImpl::layout(SkScalar rawWidth) { fClusters.reset(); fGraphemes.reset(); this->markGraphemes(); + this->computeEmptyMetrics(); if (!this->shapeTextIntoEndlessLine()) { @@ -140,15 +141,14 @@ void ParagraphImpl::layout(SkScalar rawWidth) { this->fLines.reset(); // Set the important values that are not zero - auto emptyMetrics = computeEmptyMetrics(); fWidth = floorWidth; - fHeight = emptyMetrics.height(); + fHeight = fEmptyMetrics.height(); if (fParagraphStyle.getStrutStyle().getStrutEnabled() && fParagraphStyle.getStrutStyle().getForceStrutHeight()) { fHeight = fStrutMetrics.height(); } - fAlphabeticBaseline = emptyMetrics.alphabeticBaseline(); - fIdeographicBaseline = emptyMetrics.ideographicBaseline(); + fAlphabeticBaseline = fEmptyMetrics.alphabeticBaseline(); + fIdeographicBaseline = fEmptyMetrics.ideographicBaseline(); fMinIntrinsicWidth = 0; fMaxIntrinsicWidth = 0; this->fOldWidth = floorWidth; @@ -384,7 +384,6 @@ bool ParagraphImpl::shapeTextIntoEndlessLine() { } void ParagraphImpl::breakShapedTextIntoLines(SkScalar maxWidth) { - TextWrapper textWrapper; textWrapper.breakTextIntoLines( this, @@ -413,8 +412,8 @@ void ParagraphImpl::breakShapedTextIntoLines(SkScalar maxWidth) { fWidth = maxWidth; fMaxIntrinsicWidth = textWrapper.maxIntrinsicWidth(); fMinIntrinsicWidth = textWrapper.minIntrinsicWidth(); - fAlphabeticBaseline = fLines.empty() ? 0 : fLines.front().alphabeticBaseline(); - fIdeographicBaseline = fLines.empty() ? 0 : fLines.front().ideographicBaseline(); + fAlphabeticBaseline = fLines.empty() ? fEmptyMetrics.alphabeticBaseline() : fLines.front().alphabeticBaseline(); + fIdeographicBaseline = fLines.empty() ? fEmptyMetrics.ideographicBaseline() : fLines.front().ideographicBaseline(); fExceededMaxLines = textWrapper.exceededMaxLines(); } @@ -1092,8 +1091,7 @@ void ParagraphImpl::setState(InternalState state) { } -InternalLineMetrics ParagraphImpl::computeEmptyMetrics() { - +void ParagraphImpl::computeEmptyMetrics() { auto defaultTextStyle = paragraphStyle().getTextStyle(); auto typefaces = fontCollection()->findTypefaces( @@ -1101,10 +1099,8 @@ InternalLineMetrics ParagraphImpl::computeEmptyMetrics() { auto typeface = typefaces.size() ? typefaces.front() : nullptr; SkFont font(typeface, defaultTextStyle.getFontSize()); - InternalLineMetrics metrics(font, paragraphStyle().getStrutStyle().getForceStrutHeight()); - fStrutMetrics.updateLineMetrics(metrics); - - return metrics; + fEmptyMetrics = InternalLineMetrics(font, paragraphStyle().getStrutStyle().getForceStrutHeight()); + fStrutMetrics.updateLineMetrics(fEmptyMetrics); } void ParagraphImpl::updateText(size_t from, SkString text) { diff --git a/modules/skparagraph/src/ParagraphImpl.h b/modules/skparagraph/src/ParagraphImpl.h index eb79275e91..25f6f134fc 100644 --- a/modules/skparagraph/src/ParagraphImpl.h +++ b/modules/skparagraph/src/ParagraphImpl.h @@ -196,7 +196,7 @@ public: void updateForegroundPaint(size_t from, size_t to, SkPaint paint) override; void updateBackgroundPaint(size_t from, size_t to, SkPaint paint) override; - InternalLineMetrics computeEmptyMetrics(); + InternalLineMetrics getEmptyMetrics() const { return fEmptyMetrics; } InternalLineMetrics getStrutMetrics() const { return fStrutMetrics; } private: @@ -215,6 +215,8 @@ private: void markGraphemes16(); void markGraphemes(); + void computeEmptyMetrics(); + // Input SkTArray> fLetterSpaceStyles; SkTArray> fWordSpaceStyles; @@ -241,6 +243,7 @@ private: SkTArray fFontSwitches; + InternalLineMetrics fEmptyMetrics; InternalLineMetrics fStrutMetrics; SkScalar fOldWidth; diff --git a/modules/skparagraph/src/TextWrapper.cpp b/modules/skparagraph/src/TextWrapper.cpp index a0fb5813bf..98fc5a42a4 100644 --- a/modules/skparagraph/src/TextWrapper.cpp +++ b/modules/skparagraph/src/TextWrapper.cpp @@ -205,8 +205,7 @@ void TextWrapper::breakTextIntoLines(ParagraphImpl* parent, // If the line is empty with the hard line break, let's take the paragraph font (flutter???) if (fHardLineBreak && fEndLine.width() == 0) { - auto emptyMetrics = parent->computeEmptyMetrics(); - fEndLine.setMetrics(emptyMetrics); + fEndLine.setMetrics(parent->getEmptyMetrics()); } // Deal with placeholder clusters == runs[@size==1]