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>
This commit is contained in:
Jason Simmons 2019-12-05 17:56:59 -08:00 committed by Skia Commit-Bot
parent 576b6a19ad
commit 22bb52e95b
3 changed files with 14 additions and 16 deletions

View File

@ -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) {

View File

@ -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<StyleBlock<SkScalar>> fLetterSpaceStyles;
SkTArray<StyleBlock<SkScalar>> fWordSpaceStyles;
@ -241,6 +243,7 @@ private:
SkTArray<ResolvedFontDescriptor> fFontSwitches;
InternalLineMetrics fEmptyMetrics;
InternalLineMetrics fStrutMetrics;
SkScalar fOldWidth;

View File

@ -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]