From 2bed6ac8139c311da2c34306cf5567d0dbba3357 Mon Sep 17 00:00:00 2001 From: Matt Tuttle Date: Sun, 13 Jul 2014 23:25:38 -0500 Subject: [PATCH] Adding offset and advance --- lime/graphics/Font.hx | 12 ++++++++++++ project/src/graphics/Font.cpp | 9 +++++++++ 2 files changed, 21 insertions(+) diff --git a/lime/graphics/Font.hx b/lime/graphics/Font.hx index 4243979df..b33c65360 100644 --- a/lime/graphics/Font.hx +++ b/lime/graphics/Font.hx @@ -11,8 +11,11 @@ import js.html.CanvasRenderingContext2D; typedef GlyphRect = { var x:Float; var y:Float; + var advance:Int; var width:Float; var height:Float; + var xOffset:Int; + var yOffset:Int; } typedef GlyphData = { @@ -115,6 +118,9 @@ class Font { glyphRects.set(c, { x: x, y: y, + xOffset: 0, + yOffset: 0, + advance: Std.int(width), width: width, height: height }); @@ -180,6 +186,9 @@ class Font { glyphRects.set(c, { x: x, y: y, + xOffset: 0, + yOffset: 0, + advance: Std.int(tf.textWidth + 2), width: tf.textWidth + 2, height: tf.textHeight + 2 }); @@ -214,6 +223,9 @@ class Font { glyphRects.set (glyph.char, { x: glyph.x, y: glyph.y, + xOffset: glyph.xOffset, + yOffset: glyph.yOffset, + advance: glyph.advance, width: glyph.width, height: glyph.height, }); diff --git a/project/src/graphics/Font.cpp b/project/src/graphics/Font.cpp index 6ab9f0e33..894b1ae65 100644 --- a/project/src/graphics/Font.cpp +++ b/project/src/graphics/Font.cpp @@ -13,6 +13,9 @@ namespace lime { static int id_x; 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_height; static int id_char; @@ -62,6 +65,9 @@ namespace lime { id_height = val_id ("height"); id_x = val_id ("x"); 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"); init = true; @@ -162,6 +168,9 @@ namespace lime { value v = alloc_empty_object (); alloc_field (v, id_x, alloc_int (x)); 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_height, alloc_int (bitmap.rows)); alloc_field (v, id_char, alloc_string (c));