the RTFvalue function in MacOSlib speeds up a TextArea’s RTDdata handling massively. Would it be possible to adapt this for use with StyledText objects as well (for example to to do things like concatenate styled text runs)?
[code]Function RTFValue(extends t as TextArea) As String #if targetCocoa
declare function RTFFromRange lib CocoaLib selector “RTFFromRange:” (obj_id as Ptr, range as Cocoa.NSRange) as Ptr
declare function length lib CocoaLib selector “length” (obj_id as Ptr) as Integer
declare sub getBytes lib CocoaLib selector “getBytes:length:” (obj_id as Ptr, buffer as Ptr, length as Integer)
dim range as Cocoa.NSRange
range.length = Len(t.Text)
dim p as Ptr = RTFFromRange(t.TextViewRef, range)
if p <> nil then
dim m as new MemoryBlock(length(p))
getBytes(p, m, m.Size)
return m.StringValue(0, m.Size)
else
return ""
end if
Follow on question: Ok, so I can’t use Xojo’s StyledText objects. But is it possible to define a different MyStyledText object which could be faster that does use NSAttributedStrings? Do you by any chance have something in MBS?
I also think that an invisible textarea would be best.
The slow thing with StyledText is querying the properties with all the StylerRuns and paragraphs.
[quote=94401:@Christian Schmitz]no. StyledText objects have their own data structures and as far as I know are not simply NSAttributedStrings…
[/quote]
Are you sure? It seems the textstorage property holds the NSAttributedString representing all of the text and formatting… I thought that’s why setTextAndStyle was deprecated (could be wrong…)