Skip to content

Commit

Permalink
补充ASAttributedString.Attribute.ParagraphStyle
Browse files Browse the repository at this point in the history
  • Loading branch information
lixiang1994 committed Apr 27, 2022
1 parent dacc8fb commit f87bb08
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,46 +54,33 @@
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.Carousel"
RemotePath = "/Demo-Watch WatchKit App">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9B267B4D24405CFA002F571E"
BuildableName = "Demo-Watch WatchKit App.app"
BlueprintName = "Demo-Watch WatchKit App"
ReferencedContainer = "container:Demo-Watch.xcodeproj">
</BuildableReference>
</RemoteRunnable>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.Carousel"
RemotePath = "/Demo-Watch WatchKit App">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9B267B4D24405CFA002F571E"
BuildableName = "Demo-Watch WatchKit App.app"
BlueprintName = "Demo-Watch WatchKit App"
ReferencedContainer = "container:Demo-Watch.xcodeproj">
</BuildableReference>
</RemoteRunnable>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9B267B4D24405CFA002F571E"
BuildableName = "Demo-Watch WatchKit App.app"
BlueprintName = "Demo-Watch WatchKit App"
ReferencedContainer = "container:Demo-Watch.xcodeproj">
</BuildableReference>
</MacroExpansion>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
Expand Down
16 changes: 16 additions & 0 deletions Sources/ParagraphStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ extension ASAttributedString.Attribute {
case lineHeightMultiple // CGFloat
case paragraphSpacingBefore // CGFloat
case hyphenationFactor // Float
@available(macOS 12.0, iOS 15.0, tvOS 15.0, watchOSApplicationExtension 8.0, *)
case usesDefaultHyphenation // Bool
case tabStops // [NSTextTab]
case defaultTabInterval // CGFloat
case allowsDefaultTighteningForTruncation // Bool
case lineBreakStrategy // NSParagraphStyle.LineBreakStrategy
}

fileprivate let style: [Key: Any]
Expand Down Expand Up @@ -82,9 +85,13 @@ extension ASAttributedString.Attribute {
fetch(.lineHeightMultiple) { paragraph.lineHeightMultiple = $0 }
fetch(.paragraphSpacingBefore) { paragraph.paragraphSpacingBefore = $0 }
fetch(.hyphenationFactor) { paragraph.hyphenationFactor = $0 }
if #available(macOS 12.0, iOS 15.0, tvOS 15.0, watchOSApplicationExtension 8.0, *) {
fetch(.usesDefaultHyphenation) { paragraph.usesDefaultHyphenation = $0 }
}
fetch(.tabStops) { paragraph.tabStops = $0 }
fetch(.defaultTabInterval) { paragraph.defaultTabInterval = $0 }
fetch(.allowsDefaultTighteningForTruncation) { paragraph.allowsDefaultTighteningForTruncation = $0 }
fetch(.lineBreakStrategy) { paragraph.lineBreakStrategy = $0 }
return paragraph
}
}
Expand Down Expand Up @@ -144,6 +151,11 @@ extension ASAttributedString.Attribute.ParagraphStyle {
return .init(style: [.hyphenationFactor: value])
}

@available(macOS 12.0, iOS 15.0, tvOS 15.0, watchOSApplicationExtension 8.0, *)
public static func usesDefaultHyphenation(_ value: Bool) -> Self {
return .init(style: [.usesDefaultHyphenation: value])
}

public static func tabStops(_ value: [NSTextTab]) -> Self {
return .init(style: [.tabStops: value])
}
Expand All @@ -155,6 +167,10 @@ extension ASAttributedString.Attribute.ParagraphStyle {
public static func allowsDefaultTighteningForTruncation(_ value: Bool) -> Self {
return .init(style: [.allowsDefaultTighteningForTruncation: value])
}

public static func lineBreakStrategy(_ value: NSParagraphStyle.LineBreakStrategy) -> Self {
return .init(style: [.lineBreakStrategy: value])
}
}

extension ASAttributedString.Attribute.ParagraphStyle {
Expand Down

0 comments on commit f87bb08

Please sign in to comment.