|
8 | 8 |
|
9 | 9 | #if OPENSWIFTUI_TARGET_OS_DARWIN |
10 | 10 |
|
11 | | -OPENSWIFTUI_ASSUME_NONNULL_BEGIN |
| 11 | +// Modified based on macOS 15.5 SDK |
12 | 12 |
|
| 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)) |
13 | 74 | @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 | + |
15 | 114 | @end |
16 | 115 |
|
| 116 | + |
| 117 | +OPENSWIFTUI_EXPORT API_AVAILABLE(macos(10.0), ios(6.0), tvos(9.0), watchos(2.0), visionos(1.0)) |
17 | 118 | @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 | + |
19 | 144 | @end |
20 | 145 |
|
21 | | -OPENSWIFTUI_ASSUME_NONNULL_END |
| 146 | +NS_HEADER_AUDIT_END(nullability, sendability) |
22 | 147 |
|
23 | 148 | #endif |
0 commit comments