Skip to content

Commit efcd83d

Browse files
committed
Fix header conflict issue
error: 'NSParagraphStyle' has different definitions in different modules
1 parent 3c338d6 commit efcd83d

File tree

6 files changed

+248
-16
lines changed

6 files changed

+248
-16
lines changed

Sources/OpenSwiftUI_SPI/Shims/UIFoundation/NSParagraphStyle.h

Lines changed: 129 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,141 @@
88

99
#if OPENSWIFTUI_TARGET_OS_DARWIN
1010

11-
OPENSWIFTUI_ASSUME_NONNULL_BEGIN
11+
// Modified based on macOS 15.5 SDK
1212

13+
/*
14+
NSParagraphStyle.h
15+
Copyright (c) 1994-2024, Apple Inc. All rights reserved.
16+
17+
NSParagraphStyle and NSMutableParagraphStyle hold paragraph style information
18+
NSTextTab holds information about a single tab stop
19+
*/
20+
21+
#import <Foundation/Foundation.h>
22+
#import "NSText.h"
23+
24+
@class NSTextList;
25+
26+
NS_HEADER_AUDIT_BEGIN(nullability, sendability)
27+
28+
#if !__NSPARAGRAPH_STYLE_SHARED_SECTION__
29+
#define __NSPARAGRAPH_STYLE_SHARED_SECTION__ 1
30+
31+
typedef NS_ENUM(NSUInteger, NSLineBreakMode) {
32+
NSLineBreakByWordWrapping = 0, // Wrap at word boundaries, default
33+
NSLineBreakByCharWrapping, // Wrap at character boundaries
34+
NSLineBreakByClipping, // Simply clip
35+
NSLineBreakByTruncatingHead, // Truncate at head of line: "...wxyz"
36+
NSLineBreakByTruncatingTail, // Truncate at tail of line: "abcd..."
37+
NSLineBreakByTruncatingMiddle // Truncate middle of line: "ab...yz"
38+
} API_AVAILABLE(macos(10.0), ios(6.0), watchos(2.0), tvos(9.0), visionos(1.0));
39+
40+
// Line break strategy describes a collection of options that can affect where line breaks are placed in a paragraph.
41+
// This is independent from line break mode, which describes what happens when text is too long to fit within its container.
42+
// These options won't have any effect when used with line break modes that don't support multiple lines, like clipping or truncating middle.
43+
typedef NS_OPTIONS(NSUInteger, NSLineBreakStrategy) {
44+
// Don't use any line break strategies
45+
NSLineBreakStrategyNone = 0,
46+
// Use the push out line break strategy.
47+
// This strategy allows the text system to "push out" individual lines by some number of words to avoid an orphan word on the last line of the paragraph.
48+
// The current implementation usually pushes out the last line by a single word.
49+
NSLineBreakStrategyPushOut API_AVAILABLE(macos(10.11), ios(9.0), tvos(9.0), watchos(2.0), visionos(1.0)) = 1 << 0,
50+
// When specified, it prohibits breaking between Hangul characters. It is the preferable typesetting strategy for the modern Korean documents suitable for UI strings.
51+
NSLineBreakStrategyHangulWordPriority API_AVAILABLE(macos(11.0), ios(14.0), watchos(7.0), tvos(14.0), visionos(1.0)) = 1 << 1,
52+
// Use the same configuration of line break strategies that the system uses for standard UI labels. This set of line break strategies is optimized for displaying shorter strings that are common in UI labels and may not be suitable for large amounts of text.
53+
NSLineBreakStrategyStandard API_AVAILABLE(macos(11.0), ios(14.0), watchos(7.0), tvos(14.0), visionos(1.0)) = 0xFFFF
54+
} API_AVAILABLE(macos(10.11), ios(9.0), tvos(9.0), watchos(2.0), visionos(1.0));
55+
56+
#endif // !__NSPARAGRAPH_STYLE_SHARED_SECTION__
57+
58+
// NSTextTab
59+
typedef NSString * NSTextTabOptionKey NS_TYPED_ENUM API_AVAILABLE(macos(10.0), ios(7.0), tvos(9.0), watchos(2.0), visionos(1.0));
60+
OPENSWIFTUI_EXPORT NSTextTabOptionKey NSTabColumnTerminatorsAttributeName API_AVAILABLE(macos(10.0), ios(7.0), tvos(9.0), watchos(2.0), visionos(1.0)); // An attribute for NSTextTab options. The value is NSCharacterSet. The character set is used to determine the tab column terminating character. The tab and newline characters are implied even if not included in the character set.
61+
62+
OPENSWIFTUI_EXPORT API_AVAILABLE(macos(10.0), ios(7.0), tvos(9.0), watchos(2.0), visionos(1.0))
63+
@interface NSTextTab : NSObject <NSCopying, NSCoding, NSSecureCoding>
64+
65+
+ (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.
66+
67+
@property (readonly) CGFloat location; // Location of the tab stop inside the line fragment rect coordinate system
68+
@property (readonly) NSDictionary<NSTextTabOptionKey, id> *options; // Optional configuration attributes
69+
@end
70+
71+
72+
// NSParagraphStyle
73+
OPENSWIFTUI_EXPORT API_AVAILABLE(macos(10.0), ios(6.0), tvos(9.0), watchos(2.0), visionos(1.0))
1374
@interface NSParagraphStyle : NSObject <NSCopying, NSMutableCopying, NSSecureCoding>
14-
// TODO
75+
76+
@property (class, readonly, copy) 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].
77+
78+
+ (NSWritingDirection)defaultWritingDirectionForLanguage:(nullable NSString *)languageName; // languageName is in ISO lang region format
79+
80+
@property (readonly) CGFloat lineSpacing; // "Leading": distance between the bottom of one line fragment and top of next (applied between lines in the same container). This value is included in the line fragment heights in layout manager.
81+
@property (readonly) CGFloat paragraphSpacing; // Distance between the bottom of this paragraph and top of next (or the beginning of its paragraphSpacingBefore, if any).
82+
83+
// The following values are relative to the appropriate margin (depending on the paragraph direction)
84+
85+
@property (readonly) CGFloat headIndent; // Distance from margin to front edge of paragraph
86+
@property (readonly) CGFloat tailIndent; // Distance from margin to back edge of paragraph; if negative or 0, from other margin
87+
@property (readonly) CGFloat firstLineHeadIndent; // Distance from margin to edge appropriate for text direction
88+
89+
@property (readonly) CGFloat minimumLineHeight; // Line height is the distance from bottom of descenders to top of ascenders; basically the line fragment height. Does not include lineSpacing (which is added after this computation).
90+
@property (readonly) CGFloat maximumLineHeight; // 0 implies no maximum.
91+
92+
@property (readonly) NSLineBreakMode lineBreakMode;
93+
94+
@property (readonly) NSWritingDirection baseWritingDirection;
95+
96+
@property (readonly) CGFloat lineHeightMultiple; // Natural line height is multiplied by this factor (if positive) before being constrained by minimum and maximum line height.
97+
@property (readonly) CGFloat paragraphSpacingBefore; // Distance between the bottom of the previous paragraph (or the end of its paragraphSpacing, if any) and the top of this paragraph.
98+
99+
// Specifies the threshold for hyphenation. Valid values lie between 0.0 and 1.0 inclusive. Hyphenation will be attempted when the ratio of the text width as broken without hyphenation to the width of the line fragment is less than the hyphenation factor. When this takes on its default value of 0.0, the layout manager's hyphenation factor is used instead. When both are 0.0, hyphenation is disabled.
100+
@property (readonly) float hyphenationFactor;
101+
102+
// A property controlling the hyphenation behavior for the paragraph associated with the paragraph style. The exact hyphenation logic is dynamically determined by the layout context such as language, platform, etc. When YES, it affects the return value from -hyphenationFactor when the property is set to 0.0.
103+
@property (readonly) BOOL usesDefaultHyphenation API_AVAILABLE(macos(12.0), ios(15.0), tvos(15.0), watchos(8.0), visionos(1.0));
104+
105+
@property (readonly,copy) NSArray<NSTextTab *> *tabStops API_AVAILABLE(macos(10.0), ios(7.0), tvos(9.0), watchos(2.0), visionos(1.0)); // An array of NSTextTabs. Contents should be ordered by location. The default value is an array of 12 left-aligned tabs at 28pt interval
106+
@property (readonly) CGFloat defaultTabInterval API_AVAILABLE(macos(10.0), ios(7.0), tvos(9.0), watchos(2.0), visionos(1.0)); // The default tab interval used for locations beyond the last element in tabStops
107+
108+
@property (readonly, copy) 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.
109+
110+
@property (readonly) 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.
111+
112+
@property (readonly) 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.
113+
15114
@end
16115

