RTF Alignment Surprise

When I started coding with Xojo (some version from 2016), I tried to write an RTF editor for my own needs. A big problem was that paragraph alignment was not kept when writing the RTF data from the TextArea to a file – which has also been an inconclusive point of discussion in this forum –, so I had to write some clumsy workarounds.

Yesterday I started all over again to write an RTF editor (with Xojo 2017r2), and now paragraph alignments are stored while saving and restored when loading a file. Aside from using the newer Xojo version the only difference from my former code is that now – when saving a file – I write the RTF data from the TextArea to a String variable and do some adjustments (German special characters etc.) before then saving the String to a file (instead of straighforward saving the RTF data of the TextArea to the file).

So a question just out of curiosity: Have there been any changes as to how Xojo handles RTF data in newer versions, or is it just the String detour that enables the alignment to be kept (which would have been possible in earlier versions of Xojo)?

In the time it took you to write this post you probably could have tried it out :wink:

You could also check feedback (search for rtf or alignment)

I have no older version of Xojo on my computer anymore and I did not want to rewrite my whole code just for curiosity purposes (and I could not find anything related in the forum) …

@Jens Knipp - you work with Mac or Windows ?
Did you notice that the Mac Textarea behaves different from the Windows Textarea ?

I write on a Mac, but compile for Windows and MacOS. The MacOS version of my editor uses a custom Module with some declares to enhance speed when working with RTF data; the Windows version just uses Xojo’s RTFData property. Either way the files keep alignment when saved (in both Windows on my testing system and on MacOS).

@Jens Knipp - What happens if you store the RTF-string in a database and have the mac version and the windows version of you program connected. Will the RTF typed in the Mac version be displayed exactly the same in the Windows version ?
Or … to make it easy, could you text-compare the RTF of the mac-version with the RTF of the windows version ?

I will give it a try when I’m back home from work this evening…

EDIT: I just copied an RTF document (that I saved on my Mac with my editor) to a Windows machine at work and opened it with WordPad and it showed correctly with all alignments kept. (That’s all I can do at the moment…)

I did some testing, and this is what happens: When I save an RTF file on the MacOS version it opens correctly in MacOS and Windows. But when I save the same file in the Windows version, the file gets “broken” while being saved. It seems that the Windows version sets the paragraph alignment of the first paragraph for the whole document; e.g. when I center the first paragraph, all other paragraphs of the document are centered, too, when being written to the file.
I think, I will have to look into the RTF data and dig a little deeper into this, but not today anymore…

Wrong end of line (= end of paragraph) maybe?

I’ll have a look at that at the weekend, I hope.

I had a little time left and made an RTF file both on Windows and on MacOS. The file contains two lines (= paragraphs), the first one centered and the second aligned left.

The resulting RTF data on MacOS:

[code]{\rtf1\ansi\ansicpg1252\cocoartf1504\cocoasubrtf830
{\fonttbl\f0\fnil\fcharset0 HelveticaNeue;}
{\colortbl;\red255\green255\blue255;\red0\green0\blue0;}
{\*\expandedcolortbl;;\csgenericrgb\c0\c0\c0;}
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\sl288\slmult1\pardirnatural\qc

\f0\fs24 \cf2 \ulnone This is a centered paragraph.\
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\sl288\slmult1\pardirnatural
\cf2 And this one is on the left.}[/code]

And on Windows:

{\\rtf1\\ansi\\ansicpg1252{\\fonttbl{\\f0\\fnil Calibri;}}{\\colortbl\\red0\\green0\\blue0;}\\uc0 \\qc\\f0\\fs24 This is a centered paragraph.\\par And this one is on the left.}

At first sight it seems to me that the Windows version doesn’t save end of lines (or removes them while saving). Tomorrow I’ll try to insert end of lines in my RTF String before saving it to the file; maybe that’s all that has to be done…

I knew.[quote=350310:@Jens Knipp]At first sight it seems to me that the Windows version doesn’t save end of lines (or removes them while saving). Tomorrow I’ll try to insert end of lines in my RTF String before saving it to the file; maybe that’s all that has to be done…[/quote]
I am very interested in you experiences Jens. Thank you for researching this item.

I added the following line to my code before saving the RTFstring to the file:

RTFstring = RTFstring.ReplaceAll("\\par ", EndOfLine + "\\par ")

Now the Windows version aligns as expected.