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 <jlavrova@google.com>
Commit-Queue: Jason Simmons <jsimmons@google.com>
diff --git a/modules/skparagraph/src/ParagraphImpl.cpp b/modules/skparagraph/src/ParagraphImpl.cpp
index 26d128e..7d4f08b 100644
--- a/modules/skparagraph/src/ParagraphImpl.cpp
+++ b/modules/skparagraph/src/ParagraphImpl.cpp
@@ -132,6 +132,7 @@
fClusters.reset();
fGraphemes.reset();
this->markGraphemes();
+ this->computeEmptyMetrics();
if (!this->shapeTextIntoEndlessLine()) {
@@ -140,15 +141,14 @@
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 @@
}
void ParagraphImpl::breakShapedTextIntoLines(SkScalar maxWidth) {
-
TextWrapper textWrapper;
textWrapper.breakTextIntoLines(
this,
@@ -413,8 +412,8 @@
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 @@
}
-InternalLineMetrics ParagraphImpl::computeEmptyMetrics() {
-
+void ParagraphImpl::computeEmptyMetrics() {
auto defaultTextStyle = paragraphStyle().getTextStyle();
auto typefaces = fontCollection()->findTypefaces(
@@ -1101,10 +1099,8 @@
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 eb79275..25f6f13 100644
--- a/modules/skparagraph/src/ParagraphImpl.h
+++ b/modules/skparagraph/src/ParagraphImpl.h
@@ -196,7 +196,7 @@
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 @@
void markGraphemes16();
void markGraphemes();
+ void computeEmptyMetrics();
+
// Input
SkTArray<StyleBlock<SkScalar>> fLetterSpaceStyles;
SkTArray<StyleBlock<SkScalar>> fWordSpaceStyles;
@@ -241,6 +243,7 @@
SkTArray<ResolvedFontDescriptor> fFontSwitches;
+ InternalLineMetrics fEmptyMetrics;
InternalLineMetrics fStrutMetrics;
SkScalar fOldWidth;
diff --git a/modules/skparagraph/src/TextWrapper.cpp b/modules/skparagraph/src/TextWrapper.cpp
index a0fb581..98fc5a4 100644
--- a/modules/skparagraph/src/TextWrapper.cpp
+++ b/modules/skparagraph/src/TextWrapper.cpp
@@ -205,8 +205,7 @@
// 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]