Make Font.getGlyphMetrics use an index only
This commit is contained in:
@@ -97,38 +97,21 @@ class Font {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getGlyphMetrics (glyphs:GlyphSet = null):Map<Int, Glyph> {
|
public function getGlyphMetrics (index:Int):GlyphMetrics {
|
||||||
|
|
||||||
if (glyphs == null) {
|
|
||||||
|
|
||||||
glyphs = new GlyphSet ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^`'\"/\\&*()[]{}<>|:;_-+=?,. ");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#if (cpp || neko || nodejs)
|
#if (cpp || neko || nodejs)
|
||||||
var array:Array<Dynamic> = lime_font_get_glyph_metrics (__handle, glyphs);
|
var value = lime_font_get_glyph_metrics (__handle, index);
|
||||||
var map = new Map<Int, Glyph> ();
|
var metrics = new GlyphMetrics ();
|
||||||
|
|
||||||
for (value in array) {
|
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;
|
||||||
|
|
||||||
var glyph = new Glyph (value.charCode, value.index);
|
return metrics;
|
||||||
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);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return map;
|
|
||||||
#else
|
#else
|
||||||
return null;
|
return null;
|
||||||
#end
|
#end
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ namespace lime {
|
|||||||
value GetCharIndices (char* characters);
|
value GetCharIndices (char* characters);
|
||||||
int GetDescender ();
|
int GetDescender ();
|
||||||
wchar_t *GetFamilyName ();
|
wchar_t *GetFamilyName ();
|
||||||
value GetGlyphMetrics (GlyphSet *glyphSet);
|
value GetGlyphMetrics (int index);
|
||||||
int GetHeight ();
|
int GetHeight ();
|
||||||
int GetNumGlyphs ();
|
int GetNumGlyphs ();
|
||||||
int GetUnderlinePosition ();
|
int GetUnderlinePosition ();
|
||||||
|
|||||||
@@ -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
|
#ifdef LIME_FREETYPE
|
||||||
Font *font = (Font*)(intptr_t)val_float (fontHandle);
|
Font *font = (Font*)(intptr_t)val_float (fontHandle);
|
||||||
GlyphSet glyphs = GlyphSet (glyphSet);
|
return font->GetGlyphMetrics (val_int (index));
|
||||||
return font->GetGlyphMetrics (&glyphs);
|
|
||||||
#else
|
#else
|
||||||
return alloc_null ();
|
return alloc_null ();
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -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 ();
|
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_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_horizontalBearingX, alloc_int (((FT_Face)face)->glyph->metrics.horiBearingX));
|
||||||
alloc_field (metrics, id_horizontalBearingY, alloc_int (((FT_Face)face)->glyph->metrics.horiBearingY));
|
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_verticalBearingY, alloc_int (((FT_Face)face)->glyph->metrics.vertBearingY));
|
||||||
alloc_field (metrics, id_verticalAdvance, alloc_int (((FT_Face)face)->glyph->metrics.vertAdvance));
|
alloc_field (metrics, id_verticalAdvance, alloc_int (((FT_Face)face)->glyph->metrics.vertAdvance));
|
||||||
|
|
||||||
val_array_push (glyphList, metrics);
|
return metrics;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
return alloc_null ();
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user