Attaching ellipsis to emoji cluster

Bug: skia:10253
Change-Id: Id6b8507331facba4b69ebc96646a87c5e0eb6da9
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/290132
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Julia Lavrova <jlavrova@google.com>
diff --git a/modules/skparagraph/src/TextLine.cpp b/modules/skparagraph/src/TextLine.cpp
index ce9b1a9..c8be2ad 100644
--- a/modules/skparagraph/src/TextLine.cpp
+++ b/modules/skparagraph/src/TextLine.cpp
@@ -658,7 +658,9 @@
                                                    const ClustersVisitor& visitor) const {
     // Walk through the clusters in the logical order (or reverse)
     SkSpan<const size_t> runs(fRunsInVisualOrder.data(), fRunsInVisualOrder.size());
-    directional_for_each(runs, reversed, [&](decltype(runs[0]) r) {
+    bool ignore = false;
+    directional_for_each(runs, !reversed, [&](decltype(runs[0]) r) {
+        if (ignore) return;
         auto run = this->fMaster->run(r);
         auto trimmedRange = fClusterRange.intersection(run.clusterRange());
         auto trailedRange = fGhostClusterRange.intersection(run.clusterRange());
@@ -666,12 +668,10 @@
 
         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)) {
diff --git a/samplecode/SampleParagraph.cpp b/samplecode/SampleParagraph.cpp
index c4fd8c8..f4c0888 100644
--- a/samplecode/SampleParagraph.cpp
+++ b/samplecode/SampleParagraph.cpp
@@ -2795,6 +2795,39 @@
     typedef Sample INHERITED;
 };
 
+class ParagraphView44 : public ParagraphView_Base {
+protected:
+    SkString name() override { return SkString("Paragraph44"); }
+
+    void onDrawContent(SkCanvas* canvas) override {
+
+        const std::u16string text = u"The quick brown fox \U0001f98a ate a zesty ham burger fons \U0001f354."
+                                    "The \U0001f469\u200D\U0001f469\u200D\U0001f467\u200D\U0001f467 laughed.";
+        canvas->drawColor(SK_ColorWHITE);
+
+        auto fontCollection = sk_make_sp<FontCollection>();
+        fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
+        fontCollection->enableFontFallback();
+
+        ParagraphStyle paragraph_style;
+        paragraph_style.setMaxLines(7);
+        paragraph_style.setEllipsis(u"\u2026");
+        ParagraphBuilderImpl builder(paragraph_style, fontCollection);
+        TextStyle text_style;
+        text_style.setColor(SK_ColorBLACK);
+        text_style.setFontFamilies({SkString("Roboto"), SkString("Noto Color Emoji")});
+        text_style.setFontSize(60);
+        builder.pushStyle(text_style);
+        builder.addText(text);
+        auto paragraph = builder.Build();
+        paragraph->layout(305);//width());
+        paragraph->paint(canvas, 0, 0);
+    }
+
+private:
+    typedef Sample INHERITED;
+};
+
 }  // namespace
 
 //////////////////////////////////////////////////////////////////////////////
@@ -2839,3 +2872,4 @@
 DEF_SAMPLE(return new ParagraphView41();)
 DEF_SAMPLE(return new ParagraphView42();)
 DEF_SAMPLE(return new ParagraphView43();)
+DEF_SAMPLE(return new ParagraphView44();)