I am developing a desktop app. I want the user to type text into a textarea and use bold, colour, etc. I then store this in a blob in a SQLite database and retrieve it again into a textarea. The retrieved text shows for example, endofline, as a special character, and not a physical carriage return. Other features are also lost.
How can I collect styled text in a textarea, store it in my database, and retrieve it with its ‘style’ intact?
In this particular case, base64 isn’t necessary. By definition, RTF uses only ASCII values of < 128, there are no special characters. And whitespace characters, like Return or Tab, are designated by control words.
If my memory is correct, the above sentence is true and false: false because non ASCII characters are translated to code, true because they are nor removed but coded.
From the RTF Version 1.5 Specification (the last I’m aware of): “An RTF file consists of unformatted text, control words, control symbols, and groups. For ease of transport, a standard RTF file can consist of only 7-bit ASCII characters.”
All characters above ASCII 127 are converted to control words or control symbols, which contain only ASCII.
it is still a good practice to encode base64 something we don’t exactly know the real content…
are we sure that ALL special characters are correctly rtf encoded by xojo rtf parser ?
as example : https://tracker.xojo.com/xojoinc/xojo/-/issues/76848
anyway, I still find that rtf is badly supported today by xojo methods
you’ve better use html to store styled text in a database
and use this class to edit them just like styledtext does.
FWIW, I use RTF extensively, and it’s a waste of CPU time and storage space to base64-encode the ASCII. Second, I never use Xojo RTFData, which is slow beyond belief. I use RTFDataMBS (I only code for Mac, I don’t know about other platforms), but I presume it can also be done with declares. Finally, NSTextArea (API1) and DesktopTextArea (API2), which I use to render the RTF, are actually a native macOS control, NSTextView, and can render pretty much anything TextEdit can. I’ve used RTF to render tables, native bullet lists, super/subscript, and more. RTF is far more powerful than the very limited options provided by StyledText.
In your original post, probably people with a CS degree wwill understand corerctly what you wrote. But this forum reader do not necessary is / are in this position as far as I understand. Some may understand it differently. That is why I chimed in.
Now, if this forum is reserved to members of the CS group, tell it, please.
Your chiming in that there are no “special” characters in RTF is “false because non ASCII characters are translated to code” was confusing and, as Michael Hussman alluded, missed the context and the point. I don’t think you need as CS degree to understand what ASCII 127 means, but you can look it up. I have nothing more to add.
Like Markus said: The Textarea’s StyledText property gives you a StyledText object which has an RTFData property returning a string in RTF format that you can store in a database field.
You have plans to make your application cross-platform, web / desktop / win / mac etc… then RTF is a total no-go.
Use HTML / JSON. I wrote the RTEdit class, and when we expanded the app from Xojo Desktop that used a SupaBase backend, to Web (http://www.eldr.is), using React and the same backend and Supabase API / Edge functions etc., there was no adjustment needed.