diff --git a/project/include/graphics/Font.h b/project/include/graphics/Font.h index 28c710001..36e2932d2 100644 --- a/project/include/graphics/Font.h +++ b/project/include/graphics/Font.h @@ -57,6 +57,7 @@ namespace lime { void LoadRange (unsigned long start, unsigned long end); value RenderToImage (ImageBuffer *image); void SetSize (size_t size); + bool InsertCodepointFromIndex (unsigned long codepoint); #ifdef LIME_FREETYPE FT_Face face; @@ -67,6 +68,7 @@ namespace lime { private: bool InsertCodepoint (unsigned long codepoint); + bool InsertCodepoint (unsigned long codepoint, bool b); std::list glyphList; size_t mSize; diff --git a/project/src/graphics/Font.cpp b/project/src/graphics/Font.cpp index 800e6b469..04d64fa92 100644 --- a/project/src/graphics/Font.cpp +++ b/project/src/graphics/Font.cpp @@ -529,7 +529,15 @@ namespace lime { } + bool Font::InsertCodepointFromIndex (unsigned long codepoint) { + return InsertCodepoint(codepoint, false); + } + bool Font::InsertCodepoint (unsigned long codepoint) { + return InsertCodepoint(codepoint, true); + } + + bool Font::InsertCodepoint (unsigned long codepoint, bool b) { GlyphInfo info; info.codepoint = codepoint; @@ -543,8 +551,12 @@ namespace lime { // if (codepoint < (*first).codepoint || // (codepoint == (*first).codepoint && mSize != (*first).size)) { - info.index = FT_Get_Char_Index (face, codepoint); + if (b) { + info.index = FT_Get_Char_Index (face, codepoint); + } else { + info.index = codepoint; + } if (FT_Load_Glyph (face, info.index, FT_LOAD_DEFAULT) != 0) return false; info.height = face->glyph->metrics.height; diff --git a/project/src/graphics/Text.cpp b/project/src/graphics/Text.cpp index 8cbb1dfe7..fb73b6081 100644 --- a/project/src/graphics/Text.cpp +++ b/project/src/graphics/Text.cpp @@ -11,7 +11,8 @@ namespace lime { if (strlen(script) != 4) return; - hb_script_t tag = (hb_script_t)HB_TAG (script[0], script[1], script[2], script[3]); + //hb_script_t tag = (hb_script_t)HB_TAG (script[0], script[1], script[2], script[3]); + hb_script_t tag = hb_script_from_string (script, -1); buffer = hb_buffer_create (); hb_buffer_set_direction (buffer, (hb_direction_t)direction); @@ -48,6 +49,7 @@ namespace lime { for (int i = 0; i < glyph_count; i++) { + font->InsertCodepointFromIndex(glyph_info[i].codepoint); hb_glyph_position_t pos = glyph_pos[i]; value obj = alloc_empty_object (); diff --git a/samples/TextRendering/Source/Main.hx b/samples/TextRendering/Source/Main.hx index 7db5bf40e..dec5b65d4 100644 --- a/samples/TextRendering/Source/Main.hx +++ b/samples/TextRendering/Source/Main.hx @@ -18,10 +18,11 @@ class TextField { private var size:Int; private var text:String; private var image:ImageBuffer; - + private var points:Array; public function new (text:String, size:Int, textFormat:TextFormat, font:Font, context:RenderContext, x:Float=0, y:Float=0) { + points = textFormat.fromString (font, size, text); font.loadGlyphs (size, text); image = font.createImage (); this.text = text; @@ -34,8 +35,6 @@ class TextField { public function init (context:RenderContext, textFormat:TextFormat, font:Font, x:Float, y:Float) { - var points = textFormat.fromString (font, size, text); - switch (context) { // case CANVAS (context): @@ -202,20 +201,20 @@ class Main extends Application { public override function init (context:RenderContext):Void { - textFields.push(new TextField ("صِف خَلقَ خَودِ كَمِثلِ الشَمسِ إِذ بَزَغَت — يَحظى الضَجيعُ بِها نَجلاءَ مِعطارِ", 24, + textFields.push(new TextField ("صِف خَلقَ خَودِ كَمِثلِ الشَمسِ إِذ بَزَغَت — يَحظى الضَجيعُ بِها نَجلاءَ مِعطارِ", 16, new TextFormat (RightToLeft, ScriptArabic, "ar"), - new Font ("assets/amiri-regular.ttf"), - context, window.width - 20, 100)); + Font.fromFile ("assets/amiri-regular.ttf"), + context, window.width, 80)); textFields.push(new TextField ("The quick brown fox jumps over the lazy dog.", 16, new TextFormat (LeftToRight, ScriptLatin, "en"), - new Font ("assets/amiri-regular.ttf"), + Font.fromFile ("assets/amiri-regular.ttf"), context, 20, 20)); textFields.push(new TextField ("懶惰的姜貓", 32, new TextFormat (TopToBottom, ScriptHan, "zh"), - new Font ("assets/fireflysung.ttf"), - context, 50, 150)); + Font.fromFile ("assets/fireflysung.ttf"), + context, 50, 170)); switch (context) {