Skip to content

Commit c5f9953

Browse files
dbebawyskcq-be@skia-corp.google.com.iam.gserviceaccount.com
authored andcommitted
[skparagraph] Count only soft hyphens when measuring too-long words
https://skia-review.googlesource.com/c/skia/+/1398738 made the too-long-word check in TextWrapper::lookAhead count the width of the cluster at a soft break before stopping, so that a letter-spaced soft hyphen counts. That applied to every other soft break too, including the end of the text, so a too-long word at the end of a paragraph is now split on the current line instead of first moving to the next line. That broke a Flutter test (DropdownMenuEntries do not overflow when width is specified) and the Skia rolls into Flutter (flutter/flutter#195089, flutter/flutter#195098). Count the cluster only when it's a soft hyphen. Other soft breaks again end the word before their cluster, as before 1398738. [email protected], [email protected] Bug: flutter/flutter#194582 Change-Id: Ied1e5b3b0be915952fac798002d57fba972fb5ae Reviewed-on: https://skia-review.googlesource.com/c/skia/+/1403136 Reviewed-by: Julia Lavrova <[email protected]> Commit-Queue: Julia Lavrova <[email protected]> Reviewed-by: Brandon Wilson <[email protected]>
1 parent 93bf31b commit c5f9953

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

‎modules/skparagraph/src/TextWrapper.cpp‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ void TextWrapper::lookAhead(SkScalar maxWidth,
144144
if (further->isHardBreak() || further->isWhitespaceBreak()) {
145145
break;
146146
}
147+
if (further->isSoftBreak() && !further->isSoftHyphen()) {
148+
// Other soft breaks, such as the end of the text, end the word before this
149+
// cluster; only a soft hyphen's own (letter-spaced) width counts here
150+
break;
151+
}
147152
if (further->run().isPlaceholder()) {
148153
// Placeholder ends the word
149154
break;

‎modules/skparagraph/tests/SkParagraphTest.cpp‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11155,6 +11155,35 @@ UNIX_ONLY_TEST(SkParagraph_SoftHyphenFallbackFontWidth, reporter) {
1115511155
minWidth);
1115611156
}
1115711157

11158+
// Only a soft hyphen's own width changes how a too-long word is measured. Other soft breaks, such
11159+
// as the end of the text, still end the word before their cluster, so a word too long for the
11160+
// line at the end of the text moves to the next line before it's split, as it always has
11161+
// (Flutter's DropdownMenu tests depend on this). With Ahem, every glyph is 10px wide, so each
11162+
// 56px line holds 5 glyphs
11163+
UNIX_ONLY_TEST(SkParagraph_TooLongWordAtEndOfTextBreaksAsBefore, reporter) {
11164+
sk_sp<ResourceFontCollection> fontCollection = sk_make_sp<ResourceFontCollection>();
11165+
SKIP_IF_FONTS_NOT_FOUND(reporter, fontCollection)
11166+
11167+
for (bool renderSoftHyphens : {false, true}) {
11168+
ParagraphStyle paragraphStyle;
11169+
paragraphStyle.turnHintingOff();
11170+
paragraphStyle.setApplyRoundingHack(false);
11171+
paragraphStyle.setRenderSoftHyphens(renderSoftHyphens);
11172+
ParagraphBuilderImpl builder(paragraphStyle, fontCollection, get_unicode());
11173+
TextStyle textStyle;
11174+
textStyle.setFontFamilies({SkString("Ahem")});
11175+
textStyle.setFontSize(10);
11176+
textStyle.setColor(SK_ColorBLACK);
11177+
builder.pushStyle(textStyle);
11178+
const char* text = "n twelve";
11179+
builder.addText(text, strlen(text));
11180+
builder.pop();
11181+
auto paragraph = builder.Build();
11182+
paragraph->layout(56);
11183+
checkLines(reporter, paragraph.get(), "n|twelv|e");
11184+
}
11185+
}
11186+
1115811187
#if defined(SK_UNICODE_ICU_IMPLEMENTATION)
1115911188
UNIX_ONLY_TEST(SkParagraph_ICU_EmojiRuns, reporter) {
1116011189
SkUnicode_Emoji(SkUnicodes::ICU::Make(), reporter);

0 commit comments

Comments
 (0)