Add Font.getCharIndices
This commit is contained in:
@@ -75,10 +75,10 @@ class Font {
|
||||
}
|
||||
|
||||
|
||||
public function getCharIndex (char:String):Int {
|
||||
public function getCharIndex (character:String):Int {
|
||||
|
||||
#if (cpp || neko || nodejs)
|
||||
return lime_font_get_char_index (__handle, char);
|
||||
return lime_font_get_char_index (__handle, character);
|
||||
#else
|
||||
return -1;
|
||||
#end
|
||||
@@ -86,6 +86,17 @@ class Font {
|
||||
}
|
||||
|
||||
|
||||
public function getCharIndices (characters:String):Array<Int> {
|
||||
|
||||
#if (cpp || neko || nodejs)
|
||||
return lime_font_get_char_indices (__handle, characters);
|
||||
#else
|
||||
return null;
|
||||
#end
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function getGlyphMetrics (glyphs:GlyphSet = null):Map<Int, Glyph> {
|
||||
|
||||
if (glyphs == null) {
|
||||
@@ -440,6 +451,7 @@ class Font {
|
||||
#if (cpp || neko || nodejs)
|
||||
private static var lime_font_get_ascender = System.load ("lime", "lime_font_get_ascender", 1);
|
||||
private static var lime_font_get_char_index = System.load ("lime", "lime_font_get_char_index", 2);
|
||||
private static var lime_font_get_char_indices = System.load ("lime", "lime_font_get_char_indices", 2);
|
||||
private static var lime_font_get_descender = System.load ("lime", "lime_font_get_descender", 1);
|
||||
private static var lime_font_get_family_name = System.load ("lime", "lime_font_get_family_name", 1);
|
||||
private static var lime_font_get_glyph_metrics = System.load ("lime", "lime_font_get_glyph_metrics", 2);
|
||||
|
||||
@@ -46,6 +46,7 @@ namespace lime {
|
||||
value Decompose (int em);
|
||||
int GetAscender ();
|
||||
int GetCharIndex (char* character);
|
||||
value GetCharIndices (char* characters);
|
||||
int GetDescender ();
|
||||
wchar_t *GetFamilyName ();
|
||||
value GetGlyphMetrics (GlyphSet *glyphSet);
|
||||
|
||||
@@ -145,7 +145,7 @@ namespace lime {
|
||||
|
||||
#ifdef LIME_FREETYPE
|
||||
Font *font = (Font*)(intptr_t)val_float (fontHandle);
|
||||
return alloc_int (font->GetCharIndex ((char*)val_wstring (character)));
|
||||
return alloc_int (font->GetCharIndex ((char*)val_string (character)));
|
||||
#else
|
||||
return alloc_int (-1);
|
||||
#endif
|
||||
@@ -153,6 +153,18 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_font_get_char_indices (value fontHandle, value characters) {
|
||||
|
||||
#ifdef LIME_FREETYPE
|
||||
Font *font = (Font*)(intptr_t)val_float (fontHandle);
|
||||
return font->GetCharIndices ((char*)val_string (characters));
|
||||
#else
|
||||
return alloc_null ();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
value lime_font_get_descender (value fontHandle) {
|
||||
|
||||
#ifdef LIME_FREETYPE
|
||||
@@ -659,6 +671,7 @@ namespace lime {
|
||||
DEFINE_PRIM (lime_audio_load, 1);
|
||||
DEFINE_PRIM (lime_font_get_ascender, 1);
|
||||
DEFINE_PRIM (lime_font_get_char_index, 2);
|
||||
DEFINE_PRIM (lime_font_get_char_indices, 2);
|
||||
DEFINE_PRIM (lime_font_get_descender, 1);
|
||||
DEFINE_PRIM (lime_font_get_family_name, 1);
|
||||
DEFINE_PRIM (lime_font_get_glyph_metrics, 2);
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
|
||||
// from http://stackoverflow.com/questions/2948308/how-do-i-read-utf-8-characters-via-a-pointer
|
||||
#define IS_IN_RANGE(c, f, l) (((c) >= (f)) && ((c) <= (l)))
|
||||
#define IS_IN_RANGE(c, f, l) (((c) >= (f)) && ((c) <= (l)))
|
||||
|
||||
|
||||
unsigned long readNextChar (char*& p)
|
||||
@@ -633,13 +633,32 @@ namespace lime {
|
||||
|
||||
int Font::GetCharIndex (char* character) {
|
||||
|
||||
long charCode = readNextChar (character);
|
||||
long charCode = readNextChar (character);
|
||||
|
||||
return FT_Get_Char_Index ((FT_Face)face, charCode);
|
||||
|
||||
}
|
||||
|
||||
|
||||
value Font::GetCharIndices (char* characters) {
|
||||
|
||||
value indices = alloc_array (0);
|
||||
unsigned long character;
|
||||
int index;
|
||||
|
||||
while (*characters != 0) {
|
||||
|
||||
character = readNextChar (characters);
|
||||
index = FT_Get_Char_Index ((FT_Face)face, character);
|
||||
val_array_push (indices, alloc_int (index));
|
||||
|
||||
}
|
||||
|
||||
return indices;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int Font::GetDescender () {
|
||||
|
||||
return ((FT_Face)face)->descender;
|
||||
|
||||
Reference in New Issue
Block a user