Using MacOSlib RTFvalue speed up for StyledText objects?

Hi all,

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

#else
#pragma unused t
#endif

End Function[/code]

no. StyledText objects have their own data structures and as far as I know are not simply NSAttributedStrings…

That’s what I feared, but hope springs eternal :wink:

Thanks.

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?

Why not use an invisible TextArea, off-window. Then you CAN use RTF to manipulate it.

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.

Thanks Tim I knew about this trick but wondered if directly manipulating StyledText objects might be faster.

Thanks Christian - that clears that up.

[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…)

Oh wait, misread you…
You could manipulate the NSAttributedString of the TextArea, then get the styledtext object afterward…