Underline decorations with gaps and no text

Bug: Skia:10822
Change-Id: I5ab2f743fe2837070065954bc6f5ba930292f0c8
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/328596
Commit-Queue: Julia Lavrova <jlavrova@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
diff --git a/modules/skparagraph/samples/SampleParagraph.cpp b/modules/skparagraph/samples/SampleParagraph.cpp
index f583983..5d95400 100644
--- a/modules/skparagraph/samples/SampleParagraph.cpp
+++ b/modules/skparagraph/samples/SampleParagraph.cpp
@@ -3090,6 +3090,38 @@
     using INHERITED = Sample;
 };
 
+class ParagraphView50 : public ParagraphView_Base {
+protected:
+    SkString name() override { return SkString("Paragraph50"); }
+
+    void onDrawContent(SkCanvas* canvas) override {
+        canvas->clear(SK_ColorWHITE);
+
+        auto fontCollection = sk_make_sp<FontCollection>();
+        fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
+
+        ParagraphStyle paragraph_style;
+        TextStyle text_style;
+        text_style.setColor(SK_ColorBLACK);
+        text_style.setFontFamilies({SkString("Roboto")});
+        text_style.setFontSize(16);
+        text_style.setDecorationStyle(TextDecorationStyle::kSolid);
+        text_style.setDecorationMode(TextDecorationMode::kGaps);
+        text_style.setDecorationColor(SK_ColorRED);
+        text_style.setDecoration(TextDecoration::kUnderline);
+        ParagraphBuilderImpl builder(paragraph_style, fontCollection);
+        builder.pushStyle(text_style);
+        builder.addText("\n\n");
+        builder.pop();
+        auto paragraph = builder.Build();
+        paragraph->layout(360);
+        paragraph->paint(canvas, 0, 0);
+    }
+
+private:
+    using INHERITED = Sample;
+};
+
 }  // namespace
 
 //////////////////////////////////////////////////////////////////////////////
@@ -3140,3 +3172,4 @@
 DEF_SAMPLE(return new ParagraphView47();)
 DEF_SAMPLE(return new ParagraphView48();)
 DEF_SAMPLE(return new ParagraphView49();)
+DEF_SAMPLE(return new ParagraphView50();)
diff --git a/modules/skparagraph/src/Decorations.cpp b/modules/skparagraph/src/Decorations.cpp
index 6c1bf23..32dd057 100644
--- a/modules/skparagraph/src/Decorations.cpp
+++ b/modules/skparagraph/src/Decorations.cpp
@@ -94,13 +94,16 @@
 
 void Decorations::calculateGaps(const TextLine::ClipContext& context, const SkRect& rect,
                                 SkScalar baseline, SkScalar halo) {
-    // Create a special textblob for decorations
+    // Create a special text blob for decorations
     SkTextBlobBuilder builder;
     context.run->copyTo(builder,
                       SkToU32(context.pos),
                       context.size);
-    auto blob = builder.make();
-
+    sk_sp<SkTextBlob> blob = builder.make();
+    if (!blob) {
+        // There is no text really
+        return;
+    }
     // Since we do not shift down the text by {baseline}
     // (it now happens on drawTextBlob but we do not draw text here)
     // we have to shift up the bounds to compensate