Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Samples.bundle/amex.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions SwiftDraw/Sources/LayerTree/LayerTree.Builder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ extension LayerTree {
}

func makeClipShapes(for element: DOM.GraphicsElement) -> [ClipShape] {
guard let clipId = element.attributes.clipPath?.fragmentID,
let clip = svg.defs.clipPaths.first(where: { $0.id == clipId }) else { return [] }

let attributes = DOM.presentationAttributes(for: element, styles: svg.styles)
guard let clipID = attributes.clipPath?.fragmentID,
let clip = svg.defs.clipPaths.first(where: { $0.id == clipID }) else { return [] }
return clip.childElements.compactMap(makeClipShape)
}

Expand Down
23 changes: 19 additions & 4 deletions SwiftDraw/Tests/LayerTree/LayerTree.BuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,30 @@ final class LayerTreeBuilderTests: XCTestCase {
let circle = DOM.Circle(cx: 5, cy: 5, r: 5)
let svg = DOM.SVG(width: 10, height: 10)
svg.defs.clipPaths.append(DOM.ClipPath(id: "clip1", childElements: [circle]))

var attributes = DOM.PresentationAttributes()
attributes.clipPath = URL(string: "#clip1")
svg.styles = [DOM.StyleSheet(attributes: [.class("a"): attributes])]

let builder = LayerTree.Builder(svg: svg)

let element = DOM.GraphicsElement()
var element = DOM.GraphicsElement()
element.attributes.clipPath = URL(string: "#clip1")

let shapes = builder.createClipShapes(for: element)
XCTAssertEqual(shapes, [.ellipse(within: LayerTree.Rect(x: 0, y: 0, width: 10, height: 10))])
var shapes = builder.createClipShapes(for: element)
XCTAssertEqual(
builder.createClipShapes(for: element),
[.ellipse(within: LayerTree.Rect(x: 0, y: 0, width: 10, height: 10))]
)

element = DOM.GraphicsElement()
element.class = "a"
XCTAssertEqual(
builder.createClipShapes(for: element),
[.ellipse(within: LayerTree.Rect(x: 0, y: 0, width: 10, height: 10))]
)
}

func testDOMGroupMakesChildContents() {
let builder = LayerTree.Builder(svg: DOM.SVG(width: 10, height: 10))

Expand Down