Skip to content

Commit f75b32d

Browse files
authored
Merge pull request #63 from colinc86/develop
Develop
2 parents 442366e + 2c01045 commit f75b32d

14 files changed

+32
-40
lines changed

Package.resolved

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ let package = Package(
1616
],
1717
dependencies: [
1818
.package(url: "https://github.com/colinc86/MathJaxSwift", from: "3.4.0"),
19-
.package(url: "https://github.com/colinc86/SwiftDraw", branch: "latexswiftui"),
19+
.package(url: "https://github.com/swhitty/SwiftDraw", from: "0.20.1"),
2020
.package(url: "https://github.com/Kitura/swift-html-entities", from: "4.0.1")
2121
],
2222
targets: [

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ It won't
5050
Add the dependency to your package manifest file.
5151

5252
```swift
53-
.package(url: "https://github.com/colinc86/LaTeXSwiftUI", from: "1.4.0")
53+
.package(url: "https://github.com/colinc86/LaTeXSwiftUI", from: "1.4.1")
5454
```
5555

5656
## Usage
@@ -284,7 +284,7 @@ LaTeX(input)
284284

285285
> In the above example, the input text will be displayed until the SVGs have been rendered at which point the rendered views will animate in to view.
286286
287-
### Styles
287+
### Styles (Deprecated)
288288

289289
You can use the provided view styles or create your own.
290290

Sources/LaTeXSwiftUI/Extensions/Font+Extensions.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import Foundation
2727
import SwiftUI
2828

29-
#if os(iOS)
29+
#if os(iOS) || os(visionOS)
3030
import UIKit
3131
#else
3232
import Cocoa
@@ -95,7 +95,7 @@ internal extension _Font {
9595
.caption2.bold(),
9696
.footnote.bold(),
9797
.body.bold():
98-
#if os(iOS)
98+
#if os(iOS) || os(visionOS)
9999
if let descriptor = _font.fontDescriptor.withSymbolicTraits(.traitBold) {
100100
return _Font(descriptor: descriptor, size: _font.pointSize)
101101
}
@@ -118,7 +118,7 @@ internal extension _Font {
118118
.caption2.monospaced(),
119119
.footnote.monospaced(),
120120
.body.monospaced():
121-
#if os(iOS)
121+
#if os(iOS) || os(visionOS)
122122
if let descriptor = _font.fontDescriptor.withSymbolicTraits(.traitMonoSpace) {
123123
return _Font(descriptor: descriptor, size: _font.pointSize)
124124
}
@@ -141,7 +141,7 @@ internal extension _Font {
141141
.caption2.italic(),
142142
.footnote.italic(),
143143
.body.italic():
144-
#if os(iOS)
144+
#if os(iOS) || os(visionOS)
145145
if let descriptor = _font.fontDescriptor.withSymbolicTraits(.traitItalic) {
146146
return _Font(descriptor: descriptor, size: _font.pointSize)
147147
}

Sources/LaTeXSwiftUI/Extensions/Image+Extensions.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@
2222
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
2323
// IN THE SOFTWARE.
2424
//
25-
2625
import SwiftUI
2726

2827
internal extension Image {
2928

3029
init(image: _Image, scale: CGFloat = 1.0) {
31-
#if os(iOS)
30+
#if os(iOS) || os(visionOS)
3231
self.init(uiImage: image)
3332
#else
3433
if scale > 1.0 {

Sources/LaTeXSwiftUI/LaTeX.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public struct LaTeX: View {
187187

188188
public var body: some View {
189189
VStack(spacing: 0) {
190-
if renderer.rendered {
190+
if renderer.rendered || renderer.syncRendered {
191191
// If our blocks have been rendered, display them
192192
bodyWithBlocks(renderer.blocks)
193193
}
@@ -230,6 +230,7 @@ extension LaTeX {
230230
///
231231
/// - Parameter style: The `LaTeX` view style to use.
232232
/// - Returns: A stylized view.
233+
@available(*, deprecated, message: "This will be removed in a following version. Use other modifiers to set your style.")
233234
public func latexStyle<S>(_ style: S) -> some View where S: LaTeXStyle {
234235
style.makeBody(content: self)
235236
}

Sources/LaTeXSwiftUI/Models/Aliases.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
import Foundation
2727

28-
#if os(iOS)
28+
#if os(iOS) || os(visionOS)
2929
import UIKit
3030
internal typealias _Image = UIImage
3131
internal typealias _Font = UIFont

Sources/LaTeXSwiftUI/Models/ImageContainer.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,4 @@ internal struct ImageContainer: Hashable {
3838
func hash(into hasher: inout Hasher) {
3939
hasher.combine(size)
4040
}
41-
4241
}

Sources/LaTeXSwiftUI/Models/Renderer.swift

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import MathJaxSwift
2828
import SwiftDraw
2929
import SwiftUI
3030

31-
#if os(iOS)
31+
#if os(iOS) || os(visionOS)
3232
import UIKit
3333
#else
3434
import Cocoa
@@ -58,11 +58,14 @@ internal class Renderer: ObservableObject {
5858
/// Whether or not the view's blocks have been rendered.
5959
@MainActor @Published var rendered: Bool = false
6060

61+
/// Whether or not the view's blocks have been rendered synchronously.
62+
@MainActor var syncRendered: Bool = false
63+
6164
/// Whether or not the receiver is currently rendering.
62-
@MainActor @Published var isRendering: Bool = false
65+
@MainActor var isRendering: Bool = false
6366

6467
/// The rendered blocks.
65-
@MainActor @Published var blocks: [ComponentBlock] = []
68+
@MainActor var blocks: [ComponentBlock] = []
6669

6770
// MARK: Private properties
6871

@@ -145,22 +148,21 @@ extension Renderer {
145148
guard !isRendering else {
146149
return []
147150
}
148-
guard !rendered else {
151+
guard !rendered && !syncRendered else {
149152
return blocks
150153
}
151154
isRendering = true
152155

153156
let texOptions = TeXInputProcessorOptions(processEscapes: processEscapes, errorMode: errorMode)
154-
let renderedBlocks = render(
157+
blocks = render(
155158
blocks: parseBlocks(latex: latex, unencodeHTML: unencodeHTML, parsingMode: parsingMode),
156159
font: font,
157160
displayScale: displayScale,
158161
renderingMode: renderingMode,
159162
texOptions: texOptions)
160163

161-
blocks = renderedBlocks
162164
isRendering = false
163-
rendered = true
165+
syncRendered = true
164166
return blocks
165167
}
166168

@@ -187,7 +189,8 @@ extension Renderer {
187189
) async {
188190
let isRen = await isRendering
189191
let ren = await rendered
190-
guard !isRen && !ren else {
192+
let renSync = await syncRendered
193+
guard !isRen && !ren && !renSync else {
191194
return
192195
}
193196
await MainActor.run {
@@ -413,9 +416,15 @@ extension Renderer {
413416

414417
// Continue with getting the image
415418
let imageSize = svg.size(for: xHeight)
419+
#if os(iOS) || os(visionOS)
420+
guard let image = SwiftDraw.SVG(data: svg.data)?.rasterize(size: imageSize, scale: displayScale) else {
421+
return nil
422+
}
423+
#else
416424
guard let image = SwiftDraw.SVG(data: svg.data)?.rasterize(with: imageSize, scale: displayScale) else {
417425
return nil
418426
}
427+
#endif
419428

420429
// Set the image in the cache
421430
Cache.shared.setImageCacheValue(image, for: cacheKey)

Sources/LaTeXSwiftUI/Models/SVGGeometry.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ extension SVGGeometry.XHeight {
217217
/// - Parameter font: The font.
218218
/// - Returns: The points.
219219
func toPoints(_ font: Font) -> CGFloat {
220-
#if os(iOS)
220+
#if os(iOS) || os(visionOS)
221221
toPoints(_Font.preferredFont(from: font))
222222
#else
223223
toPoints(_Font.preferredFont(from: font))

0 commit comments

Comments
 (0)