From 000a6d868c4f6ad37a37d900b461ddd28bc018ad Mon Sep 17 00:00:00 2001 From: Kyle Date: Sun, 22 Nov 2026 15:28:43 +0800 Subject: [PATCH] refactor(path): remove OPENRENDERBOX_CF_CGTYPES conditional Remove CF_CGTYPES/OPENRENDERBOX_CF_CGTYPES and select the C/C++ ORBPath backend on Darwin and the portable Swift backend on non-Darwin platforms. --- AGENTS.md | 2 +- Package.resolved | 2 +- Package.swift | 13 +- Project.swift | 23 +-- README.md | 12 +- Scripts/Tests/framework-test | 12 +- .../Animation/ORBSymbolUpdate.swift | 9 +- Sources/OpenRenderBox/Path/ORBPath.swift | 2 +- .../OpenRenderBox/Path/ORBPathCFData.swift | 2 +- .../OpenRenderBox/Path/ORBPathCallbacks.swift | 2 +- Sources/OpenRenderBox/Path/ORBPathData.swift | 2 +- .../OpenRenderBox/Path/ORBPathGeometry.swift | 2 +- .../OpenRenderBox/Path/ORBPathStorage.swift | 2 +- .../Animation/ORBSymbolUpdate.h | 2 - .../Animation/ORBSymbolUpdate.m | 5 +- Sources/OpenRenderBoxCxx/Base/CFCGTypes.h | 135 +----------------- Sources/OpenRenderBoxCxx/Base/ORBBase.h | 9 -- .../Path/ClipStrokeKeyframes.hpp | 4 +- .../OpenRenderBoxCxx/Path/NestedCallbacks.cpp | 6 +- .../OpenRenderBoxCxx/Path/NestedCallbacks.hpp | 4 +- Sources/OpenRenderBoxCxx/Path/ORBPath.cpp | 14 +- Sources/OpenRenderBoxCxx/Path/ORBPath.h | 13 +- .../Path/ORBPathCallbacks.cpp | 8 +- .../OpenRenderBoxCxx/Path/ORBPathCallbacks.h | 16 +-- .../OpenRenderBoxCxx/Path/ORBPathStorage.cpp | 9 +- .../OpenRenderBoxCxx/Path/ORBPathStorage.h | 8 +- .../OpenRenderBoxCxx/Path/PathClipStroke.cpp | 4 +- .../OpenRenderBoxCxx/Path/PathClipStroke.hpp | 4 +- Sources/OpenRenderBoxCxx/Path/PathData.cpp | 4 +- .../OpenRenderBoxCxx/Path/PathEnumeration.cpp | 4 +- .../OpenRenderBoxCxx/Path/PathGeometry.hpp | 4 +- .../Path/PathInterpolation.cpp | 4 +- .../Path/PathInterpolation.hpp | 4 +- Sources/OpenRenderBoxCxx/Path/PathMapper.cpp | 5 +- Sources/OpenRenderBoxCxx/Path/PathMapper.hpp | 4 +- .../Path/PathStorageObject.cpp | 9 +- .../Path/PathStorageObject.hpp | 4 +- Sources/OpenRenderBoxCxx/Path/RoundedRect.cpp | 4 +- Sources/OpenRenderBoxCxx/Path/RoundedRect.hpp | 6 +- Sources/OpenRenderBoxCxx/Path/Storage.cpp | 24 +--- Sources/OpenRenderBoxCxx/Path/Storage.hpp | 12 +- .../PathArcMappingTests.swift | 2 +- .../PathCallbacksTests.swift | 2 +- .../PathOperationsTests.swift | 2 +- .../PathRegressionTests.swift | 2 +- .../PathStorageTests.swift | 2 +- .../PathTestSupport.swift | 4 +- .../PathTests.swift | 2 +- .../PathWrapperTests.swift | 2 +- .../OpenRenderBoxCompatibilityTests/README.md | 12 +- Tests/OpenRenderBoxTests/Path/PathTests.swift | 2 +- .../Path/PortableCFDataTestSupport.swift | 2 +- .../Path/PortablePathTests.swift | 2 +- 53 files changed, 104 insertions(+), 346 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 8855c78..904ef66 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -3,5 +3,5 @@ ## Preprocessor Definition Naming Conventions - **C/C++ definitions**: Use `ORB_` prefix (e.g., `ORB_SWIFT_NAME`, `ORB_TARGET_OS_DARWIN`) -- **Package.swift injected definitions**: Use `OPENRENDERBOX_` prefix (e.g., `OPENRENDERBOX_CF_CGTYPES`, `OPENRENDERBOX_RENDERBOX`) +- **Package.swift injected definitions**: Use `OPENRENDERBOX_` prefix (e.g., `OPENRENDERBOX_RENDERBOX`) diff --git a/Package.resolved b/Package.resolved index a5b0fae..3803c56 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "1477c74d879eeac85b29c7bc660a95d816c9b92adc30152ebfdd49d35535b059", + "originHash" : "22645b5e9556d333d3244c9b954e21c3666f9bcfafdcbdd8987a6ec37fb5fd52", "pins" : [ { "identity" : "darwinprivateframeworks", diff --git a/Package.swift b/Package.swift index e926f83..8d3414c 100644 --- a/Package.swift +++ b/Package.swift @@ -155,20 +155,17 @@ let compatibilityTestCondition = envBoolValue("COMPATIBILITY_TEST", default: fal let useLocalDeps = envBoolValue("USE_LOCAL_DEPS") let renderBoxCondtion = envBoolValue("RENDERBOX", default: buildForDarwinPlatform && !isSPIBuild) -// C geometry types conflict with Foundation's Swift geometry types on Linux. -// Disable this flag to use Swift Path instead of the C++ implementation. -let cfCGTypes = envBoolValue("CF_CGTYPES", default: buildForDarwinPlatform) // Use OPENSWIFTUI_COREGRAPHICS to select the same backend in ORB and OCG shims. let coreGraphicsCondition = envBoolValue("COREGRAPHICS", default: buildForDarwinPlatform) // MARK: - Shared Settings -var sharedCSettings: [CSetting] = [ +let sharedCSettings: [CSetting] = [ .unsafeFlags(["-I", libSwiftPath], .when(platforms: .nonDarwinPlatforms)), // .unsafeFlags(["-fmodules"]), .define("__COREFOUNDATION_FORSWIFTFOUNDATIONONLY__", to: "1", .when(platforms: .nonDarwinPlatforms)), ] -var sharedCxxSettings: [CXXSetting] = [ +let sharedCxxSettings: [CXXSetting] = [ .unsafeFlags(["-I", libSwiftPath], .when(platforms: .nonDarwinPlatforms)), // .unsafeFlags(["-fcxx-modules"]), .define("__COREFOUNDATION_FORSWIFTFOUNDATIONONLY__", to: "1", .when(platforms: .nonDarwinPlatforms)), @@ -183,12 +180,6 @@ if libraryEvolutionCondition { sharedSwiftSettings.append(.unsafeFlags(["-enable-library-evolution", "-no-verify-emitted-module-interface"])) } -if cfCGTypes { - sharedCSettings.append(.define("OPENRENDERBOX_CF_CGTYPES")) - sharedCxxSettings.append(.define("OPENRENDERBOX_CF_CGTYPES")) - sharedSwiftSettings.append(.define("OPENRENDERBOX_CF_CGTYPES")) -} - if coreGraphicsCondition { sharedSwiftSettings.append(.define("OPENRENDERBOX_COREGRAPHICS")) } diff --git a/Project.swift b/Project.swift index 1a3dde0..8dbf590 100644 --- a/Project.swift +++ b/Project.swift @@ -15,7 +15,6 @@ let moduleHeaders = sourceModuleMap.components(separatedBy: .newlines).compactMa // Use the same module declarations for SwiftPM and the framework. let frameworkModuleMap = "framework " + sourceModuleMap .replacingOccurrences(of: "module OpenRenderBoxCxx", with: "module OpenRenderBox") - .replacingOccurrences(of: "module OpenRenderBox.C {", with: "module OpenRenderBox.C {\n header \"ORBConfiguration.h\"") .replacingOccurrences(of: "header \"OpenRenderBox/", with: "header \"") .replacingOccurrences(of: "header \"../", with: "header \"") let moduleMapDirectory = root.appendingPathComponent("Derived/ModuleMaps") @@ -26,19 +25,6 @@ try frameworkModuleMap.write( encoding: .utf8 ) -// Consumers must use the same backend as the framework binary. -let frameworkConfiguration = """ -#pragma once - -#if defined(OPENRENDERBOX_CF_CGTYPES) && OPENRENDERBOX_CF_CGTYPES != 1 -#error "This OpenRenderBox framework requires OPENRENDERBOX_CF_CGTYPES=1." -#endif -#ifndef OPENRENDERBOX_CF_CGTYPES -#define OPENRENDERBOX_CF_CGTYPES 1 -#endif - -""" - // Preserve feature paths for the C++ and Objective-C submodules. let internalHeaders = moduleHeaders.filter { $0.hasPrefix("../") }.map { String($0.dropFirst(3)) } // Tuist otherwise treats template headers as resources and adds a resource bundle. @@ -53,16 +39,11 @@ let headerCopyCommands = internalHeaders.map { header in let exportModuleHeaders = TargetScript.pre( script: """ set -eu - mkdir -p "${TARGET_BUILD_DIR}/${PUBLIC_HEADERS_FOLDER_PATH}" - cat > "${TARGET_BUILD_DIR}/${PUBLIC_HEADERS_FOLDER_PATH}/ORBConfiguration.h" <<'EOF' - \(frameworkConfiguration) - EOF \(headerCopyCommands) """, name: "Export module headers", inputPaths: internalHeaders.map { .glob(.path("\(sourceRoot)/\($0)")) }, - outputPaths: [.path("$(TARGET_BUILD_DIR)/$(PUBLIC_HEADERS_FOLDER_PATH)/ORBConfiguration.h")] - + internalHeaders.map { .path("$(TARGET_BUILD_DIR)/$(PUBLIC_HEADERS_FOLDER_PATH)/\($0)") }, + outputPaths: internalHeaders.map { .path("$(TARGET_BUILD_DIR)/$(PUBLIC_HEADERS_FOLDER_PATH)/\($0)") }, basedOnDependencyAnalysis: true ) @@ -75,8 +56,6 @@ let project = Project( name: "OpenRenderBox", settings: .settings(base: [ "CLANG_CXX_LANGUAGE_STANDARD": "c++20", - "GCC_PREPROCESSOR_DEFINITIONS": ["$(inherited)", "OPENRENDERBOX_CF_CGTYPES"], - "SWIFT_ACTIVE_COMPILATION_CONDITIONS": ["$(inherited)", "OPENRENDERBOX_CF_CGTYPES"], "SWIFT_VERSION": "5.0", ]), targets: [ diff --git a/README.md b/README.md index 4fd797c..08d6679 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,10 @@ Currently, this project is in early development. The current suggested toolchain to build the project is Swift 6.3.3 / Xcode 26.6. Tuist builds `OpenRenderBoxCxx` as a static library and links it into the dynamic -`OpenRenderBox.framework`. This build uses the Darwin SDK's CoreGraphics types. -Use SwiftPM for the other backend configurations. +`OpenRenderBox.framework`. + +Path uses the C++ implementation and the SDK's CoreGraphics types on Apple +platforms. It uses the Swift implementation on other platforms. ```sh tuist generate run --no-open --cache-profile none @@ -37,9 +39,6 @@ Scripts/Tests/framework-test .build/tuist-framework/Build/Products/Release/OpenR The framework contains the public C headers and the C++, Objective-C, and Swift modules. The client test uses a separate copy of the bundle with no source search paths and compiles the Swift interface. -The framework exports `ORBConfiguration.h` with its fixed CoreGraphics backend -setting. Consumers can use its path APIs without extra compiler definitions. -SwiftPM continues to select the backend with `OPENRENDERBOX_CF_CGTYPES`. ## Source Layout @@ -83,7 +82,8 @@ Run the helper tests with `Scripts/Tests/add-header-test`. ## Shims -The `OpenRenderBoxShims` product provides Swift aliases and a C header for path APIs. +The `OpenRenderBoxShims` product provides Swift aliases for Path APIs. Its C +header exposes Path APIs on Apple platforms. Swift clients use: ```swift diff --git a/Scripts/Tests/framework-test b/Scripts/Tests/framework-test index 8fce3db..0932106 100755 --- a/Scripts/Tests/framework-test +++ b/Scripts/Tests/framework-test @@ -84,6 +84,7 @@ EOF cat > client.swift <<'EOF' import OpenRenderBox +import OpenRenderBox.ObjC precondition(ORBColor.black.alpha == 1) precondition(ORBPath.empty.isEmpty) @@ -96,8 +97,9 @@ EOF target="$(uname -m)-apple-macos15.0" common=(-target "$target" -F "$test_root" -framework OpenRenderBox -Wl,-rpath,"$test_root") -# Each guarded header must expose its API without another header setting the backend first. -for declaration in CFCGTypes.h:CGFloat ORBPath.h:ORBPath ORBPathCallbacks.h:ORBPathCallbacks ORBPathStorage.h:ORBPathStorageRef; do +# Check the public headers independently of include order. +for declaration in CFCGTypes.h:CGFloat CFCGTypes.h:CGSize CFCGTypes.h:CGPoint CFCGTypes.h:CGRect \ + ORBPath.h:ORBPath ORBPathCallbacks.h:ORBPathCallbacks ORBPathStorage.h:ORBPathStorageRef; do printf '#include \n%s value;\n' "${declaration%:*}" "${declaration#*:}" > path-header.c xcrun clang -target "$target" -F "$test_root" -fsyntax-only path-header.c done @@ -105,12 +107,6 @@ for declaration in Path/Storage.hpp:ORB::Path::Storage Path/NestedCallbacks.hpp: printf '#include \nstatic_assert(sizeof(%s) > 0);\n' "${declaration%%:*}" "${declaration#*:}" > path-header.cpp xcrun clang++ -target "$target" -F "$test_root" -std=c++20 -fsyntax-only path-header.cpp done -if xcrun clang -target "$target" -F "$test_root" -DOPENRENDERBOX_CF_CGTYPES=0 \ - -fsyntax-only path-header.c > backend-conflict.log 2>&1; then - echo "The framework must reject a conflicting backend setting." >&2 - exit 1 -fi -grep -Fq 'requires OPENRENDERBOX_CF_CGTYPES=1' backend-conflict.log xcrun clang "${common[@]}" client.c -o client-c ./client-c xcrun clang++ "${common[@]}" -std=c++20 client.cpp -o client-cxx diff --git a/Sources/OpenRenderBox/Animation/ORBSymbolUpdate.swift b/Sources/OpenRenderBox/Animation/ORBSymbolUpdate.swift index 9ea0392..6bfbef6 100644 --- a/Sources/OpenRenderBox/Animation/ORBSymbolUpdate.swift +++ b/Sources/OpenRenderBox/Animation/ORBSymbolUpdate.swift @@ -2,12 +2,9 @@ // ORBSymbolUpdate.swift // OpenRenderBox -#if !canImport(ObjectiveC) || !OPENRENDERBOX_CF_CGTYPES +#if !canImport(ObjectiveC) public import OpenCoreGraphicsShims public import OpenRenderBoxCxx.C -#endif - -#if !canImport(ObjectiveC) extension ORBSymbolUpdate { public var nextTime: Double { .infinity } @@ -30,11 +27,7 @@ extension ORBSymbolUpdateLayer { public var defaultColor: CGColor? { nil } public func draw(in state: ORBDrawingState, color: ORBColor, opacity: Float, blendMode: ORBBlendMode, flags: ORBSymbolUpdateLayerFlags) {} -} -#endif -#if !canImport(ObjectiveC) || !OPENRENDERBOX_CF_CGTYPES -extension ORBSymbolUpdateLayer { public func path(transform: UnsafeMutablePointer, flags: ORBSymbolUpdateLayerFlags) -> ORBPath { transform.pointee = .identity return .null diff --git a/Sources/OpenRenderBox/Path/ORBPath.swift b/Sources/OpenRenderBox/Path/ORBPath.swift index 245acda..82533eb 100644 --- a/Sources/OpenRenderBox/Path/ORBPath.swift +++ b/Sources/OpenRenderBox/Path/ORBPath.swift @@ -2,7 +2,7 @@ // ORBPath.swift // OpenRenderBox -#if !OPENRENDERBOX_CF_CGTYPES +#if !canImport(Darwin) public import OpenCoreGraphicsShims public typealias ORBPathApplyCallback = (UnsafeMutableRawPointer, ORBPath.Element, UnsafePointer, UnsafeRawPointer?) -> Bool diff --git a/Sources/OpenRenderBox/Path/ORBPathCFData.swift b/Sources/OpenRenderBox/Path/ORBPathCFData.swift index b935e3b..ebb5aac 100644 --- a/Sources/OpenRenderBox/Path/ORBPathCFData.swift +++ b/Sources/OpenRenderBox/Path/ORBPathCFData.swift @@ -2,7 +2,7 @@ // ORBPathCFData.swift // OpenRenderBox -#if !OPENRENDERBOX_CF_CGTYPES +#if !canImport(Darwin) public import CoreFoundation extension ORBPath { diff --git a/Sources/OpenRenderBox/Path/ORBPathCallbacks.swift b/Sources/OpenRenderBox/Path/ORBPathCallbacks.swift index 6a77eab..aee8d37 100644 --- a/Sources/OpenRenderBox/Path/ORBPathCallbacks.swift +++ b/Sources/OpenRenderBox/Path/ORBPathCallbacks.swift @@ -2,7 +2,7 @@ // ORBPathCallbacks.swift // OpenRenderBox -#if !OPENRENDERBOX_CF_CGTYPES +#if !canImport(Darwin) public import OpenCoreGraphicsShims // MARK: - ORBPath.CallbacksFlags diff --git a/Sources/OpenRenderBox/Path/ORBPathData.swift b/Sources/OpenRenderBox/Path/ORBPathData.swift index 186b300..ac482b3 100644 --- a/Sources/OpenRenderBox/Path/ORBPathData.swift +++ b/Sources/OpenRenderBox/Path/ORBPathData.swift @@ -2,7 +2,7 @@ // ORBPathData.swift // OpenRenderBox -#if !OPENRENDERBOX_CF_CGTYPES +#if !canImport(Darwin) import OpenCoreGraphicsShims private typealias _ORBCGFloat = CGFloat diff --git a/Sources/OpenRenderBox/Path/ORBPathGeometry.swift b/Sources/OpenRenderBox/Path/ORBPathGeometry.swift index 95cdc80..db55005 100644 --- a/Sources/OpenRenderBox/Path/ORBPathGeometry.swift +++ b/Sources/OpenRenderBox/Path/ORBPathGeometry.swift @@ -2,7 +2,7 @@ // ORBPathGeometry.swift // OpenRenderBox -#if !OPENRENDERBOX_CF_CGTYPES +#if !canImport(Darwin) import Foundation import OpenCoreGraphicsShims diff --git a/Sources/OpenRenderBox/Path/ORBPathStorage.swift b/Sources/OpenRenderBox/Path/ORBPathStorage.swift index 74116b3..e0eac1e 100644 --- a/Sources/OpenRenderBox/Path/ORBPathStorage.swift +++ b/Sources/OpenRenderBox/Path/ORBPathStorage.swift @@ -2,7 +2,7 @@ // ORBPathStorage.swift // OpenRenderBox -#if !OPENRENDERBOX_CF_CGTYPES +#if !canImport(Darwin) public import OpenCoreGraphicsShims extension ORBPath.Storage { diff --git a/Sources/OpenRenderBoxCxx/Animation/ORBSymbolUpdate.h b/Sources/OpenRenderBoxCxx/Animation/ORBSymbolUpdate.h index d8de26b..7299b2a 100644 --- a/Sources/OpenRenderBoxCxx/Animation/ORBSymbolUpdate.h +++ b/Sources/OpenRenderBoxCxx/Animation/ORBSymbolUpdate.h @@ -63,9 +63,7 @@ ORB_EXPORT ORBSymbolStyle ORBSymbolUpdateLayerStyle(ORBSymbolUpdateLayer layer) ORB_EXPORT NSString * _Nullable ORBSymbolUpdateLayerColorName(ORBSymbolUpdateLayer layer) ORB_SWIFT_NAME(getter:ORBSymbolUpdateLayer.colorName(self:)); ORB_EXPORT CGColorRef _Nullable ORBSymbolUpdateLayerDefaultColor(ORBSymbolUpdateLayer layer) CF_RETURNS_NOT_RETAINED ORB_SWIFT_NAME(getter:ORBSymbolUpdateLayer.defaultColor(self:)); // The update owns the returned path. Copy it before the update ends. -#if OPENRENDERBOX_CF_CGTYPES ORB_EXPORT ORBPath ORBSymbolUpdateLayerPath(ORBSymbolUpdateLayer layer, CGAffineTransform *transform, ORBSymbolUpdateLayerFlags flags) ORB_SWIFT_NAME(ORBSymbolUpdateLayer.path(self:transform:flags:)); -#endif ORB_EXPORT void ORBSymbolUpdateLayerDraw(ORBSymbolUpdateLayer layer, ORBDrawingState state, ORBColor color, float opacity, ORBBlendMode blendMode, ORBSymbolUpdateLayerFlags flags) ORB_SWIFT_NAME(ORBSymbolUpdateLayer.draw(self:in:color:opacity:blendMode:flags:)); ORB_EXTERN_C_END diff --git a/Sources/OpenRenderBoxCxx/Animation/ORBSymbolUpdate.m b/Sources/OpenRenderBoxCxx/Animation/ORBSymbolUpdate.m index ffdb473..e40c9f9 100644 --- a/Sources/OpenRenderBoxCxx/Animation/ORBSymbolUpdate.m +++ b/Sources/OpenRenderBoxCxx/Animation/ORBSymbolUpdate.m @@ -6,7 +6,10 @@ #if ORB_OBJC_FOUNDATION +#include +#include #include +#include // Symbol updates are placeholders until the symbol renderer is implemented. double ORBSymbolUpdateNextTime(ORBSymbolUpdate update) { return INFINITY; } @@ -19,12 +22,10 @@ void ORBSymbolUpdateDrawWithStyleResolver(ORBSymbolUpdate update, ORBDrawingStat ORBSymbolStyle ORBSymbolUpdateLayerStyle(ORBSymbolUpdateLayer layer) { return ORBSymbolStylePrimary; } NSString *ORBSymbolUpdateLayerColorName(ORBSymbolUpdateLayer layer) { return nil; } CGColorRef ORBSymbolUpdateLayerDefaultColor(ORBSymbolUpdateLayer layer) { return NULL; } -#if OPENRENDERBOX_CF_CGTYPES ORBPath ORBSymbolUpdateLayerPath(ORBSymbolUpdateLayer layer, CGAffineTransform *transform, ORBSymbolUpdateLayerFlags flags) { *transform = CGAffineTransformIdentity; return ORBPathNull; } -#endif void ORBSymbolUpdateLayerDraw(ORBSymbolUpdateLayer layer, ORBDrawingState state, ORBColor color, float opacity, ORBBlendMode blendMode, ORBSymbolUpdateLayerFlags flags) {} #endif /* ORB_OBJC_FOUNDATION */ diff --git a/Sources/OpenRenderBoxCxx/Base/CFCGTypes.h b/Sources/OpenRenderBoxCxx/Base/CFCGTypes.h index 12f1be4..f8891cf 100644 --- a/Sources/OpenRenderBoxCxx/Base/CFCGTypes.h +++ b/Sources/OpenRenderBoxCxx/Base/CFCGTypes.h @@ -1,132 +1,11 @@ -#if __has_include() -#include -#endif - -#if OPENRENDERBOX_CF_CGTYPES - -/* CFCGTypes.h - Copyright (c) 1998-2021, Apple Inc. and the Swift project authors - - Portions Copyright (c) 2014-2021, Apple Inc. and the Swift project authors - Licensed under Apache License v2.0 with Runtime Library Exception - See http://swift.org/LICENSE.txt for license information - See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -*/ +// +// CFCGTypes.h +// OpenRenderBox -#if !defined(__COREFOUNDATION_CFCGTYPES__) -#define __COREFOUNDATION_CFCGTYPES__ 1 +#pragma once -#include -#include -#include -#include +#include -#define CF_DEFINES_CG_TYPES - -#if defined(__has_attribute) && __has_attribute(objc_boxable) -# define CF_BOXABLE __attribute__((objc_boxable)) -#else -# define CF_BOXABLE +#if ORB_TARGET_OS_DARWIN +#include #endif - -/* Definition of `CGFLOAT_TYPE', `CGFLOAT_IS_DOUBLE', `CGFLOAT_MIN', and - * `CGFLOAT_MAX'. */ - - #if defined(__LP64__) && __LP64__ - # define CGFLOAT_TYPE double - # define CGFLOAT_IS_DOUBLE 1 - # define CGFLOAT_MIN DBL_MIN - # define CGFLOAT_MAX DBL_MAX - # define CGFLOAT_EPSILON DBL_EPSILON - #else - # define CGFLOAT_TYPE float - # define CGFLOAT_IS_DOUBLE 0 - # define CGFLOAT_MIN FLT_MIN - # define CGFLOAT_MAX FLT_MAX - # define CGFLOAT_EPSILON FLT_EPSILON - #endif - -/* Definition of the `CGFloat' type and `CGFLOAT_DEFINED'. */ - -typedef CGFLOAT_TYPE CGFloat; -#define CGFLOAT_DEFINED 1 - -/* Points. */ -struct -CGPoint { - CGFloat x; - CGFloat y; -}; -typedef struct CF_BOXABLE CGPoint CGPoint; - -/* Sizes. */ - -struct CGSize { - CGFloat width; - CGFloat height; -}; -typedef struct CF_BOXABLE CGSize CGSize; - -/* Vectors. */ - -#define CGVECTOR_DEFINED 1 - -struct CGVector { - CGFloat dx; - CGFloat dy; -}; -typedef struct CF_BOXABLE CGVector CGVector; - -/* Rectangles. */ - -struct CGRect { - CGPoint origin; - CGSize size; -}; -typedef struct CF_BOXABLE CGRect CGRect; - -/* Rectangle edges. */ - -typedef CF_CLOSED_ENUM(uint32_t, CGRectEdge) { - CGRectMinXEdge, CGRectMinYEdge, CGRectMaxXEdge, CGRectMaxYEdge -}; - -typedef struct CGAffineTransform CGAffineTransform; - -struct CGAffineTransform { - CGFloat a, b, c, d; - CGFloat tx, ty; -}; - -#define CF_DEFINES_CGAFFINETRANSFORMCOMPONENTS - -/* |------------------ CGAffineTransformComponents ----------------| - * - * | a b 0 | | sx 0 0 | | 1 0 0 | | cos(t) sin(t) 0 | | 1 0 0 | - * | c d 0 | = | 0 sy 0 | * | sh 1 0 | * |-sin(t) cos(t) 0 | * | 0 1 0 | - * | tx ty 1 | | 0 0 1 | | 0 0 1 | | 0 0 1 | | tx ty 1 | - * CGAffineTransform scale shear rotation translation - */ -typedef struct CGAffineTransformComponents CGAffineTransformComponents - CF_SWIFT_NAME(CGAffineTransform.Components); - -struct CGAffineTransformComponents { - - /* initial scaling in X and Y dimensions. {sx,sy} */ - /* Negative values indicate the image has been flipped in this dimension. */ - CGSize scale; - - /* shear distortion (sh). Turns rectangles to parallelograms. 0 for no shear. Typically 0. */ - CGFloat horizontalShear; - - /* Rotation angle in radians about the origin. (t) Sign convention for clockwise rotation */ - /* may differ between various Apple frameworks based on origin placement. Please see discussion. */ - CGFloat rotation; - - /* Displacement from the origin (ty, ty) */ - CGVector translation; -}; - -#endif /* ! __COREFOUNDATION_CFCGTYPES__ */ - -#endif /* OPENRENDERBOX_CF_CGTYPES */ diff --git a/Sources/OpenRenderBoxCxx/Base/ORBBase.h b/Sources/OpenRenderBoxCxx/Base/ORBBase.h index 84627af..636afce 100644 --- a/Sources/OpenRenderBoxCxx/Base/ORBBase.h +++ b/Sources/OpenRenderBoxCxx/Base/ORBBase.h @@ -4,11 +4,6 @@ #pragma once -// Framework builds export their fixed backend configuration. -#if __has_include() -#include -#endif - #if DEBUG #define ORB_ASSERTION #else @@ -70,7 +65,3 @@ #else #define ORB_OBJC_FOUNDATION 0 #endif /* TARGET_OS_DARWIN && __OBJC__ */ - -#if !ORB_TRRET_OS_DARWIN -#include -#endif diff --git a/Sources/OpenRenderBoxCxx/Path/ClipStrokeKeyframes.hpp b/Sources/OpenRenderBoxCxx/Path/ClipStrokeKeyframes.hpp index 10f8edb..3408d9a 100644 --- a/Sources/OpenRenderBoxCxx/Path/ClipStrokeKeyframes.hpp +++ b/Sources/OpenRenderBoxCxx/Path/ClipStrokeKeyframes.hpp @@ -6,7 +6,7 @@ #include "PathClipStroke.hpp" -#if OPENRENDERBOX_CF_CGTYPES && ORB_TARGET_OS_DARWIN +#if ORB_TARGET_OS_DARWIN #include #include @@ -261,4 +261,4 @@ inline std::vector remapKeyframes(const std::vector &keys, } } // namespace ORB::Path::ClipStroke -#endif +#endif /* ORB_TARGET_OS_DARWIN */ diff --git a/Sources/OpenRenderBoxCxx/Path/NestedCallbacks.cpp b/Sources/OpenRenderBoxCxx/Path/NestedCallbacks.cpp index 946779d..95979b5 100644 --- a/Sources/OpenRenderBoxCxx/Path/NestedCallbacks.cpp +++ b/Sources/OpenRenderBoxCxx/Path/NestedCallbacks.cpp @@ -2,7 +2,9 @@ // NestedCallbacks.cpp // OpenRenderBox -#if OPENRENDERBOX_CF_CGTYPES +#include + +#if ORB_TARGET_OS_DARWIN #include "NestedCallbacks.hpp" #include @@ -182,4 +184,4 @@ bool NestedCallbacks::first_element(const Storage &storage, Storage::Iterator &i } /* Path */ } /* ORB */ -#endif /* OPENRENDERBOX_CF_CGTYPES */ +#endif /* ORB_TARGET_OS_DARWIN */ diff --git a/Sources/OpenRenderBoxCxx/Path/NestedCallbacks.hpp b/Sources/OpenRenderBoxCxx/Path/NestedCallbacks.hpp index b720382..f438347 100644 --- a/Sources/OpenRenderBoxCxx/Path/NestedCallbacks.hpp +++ b/Sources/OpenRenderBoxCxx/Path/NestedCallbacks.hpp @@ -6,7 +6,7 @@ #include -#if OPENRENDERBOX_CF_CGTYPES +#if ORB_TARGET_OS_DARWIN #include #include "Storage.hpp" @@ -57,4 +57,4 @@ static_assert(offsetof(NestedCallbacks, nestedIndex) == 0x60, "nestedIndex offse ORB_ASSUME_NONNULL_END -#endif /* OPENRENDERBOX_CF_CGTYPES */ +#endif /* ORB_TARGET_OS_DARWIN */ diff --git a/Sources/OpenRenderBoxCxx/Path/ORBPath.cpp b/Sources/OpenRenderBoxCxx/Path/ORBPath.cpp index be1d02b..af736f9 100644 --- a/Sources/OpenRenderBoxCxx/Path/ORBPath.cpp +++ b/Sources/OpenRenderBoxCxx/Path/ORBPath.cpp @@ -5,7 +5,9 @@ // Created by Kyle on 2025/3/25. // -#if OPENRENDERBOX_CF_CGTYPES +#include + +#if ORB_TARGET_OS_DARWIN #include #include @@ -62,8 +64,6 @@ void ORBPathRelease(ORBPath path) { } } -#if ORB_TARGET_OS_DARWIN - CG_EXTERN bool CGPathIsPrimitive(CGPathRef path); CG_EXTERN bool CGPathIsRectWithTransform( CGPathRef path, @@ -90,7 +90,6 @@ CG_EXTERN void CGPathAddContinuousRoundedRect( CGFloat cornerHeight ); - // MARK: - Path Creation namespace { @@ -436,8 +435,6 @@ ORBPath ORBPathCopyTrimmedPath(ORBPath path, CGFloat from, CGFloat to) { return {reinterpret_cast(storage), &wrapped_path_callbacks}; } -#endif /* ORB_TARGET_OS_DARWIN */ - bool ORBPathIsEmpty(ORBPath path) { if (path.callbacks == &empty_path_callbacks) { return true; @@ -532,7 +529,6 @@ bool ORBPathApplyShape( return false; } -#if ORB_TARGET_OS_DARWIN if (path.callbacks == &ORBPathCGPathCallbacks) { auto cgPath = reinterpret_cast(path.storage); if (!CGPathIsPrimitive(cgPath)) { @@ -578,7 +574,6 @@ bool ORBPathApplyShape( } return false; } -#endif if (ORBPathIsSingleElement(path)) { struct ShapeInfo { @@ -816,7 +811,6 @@ bool ORBPathEqualToPath(ORBPath lhs, ORBPath rhs) { return equal && comparison.iterator.offset >= storage.actual_size(); } -#if ORB_TARGET_OS_DARWIN CGPathRef ORBPathCopyCGPath(ORBPath path) { if (path.callbacks == &empty_path_callbacks) { return CGPathCreateMutable(); @@ -995,5 +989,3 @@ uint64_t ORBPathContainsPoints(ORBPath path, uint64_t count, const CGPoint *poin } #endif /* ORB_TARGET_OS_DARWIN */ - -#endif /* OPENRENDERBOX_CF_CGTYPES */ diff --git a/Sources/OpenRenderBoxCxx/Path/ORBPath.h b/Sources/OpenRenderBoxCxx/Path/ORBPath.h index 5afeed4..755d47b 100644 --- a/Sources/OpenRenderBoxCxx/Path/ORBPath.h +++ b/Sources/OpenRenderBoxCxx/Path/ORBPath.h @@ -6,7 +6,7 @@ #include -#if OPENRENDERBOX_CF_CGTYPES +#if ORB_TARGET_OS_DARWIN #include #include @@ -60,7 +60,6 @@ typedef ORB_ENUM(int32_t, ORBPathRoundedCornerStyle) { /// Returns true to continue enumeration, false to stop typedef bool (*ORBPathApplyCallback)(void * info, ORBPathElement element, const CGFloat *points, const void * _Nullable userInfo); -#if ORB_TARGET_OS_DARWIN /// Callback for mapped Core Graphics elements. Return false to stop callbacks. typedef bool (*ORBPathApplierCallback)(void *info, const CGPathElement *element); @@ -72,7 +71,6 @@ typedef ORB_ENUM(int32_t, ORBPathLineElement) { /// The point is unused for a close-subpath callback. typedef bool (*ORBPathLineApplyCallback)(void *info, ORBPathLineElement element, const CGPoint *point); -#endif typedef struct ORBPathCallbacks ORBPathCallbacks ORB_SWIFT_NAME(ORBPath.ApplyCallback); @@ -186,7 +184,6 @@ void ORBPathRelease(ORBPath path) ORB_SWIFT_NAME(ORBPath.release(self:)); // MARK: - Path Creation -#if ORB_TARGET_OS_DARWIN ORB_EXPORT ORBPath ORBPathMakeWithCGPath(CGPathRef _Nullable cgPath) ORB_SWIFT_NAME(ORBPath.init(cgPath:)); @@ -201,7 +198,6 @@ ORBPath ORBPathMakeRoundedRect(CGRect rect, CGFloat cornerWidth, CGFloat cornerH ORB_EXPORT ORBPath ORBPathMakeUnevenRoundedRect(CGRect rect, CGFloat topLeftRadius, CGFloat topRightRadius, CGFloat bottomRightRadius, CGFloat bottomLeftRadius, ORBPathRoundedCornerStyle style, const CGAffineTransform * _Nullable transform) ORB_SWIFT_NAME(ORBPath.init(roundedRect:topLeftRadius:topRightRadius:bottomRightRadius:bottomLeftRadius:style:transform:)); -#endif ORB_EXPORT ORBPath ORBPathCopyTransformedPath(ORBPath path, const CGAffineTransform * _Nullable transform) ORB_SWIFT_NAME(ORBPath.copy(self:transform:)); @@ -216,7 +212,6 @@ static ORB_INLINE bool ORBPathIsNull(ORBPath path) ORB_SWIFT_NAME(getter:ORBPath return path.storage == ORBPathNull.storage && path.callbacks == ORBPathNull.callbacks; } - // MARK: - Path Operation ORB_EXPORT @@ -239,7 +234,6 @@ bool ORBPathEqualToPath(ORBPath lhs, ORBPath rhs) ORB_SWIFT_NAME(ORBPath.isEqual // MARK: - CGPath Interoperability -#if ORB_TARGET_OS_DARWIN ORB_EXPORT bool ORBPathApply(ORBPath path, const CGAffineTransform * _Nullable transform, void *info, ORBPathApplierCallback callback) ORB_SWIFT_NAME(ORBPath.applyCGPathElements(self:transform:info:callback:)); @@ -269,19 +263,16 @@ CGPathRef ORBPathCopyCGPath(ORBPath path) ORB_SWIFT_NAME(getter:ORBPath.cgPath(s ORB_EXPORT CGRect ORBPathGetBoundingRect(ORBPath path) ORB_SWIFT_NAME(getter:ORBPath.boundingRect(self:)); -#endif // MARK: - Point Containment -#if ORB_TARGET_OS_DARWIN ORB_EXPORT bool ORBPathContainsPoint(ORBPath path, CGPoint point, bool eoFill) ORB_SWIFT_NAME(ORBPath.contains(self:point:eoFill:)); ORB_EXPORT uint64_t ORBPathContainsPoints(ORBPath path, uint64_t count, const CGPoint *points, bool eoFill, const CGAffineTransform * _Nullable transform) ORB_SWIFT_NAME(ORBPath.containsPoints(self:count:points:eoFill:transform:)); -#endif ORB_EXTERN_C_END ORB_ASSUME_NONNULL_END -#endif /* OPENRENDERBOX_CF_CGTYPES */ +#endif /* ORB_TARGET_OS_DARWIN */ diff --git a/Sources/OpenRenderBoxCxx/Path/ORBPathCallbacks.cpp b/Sources/OpenRenderBoxCxx/Path/ORBPathCallbacks.cpp index c1691cc..f91aafb 100644 --- a/Sources/OpenRenderBoxCxx/Path/ORBPathCallbacks.cpp +++ b/Sources/OpenRenderBoxCxx/Path/ORBPathCallbacks.cpp @@ -5,13 +5,13 @@ // Audited for 6.5.1 // Status: Complete -#if OPENRENDERBOX_CF_CGTYPES +#include + +#if ORB_TARGET_OS_DARWIN #include #include -#if ORB_TARGET_OS_DARWIN - CG_EXTERN size_t CGPathGetNumberOfPoints(CGPathRef cg_nullable path); CG_EXTERN size_t CGPathGetNumberOfElements(CGPathRef cg_nullable path); typedef void (^CGPathApplyBlock2)(const CGPathElement * element, bool *stop); @@ -75,5 +75,3 @@ const ORBPathCallbacks ORBPathCGPathCallbacks = { }; #endif /* ORB_TARGET_OS_DARWIN */ - -#endif /* OPENRENDERBOX_CF_CGTYPES */ diff --git a/Sources/OpenRenderBoxCxx/Path/ORBPathCallbacks.h b/Sources/OpenRenderBoxCxx/Path/ORBPathCallbacks.h index 0dbf174..5040bf9 100644 --- a/Sources/OpenRenderBoxCxx/Path/ORBPathCallbacks.h +++ b/Sources/OpenRenderBoxCxx/Path/ORBPathCallbacks.h @@ -9,13 +9,11 @@ #include -#if OPENRENDERBOX_CF_CGTYPES +#if ORB_TARGET_OS_DARWIN #include #include -#if ORB_TARGET_OS_DARWIN #include -#endif ORB_ASSUME_NONNULL_BEGIN @@ -41,11 +39,7 @@ typedef struct ORB_SWIFT_NAME(ORBPath.Callbacks) ORBPathCallbacks { bool (* _Nullable isSingleElement)(const void *object); size_t (* _Nullable bezierOrder)(const void *object); CGRect (* _Nullable boundingRect)(const void *object); - #if ORB_TARGET_OS_DARWIN CGPathRef _Nullable (* _Nullable cgPath)(const void *object); - #else - void * _Nullable (* _Nullable cgPath)(const void *object); - #endif ORBPath (* _Nullable next)(const void *object); } ORBPathCallbacks; @@ -76,11 +70,7 @@ typedef struct ORB_SWIFT_NAME(ORBPath.CallbacksExtended) ORBPathCallbacksExtende bool (* _Nullable isSingleElement)(const void *object, const struct ORBPathCallbacksExtended *extended); size_t (* _Nullable bezierOrder)(const void *object, const struct ORBPathCallbacksExtended *extended); CGRect (* _Nullable boundingRect)(const void *object, const struct ORBPathCallbacksExtended *extended); - #if ORB_TARGET_OS_DARWIN CGPathRef _Nullable (* _Nullable cgPath)(const void *object, const struct ORBPathCallbacksExtended *extended); - #else - void * _Nullable (* _Nullable cgPath)(const void *object, const struct ORBPathCallbacksExtended *extended); - #endif ORBPath (* _Nullable next)(const void *object, const struct ORBPathCallbacksExtended *extended); } ORBPathCallbacksExtended; @@ -100,7 +90,6 @@ static_assert(offsetof(struct ORBPathCallbacksExtended, cgPath) == 0x48); static_assert(offsetof(struct ORBPathCallbacksExtended, next) == 0x50); #endif -#if ORB_TARGET_OS_DARWIN /// Global callbacks for CGPath-backed paths ORB_EXPORT const ORBPathCallbacks ORBPathCGPathCallbacks ORB_REFINED_FOR_SWIFT; @@ -109,10 +98,9 @@ static ORB_INLINE const ORBPathCallbacks *_ORBPathCallbacksGetCGPath(void) ORB_SWIFT_NAME(getter:ORBPathCallbacks.cgPath()) { return &ORBPathCGPathCallbacks; } -#endif ORB_EXTERN_C_END ORB_ASSUME_NONNULL_END -#endif /* OPENRENDERBOX_CF_CGTYPES */ +#endif /* ORB_TARGET_OS_DARWIN */ diff --git a/Sources/OpenRenderBoxCxx/Path/ORBPathStorage.cpp b/Sources/OpenRenderBoxCxx/Path/ORBPathStorage.cpp index 1512ed4..48357bf 100644 --- a/Sources/OpenRenderBoxCxx/Path/ORBPathStorage.cpp +++ b/Sources/OpenRenderBoxCxx/Path/ORBPathStorage.cpp @@ -2,7 +2,9 @@ // ORBPathStorage.cpp // OpenRenderBox -#if OPENRENDERBOX_CF_CGTYPES +#include + +#if ORB_TARGET_OS_DARWIN #include #include "Storage.hpp" @@ -72,8 +74,6 @@ size_t ORBPathStorageGetBezierOrder(ORBPathStorageRef storage) { return storage->storage.flags().bezierOrder(); } -#if ORB_TARGET_OS_DARWIN - CGRect ORBPathStorageGetBoundingRect(ORBPathStorageRef storage) { return storage->storage.bounding_rect(); } @@ -81,6 +81,5 @@ CGRect ORBPathStorageGetBoundingRect(ORBPathStorageRef storage) { CGPathRef ORBPathStorageGetCGPath(ORBPathStorageRef storage) { return storage->storage.cgpath(); } -#endif -#endif /* OPENRENDERBOX_CF_CGTYPES */ +#endif /* ORB_TARGET_OS_DARWIN */ diff --git a/Sources/OpenRenderBoxCxx/Path/ORBPathStorage.h b/Sources/OpenRenderBoxCxx/Path/ORBPathStorage.h index c0fbcc5..be43b24 100644 --- a/Sources/OpenRenderBoxCxx/Path/ORBPathStorage.h +++ b/Sources/OpenRenderBoxCxx/Path/ORBPathStorage.h @@ -9,12 +9,10 @@ #include -#if OPENRENDERBOX_CF_CGTYPES +#if ORB_TARGET_OS_DARWIN #include -#if ORB_TARGET_OS_DARWIN #include -#endif ORB_ASSUME_NONNULL_BEGIN @@ -50,17 +48,15 @@ bool ORBPathStorageIsSingleElement(ORBPathStorageRef storage) ORB_SWIFT_NAME(get ORB_EXPORT size_t ORBPathStorageGetBezierOrder(ORBPathStorageRef storage) ORB_SWIFT_NAME(getter:ORBPathStorageRef.bezierOrder(self:)); -#if ORB_TARGET_OS_DARWIN ORB_EXPORT CGRect ORBPathStorageGetBoundingRect(ORBPathStorageRef storage) ORB_SWIFT_NAME(getter:ORBPathStorageRef.boundingRect(self:)); ORB_EXPORT CF_RETURNS_NOT_RETAINED __nullable CGPathRef ORBPathStorageGetCGPath(ORBPathStorageRef storage) ORB_SWIFT_NAME(getter:ORBPathStorageRef.cgPath(self:)); -#endif ORB_EXTERN_C_END ORB_ASSUME_NONNULL_END -#endif /* OPENRENDERBOX_CF_CGTYPES */ +#endif /* ORB_TARGET_OS_DARWIN */ diff --git a/Sources/OpenRenderBoxCxx/Path/PathClipStroke.cpp b/Sources/OpenRenderBoxCxx/Path/PathClipStroke.cpp index 2e21189..7b5c503 100644 --- a/Sources/OpenRenderBoxCxx/Path/PathClipStroke.cpp +++ b/Sources/OpenRenderBoxCxx/Path/PathClipStroke.cpp @@ -4,7 +4,7 @@ #include "PathClipStroke.hpp" -#if OPENRENDERBOX_CF_CGTYPES && ORB_TARGET_OS_DARWIN +#if ORB_TARGET_OS_DARWIN #include "ClipStrokeKeyframes.hpp" #include "PathGeometry.hpp" @@ -596,4 +596,4 @@ CGPathRef copy_clip_stroke_path(CGPathRef path, float progress, const ClipStroke } // namespace ORB::Path -#endif +#endif /* ORB_TARGET_OS_DARWIN */ diff --git a/Sources/OpenRenderBoxCxx/Path/PathClipStroke.hpp b/Sources/OpenRenderBoxCxx/Path/PathClipStroke.hpp index 30360d8..22fd5a1 100644 --- a/Sources/OpenRenderBoxCxx/Path/PathClipStroke.hpp +++ b/Sources/OpenRenderBoxCxx/Path/PathClipStroke.hpp @@ -6,7 +6,7 @@ #include -#if OPENRENDERBOX_CF_CGTYPES && ORB_TARGET_OS_DARWIN +#if ORB_TARGET_OS_DARWIN #include #include @@ -32,4 +32,4 @@ CGPathRef copy_clip_stroke_path(CGPathRef path, float progress, const ClipStroke } // namespace ORB::Path -#endif +#endif /* ORB_TARGET_OS_DARWIN */ diff --git a/Sources/OpenRenderBoxCxx/Path/PathData.cpp b/Sources/OpenRenderBoxCxx/Path/PathData.cpp index 64cb55c..b1ba682 100644 --- a/Sources/OpenRenderBoxCxx/Path/PathData.cpp +++ b/Sources/OpenRenderBoxCxx/Path/PathData.cpp @@ -4,7 +4,7 @@ #include -#if OPENRENDERBOX_CF_CGTYPES && ORB_TARGET_OS_DARWIN +#if ORB_TARGET_OS_DARWIN #include #include "PathClipStroke.hpp" @@ -430,4 +430,4 @@ CFStringRef ORBPathCopyDebugDescription(ORBPath path) { return result; } -#endif +#endif /* ORB_TARGET_OS_DARWIN */ diff --git a/Sources/OpenRenderBoxCxx/Path/PathEnumeration.cpp b/Sources/OpenRenderBoxCxx/Path/PathEnumeration.cpp index 30752e5..e45a996 100644 --- a/Sources/OpenRenderBoxCxx/Path/PathEnumeration.cpp +++ b/Sources/OpenRenderBoxCxx/Path/PathEnumeration.cpp @@ -4,7 +4,7 @@ #include -#if OPENRENDERBOX_CF_CGTYPES && ORB_TARGET_OS_DARWIN +#if ORB_TARGET_OS_DARWIN #include #include "PathMapper.hpp" @@ -238,4 +238,4 @@ double ORBPathGetLength(ORBPath path, double tolerance, const CGAffineTransform return accumulator.length; } -#endif +#endif /* ORB_TARGET_OS_DARWIN */ diff --git a/Sources/OpenRenderBoxCxx/Path/PathGeometry.hpp b/Sources/OpenRenderBoxCxx/Path/PathGeometry.hpp index 33b68a4..864bc55 100644 --- a/Sources/OpenRenderBoxCxx/Path/PathGeometry.hpp +++ b/Sources/OpenRenderBoxCxx/Path/PathGeometry.hpp @@ -6,7 +6,7 @@ #include -#if OPENRENDERBOX_CF_CGTYPES && ORB_TARGET_OS_DARWIN +#if ORB_TARGET_OS_DARWIN #include #include @@ -124,4 +124,4 @@ inline CGFloat curve_measure(Cubic curve, CGFloat requested, bool findIndex) { } // namespace ORB::Path::Geometry -#endif +#endif /* ORB_TARGET_OS_DARWIN */ diff --git a/Sources/OpenRenderBoxCxx/Path/PathInterpolation.cpp b/Sources/OpenRenderBoxCxx/Path/PathInterpolation.cpp index 33a050f..d7e79e1 100644 --- a/Sources/OpenRenderBoxCxx/Path/PathInterpolation.cpp +++ b/Sources/OpenRenderBoxCxx/Path/PathInterpolation.cpp @@ -4,7 +4,7 @@ #include "PathInterpolation.hpp" -#if OPENRENDERBOX_CF_CGTYPES && ORB_TARGET_OS_DARWIN +#if ORB_TARGET_OS_DARWIN #include "NestedCallbacks.hpp" #include "PathStorageObject.hpp" @@ -201,4 +201,4 @@ extern "C" ORBPath ORBPathCopyInterpolatedPath(ORBPath from, ORBPath to, float a return ORB::Path::copy_interpolated_path(from, to, amount); } -#endif +#endif /* ORB_TARGET_OS_DARWIN */ diff --git a/Sources/OpenRenderBoxCxx/Path/PathInterpolation.hpp b/Sources/OpenRenderBoxCxx/Path/PathInterpolation.hpp index 8006fd9..01118f4 100644 --- a/Sources/OpenRenderBoxCxx/Path/PathInterpolation.hpp +++ b/Sources/OpenRenderBoxCxx/Path/PathInterpolation.hpp @@ -6,7 +6,7 @@ #include -#if OPENRENDERBOX_CF_CGTYPES && ORB_TARGET_OS_DARWIN +#if ORB_TARGET_OS_DARWIN #include @@ -15,4 +15,4 @@ bool can_interpolate(ORBPath from, ORBPath to); ORBPath copy_interpolated_path(ORBPath from, ORBPath to, float amount); } -#endif +#endif /* ORB_TARGET_OS_DARWIN */ diff --git a/Sources/OpenRenderBoxCxx/Path/PathMapper.cpp b/Sources/OpenRenderBoxCxx/Path/PathMapper.cpp index 4786f3a..91ede51 100644 --- a/Sources/OpenRenderBoxCxx/Path/PathMapper.cpp +++ b/Sources/OpenRenderBoxCxx/Path/PathMapper.cpp @@ -4,7 +4,7 @@ #include -#if OPENRENDERBOX_CF_CGTYPES && ORB_TARGET_OS_DARWIN +#if ORB_TARGET_OS_DARWIN #include "PathMapper.hpp" #include "PathClipStroke.hpp" @@ -214,7 +214,6 @@ CGPathRef copy_trimmed_path(CGPathRef path, float from, float to) { return result; } - struct Dilator { CGMutablePathRef path; CGPoint amount; @@ -1072,4 +1071,4 @@ CGPathRef copy_cg_path(ORBPath path) { } /* Path */ } /* ORB */ -#endif +#endif /* ORB_TARGET_OS_DARWIN */ diff --git a/Sources/OpenRenderBoxCxx/Path/PathMapper.hpp b/Sources/OpenRenderBoxCxx/Path/PathMapper.hpp index 152cf78..e4e8542 100644 --- a/Sources/OpenRenderBoxCxx/Path/PathMapper.hpp +++ b/Sources/OpenRenderBoxCxx/Path/PathMapper.hpp @@ -6,7 +6,7 @@ #include -#if OPENRENDERBOX_CF_CGTYPES && ORB_TARGET_OS_DARWIN +#if ORB_TARGET_OS_DARWIN #include @@ -21,4 +21,4 @@ void invalidate_mapped_storage(uint32_t identifier); } /* Path */ } /* ORB */ -#endif +#endif /* ORB_TARGET_OS_DARWIN */ diff --git a/Sources/OpenRenderBoxCxx/Path/PathStorageObject.cpp b/Sources/OpenRenderBoxCxx/Path/PathStorageObject.cpp index 409f2dc..888c077 100644 --- a/Sources/OpenRenderBoxCxx/Path/PathStorageObject.cpp +++ b/Sources/OpenRenderBoxCxx/Path/PathStorageObject.cpp @@ -4,7 +4,7 @@ #include "PathStorageObject.hpp" -#if OPENRENDERBOX_CF_CGTYPES +#if ORB_TARGET_OS_DARWIN #include "NestedCallbacks.hpp" #include "Storage.hpp" @@ -43,13 +43,8 @@ const ORBPathCallbacks callbacks = { .bezierOrder = +[](const void *object) -> size_t { return static_cast(object)->storage.flags().bezierOrder(); }, - #if ORB_TARGET_OS_DARWIN .boundingRect = +[](const void *object) { return static_cast(object)->storage.bounding_rect(); }, .cgPath = +[](const void *object) { return static_cast(object)->storage.cgpath(); }, - #else - .boundingRect = nullptr, - .cgPath = nullptr, - #endif .next = +[](const void *object) -> ORBPath { auto *nested = NestedCallbacks::get(&callbacks, 1); return {reinterpret_cast(const_cast(object)), @@ -65,4 +60,4 @@ ORBPath copy_storage_path(const Storage &storage) { } // namespace ORB::Path -#endif +#endif /* ORB_TARGET_OS_DARWIN */ diff --git a/Sources/OpenRenderBoxCxx/Path/PathStorageObject.hpp b/Sources/OpenRenderBoxCxx/Path/PathStorageObject.hpp index 5e61de3..22e5a51 100644 --- a/Sources/OpenRenderBoxCxx/Path/PathStorageObject.hpp +++ b/Sources/OpenRenderBoxCxx/Path/PathStorageObject.hpp @@ -6,7 +6,7 @@ #include -#if OPENRENDERBOX_CF_CGTYPES +#if ORB_TARGET_OS_DARWIN #include @@ -15,4 +15,4 @@ class Storage; ORBPath copy_storage_path(const Storage &storage); } -#endif +#endif /* ORB_TARGET_OS_DARWIN */ diff --git a/Sources/OpenRenderBoxCxx/Path/RoundedRect.cpp b/Sources/OpenRenderBoxCxx/Path/RoundedRect.cpp index 2a01899..f3963fd 100644 --- a/Sources/OpenRenderBoxCxx/Path/RoundedRect.cpp +++ b/Sources/OpenRenderBoxCxx/Path/RoundedRect.cpp @@ -1,5 +1,5 @@ #include -#if OPENRENDERBOX_CF_CGTYPES && ORB_TARGET_OS_DARWIN +#if ORB_TARGET_OS_DARWIN #include "RoundedRect.hpp" #include #include @@ -106,4 +106,4 @@ void add_rounded_rect(CGMutablePathRef path, ORBPathElement element, const CGFlo CGPathCloseSubpath(path); } } // namespace ORB::Path -#endif +#endif /* ORB_TARGET_OS_DARWIN */ diff --git a/Sources/OpenRenderBoxCxx/Path/RoundedRect.hpp b/Sources/OpenRenderBoxCxx/Path/RoundedRect.hpp index e0b4e08..198958e 100644 --- a/Sources/OpenRenderBoxCxx/Path/RoundedRect.hpp +++ b/Sources/OpenRenderBoxCxx/Path/RoundedRect.hpp @@ -1,9 +1,11 @@ #pragma once -#if OPENRENDERBOX_CF_CGTYPES && ORB_TARGET_OS_DARWIN +#include + +#if ORB_TARGET_OS_DARWIN #include namespace ORB::Path { void add_rounded_rect(CGMutablePathRef path, ORBPathElement element, const CGFloat *values, const CGAffineTransform *transform); } -#endif +#endif /* ORB_TARGET_OS_DARWIN */ diff --git a/Sources/OpenRenderBoxCxx/Path/Storage.cpp b/Sources/OpenRenderBoxCxx/Path/Storage.cpp index b4155bd..ff73561 100644 --- a/Sources/OpenRenderBoxCxx/Path/Storage.cpp +++ b/Sources/OpenRenderBoxCxx/Path/Storage.cpp @@ -2,7 +2,9 @@ // Storage.cpp // OpenRenderBox -#if OPENRENDERBOX_CF_CGTYPES +#include + +#if ORB_TARGET_OS_DARWIN #include #include "NestedCallbacks.hpp" @@ -12,10 +14,8 @@ #include #include #include -#if ORB_TARGET_OS_DARWIN #include "PathMapper.hpp" #include -#endif const uint8_t __ORBPathElementArgumentCount[25] = { 2, 2, 4, 6, 0, 4, 4, 4, 6, 6, 8, 8, 5, 5, 5, 5, 0, 0, 2, 3, 0, 0, 2, 1, 1, @@ -71,7 +71,6 @@ void read_values(const uint8_t *bytes, size_t &offset, uint8_t encoding, CGFloat } } -#if ORB_TARGET_OS_DARWIN const ORBPathCallbacks storageCallbacks = { .flags = {}, .retain = nullptr, @@ -89,7 +88,6 @@ const ORBPathCallbacks storageCallbacks = { .cgPath = nullptr, .next = nullptr, }; -#endif } // namespace @@ -147,9 +145,7 @@ void Storage::reserve_slow(size_t size) { size_t currentCapacity = capacity(); size_t doubled = currentCapacity <= std::numeric_limits::max() / 2 ? currentCapacity * 2 : size; size_t newCapacity = std::max(doubled, size); - #if ORB_TARGET_OS_DARWIN newCapacity = malloc_good_size(newCapacity); - #endif if (_flags.isExternal()) { auto *newBytes = static_cast(std::realloc(_external_storage, newCapacity)); if (!newBytes) { @@ -168,9 +164,7 @@ void Storage::reserve_slow(size_t size) { _external_storage = newBytes; _external_size = size; _external_capacity = newCapacity; - #if ORB_TARGET_OS_DARWIN _cached_cgPath = nullptr; - #endif } } @@ -206,23 +200,19 @@ void Storage::push_values(uint8_t encoding, const CGFloat *values, size_t count) } void Storage::invalidate() { -#if ORB_TARGET_OS_DARWIN if (_flags.requiresMapping()) { invalidate_mapped_storage(_identifier); } -#endif uintptr_t bounds = __atomic_exchange_n(&_bounds, 0, __ATOMIC_ACQ_REL); if (bounds & 1) { delete[] reinterpret_cast(bounds & ~uintptr_t(3)); } - #if ORB_TARGET_OS_DARWIN if (_flags.isExternal()) { CGPathRef path = __atomic_exchange_n(&_cached_cgPath, nullptr, __ATOMIC_ACQ_REL); if (path) { CGPathRelease(path); } } - #endif } bool Storage::operator==(const Storage &other) const ORB_NOEXCEPT { @@ -430,11 +420,9 @@ bool Storage::apply_elements(void *info, ORBPathApplyCallback callback) const OR if (callback == NestedCallbacks::single_element_callback) { return NestedCallbacks::single_element_fast(*this, info); } -#if ORB_TARGET_OS_DARWIN if (_flags.requiresMapping() && callback == apply_mapping_element) { return apply_mapped_storage(*this, info, 0); } -#endif return apply_elements_(info, callback); } @@ -450,11 +438,9 @@ bool Storage::apply_elements_(void *info, ORBPathApplyCallback callback) const O } bool Storage::apply_elements_at_depth(void *info, ORBPathApplyCallback callback, size_t depth) const ORB_NOEXCEPT { -#if ORB_TARGET_OS_DARWIN if (_flags.requiresMapping() && callback == apply_mapping_element) { return apply_mapped_storage(*this, info, depth); } -#endif if (depth == 0) { return apply_elements_(info, callback); } @@ -480,7 +466,6 @@ bool Storage::apply_elements_at_depth(void *info, ORBPathApplyCallback callback, return true; } -#if ORB_TARGET_OS_DARWIN CGRect Storage::bounding_rect() const ORB_NOEXCEPT { uintptr_t cache = __atomic_load_n(&_bounds, __ATOMIC_ACQUIRE); if (cache) { @@ -545,9 +530,8 @@ CGPathRef Storage::cgpath() const ORB_NOEXCEPT { CGPathRelease(newPath); return expected; } -#endif } /* Path */ } /* ORB */ -#endif /* OPENRENDERBOX_CF_CGTYPES */ +#endif /* ORB_TARGET_OS_DARWIN */ diff --git a/Sources/OpenRenderBoxCxx/Path/Storage.hpp b/Sources/OpenRenderBoxCxx/Path/Storage.hpp index c9a9226..b43a775 100644 --- a/Sources/OpenRenderBoxCxx/Path/Storage.hpp +++ b/Sources/OpenRenderBoxCxx/Path/Storage.hpp @@ -6,7 +6,7 @@ #include -#if OPENRENDERBOX_CF_CGTYPES +#if ORB_TARGET_OS_DARWIN #include #include "../Util/assert.hpp" @@ -14,9 +14,7 @@ #include #include #include -#if ORB_TARGET_OS_DARWIN #include -#endif ORB_ASSUME_NONNULL_BEGIN @@ -202,10 +200,8 @@ class Storage { bool apply_elements(void *info, ORBPathApplyCallback _Nullable callback) const ORB_NOEXCEPT; bool apply_elements_at_depth(void *info, ORBPathApplyCallback callback, size_t depth) const ORB_NOEXCEPT; - #if ORB_TARGET_OS_DARWIN CGRect bounding_rect() const ORB_NOEXCEPT; CGPathRef _Nullable cgpath() const ORB_NOEXCEPT; - #endif ORB_INLINE ORB_CONSTEXPR StorageFlags flags() const ORB_NOEXCEPT { return _flags; } @@ -240,11 +236,7 @@ class Storage { size_t _external_size; // 0x18 size_t _external_capacity; // 0x20 mutable float _external_bounds[4]; // 0x28 - #if ORB_TARGET_OS_DARWIN mutable CGPathRef _Nullable _cached_cgPath; // 0x38 - #else - void *_reserved; // 0x38 - #endif }; static_assert(sizeof(Storage) == 64, "Storage header and external overlay must fit 64 bytes"); @@ -260,4 +252,4 @@ struct ORBPathStorage { ORB_ASSUME_NONNULL_END -#endif /* OPENRENDERBOX_CF_CGTYPES */ +#endif /* ORB_TARGET_OS_DARWIN */ diff --git a/Tests/OpenRenderBoxCompatibilityTests/PathArcMappingTests.swift b/Tests/OpenRenderBoxCompatibilityTests/PathArcMappingTests.swift index eed02d4..16aaac8 100644 --- a/Tests/OpenRenderBoxCompatibilityTests/PathArcMappingTests.swift +++ b/Tests/OpenRenderBoxCompatibilityTests/PathArcMappingTests.swift @@ -2,7 +2,7 @@ // PathArcMappingTests.swift // OpenRenderBoxCompatibilityTests -#if canImport(CoreGraphics) && (OPENRENDERBOX_CF_CGTYPES || OPENRENDERBOX_COMPATIBILITY_TEST) +#if canImport(Darwin) import CoreGraphics import Foundation import Testing diff --git a/Tests/OpenRenderBoxCompatibilityTests/PathCallbacksTests.swift b/Tests/OpenRenderBoxCompatibilityTests/PathCallbacksTests.swift index 674b369..a560a90 100644 --- a/Tests/OpenRenderBoxCompatibilityTests/PathCallbacksTests.swift +++ b/Tests/OpenRenderBoxCompatibilityTests/PathCallbacksTests.swift @@ -4,7 +4,7 @@ import Testing -#if canImport(CoreGraphics) && (OPENRENDERBOX_CF_CGTYPES || OPENRENDERBOX_COMPATIBILITY_TEST) +#if canImport(Darwin) import CoreGraphics @Suite diff --git a/Tests/OpenRenderBoxCompatibilityTests/PathOperationsTests.swift b/Tests/OpenRenderBoxCompatibilityTests/PathOperationsTests.swift index f941ec7..4132443 100644 --- a/Tests/OpenRenderBoxCompatibilityTests/PathOperationsTests.swift +++ b/Tests/OpenRenderBoxCompatibilityTests/PathOperationsTests.swift @@ -4,7 +4,7 @@ import Testing -#if canImport(CoreGraphics) && (OPENRENDERBOX_CF_CGTYPES || OPENRENDERBOX_COMPATIBILITY_TEST) +#if canImport(Darwin) import CoreGraphics import Foundation diff --git a/Tests/OpenRenderBoxCompatibilityTests/PathRegressionTests.swift b/Tests/OpenRenderBoxCompatibilityTests/PathRegressionTests.swift index c8c2e92..b559a96 100644 --- a/Tests/OpenRenderBoxCompatibilityTests/PathRegressionTests.swift +++ b/Tests/OpenRenderBoxCompatibilityTests/PathRegressionTests.swift @@ -4,7 +4,7 @@ import Testing -#if canImport(CoreGraphics) && (OPENRENDERBOX_CF_CGTYPES || OPENRENDERBOX_COMPATIBILITY_TEST) +#if canImport(Darwin) import CoreGraphics @Suite diff --git a/Tests/OpenRenderBoxCompatibilityTests/PathStorageTests.swift b/Tests/OpenRenderBoxCompatibilityTests/PathStorageTests.swift index 7f66142..204df06 100644 --- a/Tests/OpenRenderBoxCompatibilityTests/PathStorageTests.swift +++ b/Tests/OpenRenderBoxCompatibilityTests/PathStorageTests.swift @@ -4,7 +4,7 @@ import Testing -#if canImport(CoreGraphics) && (OPENRENDERBOX_CF_CGTYPES || OPENRENDERBOX_COMPATIBILITY_TEST) +#if canImport(Darwin) import CoreGraphics @Suite diff --git a/Tests/OpenRenderBoxCompatibilityTests/PathTestSupport.swift b/Tests/OpenRenderBoxCompatibilityTests/PathTestSupport.swift index 6d0640e..35a4b53 100644 --- a/Tests/OpenRenderBoxCompatibilityTests/PathTestSupport.swift +++ b/Tests/OpenRenderBoxCompatibilityTests/PathTestSupport.swift @@ -2,7 +2,7 @@ // PathTestSupport.swift // OpenRenderBoxCompatibilityTests -#if canImport(CoreGraphics) && (OPENRENDERBOX_CF_CGTYPES || OPENRENDERBOX_COMPATIBILITY_TEST) +#if canImport(Darwin) import CoreGraphics import Foundation @@ -92,9 +92,7 @@ func pathElements(_ path: ORBPath) -> [PathElementRecord] { } return elements } -#endif -#if canImport(CoreGraphics) && (OPENRENDERBOX_CF_CGTYPES || OPENRENDERBOX_COMPATIBILITY_TEST) func cgPathElements(_ path: CGPath) -> [PathElementRecord] { var elements: [PathElementRecord] = [] path.applyWithBlock { element in diff --git a/Tests/OpenRenderBoxCompatibilityTests/PathTests.swift b/Tests/OpenRenderBoxCompatibilityTests/PathTests.swift index e526a94..c7e753a 100644 --- a/Tests/OpenRenderBoxCompatibilityTests/PathTests.swift +++ b/Tests/OpenRenderBoxCompatibilityTests/PathTests.swift @@ -4,7 +4,7 @@ import Testing -#if canImport(CoreGraphics) && (OPENRENDERBOX_CF_CGTYPES || OPENRENDERBOX_COMPATIBILITY_TEST) +#if canImport(Darwin) import CoreGraphics @Suite diff --git a/Tests/OpenRenderBoxCompatibilityTests/PathWrapperTests.swift b/Tests/OpenRenderBoxCompatibilityTests/PathWrapperTests.swift index e5245c3..c2c0542 100644 --- a/Tests/OpenRenderBoxCompatibilityTests/PathWrapperTests.swift +++ b/Tests/OpenRenderBoxCompatibilityTests/PathWrapperTests.swift @@ -4,7 +4,7 @@ import Testing -#if canImport(CoreGraphics) && (OPENRENDERBOX_CF_CGTYPES || OPENRENDERBOX_COMPATIBILITY_TEST) +#if canImport(Darwin) import CoreGraphics @Suite diff --git a/Tests/OpenRenderBoxCompatibilityTests/README.md b/Tests/OpenRenderBoxCompatibilityTests/README.md index 3aad5fa..c180e17 100644 --- a/Tests/OpenRenderBoxCompatibilityTests/README.md +++ b/Tests/OpenRenderBoxCompatibilityTests/README.md @@ -1,6 +1,6 @@ ## OpenRenderBoxCompatibilityTests -Run the Path suites against native OpenRenderBox: +Run the native OpenRenderBox Path suites on Apple platforms. ```sh OPENRENDERBOX_USE_LOCAL_DEPS=1 OPENRENDERBOX_RENDERBOX=0 \ @@ -19,18 +19,12 @@ The local dependency options require sibling OpenCoreGraphics and DarwinPrivateFrameworks checkouts. Native Path suites run without enabling other unfinished compatibility suites. -To test Swift Path with OpenCoreGraphics, use: +The Swift Path suite runs on Linux with the default SwiftPM settings. ```sh -OPENSWIFTUI_COREGRAPHICS=0 OPENRENDERBOX_CF_CGTYPES=0 \ -OPENRENDERBOX_USE_LOCAL_DEPS=1 OPENRENDERBOX_RENDERBOX=0 \ -OPENRENDERBOX_LIBRARY_EVOLUTION=0 swift test --filter PortablePathTests +swift test --filter PortablePathTests ``` -Set `OPENSWIFTUI_COREGRAPHICS=1` to test Swift Path with system CoreGraphics. -This shared setting selects the same backend in ORB and OpenCoreGraphicsShims. -`OPENRENDERBOX_CF_CGTYPES` selects C++ Path (`1`) or Swift Path (`0`). - The exact curve-trimming, line-flattening, and clip-stroke undershoot fixtures use RenderBox from iOS 18.5 (22F77). They run against native OpenRenderBox and Apple RenderBox on iOS 18.5. diff --git a/Tests/OpenRenderBoxTests/Path/PathTests.swift b/Tests/OpenRenderBoxTests/Path/PathTests.swift index 2a21c5b..2f82974 100644 --- a/Tests/OpenRenderBoxTests/Path/PathTests.swift +++ b/Tests/OpenRenderBoxTests/Path/PathTests.swift @@ -5,7 +5,7 @@ // Created by Kyle on 12/21/25. // -#if canImport(Darwin) && OPENRENDERBOX_CF_CGTYPES +#if canImport(Darwin) import Foundation import OpenRenderBox import OpenRenderBoxCxx.Path diff --git a/Tests/OpenRenderBoxTests/Path/PortableCFDataTestSupport.swift b/Tests/OpenRenderBoxTests/Path/PortableCFDataTestSupport.swift index 844552a..a9156d2 100644 --- a/Tests/OpenRenderBoxTests/Path/PortableCFDataTestSupport.swift +++ b/Tests/OpenRenderBoxTests/Path/PortableCFDataTestSupport.swift @@ -2,7 +2,7 @@ // PortableCFDataTestSupport.swift // OpenRenderBoxTests -#if !OPENRENDERBOX_CF_CGTYPES +#if !canImport(Darwin) import CoreFoundation func makeTestCFData(_ bytes: [UInt8]) -> CFData { diff --git a/Tests/OpenRenderBoxTests/Path/PortablePathTests.swift b/Tests/OpenRenderBoxTests/Path/PortablePathTests.swift index 86dce91..3f576f2 100644 --- a/Tests/OpenRenderBoxTests/Path/PortablePathTests.swift +++ b/Tests/OpenRenderBoxTests/Path/PortablePathTests.swift @@ -2,7 +2,7 @@ // PortablePathTests.swift // OpenRenderBoxTests -#if !OPENRENDERBOX_CF_CGTYPES +#if !canImport(Darwin) import OpenCoreGraphicsShims import OpenRenderBox import Testing