diff --git a/lime/text/Font.hx b/lime/text/Font.hx index ee74ca720..ce116e6ce 100644 --- a/lime/text/Font.hx +++ b/lime/text/Font.hx @@ -97,38 +97,21 @@ class Font { } - public function getGlyphMetrics (glyphs:GlyphSet = null):Map { - - if (glyphs == null) { - - glyphs = new GlyphSet ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^`'\"/\\&*()[]{}<>|:;_-+=?,. "); - - } + public function getGlyphMetrics (index:Int):GlyphMetrics { #if (cpp || neko || nodejs) - var array:Array = lime_font_get_glyph_metrics (__handle, glyphs); - var map = new Map (); + var value = lime_font_get_glyph_metrics (__handle, index); + var metrics = new GlyphMetrics (); - for (value in array) { - - var glyph = new Glyph (value.charCode, value.index); - var metrics = new GlyphMetrics (); - - metrics.height = value.height; - metrics.horizontalAdvance = value.horizontalAdvance; - metrics.horizontalBearingX = value.horizontalBearingX; - metrics.horizontalBearingY = value.horizontalBearingY; - metrics.verticalAdvance = value.verticalAdvance; - metrics.verticalBearingX = value.verticalBearingX; - metrics.verticalBearingY = value.verticalBearingY; - - glyph.metrics = metrics; - - map.set (glyph.index, glyph); - - } + metrics.height = value.height; + metrics.horizontalAdvance = value.horizontalAdvance; + metrics.horizontalBearingX = value.horizontalBearingX; + metrics.horizontalBearingY = value.horizontalBearingY; + metrics.verticalAdvance = value.verticalAdvance; + metrics.verticalBearingX = value.verticalBearingX; + metrics.verticalBearingY = value.verticalBearingY; - return map; + return metrics; #else return null; #end diff --git a/project/include/text/Font.h b/project/include/text/Font.h index 3d9bf04a5..d8a3e8733 100644 --- a/project/include/text/Font.h +++ b/project/include/text/Font.h @@ -49,7 +49,7 @@ namespace lime { value GetCharIndices (char* characters); int GetDescender (); wchar_t *GetFamilyName (); - value GetGlyphMetrics (GlyphSet *glyphSet); + value GetGlyphMetrics (int index); int GetHeight (); int GetNumGlyphs (); int GetUnderlinePosition (); diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp index b2dc16b37..e66a479aa 100644 --- a/project/src/ExternalInterface.cpp +++ b/project/src/ExternalInterface.cpp @@ -189,12 +189,11 @@ namespace lime { } - value lime_font_get_glyph_metrics (value fontHandle, value glyphSet) { + value lime_font_get_glyph_metrics (value fontHandle, value index) { #ifdef LIME_FREETYPE Font *font = (Font*)(intptr_t)val_float (fontHandle); - GlyphSet glyphs = GlyphSet (glyphSet); - return font->GetGlyphMetrics (&glyphs); + return font->GetGlyphMetrics (val_int (index)); #else return alloc_null (); #endif diff --git a/project/src/text/Font.cpp b/project/src/text/Font.cpp index 7f80d2c84..4590eca73 100644 --- a/project/src/text/Font.cpp +++ b/project/src/text/Font.cpp @@ -721,14 +721,14 @@ namespace lime { } - void GetGlyphMetrics_Push (FT_Face face, FT_ULong charCode, FT_UInt glyphIndex, value glyphList) { + value Font::GetGlyphMetrics (int index) { - if (FT_Load_Glyph (face, glyphIndex, FT_LOAD_NO_BITMAP | FT_LOAD_FORCE_AUTOHINT | FT_LOAD_DEFAULT) == 0) { + initialize (); + + if (FT_Load_Glyph ((FT_Face)face, index, FT_LOAD_NO_BITMAP | FT_LOAD_FORCE_AUTOHINT | FT_LOAD_DEFAULT) == 0) { value metrics = alloc_empty_object (); - alloc_field (metrics, id_charCode, alloc_int (charCode)); - alloc_field (metrics, id_index, alloc_int (glyphIndex)); alloc_field (metrics, id_height, alloc_int (((FT_Face)face)->glyph->metrics.height)); alloc_field (metrics, id_horizontalBearingX, alloc_int (((FT_Face)face)->glyph->metrics.horiBearingX)); alloc_field (metrics, id_horizontalBearingY, alloc_int (((FT_Face)face)->glyph->metrics.horiBearingY)); @@ -737,81 +737,11 @@ namespace lime { alloc_field (metrics, id_verticalBearingY, alloc_int (((FT_Face)face)->glyph->metrics.vertBearingY)); alloc_field (metrics, id_verticalAdvance, alloc_int (((FT_Face)face)->glyph->metrics.vertAdvance)); - val_array_push (glyphList, metrics); + return metrics; } - } - - - value Font::GetGlyphMetrics (GlyphSet *glyphSet) { - - initialize (); - - value glyphList = alloc_array (0); - - if (!glyphSet->glyphs.empty ()) { - - FT_ULong charCode; - - for (unsigned int i = 0; i < glyphSet->glyphs.length (); i++) { - - charCode = glyphSet->glyphs[i]; - GetGlyphMetrics_Push ((FT_Face)face, charCode, FT_Get_Char_Index ((FT_Face)face, charCode), glyphList); - - } - - } - - GlyphRange range; - - for (int i = 0; i < glyphSet->ranges.size (); i++) { - - range = glyphSet->ranges[i]; - - if (range.start == 0 && range.end == -1) { - - FT_UInt glyphIndex; - FT_ULong charCode = FT_Get_First_Char ((FT_Face)face, &glyphIndex); - - while (glyphIndex != 0) { - - GetGlyphMetrics_Push ((FT_Face)face, charCode, glyphIndex, glyphList); - charCode = FT_Get_Next_Char ((FT_Face)face, charCode, &glyphIndex); - - } - - } else { - - unsigned long end = range.end; - - FT_ULong charCode = range.start; - FT_UInt glyphIndex = FT_Get_Char_Index ((FT_Face)face, charCode); - - while (charCode <= end || end < 0) { - - if (glyphIndex > 0) { - - GetGlyphMetrics_Push ((FT_Face)face, charCode, glyphIndex, glyphList); - - } - - glyphIndex = -1; - charCode = FT_Get_Next_Char ((FT_Face)face, charCode, &glyphIndex); - - if (glyphIndex == 0) { - - break; - - } - - } - - } - - } - - return glyphList; + return alloc_null (); }