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

Commit 1b44330

Browse files
RusinoSkia Commit-Bot
authored andcommitted
Placeholder at the end of the text right before \n.
Bug: skia:10838 Change-Id: I0f6ebe442d67ba4c91cbef4fcaec6dea02739d34 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/327339 Reviewed-by: Ben Wagner <bungeman@google.com> Commit-Queue: Julia Lavrova <jlavrova@google.com>
1 parent d6cf56f commit 1b44330

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

modules/skparagraph/samples/SampleParagraph.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3056,6 +3056,40 @@ class ParagraphView48 : public ParagraphView_Base {
30563056
using INHERITED = Sample;
30573057
};
30583058

3059+
class ParagraphView49 : public ParagraphView_Base {
3060+
protected:
3061+
SkString name() override { return SkString("Paragraph49"); }
3062+
3063+
void onDrawContent(SkCanvas* canvas) override {
3064+
canvas->clear(SK_ColorGRAY);
3065+
auto fontCollection = getFontCollection();
3066+
fontCollection->disableFontFallback();
3067+
const char* text = "AAAAAAAAA\n";
3068+
3069+
ParagraphStyle paragraph_style;
3070+
TextStyle text_style;
3071+
text_style.setColor(SK_ColorBLACK);
3072+
text_style.setFontFamilies({SkString("Roboto"), SkString("Noto Serif CJK JP")});
3073+
text_style.setFontSize(16);
3074+
ParagraphBuilderImpl builder(paragraph_style, fontCollection);
3075+
builder.pushStyle(text_style);
3076+
builder.addText(text);
3077+
PlaceholderStyle placeholder_style;
3078+
placeholder_style.fHeight = 42;
3079+
placeholder_style.fWidth = 45;
3080+
placeholder_style.fBaselineOffset = 42;
3081+
placeholder_style.fBaseline = TextBaseline::kAlphabetic;
3082+
placeholder_style.fAlignment = PlaceholderAlignment::kBottom;
3083+
builder.addPlaceholder(placeholder_style);
3084+
auto paragraph = builder.Build();
3085+
paragraph->layout(360);
3086+
paragraph->paint(canvas, 0, 0);
3087+
}
3088+
3089+
private:
3090+
using INHERITED = Sample;
3091+
};
3092+
30593093
} // namespace
30603094

30613095
//////////////////////////////////////////////////////////////////////////////
@@ -3105,3 +3139,4 @@ DEF_SAMPLE(return new ParagraphView45();)
31053139
DEF_SAMPLE(return new ParagraphView46();)
31063140
DEF_SAMPLE(return new ParagraphView47();)
31073141
DEF_SAMPLE(return new ParagraphView48();)
3142+
DEF_SAMPLE(return new ParagraphView49();)

modules/skparagraph/src/TextWrapper.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,14 @@ void TextWrapper::lookAhead(SkScalar maxWidth, Cluster* endOfClusters) {
105105

106106
// It also creates a separate word; it does not count in fMinIntrinsicWidth
107107
fWords.extend(cluster);
108-
continue;
109-
}
110-
111-
fClusters.extend(cluster);
108+
} else {
109+
fClusters.extend(cluster);
112110

113-
// Keep adding clusters/words
114-
if (fClusters.endOfWord()) {
115-
fMinIntrinsicWidth = std::max(fMinIntrinsicWidth, getClustersTrimmedWidth());
116-
fWords.extend(fClusters);
111+
// Keep adding clusters/words
112+
if (fClusters.endOfWord()) {
113+
fMinIntrinsicWidth = std::max(fMinIntrinsicWidth, getClustersTrimmedWidth());
114+
fWords.extend(fClusters);
115+
}
117116
}
118117

119118
if ((fHardLineBreak = cluster->isHardBreak())) {

0 commit comments

Comments
 (0)