Make Font.getGlyphMetrics use an index only

This commit is contained in:
Joshua Granick
2015-03-12 21:59:51 -07:00
parent 1eede284a6
commit 7aaaa16ada
4 changed files with 20 additions and 108 deletions

View File

@@ -97,38 +97,21 @@ class Font {
}
public function getGlyphMetrics (glyphs:GlyphSet = null):Map<Int, Glyph> {
if (glyphs == null) {
glyphs = new GlyphSet ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^`'\"/\\&*()[]{}<>|:;_-+=?,. ");
}
public function getGlyphMetrics (index:Int):GlyphMetrics {
#if (cpp || neko || nodejs)
var array:Array<Dynamic> = lime_font_get_glyph_metrics (__handle, glyphs);
var map = new Map<Int, Glyph> ();
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

View File

@@ -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 ();

View File

@@ -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

View File

@@ -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 ();
}