Skip to content

refactor(painters/dom): unify drawing block rendering (SD-2838)#3334

Open
luccas-harbour wants to merge 7 commits into
luccas/sd-2838-unify-image-block-renderingfrom
luccas/sd-2838-unify-drawing-block-rendering
Open

refactor(painters/dom): unify drawing block rendering (SD-2838)#3334
luccas-harbour wants to merge 7 commits into
luccas/sd-2838-unify-image-block-renderingfrom
luccas/sd-2838-unify-drawing-block-rendering

Conversation

@luccas-harbour
Copy link
Copy Markdown
Contributor

Summary

Builds on the image-block unification (parent branch luccas/sd-2838-unify-image-block-rendering) by collapsing the remaining drawing-rendering duplication between DomPainter and renderTableCell onto a single implementation. Non-image drawings (vector shapes, shape groups, charts, shape text) now render through the same code path in body content and table cells, and the table-cell drawing wrapper is no longer reinvented for in-flow vs. anchored cases.

What changed

New modules in painters/dom/src/drawings/:

  • renderDrawingContent.ts — extracts ~890 lines of vector-shape / chart / shape-group / shape-text rendering (preset + custom geometry, gradient/alpha fills, line ends, fallback styles, shape text layout) out of DomPainter into a pure function. Accepts doc, block, optional geometry, optional clipContainer, and a buildImageHyperlinkAnchor callback — no painter coupling.
  • renderDrawingFragment.ts — moves renderDrawingFragment and isHeaderWordArtWatermark out of DomPainter; the painter now passes its frame/anchor helpers (applyResolvedFragmentFrame, applyFragmentFrame, applyFragmentWrapperZIndex, createErrorPlaceholder) in as parameters.
  • tableDrawingFrame.ts — single helper that builds the table-cell drawing wrapper for both position: relative (in-flow) and position: absolute (anchored) drawings, deduplicating the wrapper/inner/SDT-dataset scaffolding that previously existed twice in renderTableCell.
  • placeholder.ts — small shared factory for the diagonal-stripe drawing placeholder.

renderer.ts shrinks by ~1000 lines. Drawing-related private methods (renderDrawingFragment, renderDrawingContent, createVectorShapeElement, createShapeGroupElement, createChartElement, createDrawingPlaceholder, isHeaderWordArtWatermark, plus their effect-extent / SVG / transform helpers) all delegate to the new modules. SVG/WordArt constants and local types (LineEnd, EffectExtent, VectorShapeDrawingWithEffects) move with them.

renderTableCell.ts is slimmed by ~95 lines:

  • Both in-flow and anchored drawing branches now call renderTableDrawingFrame instead of building the wrapper inline.
  • The renderDrawingContent callback signature gains an optional { clipContainer } so image clipping can flow through the shared path.
  • When the caller doesn't supply a callback (e.g. tests), the cell falls back to renderDrawingContent directly with buildSharedImageHyperlinkAnchor — non-image drawings in tables no longer disappear.

images/drawing-image.tscreateDrawingImageElement accepts an optional clipContainer forwarded to createBlockImageContent, so the shared renderer can pipe the table cell's inner wrapper through for image clipping.

Tests

  • New renderDrawingContent.test.ts covers vector shapes, shape groups, charts, fallback placeholders, and image hyperlink/clip-container behavior through the shared path.
  • renderTableCell.test.ts gains ~260 lines of new coverage: image drawings rendering through the shared renderer, placeholder for image without source, callback override behavior, fallback to the shared renderer when no callback is supplied, clip-container threading, and SDT metadata sourced from attrs.sdt.

… and table cells

Move renderDrawingContent (vectorShape, chart, shapeGroup, shapeText
paths) out of renderer.ts into drawings/renderDrawingContent.ts so the
main renderer and table cells share a single rendering implementation.
Extract the table-cell drawing wrapper into drawings/tableDrawingFrame.ts
to deduplicate the in-flow and anchored drawing scaffolding, and thread
the renderDrawingContent callback through renderTableCell so non-image
drawings render via the shared path. Add unit coverage for the new
renderDrawingContent module and the table cell frame builder.
Move renderDrawingFragment and isHeaderWordArtWatermark from
DomPainter into a standalone drawings/renderDrawingFragment.ts
module, drop the redundant renderDrawingContent wrapper method,
and pass the painter's frame/anchor helpers in via parameters.
@luccas-harbour luccas-harbour requested a review from a team as a code owner May 16, 2026 00:06
@linear-code
Copy link
Copy Markdown

linear-code Bot commented May 16, 2026

SD-2838

@luccas-harbour luccas-harbour changed the title Luccas/sd 2838 unify drawing block rendering refactor(painters/dom): unify drawing block rendering (SD-2838) May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant