aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Graphics/Font/Decoder.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-10-14 22:52:40 +0800
committerchai <chaifix@163.com>2018-10-14 22:52:40 +0800
commitb1bbc998960fff2169dc5a992c47d08723472f9b (patch)
tree220f3bd5de2266e248884e11161dd715d7632ef2 /src/libjin/Graphics/Font/Decoder.cpp
parentfbf989f9950a38566e0fb0fc5b6a7aebc9f0fb45 (diff)
*直接渲染字符串
Diffstat (limited to 'src/libjin/Graphics/Font/Decoder.cpp')
-rw-r--r--src/libjin/Graphics/Font/Decoder.cpp93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/libjin/Graphics/Font/Decoder.cpp b/src/libjin/Graphics/Font/Decoder.cpp
new file mode 100644
index 0000000..10927f0
--- /dev/null
+++ b/src/libjin/Graphics/Font/Decoder.cpp
@@ -0,0 +1,93 @@
+#include <stdlib.h>
+#include <string.h>
+#include "Decoder.h"
+
+namespace jin
+{
+namespace graphics
+{
+
+ /* utf8 byte string to unicode codepoint */
+ static const char *utf8toCodepoint(const char *p, unsigned *res) {
+ return nullptr;
+
+ }
+
+ /////////////////////////////////////////////////////////////////////////////
+ // decoders
+ /////////////////////////////////////////////////////////////////////////////
+
+ const void* Utf8::decode(const void* data, Codepoint* res) const
+ {
+ const char* p = (char*)data;
+ unsigned x, mask, shift;
+ switch (*p & 0xf0) {
+ case 0xf0: mask = 0x07; shift = 18; break;
+ case 0xe0: mask = 0x0f; shift = 12; break;
+ case 0xc0:
+ case 0xd0: mask = 0x1f; shift = 6; break;
+ default:
+ *res = *p;
+ return p + 1;
+ }
+ x = (*p & mask) << shift;
+ do {
+ if (*(++p) == '\0') {
+ *res = x;
+ return p;
+ }
+ shift -= 6;
+ x |= (*p & 0x3f) << shift;
+ } while (shift);
+ *res = x;
+ return p + 1;
+ }
+
+ const void* Utf8::next(const void* data) const
+ {
+ const char* p = (char*)data;
+ unsigned x, mask, shift;
+ switch (*p & 0xf0) {
+ case 0xf0: mask = 0x07; shift = 18; break;
+ case 0xe0: mask = 0x0f; shift = 12; break;
+ case 0xc0:
+ case 0xd0: mask = 0x1f; shift = 6; break;
+ default:
+ return p + 1;
+ }
+ x = (*p & mask) << shift;
+ do {
+ if (*(++p) == '\0') {
+ return p;
+ }
+ shift -= 6;
+ x |= (*p & 0x3f) << shift;
+ } while (shift);
+ return p + 1;
+ }
+/*
+ const void* Utf16::decode(const void* data, Codepoint* res) const
+ {
+ return nullptr;
+ }
+
+ const void* Utf16::next(const void* data) const
+ {
+ return nullptr;
+ }
+*/
+ const void* Ascii::decode(const void* data, Codepoint* res) const
+ {
+ const char* p = (char*)data;
+ *res = *p;
+ return p + 1;
+ }
+
+ const void* Ascii::next(const void* data) const
+ {
+ const char* p = (char*)data;
+ return p + 1;
+ }
+
+} // graphics
+} // jin \ No newline at end of file