forked from gonzalezreal/swift-markdown-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use the environment's line spacing (gonzalezreal#95)
* Set the environment's line spacing value to the attributed string paragraph style * Refactor renderer environment
- Loading branch information
1 parent
b6e88f1
commit 4c16430
Showing
7 changed files
with
138 additions
and
119 deletions.
There are no files selected for viewing
This file contains 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
58 changes: 58 additions & 0 deletions
58
Sources/MarkdownUI/Rendering/AttributedStringRenderer+Environment.swift
This file contains 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,58 @@ | ||
import SwiftUI | ||
|
||
extension AttributedStringRenderer { | ||
struct Environment: Hashable { | ||
let baseURL: URL? | ||
let baseWritingDirection: NSWritingDirection | ||
let alignment: NSTextAlignment | ||
let lineSpacing: CGFloat | ||
let sizeCategory: ContentSizeCategory | ||
let style: MarkdownStyle | ||
|
||
init( | ||
baseURL: URL?, | ||
layoutDirection: LayoutDirection, | ||
alignment: TextAlignment, | ||
lineSpacing: CGFloat, | ||
sizeCategory: ContentSizeCategory, | ||
style: MarkdownStyle | ||
) { | ||
self.baseURL = baseURL | ||
self.baseWritingDirection = .init(layoutDirection) | ||
self.alignment = .init(layoutDirection, alignment) | ||
self.lineSpacing = lineSpacing | ||
self.sizeCategory = sizeCategory | ||
self.style = style | ||
} | ||
} | ||
} | ||
|
||
extension NSWritingDirection { | ||
fileprivate init(_ layoutDirection: LayoutDirection) { | ||
switch layoutDirection { | ||
case .leftToRight: | ||
self = .leftToRight | ||
case .rightToLeft: | ||
self = .rightToLeft | ||
@unknown default: | ||
self = .natural | ||
} | ||
} | ||
} | ||
|
||
extension NSTextAlignment { | ||
fileprivate init(_ layoutDirection: LayoutDirection, _ textAlignment: TextAlignment) { | ||
switch (layoutDirection, textAlignment) { | ||
case (_, .leading): | ||
self = .natural | ||
case (_, .center): | ||
self = .center | ||
case (.leftToRight, .trailing): | ||
self = .right | ||
case (.rightToLeft, .trailing): | ||
self = .left | ||
default: | ||
self = .natural | ||
} | ||
} | ||
} |
This file contains 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
Oops, something went wrong.