116+
117+
OPENSWIFTUI_EXPORT API_AVAILABLE(macos(10.0), ios(6.0), tvos(9.0), watchos(2.0), visionos(1.0))
17118
@interface NSMutableParagraphStyle : NSParagraphStyle
18-
// TODO
119+
120+
@property CGFloat lineSpacing;
121+
@property CGFloat paragraphSpacing;
122+
@property CGFloat firstLineHeadIndent;
123+
@property CGFloat headIndent;
124+
@property CGFloat tailIndent;
125+
@property NSLineBreakMode lineBreakMode;
126+
@property CGFloat minimumLineHeight;
127+
@property CGFloat maximumLineHeight;
128+
@property NSWritingDirection baseWritingDirection;
129+
@property CGFloat lineHeightMultiple;
130+
@property CGFloat paragraphSpacingBefore;
131+
@property float hyphenationFactor;
132+
@property (readwrite) BOOL usesDefaultHyphenation API_AVAILABLE(macos(12.0), ios(15.0), tvos(15.0), watchos(8.0), visionos(1.0));
133+
@property (null_resettable, copy) NSArray<NSTextTab *> *tabStops API_AVAILABLE(macos(10.0), ios(7.0), tvos(9.0), watchos(2.0), visionos(1.0));
134+
@property CGFloat defaultTabInterval API_AVAILABLE(macos(10.0), ios(7.0), tvos(9.0), watchos(2.0), visionos(1.0));
135+
@property BOOL allowsDefaultTighteningForTruncation API_AVAILABLE(macos(10.11), ios(9.0), tvos(9.0), watchos(2.0), visionos(1.0));
136+
@property NSLineBreakStrategy lineBreakStrategy API_AVAILABLE(macos(10.11), ios(9.0), tvos(9.0), watchos(2.0), visionos(1.0));
137+
@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));
138+
139+
- (void)addTabStop:(NSTextTab *)anObject API_AVAILABLE(macos(10.0), ios(9.0), tvos(9.0), watchos(2.0), visionos(1.0));
140+
- (void)removeTabStop:(NSTextTab *)anObject API_AVAILABLE(macos(10.0), ios(9.0), tvos(9.0), watchos(2.0), visionos(1.0));
141+
142+
- (void)setParagraphStyle:(NSParagraphStyle *)obj API_AVAILABLE(macos(10.0), ios(9.0), tvos(9.0), watchos(2.0), visionos(1.0));
143+
19144
@end
20145

