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
24 changes: 24 additions & 0 deletions Sources/OpenSwiftUI_SPI/OpenSwiftUIBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,30 @@
#include <stdio.h>
#include "OpenSwiftUITargetConditionals.h"

#if OPENSWIFTUI_TARGET_OS_DARWIN
#if (defined(__IPHONE_26_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_26_0) || \
(defined(__MAC_26_0) && __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_26_0) || \
(defined(__TV_26_0) && __TV_OS_VERSION_MAX_ALLOWED >= __TV_26_0) || \
(defined(__WATCH_26_0) && __WATCH_OS_VERSION_MAX_ALLOWED >= __WATCH_26_0)
#define OPENSWIFTUI_HAS_SDK_26_ADDITIONS 1
#else
#define OPENSWIFTUI_HAS_SDK_26_ADDITIONS 0
#endif

#if (defined(__IPHONE_27_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_27_0) || \
(defined(__MAC_27_0) && __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_27_0) || \
(defined(__TV_27_0) && __TV_OS_VERSION_MAX_ALLOWED >= __TV_27_0) || \
(defined(__WATCH_27_0) && __WATCH_OS_VERSION_MAX_ALLOWED >= __WATCH_27_0) || \
(defined(__VISIONOS_27_0) && __VISION_OS_VERSION_MAX_ALLOWED >= __VISIONOS_27_0)
#define OPENSWIFTUI_HAS_SDK_27_ADDITIONS 1
#else
#define OPENSWIFTUI_HAS_SDK_27_ADDITIONS 0
#endif
#else
#define OPENSWIFTUI_HAS_SDK_26_ADDITIONS 0
#define OPENSWIFTUI_HAS_SDK_27_ADDITIONS 0
#endif

#if defined(__cplusplus)
#define OPENSWIFTUI_INLINE inline
#else
Expand Down
32 changes: 31 additions & 1 deletion Sources/OpenSwiftUI_SPI/Shims/UIFoundation/NSParagraphStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#if OPENSWIFTUI_TARGET_OS_DARWIN

// Modified based on iOS 18.5 SDK
// Modified based on iOS 18.5 SDK and macOS 27.0 SDK

// NSParagraphStyle.h
// UIKit
Expand All @@ -22,6 +22,7 @@
#import "NSText.h"

@class NSTextList;
@class NSTextBlock;

NS_HEADER_AUDIT_BEGIN(nullability, sendability)

