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

Commit 9bfe92a

Browse files
RusinoSkia Commit-Bot
authored andcommitted
Fixing a bug (reusing wrong formatting state)
Bug: skia:10702 Change-Id: I2b7814917bb1f2a729f231db6df6f010a7ec1abb Reviewed-on: https://skia-review.googlesource.com/c/skia/+/315654 Reviewed-by: Ben Wagner <bungeman@google.com> Commit-Queue: Julia Lavrova <jlavrova@google.com>
1 parent cf1a4f5 commit 9bfe92a

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

modules/skparagraph/samples/SampleParagraph.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2939,6 +2939,60 @@ class ParagraphView46 : public ParagraphView_Base {
29392939
using INHERITED = Sample;
29402940
};
29412941

2942+
class ParagraphView47 : public ParagraphView_Base {
2943+
protected:
2944+
SkString name() override { return SkString("Paragraph47"); }
2945+
2946+
void onDrawContent(SkCanvas* canvas) override {
2947+
2948+
canvas->clear(SK_ColorWHITE);
2949+
2950+
SkPaint paint;
2951+
paint.setColor(SK_ColorRED);
2952+
2953+
auto fontCollection = sk_make_sp<FontCollection>();
2954+
fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
2955+
2956+
TextStyle defaultStyle;
2957+
defaultStyle.setForegroundColor(paint);
2958+
2959+
ParagraphStyle paraStyle;
2960+
paraStyle.setTextStyle(defaultStyle);
2961+
paraStyle.setMaxLines(1);
2962+
paraStyle.setEllipsis(SkString("..."));
2963+
2964+
const char* hello = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do";
2965+
auto builder = ParagraphBuilder::make(paraStyle, fontCollection);
2966+
builder->addText(hello, strlen(hello));
2967+
2968+
auto paragraph = builder->Build();
2969+
paragraph->layout(100);
2970+
paragraph->paint(canvas, 200, 200);
2971+
2972+
paragraph->layout(200);
2973+
paragraph->paint(canvas, 200, 300);
2974+
2975+
ParagraphStyle paraStyle2;
2976+
paraStyle2.setTextStyle(defaultStyle);
2977+
paraStyle2.setMaxLines(1);
2978+
paraStyle.setEllipsis(SkString(""));
2979+
2980+
auto builder2 = ParagraphBuilder::make(paraStyle, fontCollection);
2981+
builder2->addText(hello, strlen(hello));
2982+
2983+
auto paragraph2 = builder2->Build();
2984+
paragraph2->layout(100);
2985+
paragraph2->paint(canvas, 200, 400);
2986+
2987+
paragraph2->layout(200);
2988+
paragraph2->paint(canvas, 200, 500);
2989+
canvas->restore();
2990+
}
2991+
2992+
private:
2993+
using INHERITED = Sample;
2994+
};
2995+
29422996
} // namespace
29432997

29442998
//////////////////////////////////////////////////////////////////////////////
@@ -2986,3 +3040,4 @@ DEF_SAMPLE(return new ParagraphView43();)
29863040
DEF_SAMPLE(return new ParagraphView44();)
29873041
DEF_SAMPLE(return new ParagraphView45();)
29883042
DEF_SAMPLE(return new ParagraphView46();)
3043+
DEF_SAMPLE(return new ParagraphView47();)

modules/skparagraph/src/ParagraphImpl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,9 @@ void ParagraphImpl::layout(SkScalar rawWidth) {
116116
fState >= kLineBroken &&
117117
fLines.size() == 1 && fLines.front().ellipsis() == nullptr) {
118118
// Most common case: one line of text (and one line is never justified, so no cluster shifts)
119+
// We cannot mark it as kLineBroken because the new width can be bigger than the old width
119120
fWidth = floorWidth;
120-
fState = kLineBroken;
121+
fState = kMarked;
121122
} else if (fState >= kLineBroken && fOldWidth != floorWidth) {
122123
// We can use the results from SkShaper but have to do EVERYTHING ELSE again
123124
fState = kShaped;

0 commit comments

Comments
 (0)