Fixing minor bugs: ellipsis on justified text
Change-Id: Ic0ebf53b221defa5d07ba2832666b322a2629547
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/289020
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Julia Lavrova <jlavrova@google.com>
diff --git a/modules/skparagraph/src/Run.cpp b/modules/skparagraph/src/Run.cpp
index d2ca6f7..e679be8 100644
--- a/modules/skparagraph/src/Run.cpp
+++ b/modules/skparagraph/src/Run.cpp
@@ -67,6 +67,7 @@
}
auto correction = 0.0f;
if (end > start && !fJustificationShifts.empty()) {
+ // This is not a typo: we are using Point as a pair of SkScalars
correction = fJustificationShifts[end - 1].fX -
fJustificationShifts[start].fY;
}
diff --git a/modules/skparagraph/src/TextLine.cpp b/modules/skparagraph/src/TextLine.cpp
index f363502..ce9b1a9 100644
--- a/modules/skparagraph/src/TextLine.cpp
+++ b/modules/skparagraph/src/TextLine.cpp
@@ -666,12 +666,16 @@
auto trailed = fMaster->clusters(trailedRange);
auto trimmed = fMaster->clusters(trimmedRange);
+ bool ignore = false;
directional_for_each(trailed, reversed != run.leftToRight(), [&](Cluster& cluster) {
+ if (ignore) return;
bool ghost = &cluster >= trimmed.end();
if (!includeGhosts && ghost) {
+ ignore = true;
return;
}
if (!visitor(&cluster, ghost)) {
+ ignore = true;
return;
}
});
@@ -876,6 +880,7 @@
// TODO: For some reason Flutter imagines a hard line break at the end of the last line.
// To be removed...
return fMaster->cluster(fGhostClusterRange.end - 1).isHardBreak() ||
+ fEllipsis != nullptr ||
fGhostClusterRange.end == fMaster->clusters().size() - 1;
}
diff --git a/samplecode/SampleParagraph.cpp b/samplecode/SampleParagraph.cpp
index 6208ea7..aaf91fd 100644
--- a/samplecode/SampleParagraph.cpp
+++ b/samplecode/SampleParagraph.cpp
@@ -2730,7 +2730,41 @@
private:
typedef Sample INHERITED;
};
-//
+
+class ParagraphView43 : public ParagraphView_Base {
+protected:
+ SkString name() override { return SkString("Paragraph43"); }
+
+ void onDrawContent(SkCanvas* canvas) override {
+
+ SkString text("World domination is such an ugly phrase - I prefer to call it world optimisation");
+ canvas->drawColor(SK_ColorWHITE);
+
+ auto fontCollection = sk_make_sp<FontCollection>();
+ fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
+ fontCollection->enableFontFallback();
+
+ ParagraphStyle paragraph_style;
+ paragraph_style.setTextAlign(TextAlign::kJustify);
+ paragraph_style.setEllipsis(u"\u2026");
+ paragraph_style.setMaxLines(2);
+ ParagraphBuilderImpl builder(paragraph_style, fontCollection);
+ TextStyle text_style;
+ text_style.setColor(SK_ColorBLACK);
+ text_style.setFontFamilies({SkString("Roboto")});
+ text_style.setFontSize(40);
+ text_style.setHeightOverride(true);
+ builder.pushStyle(text_style);
+ builder.addText(text.c_str());
+ auto paragraph = builder.Build();
+ paragraph->layout(width() / 4);
+ paragraph->paint(canvas, 0, 0);
+ }
+
+private:
+ typedef Sample INHERITED;
+};
+
//////////////////////////////////////////////////////////////////////////////
DEF_SAMPLE(return new ParagraphView1();)
DEF_SAMPLE(return new ParagraphView2();)
@@ -2772,3 +2806,4 @@
DEF_SAMPLE(return new ParagraphView39();)
DEF_SAMPLE(return new ParagraphView41();)
DEF_SAMPLE(return new ParagraphView42();)
+DEF_SAMPLE(return new ParagraphView43();)