Open
Conversation
Removes the early-return that printed "clip-path unsupported in SF Symbols" and instead bakes path ∩ clipPath into the emitted symbol path using CGPath.intersection on macOS 13/iOS 16+. Mirrors the existing Renderer.SFSymbol+CGPath.swift pattern used for stroke outlines. Adds clipPathUnits support (userSpaceOnUse + objectBoundingBox) by threading a new LayerTree.ClipUnits through DOM.ClipPath and Layer. Fixes swhitty#37
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #124 +/- ##
==========================================
+ Coverage 89.80% 89.95% +0.14%
==========================================
Files 159 161 +2
Lines 15868 16174 +306
==========================================
+ Hits 14251 14549 +298
- Misses 1617 1625 +8 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #37
Pre-change, emitting an
sfsymbolfor an SVG that used<clipPath>printedclip-path unsupported in SF Symbolsand produced no content. This PR bakespath ∩ clipPathinto the emitted symbol path so the final SVG contains the already-clipped geometry (SF Symbols themselves still don't support clipPath, so the clip has to be resolved at generation time).Approach
Renderer.SFSymbol+CGPath.swiftprecedent: uses CoreGraphics from inside the SFSymbol renderer when it gives us hard geometry we'd otherwise have to implement from scratch, all behind#if canImport(CoreGraphics)Renderer.SFSymbol+ClipPath.swiftusesCGPath.intersection(_:using:)on macOS 13 / iOS 16 / tvOS 16 / watchOS 9 with a bbox-only fallback for older deployment targets so nothing crashes or silently corrupts outputLayerTree.Layer.clipis no longer an early-reject ingetSymbolPaths. After the recursion collects child paths the newapplyClipruns each through the intersector. Entirely-outside shapes drop, entirely-inside shapes pass through, partial intersections become baked geometryclip-rule(evenodd/nonzero) and per-childtransforminside<clipPath>clipPathUnits(userSpaceOnUse default + objectBoundingBox) by threading a newDOM.ClipPath.Unitsthrough the parser and a newLayerTree.ClipUnitsonLayerTree.Layer. The SFSymbol clipper appliestranslate(bbox.x, bbox.y) * scale(bbox.w, bbox.h)when units areobjectBoundingBox, computed against the path being clippedWhat's covered
<clipPath>withrect,circle,ellipse,polygon,pathchildrenclip-pathon a<g>propagating to all descendantsclip-rule="evenodd"producing hollowed regionsclipPathUnits="objectBoundingBox"with shape-relative coordinatestransforminside<clipPath>transformon the clipped element's parentTests
SwiftDraw/Tests/Test.bundle/clip-*.svgcovering every variant aboveRendererSFSymbolClipPathTestswith 18 cases:path.boundsagainst the analytically expected result with 0.5pt tolerance to absorb bezier approximationLayerTree.Buildertests confirmingclipUnitsflows through from DOM for both default andobjectBoundingBoxNo valid content)swift test: 214 passed, 0 failed (was 196 pre-fix, +18 new). No regressions in the pre-existing rasterization or sfsymbol tests.Test plan
swift testpasses across the full packagechart.svg,dash.svg,key.svgtests all still pass)