Troubles with RTF

the code below loads the RTF Source code and place it into a TextArea (TA):

TA.Text = OpenTIS.ReadAll

the code below seems to loop forever:

TA.StyledText.RTFData = OpenTIS.ReadAll

Xojo 2014r1
OS X 10.8.5

  • the file does not contain rtf data
  • the file contains malformed or unsupported rtf data
  • TA.Multiline is False (instead of True)
  • TA.Styled is False (instead of True)
  • OpenTIS is returning an error, but you’re not catching it

Difficult to say without the RTF (and the source code before and after the erroneous line)

for OSX

load this into your project
RTFModul

Load RTF:

TextArea1.RTFValue=DefineEncoding(OpenTIS.ReadAll(),Encodings.MacRoman)

SaveRTF:

tos.Write ConvertEncoding(TextArea1.RTFValue,Encodings.MacRoman)

(adjust encoding as you need it)

[quote=72538:@Eli Ott]- the file does not contain rtf data

  • the file contains malformed or unsupported rtf data
  • TA.Multiline is False (instead of True)
  • TA.Styled is False (instead of True)
  • OpenTIS is returning an error, but you’re not catching it

Difficult to say without the RTF (and the source code before and after the erroneous line)[/quote]
Eli:
Thank you for your answer.

The file can be read with both TextEdit (OS X) and WordPad (Windows).
TA.Multiline is True (if False, I could read the beginning of the text…)
TA.Styled is True
OpenTIX does not return an error: I followed in the debugger and it loops forever in that line.

Atr last, a different rtf file was loaded… (one that have been created with Xojo).

Axel:

Thank you for the module, I will try it this afternoon.

Your examples: I do not need to use any encoding (or will I?): I want to use UTF-8.

TextArea1.RTFValue …

you meant:

TextArea1.StyledText.RTFData …

Emile

Xojo doesn’t support a lot of the RTF control codes - only the ones you can access through StyledText (Bold, Font, Italic and a few more). So opening the file in TextEdit doesn’t tell you at all if Xojo will be able to interpret the data.

OK, so this is a bug since an RTF reader must not loop 'till its death.

PS: even that does not works !!!

[quote=72534:@Emile Schwarz]the code below seems to loop forever:

TA.StyledText.RTFData = OpenTIS.ReadAll
Xojo 2014r1
OS X 10.8.5

[/quote]

What is the size of the RTF file ? I repost what I did in a previous thread :

Loading a TextArea RTFData is not only slow, it is INCREDIBLY slow. I used the example StyledText.xojo_binary_project and modified it to save and load RTF. Then I proceeded to load and save different versions of the Princess of Mars of different sizes. Results are gross :

Size time to load load rate 3031 0 sec 8309 6 1384 bytes/sec 15084 29 520 bytes/sec 29778 239 124 bytes/sec
The bigger the file, the slower the load rate. I could not measure anything bigger than 40K, it took forever and I had to force quit.

[quote=72551:@Emile Schwarz]Axel:

Thank you for the module, I will try it this afternoon.

Your examples: I do not need to use any encoding (or will I?): I want to use UTF-8.

TextArea1.RTFValue …

you meant:

TextArea1.StyledText.RTFData …

Emile[/quote]

You can use it without encoding.

Here is a little Example with a TextArea and Open/Save Buttons

link text

it loads RTF files very quickly

Your RTF Value method is wonderful. It loads a 300K RTF file instantly :slight_smile:

Thank you.

Michel:

Thank you for your kind answer.

The tested (not created with Xojo) file size is 19,142 Bytes…
I usually manage less than 10KB files, so the speed is not an issue for me.

About RTF and encoding:

I do not use French RTF text created with TextEdit (Apple) ALSO because of the wrong encoding…

[quote=72579:@Michel Bujardet]Your RTF Value method is wonderful. It loads a 300K RTF file instantly :slight_smile:

Thank you.[/quote]

it comes from the MACOSLib
I have taken it from there and packed into the module.

Axel, Michel:

  1. Axel: you shared stuff read nicely my offending RTF file, fast, but fast (Michel)…

  2. Michel: you are right for the speed: it is fas, but fast… less than 5 seconds (in fact i do not even checked the time spend because it was fast…)

So, I decided to let Xojo deal with the offending rtf file and report the wasted time… it was 8 minutes and 6 seconds. The application was not looping forever as I was suspecting.

I will issue a bug report on the subject asap.

Thank you all.

Another option: I’ve uploaded version 1 of a module that works around the performance issues: https://forum.xojo.com/12034-rtfutils-fixes-slow-styledtext-rtfdata-performance