RTF Copy & Paste weird behaviour

Hello everyone!
I’m new to Xojo and can’t seem to figure out a problem…

MacOS Monterey
Xojo 2022 1
Desktop

Let’s say I have a very simple TextArea (Allow Styled Text ON)
Nothing else…

With MacOS TextEdit I open an RTF file (which I attach)
and TextEdit shows it to me the way I want it.
I do a simple copy & paste in the TextArea and the text comes out identical …
So I’ll did this …
I open with a text editor (BBedit) the RTF file that gives me the following result

{\rtf1\ansi\ansicpg1252\cocoartf2638
\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fswiss\fcharset0 Helvetica;\f1\fswiss\fcharset0 Helvetica-Bold;}
{\colortbl;\red255\green255\blue255;}
{*\expandedcolortbl;;}
\paperw11900\paperh16840\margl1440\margr1440\vieww11520\viewh8400\viewkind0
\deftab708
\pard\tx284\tx2098\tqr\tx3126\tqr\tx4084\tqr\tx5217\tx5670\tqr\tx9074\tx9407\tx12028\tx13527\tx14420\tx15301\pardeftab708\ri-903\partightenfactor0

\f0\fs24 \cf0 Pena Base 0 = 06 Anni 05 Mesi 01 Giorni Pena pecuniaria 026.000,00 \'80
\

  • Aumento di 1 = 19 Anni 19 Mesi 19 Giorni Pena pecuniaria 130.333,00 '80 \
  • Diminuzione di 2 = 29 Anni 29 Mesi 29 Giorni Pena pecuniaria 230.333,00 \'80 \
  • Diminuzione di 3 = 39 Anni 39 Mesi 39 Giorni Pena pecuniaria 330.333,00 \'80 \
  • Diminuzione di 4 = 49 Anni 49 Mesi 49 Giorni Pena pecuniaria 430.333,00 \'80
    \

\f1\b Pena Finale 5 = 59 Anni 59 Mesi 59 Giorni Pena pecuniaria 530.333,00 \'80}

So I take THAT , line by line, and construct a variable whose result is:

{\rtf1\ansi\ansicpg1252\cocoartf2638
\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fswiss\fcharset0 Helvetica;\f1\fswiss\fcharset0 Helvetica-Bold;}
{\colortbl;\red255\green255\blue255;}
{*\expandedcolortbl;;}
\paperw11900\paperh16840\margl1440\margr1440\vieww11520\viewh8400\viewkind0
\deftab708
\pard\tx284\tx2098\tqr\tx3126\tqr\tx4084\tqr\tx5217\tx5670\tqr\tx9074\tx9407\tx12028\tx13527\tx14420\tx15301\pardeftab708\ri-903\partightenfactor0

\f0\fs24 \cf0 Pena Base 0 = 06 Anni 05 Mesi 01 Giorni Pena pecuniaria 026.000,00 \'80
\

  • Aumento di 1 = 19 Anni 19 Mesi 19 Giorni Pena pecuniaria 130.333,00 \'80 \
  • Diminuzione di 2 = 29 Anni 29 Mesi 29 Giorni Pena pecuniaria 230.333,00 \'80 \
  • Diminuzione di 3 = 39 Anni 39 Mesi 39 Giorni Pena pecuniaria 330.333,00 \'80 \
  • Diminuzione di 4 = 49 Anni 49 Mesi 49 Giorni Pena pecuniaria 430.333,00 \'80
    \

\f1\b Pena Finale 5 = 59 Anni 59 Mesi 59 Giorni Pena pecuniaria 530.333,00 \'80}

let’s say I call the variable “blocco” As String
(I was careful to put a chr(10) at the end of each line representing the rtf file)
At this point, considering the two identical representations of the rtf file, I assumed that the result of the paste should be identical to loading the contents of the rtf file.

TextArea(name).StyledText.RTFData = blocco

