Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions Source/CoreGraphicsPolyfill.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
// Created by khoi on 10/5/25.
//

#if os(Linux) || os(WASI) || os(Android)
import Foundation
#elseif canImport(FoundationEssentials)
#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
Expand All @@ -21,12 +19,7 @@ import Android
import Glibc
#endif

#if os(Linux) || os(WASI) || os(Android)
public typealias CGFloat = Foundation.CGFloat
public typealias CGPoint = Foundation.CGPoint
public typealias CGSize = Foundation.CGSize
public typealias CGRect = Foundation.CGRect
#elseif !canImport(CoreGraphics)
#if !canImport(CoreGraphics)
public typealias CGFloat = Double

public struct CGPoint: Equatable {
Expand Down
2 changes: 1 addition & 1 deletion Source/Serialization/Serializations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ extension CGFloat: SerializableAtom {

}

#if canImport(CoreGraphics) || os(Linux) || os(WASI) || os(Android)
#if canImport(CoreGraphics)
extension Double: SerializableAtom {

func serialize() -> String {
Expand Down
27 changes: 18 additions & 9 deletions Tests/CoreGraphicsPolyfillTests/PolyfillTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,32 @@
// since the polyfill types are aliases to the native CoreGraphics types.
//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

#if os(WASI)
import WASILibc
#elseif canImport(Android)
import Android
#elseif canImport(Glibc)
import Glibc
#endif

import XCTest

@testable import SVGView

final class PolyfillTests: XCTestCase {

#if os(WASI) || os(Linux) || os(Android)

func testGeometryTypesMatchFoundation() {
let scalar: Foundation.CGFloat = CGFloat(1)
let point: Foundation.CGPoint = CGPoint(x: scalar, y: scalar)
let size: Foundation.CGSize = CGSize(width: scalar, height: scalar)
let rect: Foundation.CGRect = CGRect(origin: point, size: size)
#if os(WASI) || os(Linux) || os(Android)

XCTAssertEqual(rect, Foundation.CGRect(x: 1, y: 1, width: 1, height: 1))
}
private typealias CGFloat = SVGView.CGFloat
private typealias CGPoint = SVGView.CGPoint
private typealias CGSize = SVGView.CGSize
private typealias CGRect = SVGView.CGRect

func testDoubleSerialization() {
XCTAssertEqual(Double(1).serialize(), "1")
Expand Down
Loading