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
4 changes: 2 additions & 2 deletions Package.resolved

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

Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
// Status: WIP
// ID: F37E3733E490AA5E3BDC045E3D34D9F8 (SwiftUICore)

package import OpenCoreGraphicsShims
package import Foundation
package import OpenAttributeGraphShims
package import OpenCoreGraphicsShims
package import OpenRenderBoxShims

// MARK: - _DisplayList_Identity

Expand Down Expand Up @@ -561,4 +562,3 @@ extension DisplayList.Item {
package class ORBDisplayListContents {}
package class ORBDisplayListInterpolator {}
package struct ORBTransition {}
package class ORBAnimation {}
1 change: 1 addition & 0 deletions Sources/OpenSwiftUICore/Render/SymbolEffect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Status: Empty

import OpenAttributeGraphShims
package import OpenRenderBoxShims

package struct _SymbolEffect: Equatable {

Expand Down
9 changes: 9 additions & 0 deletions Sources/OpenSwiftUICore/Util/CoreUIShims.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// CoreUIShims.swift
// OpenSwiftUICore

#if !OPENSWIFTUI_LINK_COREUI
package import Foundation
package class CUICatalog: NSObject {}
package class CUINamedVectorGlyph: NSObject {}
#endif
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUICore/Util/RenderBoxShims.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// RenderBoxShims.swift
// OpenSwiftUI
// OpenSwiftUICore

package protocol RBDisplayListContents {} // RenderBox.RBDisplayListContents

Expand Down
122 changes: 95 additions & 27 deletions Sources/OpenSwiftUICore/View/Image/GraphicsImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
// OpenSwiftUICore
//
// Audited for 6.5.4
// Status: Complete with WIP implementation
// Status: Complete
// ID: B4F00EDEBAA4ECDCB2CAB650A00E4160 (SwiftUICore)

package import OpenCoreGraphicsShims
package import OpenRenderBoxShims
#if canImport(CoreGraphics)
import CoreGraphics_Private
#endif
Expand Down Expand Up @@ -160,7 +161,7 @@ extension GraphicsImage.Contents {
}
}

// TODO: ResolvedVectorGlyph
// MARK: - ResolvedVectorGlyph

package struct ResolvedVectorGlyph: Equatable {
package let animator: ORBSymbolAnimator
Expand All @@ -169,9 +170,7 @@ package struct ResolvedVectorGlyph: Equatable {
package var animatorVersion: UInt32
package var allowsContentTransitions: Bool
package var preservesVectorRepresentation: Bool
#if OPENSWIFTUI_LINK_COREUI
package let catalog: CUICatalog
#endif

package init(
glyph: CUINamedVectorGlyph,
Expand All @@ -181,48 +180,117 @@ package struct ResolvedVectorGlyph: Equatable {
at location: Image.Location,
catalog: CUICatalog
) {
_openSwiftUIUnimplementedFailure()
let variableValue: CGFloat
let animator: ORBSymbolAnimator
let allowsContentTransitions: Bool
if let existingAnimator = context.symbolAnimator {
variableValue = value.map { CGFloat($0) } ?? .infinity
animator = existingAnimator
allowsContentTransitions = context.willUpdateVectorGlyph(
to: glyph,
variableValue: variableValue
)
} else {
animator = ORBSymbolAnimator()
animator.anchorPoint = .zero
allowsContentTransitions = false
variableValue = value.map { CGFloat($0) } ?? .infinity
}
animator.glyph = glyph
animator.variableValue = variableValue
animator.flipsRightToLeft = flipsRightToLeft
animator.renderingMode = context.effectiveSymbolRenderingMode?.rbRenderingMode ?? 255
let direction = context.environment.layoutDirection
let version = animator.version
let options = context.options
self.animator = animator
self.layoutDirection = direction
self.location = location
self.animatorVersion = version
self.allowsContentTransitions = allowsContentTransitions
self.preservesVectorRepresentation = options.contains(.preservesVectors)
self.catalog = catalog
}

// MARK: - Computed properties

package var flipsRightToLeft: Bool {
animator.flipsRightToLeft
}

package func isClear(styles: ShapeStyle.Pack) -> Bool {
_openSwiftUIUnimplementedWarning()
return false
#if OPENSWIFTUI_LINK_COREUI
package var glyph: CUINamedVectorGlyph? {
animator.glyph
}
}
#endif

extension GraphicsImage {
package var bitmapOrientation: Image.Orientation {
guard case let .vectorGlyph(vectorGlyph) = contents else {
return orientation
}
return vectorGlyph.flipsRightToLeft ? orientation.mirrored : orientation
package var value: Float? {
let v = animator.variableValue
guard v.isFinite else { return nil }
return Float(v)
}

package func render(at targetSize: CGSize, prefersMask: Bool = false) -> CGImage? {
package var renderingMode: SymbolRenderingMode.Storage? {
SymbolRenderingMode(rbRenderingMode: animator.renderingMode)?.storage
}

package var resolvedRenderingMode: SymbolRenderingMode.Storage? {
#if OPENSWIFTUI_LINK_COREUI && OPENSWIFTUI_RENDERBOX
let rbMode = animator.renderingMode
guard rbMode == 0 else {
return SymbolRenderingMode(rbRenderingMode: rbMode)?.storage
}
guard let glyph = animator.glyph else {
return .preferred
}
switch glyph.preferredRenderingMode {
case 2: return .multicolor
case 3: return .hierarchical
default: return nil
}
#else
_openSwiftUIUnimplementedFailure()
#endif
}
}

// FIXME
package var alignmentRect: CGRect {
animator.alignmentRect
}

package class ORBSymbolAnimator: Hashable {
var styleMask: UInt32 {
.zero
package var styleResolverMode: ShapeStyle.ResolverMode {
.init(rbSymbolStyleMask: animator.styleMask, location: location)
}

var flipsRightToLeft: Bool {
false
// MARK: - Methods

package func isClear(styles: ShapeStyle.Pack) -> Bool {
guard animator.styleMask & 0x1200 == 0 else {
return false
}
return styles.isClear(name: .foreground)
}

package func hash(into hasher: inout Hasher) {
hasher.combine(ObjectIdentifier(self))
// MARK: - ResolvedVectorGlyph + Equatable

package static func == (lhs: ResolvedVectorGlyph, rhs: ResolvedVectorGlyph) -> Bool {
lhs.animator === rhs.animator
&& lhs.animatorVersion == rhs.animatorVersion
&& lhs.layoutDirection == rhs.layoutDirection
&& lhs.location == rhs.location
}
}

// MARK: - GraphicsImage + Extension [WIP]

package static func == (lhs: ORBSymbolAnimator, rhs: ORBSymbolAnimator) -> Bool {
lhs === rhs
extension GraphicsImage {
package var bitmapOrientation: Image.Orientation {
guard case let .vectorGlyph(vectorGlyph) = contents else {
return orientation
}
return vectorGlyph.flipsRightToLeft ? orientation.mirrored : orientation
}

package func render(at targetSize: CGSize, prefersMask: Bool = false) -> CGImage? {
_openSwiftUIUnimplementedFailure()
}
}
33 changes: 31 additions & 2 deletions Sources/OpenSwiftUICore/View/Image/Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

package import OpenAttributeGraphShims
package import OpenCoreGraphicsShims
package import OpenRenderBoxShims
#if OPENSWIFTUI_LINK_COREUI
package import CoreUI
#endif

// MARK: - Image

Expand Down Expand Up @@ -83,7 +87,7 @@ public struct Image: Equatable, Sendable {
}
}

// MARK: - ImageResolutionContext
// MARK: - ImageResolutionContext [WIP] [willUpdateVectorGlyph]

package struct ImageResolutionContext {
package struct Options: OptionSet {
Expand Down Expand Up @@ -128,7 +132,32 @@ package struct ImageResolutionContext {
self.transaction = transaction
}

// TODO: willUpdateVectorGlyph
// TODO: Full implementation of willUpdateVectorGlyph
// This is a complex method that handles animator state transitions
// when an existing symbolAnimator is being reused for a new glyph.
package func willUpdateVectorGlyph(
to glyph: CUINamedVectorGlyph,
variableValue: CGFloat
) -> Bool {
_openSwiftUIUnimplementedWarning()
return false
}

package var effectiveSymbolRenderingMode: SymbolRenderingMode? {
if let mode = symbolRenderingMode {
return mode
}
if let envMode = environment.symbolRenderingMode {
return envMode
}
if ForegroundStyle().isMultiLevel(in: environment) {
return .palette
}
guard options.contains(.inferSymbolRenderingMode) else {
return nil
}
return SymbolRenderingMode.preferredIfEnabled ?? .monochrome
}

package func effectiveAllowedDynamicRange(for image: GraphicsImage) -> Image.DynamicRange? {
#if canImport(CoreGraphics)
Expand Down
14 changes: 12 additions & 2 deletions Sources/OpenSwiftUICore/View/Image/NamedImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

public import Foundation
package import OpenCoreGraphicsShims
package import OpenRenderBoxShims
#if canImport(CoreGraphics)
import CoreGraphics_Private
#endif
Expand Down Expand Up @@ -594,8 +595,13 @@ package enum NamedImage {
}
let resolved = try delegate.resolveImage(uuid: uuid)
let cgImage = resolved.cgImage
#if canImport(CoreGraphics)
let width = CGFloat(cgImage.width)
let height = CGFloat(cgImage.height)
#else
let width = CGFloat.zero
let height = CGFloat.zero
#endif
let decoded = DecodedInfo(
contents: .cgImage(cgImage),
scale: resolved.scale,
Expand Down Expand Up @@ -721,14 +727,13 @@ extension Image {
package static let privateSystemAssetManager = SystemAssetManager(internalUse: true)

package struct SystemAssetManager {
#if OPENSWIFTUI_LINK_COREUI
let catalog: CUICatalog
#endif
let fillMapping: [String: String]
let nameAliases: [String: String]
let symbols: [String]

package init(internalUse: Bool) {
#if canImport(Darwin)
let bundlePath: String
if internalUse {
fillMapping = SFSymbols.private_nofill_to_fill
Expand All @@ -745,6 +750,11 @@ extension Image {
let fullPath = _SimulatorSystemRootDirectory() + bundlePath
let bundle = Bundle(path: fullPath)!
catalog = try! CUICatalog(name: "Assets", from: bundle, error: ())
#else
_openSwiftUIPlatformUnimplementedFailure()
#endif
#else
_openSwiftUIPlatformUnimplementedFailure()
#endif
}
}
Expand Down
31 changes: 31 additions & 0 deletions Sources/OpenSwiftUICore/View/Image/SymbolRenderingMode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,37 @@ public struct SymbolRenderingMode: Sendable {
}()
}

// MARK: - SymbolRenderingMode + RB Rendering Mode

extension SymbolRenderingMode {
package var rbRenderingMode: UInt32 {
switch storage {
case .monochrome: 1
case .multicolor: 2
case .hierarchical: 3
case .palette: 4
case .preferred: 0
case .hierarchicalUnlessSlashed: 128
case .hierarchicalSlashBadge: 129
case .paletteSlashBadge: 130
}
}

package init?(rbRenderingMode mode: UInt32) {
switch mode {
case 0: self = .preferred
case 1: self = .monochrome
case 2: self = .multicolor
case 3: self = .hierarchical
case 4: self = .palette
case 128: self = .hierarchicalUnlessSlashed
case 129: self = .hierarchicalSlashBadge
case 130: self = .paletteSlashBadge
default: return nil
}
}
}

@_spi(Private)
@available(OpenSwiftUI_v6_0, *)
extension SymbolRenderingMode {
Expand Down
4 changes: 2 additions & 2 deletions Sources/OpenSwiftUICore/View/Text/Font/ModifiedFont.swift
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ extension Font {
}

package func modify(traits: inout Font.ResolvedTraits) {
_openSwiftUIUnimplementedFailure()
traits.weight = weight.value
}
}

Expand All @@ -479,7 +479,7 @@ extension Font {
}

package func modify(traits: inout Font.ResolvedTraits) {
_openSwiftUIUnimplementedFailure()
traits.width = width
}
}

Expand Down
Loading
Loading