Not even in my dreams …
The last tab on the right is sent to a new line, whatever the number of TABs per line are…
the € character is not shown at all … (naturally that was a “\'80”
I also tried replacing the € character with EUR or even with an empty string.
No way.
the last tab of each line is sent to the next line.
I tried adding an extra tab to each row.
Same story …

HELP!!

I have been losing my sleep for three nights in a row…

I also thought about buying a plugin that could replace TextArea but I can’t find it.

Any suggestions from someone with more experience than me?

Thanks so much to anyone who wants to waste precious time to give me a hand …

Carlo

P.S.: I couldn’t find a way to attach my RTF file, so I beg you to trust me that it’s just a simple text, except for the TABS which are both left and right positioning… the last one per line being a right one (numbers to be represented)

All I could do is copy and paste from TextEdit, but the tabs are not well positioned in here (the last line is bold)…
Pena Base 0 = 06 Anni 05 Mesi 01 Giorni Pena pecuniaria 026.000,00 €

  • Aumento di 1 = 19 Anni 19 Mesi 19 Giorni Pena pecuniaria 130.333,00 €
  • Diminuzione di 2 = 29 Anni 29 Mesi 29 Giorni Pena pecuniaria 230.333,00 €

  • Diminuzione di 3 = 39 Anni 39 Mesi 39 Giorni Pena pecuniaria 330.333,00 €

  • Diminuzione di 4 = 49 Anni 49 Mesi 49 Giorni Pena pecuniaria 430.333,00 €

    Pena Finale 5 = 59 Anni 59 Mesi 59 Giorni Pena pecuniaria 530.333,00 €

How do you construct your variable? I’ve used rtf in the past and I stuffed everything into a constant which worked fine.

Hello Carlo,

please, read carefully the DesktopTextEdit entry of the Language Reference for what is supported and what is not in terms of styles (Bold, Italic, …) and Rules (Tabs)…

Then, you cannot compare TextEdit (from Apple) and a TextArea (Xojo): they behave differently by default.

Your text have to be created in TextArea, then yopu can paste it elsewhere and ypou certainly will get the same result (that is what I saw). The reverse is not always true.

https://documentation.xojo.com/api/user_interface/desktop/desktoptextarea.html#desktoptextarea

There are instructions to change the text selection behavior (.SelectionBold) and other ( StyledText) to access these properties “differently”. The LR explains that.

Since the euro character is not standard ascii, are you defining the encoding of the string before using it?

1 Like

\'80 does appear to be a Euro symbol in code page 1252 so my guess is that Xojo isn’t parsing the data / converting the characters correctly.

I’m basing this on the fact that there are several bugs in the RTF parser relating to the \u & ’ commands so this is probably one of them.

EDIT.
If you can perform a find & replace in the text you might have better look switching \’ sequence to the equivalent \u sequence:
\'80 in code page 1252 is \u8364

€ should be \u8364 as rtf code.
here it is '80

I created some Vars to “assemble” the RTF file as needed…

e.g.
Var RTFc10 as string=CHR(10)
Var TAB As String=chr(9)
Var RTFbegin as string="{\rtf1\ansi\ansicpg1252\cocoartf2638"+RTFc10+"\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fnil\fcharset0 HelveticaNeue;\f1\fnil\fcharset0 HelveticaNeue-Bold;}"+RTFc10
Var RTFcolor As String="{\colortbl;\red255\green255\blue255;\red0\green0\blue0;}"+RTFc10
Var RTFexpcolor As String="{*\expandedcolortbl;;\csgenericrgb\c0\c0\c0;}"+RTFc10
Var RTFpaper as string="\paperw12240\paperh15840\vieww13520\viewh11400\viewkind0"+RTFc10
That creates an rtf file which, seen with BBedit and any Hex Editor, is identical to the original RTF created by Apple’s Texedit.

That was my first choice but I couldn’t find a way to define each of the some 8 tabs per line I need.
e.g.
I need the first tab to be right at 2578 twips, the second to be left oriented at another twips value and so on.
If I could define the tab positions and orientation per each line, I’d have solved the problem.
Is there a way to define them?

'80 is the RTF standard for the euro character, that is why I used it.
I tried replacing it with \u8364 but the result is not changing. Still not visible.
whichever combination I use
Var RTFeur As String="\u8364" //“EUR” //"\'80"
I get the same result: not shown.

I get this rtf codes for your styled text.

{\rtf1\ansi\ansicpg1252{\fonttbl{\f0\fnil .AppleSystemUIFont;}}{\colortbl\red0\green0\blue0;}\uc0 \f0\fs26 Pena Base 0 = 06 Anni 05 Mesi 01 Giorni Pena pecuniaria 026.000,00 \u8364\par\par Aumento di 1 = 19 Anni 19 Mesi 19 Giorni Pena pecuniaria 130.333,00 \u8364\par Diminuzione di 2 = 29 Anni 29 Mesi 29 Giorni Pena pecuniaria 230.333,00 \u8364\par\par Diminuzione di 3 = 39 Anni 39 Mesi 39 Giorni Pena pecuniaria 330.333,00 \u8364\par\par Diminuzione di 4 = 49 Anni 49 Mesi 49 Giorni Pena pecuniaria 430.333,00 \u8364\par\par Pena Finale 5 = 59 Anni 59 Mesi 59 Giorni Pena pecuniaria 530.333,00 \u8364 }