aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-09-13 21:32:49 +0800
committerchai <chaifix@163.com>2018-09-13 21:32:49 +0800
commit2250248b97d31c15f3f4c0381bff8d52e88a8c9e (patch)
tree23d45a8782ca38201ed1929495d98d0575537ba6
parente85fcaf2c40da42c5949f8dbeae8db1053251732 (diff)
*update
-rw-r--r--libjin/Graphics/Font.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/libjin/Graphics/Font.cpp b/libjin/Graphics/Font.cpp
index ec4f7fb..9b7d45b 100644
--- a/libjin/Graphics/Font.cpp
+++ b/libjin/Graphics/Font.cpp
@@ -1,4 +1,4 @@
-#include "../jin_configuration.h"
+#include "../jin_configuration.h"
#if LIBJIN_MODULES_RENDER
#include "font.h"
@@ -17,6 +17,14 @@ namespace graphics
const int Font::TEXTURE_WIDTHS[] = { 128, 256, 256, 512, 512, 1024, 1024 };
const int Font::TEXTURE_HEIGHTS[] = { 128, 128, 256, 256, 512, 512, 1024 };
+
+ /**
+ * 每个10开头的字节都只有6位有效,11开头的表明是code units的开头
+ * 0000 0000-0000 007F | 0xxx xxxx 7
+ * 0000 0080-0000 07FF | 110x xxxx 10xxxxxx 5 + 6
+ * 0000 0800-0000 FFFF | 1110 xxxx 10xxxxxx 10xxxxxx 4 + 6*2
+ * 0001 0000-0010 FFFF | 1111 0xxx 10xxxxxx 10xxxxxx 10xxxxxx 3 + 6*3
+ */
/* https://www.zhihu.com/question/23374078 */
/* https://blog.csdn.net/carrie0728/article/details/17286043 */
/* https://wenku.baidu.com/view/a6fddd07bed5b9f3f90f1ceb.html */
@@ -24,12 +32,15 @@ namespace graphics
/* utf8 to unicode */
static const char *ttf_utf8toCodepoint(const char *p, unsigned *res) {
unsigned x, mask, shift;
+ /* 处理code units的第一个字节 */
switch (*p & 0xf0) { // 1111 0000
case 0xf0 /*1111 0000*/ : mask = 0x07 /*0111*/; shift = 18; break;
case 0xe0 /*1110 0000*/: mask = 0x0f /*1111*/; shift = 12; break;
+ /* 110x */
case 0xc0 /*1100 0000*/:
case 0xd0 /*1101 0000*/: mask = 0x1f /*0001 1111*/; shift = 6; break;
default:
+ /* 0xxx */
*res = *p;
return p + 1;
}
@@ -41,7 +52,7 @@ namespace graphics
return p;
}
shift -= 6;
- x |= (*p & 0x3f) << shift;
+ x |= (*p & 0x3f) /*‭0011 1111*/<< shift;
} while (shift);
*res = x;
return p + 1;
@@ -110,7 +121,7 @@ namespace graphics
}
/**
- * unicodeȾļtextureϣglyphs
+ * 根据unicode渲染字体文件到texture上,并更新glyphs
*/
Glyph* Font::addGlyph(unsigned int character)
{