@@ -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
1289512768DEF_TEST(SkParagraph_LigatureWithUnresolvedMark, reporter) {
0 commit comments