From 195f828f77410e0c18a9adbfa03d3462afebcbe0 Mon Sep 17 00:00:00 2001 From: Alisa Mylnikova Date: Thu, 28 May 2020 15:34:37 +0700 Subject: [PATCH 1/4] Add toMacaw for CGPath --- Source/utils/CGMappings.swift | 49 +++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/Source/utils/CGMappings.swift b/Source/utils/CGMappings.swift index e3acc84b..1f727bd8 100644 --- a/Source/utils/CGMappings.swift +++ b/Source/utils/CGMappings.swift @@ -153,3 +153,52 @@ public extension Node { } } + +extension CGPath { + + public func toMacaw() -> 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) + } +} From 8d6607c307fd918d6e25647422b89ca91c25fde7 Mon Sep 17 00:00:00 2001 From: Alisa Mylnikova Date: Thu, 28 May 2020 16:15:53 +0700 Subject: [PATCH 2/4] Fix #688: Review fixes --- Source/utils/CGMappings.swift | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Source/utils/CGMappings.swift b/Source/utils/CGMappings.swift index 1f727bd8..a7a35173 100644 --- a/Source/utils/CGMappings.swift +++ b/Source/utils/CGMappings.swift @@ -154,9 +154,18 @@ public extension Node { } -extension CGPath { +extension UIBezierPath { 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 { @@ -184,7 +193,7 @@ extension CGPath { case .closeSubpath: segment = PathSegment(type: .z) @unknown default: - fatalError() + fatalError("Unknown element type: \(element.type)") } segments.append(segment) }) From 9abede7354bf6fbb2507b7e67abde205e5901745 Mon Sep 17 00:00:00 2001 From: Alisa Mylnikova Date: Thu, 28 May 2020 19:11:43 +0700 Subject: [PATCH 3/4] Fix mac build --- Source/utils/CGMappings.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/utils/CGMappings.swift b/Source/utils/CGMappings.swift index a7a35173..45a96873 100644 --- a/Source/utils/CGMappings.swift +++ b/Source/utils/CGMappings.swift @@ -154,7 +154,7 @@ public extension Node { } -extension UIBezierPath { +extension MBezierPath { public func toMacaw() -> Path { let fillRule: FillRule = self.usesEvenOddFillRule ? .evenodd : .nonzero From e5d93909df61644d816af461d9fd1254e13dad77 Mon Sep 17 00:00:00 2001 From: Alisa Mylnikova Date: Fri, 29 May 2020 12:24:22 +0700 Subject: [PATCH 4/4] More fixes for mac --- Source/platform/iOS/Common_iOS.swift | 6 ++++++ Source/platform/macOS/Common_macOS.swift | 6 ++++++ 2 files changed, 12 insertions(+) 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