21-
OPENSWIFTUI_ASSUME_NONNULL_END
146+
NS_HEADER_AUDIT_END(nullability, sendability)
22147

23148
#endif

Sources/OpenSwiftUI_SPI/Shims/UIFoundation/NSParagraphStyle.m

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//
2+
// NSStringDrawing.h
3+
// OpenSwiftUI_SPI
4+
5+
#pragma once
6+
7+
#import "OpenSwiftUIBase.h"
8+
9+
#if OPENSWIFTUI_TARGET_OS_DARWIN
10+
11+
// Modified based on macOS 15.5 SDK
12+
13+
/*
14+
NSStringDrawing.h
15+
Copyright (c) 1994-2024, Apple Inc. All rights reserved.
16+
*/
17+
18+
#import <Foundation/Foundation.h>
19+
@class NSAttributedString;
20+
@class NSString;
21+
@class NSStringDrawingContext;
22+
23+
NS_HEADER_AUDIT_BEGIN(nullability, sendability)
24+
25+
// When attributes=nil, the methods declared here uses the default behavior for each attribute described in <UIKitCore/NSAttributedString.h>. When stringDrawingContext=nil, it's equivalent of passing the default instance initialized with [[NSStringDrawingContext alloc] init].
26+
27+
OPENSWIFTUI_EXPORT API_AVAILABLE(macos(10.11), ios(6.0), tvos(9.0), watchos(2.0), visionos(1.0))
28+
@interface NSStringDrawingContext : NSObject
29+
30+
// Minimum scale factor for drawWithRect:options:context: and boundingRectWithSize:options:context: methods. If this property is set, the extended string drawing methods will attempt to draw the attributed string in the given bounds by proportionally scaling the font(s) in the attributed string
31+
@property (NS_NONATOMIC_IOSONLY)CGFloat minimumScaleFactor;
32+
33+
// actual scale factor used by the last drawing call where minimum scale factor was specified
34+
@property (readonly, NS_NONATOMIC_IOSONLY) CGFloat actualScaleFactor;
35+
36+
// bounds of the string drawn by the previous invocation of drawWithRect:options:context:
37+
@property (readonly, NS_NONATOMIC_IOSONLY) CGRect totalBounds;
38+
39+
@end
40+
41+
@interface NSString(NSStringDrawing)
42+
- (CGSize)sizeWithAttributes:(nullable NSDictionary<NSAttributedStringKey, id> *)attrs API_AVAILABLE(macos(10.0), ios(7.0), tvos(9.0), watchos(2.0), visionos(1.0));
43+
- (void)drawAtPoint:(CGPoint)point withAttributes:(nullable NSDictionary<NSAttributedStringKey, id> *)attrs API_AVAILABLE(macos(10.0), ios(7.0), tvos(9.0), watchos(2.0), visionos(1.0));
44+
- (void)drawInRect:(CGRect)rect withAttributes:(nullable NSDictionary<NSAttributedStringKey, id> *)attrs API_AVAILABLE(macos(10.0), ios(7.0), tvos(9.0), watchos(2.0), visionos(1.0));
45+
@end
46+
47+
@interface NSAttributedString(NSStringDrawing)
48+
- (CGSize)size API_AVAILABLE(macos(10.0), ios(6.0), tvos(9.0), watchos(2.0), visionos(1.0));
49+
- (void)drawAtPoint:(CGPoint)point API_AVAILABLE(macos(10.0), ios(6.0), tvos(9.0), watchos(2.0), visionos(1.0));
50+
- (void)drawInRect:(CGRect)rect API_AVAILABLE(macos(10.0), ios(6.0), tvos(9.0), watchos(2.0), visionos(1.0));
51+
@end
52+
53+
typedef NS_OPTIONS(NSInteger, NSStringDrawingOptions) {
54+
NSStringDrawingUsesLineFragmentOrigin = 1 << 0, // The specified origin is the line fragment origin, not the base line origin
55+
NSStringDrawingUsesFontLeading = 1 << 1, // Uses the font leading for calculating line heights
56+
NSStringDrawingUsesDeviceMetrics = 1 << 3, // Uses image glyph bounds instead of typographic bounds
57+
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.
58+
NSStringDrawingDisableScreenFontSubstitution API_DEPRECATED("", macos(10.0,10.11)) = (1 << 2),
59+
NSStringDrawingOneShot API_DEPRECATED("", macos(10.0,10.11)) = (1 << 4),
60+
}
61+
NS_SWIFT_NAME(NSString.DrawingOptions)
62+
API_AVAILABLE(macos(10.0), ios(6.0), tvos(9.0), watchos(2.0), visionos(1.0));
63+
64+
65+
// NOTE: All of the following methods will default to drawing on a baseline, limiting drawing to a single line.
66+
// To correctly draw and size multi-line text, pass NSStringDrawingUsesLineFragmentOrigin in the options parameter.
67+
@interface NSString (NSExtendedStringDrawing)
68+
- (void)drawWithRect:(CGRect)rect options:(NSStringDrawingOptions)options attributes:(nullable NSDictionary<NSAttributedStringKey, id> *)attributes context:(nullable NSStringDrawingContext *)context API_AVAILABLE(macos(10.11), ios(7.0), tvos(9.0), watchos(2.0), visionos(1.0));
69+
- (CGRect)boundingRectWithSize:(CGSize)size options:(NSStringDrawingOptions)options attributes:(nullable NSDictionary<NSAttributedStringKey, id> *)attributes context:(nullable NSStringDrawingContext *)context API_AVAILABLE(macos(10.11), ios(7.0), tvos(9.0), watchos(2.0), visionos(1.0));
70+
@end
71+
72+
@interface NSAttributedString (NSExtendedStringDrawing)
73+
- (void)drawWithRect:(CGRect)rect options:(NSStringDrawingOptions)options context:(nullable NSStringDrawingContext *)context API_AVAILABLE(macos(10.11), ios(6.0), tvos(9.0), watchos(2.0), visionos(1.0));
74+
- (CGRect)boundingRectWithSize:(CGSize)size options:(NSStringDrawingOptions)options context:(nullable NSStringDrawingContext *)context API_AVAILABLE(macos(10.11), ios(6.0), tvos(9.0), watchos(2.0), visionos(1.0));
75+
@end
76+
77+
NS_HEADER_AUDIT_END(nullability, sendability)
78+
79+
#endif

