-
Notifications
You must be signed in to change notification settings - Fork 70
Update ResolvedStyledText API #945
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
bc8c274
Update ResolvedStyledText API
Kyle-Ye 7d508c1
Update NSAttributedString API
Kyle-Ye bdf016d
Update Package.resolved
Kyle-Ye 1bebbb2
Implement NSAttributedString.maxFontMetrics
Kyle-Ye f5d40a6
Update TextDrawingContext
Kyle-Ye fcaedaf
Update ResolvedStyledText.init
Kyle-Ye c2b64f0
Update ResolvedStyledText.lineHeightScalingAdjustment
Kyle-Ye 6f94cc7
Update ResolvedStyledText abstract method
Kyle-Ye 427a3cf
Add NSAttributedString.Metrics API
Kyle-Ye 3cfbe40
Update ResolvedStyledText missing API
Kyle-Ye 05e1ddc
Update metrics and layout API
Kyle-Ye 2573597
[WIP] Update resolving API
Kyle-Ye 1234335
[NFC] Optimize AttributeCountTestInfo
Kyle-Ye 92cb749
Update ResolvedStyledText + styledText
Kyle-Ye a0211d8
Add MetricsCache
Kyle-Ye 666b529
Workaround Linux compile issue
Kyle-Ye File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // | ||
| // AttributeCountInfoKey.swift | ||
| // OpenSwiftUICore | ||
| // | ||
| // Audited for 6.5.4 | ||
| // Status: Complete | ||
|
|
||
| // MARK: - AttributeCountInfoKey | ||
|
|
||
| package struct AttributeCountInfoKey: HostPreferenceKey { | ||
| package static let defaultValue = AttributeCountTestInfo() | ||
|
|
||
| package static func reduce( | ||
| value: inout AttributeCountTestInfo, | ||
| nextValue: () -> AttributeCountTestInfo | ||
| ) { | ||
| value.merge(nextValue()) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
Sources/OpenSwiftUICore/View/Text/Text/Text+Measure.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| // | ||
| // Text+StringDrawingContext.swift | ||
| // OpenSwiftUICore | ||
| // | ||
| // Audited for 6.5.4 | ||
| // Status: WIP | ||
| // ID: 68D51D45BC7225E72FB030F887E5A492 (SwiftUICore) | ||
|
|
||
| public import Foundation | ||
|
|
||
| @available(OpenSwiftUI_v6_0, *) | ||
| extension NSAttributedString { | ||
| @usableFromInline | ||
| package struct Metrics: Equatable { | ||
| package var size: CGSize | ||
| package let scale: CGFloat | ||
| package var firstBaseline: CGFloat | ||
| package var lastBaseline: CGFloat | ||
| package var baselineAdjustment: CGFloat | ||
| package var requestedWidth: CGFloat | ||
| package var numberOfLines: UInt? | ||
| package var hasTruncatedRanges: Bool | ||
|
|
||
| package init( | ||
| size: CGSize, | ||
| scale: CGFloat, | ||
| firstBaseline: CGFloat, | ||
| lastBaseline: CGFloat, | ||
| baselineAdjustment: CGFloat, | ||
| requestedWidth: CGFloat, | ||
| numberOfLines: UInt?, | ||
| hasTruncatedRanges: Bool | ||
| ) { | ||
| self.size = size | ||
| self.scale = scale | ||
| self.firstBaseline = firstBaseline | ||
| self.lastBaseline = lastBaseline | ||
| self.baselineAdjustment = baselineAdjustment | ||
| self.requestedWidth = requestedWidth | ||
| self.numberOfLines = numberOfLines | ||
| self.hasTruncatedRanges = hasTruncatedRanges | ||
| } | ||
| } | ||
|
|
||
| struct MetricsCache { | ||
| var kitCache: AnyObject? | ||
| let string: NSAttributedString | ||
| let lineLimit: Int? | ||
| let lowerLineLimit: Int? | ||
| let minScaleFactor: CGFloat | ||
| let bodyHeadOutdent: CGFloat | ||
| let pixelLength: CGFloat | ||
| let widthIsFlexible: Bool | ||
| let drawWithRequestedWidth: Bool | ||
| let isCollapsible: Bool | ||
| var entries: [(CGSize, Metrics)] | ||
|
|
||
| init( | ||
| _ string: NSAttributedString?, | ||
| scaleFactorOverride: CGFloat?, | ||
| lineLimit: Int?, | ||
| lowerLineLimit: Int?, | ||
| minScaleFactor: CGFloat, | ||
| bodyHeadOutdent: CGFloat, | ||
| pixelLength: CGFloat, | ||
| widthIsFlexible: Bool, | ||
| drawWithRequestedWidth: Bool, | ||
| isCollapsible: Bool | ||
| ) { | ||
| self.kitCache = nil | ||
| self.string = string?.scaled(by: scaleFactorOverride ?? 1) ?? .emptyString | ||
| self.lineLimit = lineLimit | ||
| self.lowerLineLimit = lowerLineLimit | ||
| // A scale override has already been baked into `string`, so the drawing | ||
| // context must not apply the original minimum scale factor a second time. | ||
| self.minScaleFactor = scaleFactorOverride == nil ? minScaleFactor : 1 | ||
| self.bodyHeadOutdent = bodyHeadOutdent | ||
| self.pixelLength = pixelLength | ||
| self.widthIsFlexible = widthIsFlexible | ||
| self.drawWithRequestedWidth = drawWithRequestedWidth | ||
| self.isCollapsible = isCollapsible | ||
| self.entries = [] | ||
| } | ||
|
|
||
| mutating func metrics( | ||
| requestedSize: CGSize, | ||
| layoutMargins: EdgeInsets, | ||
| wantsNumberOfLineFragments: Bool, | ||
| context: TextDrawingContext | ||
| ) -> Metrics { | ||
| _openSwiftUIUnimplementedFailure() | ||
| } | ||
| } | ||
|
|
||
| private static let emptyString = NSAttributedString() | ||
|
|
||
| private func measured( | ||
| requestedSize: CGSize, | ||
| lineLimit: Int?, | ||
| lowerLineLimit: Int?, | ||
| minScaleFactor: CGFloat, | ||
| bodyHeadOutdent: CGFloat, | ||
| widthIsFlexible: Bool, | ||
| kitCache: inout AnyObject?, | ||
| isCollapsible: Bool, | ||
| wantsNumberOfLineFragments: Bool, | ||
| context: TextDrawingContext | ||
| ) -> NSAttributedString.Metrics { | ||
| _openSwiftUIUnimplementedFailure() | ||
| } | ||
| } | ||
|
|
||
| @available(*, unavailable) | ||
| extension NSAttributedString.Metrics: Sendable {} | ||
|
|
||
| extension ResolvedStyledText { | ||
| // FIXME | ||
| package class StringDrawing: ResolvedStyledText {} | ||
|
|
||
| // FIXME | ||
| package class TextLayoutManager: ResolvedStyledText {} | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.