Skip to content

Commit bef4da1

Browse files
Rusinoskcq-be@skia-corp.google.com.iam.gserviceaccount.com
authored andcommitted
Revert "[skparagraph] Cap letter spacing line shift"
This reverts commit 9628428. Reason for revert: breaks the Flutter roll (flutter/flutter#196144). The web CanvasKit test SkParagraph kitchensink in canvaskit_api_test.dart pins LineMetrics.left == 2.5: its line starts with letterSpacing 5 and ends with plain "!", so the line shift is now 0 instead of 2.5, as intended. The test also has a golden (paragraph_kitchen_sink.png). Flutter will first accept both values, then this change relands. The revert had a conflict in SkParagraphTest.cpp with the next change (SkParagraph_LigatureWithUnresolvedMark); only the test of the reverted change is removed. Bug: flutter/flutter#184815 Assisted-by: Claude Opus 5.5 (Medium) Change-Id: I86d695b30f5daa9f945706c59bb5ddb4e9ce0369 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/1420816 Reviewed-by: Thomas Smith <[email protected]> Commit-Queue: Julia Lavrova <[email protected]> Reviewed-by: Brett Somocurcio <[email protected]>
1 parent 3a1af95 commit bef4da1

2 files changed

Lines changed: 0 additions & 144 deletions

File tree

‎modules/skparagraph/src/TextLine.cpp‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -222,23 +222,6 @@ TextLine::TextLine(ParagraphImpl* owner,
222222
break;
223223
}
224224
}
225-
// Glyphs of every run, right to left ones too, keep their whole letter spacing on their
226-
// right side, so the shift keeps the ink inside the line width only up to the half spacing
227-
// of the visually rightmost text cluster (same as with uniform spacing). Trailing
228-
// placeholders keep the shift (InlinePlaceholder tests pin it)
229-
if (fShift > 0) {
230-
for (auto visual = fRunsInVisualOrder.size(); visual > 0; --visual) {
231-
const Run& run = owner->run(fRunsInVisualOrder[visual - 1]);
232-
ClusterRange inLine = intersected(run.clusterRange(), fClusterRange);
233-
if (run.isPlaceholder() || inLine.width() == 0) {
234-
continue;
235-
}
236-
const Cluster& right =
237-
owner->cluster(run.leftToRight() ? inLine.end - 1 : inLine.start);
238-
fShift = std::min(fShift, std::max(right.getHalfLetterSpacing(), 0.0f));
239-
break;
240-
}
241-
}
242225
}
243226