Sources/OpenSwiftUI_SPI/Shims/UIFoundation/NSStringDrawingContext.h renamed to Sources/OpenSwiftUI_SPI/Shims/UIFoundation/NSStringDrawing_Private.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
//
2-
// NSStringDrawingContext.h
2+
// NSStringDrawing_Private.h
33
// OpenSwiftUI_SPI
44

55
#pragma once
66

77
#import "OpenSwiftUIBase.h"
88

99
#if OPENSWIFTUI_TARGET_OS_DARWIN
10+
#import "NSStringDrawing.h"
1011

1112
OPENSWIFTUI_ASSUME_NONNULL_BEGIN
1213

13-
@interface NSStringDrawingContext : NSObject
14-
@property (NS_NONATOMIC_IOSONLY) CGFloat minimumScaleFactor;
15-
@end
16-
1714
@interface NSStringDrawingContext (OpenSwiftUI_SPI)
1815
@property (nonatomic, assign) CGFloat baselineOffset;
1916
@property (nonatomic, assign) CGFloat firstBaselineOffset;

Sources/OpenSwiftUI_SPI/Shims/UIFoundation/NSStringDrawingContext.m renamed to Sources/OpenSwiftUI_SPI/Shims/UIFoundation/NSStringDrawing_Private.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//
2-
// NSStringDrawingContext.m
2+
// NSStringDrawing_Private.m
33
// OpenSwiftUI_SPI
44

