Skip to content

Commit 08a079d

Browse files
committed
feat: Add Text and Painting types for swift-svg-printer compatibility
Add comprehensive Text and Painting types needed for migrating swift-svg-printer from swift-svg-types to swift-w3c-svg: Text namespace (Chapter 11): - Text element with content property - TSpan element with content property - Text.TextLengthAdjust enum Painting namespace (Chapter 13): - LineCap enum (butt, round, square) - LineJoin enum (miter, round, bevel) - FillRule enum (nonzero, evenodd) - ClipPath element with ClipPathUnits enum - Mask element with MaskUnits enum - Marker element with MarkerUnits enum PaintServers nested enums: - LinearGradient.GradientUnits enum - LinearGradient.SpreadMethod enum - RadialGradient.GradientUnits enum - RadialGradient.SpreadMethod enum - Pattern.PatternUnits enum All types include comprehensive W3C SVG 2 spec documentation with section references and usage examples. Tests: 79 passing in 29 suites (+29 tests, +9 suites)
1 parent b255c4e commit 08a079d

12 files changed

+932
-0
lines changed

Sources/W3C SVG/W3C_SVG2.PaintServers.LinearGradient.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,33 @@ extension W3C_SVG2.PaintServers {
8181
/// Format: "#elementId" or URL
8282
public let href: String?
8383

84+
/// Coordinate system for gradient geometry
85+
///
86+
/// W3C SVG 2 Section 14.2.3.4
87+
/// https://www.w3.org/TR/SVG2/pservers.html#LinearGradientElementGradientUnitsAttribute
88+
public enum GradientUnits: String, Sendable, Equatable {
89+
/// Coordinate system established by user space
90+
case userSpaceOnUse
91+
92+
/// Coordinate system relative to bounding box (0-1 range)
93+
case objectBoundingBox
94+
}
95+
96+
/// Behavior beyond gradient bounds
97+
///
98+
/// W3C SVG 2 Section 14.2.3.6
99+
/// https://www.w3.org/TR/SVG2/pservers.html#LinearGradientElementSpreadMethodAttribute
100+
public enum SpreadMethod: String, Sendable, Equatable {
101+
/// Extend with terminal colors (default)
102+
case pad
103+
104+
/// Reflect the gradient pattern
105+
case reflect
106+
107+
/// Repeat the gradient pattern
108+
case `repeat`
109+
}
110+
84111
/// Creates a linear gradient element
85112
///
86113
/// - Parameters:

Sources/W3C SVG/W3C_SVG2.PaintServers.Pattern.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ extension W3C_SVG2.PaintServers {
8383
/// Format: "#elementId" or URL
8484
public let href: String?
8585

86+
/// Coordinate system for pattern geometry
87+
///
88+
/// W3C SVG 2 Section 14.3.2
89+
/// https://www.w3.org/TR/SVG2/pservers.html#PatternElementPatternUnitsAttribute
90+
public enum PatternUnits: String, Sendable, Equatable {
91+
/// Coordinate system established by user space
92+
case userSpaceOnUse
93+
94+
/// Coordinate system relative to bounding box (0-1 range)
95+
case objectBoundingBox
96+
}
97+
8698
/// Creates a pattern element
8799
///
88100
/// - Parameters:

Sources/W3C SVG/W3C_SVG2.PaintServers.RadialGradient.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,33 @@ extension W3C_SVG2.PaintServers {
9898
/// Format: "#elementId" or URL
9999
public let href: String?
100100

101+
/// Coordinate system for gradient geometry
102+
///
103+
/// W3C SVG 2 Section 14.2.4.4
104+
/// https://www.w3.org/TR/SVG2/pservers.html#RadialGradientElementGradientUnitsAttribute
105+
public enum GradientUnits: String, Sendable, Equatable {
106+
/// Coordinate system established by user space
107+
case userSpaceOnUse
108+
109+
/// Coordinate system relative to bounding box (0-1 range)
110+
case objectBoundingBox
111+
}
112+
113+
/// Behavior beyond gradient bounds
114+
///
115+
/// W3C SVG 2 Section 14.2.4.6
116+
/// https://www.w3.org/TR/SVG2/pservers.html#RadialGradientElementSpreadMethodAttribute
117+
public enum SpreadMethod: String, Sendable, Equatable {
118+
/// Extend with terminal colors (default)
119+
case pad
120+
121+
/// Reflect the gradient pattern
122+
case reflect
123+
124+
/// Repeat the gradient pattern
125+
case `repeat`
126+
}
127+
101128
/// Creates a radial gradient element
102129
///
103130
/// - Parameters:
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//
2+
// W3C_SVG2.Painting.ClipPath.swift
3+
// swift-w3c-svg
4+
//
5+
// The 'clipPath' element (SVG 2 Section 14.3)
6+
//
7+
8+
extension W3C_SVG2.Painting {
9+
/// The 'clipPath' element
10+
///
11+
/// W3C SVG 2 Section 14.3
12+
/// https://www.w3.org/TR/SVG2/masking.html#ClipPathElement
13+
///
14+
/// The 'clipPath' element defines a clipping path, which restricts the region
15+
/// to which paint can be applied.
16+
///
17+
/// ## Coordinate System
18+
///
19+
/// - **clipPathUnits**: Defines the coordinate system for the clipping path
20+
///
21+
/// ## Behavior
22+
///
23+
/// Portions of a graphical element that lie outside the clipping path are not rendered.
24+
/// The clipping path is defined by the child elements of the clipPath.
25+
///
26+
/// ## Example
27+
///
28+
/// ```swift
29+
/// let clipPath = W3C_SVG2.Painting.ClipPath(id: "myClip")
30+
/// ```
31+
///
32+
/// ## See Also
33+
///
34+
/// - ``Mask``
35+
public struct ClipPath: Sendable, Equatable {
36+
/// Identifier for referencing the clip path
37+
public let id: String?
38+
39+
/// Coordinate system for clip path geometry
40+
///
41+
/// W3C SVG 2 Section 14.3.2
42+
/// https://www.w3.org/TR/SVG2/masking.html#ClipPathElementClipPathUnitsAttribute
43+
public enum ClipPathUnits: String, Sendable, Equatable {
44+
/// Coordinate system established by user space
45+
case userSpaceOnUse
46+
47+
/// Coordinate system relative to bounding box (0-1 range)
48+
case objectBoundingBox
49+
}
50+
51+
/// Creates a clipPath element
52+
///
53+
/// - Parameters:
54+
/// - id: Identifier for referencing (default: nil)
55+
public init(
56+
id: String? = nil
57+
) {
58+
self.id = id
59+
}
60+
61+
/// SVG element tag name
62+
public static let tagName = "clipPath"
63+
64+
/// Whether this element is self-closing
65+
public static let isSelfClosing = false
66+
}
67+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
// W3C_SVG2.Painting.FillRule.swift
3+
// swift-w3c-svg
4+
//
5+
// Fill rule (SVG 2 Section 13.2)
6+
//
7+
8+
extension W3C_SVG2.Painting {
9+
/// Fill rule
10+
///
11+
/// W3C SVG 2 Section 13.2
12+
/// https://www.w3.org/TR/SVG2/painting.html#FillRuleProperty
13+
///
14+
/// The `fill-rule` property indicates the algorithm to be used to determine
15+
/// what parts of the canvas are included inside the shape.
16+
///
17+
/// ## Values
18+
///
19+
/// - **nonzero**: Nonzero winding rule (default)
20+
/// - **evenodd**: Even-odd winding rule
21+
///
22+
/// ## Winding Rules
23+
///
24+
/// **Nonzero:** Determines whether a point is inside by drawing a ray and
25+
/// counting path crossings. Non-zero count means inside.
26+
///
27+
/// **Even-odd:** Determines whether a point is inside by drawing a ray and
28+
/// counting path crossings. Odd count means inside, even count means outside.
29+
///
30+
/// ## Example
31+
///
32+
/// ```swift
33+
/// let fillRule = W3C_SVG2.Painting.FillRule.evenodd
34+
/// ```
35+
public enum FillRule: String, Sendable, Equatable {
36+
/// Nonzero winding rule (default)
37+
case nonzero
38+
39+
/// Even-odd winding rule
40+
case evenodd
41+
}
42+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// W3C_SVG2.Painting.LineCap.swift
3+
// swift-w3c-svg
4+
//
5+
// Line cap style (SVG 2 Section 13.3)
6+
//
7+
8+
extension W3C_SVG2.Painting {
9+
/// Line cap style
10+
///
11+
/// W3C SVG 2 Section 13.3
12+
/// https://www.w3.org/TR/SVG2/painting.html#LineCaps
13+
///
14+
/// The `stroke-linecap` property specifies the shape to be used at the end
15+
/// of open subpaths when they are stroked.
16+
///
17+
/// ## Values
18+
///
19+
/// - **butt**: The stroke does not extend beyond the endpoint (default)
20+
/// - **round**: A rounded end cap with radius equal to half stroke width
21+
/// - **square**: A square cap extending beyond the endpoint
22+
///
23+
/// ## Example
24+
///
25+
/// ```swift
26+
/// let lineCap = W3C_SVG2.Painting.LineCap.round
27+
/// ```
28+
public enum LineCap: String, Sendable, Equatable {
29+
/// Stroke does not extend beyond endpoint
30+
case butt
31+
32+
/// Rounded end cap
33+
case round
34+
35+
/// Square cap extending beyond endpoint
36+
case square
37+
}
38+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// W3C_SVG2.Painting.LineJoin.swift
3+
// swift-w3c-svg
4+
//
5+
// Line join style (SVG 2 Section 13.3)
6+
//
7+
8+
extension W3C_SVG2.Painting {
9+
/// Line join style
10+
///
11+
/// W3C SVG 2 Section 13.3
12+
/// https://www.w3.org/TR/SVG2/painting.html#LineJoin
13+
///
14+
/// The `stroke-linejoin` property specifies the shape to be used at the
15+
/// corners of paths or basic shapes when they are stroked.
16+
///
17+
/// ## Values
18+
///
19+
/// - **miter**: Sharp corner with extended outer edges (default)
20+
/// - **round**: Rounded corner with radius equal to half stroke width
21+
/// - **bevel**: Flattened corner
22+
///
23+
/// ## Example
24+
///
25+
/// ```swift
26+
/// let lineJoin = W3C_SVG2.Painting.LineJoin.round
27+
/// ```
28+
public enum LineJoin: String, Sendable, Equatable {
29+
/// Sharp corner with extended edges
30+
case miter
31+
32+
/// Rounded corner
33+
case round
34+
35+
/// Flattened corner
36+
case bevel
37+
}
38+
}

0 commit comments

Comments
 (0)