Adding offset and advance

This commit is contained in:
Matt Tuttle
2014-07-13 23:25:38 -05:00
parent d5084081e2
commit 2bed6ac813
2 changed files with 21 additions and 0 deletions

View File

@@ -11,8 +11,11 @@ import js.html.CanvasRenderingContext2D;
typedef GlyphRect = { typedef GlyphRect = {
var x:Float; var x:Float;
var y:Float; var y:Float;
var advance:Int;
var width:Float; var width:Float;
var height:Float; var height:Float;
var xOffset:Int;
var yOffset:Int;
} }
typedef GlyphData = { typedef GlyphData = {
@@ -115,6 +118,9 @@ class Font {
glyphRects.set(c, { glyphRects.set(c, {
x: x, x: x,
y: y, y: y,
xOffset: 0,
yOffset: 0,
advance: Std.int(width),
width: width, width: width,
height: height height: height
}); });
@@ -180,6 +186,9 @@ class Font {
glyphRects.set(c, { glyphRects.set(c, {
x: x, x: x,
y: y, y: y,
xOffset: 0,
yOffset: 0,
advance: Std.int(tf.textWidth + 2),
width: tf.textWidth + 2, width: tf.textWidth + 2,
height: tf.textHeight + 2 height: tf.textHeight + 2
}); });
@@ -214,6 +223,9 @@ class Font {
glyphRects.set (glyph.char, { glyphRects.set (glyph.char, {
x: glyph.x, x: glyph.x,
y: glyph.y, y: glyph.y,
xOffset: glyph.xOffset,
yOffset: glyph.yOffset,
advance: glyph.advance,
width: glyph.width, width: glyph.width,
height: glyph.height, height: glyph.height,
}); });

View File

@@ -13,6 +13,9 @@ namespace lime {
static int id_x; static int id_x;
static int id_y; static int id_y;
static int id_x_offset;
static int id_y_offset;
static int id_advance;
static int id_width; static int id_width;
static int id_height; static int id_height;
static int id_char; static int id_char;
@@ -62,6 +65,9 @@ namespace lime {
id_height = val_id ("height"); id_height = val_id ("height");
id_x = val_id ("x"); id_x = val_id ("x");
id_y = val_id ("y"); id_y = val_id ("y");
id_x_offset = val_id ("xOffset");
id_y_offset = val_id ("yOffset");
id_advance = val_id ("advance");
id_char = val_id ("char"); id_char = val_id ("char");
init = true; init = true;
@@ -162,6 +168,9 @@ namespace lime {
value v = alloc_empty_object (); value v = alloc_empty_object ();
alloc_field (v, id_x, alloc_int (x)); alloc_field (v, id_x, alloc_int (x));
alloc_field (v, id_y, alloc_int (y)); alloc_field (v, id_y, alloc_int (y));
alloc_field (v, id_x_offset, alloc_int (face->glyph->metrics.horiBearingX / 64));
alloc_field (v, id_y_offset, alloc_int (face->glyph->metrics.horiBearingY / 64));
alloc_field (v, id_advance, alloc_int (face->glyph->metrics.horiAdvance / 64));
alloc_field (v, id_width, alloc_int (bitmap.width)); alloc_field (v, id_width, alloc_int (bitmap.width));
alloc_field (v, id_height, alloc_int (bitmap.rows)); alloc_field (v, id_height, alloc_int (bitmap.rows));
alloc_field (v, id_char, alloc_string (c)); alloc_field (v, id_char, alloc_string (c));