Skip to content

test(richtextblock): Pin geometry and hit-testing against native WinUI - #26724

Open
mikernet wants to merge 2 commits into
unoplatform:masterfrom
mikernet:dev/mikernet/richtextblock-geometry-tests
Open

mikernet wants to merge 2 commits into
unoplatform:masterfrom
mikernet:dev/mikernet/richtextblock-geometry-tests

Conversation

@mikernet

@mikernet mikernet commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

GitHub Issue: part of #24339 (epic: #26728)

PR Type:

💬 Other: tests only, no product change.

What changed? 🚀

I'm about to move RichTextBlock from the legacy ParsedText engine to UnicodeText (tracked in #24339). Before touching the engine, this PR adds the regression net that change has to pass: tests that pin what RichTextBlock already gets right today, checked against native WinUI.

New: Given_RichTextBlock_Geometry (15 cases, run on Skia and on native WinUI)

  • When_CharacterRect_On_Ink, 6 LTR rows (left, center, right, padding, two paragraphs, wrapped). On every line:

    • the first and last TextPointer.GetCharacterRect lie within 4 px of the drawn ink's left and right edges;
    • the ink is where the line belongs, also within 4 px: at the left edge for the Left rows, centered for Center, at the right edge for Right, and for Padding (a wrapping paragraph) starting at the left padding and ending before the right padding.

    Both checks are relations, not coordinates, so they don't depend on the font.

  • When_GetPositionFromPoint_Beside_Line(01-plain): a point left of an LTR line maps to its reading start, a point right of it to its reading end.

  • When_Line_Heights_Match_WinUI, rows H1, H4, H7 and H9 (plain, LineHeight 40 with MaxHeight, LineHeight 10 with BlockLineHeight over two lines, TextLineBounds.Tight): desired height and BaselineOffset, ±1 px, against values measured on native WinUI.

  • When_Line_Height_With_Fallback_Font_Matches_WinUI (H3): Latin plus CJK must not grow the line. It needs a CJK fallback font, so it only runs on Skia Win32 and native WinUI.

  • When_Object_Only_Paragraph_Keeps_Following_Paragraphs: a paragraph holding only an InlineUIContainer doesn't stop the paragraph after it from being laid out and drawn, and that paragraph is drawn below the object, not over it.

  • When_Object_At_Page_Break(false|true): with a linked RichTextBlockOverflow, an inline object is drawn exactly once, on the page that holds its line.

Rewritten without the ParsedText oracle (4 cases, Skia only, since they use Uno internals)

  • Given_SkiaTextFormatter becomes Given_TextFormatter. Its tests used to feed the formatter a hand-made ISkiaParagraphSource and compare its lines with a direct ParsedText.ParseText call. They now take the formatter, ParagraphTextSource and paragraph properties the layout tree itself builds, and go through the TextFormatter contract only, so they keep holding when the engine behind the formatter changes:
    • When_FormatLine_Vends_All_Lines, which checks that:

      • the lines cover the paragraph, none is empty, each fits the wrapping width, and only the last one has no break;
      • no line breaks early: each line plus the next line's first word, laid out on its own without wrapping, is wider than the wrapping width;
      • the control's desired width is the widest line, and its height is the sum of the line heights.

      Lines are formatted from where the previous one ended, as ParagraphNode does.

    • When_Paragraph_Properties_Change_At_Same_Width and When_Clusters_Span_Several_Code_Units: same assertions as before, on the real pipeline.

  • Given_BlockLayoutEngine.When_Measure_Single_Paragraph_Matches_ParsedText becomes When_Measure_Single_Paragraph: the page's desired width and height now come from the formatter's own lines, not from ParsedText.

What the rewrites no longer check. The oracle gave an independent expectation for every line: the line count and each line's width and height came from a second layout of the same text. The rewrites can't do that without a second engine. They check the lines against each other, against the wrapping width, against the next word, and against the control's size. So a formatter whose lines are all consistently off by the same amount, for example all slightly too tall, would still pass them. Such a change would still show in the WinUI-backed geometry and height tests above.

Validation

Runtime, Skia Desktop (Win32):

  • The 19 new and rewritten cases pass, in 3 runs out of 3 (each run also includes the 2 unchanged Given_BlockLayoutEngine cases, 21 in all).

  • The RichTextBlock group (Given_RichTextBlock|Given_SkiaTextFormatter|Given_TextFormatter|Given_BlockLayoutEngine|Given_HyperlinkAutomation): 222 of 222 pass. Against a master run of the same group (207 of 207), no case went from pass to fail. The only cases gone are the 4 replaced ones, and the 19 added cases all pass.

  • Each test can fail. I added temporary product changes, switched by an environment variable, and checked that every test and every anchor fails under its own:

    • character rects moved 8 px;
    • alignment forced to Left (Center and Right anchors) or to Center (Left and Padding anchors), which moves the rects and the ink together;
    • a negative right padding (right-padding anchor);
    • a hit past the line end returned at the line start;
    • lines 3 px taller;
    • a page that stops at a one-position paragraph;
    • the second paragraph drawn at the top of the control (drawn over the object);
    • inline objects arranged off-screen, or left where they would be drawn twice;
    • a formatter that drops the last line, wraps at 60% of the width (the early-break check), ignores NoWrap or splits a surrogate pair;
    • a page 3 px taller than its lines.

    I then reverted them.

Runtime, native WinUI (WinAppSDK): the 15 cases of Given_RichTextBlock_Geometry pass. The ink anchors hold on WinUI with the same 4 px tolerance.

Compile: the runtime tests project builds with analyzers and code style on, with no warning or error.

Not in this PR: RTL, justified text, trailing spaces, links beside a line and the other line-height rows (H2, H5, H6, H8): they fail on master today, so they come with the engine change.

PR Checklist ✅

Character rects on the ink and the line where its alignment and padding put it, the position beside a line, line heights, and inline objects across paragraphs and page breaks, with values that match native WinUI. These are the regression net for moving RichTextBlock to another text engine.
…acle

Given_SkiaTextFormatter becomes Given_TextFormatter and drives the real ParagraphTextSource and formatter through the TextFormatter contract, including a check that no line breaks before the next word would overflow. Given_BlockLayoutEngine compares the page with the formatter's own lines. Both keep holding when the engine behind the formatter changes.
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@github-actions github-actions Bot added the area/skia ✏️ Categorizes an issue or PR as relevant to Skia label Nov 25, 2026
@mergify

mergify Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request once it meets the queue conditions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/skia ✏️ Categorizes an issue or PR as relevant to Skia

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant