Fixing a crash in Flutter Text Editor

Change-Id: I01b92f7c5f6030afae164ba2999e3aa8168597b0
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/368417
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Julia Lavrova <jlavrova@google.com>
This commit is contained in:
Julia Lavrova 2021-02-09 15:10:11 -05:00 committed by Skia Commit-Bot
parent 1cda194366
commit f756979dbf
2 changed files with 7 additions and 26 deletions

View File

@ -3396,26 +3396,11 @@ protected:
text_style.setFontSize(20);
text_style.setColor(SK_ColorBLACK);
builder.pushStyle(text_style);
builder.addText("A\n\n");
builder.addText(" ");
builder.pop();
auto paragraph = builder.Build();
paragraph->layout(width());
//auto impl = static_cast<ParagraphImpl*>(paragraph.get());
//auto blocks = impl->ParagraphImpl::findAllBlocks({0, 24});
paragraph->layout(0);
paragraph->paint(canvas, 0, 0);
auto res1 = paragraph->
getGlyphPositionAtCoordinate(paragraph->getMinIntrinsicWidth(),
+ 1);
auto res2 = paragraph->
getGlyphPositionAtCoordinate(0,
paragraph->getHeight() * 0.5);
auto res3 = paragraph->
getGlyphPositionAtCoordinate(0,
paragraph->getHeight() - 1);
SkDebugf("res1: %d %s\n", res1.position, res1.affinity == Affinity::kDownstream ? "D" : "U");
SkDebugf("res2: %d %s\n", res2.position, res2.affinity == Affinity::kDownstream ? "D" : "U");
SkDebugf("res3: %d %s\n", res3.position, res3.affinity == Affinity::kDownstream ? "D" : "U");
}
private:

View File

@ -195,17 +195,13 @@ std::tuple<Cluster*, size_t, SkScalar> TextWrapper::trimStartSpaces(Cluster* end
return std::make_tuple(fEndLine.breakCluster() + 1, 0, width);
}
// breakCluster points to the end of the line;
// It's a soft line break so we need to move lineStart forward skipping all the spaces
auto width = fEndLine.widthWithGhostSpaces();
auto cluster = fEndLine.breakCluster();
if (fEndLine.endCluster() != fEndLine.startCluster() ||
fEndLine.endPos() != fEndLine.startPos()) {
auto cluster = fEndLine.breakCluster() + 1;
while (cluster < endOfClusters && cluster->isWhitespaces()) {
width += cluster->width();
++cluster;
while (cluster < endOfClusters && cluster->isWhitespaces()) {
width += cluster->width();
++cluster;
}
} else {
// Nothing fits the line - no need to check for spaces
}
return std::make_tuple(cluster, 0, width);