From aae40a4189bfee41d1f402f9cbf29b22369870b4 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Mon, 9 Oct 2017 11:20:41 -0700 Subject: [PATCH] Improve support for combining characters in TextLayout --- lime/text/TextLayout.hx | 17 ++++++++++++++--- project/include/text/TextLayout.h | 1 + project/src/text/TextLayout.cpp | 6 ++++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lime/text/TextLayout.hx b/lime/text/TextLayout.hx index 99376ccc5..2b00a45f8 100644 --- a/lime/text/TextLayout.hx +++ b/lime/text/TextLayout.hx @@ -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; } diff --git a/project/include/text/TextLayout.h b/project/include/text/TextLayout.h index b7320d666..8736e6495 100644 --- a/project/include/text/TextLayout.h +++ b/project/include/text/TextLayout.h @@ -11,6 +11,7 @@ namespace lime { typedef struct { + uint32_t codepoint; uint32_t index; float advanceX; float advanceY; diff --git a/project/src/text/TextLayout.cpp b/project/src/text/TextLayout.cpp index 193a99dc9..786e714b9 100644 --- a/project/src/text/TextLayout.cpp +++ b/project/src/text/TextLayout.cpp @@ -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));