Implement HB getGlyphInfo and position, add buffer.clusterLevel
This commit is contained in:
@@ -130,6 +130,13 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
int lime_hb_buffer_get_cluster_level (value buffer) {
|
||||
|
||||
return hb_buffer_get_cluster_level ((hb_buffer_t*)val_data (buffer));
|
||||
|
||||
}
|
||||
|
||||
|
||||
int lime_hb_buffer_get_content_type (value buffer) {
|
||||
|
||||
return hb_buffer_get_content_type ((hb_buffer_t*)val_data (buffer));
|
||||
@@ -159,26 +166,84 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_hb_buffer_get_glyph_infos (value buffer) {
|
||||
struct HBGlyphInfo {
|
||||
|
||||
// TODO: Write into byte buffer instead array?
|
||||
int codepoint;
|
||||
int mask;
|
||||
int cluster;
|
||||
|
||||
value result = alloc_array (0);
|
||||
return result;
|
||||
//unsigned int length = 0;
|
||||
//hb_glyph_info_t* info = hb_buffer_get_glyph_infos ((hb_buffer_t*)val_data (buffer), &length);
|
||||
//return CFFIPointer (info);
|
||||
};
|
||||
|
||||
|
||||
value lime_hb_buffer_get_glyph_infos (value buffer, value bytes) {
|
||||
|
||||
unsigned int length = 0;
|
||||
hb_glyph_info_t* info = hb_buffer_get_glyph_infos ((hb_buffer_t*)val_data (buffer), &length);
|
||||
|
||||
if (length > 0) {
|
||||
|
||||
Bytes _bytes = Bytes (bytes);
|
||||
_bytes.Resize (length * sizeof (HBGlyphInfo));
|
||||
|
||||
HBGlyphInfo* glyphInfo = (HBGlyphInfo*)_bytes.b;
|
||||
|
||||
for (int i = 0; i < length; i++, info++, glyphInfo++) {
|
||||
|
||||
glyphInfo->codepoint = info->codepoint;
|
||||
glyphInfo->mask = info->mask;
|
||||
glyphInfo->cluster = info->cluster;
|
||||
|
||||
}
|
||||
|
||||
return _bytes.Value (bytes);
|
||||
|
||||
} else {
|
||||
|
||||
return alloc_null ();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
value lime_hb_buffer_get_glyph_positions (value buffer) {
|
||||
struct HBGlyphPosition {
|
||||
|
||||
value result = alloc_array (0);
|
||||
return result;
|
||||
//unsigned int length = 0;
|
||||
//hb_glyph_position_t* positions = hb_buffer_get_glyph_positions ((hb_buffer_t*)val_data (buffer), &length);
|
||||
//return CFFIPointer (positions);
|
||||
int xAdvance;
|
||||
int yAdvance;
|
||||
int xOffset;
|
||||
int yOffset;
|
||||
|
||||
};
|
||||
|
||||
|
||||
value lime_hb_buffer_get_glyph_positions (value buffer, value bytes) {
|
||||
|
||||
unsigned int length = 0;
|
||||
hb_glyph_position_t* positions = hb_buffer_get_glyph_positions ((hb_buffer_t*)val_data (buffer), &length);
|
||||
|
||||
if (length > 0) {
|
||||
|
||||
Bytes _bytes = Bytes (bytes);
|
||||
_bytes.Resize (length * sizeof (HBGlyphPosition));
|
||||
|
||||
HBGlyphPosition* glyphPosition = (HBGlyphPosition*)_bytes.b;
|
||||
|
||||
for (int i = 0; i < length; i++, positions++, glyphPosition++) {
|
||||
|
||||
glyphPosition->xAdvance = positions->x_advance;
|
||||
glyphPosition->yAdvance = positions->y_advance;
|
||||
glyphPosition->xOffset = positions->x_offset;
|
||||
glyphPosition->yOffset = positions->y_offset;
|
||||
|
||||
}
|
||||
|
||||
return _bytes.Value (bytes);
|
||||
|
||||
} else {
|
||||
|
||||
return alloc_null ();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -304,6 +369,13 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
void lime_hb_buffer_set_cluster_level (value buffer, int clusterLevel) {
|
||||
|
||||
hb_buffer_set_cluster_level ((hb_buffer_t*)val_data (buffer), (hb_buffer_cluster_level_t)clusterLevel);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void lime_hb_buffer_set_content_type (value buffer, int contentType) {
|
||||
|
||||
hb_buffer_set_content_type ((hb_buffer_t*)val_data (buffer), (hb_buffer_content_type_t)contentType);
|
||||
@@ -348,6 +420,10 @@ namespace lime {
|
||||
|
||||
void lime_hb_buffer_set_script (value buffer, int script) {
|
||||
|
||||
script = HB_SCRIPT_COMMON;
|
||||
|
||||
// TODO: COMMON is an int32 and doesn't translate properly on Neko
|
||||
|
||||
hb_buffer_set_script ((hb_buffer_t*)val_data (buffer), (hb_script_t)script);
|
||||
|
||||
}
|
||||
@@ -639,6 +715,15 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_hb_ft_font_create (value font) {
|
||||
|
||||
Font* _font = (Font*)val_data (font);
|
||||
hb_font_t* __font = hb_ft_font_create ((FT_Face)_font->face, NULL);
|
||||
return CFFIPointer (__font);
|
||||
|
||||
}
|
||||
|
||||
|
||||
value lime_hb_ft_font_create_referenced (value font) {
|
||||
|
||||
Font* _font = (Font*)val_data (font);
|
||||
@@ -881,9 +966,8 @@ namespace lime {
|
||||
|
||||
void lime_hb_shape (value font, value buffer, value features) {
|
||||
|
||||
int length = val_array_size (features);
|
||||
double* _features = val_array_double (features);
|
||||
|
||||
int length = !val_is_null (features) ? val_array_size (features) : 0;
|
||||
double* _features = !val_is_null (features) ? val_array_double (features) : NULL;
|
||||
hb_shape ((hb_font_t*)val_data (font), (hb_buffer_t*)val_data (buffer), (const hb_feature_t*)(uintptr_t*)_features, length);
|
||||
|
||||
}
|
||||
@@ -941,12 +1025,13 @@ namespace lime {
|
||||
DEFINE_PRIME1 (lime_hb_buffer_allocation_successful);
|
||||
DEFINE_PRIME1v (lime_hb_buffer_clear_contents);
|
||||
DEFINE_PRIME0 (lime_hb_buffer_create);
|
||||
DEFINE_PRIME1 (lime_hb_buffer_get_cluster_level);
|
||||
DEFINE_PRIME1 (lime_hb_buffer_get_content_type);
|
||||
DEFINE_PRIME1 (lime_hb_buffer_get_direction);
|
||||
DEFINE_PRIME0 (lime_hb_buffer_get_empty);
|
||||
DEFINE_PRIME1 (lime_hb_buffer_get_flags);
|
||||
DEFINE_PRIME1 (lime_hb_buffer_get_glyph_infos);
|
||||
DEFINE_PRIME1 (lime_hb_buffer_get_glyph_positions);
|
||||
DEFINE_PRIME2 (lime_hb_buffer_get_glyph_infos);
|
||||
DEFINE_PRIME2 (lime_hb_buffer_get_glyph_positions);
|
||||
DEFINE_PRIME1 (lime_hb_buffer_get_length);
|
||||
DEFINE_PRIME1 (lime_hb_buffer_get_replacement_codepoint);
|
||||
DEFINE_PRIME1 (lime_hb_buffer_get_script);
|
||||
@@ -961,6 +1046,7 @@ namespace lime {
|
||||
DEFINE_PRIME1 (lime_hb_buffer_serialize_format_from_string);
|
||||
DEFINE_PRIME1 (lime_hb_buffer_serialize_format_to_string);
|
||||
DEFINE_PRIME0 (lime_hb_buffer_serialize_list_formats);
|
||||
DEFINE_PRIME2v (lime_hb_buffer_set_cluster_level);
|
||||
DEFINE_PRIME2v (lime_hb_buffer_set_content_type);
|
||||
DEFINE_PRIME2v (lime_hb_buffer_set_direction);
|
||||
DEFINE_PRIME2v (lime_hb_buffer_set_flags);
|
||||
@@ -1001,6 +1087,7 @@ namespace lime {
|
||||
DEFINE_PRIME3v (lime_hb_font_set_ppem);
|
||||
DEFINE_PRIME3v (lime_hb_font_set_scale);
|
||||
DEFINE_PRIME5v (lime_hb_font_subtract_glyph_origin_for_direction);
|
||||
DEFINE_PRIME1 (lime_hb_ft_font_create);
|
||||
DEFINE_PRIME1 (lime_hb_ft_font_create_referenced);
|
||||
DEFINE_PRIME1 (lime_hb_ft_font_get_load_flags);
|
||||
DEFINE_PRIME2v (lime_hb_ft_font_set_load_flags);
|
||||
|
||||
@@ -743,12 +743,13 @@ class NativeCFFI {
|
||||
@:cffi private static function lime_hb_buffer_allocation_successful (buffer:CFFIPointer):Bool;
|
||||
@:cffi private static function lime_hb_buffer_clear_contents (buffer:CFFIPointer):Void;
|
||||
@:cffi private static function lime_hb_buffer_create ():CFFIPointer;
|
||||
@:cffi private static function lime_hb_buffer_get_cluster_level (buffer:CFFIPointer):Int;
|
||||
@:cffi private static function lime_hb_buffer_get_content_type (buffer:CFFIPointer):Int;
|
||||
@:cffi private static function lime_hb_buffer_get_direction (buffer:CFFIPointer):Int;
|
||||
@:cffi private static function lime_hb_buffer_get_empty ():CFFIPointer;
|
||||
@:cffi private static function lime_hb_buffer_get_flags (buffer:CFFIPointer):Int;
|
||||
@:cffi private static function lime_hb_buffer_get_glyph_infos (buffer:CFFIPointer):CFFIPointer;
|
||||
@:cffi private static function lime_hb_buffer_get_glyph_positions (buffer:CFFIPointer):CFFIPointer;
|
||||
@:cffi private static function lime_hb_buffer_get_glyph_infos (buffer:CFFIPointer, bytes:Bytes):Bytes;
|
||||
@:cffi private static function lime_hb_buffer_get_glyph_positions (buffer:CFFIPointer, bytes:Bytes):Bytes;
|
||||
@:cffi private static function lime_hb_buffer_get_language (buffer:CFFIPointer):CFFIPointer;
|
||||
@:cffi private static function lime_hb_buffer_get_length (buffer:CFFIPointer):Int;
|
||||
@:cffi private static function lime_hb_buffer_get_replacement_codepoint (buffer:CFFIPointer):Int;
|
||||
@@ -763,6 +764,7 @@ class NativeCFFI {
|
||||
@:cffi private static function lime_hb_buffer_serialize_format_from_string (str:String):Int;
|
||||
@:cffi private static function lime_hb_buffer_serialize_format_to_string (format:Int):CFFIPointer;
|
||||
@:cffi private static function lime_hb_buffer_serialize_list_formats ():CFFIPointer;
|
||||
@:cffi private static function lime_hb_buffer_set_cluster_level (buffer:CFFIPointer, clusterLevel:Int):Void;
|
||||
@:cffi private static function lime_hb_buffer_set_content_type (buffer:CFFIPointer, contentType:Int):Void;
|
||||
@:cffi private static function lime_hb_buffer_set_direction (buffer:CFFIPointer, direction:Int):Void;
|
||||
@:cffi private static function lime_hb_buffer_set_flags (buffer:CFFIPointer, flags:Int):Void;
|
||||
@@ -803,6 +805,7 @@ class NativeCFFI {
|
||||
@:cffi private static function lime_hb_font_set_ppem (font:CFFIPointer, xppem:Int, yppem:Int):Void;
|
||||
@:cffi private static function lime_hb_font_set_scale (font:CFFIPointer, xScale:Int, yScale:Int):Void;
|
||||
@:cffi private static function lime_hb_font_subtract_glyph_origin_for_direction (font:CFFIPointer, glyph:Int, direction:Int, x:Int, y:Int):Void;
|
||||
@:cffi private static function lime_hb_ft_font_create (font:CFFIPointer):CFFIPointer;
|
||||
@:cffi private static function lime_hb_ft_font_create_referenced (font:CFFIPointer):CFFIPointer;
|
||||
@:cffi private static function lime_hb_ft_font_get_load_flags (font:CFFIPointer):Int;
|
||||
@:cffi private static function lime_hb_ft_font_set_load_flags (font:CFFIPointer, loadFlags:Int):Void;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package lime.text.harfbuzz;
|
||||
|
||||
|
||||
import lime._backend.native.NativeCFFI;
|
||||
import lime._internal.backend.native.NativeCFFI;
|
||||
import lime.system.CFFIPointer;
|
||||
import lime.utils.DataPointer;
|
||||
|
||||
@:access(lime._backend.native.NativeCFFI)
|
||||
@:access(lime._internal.backend.native.NativeCFFI)
|
||||
|
||||
|
||||
abstract HBBlob(CFFIPointer) from CFFIPointer to CFFIPointer {
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
package lime.text.harfbuzz;
|
||||
|
||||
|
||||
import lime._backend.native.NativeCFFI;
|
||||
import lime._internal.backend.native.NativeCFFI;
|
||||
import lime.system.CFFIPointer;
|
||||
import lime.utils.Bytes;
|
||||
import lime.utils.DataPointer;
|
||||
|
||||
@:access(lime._backend.native.NativeCFFI)
|
||||
@:access(lime._internal.backend.native.NativeCFFI)
|
||||
|
||||
|
||||
abstract HBBuffer(CFFIPointer) from CFFIPointer to CFFIPointer {
|
||||
|
||||
|
||||
public var allocationSuccessful (get, never):Bool;
|
||||
public var clusterLevel (get, set):HBBufferClusterLevel;
|
||||
public var contentType (get, set):HBBufferContentType;
|
||||
public var direction (get, set):HBDirection;
|
||||
public var flags (get, set):Int;
|
||||
@@ -90,7 +92,33 @@ abstract HBBuffer(CFFIPointer) from CFFIPointer to CFFIPointer {
|
||||
public function getGlyphInfo ():Array<HBGlyphInfo> {
|
||||
|
||||
#if (lime_cffi && lime_harfbuzz && !macro)
|
||||
return NativeCFFI.lime_hb_buffer_get_glyph_infos (this);
|
||||
var bytes = Bytes.alloc (0);
|
||||
bytes = NativeCFFI.lime_hb_buffer_get_glyph_infos (this, bytes);
|
||||
|
||||
if (bytes == null) {
|
||||
|
||||
return null;
|
||||
|
||||
} else {
|
||||
|
||||
var result = new Array<HBGlyphInfo> ();
|
||||
|
||||
var length = bytes.length;
|
||||
var position = 0, info;
|
||||
|
||||
while (position < length) {
|
||||
|
||||
info = new HBGlyphInfo ();
|
||||
info.codepoint = bytes.getInt32 (position); position += 4;
|
||||
info.mask = bytes.getInt32 (position); position += 4;
|
||||
info.cluster = bytes.getInt32 (position); position += 4;
|
||||
result.push (info);
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
#else
|
||||
return null;
|
||||
#end
|
||||
@@ -101,7 +129,34 @@ abstract HBBuffer(CFFIPointer) from CFFIPointer to CFFIPointer {
|
||||
public function getGlyphPositions ():Array<HBGlyphPosition> {
|
||||
|
||||
#if (lime_cffi && lime_harfbuzz && !macro)
|
||||
return NativeCFFI.lime_hb_buffer_get_glyph_positions (this);
|
||||
var bytes = Bytes.alloc (0);
|
||||
bytes = NativeCFFI.lime_hb_buffer_get_glyph_positions (this, bytes);
|
||||
|
||||
if (bytes == null) {
|
||||
|
||||
return null;
|
||||
|
||||
} else {
|
||||
|
||||
var result = new Array<HBGlyphPosition> ();
|
||||
|
||||
var length = bytes.length;
|
||||
var position = 0, glyphPosition;
|
||||
|
||||
while (position < length) {
|
||||
|
||||
glyphPosition = new HBGlyphPosition ();
|
||||
glyphPosition.xAdvance = bytes.getInt32 (position); position += 4;
|
||||
glyphPosition.yAdvance = bytes.getInt32 (position); position += 4;
|
||||
glyphPosition.xOffset = bytes.getInt32 (position); position += 4;
|
||||
glyphPosition.yOffset = bytes.getInt32 (position); position += 4;
|
||||
result.push (glyphPosition);
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
#else
|
||||
return null;
|
||||
#end
|
||||
@@ -183,6 +238,27 @@ abstract HBBuffer(CFFIPointer) from CFFIPointer to CFFIPointer {
|
||||
}
|
||||
|
||||
|
||||
private inline function get_clusterLevel ():HBBufferClusterLevel {
|
||||
|
||||
#if (lime_cffi && lime_harfbuzz && !macro)
|
||||
return NativeCFFI.lime_hb_buffer_get_cluster_level (this);
|
||||
#else
|
||||
return 0;
|
||||
#end
|
||||
|
||||
}
|
||||
|
||||
|
||||
private inline function set_clusterLevel (value:HBBufferClusterLevel):HBBufferClusterLevel {
|
||||
|
||||
#if (lime_cffi && lime_harfbuzz && !macro)
|
||||
NativeCFFI.lime_hb_buffer_set_cluster_level (this, value);
|
||||
#end
|
||||
return value;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private inline function get_contentType ():HBBufferContentType {
|
||||
|
||||
#if (lime_cffi && lime_harfbuzz && !macro)
|
||||
|
||||
11
src/lime/text/harfbuzz/HBBufferClusterLevel.hx
Normal file
11
src/lime/text/harfbuzz/HBBufferClusterLevel.hx
Normal file
@@ -0,0 +1,11 @@
|
||||
package lime.text.harfbuzz;
|
||||
|
||||
|
||||
@:enum abstract HBBufferClusterLevel(Int) from Int to Int {
|
||||
|
||||
public var MONOTONE_GRAPHEMES = 0;
|
||||
public var MONOTONE_CHARACTERS = 1;
|
||||
public var CHARACTERS = 2;
|
||||
public var DEFAULT = 0;
|
||||
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
package lime.text.harfbuzz;
|
||||
|
||||
|
||||
import lime._backend.native.NativeCFFI;
|
||||
import lime._internal.backend.native.NativeCFFI;
|
||||
import lime.system.CFFIPointer;
|
||||
import lime.text.Font;
|
||||
|
||||
@:forward
|
||||
@:access(lime._backend.native.NativeCFFI)
|
||||
@:access(lime._internal.backend.native.NativeCFFI)
|
||||
|
||||
|
||||
abstract HBFTFont(HBFont) to HBFont from CFFIPointer to CFFIPointer {
|
||||
@@ -18,6 +18,7 @@ abstract HBFTFont(HBFont) to HBFont from CFFIPointer to CFFIPointer {
|
||||
public function new (font:Font) {
|
||||
|
||||
#if (lime_cffi && lime_harfbuzz && !macro)
|
||||
// this = NativeCFFI.lime_hb_ft_font_create (font.src);
|
||||
this = NativeCFFI.lime_hb_ft_font_create_referenced (font.src);
|
||||
#else
|
||||
this = null;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package lime.text.harfbuzz;
|
||||
|
||||
|
||||
import lime._backend.native.NativeCFFI;
|
||||
import lime._internal.backend.native.NativeCFFI;
|
||||
import lime.system.CFFIPointer;
|
||||
|
||||
@:access(lime._backend.native.NativeCFFI)
|
||||
@:access(lime._internal.backend.native.NativeCFFI)
|
||||
|
||||
|
||||
abstract HBFace(CFFIPointer) from CFFIPointer to CFFIPointer {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package lime.text.harfbuzz;
|
||||
|
||||
|
||||
import lime._backend.native.NativeCFFI;
|
||||
import lime._internal.backend.native.NativeCFFI;
|
||||
import lime.math.Vector2;
|
||||
import lime.system.CFFIPointer;
|
||||
|
||||
@:access(lime._backend.native.NativeCFFI)
|
||||
@:access(lime._internal.backend.native.NativeCFFI)
|
||||
|
||||
|
||||
abstract HBFont(CFFIPointer) from CFFIPointer to CFFIPointer {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package lime.text.harfbuzz;
|
||||
|
||||
|
||||
import lime._backend.native.NativeCFFI;
|
||||
import lime._internal.backend.native.NativeCFFI;
|
||||
import lime.system.CFFIPointer;
|
||||
|
||||
@:access(lime._backend.native.NativeCFFI)
|
||||
@:access(lime._internal.backend.native.NativeCFFI)
|
||||
|
||||
|
||||
abstract HBLanguage(CFFIPointer) from CFFIPointer to CFFIPointer {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package lime.text.harfbuzz;
|
||||
|
||||
|
||||
import lime._backend.native.NativeCFFI;
|
||||
import lime._internal.backend.native.NativeCFFI;
|
||||
import lime.system.CFFIPointer;
|
||||
|
||||
@:access(lime._backend.native.NativeCFFI)
|
||||
@:access(lime._internal.backend.native.NativeCFFI)
|
||||
|
||||
|
||||
abstract HBSet(CFFIPointer) from CFFIPointer to CFFIPointer {
|
||||
|
||||
Reference in New Issue
Block a user