Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
9 changes: 4 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,22 @@ jobs:
name: Test on Linux
runs-on: ubuntu-latest
container:
image: swift:5.9
image: swiftlang/swift:nightly-6.4.x-noble

steps:
- name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@v5

- name: Run tests
run: swift test --filter CoreGraphicsPolyfillTests

test-macos:
name: Test on macOS
runs-on: macos-latest
runs-on: macos-26

steps:
- name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@v5

- name: Run tests
run: swift test --enable-test-discovery

8 changes: 8 additions & 0 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 20 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.9
// swift-tools-version:6.2

import PackageDescription

Expand All @@ -24,6 +24,10 @@ let package = Package(
url: "https://github.com/apple/swift-argument-parser.git",
from: "1.5.0"
),
.package(
url: "https://github.com/compnerd/xylem.git",
revision: "9881c95ce3a139f4ccfa584676201516c2a5751d"
),
Comment on lines +27 to +30

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pointing to a specific rev might be an issue with some internal tooling we have about the SPM registry, but since we are not actively using it ATM we can revisit this problem later, hopefully xylem cuts a version soon.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I already faced this now

error: Dependencies could not be resolved because package 'svgview' is required using a stable-version but 'svgview' depends on an unstable-version package 'xylem' and 'svgtonotesitems' depends on 'svgview' 0.2.20-goodnotes-foundation-essentials.

],
targets: [
.executableTarget(
Expand All @@ -34,8 +38,20 @@ let package = Package(
],
path: "GenerateReferencesCLI"
),
.target(
name: "SVGView",
.target(
name: "SVGView",
dependencies: [
.product(
name: "SAXParser",
package: "xylem",
condition: .when(platforms: [.wasi, .linux, .android, .windows])
),
.product(
name: "XMLCore",
package: "xylem",
condition: .when(platforms: [.wasi, .linux, .android, .windows])
),
],
path: "Source"
),
.testTarget(
Expand All @@ -50,5 +66,5 @@ let package = Package(
]
),
],
swiftLanguageVersions: [.v5]
swiftLanguageModes: [.v5]
)
79 changes: 79 additions & 0 deletions Source/CoreGraphicsPolyfill.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,86 @@
// Created by khoi on 10/5/25.
//

#if os(Linux)
import Foundation
#elseif canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

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

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

public struct CGPoint: Equatable {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially I wanted to separate these in another repo since it's reusable. But, this repo is public and I can't make this thing public without legal approval so this is the best I can do

https://github.com/GoodNotes/FoundationEssentialsExtras

public static let zero = CGPoint()

public var x: CGFloat
public var y: CGFloat

public init(x: CGFloat = 0, y: CGFloat = 0) {
self.x = x
self.y = y
}
}

public struct CGSize: Equatable {
public static let zero = CGSize()

public var width: CGFloat
public var height: CGFloat

public init(width: CGFloat = 0, height: CGFloat = 0) {
self.width = width
self.height = height
}
}

public struct CGRect: Equatable {
public static let zero = CGRect()

public var origin: CGPoint
public var size: CGSize

public init(origin: CGPoint = .zero, size: CGSize = CGSize()) {
self.origin = origin
self.size = size
}

public init(x: CGFloat, y: CGFloat, width: CGFloat, height: CGFloat) {
self.init(
origin: CGPoint(x: x, y: y),
size: CGSize(width: width, height: height)
)
}

public var width: CGFloat { maxX - minX }
public var height: CGFloat { maxY - minY }
public var minX: CGFloat { Swift.min(origin.x, origin.x + size.width) }
public var minY: CGFloat { Swift.min(origin.y, origin.y + size.height) }
public var maxX: CGFloat { Swift.max(origin.x, origin.x + size.width) }
public var maxY: CGFloat { Swift.max(origin.y, origin.y + size.height) }

public func union(_ other: CGRect) -> CGRect {
let minX = Swift.min(self.minX, other.minX)
let minY = Swift.min(self.minY, other.minY)
let maxX = Swift.max(self.maxX, other.maxX)
let maxY = Swift.max(self.maxY, other.maxY)
return CGRect(x: minX, y: minY, width: maxX - minX, height: maxY - minY)
}
}
#endif

