Font: Allow setting dpi internally

This fixes some unexpected changes in text rendering for OpenFL which rely on a private function in Lime. Previously we defaulted at 72 dpi, which apparently is expected to layout the text properly. Most displays are 96 dpi or higher today, so we should probably look into this. For RenderGlyph, which was previously broken over several versions, we will now use a dpi of 96 for now. In the next version of lime, we absolutely should alter the function signature to allow for renderGlyph to accept a dpi argument.
This commit is contained in:
Chris Speciale
2024-10-30 12:49:30 -04:00
parent dbfd6615c0
commit 579efa5351
5 changed files with 27 additions and 19 deletions

View File

@@ -149,7 +149,7 @@ class NativeCFFI
@: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_font_set_size(handle:Dynamic, size:Int, dpi:Int):Void;
@:cffi private static function lime_gamepad_add_mappings(mappings:Dynamic):Void;
@@ -439,7 +439,7 @@ class NativeCFFI
"lime_font_render_glyph", "oioo", false));
private static var lime_font_render_glyphs = new cpp.Callable<cpp.Object->cpp.Object->cpp.Object->cpp.Object>(cpp.Prime._loadPrime("lime",
"lime_font_render_glyphs", "oooo", false));
private static var lime_font_set_size = new cpp.Callable<cpp.Object->Int->cpp.Void>(cpp.Prime._loadPrime("lime", "lime_font_set_size", "oiv", false));
private static var lime_font_set_size = new cpp.Callable<cpp.Object->Int->Int->ccpp.Void>(cpp.Prime._loadPrime("lime", "lime_font_set_size", "oiiv", false));
private static var lime_gamepad_add_mappings = new cpp.Callable<cpp.Object->cpp.Void>(cpp.Prime._loadPrime("lime", "lime_gamepad_add_mappings", "ov",
false));
private static var lime_gamepad_get_device_guid = new cpp.Callable<Int->cpp.Object>(cpp.Prime._loadPrime("lime", "lime_gamepad_get_device_guid", "io",
@@ -672,7 +672,7 @@ class NativeCFFI
private static var lime_font_outline_decompose = CFFI.load("lime", "lime_font_outline_decompose", 2);
private static var lime_font_render_glyph = CFFI.load("lime", "lime_font_render_glyph", 3);
private static var lime_font_render_glyphs = CFFI.load("lime", "lime_font_render_glyphs", 3);
private static var lime_font_set_size = CFFI.load("lime", "lime_font_set_size", 2);
private static var lime_font_set_size = CFFI.load("lime", "lime_font_set_size", 3);
private static var lime_gamepad_add_mappings = CFFI.load("lime", "lime_gamepad_add_mappings", 1);
private static var lime_gamepad_get_device_guid = CFFI.load("lime", "lime_gamepad_get_device_guid", 1);
private static var lime_gamepad_get_device_name = CFFI.load("lime", "lime_gamepad_get_device_name", 1);
@@ -993,7 +993,7 @@ class NativeCFFI
return null;
}
@:hlNative("lime", "hl_font_set_size") private static function lime_font_set_size(handle:CFFIPointer, size:Int):Void {}
@:hlNative("lime", "hl_font_set_size") private static function lime_font_set_size(handle:CFFIPointer, size:Int, dpi:Int):Void {}
@:hlNative("lime", "hl_gamepad_add_mappings") private static function lime_gamepad_add_mappings(mappings:hl.NativeArray<String>):Void {}

View File

@@ -317,7 +317,7 @@ class Font
public function renderGlyph(glyph:Glyph, fontSize:Int):Image
{
#if (lime_cffi && !macro)
__setSize(fontSize);
__setSize(fontSize, 96);
// Allocate an estimated buffer size - adjust if necessary
var bytes:Bytes = Bytes.alloc(0); // Allocate some reasonable initial size
@@ -714,7 +714,7 @@ class Font
}
#end
@:noCompletion private function __setSize(size:Int):Void
@:noCompletion private function __setSize(size:Int, dpi:Int):Void
{
#if (lime_cffi && !macro)
NativeCFFI.lime_font_set_size(src, size);