5-
#import "NSStringDrawingContext.h"
5+
#import "NSStringDrawing_Private.h"
66

77
#if OPENSWIFTUI_TARGET_OS_DARWIN
88

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//
2+
// NSText.h
3+
// OpenSwiftUI_SPI
4+
5+
#pragma once
6+
7+
#import "OpenSwiftUIBase.h"
8+
9+
#if OPENSWIFTUI_TARGET_OS_DARWIN
10+
11+
// Modified based on macOS 15.5 SDK
12+
13+
/*
14+
NSText.h
15+
Application Kit
16+
Copyright (c) 1994-2024, Apple Inc.
17+
All rights reserved.
18+
*/
19+
20+
#import <Foundation/Foundation.h>
21+
22+
NS_HEADER_AUDIT_BEGIN(nullability, sendability)
23+
24+
#if !__NSWRITING_DIRECTION_SHARED_SECTION__
25+
#define __NSWRITING_DIRECTION_SHARED_SECTION__ 1
26+
#pragma mark NSWritingDirection
27+
typedef NS_ENUM(NSInteger, NSWritingDirection) {
28+
NSWritingDirectionNatural = -1, // Determines direction using the Unicode Bidi Algorithm rules P2 and P3
29+
NSWritingDirectionLeftToRight = 0, // Left to right writing direction
30+
NSWritingDirectionRightToLeft = 1 // Right to left writing direction
31+
} API_AVAILABLE(macos(10.0), ios(6.0), watchos(2.0), tvos(9.0), visionos(1.0));
32+
#endif // !__NSWRITING_DIRECTION_SHARED_SECTION__
33+
34+
NS_HEADER_AUDIT_END(nullability, sendability)
35+
36+
#endif

0 commit comments

Comments
 (0)