Skip to content

Commit 3f1503a

Browse files
rphilliskcq-be@skia-corp.google.com.iam.gserviceaccount.com
authored andcommitted
Revert "[skparagraph] Use surrounding run's bidi level in shapeEllipsis"
This reverts commit fcf3a18. Reason for revert: checking to see if this is breaking builds on the tree Failure Link: checking to see if this is breaking builds on the tree Original change's description: > [skparagraph] Use surrounding run's bidi level in shapeEllipsis > > shapeEllipsis passed SkBidiIterator::kLTR to its internal > BidiRunIterator regardless of the surrounding paragraph's direction, > so in RTL text the affix's neutral and weak characters resolved LTR. > For the default "-" and "…" this only gives the shaped run the wrong > bidi level; the glyphs are the same. But a custom ellipsis that mixes > RTL letters with a neutral, such as "النهاية!", is split into two > bidi runs (the "!" resolves LTR), and ShapeHandler supports only one: > debug builds fail SkASSERT(!fRun), and release builds keep only the > last run. > > The fix uses the bidi level of the surrounding cluster's run, which > is already in scope via the existing 'cluster' parameter. Both call > sites (createEllipsis, createSoftHyphen) pass the cluster adjacent > to the break, so the affix inherits the correct direction at the > shaping boundary. > > This also unblocks a follow-up that exposes a configurable soft > hyphen string, and addresses reviewer feedback on the Flutter design > doc for flutter/flutter#18443. > > Tests: > - SkParagraph_SoftHyphenRTLBidiLevel / SoftHyphenLTRBidiLevel assert > the shaped hyphen run's bidi level matches the paragraph context. > - SkParagraph_EllipsisRTLCustomStringBidiLevel uses "النهاية!" as a > custom ellipsis in an RTL paragraph (hits the SkASSERT without > this change). > - SkParagraph_EllipsisLTRDefaultBidiLevel guards the common LTR > path against regression. > > GM: > - paragraph_ellipsis_bidi adds Skia Gold visual coverage across > LTR/RTL x default/custom affix combinations. > > [email protected], [email protected] > > Change-Id: Id51f71e4506272662a95baae197bca808d27e7d1 > Bug: flutter/flutter#189617 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/1217709 > Reviewed-by: Julia Lavrova <[email protected]> > Auto-Submit: David H Bebawy <[email protected]> > Commit-Queue: Alexis Cruz-Ayala <[email protected]> > Reviewed-by: Alexis Cruz-Ayala <[email protected]> Bug: flutter/flutter#189617 No-Presubmit: true No-Tree-Checks: true No-Try: true Change-Id: Ia6f217051a1815171e14b29321ec46d065ce4b54 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/1394356 Commit-Queue: Robert Phillips <[email protected]> Reviewed-by: Robert Phillips <[email protected]> Bot-Commit: [email protected] <[email protected]>
1 parent 5e1ccee commit 3f1503a

5 files changed

Lines changed: 3 additions & 313 deletions

File tree

