You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
RTF dictionary export fails with encoding errorΒ #1705
An encoding error occurs: Exception: creating dictionary /Users/martin/Downloads/main - Copy.rtf failed. 'charmap' codec can't encode character '\u0301' in position 24: character maps to <undefined>
The issue is with U+0301 : COMBINING ACUTE ACCENT {stress mark; Greek oxia, tonos}, as the error says, although there are other chars that cause it; the first report had the problem as \u1edf (which is from "TPA*": "phα»",)
We know that Plover encodes RTF files using code page 1252, which is the de facto standard code page that professional CAT programs use. It doesn't exactly have a facility for encoding characters outside the code page, unlike UTF-8 which uses multiple bytes.
According to the RTF 1.6 spec, Unicode characters can be encoded using UTF-16 and the \uN control word. Examples:
The character that spawned this issue report, α» U+1EDF, can be "escaped" in RTF as \u7903 (7903 = 0x1EDF).
The spec says Unicode values greater than 32767 must be expressed as negative numbers, so μ U+C18D can be escaped not as \u49549 β, but as \u-15987 (49549 β 65536).
Unicode codepoints above U+10000 can be expressed in two bytes using surrogate pairs: π U+1F60A would be treated as two bytes, U+D83D U+DE0A, which can be escaped as \u-10179\u-8694.
I don't think the Python encoder supports any of this, so it'll have to be done on Plover's end.
The RTF spec also says \uN should be followed by a fallback character β in our case I think ? should suffice for non-Unicode-supporting CAT programs.
For what it's worth, if we want to break from the RTF spec slightly for convenience, we could simply write \uN with one positive number and not have a fallback, e.g. \u128522 instead of \u-10179 ?\u-8694 ?.
The last two lines are curious though β \u128522 was rendered as U+F60A, so it looks like it just clips the numbers to below 65536, and you can see that with \u65601 (0x10041) being equivalent to A (U+0041). Not really relevant to this issue, just an interesting find.
I'm fine with the approach of using surrogate pairs but positive numbers since Mac supports it, and it's unlikely pro software would even bother supporting Unicode to this extent.
Activity
[-]RTF dictionary fails with encoding error[/-][+]RTF dictionary export fails with encoding error[/+]r-tae commentedon Mar 11, 2025
Minimal reproduction:
1705-reproduction.json
The issue is with
U+0301 : COMBINING ACUTE ACCENT {stress mark; Greek oxia, tonos}, as the error says, although there are other chars that cause it; the first report had the problem as\u1edf(which is from"TPA*": "phα»",)r-tae commentedon Mar 11, 2025
Getting rid of just those two entries makes main.json work again
sammdot commentedon Mar 11, 2025
We know that Plover encodes RTF files using code page 1252, which is the de facto standard code page that professional CAT programs use. It doesn't exactly have a facility for encoding characters outside the code page, unlike UTF-8 which uses multiple bytes.
According to the RTF 1.6 spec, Unicode characters can be encoded using UTF-16 and the
\uNcontrol word. Examples:α»U+1EDF, can be "escaped" in RTF as\u7903(7903 = 0x1EDF).μU+C18D can be escaped not as\u49549β, but as\u-15987(49549 β 65536).\u-10179\u-8694.I don't think the Python encoder supports any of this, so it'll have to be done on Plover's end.
The RTF spec also says
\uNshould be followed by a fallback character β in our case I think?should suffice for non-Unicode-supporting CAT programs.For what it's worth, if we want to break from the RTF spec slightly for convenience, we could simply write
\uNwith one positive number and not have a fallback, e.g.\u128522instead of\u-10179 ?\u-8694 ?.jthlim commentedon Mar 16, 2025
fwiw.. macOS TextEdit.app encodes rtf
δ½ ε₯½ππas:So they're using surrogate pairs, and they're not using negative numbers like the spec suggests.
sammdot commentedon Mar 16, 2025
I tested this myself, and found that it accepted both positive and negative versions, as long as you used surrogate pairs:
The last two lines are curious though β
\u128522was rendered as U+F60A, so it looks like it just clips the numbers to below 65536, and you can see that with\u65601(0x10041) being equivalent toA(U+0041). Not really relevant to this issue, just an interesting find.I'm fine with the approach of using surrogate pairs but positive numbers since Mac supports it, and it's unlikely pro software would even bother supporting Unicode to this extent.