addText to TextArea in RTF-Format

Thanks Jean-Yves! That brought me a step further. But the following still invokes the beach ball at line 7:

TextArea1.StyledText.RTFData = "{\rtf1\ansi\ansicpg1252{\fonttbl{\f0\fnil .AppleSystemUIFont;}}{\colortbl\red0\green0\blue0;}\uc0 \f0\fs26}"

for rCount=0 to 10
  TextArea1.addText("line_"+rCount.toString)
next

system.DebugLog "TextArea1 = "+TextArea1.StyledText.RTFData
system.DebugLog "TextArea1 = "+TextArea1.Text
```works, but does not output the RTF-Info

Have you set the AllowStyledText property to True on the TextArea?

Yes.

normal it outputs only plain text

17:35:24 : test Launched
17:35:26 : TextArea1 = {\rtf1\ansi\ansicpg1252{\fonttbl{\f0\fnil .AppleSystemUIFont;}}{\colortbl\red0\green0\blue0;}\uc0 \f0\fs26 line_0line_1line_2line_3line_4line_5line_6line_7line_8line_9line_10}
17:35:39 : test Ended

would like to upload a test project but itā€™s not allowed ???
so here it is in an external upload web site

works fine for me xojo 2021r21

I think I got it! First I assemble the string in a variable string, then I hand it over in one piece to TextArea1. Like you mentioned just above.

var ST as String
ST = "{\rtf1\ansi\ansicpg1252{\fonttbl{\f0\fnil .AppleSystemUIFont;}}{\colortbl\red0\green0\blue0;}\uc0 \f0\fs26"
for rCount as integer=0 to 10
  ST = ST + "Line_"+rCount
next
ST = ST+"}"
TextArea1.StyledText.RTFData = ST

The only thing now is, that in the textArea, the font size is about one letter per width of TextArea1ā€¦:slight_smile: but that is easy to fix

TextArea1.FontSize = 14

BUT! No I have a problem with the Encoding of the text in TextArea1. The EndOfLine is shown by a sign like this: ļæ½
Any ideas how to fix that?

TextArea1.StyledText.RTFData = ST.DefineEncoding(Encodings.UTF8)

gets rid of the ļæ½-signs, but no there are no line breaks at all. Tried also other encodings like MacRoman, WindowsLatin1, UTF16 and so on.

Looks like you dont even know what RTF is :neutral_face:

You cant just add a random RTF snippet and expect it to work magically

:face_with_raised_eyebrow: soā€¦ why you add RTF code to do that if it is not what you want?

Encoding? Where are you adding the RTF code to have a ā€œEndOfLineā€ ?

Why are you adding Plain text and expect to have RTFData?

ā€¦

If you are NOT adding any formating, just forget the RTFData and use PLAIN TEXT:

If you want RTF read how to use the StyledText Class to actually add something to the RTFData Property before trying to access it.

Well I try to wrap my head around it, but you are right, I am not experienced with RTF. That is also, why I am posting here.

I am saving my file as RTF for Styling and also Header information. Is that enough reason you think?

Yes it is, you must learn to use the StyledText class to do that

I donā€™t think this is a styling issue. To me it look clearly as a text encoding issue.

if the encoding is not ansiā€¦, change itā€¦

Thanks Emile. How do I check, what encoding the TextArea is? And ANSI is not an option with DefineEncodingā€¦ Maybe I am mixing here something up?

ā†’ I correct myself: TextArea1.StyledText.RTFData = ST.DefineEncoding(Encodings.WindowsANSI) does not bring the solution. Still no line break displayed.

ok, here is the solution:

TextArea1.StyledText.RTFData = "{\rtf1\ansi\ansicpg1252{\fonttbl{\f0\fnil .AppleSystemUIFont;}}{\colortbl\red0\green0\blue0;}\uc0 \f0\fs26}"

for rCount=0 to  10  
  TextArea1.addText("line_"+rCount+EndOfLine+EndOfLine)  
next

Then the encoding issue is gone. Thanks everyone for the help.

Are-you aware that your RTF document have ansi as encoding ?

Also, the code you share is incomplete; and it cannot be run.

Example of error:
Window1.PushButton1.Action, line 6
Parameter ā€œtextā€ expects type String, but this is type No Type.
TextArea1.addText(ā€œline_ā€+rCount+EndOfLine+EndOfLine)

RTF Languare Reference:

http://www.biblioscape.com/rtf15_spec.htm

Other links exists.

At last, maybe this will solve your ā€œReturnā€ problem:

https://documentation.xojo.com/api/data_types/string.html#string-replaceLineEndings

Thanks Emile.

For the record, in RTF the line ends should be marked with a backslash. So for every line end I write:

"\"+EndOfLine