We use NSLayoutManager/NSTextStorage/NSTextContainer to display markdown attributed string on a canvas. MarkDown string was processed properly, but NSLayoutManager just exhibits the plain text. The code is as follows:
var layoutmanager = NSLayoutManager()
var textstorage = NSTextStorage()
var textcontainer = NSTextContainer()
var attrStr = try AttributedString.init(markdown: "**test**", options: AttributedString.MarkdownParsingOptions(interpretedSyntax: .inlineOnlyPreservingWhitespace))
var attrString = NSMutableAttributedString(attrStr)
self.textstorage.setAttributedString(attrString!)
// draw text layout
let range = self.layoutmanager.glyphRange(for: self.textcontainer)
self.layoutmanager.drawBackground(forGlyphRange: range, at: self.textLocation)
self.layoutmanager.drawGlyphs(forGlyphRange: range, at: self.textLocation)
Is it because TextKit 1 does not support markdown string display or I miss something else ?
Any help will be appreciated. Thanks!
WWDC2020 videos said SwiftUI on Xcode12 can create and manage different scenes in an App, but we do not find out any API could do that. We try the method of SwiftUI on Xcode11 to create new Window on Xcode 12 :
UIApplication.shared.requestSceneSessionActivation(nil, userActivity: nil, options: nil, errorHandler: nil) })
But it does not work as we expect. The code create a window of the same scene. If we set a different userActivity, SwiftUI have no method to set SceneDelegate.swift. It only has @UIApplicationDelegateAdaptor to set AppDelegate.
So, I Wonder whether there is a convenient way to create a new Scene by new SwiftUI APIs.
The following code can only create Scenes with the same content view :
@main struct test: App {
let newWindowPublisher = NotificationCenter.default.publisher(for: Notification.Name("anotherScene"))
var body: some Scene {
WindowGroup {
ContentView()
.onReceive(newWindowPublish, perform: { info in
UIApplication.shared.requestSceneSessionActivation(nil, userActivity: nil, options: nil, errorHandler: nil) })
}
}
}
Post not yet marked as solved
A very simple App is created to deal with pdf file providing open/save/highlight pdf file utilizing PDFKit.pdfDoc is used to load pdf file: pdfDoc = [PDFDocument alloc]; pdfDoc = [pdfDoc initWithURL:url];the following code is used to save changed pdf file: [pdfDoc writeToFile:path];The App can save a pdf file changed by highlight some texts and reopen it properly. But if theChinese/Japanese/Korea (CJK) text of the reopened pdf file is selected and copied, the text pastedis error codes. I do not know whether I miss something in the codes or it is a bug in PDFKit. It seems Preview.app has thesame problem before, but it works fine now.Any suggestion for solving the problem will be appreciated.