Skip to content

Commit 29f276d

Browse files
authored
Merge pull request #23 from GoodNotes/adin/foundation-essentials-polyfill-cleanup
[CPF] Use pure-Swift CG geometry on WASI/Linux/Android
2 parents 3deb742 + d5c9767 commit 29f276d

3 files changed

Lines changed: 21 additions & 19 deletions

File tree

‎Source/CoreGraphicsPolyfill.swift‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
// Created by khoi on 10/5/25.
66
//
77

8-
#if os(Linux) || os(WASI) || os(Android)
9-
import Foundation
10-
#elseif canImport(FoundationEssentials)
8+
#if canImport(FoundationEssentials)
119
import FoundationEssentials
1210
#else
1311
import Foundation
@@ -21,12 +19,7 @@ import Android
2119
import Glibc
2220
#endif
2321

24-
#if os(Linux) || os(WASI) || os(Android)
25-
public typealias CGFloat = Foundation.CGFloat
26-
public typealias CGPoint = Foundation.CGPoint
27-
public typealias CGSize = Foundation.CGSize
28-
public typealias CGRect = Foundation.CGRect
29-
#elseif !canImport(CoreGraphics)
22+
#if !canImport(CoreGraphics)
3023
public typealias CGFloat = Double
3124

3225
public struct CGPoint: Equatable {

‎Source/Serialization/Serializations.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ extension CGFloat: SerializableAtom {
4949

5050
}
5151

52-
#if canImport(CoreGraphics) || os(Linux) || os(WASI) || os(Android)
52+
#if canImport(CoreGraphics)
5353
extension Double: SerializableAtom {
5454

5555
func serialize() -> String {

‎Tests/CoreGraphicsPolyfillTests/PolyfillTests.swift‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,32 @@
1616
// since the polyfill types are aliases to the native CoreGraphics types.
1717
//
1818

19+
#if canImport(FoundationEssentials)
20+
import FoundationEssentials
21+
#else
1922
import Foundation
23+
#endif
24+
25+
#if os(WASI)
26+
import WASILibc
27+
#elseif canImport(Android)
28+
import Android
29+
#elseif canImport(Glibc)
30+
import Glibc
31+
#endif
32+
2033
import XCTest
2134

2235
@testable import SVGView
2336

2437
final class PolyfillTests: XCTestCase {
25-
26-
#if os(WASI) || os(Linux) || os(Android)
2738

28-
func testGeometryTypesMatchFoundation() {
29-
let scalar: Foundation.CGFloat = CGFloat(1)
30-
let point: Foundation.CGPoint = CGPoint(x: scalar, y: scalar)
31-
let size: Foundation.CGSize = CGSize(width: scalar, height: scalar)
32-
let rect: Foundation.CGRect = CGRect(origin: point, size: size)
39+
#if os(WASI) || os(Linux) || os(Android)
3340

34-
XCTAssertEqual(rect, Foundation.CGRect(x: 1, y: 1, width: 1, height: 1))
35-
}
41+
private typealias CGFloat = SVGView.CGFloat
42+
private typealias CGPoint = SVGView.CGPoint
43+
private typealias CGSize = SVGView.CGSize
44+
private typealias CGRect = SVGView.CGRect
3645

3746
func testDoubleSerialization() {
3847
XCTAssertEqual(Double(1).serialize(), "1")

0 commit comments

Comments
 (0)