From 6af853b002be9981b739ed07895fa65e7e5c7577 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Thu, 1 Nov 2018 10:17:52 -0700 Subject: [PATCH] Resolve issues in Font.renderGlyph(s) --- project/src/ExternalInterface.cpp | 47 ++++++++++++------- .../_internal/backend/native/NativeCFFI.hx | 12 ++--- src/lime/text/Font.hx | 6 ++- 3 files changed, 41 insertions(+), 24 deletions(-) diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp index 1ab94b197..91592cca2 100644 --- a/project/src/ExternalInterface.cpp +++ b/project/src/ExternalInterface.cpp @@ -1454,51 +1454,66 @@ namespace lime { } - bool lime_font_render_glyph (value fontHandle, int index, value data) { + value lime_font_render_glyph (value fontHandle, int index, value data) { #ifdef LIME_FREETYPE Font *font = (Font*)val_data (fontHandle); Bytes bytes (data); - return font->RenderGlyph (index, &bytes); - #else - return false; + + if (font->RenderGlyph (index, &bytes)) { + + return bytes.Value (data); + + } #endif + return alloc_null (); + } - HL_PRIM bool hl_lime_font_render_glyph (HL_CFFIPointer* fontHandle, int index, Bytes* data) { + HL_PRIM Bytes* hl_lime_font_render_glyph (HL_CFFIPointer* fontHandle, int index, Bytes* data) { #ifdef LIME_FREETYPE Font *font = (Font*)fontHandle->ptr; - return font->RenderGlyph (index, data); - #else - return false; + + if (font->RenderGlyph (index, data)) { + + return data; + + } #endif + return NULL; + } - bool lime_font_render_glyphs (value fontHandle, value indices, value data) { + value lime_font_render_glyphs (value fontHandle, value indices, value data) { #ifdef LIME_FREETYPE Font *font = (Font*)val_data (fontHandle); Bytes bytes (data); - return font->RenderGlyphs (indices, &bytes); - #else - return false; + + if (font->RenderGlyphs (indices, &bytes)) { + + return bytes.Value (data); + + } #endif + return alloc_null (); + } - HL_PRIM bool hl_lime_font_render_glyphs (HL_CFFIPointer* fontHandle, hl_varray* indices, Bytes* data) { + HL_PRIM Bytes* hl_lime_font_render_glyphs (HL_CFFIPointer* fontHandle, hl_varray* indices, Bytes* data) { // #ifdef LIME_FREETYPE // Font *font = (Font*)fontHandle->ptr; // return font->RenderGlyphs (indices, &bytes); // #else - return false; + return NULL; // #endif } @@ -3983,8 +3998,8 @@ namespace lime { DEFINE_HL_PRIM (_TCFFIPOINTER, lime_font_load_bytes, _TBYTES); DEFINE_HL_PRIM (_TCFFIPOINTER, lime_font_load_file, _STRING); DEFINE_HL_PRIM (_DYN, lime_font_outline_decompose, _TCFFIPOINTER _I32); - DEFINE_HL_PRIM (_BOOL, lime_font_render_glyph, _TCFFIPOINTER _I32 _TBYTES); - DEFINE_HL_PRIM (_BOOL, lime_font_render_glyphs, _TCFFIPOINTER _ARR _TBYTES); + DEFINE_HL_PRIM (_TBYTES, lime_font_render_glyph, _TCFFIPOINTER _I32 _TBYTES); + DEFINE_HL_PRIM (_TBYTES, lime_font_render_glyphs, _TCFFIPOINTER _ARR _TBYTES); DEFINE_HL_PRIM (_VOID, lime_font_set_size, _TCFFIPOINTER _I32); DEFINE_HL_PRIM (_VOID, lime_gamepad_add_mappings, _ARR); DEFINE_HL_PRIM (_VOID, lime_gamepad_event_manager_register, _FUN(_VOID, _NO_ARG) _TGAMEPAD_EVENT); diff --git a/src/lime/_internal/backend/native/NativeCFFI.hx b/src/lime/_internal/backend/native/NativeCFFI.hx index 2933c5979..cfe2dc120 100644 --- a/src/lime/_internal/backend/native/NativeCFFI.hx +++ b/src/lime/_internal/backend/native/NativeCFFI.hx @@ -111,8 +111,8 @@ class NativeCFFI { @:cffi private static function lime_font_load_bytes (data:Dynamic):Dynamic; @:cffi private static function lime_font_load_file (path:Dynamic):Dynamic; @:cffi private static function lime_font_outline_decompose (handle:Dynamic, size:Int):Dynamic; - @:cffi private static function lime_font_render_glyph (handle:Dynamic, index:Int, data:Dynamic):Bool; - @:cffi private static function lime_font_render_glyphs (handle:Dynamic, indices:Dynamic, data:Dynamic):Bool; + @:cffi private static function lime_font_render_glyph (handle:Dynamic, index:Int, data:Dynamic):Dynamic; + @:cffi private static function lime_font_render_glyphs (handle:Dynamic, indices:Dynamic, data:Dynamic):Dynamic; @:cffi private static function lime_font_set_size (handle:Dynamic, size:Int):Void; @:cffi private static function lime_gamepad_add_mappings (mappings:Dynamic):Void; @:cffi private static function lime_gamepad_get_device_guid (id:Int):Dynamic; @@ -258,8 +258,8 @@ class NativeCFFI { private static var lime_font_load_bytes = new cpp.Callablecpp.Object> (cpp.Prime._loadPrime ("lime", "lime_font_load_bytes", "oo", false)); private static var lime_font_load_file = new cpp.Callablecpp.Object> (cpp.Prime._loadPrime ("lime", "lime_font_load_file", "oo", false)); private static var lime_font_outline_decompose = new cpp.CallableInt->cpp.Object> (cpp.Prime._loadPrime ("lime", "lime_font_outline_decompose", "oio", false)); - private static var lime_font_render_glyph = new cpp.CallableInt->cpp.Object->Bool> (cpp.Prime._loadPrime ("lime", "lime_font_render_glyph", "oiob", false)); - private static var lime_font_render_glyphs = new cpp.Callablecpp.Object->cpp.Object->Bool> (cpp.Prime._loadPrime ("lime", "lime_font_render_glyphs", "ooob", false)); + private static var lime_font_render_glyph = new cpp.CallableInt->cpp.Object->cpp.Object> (cpp.Prime._loadPrime ("lime", "lime_font_render_glyph", "oioo", false)); + private static var lime_font_render_glyphs = new cpp.Callablecpp.Object->cpp.Object->cpp.Object> (cpp.Prime._loadPrime ("lime", "lime_font_render_glyphs", "oooo", false)); private static var lime_font_set_size = new cpp.CallableInt->cpp.Void> (cpp.Prime._loadPrime ("lime", "lime_font_set_size", "oiv", false)); private static var lime_gamepad_add_mappings = new cpp.Callablecpp.Void> (cpp.Prime._loadPrime ("lime", "lime_gamepad_add_mappings", "ov", false)); private static var lime_gamepad_get_device_guid = new cpp.Callablecpp.Object> (cpp.Prime._loadPrime ("lime", "lime_gamepad_get_device_guid", "io", false)); @@ -557,8 +557,8 @@ class NativeCFFI { @:hlNative("lime", "lime_font_load_bytes") private static function lime_font_load_bytes (data:Bytes):CFFIPointer { return null; } @:hlNative("lime", "lime_font_load_file") private static function lime_font_load_file (path:String):CFFIPointer { return null; } @:hlNative("lime", "lime_font_outline_decompose") private static function lime_font_outline_decompose (handle:CFFIPointer, size:Int):Dynamic { return null; } - @:hlNative("lime", "lime_font_render_glyph") private static function lime_font_render_glyph (handle:CFFIPointer, index:Int, data:Bytes):Bool { return false; } - @:hlNative("lime", "lime_font_render_glyphs") private static function lime_font_render_glyphs (handle:CFFIPointer, indices:hl.NativeArray, data:Bytes):Bool { return false; } + @:hlNative("lime", "lime_font_render_glyph") private static function lime_font_render_glyph (handle:CFFIPointer, index:Int, data:Bytes):Bytes { return null; } + @:hlNative("lime", "lime_font_render_glyphs") private static function lime_font_render_glyphs (handle:CFFIPointer, indices:hl.NativeArray, data:Bytes):Bytes { return null; } @:hlNative("lime", "lime_font_set_size") private static function lime_font_set_size (handle:CFFIPointer, size:Int):Void {} @:hlNative("lime", "lime_gamepad_add_mappings") private static function lime_gamepad_add_mappings (mappings:hl.NativeArray):Void {} @:hlNative("lime", "lime_gamepad_get_device_guid") private static function lime_gamepad_get_device_guid (id:Int):hl.Bytes { return null; } diff --git a/src/lime/text/Font.hx b/src/lime/text/Font.hx index 5b5a60113..2c1ac7350 100644 --- a/src/lime/text/Font.hx +++ b/src/lime/text/Font.hx @@ -235,8 +235,9 @@ class Font { //bytes.endian = (System.endianness == BIG_ENDIAN ? "bigEndian" : "littleEndian"); var dataPosition = 0; + bytes = NativeCFFI.lime_font_render_glyph (src, glyph, bytes); - if (NativeCFFI.lime_font_render_glyph (src, glyph, bytes)) { + if (bytes != null && bytes.length > 0) { var index = bytes.getInt32 (dataPosition); dataPosition += 4; var width = bytes.getInt32 (dataPosition); dataPosition += 4; @@ -298,8 +299,9 @@ class Font { NativeCFFI.lime_font_set_size (src, fontSize); var bytes = Bytes.alloc (0); + bytes = NativeCFFI.lime_font_render_glyphs (src, glyphList, bytes); - if (NativeCFFI.lime_font_render_glyphs (src, glyphList, bytes)) { + if (bytes != null && bytes.length > 0) { var bytesPosition = 0; var count = bytes.getInt32 (bytesPosition); bytesPosition += 4;