PDA

View Full Version : Help with text formatting in an NSTextView




dryjoy
Jan 5, 2012, 10:27 AM
I'm pretty inexperienced with Objective-C & Cocoa, but learning fast! I'm working on an app that needs to parse XML files, and format some text according to a few pseudo-HTML tags, such as <body>content</body> and <heading>content</heading> etc.

I've been doing some command-line app experiments with the NSXML API (NSXMLNode, NSXMLDocument, NSXMLElement etc.) and I'm happy about reading, writing, creating, parsing etc. an XML document.

What I'm not sure of is, once I've extracted the data from the XML document and got a tree of XML objects, how to format the text in the NSTextView, and also how to detect which ranges of text in the NSTextView are in what size, font weight etc.

Could somebody please point me towards the appropriate classes etc, and I'll try and work it out from the Apple docs.



jiminaus
Jan 5, 2012, 03:20 PM
These guides should get you started:
Text System Overview (http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/TextArchitecture/Concepts/CocoaAndATSUI.html)
Cocoa Text Architecture Guide (http://developer.apple.com/library/mac/#documentation/TextFonts/Conceptual/CocoaTextArchitecture)
Text System User Interface Layer Programming Guide (http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/TextUILayer/TextUILayer.html)
Text Attributes (http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/TextAttributes/TextAttributes.html)
Attributed String Programming Guide (http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/AttributedStrings/AttributedStrings.html)
Text Layout Programming Guide (http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/TextLayout/TextLayout.html)

Or you could possibly transform your XML into HTML, display it in a WebView, and implement the editing behaviour with a combination of JavaScript, web script objects and a WebEditingDelegate.

dryjoy
Jan 5, 2012, 04:14 PM
Thanks very much. I'll have a read... no doubt I'll have some specific questions once I get stuck in.