You might want to have a look at MacOSLib - it has functions to deal with RTF that used to be MUCH faster than Xojo’s build-in ones (by a factor of 100) and didn’t mangle the RTF text. Not sure if Xojo has ever improved their own functions.
The original data is :
cnRmZAAAAAADAAAAAgAAAAcAAABUWFQucnRmAQAAAC5fAQAAKwAAAAEAAABXAQAAe1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcY29jb2FydGYxNjcxXGNvY29hc3VicnRmNjAwCntcZm9udHRibFxmMFxmbmlsXGZjaGFyc2V0MCBHZW5ldmE7fQp7XGNvbG9ydGJsO1xyZWQyNTVcZ3JlZW4yNTVcYmx1ZTI1NTtccmVkMFxncmVlbjBcYmx1ZTA7fQp7XCpcZXhwYW5kZWRjb2xvcnRibDs7XGNzZ2VuZXJpY3JnYlxjMFxjMFxjMDt9ClxwYXJkXHR4NTYwXHR4MTEyMFx0eDE2ODBcdHgyMjQwXHR4MjgwMFx0eDMzNjBcdHgzOTIwXHR4NDQ4MFx0eDUwNDBcdHg1NjAwXHR4NjE2MFx0eDY3MjBccGFyZGlybmF0dXJhbFxwYXJ0aWdodGVuZmFjdG9yMAoKXGYwXGZzMjQgXGNmMiBBZHZhbmNlZCBUZXh0fQEAAAAjAAAAAQAAAAcAAABUWFQucnRmEAAAALwa8mC2AQAAAAAAAAAAAAA=
To open the RTFD add the MacOSlib and the Additional Modules to your project.
MacOSlib has a readRTFD method that is an extension of a TextArea and returns a boolean
So all you have to do is either use CALL (if you don’t want to use the return value)
#if TargetCocoa
Var file As FolderItem = Folderitem.ShowOpenFileDialog("Special/Any")
Call t.ReadRTFDFromFile(file.NativePath)
#else
#pragma unused t
#endif
or use if … end if:
#if TargetCocoa
Var file As FolderItem = Folderitem.ShowOpenFileDialog("Special/Any")
If t.ReadRTFDFromFile(file.NativePath) Then
// your own stuff, eg add window to window menu
else
MessageBox "Could not open file."
End If
#else
#pragma unused t
#endif
Best wrap it into an extension method that you can call from anywhere:
Public Sub OpenRTFD(extends t as TextArea)
#if TargetCocoa
Var file As FolderItem = Folderitem.ShowOpenFileDialog("Special/Any")
If file Is Nil Then
// user cancelled
Else
Try
Call t.ReadRTFDFromFile(file.NativePath)
// or
' If t.ReadRTFDFromFile(file.NativePath) Then
'
' End If
Catch e As IOException
// unable to open file
End Try
End If
#else
#pragma unused t
#endif
End Sub
MacOSlib also has a WriteRTFDToFile extension method …
In the TextArea Open event add:
Sub Open() Handles Open
Me.UsesFindPanel = True
me.UsesFindBar = True
me.UsesInspectorBar = True
End Sub