diff --git a/Source/platform/iOS/Common_iOS.swift b/Source/platform/iOS/Common_iOS.swift index 219342fe..9e2f21e6 100644 --- a/Source/platform/iOS/Common_iOS.swift +++ b/Source/platform/iOS/Common_iOS.swift @@ -99,4 +99,10 @@ extension UIScreen { } } +extension UIBezierPath { + var usesEvenOddFillRule: Bool { + return self.usesEvenOddFillRule + } +} + #endif diff --git a/Source/platform/macOS/Common_macOS.swift b/Source/platform/macOS/Common_macOS.swift index b987e957..d870d1f2 100644 --- a/Source/platform/macOS/Common_macOS.swift +++ b/Source/platform/macOS/Common_macOS.swift @@ -184,4 +184,10 @@ extension NSWindow { } } +extension NSBezierPath { + var usesEvenOddFillRule: Bool { + return self.windingRule == .evenOdd + } +} + #endif diff --git a/Source/utils/CGMappings.swift b/Source/utils/CGMappings.swift index e3acc84b..45a96873 100644 --- a/Source/utils/CGMappings.swift +++ b/Source/utils/CGMappings.swift @@ -153,3 +153,61 @@ public extension Node { } } + +extension MBezierPath { + + public func toMacaw() -> Path { + let fillRule: FillRule = self.usesEvenOddFillRule ? .evenodd : .nonzero + return self.cgPath.toMacaw(fillRule: fillRule) + } + +} + +extension CGPath { + + public func toMacaw(fillRule: FillRule = .nonzero) -> Path { + + func createPathSegment(type: PathSegmentType, points: UnsafeMutablePointer, count: Int) -> PathSegment { + + var data = [Double]() + for index in 0.. Void) { + typealias Body = @convention(block) (CGPathElement) -> Void + func callback(info: UnsafeMutableRawPointer?, element: UnsafePointer) { + let body = unsafeBitCast(info, to: Body.self) + body(element.pointee) + } + let unsafeBody = unsafeBitCast(body, to: UnsafeMutableRawPointer.self) + self.apply(info: unsafeBody, function: callback) + } +}