RTF Unicode Conversion

Base 10 vs Base 16… ok… I’ll buy that… I was just going by what Norman said should work, vs what I found did work.

Font Fallback… has nothing to do with XOJO…at least not in this context. once an RTF document is created, its up to the display engine of what ever app (TextEdit, Word etc), and the example I place above DOES render a smiley. Now the smiley in OSX is a pretty yellow Emoji, while the one is WORD is “black and white”, but the point is it was defined by the unicode values (\u), not the selected font (\F)… just indicating that the display agent is smart enough to know what to do

Kevin’s sample code is a bit unsafe by checking the length of UTF8-encoded strings. The safe way is to FIRST convert to UTF-16, then check if the entire string’s Length (which is the number of chars) equals the number of bytes times two, like this:

dim s = "abc" s = s.ConvertEncoding (Encodings.UTF16) if s.Len * 2 = s.Lenb then ' all chars are fit into utf-16 values else ' one or more chars need two 16 bit values - now go into detail end

With the if clause, a quick check can be done before going into time-consuming char-by-char checking.

Disclaimer: That’s what I believe how it would work. I have no actually tested this. But I remember having done something similar a few years ago :slight_smile:

[quote=257852:@Thomas Tempelmann]Kevin’s sample code is a bit unsafe by checking the length of UTF8-encoded strings. The safe way is to FIRST convert to UTF-16, then check if the entire string’s Length (which is the number of chars) equals the number of bytes times two, like this:

dim s = "abc" s = s.ConvertEncoding (Encodings.UTF16) if s.Len * 2 = s.Lenb then ' all chars are fit into utf-16 values else ' one or more chars need two 16 bit values - now go into detail end

With the if clause, a quick check can be done before going into time-consuming char-by-char checking.

Disclaimer: That’s what I believe how it would work. I have no actually tested this. But I remember having done something similar a few years ago :)[/quote]

Hi Thomas

You could be right. I knocked that tweak up in about 10 minutes when I realised my original code didn’t handle surrogate pairs.

Kev

The inconvenient about relying on font fallback lies precisely here. If you actually count on a color emoji, you better code for it. Otherwise as I said, the system or the app fetches the first one it finds that contains the Unicode glyph.

Since color emoji exists on Mac only, though, in a cross platform environment, better use a monochrome font.

I agree with you it has little to nothing to do with Xojo.

[quote=257892:@Michel Bujardet]The inconvenient about relying on font fallback lies precisely here. If you actually count on a color emoji, you better code for it. Otherwise as I said, the system or the app fetches the first one it finds that contains the Unicode glyph.

Since color emoji exists on Mac only, though, in a cross platform environment, better use a monochrome font.

I agree with you it has little to nothing to do with Xojo.[/quote]

I wasn’t actually trying to say that Font Fallback had anything to do with Xojo. I was simply explaining the concepts and included how it also affects Xojo since this is, after all, a Xojo forum. Apologies if that caused any kind of confusion.

No need for apologies. It does affect Xojo as any other app. But as it is transparent, there is simply in principle no need to worry about it.