Saving and Loading Files using UTF8 encoding Not working as expected

I’m trying to save files using UTF8 encoding so I can have various fonts, emojis, etc. in the file. This is very basic code with no try catch or anything else fancy at this point (that will come when I get the basics working). It does save and load the text just fine but all special attributes such as fonts or special characters such as emojis are lost. My searches so far have not found an answer. I know this can be done as I’ve seen it in a video, but the example code in the video is having the same issue.

Here’s my two code segments I have stored in Methods.

'Write text area to file
Var f As FolderItem
f = SpecialFolder.Documents
Var t As TextOutputStream
f=f.child("mydata").child("textiles").child("scratchpad.txt")
If f <> Nil Then
  t = TextOutputStream.Create(f)
  t.Encoding = Encodings.UTF8
  t.write(txt_scratchpad.text)
  t.Close
End If
'Read text file and display in text area
Var f As FolderItem
f = SpecialFolder.Documents
Var t As TextInputStream
f=f.child("mydata").child("textiles").child("scratchpad.txt")
If f <> Nil Then
  t = TextInputStream.Open(f)
  t.Encoding = Encodings.UTF8
  txt_scratchpad.text = t.ReadAll
  t.Close
End If

What do you mean by “fonts”? Can you post a sample of the text you are saving?

Basically, I’ve seen an example of the simple text editor written in XoJo that you could highlight text, change fonts, bold, etc. as well as do things like emojis in the document. This was all using a TextArea control. When I try to duplicate what I’ve seen, it just saves and loads straight text.

Here’s the text in the TextArea just before I save.

Screen Shot 2022-01-09 at 11.24.42 AM

Im afraid you’ve misunderstood the purpose behind text encodings like UTF-8. I gave a presentation at XDC that might help, but the short version is, the encoding tells your app how to interpret the bytes within a string as human-readable text. It has nothing to do with formatting like fonts, sizes, bolding, and the like.

What you likely want is the RTF data, accessed through the StyledText property.

Kem,

I don’t doubt what you are saying at all. I’m still trying to figure this out. The example I did see in a Video about XoJo doing this did not use the RTF Data an it worked just fine. There was no mention of RTF. When I try to use that in a test, I get all the formatting characters loading the file back in.

I may need to go back, watch the video and try to duplicate everything exactly in a test project and see what happens.

This article:

has a good description of UTF8 and its relationship to Unicode. UTF8 stores characters, but not information such as fonts, styles, or character decoration (bold, underline, etc). That is all done separately (on a web page, in CSS, typically).

I’m working with a desktop app so the web stuff isn’t what I’m looking for. I did get the RTF working though. Only thing now, which isn’t a big deal is that my RTF Stuff doesn’t like emojis, they show up as ???. Probably by design. Not a show stopper.

That may be a text encoding issue.

Do you have a link to this video?

As you know, rtf is not mandatory nor the only way to save / load styled texts.

I think MS Word do not use rtf anymore (unsure)…