Improve support for combining characters in TextLayout

This commit is contained in:
Joshua Granick
2017-10-09 11:20:41 -07:00
parent e991ae1205
commit aae40a4189
3 changed files with 19 additions and 5 deletions

View File

@@ -64,7 +64,7 @@ class TextLayout {
if (__buffer == null) {
__buffer = Bytes.alloc (text.length);
__buffer = Bytes.alloc (text.length * 5);
//__buffer.endian = (System.endianness == BIG_ENDIAN ? "bigEndian" : "littleEndian");
}
@@ -75,17 +75,28 @@ class TextLayout {
if (__buffer.length > 4) {
var count = __buffer.getInt32 (position); position += 4;
var index, advanceX, advanceY, offsetX, offsetY;
var codepoint, index, advanceX, advanceY, offsetX, offsetY;
var lastIndex = -1;
for (i in 0...count) {
codepoint = __buffer.getInt32 (position); position += 4;
index = __buffer.getInt32 (position); position += 4;
advanceX = __buffer.getFloat (position); position += 4;
advanceY = __buffer.getFloat (position); position += 4;
offsetX = __buffer.getFloat (position); position += 4;
offsetY = __buffer.getFloat (position); position += 4;
positions.push (new GlyphPosition (index, new Vector2 (advanceX, advanceY), new Vector2 (offsetX, offsetY)));
for (j in lastIndex + 1...index) {
// TODO: Handle differently?
positions.push (new GlyphPosition (0, new Vector2 (0, 0), new Vector2 (0, 0)));
}
positions.push (new GlyphPosition (codepoint, new Vector2 (advanceX, advanceY), new Vector2 (offsetX, offsetY)));
lastIndex = index;
}

View File

@@ -11,6 +11,7 @@ namespace lime {
typedef struct {
uint32_t codepoint;
uint32_t index;
float advanceX;
float advanceY;

View File

@@ -59,6 +59,7 @@ namespace lime {
hb_buffer_set_direction ((hb_buffer_t*)mBuffer, (hb_direction_t)mDirection);
hb_buffer_set_script ((hb_buffer_t*)mBuffer, (hb_script_t)mScript);
hb_buffer_set_language ((hb_buffer_t*)mBuffer, (hb_language_t)mLanguage);
hb_buffer_set_cluster_level ((hb_buffer_t*)mBuffer, HB_BUFFER_CLUSTER_LEVEL_CHARACTERS);
// layout the text
hb_buffer_add_utf8 ((hb_buffer_t*)mBuffer, text, strlen (text), 0, -1);
@@ -79,7 +80,7 @@ namespace lime {
int posIndex = 0;
int glyphSize = sizeof (GlyphPosition);
uint32_t dataSize = 4 + (glyph_count * glyphSize);
uint32_t dataSize = 5 + (glyph_count * glyphSize);
if (bytes->Length () < dataSize) {
@@ -102,7 +103,8 @@ namespace lime {
data = (GlyphPosition*)(bytesPosition);
data->index = glyph_info[i].codepoint;
data->codepoint = glyph_info[i].codepoint;
data->index = glyph_info[i].cluster;
data->advanceX = (float)(pos.x_advance / (float)(64));
data->advanceY = (float)(pos.y_advance / (float)64);
data->offsetX = (float)(pos.x_offset / (float)(64));