Add Font.getCharIndices
This commit is contained in:
@@ -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