diff --git a/Package.resolved b/Package.resolved index 9e6bfad..28fd5fa 100644 --- a/Package.resolved +++ b/Package.resolved @@ -7,7 +7,7 @@ "location" : "https://github.com/OpenSwiftUIProject/DarwinPrivateFrameworks.git", "state" : { "branch" : "main", - "revision" : "600fcdfb9462e985d5fef429daf236e2de3104db" + "revision" : "7b1da8b32736a879afd3964a13085c076eaa1221" } }, { diff --git a/Sources/OpenRenderBox/Path/ORBPath.swift b/Sources/OpenRenderBox/Path/ORBPath.swift index e7161f1..245acda 100644 --- a/Sources/OpenRenderBox/Path/ORBPath.swift +++ b/Sources/OpenRenderBox/Path/ORBPath.swift @@ -77,8 +77,8 @@ public struct ORBPathLineShape: @unchecked Sendable { public struct ORBPathStrokeStyle: @unchecked Sendable { public var lineWidth: CGFloat - public var lineCap: Int32 - public var lineJoin: Int32 + public var lineCap: CGLineCap + public var lineJoin: CGLineJoin public var miterLimit: CGFloat public var dashPhase: CGFloat public var dashCount: UInt64 @@ -86,8 +86,8 @@ public struct ORBPathStrokeStyle: @unchecked Sendable { public init( lineWidth: CGFloat, - lineCap: Int32, - lineJoin: Int32, + lineCap: CGLineCap, + lineJoin: CGLineJoin, miterLimit: CGFloat, dashPhase: CGFloat, dashCount: UInt64, @@ -662,7 +662,7 @@ extension ORBPath { var shape = ORBPathShape( rect: zeroRect, ellipse: zeroRect, fixedRoundedRect: .init(transform: .identity, rect: .zero, cornerSize: .zero, style: .circular), - stroked: .init(path: self, style: .init(lineWidth: 0, lineCap: 0, lineJoin: 0, miterLimit: 0, dashPhase: 0, dashCount: 0, dash: nil)) + stroked: .init(path: self, style: .init(lineWidth: 0, lineCap: .butt, lineJoin: .miter, miterLimit: 0, dashPhase: 0, dashCount: 0, dash: nil)) ) let type: ORBPathShapeType var ownedChild: ORBPath? @@ -687,9 +687,18 @@ extension ORBPath { default: type = .stroked strokeDash = record.stroke?.dash ?? [] - shape.stroked = .init(path: child, style: .init(lineWidth: record.values[0], lineCap: record.stroke?.lineCap ?? 0, - lineJoin: record.stroke?.lineJoin ?? 0, miterLimit: record.values[1], dashPhase: record.values[2], - dashCount: UInt64(strokeDash!.count), dash: nil)) + shape.stroked = .init( + path: child, + style: .init( + lineWidth: record.values[0], + lineCap: CGLineCap(rawValue: record.stroke?.lineCap ?? 0) ?? .butt, + lineJoin: CGLineJoin(rawValue: record.stroke?.lineJoin ?? 0) ?? .miter, + miterLimit: record.values[1], + dashPhase: record.values[2], + dashCount: UInt64(strokeDash!.count), + dash: nil + ) + ) } } else if records.count == 1, let record = records.first { switch record.element { diff --git a/Sources/OpenRenderBoxCxx/Path/ORBPath.cpp b/Sources/OpenRenderBoxCxx/Path/ORBPath.cpp index 62ca70c..be1d02b 100644 --- a/Sources/OpenRenderBoxCxx/Path/ORBPath.cpp +++ b/Sources/OpenRenderBoxCxx/Path/ORBPath.cpp @@ -611,7 +611,18 @@ bool ORBPathApplyShape( static const CGFloat emptyDash = 0; size_t count = stroke.values ? stroke.count : 0; auto *dash = count ? static_cast(stroke.values) : &emptyDash; - shape.stroked = {nested, {values[0], stroke.cap, stroke.join, values[1], values[2], count, dash}}; + shape.stroked = { + nested, + { + values[0], + static_cast(stroke.cap), + static_cast(stroke.join), + values[1], + values[2], + count, + dash, + }, + }; type = ORBPathShapeTypeStroked; } info->callback(info->info, type, &shape); diff --git a/Sources/OpenRenderBoxCxx/Path/ORBPath.h b/Sources/OpenRenderBoxCxx/Path/ORBPath.h index 3b55e1d..5afeed4 100644 --- a/Sources/OpenRenderBoxCxx/Path/ORBPath.h +++ b/Sources/OpenRenderBoxCxx/Path/ORBPath.h @@ -125,8 +125,8 @@ typedef struct ORBPathLineShape { typedef struct ORBPathStrokeStyle { CGFloat lineWidth; - int32_t lineCap; - int32_t lineJoin; + CGLineCap lineCap; + CGLineJoin lineJoin; CGFloat miterLimit; CGFloat dashPhase; uint64_t dashCount; diff --git a/Tests/OpenRenderBoxCompatibilityTests/PathOperationsTests.swift b/Tests/OpenRenderBoxCompatibilityTests/PathOperationsTests.swift index eeeb8ff..f941ec7 100644 --- a/Tests/OpenRenderBoxCompatibilityTests/PathOperationsTests.swift +++ b/Tests/OpenRenderBoxCompatibilityTests/PathOperationsTests.swift @@ -179,7 +179,7 @@ struct PathOperationsTests { let path = lhs.interpolated(to: rhs, fraction: 0.25) lhs.release() rhs.release() - struct Result { var width: CGFloat = 0; var cap: Int32 = -1; var dash: [CGFloat] = []; var child = ORBPath.empty } + struct Result { var width: CGFloat = 0; var cap: CGLineCap = .butt; var dash: [CGFloat] = []; var child = ORBPath.empty } var result = Result() #expect(path.applyShape(allowLine: true, info: &result) { info, type, shape in if type == .stroked { @@ -194,7 +194,7 @@ struct PathOperationsTests { path.release() defer { result.child.release() } #expect(result.width == 1.5) - #expect(result.cap == 2) + #expect(result.cap == .square) #expect(result.dash == [3, 5, 7]) #expect(result.child.boundingRect == CGRect(x: 1.5, y: 2.5, width: 15, height: 25)) } diff --git a/Tests/OpenRenderBoxTests/Path/PortablePathTests.swift b/Tests/OpenRenderBoxTests/Path/PortablePathTests.swift index aa17b15..86dce91 100644 --- a/Tests/OpenRenderBoxTests/Path/PortablePathTests.swift +++ b/Tests/OpenRenderBoxTests/Path/PortablePathTests.swift @@ -372,7 +372,7 @@ struct PortablePathTests { let mixedStroke = lhs.interpolated(to: rhs, fraction: 0.25) lhs.release() rhs.release() - struct StrokeResult { var width: CGFloat = 0; var cap: Int32 = -1; var dash: [CGFloat] = []; var child = ORBPath.empty } + struct StrokeResult { var width: CGFloat = 0; var cap: CGLineCap = .butt; var dash: [CGFloat] = []; var child = ORBPath.empty } var result = StrokeResult() let strokeRecognized = withUnsafeMutablePointer(to: &result) { resultPtr in mixedStroke.applyShape(allowLine: true, info: resultPtr) { info, type, shape in @@ -390,7 +390,7 @@ struct PortablePathTests { mixedStroke.release() defer { result.child.release() } #expect(result.width == 1.5) - #expect(result.cap == 2) + #expect(result.cap == .square) #expect(result.dash == [3, 5, 7]) #expect(result.child.boundingRect == CGRect(x: 1.5, y: 2.5, width: 15, height: 25))