Thanks, Norman. Yeah, what can I say? In fact the output does not match the RTF code of Apple Pages and Microsoft Word, but the RTF code of Microsoft Word is similar to the result of the function and if I embed this result in an RTF file, the emoji will load correctly in Word and Pages. Now compare the RTF output of Xojo, Word and Pages and you will see that Word outputs the string \'5f
instead of ?
. According to the RTF documentation this means an underscore.
Input: 🧛🏽♂️
-
Xojo:
\u-10178?\u-8741?\u-10180?\u-8195?\uc0\u8205 \uc0\u9794 \uc0\u-497
-
Word:
\u-10178\'5f\u-8741\'5f\u-10180\'5f\u-8195\'5f
-
Pages:
\uc0\u55358 \u56795 \u55356 \u57341 \u8205 \u9794 \u65039
What I notice about my modified function is that the output is a few characters longer than the original RTF code. Why is that?
And one more question about the syntax, what exactly happens with such a construct: (iCodePoint And 1047552)
? I have never seen that an integer is calculated with an And.
Function ToRTF(value As String) As String
Var iCharacterCount As Integer = value.Length - 1
Var sCharacter As String
Var iCodePoint As Integer
Var arsRTF() As String
Var d1, d2 As Integer
For i As Integer = 0 To iCharacterCount
sCharacter = value.Middle(i, 1)
iCodePoint = sCharacter.Asc
Select Case iCodePoint
Case 92, 123, 15
arsRTF.AddRow("\" + Encodings.UTF8.Chr(iCodePoint))
Case Is <= 127
arsRTF.AddRow(Encodings.UTF8.Chr(iCodePoint))
Case 128 To 255
arsRTF.AddRow("\'" + Hex(iCodePoint))
Case 256 To 32768
arsRTF.AddRow("\uc0\u" + iCodePoint.ToString + " ")
Case 32769 To 65535
iCodepoint = iCodepoint - 65536
arsRTF.AddRow("\uc0\u" + iCodePoint.ToString + " ")
Else
iCodePoint = iCodePoint - 65536
d1 = 55296 + (iCodePoint And 1047552) / 1024 - 65536
d2 = 56320 + (iCodePoint And 1023) - 65536
arsRTF.AddRow("\u" + d1.ToString + "?\u" + d2.ToString + "?")
End Select
Next
Return String.FromArray(arsRTF, "")
End Function