Skip to content

test(render): cover text-state invalidation around inline graphics#202

Merged
DemchaAV merged 1 commit into
developfrom
test/paragraph-textstate-invalidation
Jun 16, 2026
Merged

test(render): cover text-state invalidation around inline graphics#202
DemchaAV merged 1 commit into
developfrom
test/paragraph-textstate-invalidation

Conversation

@DemchaAV

Copy link
Copy Markdown
Owner

Why

PdfParagraphFragmentRenderHandler tracks the last-written font and
non-stroking colour within a paragraph's q...Q block so a single-style
paragraph emits one Tf/rg instead of one per span. After an inline image
or shape it calls TextRenderState.invalidate(), because the graphic ends the
text block and runs its own graphics-state/colour ops — so the next text span
must re-emit Tf/rg rather than trust the disturbed state. ParagraphTextStateDedupTest
covered single-style dedup (one Tf) and multi-style re-emit (≥2 Tf) but
never paired same-style text across an inline graphic — the exact path the
invalidate() guards. A dropped invalidate() would render the trailing text
in whatever font/colour the graphic left set and no test would catch it.

What changed

Added two cases: same-style text on both sides of an inline shape, and of an
inline image, each asserting two setFont operators. Both use the rich-text
builder (p.rich(r -> r.plain(...).diamond(...)/.image(...).plain(...))) so the
runs keep their declared [text, graphic, text] order — the ParagraphBuilder
text()/shape() chain collapses the text into one field, which is why the rich
seam is the right surface here. Test-only; no production change.

Verification

  • ./mvnw test -pl . → BUILD SUCCESS, 1387 tests, 0 failures.
  • Mutation-checked: removing both textState.invalidate() calls collapses the
    operator count to one and fails both new cases while the two existing dedup
    cases stay green — confirming each case drives its own invalidate site.

Lane: canonical (document.backend.fixed.pdf render guard). No public API change.

The paragraph render handler invalidates its tracked font/colour after an
inline image or shape so the following text span re-emits Tf/rg rather than
trusting state the graphic disturbed. ParagraphTextStateDedupTest covered
single-style dedup and multi-style re-emit but never paired same-style text
across an inline graphic — the exact case the invalidate guards. Add a shape
case and an image case (same-style text on both sides of the graphic) that
assert two setFont operators. Both use the rich-text builder so the runs keep
their declared [text, graphic, text] order. Mutation-checked: removing either
invalidate() collapses the count to one and fails the matching case.
@DemchaAV DemchaAV merged commit 8551dfe into develop Jun 16, 2026
11 checks passed
@DemchaAV DemchaAV deleted the test/paragraph-textstate-invalidation branch June 16, 2026 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant