Skip to content

3/7: Implement pattern & gradient paint servers#10

Merged
Amnell merged 9 commits into
mainfrom
pr/03-pattern-gradient-paint
May 27, 2026
Merged

3/7: Implement pattern & gradient paint servers#10
Amnell merged 9 commits into
mainfrom
pr/03-pattern-gradient-paint

Conversation

@Amnell
Copy link
Copy Markdown
Owner

@Amnell Amnell commented May 27, 2026

Summary

Implement SVG pattern and gradient paint server rendering with full transform support.

Changes

  • Implement SVG pattern paint server with xlink:href inheritance (pservers-grad-03-b)
  • Add AGENTS.md and architecture/feature reference docs
  • Implement patternTransform support; add pservers-grad-06-b
  • Fix radialGradient gradientTransform: store transform, render via CGBitmapContext
  • Guide agents in how to export rendered PNGs for debugging
  • Fix tiling vertical shift in pservers-grad-06-b

Merge order

⚠️ Merge these PRs in order: #8#9#10#11#12#13#14. After merging each PR, GitHub will automatically update the next PR's base to main.

Stack:

  1. Swift 6 prep & test modernization (1/7: Swift 6 prep & test modernization #8)
  2. Docs & tooling (2/7: Project docs, tooling & initial W3C coverage #9)
  3. Pattern/gradient paint servers ← this PR
  4. Test reporting
  5. DOM scripting & currentColor
  6. Shapes & coordinates
  7. Structural elements & text

Amnell added 9 commits May 27, 2026 12:29
…ers-grad-03-b)

- Add SVGPattern model (SVGPaint subclass) with CGBitmapContext tile rendering
- Add draw(in: CGContext) to SVGNode (no-op), SVGRect, and SVGGroup
- Add SVGParser.parseElements(_:index:) internal helper for pattern tile parsing
- Register <pattern> elements as paint servers in SVGIndex with xlink:href inheritance
- Wire SVGPattern into SVGPaint.apply(paint:model:) switch
- Add pserversGrad03B test and reference file
- SVGPattern.apply() now uses Canvas-based tiling when patternTransform != .identity
  Computes inverse-transform bounds to determine exact tile coverage; falls back
  to cheaper ImagePaint path for identity transforms
- Add pserversGrad06B test and reference file
…itmapContext

Previously the parser baked gradientTransform into cx/cy/r, which only worked
for uniform scale+translate and silently dropped skew/rotation (shear).

Changes:
- SVGRadialGradient now stores gradientTransform: CGAffineTransform (default .identity)
- Parser no longer transforms the gradient points; raw gradient-space cx/cy/fx/fy/r
  are preserved and gradientTransform is passed directly to the model
- SVGRadialGradient.apply() uses a CGBitmapContext path when gradientTransform is
  non-identity: sets up y-flip + shape-offset CTM, concatenates gradientTransform,
  then calls drawRadialGradient in gradient space so CoreGraphics handles the full
  affine deformation (translate, scale, skewX/Y, rotate, arbitrary matrix)
- Falls back to the existing SwiftUI RadialGradient path for identity transforms

Fixes the pservers-grad-06-b skewX(45) radial gradient rendering.
@Amnell Amnell force-pushed the pr/03-pattern-gradient-paint branch from 1cc27b0 to e77ab96 Compare May 27, 2026 10:31
@Amnell Amnell merged commit c45ab12 into main May 27, 2026
@Amnell Amnell deleted the pr/03-pattern-gradient-paint branch May 27, 2026 10:31
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