diff --git a/Package.swift b/Package.swift index 782dcf6..d9a6007 100644 --- a/Package.swift +++ b/Package.swift @@ -8,7 +8,7 @@ let package = Package( platforms: [ .iOS(.v15), .macOS(.v12), - .visionOS(.v1) + .visionOS(.v2) ], products: [ .library( diff --git a/Sources/LaTeXSwiftUI/Extensions/Image+Extensions.swift b/Sources/LaTeXSwiftUI/Extensions/Image+Extensions.swift index ca1b486..a398920 100644 --- a/Sources/LaTeXSwiftUI/Extensions/Image+Extensions.swift +++ b/Sources/LaTeXSwiftUI/Extensions/Image+Extensions.swift @@ -26,25 +26,15 @@ import SwiftUI internal extension Image { - init(image: _Image, scale: CGFloat = 1.0) { + init(image: _Image) { #if os(iOS) || os(visionOS) + // `UIImage(cgImage:scale:orientation:)` already carries the display + // scale, so its `size` is in points. self.init(uiImage: image) #else - if scale > 1.0 { - let scaledSize = NSSize( - width: image.size.width / scale, - height: image.size.height / scale - ) - - let scaledImage = image.resized(to: scaledSize) - if let representation = image.representations.first { - scaledImage.addRepresentation(representation) - } - - self.init(nsImage: scaledImage) - return - } - + // `NSImage(cgImage:size:)` is created with the logical size, so its + // `size` is already in points — dividing by the display scale again + // would lay the image out at half its intended size on Retina screens. self.init(nsImage: image) #endif } diff --git a/Sources/LaTeXSwiftUI/Extensions/NSImage+Extensions.swift b/Sources/LaTeXSwiftUI/Extensions/NSImage+Extensions.swift deleted file mode 100644 index 10b5f93..0000000 --- a/Sources/LaTeXSwiftUI/Extensions/NSImage+Extensions.swift +++ /dev/null @@ -1,47 +0,0 @@ -// -// NSImage+Extensions.swift -// LaTeXSwiftUI -// -// Copyright (c) 2023 Colin Campbell -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -// - -#if os(macOS) -import Cocoa - -internal extension NSImage { - - /// Resizes the image. - /// - Parameter newSize: The image's new size. - /// - Returns: A resized image. - func resized(to newSize: CGSize) -> NSImage { - let newImage = NSImage(size: newSize) - newImage.lockFocus() - defer { newImage.unlockFocus() } - self.draw( - in: CGRect(origin: .zero, size: newSize), - from: CGRect(origin: .zero, size: self.size), - operation: .copy, - fraction: 1.0) - return newImage - } - -} -#endif diff --git a/Sources/LaTeXSwiftUI/Extensions/TeXInputProcessorOptions+Extensions.swift b/Sources/LaTeXSwiftUI/Extensions/TeXInputProcessorOptions+Extensions.swift index 4a12d8d..f7b4bc0 100644 --- a/Sources/LaTeXSwiftUI/Extensions/TeXInputProcessorOptions+Extensions.swift +++ b/Sources/LaTeXSwiftUI/Extensions/TeXInputProcessorOptions+Extensions.swift @@ -37,7 +37,16 @@ extension TeXInputProcessorOptions { convenience init(processEscapes: Bool, errorMode: LaTeX.ErrorMode) { self.init() self.processEscapes = processEscapes - + + // MathJaxSwift 3.5.0 ships `defaultDigits` with its escapes stripped + // (`\{,\}` → `{,}`, `\.` → `.`), so the unescaped `.` matches *any* + // character and the tokenizer swallows whatever follows a number: `x^{2}` + // loses its closing brace and MathJax fails with "Extra open brace or + // missing close brace". Restore MathJax's own default regex. + // See colinc86/MathJaxSwift#45. + digits = #"^(?:[0-9]+(?:\{,\}[0-9]{3})*(?:\.[0-9]*)?|\.[0-9]+)"# + + var packages = TeXInputProcessorOptions.Packages.all if errorMode != .rendered { if let noErrorsIndex = packages.firstIndex(of: TeXInputProcessorOptions.Packages.noerrors) { diff --git a/Sources/LaTeXSwiftUI/Models/Renderer.swift b/Sources/LaTeXSwiftUI/Models/Renderer.swift index 20d736e..ec449e4 100644 --- a/Sources/LaTeXSwiftUI/Models/Renderer.swift +++ b/Sources/LaTeXSwiftUI/Models/Renderer.swift @@ -515,7 +515,7 @@ extension Renderer { Cache.shared.setImageCacheValue(image, for: cacheKey) // Finish up - return Image(image: image, scale: displayScale) + return Image(image: image) .renderingMode(renderingMode) .antialiased(true) .interpolation(.high) diff --git a/Sources/LaTeXSwiftUI/Previews/LaTeX_Previews+Fonts.swift b/Sources/LaTeXSwiftUI/Previews/LaTeX_Previews+Fonts.swift index 9804604..44a361a 100644 --- a/Sources/LaTeXSwiftUI/Previews/LaTeX_Previews+Fonts.swift +++ b/Sources/LaTeXSwiftUI/Previews/LaTeX_Previews+Fonts.swift @@ -25,7 +25,7 @@ import SwiftUI -#if os(iOS) +#if os(iOS) || os(visionOS) import UIKit typealias PlatformFont = UIFont #else