Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 68d1433

Browse files
RusinoSkia Commit-Bot
authored andcommitted
Fixing minor bugs: ellipsis on justified text
Change-Id: Ic0ebf53b221defa5d07ba2832666b322a2629547 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/289020 Reviewed-by: Ben Wagner <[email protected]> Commit-Queue: Julia Lavrova <[email protected]>
1 parent 25dc7ca commit 68d1433

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

modules/skparagraph/src/Run.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ SkScalar Run::calculateWidth(size_t start, size_t end, bool clip) const {
6767
}
6868
auto correction = 0.0f;
6969
if (end > start && !fJustificationShifts.empty()) {
70+
// This is not a typo: we are using Point as a pair of SkScalars
7071
correction = fJustificationShifts[end - 1].fX -
7172
fJustificationShifts[start].fY;
7273
}

modules/skparagraph/src/TextLine.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,12 +666,16 @@ void TextLine::iterateThroughClustersInGlyphsOrder(bool reversed,
666666

667667
auto trailed = fMaster->clusters(trailedRange);
668668
auto trimmed = fMaster->clusters(trimmedRange);
669+
bool ignore = false;
669670
directional_for_each(trailed, reversed != run.leftToRight(), [&](Cluster& cluster) {
671+
if (ignore) return;
670672
bool ghost = &cluster >= trimmed.end();
671673
if (!includeGhosts && ghost) {
674+
ignore = true;
672675
return;
673676
}
674677
if (!visitor(&cluster, ghost)) {
678+
ignore = true;
675679
return;
676680
}
677681
});
@@ -876,6 +880,7 @@ bool TextLine::endsWithHardLineBreak() const {
876880
// TODO: For some reason Flutter imagines a hard line break at the end of the last line.
877881
// To be removed...
878882
return fMaster->cluster(fGhostClusterRange.end - 1).isHardBreak() ||
883+
fEllipsis != nullptr ||
879884
fGhostClusterRange.end == fMaster->clusters().size() - 1;
880885
}
881886

samplecode/SampleParagraph.cpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2730,7 +2730,41 @@ class ParagraphView42 : public ParagraphView_Base {
27302730
private:
27312731
typedef Sample INHERITED;
27322732
};
2733-
//
2733+
2734+
class ParagraphView43 : public ParagraphView_Base {
2735+
protected:
2736+
SkString name() override { return SkString("Paragraph43"); }
2737+
2738+
void onDrawContent(SkCanvas* canvas) override {
2739+
2740+
SkString text("World domination is such an ugly phrase - I prefer to call it world optimisation");
2741+
canvas->drawColor(SK_ColorWHITE);
2742+
2743+
auto fontCollection = sk_make_sp<FontCollection>();
2744+
fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2745+
fontCollection->enableFontFallback();
2746+
2747+
ParagraphStyle paragraph_style;
2748+
paragraph_style.setTextAlign(TextAlign::kJustify);
2749+
paragraph_style.setEllipsis(u"\u2026");
2750+
paragraph_style.setMaxLines(2);
2751+
ParagraphBuilderImpl builder(paragraph_style, fontCollection);
2752+
TextStyle text_style;
2753+
text_style.setColor(SK_ColorBLACK);
2754+
text_style.setFontFamilies({SkString("Roboto")});
2755+
text_style.setFontSize(40);
2756+
text_style.setHeightOverride(true);
2757+
builder.pushStyle(text_style);
2758+
builder.addText(text.c_str());
2759+
auto paragraph = builder.Build();
2760+
paragraph->layout(width() / 4);
2761+
paragraph->paint(canvas, 0, 0);
2762+
}
2763+
2764+
private:
2765+
typedef Sample INHERITED;
2766+
};
2767+
27342768
//////////////////////////////////////////////////////////////////////////////
27352769
DEF_SAMPLE(return new ParagraphView1();)
27362770
DEF_SAMPLE(return new ParagraphView2();)
@@ -2772,3 +2806,4 @@ DEF_SAMPLE(return new ParagraphView38();)
27722806
DEF_SAMPLE(return new ParagraphView39();)
27732807
DEF_SAMPLE(return new ParagraphView41();)
27742808
DEF_SAMPLE(return new ParagraphView42();)
2809+
DEF_SAMPLE(return new ParagraphView43();)

0 commit comments

Comments
 (0)