#if os(WASI) || os(Linux) || os(Android)
private let KAPPA: CGFloat = 0.5522847498 // 4 *(sqrt(2) -1)/3
Expand Down
8 changes: 5 additions & 3 deletions Source/Model/Images/SVGDataImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
// Created by Alisa Mylnikova on 10/06/2021.
//

#if os(WASI) || os(Linux) || os(Android)
import Foundation
#else
#if canImport(SwiftUI)
import SwiftUI
import Combine
#elseif canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

public class SVGDataImage: SVGImage {
Expand Down
8 changes: 5 additions & 3 deletions Source/Model/Images/SVGURLImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
// Created by Alisa Mylnikova on 22/09/2021.
//

#if os(WASI) || os(Linux) || os(Android)
import Foundation
#else
#if canImport(SwiftUI)
import SwiftUI
#elseif canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

public class SVGURLImage: SVGImage {
Expand Down
8 changes: 5 additions & 3 deletions Source/Model/Nodes/SVGDefs.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#if os(WASI) || os(Linux) || os(Android)
import Foundation
#else
#if canImport(SwiftUI)
import SwiftUI
import Combine
#elseif canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

public class SVGDefs: SVGGroup {}
Expand Down
8 changes: 5 additions & 3 deletions Source/Model/Nodes/SVGGroup.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#if os(WASI) || os(Linux) || os(Android)
import Foundation
#else
#if canImport(SwiftUI)
import SwiftUI
import Combine
#elseif canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

public class SVGGroup: SVGNode {
Expand Down
8 changes: 5 additions & 3 deletions Source/Model/Nodes/SVGImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
// Created by Alisa Mylnikova on 03/06/2021.
//

#if os(WASI) || os(Linux) || os(Android)
import Foundation
#else
#if canImport(SwiftUI)
import SwiftUI
import Combine
#elseif canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

public class SVGImage: SVGNode {
Expand Down
8 changes: 5 additions & 3 deletions Source/Model/Nodes/SVGMarker.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#if os(WASI) || os(Linux) || os(Android)
import Foundation
#else
#if canImport(SwiftUI)
import SwiftUI
import Combine
#elseif canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

public class SVGMarker: SVGGroup {
Expand Down
8 changes: 5 additions & 3 deletions Source/Model/Nodes/SVGNode.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#if os(WASI) || os(Linux) || os(Android)
import Foundation
#else
#if canImport(SwiftUI)
import SwiftUI
import Combine
#elseif canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

public class SVGNode: SerializableElement {
Expand Down
8 changes: 5 additions & 3 deletions Source/Model/Nodes/SVGShape.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#if os(WASI) || os(Linux) || os(Android)
import Foundation
#else
#if canImport(SwiftUI)
import SwiftUI
import Combine
#elseif canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

public class SVGShape: SVGNode {
Expand Down
8 changes: 5 additions & 3 deletions Source/Model/Nodes/SVGText.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#if os(WASI) || os(Linux) || os(Android)
import Foundation
#else
#if canImport(SwiftUI)
import SwiftUI
import Combine
#elseif canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

public class SVGText: SVGNode {
Expand Down
8 changes: 5 additions & 3 deletions Source/Model/Nodes/SVGUserSpaceNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
// Created by Alisa Mylnikova on 14/10/2020.
//

#if os(WASI) || os(Linux) || os(Android)
import Foundation
#else
#if canImport(SwiftUI)
import SwiftUI
#elseif canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

public class SVGUserSpaceNode: SVGNode {
Expand Down
8 changes: 5 additions & 3 deletions Source/Model/Nodes/SVGViewport.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#if os(WASI) || os(Linux) || os(Android)
import Foundation
#else
#if canImport(SwiftUI)
import SwiftUI
import Combine
#elseif canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

public class SVGViewport: SVGGroup {
Expand Down
Loading