aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRadAd <adamgates84+github@gmail.com>2019-05-24 14:28:04 +1000
committerRadAd <adamgates84+github@gmail.com>2019-05-24 14:28:04 +1000
commitf30df178845e2c207646c1df3d138c153ba2f373 (patch)
tree7c8c385f9e394d4e13fe6f1cf729ed9588ff2226
parentf8c69335d47536ebd4c2e695f383ddbf5e897aeb (diff)
downloadRadTerminal-f30df178845e2c207646c1df3d138c153ba2f373.tar.gz
RadTerminal-f30df178845e2c207646c1df3d138c153ba2f373.zip
better unicode drawing
-rw-r--r--RadTerminal.cpp30
1 files changed, 24 insertions, 6 deletions
diff --git a/RadTerminal.cpp b/RadTerminal.cpp
index 15f5a35..674fc22 100644
--- a/RadTerminal.cpp
+++ b/RadTerminal.cpp
@@ -193,6 +193,23 @@ void Flush(tsm_screen_draw_data* const draw)
}
}
+static size_t ucs4_to_utf16(uint32_t wc, wchar_t *wbuf)
+{
+ if (wc < 0x10000)
+ {
+ wbuf[0] = wc;
+ return 1;
+ }
+ else
+ {
+ wc -= 0x10000;
+ wbuf[0] = 0xD800 | ((wc >> 10) & 0x3FF);
+ wbuf[1] = 0xDC00 | (wc & 0x3FF);
+ return 2;
+ }
+}
+
+
int tsm_screen_draw(struct tsm_screen *con,
uint64_t id,
const uint32_t *ch,
@@ -222,14 +239,15 @@ int tsm_screen_draw(struct tsm_screen *con,
for (int i = 0; i < len; ++i)
{
uint32_t chr = ch[i];
-
+#ifdef _UNICODE
+ wchar_t buf[2];
+ size_t buflen = ucs4_to_utf16(chr, buf);
+ draw->drawbuf.append(buf, buflen);
+#else
char buf[4];
size_t buflen = tsm_ucs4_to_utf8(chr, buf);
-
- wchar_t bufw[4];
- int bufwlen = MultiByteToWideChar(CP_UTF8, 0, buf, (int) buflen, bufw, ARRAYSIZE(bufw));
-
- draw->drawbuf.append(bufw, bufwlen);
+ draw->drawbuf.append(buf, buflen);
+#endif
}
}
else