‎modules/skparagraph/BUILD.gn‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ if (skia_enable_skparagraph && skia_enable_skshaper && skia_enable_skunicode &&
5454
if (paragraph_gms_enabled &&
5555
(skia_use_icu || skia_use_libgrapheme || skia_use_icu4x)) {
5656
testonly = true
57-
sources = [
58-
"gm/ellipsis_bidi_gm.cpp",
59-
"gm/simple_gm.cpp",
60-
]
57+
sources = [ "gm/simple_gm.cpp" ]
6158
deps = [
6259
":skparagraph",
6360
"../..:skia",

‎modules/skparagraph/gm/ellipsis_bidi_gm.cpp‎

Lines changed: 0 additions & 149 deletions
This file was deleted.

‎modules/skparagraph/src/Run.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ class Run {
9494
SkScalar correctLeading() const { return fCorrectLeading; }
9595
const SkFont& font() const { return fFont; }
9696
bool leftToRight() const { return fBidiLevel % 2 == 0; }
97-
uint8_t bidiLevel() const { return fBidiLevel; }
9897
TextDirection getTextDirection() const { return leftToRight() ? TextDirection::kLtr : TextDirection::kRtl; }
9998
size_t index() const { return fIndex; }
10099
SkScalar heightMultiplier() const { return fHeightMultiplier; }

‎modules/skparagraph/src/TextLine.cpp‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -767,18 +767,12 @@ std::unique_ptr<Run> TextLine::shapeEllipsis(const SkString& ellipsis,
767767
std::unique_ptr<SkShaper> shaper = SkShapers::HB::ShapeDontWrapOrReorder(
768768
fOwner->getUnicode(), fallback ? fallback : SkFontMgr::RefEmpty());
769769

770-
// Shape the affix with the surrounding run's bidi level, so neutral and
771-
// weak characters in a custom affix (like a "!" after Arabic letters)
772-
// take the surrounding direction instead of LTR. Resolved as LTR, they
773-
// can split the affix into two bidi runs, which ShapeHandler doesn't
774-
// support. The default "-" (ES-class) and "…" (ON-class) produce the
775-
// same glyphs regardless of the level.
776-
const SkBidiIterator::Level bidiLevel = run.bidiLevel();
770+
const SkBidiIterator::Level defaultLevel = SkBidiIterator::kLTR;
777771
const char* utf8 = ellipsis.c_str();
778772
size_t utf8Bytes = ellipsis.size();
779773

780774
std::unique_ptr<SkShaper::BiDiRunIterator> bidi = SkShapers::unicode::BidiRunIterator(
781-
fOwner->getUnicode(), utf8, utf8Bytes, bidiLevel);
775+
fOwner->getUnicode(), utf8, utf8Bytes, defaultLevel);
782776
SkASSERT(bidi);
783777

784778
std::unique_ptr<SkShaper::LanguageRunIterator> language =

‎modules/skparagraph/tests/SkParagraphTest.cpp‎

Lines changed: 0 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -9086,157 +9086,6 @@ UNIX_ONLY_TEST(SkParagraph_SoftHyphenRTL, reporter) {
90869086
REPORTER_ASSERT(reporter, firstLine.width() > firstLine.widthWithoutEllipsis());
90879087
}
90889088

9089-
// Soft hyphen affix must be shaped at the bidi level of the run it follows, not
9090-
// a hardcoded LTR level. In an RTL paragraph the last cluster before the break
9091-
// is RTL, so the shaped hyphen run must report leftToRight() == false.
9092-
UNIX_ONLY_TEST(SkParagraph_SoftHyphenRTLBidiLevel, reporter) {
9093-
sk_sp<ResourceFontCollection> fontCollection = sk_make_sp<ResourceFontCollection>(true);
9094-
SKIP_IF_FONTS_NOT_FOUND(reporter, fontCollection)
9095-
9096-
// Arabic "كلمة\u00ADطويلة" — same text as SkParagraph_SoftHyphenRTL.
9097-
const char* text =
9098-
"\xD9\x83\xD9\x84\xD9\x85\xD8\xA9"
9099-
"\xC2\xAD"
9100-
"\xD8\xB7\xD9\x88\xD9\x8A\xD9\x84\xD8\xA9";
9101-
9102-
ParagraphStyle paragraph_style;
9103-
paragraph_style.turnHintingOff();
9104-
paragraph_style.setRenderSoftHyphens(true);
9105-
paragraph_style.setTextDirection(TextDirection::kRtl);
9106-
ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
9107-
9108-
TextStyle text_style;
9109-
text_style.setFontFamilies({SkString("Noto Naskh Arabic")});
9110-
text_style.setFontSize(20);
9111-
text_style.setColor(SK_ColorBLACK);
9112-
builder.pushStyle(text_style);
9113-
builder.addText(text, strlen(text));
9114-
builder.pop();
9115-
9116-
auto paragraph = builder.Build();
9117-
paragraph->layout(40);
9118-
9119-
auto impl = static_cast<ParagraphImpl*>(paragraph.get());
9120-
REPORTER_ASSERT(reporter, !impl->lines().empty());
9121-
9122-
auto& firstLine = impl->lines()[0];
9123-
REPORTER_ASSERT(reporter, firstLine.hyphen() != nullptr);
9124-
if (firstLine.hyphen() == nullptr) return;
9125-
// The shaped hyphen run inherits the surrounding cluster's bidi level.
9126-
REPORTER_ASSERT(reporter, !firstLine.hyphen()->leftToRight());
9127-
REPORTER_ASSERT(reporter, (firstLine.hyphen()->bidiLevel() % 2) == 1);
9128-
}
9129-
9130-
// Regression guard: the default LTR case must still produce an LTR hyphen run.
9131-
UNIX_ONLY_TEST(SkParagraph_SoftHyphenLTRBidiLevel, reporter) {
9132-
sk_sp<ResourceFontCollection> fontCollection = sk_make_sp<ResourceFontCollection>(true);
9133-
SKIP_IF_FONTS_NOT_FOUND(reporter, fontCollection)
9134-
9135-
const char* text =
9136-
"inter\xC2\xAD"
9137-
"national";
9138-
9139-
ParagraphStyle paragraph_style;
9140-
paragraph_style.turnHintingOff();
9141-
paragraph_style.setRenderSoftHyphens(true);
9142-
ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
9143-
9144-
TextStyle text_style;
9145-
text_style.setFontFamilies({SkString("Roboto")});
9146-
text_style.setFontSize(20);
9147-
text_style.setColor(SK_ColorBLACK);
9148-
builder.pushStyle(text_style);
9149-
builder.addText(text, strlen(text));
9150-
builder.pop();
9151-
9152-
auto paragraph = builder.Build();
9153-
paragraph->layout(80);
9154-
9155-
auto impl = static_cast<ParagraphImpl*>(paragraph.get());
9156-
REPORTER_ASSERT(reporter, !impl->lines().empty());
9157-
9158-
auto& firstLine = impl->lines()[0];
9159-
REPORTER_ASSERT(reporter, firstLine.hyphen() != nullptr);
9160-
if (firstLine.hyphen() == nullptr) return;
9161-
REPORTER_ASSERT(reporter, firstLine.hyphen()->leftToRight());
9162-
REPORTER_ASSERT(reporter, (firstLine.hyphen()->bidiLevel() % 2) == 0);
9163-
REPORTER_ASSERT(reporter, firstLine.hyphen()->advance().fX > 0);
9164-
}
9165-
9166-
// Custom ellipsis strings must be shaped in the surrounding bidi context. With
9167-
// a hardcoded LTR level, the trailing "!" of an Arabic custom ellipsis resolves
9168-
// LTR and splits the ellipsis into two bidi runs, which shapeEllipsis doesn't
9169-
// support (it expects a single run).
9170-
UNIX_ONLY_TEST(SkParagraph_EllipsisRTLCustomStringBidiLevel, reporter) {
9171-
sk_sp<ResourceFontCollection> fontCollection = sk_make_sp<ResourceFontCollection>(true);
9172-
SKIP_IF_FONTS_NOT_FOUND(reporter, fontCollection)
9173-
9174-
TextStyle text_style;
9175-
text_style.setFontFamilies({SkString("Noto Naskh Arabic"), SkString("Roboto")});
9176-
text_style.setFontSize(40);
9177-
text_style.setColor(SK_ColorBLACK);
9178-
9179-
ParagraphStyle paragraph_style;
9180-
paragraph_style.setTextStyle(text_style);
9181-
paragraph_style.setTextDirection(TextDirection::kRtl);
9182-
// Arabic word "النهاية" (nihaya = "the end") plus "!", used as a custom ellipsis.
9183-
paragraph_style.setEllipsis(u"\u0627\u0644\u0646\u0647\u0627\u064A\u0629!");
9184-
paragraph_style.setMaxLines(1);
9185-
9186-
ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
9187-
builder.pushStyle(text_style);
9188-
builder.addText(u"\u062A\u0638\u0627\u0647\u0631\u0627\u062A \u0648 \u062A\u062C\u0645\u0639\u0627\u062A");
9189-
auto paragraph = builder.Build();
9190-
// Layout width chosen so that (a) the paragraph text (about 270px wide)
9191-
// exceeds it and truncation is forced, and (b) the custom Arabic ellipsis
9192-
// comfortably fits — otherwise shapeEllipsis falls back to "ellipsis did
9193-
// not fit" and line.ellipsis() is nullptr, which would mask the regression
9194-
// being tested.
9195-
paragraph->layout(200);
9196-
9197-
auto impl = static_cast<ParagraphImpl*>(paragraph.get());
9198-
REPORTER_ASSERT(reporter, paragraph->lineNumber() == 1);
9199-
auto& line = impl->lines()[0];
9200-
REPORTER_ASSERT(reporter, line.ellipsis() != nullptr);
9201-
if (line.ellipsis() == nullptr) return;
9202-
// Surrounded by RTL Arabic content; the ellipsis must be shaped as RTL.
9203-
REPORTER_ASSERT(reporter, !line.ellipsis()->leftToRight());
9204-
REPORTER_ASSERT(reporter, (line.ellipsis()->bidiLevel() % 2) == 1);
9205-
REPORTER_ASSERT(reporter, line.ellipsis()->advance().fX > 0);
9206-
}
9207-
9208-
// Regression guard for the common path: default "…" (ON-class) ellipsis in an
9209-
// LTR paragraph must still produce an LTR ellipsis run.
9210-
UNIX_ONLY_TEST(SkParagraph_EllipsisLTRDefaultBidiLevel, reporter) {
9211-
sk_sp<ResourceFontCollection> fontCollection = sk_make_sp<ResourceFontCollection>(true);
9212-
SKIP_IF_FONTS_NOT_FOUND(reporter, fontCollection)
9213-
9214-
TextStyle text_style;
9215-
text_style.setFontFamilies({SkString("Roboto")});
9216-
text_style.setFontSize(20);
9217-
text_style.setColor(SK_ColorBLACK);
9218-
9219-
ParagraphStyle paragraph_style;
9220-
paragraph_style.setTextStyle(text_style);
9221-
paragraph_style.setEllipsis(u"\u2026");
9222-
paragraph_style.setMaxLines(1);
9223-
9224-
ParagraphBuilderImpl builder(paragraph_style, fontCollection, get_unicode());
9225-
builder.pushStyle(text_style);
9226-
builder.addText("The quick brown fox jumps over the lazy dog");
9227-
auto paragraph = builder.Build();
9228-
paragraph->layout(100);
9229-
9230-
auto impl = static_cast<ParagraphImpl*>(paragraph.get());
9231-
REPORTER_ASSERT(reporter, paragraph->lineNumber() == 1);
9232-
auto& line = impl->lines()[0];
9233-
REPORTER_ASSERT(reporter, line.ellipsis() != nullptr);
9234-
if (line.ellipsis() == nullptr) return;
9235-
REPORTER_ASSERT(reporter, line.ellipsis()->leftToRight());
9236-
REPORTER_ASSERT(reporter, (line.ellipsis()->bidiLevel() % 2) == 0);
9237-
REPORTER_ASSERT(reporter, line.ellipsis()->advance().fX > 0);
9238-
}
9239-
92409089
// Verify that with the default (setRenderSoftHyphens(false)), no visible hyphen
92419090
// is rendered even when the line break occurs at a soft hyphen position.
92429091
UNIX_ONLY_TEST(SkParagraph_SoftHyphenDefaultOff, reporter) {

0 commit comments

Comments
 (0)