Expand Down Expand Up @@ -75,6 +76,11 @@ OPENSWIFTUI_EXPORT API_AVAILABLE(macos(10.0), ios(7.0), tvos(9.0), watchos(2.0),

+ (NSCharacterSet *)columnTerminatorsForLocale:(nullable NSLocale *)aLocale API_AVAILABLE(macos(10.11), ios(7.0), tvos(9.0), watchos(2.0), visionos(1.0)); // Returns the column terminators for locale. Passing nil returns an instance corresponding to +[NSLocale systemLocale]. For matching user's formatting preferences, pass +[NSLocale currentLocale]. Can be used as the value for NSTabColumnTerminatorsAttributeName to make a decimal tab stop.

#if OPENSWIFTUI_HAS_SDK_27_ADDITIONS
- (instancetype)initWithTextAlignment:(NSTextAlignment)alignment location:(CGFloat)loc options:(NSDictionary<NSTextTabOptionKey, id> *)options NS_DESIGNATED_INITIALIZER; // Initializes a text tab with the text alignment, location, and options. The text alignment is used to determine the position of text inside the tab column.

@property (readonly, NS_NONATOMIC_IOSONLY) NSTextAlignment alignment; // Defines the alignment of tab column contents.
#endif
@property (readonly, NS_NONATOMIC_IOSONLY) CGFloat location; // Location of the tab stop inside the line fragment rect coordinate system
@property (readonly, NS_NONATOMIC_IOSONLY) NSDictionary<NSTextTabOptionKey, id> *options; // Optional configuration attributes
@end
Expand All @@ -84,6 +90,10 @@ OPENSWIFTUI_EXPORT API_AVAILABLE(macos(10.0), ios(7.0), tvos(9.0), watchos(2.0),
OPENSWIFTUI_EXPORT API_AVAILABLE(macos(10.0), ios(6.0), tvos(9.0), watchos(2.0), visionos(1.0))
@interface NSParagraphStyle : NSObject <NSCopying, NSMutableCopying, NSSecureCoding>

#if OPENSWIFTUI_HAS_SDK_27_ADDITIONS
@property (readonly, NS_NONATOMIC_IOSONLY) NSTextAlignment alignment;

#endif
@property (class, readonly, copy, NS_NONATOMIC_IOSONLY) NSParagraphStyle *defaultParagraphStyle; // This class property returns a shared and cached NSParagraphStyle instance with the default style settings, with same value as the result of [[NSParagraphStyle alloc] init].

+ (NSWritingDirection)defaultWritingDirectionForLanguage:(nullable NSString *)languageName; // languageName is in ISO lang region format
Expand Down Expand Up @@ -118,16 +128,28 @@ OPENSWIFTUI_EXPORT API_AVAILABLE(macos(10.0), ios(6.0), tvos(9.0), watchos(2.0),

@property (readonly, copy, NS_NONATOMIC_IOSONLY) NSArray<NSTextList *> *textLists API_AVAILABLE(macos(10.0), ios(7.0), tvos(9.0), watchos(2.0), visionos(1.0)); // Array to specify the text lists containing the paragraph, nested from outermost to innermost.

#if OPENSWIFTUI_HAS_SDK_27_ADDITIONS
@property (readonly, copy, NS_NONATOMIC_IOSONLY) NSArray<__kindof NSTextBlock *> *textBlocks API_AVAILABLE(macos(10.0), ios(6.0), tvos(9.0), visionos(1.0), watchos(2.0)); // Array to specify the text blocks containing the paragraph, nested from outermost to innermost.

#endif
@property (readonly, NS_NONATOMIC_IOSONLY) BOOL allowsDefaultTighteningForTruncation API_AVAILABLE(macos(10.11), ios(9.0), tvos(9.0), watchos(2.0), visionos(1.0)); // Tightens inter-character spacing in attempt to fit lines wider than the available space if the line break mode is one of the truncation modes before starting to truncate. NO by default. The maximum amount of tightening performed is determined by the system based on contexts such as font, line width, etc.

@property (readonly, NS_NONATOMIC_IOSONLY) NSLineBreakStrategy lineBreakStrategy API_AVAILABLE(macos(10.11), ios(9.0), tvos(9.0), watchos(2.0), visionos(1.0)); // Specifies the line break strategies that may be used for laying out the paragraph. The default value is NSLineBreakStrategyNone.

#if OPENSWIFTUI_HAS_SDK_27_ADDITIONS && OPENSWIFTUI_TARGET_OS_OSX
@property (readonly) float tighteningFactorForTruncation; // Specifies the threshold for using tightening as an alternative to truncation when -allowsDefaultTighteningForTruncation=NO.
@property (readonly) NSInteger headerLevel; // Specifies whether the paragraph is to be treated as a header for purposes of HTML generation.
#endif

@end


OPENSWIFTUI_EXPORT API_AVAILABLE(macos(10.0), ios(6.0), tvos(9.0), watchos(2.0), visionos(1.0))
@interface NSMutableParagraphStyle : NSParagraphStyle

#if OPENSWIFTUI_HAS_SDK_27_ADDITIONS
@property (NS_NONATOMIC_IOSONLY) NSTextAlignment alignment;
#endif
@property (NS_NONATOMIC_IOSONLY) CGFloat lineSpacing;
@property (NS_NONATOMIC_IOSONLY) CGFloat paragraphSpacing;
@property (NS_NONATOMIC_IOSONLY) CGFloat firstLineHeadIndent;
Expand All @@ -146,12 +168,20 @@ OPENSWIFTUI_EXPORT API_AVAILABLE(macos(10.0), ios(6.0), tvos(9.0), watchos(2.0),
@property (NS_NONATOMIC_IOSONLY) BOOL allowsDefaultTighteningForTruncation API_AVAILABLE(macos(10.11), ios(9.0), tvos(9.0), watchos(2.0), visionos(1.0));
@property (NS_NONATOMIC_IOSONLY) NSLineBreakStrategy lineBreakStrategy API_AVAILABLE(macos(10.11), ios(9.0), tvos(9.0), watchos(2.0), visionos(1.0));
@property (NS_NONATOMIC_IOSONLY, copy) NSArray<NSTextList *> *textLists API_AVAILABLE(macos(10.0), ios(7.0), tvos(9.0), watchos(2.0), visionos(1.0));
#if OPENSWIFTUI_HAS_SDK_27_ADDITIONS
@property (copy, NS_NONATOMIC_IOSONLY) NSArray<__kindof NSTextBlock *> *textBlocks API_AVAILABLE(macos(10.0), ios(6.0), tvos(9.0), visionos(1.0), watchos(2.0));
#endif

- (void)addTabStop:(NSTextTab *)anObject API_AVAILABLE(macos(10.0), ios(9.0), tvos(9.0), watchos(2.0), visionos(1.0));
- (void)removeTabStop:(NSTextTab *)anObject API_AVAILABLE(macos(10.0), ios(9.0), tvos(9.0), watchos(2.0), visionos(1.0));

- (void)setParagraphStyle:(NSParagraphStyle *)obj API_AVAILABLE(macos(10.0), ios(9.0), tvos(9.0), watchos(2.0), visionos(1.0));

#if OPENSWIFTUI_HAS_SDK_27_ADDITIONS && OPENSWIFTUI_TARGET_OS_OSX
@property float tighteningFactorForTruncation;
@property NSInteger headerLevel;
#endif

@end

NS_HEADER_AUDIT_END(nullability, sendability)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ typedef NS_OPTIONS(NSInteger, NSStringDrawingOptions) {
NSStringDrawingUsesFontLeading = 1 << 1, // Uses the font leading for calculating line heights
NSStringDrawingUsesDeviceMetrics = 1 << 3, // Uses image glyph bounds instead of typographic bounds
NSStringDrawingTruncatesLastVisibleLine API_AVAILABLE(macos(10.5), ios(6.0), tvos(9.0), watchos(2.0), visionos(1.0)) = 1 << 5, // Truncates and adds the ellipsis character to the last visible line if the text doesn't fit into the bounds specified. Ignored if NSStringDrawingUsesLineFragmentOrigin is not also set.
// Check if Xcode 26.0 related platform SDKs are available
#if (defined(__IPHONE_26_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_26_0) || \
(defined(__MAC_26_0) && __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_26_0) || \
(defined(__TV_26_0) && __TV_OS_VERSION_MAX_ALLOWED >= __TV_26_0) || \
(defined(__WATCH_26_0) && __WATCH_OS_VERSION_MAX_ALLOWED >= __WATCH_26_0)
#if OPENSWIFTUI_HAS_SDK_26_ADDITIONS
/// Specifies the behavior for resolving ``NSTextAlignment.natural`` to the visual alignment.
///
/// When set, the resolved visual alignment is determined by the resolved base writing direction; otherwise, it is using the user’s preferred language.
Expand Down
25 changes: 24 additions & 1 deletion Sources/OpenSwiftUI_SPI/Shims/UIFoundation/NSText.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#if OPENSWIFTUI_TARGET_OS_DARWIN

// Modified based on macOS 15.5 SDK
// Modified based on macOS 27.0 SDK

/*
NSText.h
Expand All @@ -31,6 +31,29 @@ typedef NS_ENUM(NSInteger, NSWritingDirection) {
} API_AVAILABLE(macos(10.0), ios(6.0), watchos(2.0), tvos(9.0), visionos(1.0));
#endif // !__NSWRITING_DIRECTION_SHARED_SECTION__

#if !__NSTEXT_ALIGNMENT_SHARED_SECTION__
#define __NSTEXT_ALIGNMENT_SHARED_SECTION__ 1
#pragma mark NSTextAlignment
typedef NS_ENUM(NSInteger, NSTextAlignment) {
NSTextAlignmentLeft = 0, // Visually left aligned
#if TARGET_ABI_USES_IOS_VALUES
NSTextAlignmentCenter = 1, // Visually centered
NSTextAlignmentRight = 2, // Visually right aligned
#else /* !TARGET_ABI_USES_IOS_VALUES */
NSTextAlignmentRight = 1, // Visually right aligned
NSTextAlignmentCenter = 2, // Visually centered
#endif
NSTextAlignmentJustified = 3, // Fully-justified. The last line in a paragraph is natural-aligned.

/// Resolved to either ``left`` or ``right`` based on the natural alignment resolution type active in the associated component.
///
/// There are two types of natural alignment resolution behavior. The natural alignment is resolved based on either the UI language or the base writing direction.
/// The behavior is selected by the ``resolvesNaturalAlignmentWithBaseWritingDirection`` property for ``NSTextLayoutManager``.
/// ``NSStringDrawingOptions.resolvesNaturalAlignmentWithBaseWritingDirection`` specifies the base writing direction based resolution for ``NSStringDrawing``.
NSTextAlignmentNatural = 4
} API_AVAILABLE(macos(10.0), ios(6.0), watchos(2.0), tvos(9.0), visionos(1.0));
#endif // !__NSTEXT_ALIGNMENT_SHARED_SECTION__

NS_HEADER_AUDIT_END(nullability, sendability)

#endif
Loading