-
Notifications
You must be signed in to change notification settings - Fork 1
Make SVGView XP compliant #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Add conditional import statements across all SVG-related files - Use Foundation for WebAssembly System Interface (WASI) platform - Keep SwiftUI/Combine imports for other platforms - Enable cross-platform compatibility for WebAssembly environments
- Remove @published property wrappers when targeting WASI platform - Maintain identical public API surface with conditional compilation - Continue implementation of WASI platform support from previous commit
- Change approach from conditionally compiling model properties to conditionally compiling UI code - Wrap SwiftUI view implementations in #if !os(WASI) blocks instead of duplicating property declarations - Simplify code structure while maintaining full WASI platform compatibility - Improve maintainability by reducing conditional compilation complexity
- Upgrade Swift tools version from 5.3 to 5.9 - Increase minimum macOS version from 11 to 14 - Maintain existing requirements for iOS (14) and watchOS (7)
- Change `#if os(WASI)` to `#if os(WASI) || os(Linux)` throughout codebase - Replace `#if !os(WASI)` with `#if canImport(SwiftUI)` for better platform detection - Add conditional compilation for published properties on Linux platform - Ensure proper handling of SwiftUI dependencies across all platforms
- Implement CGPath, CGAffineTransform and related types for non-Apple platforms - Create MBezierPath implementation compatible with Linux/WASI - Add mathematical function wrappers needed for graphics operations - Use conditional compilation to maintain native CoreGraphics on Apple platforms
- Improves code organization by separating core SVG functionality from SwiftUI integrations - Reduces platform-specific dependencies in base class definitions - Makes the codebase more maintainable by isolating UI framework bindings - Consistent with modern Swift architectural practices of protocol conformance via extensions
- Wrap SwiftUI-dependent methods in SVGNode, SVGColor, SVGFont and SVGStroke with #if canImport(SwiftUI) - Move gesture handling code inside conditional compilation blocks - Ensure SVG components work on platforms where SwiftUI is unavailable - Continues the cross-platform compatibility work for Linux and WASI platforms
- Organize imports into clearer platform-specific sections - Add explicit UIKit import for iOS/tvOS/watchOS platforms - Remove unnecessary SwiftUI import - Move Foundation import to Linux/WASI specific section
- Replace SwiftUI's HorizontalAlignment with custom SVGText.Anchor enum - Add conversion between Anchor and HorizontalAlignment for SwiftUI compatibility - Update serialization to work with the new enum - Continue ongoing efforts to reduce platform-specific dependencies
09038a2 to
e24b4ed
Compare
- Add conditional compilation directives to make bezierPath variables mutable on Linux/WASI - Follows pattern of other platform-specific fixes for cross-platform compatibility
|
|
||
| public func concatenating(_ t: CGAffineTransform) -> CGAffineTransform { | ||
| return CGAffineTransform( | ||
| a: a * t.a + c * t.b, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the meat of the PR is in this file, take a look
| name: "SVGView", | ||
| platforms: [ | ||
| .macOS(.v11), | ||
| .macOS(.v14), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bumping to match our packages, also to get rid of some of the unnecessary methods like cgPath on NSBezierPath
pedrovgs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done @khoi ! Please add automated tests to the polyfill. If one of the operations is not computed properly we all the SVG parsing will break later when we position elements on the screen based on the parsed data.
Thank you so much for the PR.
| public typealias CGPathFillRule = CoreGraphics.CGPathFillRule | ||
| public typealias CGPath = CoreGraphics.CGPath | ||
| public typealias CGAffineTransform = CoreGraphics.CGAffineTransform | ||
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super nice contriution. Thank you so much @khoi. Did you add some tests to guarantee the implementation is correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added tests, add github actions https://github.com/GoodNotes/SVGView/actions/runs/15201364624?pr=2
|
|
||
| private let KAPPA: CGFloat = 0.5522847498 // 4 *(sqrt(2) -1)/3 | ||
|
|
||
| public struct CGAffineTransform: Equatable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you consider if we can use Foundation.AffineTransform?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checking
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not directly translatable as the props are stored differently in AffineTransform under
public var m11: CGFloat
public var m12: CGFloat
public var m21: CGFloat
public var m22: CGFloat
Not going to change for now
- Remove unnecessary CGFloat, CGSize, and CGPoint typealiases - Add missing Foundation imports to SVG parser files - Continue improving cross-platform compatibility
These math function declarations (sqrt, copysign, acos, cos, sin) are no longer needed in the Linux/WASI environment as they're likely available from standard libraries or other imports.
- Change implementation from struct to class to better match CoreGraphics behavior - Remove mutating keywords from methods as they're no longer needed - Update parameter types in addArcTo method to match class-based approach
- Tests CGAffineTransform operations (identity, translation, scaling, rotation) - Verifies CGPath functionality (basic operations, bounding box calculation) - Covers MBezierPath operations (initialization, path building, transformations) - Includes tests for PathElement enum and extensions - Handles edge cases and platform-specific behavior
- Set up GitHub Actions workflow to run tests on Linux - Add CoreGraphicsPolyfillTests test target to Package.swift - Remove unnecessary exclude entry for Info.plist
- Test on macOS-latest to validate against native CoreGraphics implementation - Mirror existing Linux test job structure with caching and test discovery
This PR makes the library XP compliant while keeping all the existing features for platforms that support them
#ifcompiler directiveshttps://github.com/GoodNotes/GoodNotes-5/pull/37926 is pointing to this branch, so if you want to try compile it, use that.