244227
void TextLine::paint(ParagraphPainter* painter, SkScalar x, SkScalar y) {

‎modules/skparagraph/tests/SkParagraphTest.cpp‎

Lines changed: 0 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -12763,133 +12763,6 @@ DEF_TEST(SkParagraph_GlyphOffsetsOnlyWhenNeeded, reporter) {
1276312763
REPORTER_ASSERT(reporter, movedUpOrDown);
1276412764
}
1276512765

12766-
// Letter spacing is part of the cluster widths that line breaking and intrinsic widths add up,
12767-
// so a left aligned line must draw and report its glyphs inside that width, even when only the
12768-
// start of the line is letter spaced
12769-
DEF_TEST(SkParagraph_LetterSpacingStaysInsideLineWidth, reporter) {
12770-
sk_sp<ResourceFontCollection> fontCollection = sk_make_sp<ResourceFontCollection>();
12771-
SKIP_IF_FONTS_NOT_FOUND(reporter, fontCollection)
12772-
fontCollection->disableFontFallback();
12773-
12774-
TextStyle plain;
12775-
plain.setFontFamilies({SkString("Roboto"), SkString("Noto Naskh Arabic")});
12776-
plain.setFontSize(14);
12777-
plain.setColor(SK_ColorBLACK);
12778-
TextStyle spaced = plain;
12779-
spaced.setLetterSpacing(30);
12780-
TextStyle tight = plain;
12781-
tight.setLetterSpacing(-4);
12782-
12783-
using Segments = std::vector<std::pair<const TextStyle*, const char*>>;
12784-
auto build = [&](size_t maxLines, const Segments& segments, int count,
12785-
TextDirection direction = TextDirection::kLtr) {
12786-
ParagraphStyle paragraphStyle;
12787-
paragraphStyle.setTextStyle(plain);
12788-
paragraphStyle.setMaxLines(maxLines);
12789-
paragraphStyle.setTextDirection(direction);
12790-
// Right or centered lines replace the shift with the alignment offset
12791-
paragraphStyle.setTextAlign(TextAlign::kLeft);
12792-
ParagraphBuilderImpl builder(paragraphStyle, fontCollection, get_unicode());
12793-
for (int i = 0; i < count; ++i) {
12794-
for (auto& [style, text] : segments) {
12795-
builder.pushStyle(*style);
12796-
builder.addText(text);
12797-
builder.pop();
12798-
}
12799-
}
12800-
return builder.Build();
12801-
};
12802-
12803-
auto checkInside = [&](Paragraph* paragraph, SkScalar width, bool checkBoxes = true) {
12804-
const SkScalar epsilon = 0.01f;
12805-
SkScalar drawnLeft = 0;
12806-
SkScalar drawnRight = 0;
12807-
paragraph->visit([&](int, const Paragraph::VisitorInfo* info) {
12808-
if (!info) {
12809-
return;
12810-
}
12811-
std::vector<SkScalar> advances(SkToSizeT(info->count));
12812-
info->font.getWidths({info->glyphs, SkToSizeT(info->count)}, advances);
12813-
for (int i = 0; i < info->count; ++i) {
12814-
SkScalar x = info->origin.fX + info->positions[i].fX;
12815-
drawnLeft = std::min(drawnLeft, x);
12816-
drawnRight = std::max(drawnRight, x + advances[i]);
12817-
}
12818-
});
12819-
REPORTER_ASSERT(reporter, drawnLeft >= -epsilon, "%f", drawnLeft);
12820-
REPORTER_ASSERT(reporter, drawnRight <= width + epsilon, "%f > %f", drawnRight, width);
12821-
if (!checkBoxes) {
12822-
return;
12823-
}
12824-
auto boxes = paragraph->getRectsForRange(
12825-
0, 1000, RectHeightStyle::kTight, RectWidthStyle::kTight);
12826-
REPORTER_ASSERT(reporter, !boxes.empty());
12827-
for (auto& box : boxes) {
12828-
REPORTER_ASSERT(reporter, box.rect.fLeft >= -epsilon, "%f", box.rect.fLeft);
12829-
REPORTER_ASSERT(reporter, box.rect.fRight <= width + epsilon,
12830-
"%f > %f", box.rect.fRight, width);
12831-
}
12832-
};
12833-
12834-
// Lines end with plain text after letter spaced text; maxLines makes Flutter clip the text
12835-
// at the max intrinsic width
12836-
auto clipped = build(3, {{&spaced, "-1 12345"}, {&plain, "67890\n"}}, 5);
12837-
clipped->layout(1000);
12838-
REPORTER_ASSERT(reporter, clipped->didExceedMaxLines());
12839-
checkInside(clipped.get(), clipped->getMaxIntrinsicWidth());
12840-
checkInside(clipped.get(), clipped->getLongestLine());
12841-
12842-
// A letter spaced start followed by a long plain word that wraps at the paragraph width
12843-
auto wrapped = build(std::numeric_limits<size_t>::max(),
12844-
{{&spaced, "12345"},
12845-
{&plain, "678901234567890123456789012345678901234567890"}}, 1);
12846-
wrapped->layout(300);
12847-
REPORTER_ASSERT(reporter, wrapped->lineNumber() > 1);
12848-
checkInside(wrapped.get(), 300);
12849-
12850-
// The line ends with negative letter spacing, which must not move the line left; the last
12851-
// glyph still draws its whole advance, 4 px past its tight cell
12852-
auto negative = build(1, {{&spaced, "12345"}, {&tight, "67890"}}, 1);
12853-
negative->layout(1000);
12854-
checkInside(negative.get(), negative->getMaxIntrinsicWidth() + 4);
12855-
12856-
// The line ends with a cursive script, which gets no letter spacing
12857-
auto cursive = build(1, {{&spaced, "12345 \u0645\u0631\u062D\u0628\u0627"}}, 1);
12858-
cursive->layout(1000);
12859-
checkInside(cursive.get(), cursive->getMaxIntrinsicWidth());
12860-
12861-
// Glyphs of right to left runs are laid out left to right too, each with its spacing on the
12862-
// right, so the visually rightmost cluster decides whether the shift fits
12863-
const char* spacedHebrew = "\u05D0\u05D1\u05D2\u05D3\u05D4";
12864-
const char* plainHebrew = "\u05D5\u05D6\u05D7\u05D8\u05D9";
12865-
auto drawnLeft = [](Paragraph* paragraph) {
12866-
SkScalar left = SK_ScalarMax;
12867-
paragraph->visit([&](int, const Paragraph::VisitorInfo* info) {
12868-
if (info) {
12869-
left = std::min(left, info->origin.fX + info->positions[0].fX);
12870-
}
12871-
});
12872-
return left;
12873-
};
12874-
12875-
// Right to left text with a letter spaced logical start: that start is the visually
12876-
// rightmost cluster, so the line fits with the shift and keeps it. Only the ink is checked:
12877-
// the box of a right to left cluster includes its spacing even at the visual line end
12878-
auto rtl = build(1, {{&spaced, spacedHebrew}, {&plain, plainHebrew}}, 1,
12879-
TextDirection::kRtl);
12880-
rtl->layout(1000);
12881-
checkInside(rtl.get(), rtl->getMaxIntrinsicWidth(), /*checkBoxes=*/false);
12882-
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(drawnLeft(rtl.get()), 15), "%f",
12883-
drawnLeft(rtl.get()));
12884-
12885-
// A right to left run at the end of a left to right line, letter spaced only at its logical
12886-
// end: its visually rightmost cluster is plain
12887-
auto mixed = build(1, {{&spaced, "12345"}, {&plain, plainHebrew}, {&spaced, spacedHebrew}},
12888-
1);
12889-
mixed->layout(1000);
12890-
checkInside(mixed.get(), mixed->getMaxIntrinsicWidth());
12891-
}
12892-
1289312766
// When an unresolved combining mark attaches to the non-initial codepoint of a multi-char
1289412767
// ligature, clusteredText must expand both the glyph range and text range to the whole ligature
1289512768
DEF_TEST(SkParagraph_LigatureWithUnresolvedMark, reporter) {

0 commit comments

Comments
 (0)