Browse Source

Change h2d.Tile to use Float.

Yanrishatum 6 years ago
parent
commit
21bf81e3f1

+ 1 - 1
h2d/Console.hx

@@ -38,7 +38,7 @@ class Console #if !macro extends h2d.Object #end {
 
 	public function new(font:h2d.Font,?parent) {
 		super(parent);
-		height = font.lineHeight + 2;
+		height = Math.ceil(font.lineHeight) + 2;
 		logTxt = new h2d.HtmlText(font, this);
 		logTxt.x = 2;
 		logTxt.dropShadow = { dx : 0, dy : 1, color : 0, alpha : 0.5 };

+ 31 - 15
h2d/Font.hx

@@ -2,7 +2,7 @@ package h2d;
 
 class Kerning {
 	public var prevChar : Int;
-	public var offset : Int;
+	public var offset : Float;
 	public var next : Null<Kerning>;
 	public function new(c, o) {
 		this.prevChar = c;
@@ -13,7 +13,7 @@ class Kerning {
 class FontChar {
 
 	public var t : h2d.Tile;
-	public var width : Int;
+	public var width : Float;
 	var kerning : Null<Kerning>;
 
 	public function new(t,w) {
@@ -39,7 +39,18 @@ class FontChar {
 
 	public function clone() {
 		var c = new FontChar(t.clone(), width);
-		c.kerning = kerning;
+		// Clone entire kerning tree in case Font got resized.
+		var k = kerning;
+		if ( k != null ) {
+			var kc = new Kerning(k.prevChar, k.offset);
+			c.kerning = kc;
+			k = k.next;
+			while ( k != null ) {
+				var kn = new Kerning(k.prevChar, k.offset);
+				kc = kc.next = kn;
+				k = k.next;
+			}
+		}
 		return c;
 	}
 
@@ -69,8 +80,8 @@ class Font {
 
 	public var name(default, null) : String;
 	public var size(default, null) : Int;
-	public var baseLine(default, null) : Int;
-	public var lineHeight(default, null) : Int;
+	public var baseLine(default, null) : Float;
+	public var lineHeight(default, null) : Float;
 	public var tile(default,null) : h2d.Tile;
 	public var tilePath(default,null) : String;
 	public var type : FontType;
@@ -79,10 +90,10 @@ class Font {
 	var nullChar : FontChar;
 	var defaultChar : FontChar;
 	var initSize:Int;
-	var offsetX:Int = 0;
-	var offsetY:Int = 0;
+	var offsetX:Float = 0;
+	var offsetY:Float = 0;
 
-	function new(name,size,?type) {
+	function new(name : String, size : Int, ?type : FontType) {
 		this.name = name;
 		this.size = size;
 		this.initSize = size;
@@ -107,7 +118,7 @@ class Font {
 		return c;
 	}
 
-	public function setOffset(x,y) {
+	public function setOffset( x : Float, y :Float ) {
 		var dx = x - offsetX;
 		var dy = y - offsetY;
 		if( dx == 0 && dy == 0 ) return;
@@ -142,13 +153,18 @@ class Font {
 	public function resizeTo( size : Int ) {
 		var ratio = size / initSize;
 		for( c in glyphs ) {
-			c.width = Std.int(c.width * ratio);
-			c.t.scaleToSize(Std.int(c.t.width * ratio), Std.int(c.t.height * ratio));
-			c.t.dx = Std.int(c.t.dx * ratio);
-			c.t.dy = Std.int(c.t.dy * ratio);
+			c.width *= ratio;
+			c.t.scaleToSize(c.t.width * ratio, c.t.height * ratio);
+			c.t.dx *= ratio;
+			c.t.dy *= ratio;
+			var k = @:privateAccess c.kerning;
+			while ( k != null ) {
+				k.offset *= ratio;
+				k = k.next;
+			}
 		}
-		lineHeight = Std.int(lineHeight * ratio);
-		baseLine = Std.int(baseLine * ratio);
+		lineHeight = lineHeight * ratio;
+		baseLine = baseLine * ratio;
 		this.size = size;
 	}
 

+ 14 - 14
h2d/HtmlText.hx

@@ -7,10 +7,10 @@ class HtmlText extends Text {
 	public var condenseWhite(default,set) : Bool = true;
 
 	var elements : Array<Object> = [];
-	var xPos : Int;
-	var yPos : Int;
-	var xMax : Int;
-	var xMin : Int;
+	var xPos : Float;
+	var yPos : Float;
+	var xMax : Float;
+	var xMin : Float;
 	var sizePos : Int;
 	var dropMatrix : h3d.shader.ColorMatrix;
 	var prevChar : Int;
@@ -47,7 +47,7 @@ class HtmlText extends Text {
 		return font;
 	}
 
-	override function initGlyphs( text : String, rebuild = true, handleAlign = true, ?lines : Array<Int> ) {
+	override function initGlyphs( text : String, rebuild = true, handleAlign = true, ?lines : Array<Float> ) {
 		if( rebuild ) {
 			glyphs.clear();
 			for( e in elements ) e.remove();
@@ -64,9 +64,9 @@ class HtmlText extends Text {
 				lines = [];
 				initGlyphs(text, false, false, lines);
 				var max = if( align == MultilineCenter || align == MultilineRight ) calcWidth else realMaxWidth < 0 ? 0 : Std.int(realMaxWidth);
-				var k = align == Center || align == MultilineCenter ? 1 : 0;
+				var k = align == Center || align == MultilineCenter ? 0.5 : 1;
 				for( i in 0...lines.length )
-					lines[i] = (max - lines[i]) >> k;
+					lines[i] = (max - lines[i]) * k;
 				xPos = lines.shift();
 				xMin = xPos;
 			default:
@@ -79,7 +79,7 @@ class HtmlText extends Text {
 
 		var doc = try Xml.parse(text) catch( e : Dynamic ) throw "Could not parse " + text + " (" + e +")";
 
-		var sizes = [];
+		var sizes = new Array<Float>();
 		prevChar = -1;
 		newLine = true;
 		for( e in doc )
@@ -101,9 +101,9 @@ class HtmlText extends Text {
 		calcDone = true;
 	}
 
-	function buildSizes( e : Xml, font : Font, sizes : Array<Int> ) {
+	function buildSizes( e : Xml, font : Font, sizes : Array<Float> ) {
 		if( e.nodeType == Xml.Element ) {
-			var len = 0;
+			var len = 0.;
 			var nodeName = e.nodeName.toLowerCase();
 			switch( nodeName ) {
 			case "p":
@@ -141,7 +141,7 @@ class HtmlText extends Text {
 		} else {
 			newLine = false;
 			var text = htmlToText(e.nodeValue);
-			var xp = 0;
+			var xp = 0.;
 			for( i in 0...text.length ) {
 				var cc = text.charCodeAt(i);
 				var fc = font.getChar(cc);
@@ -165,8 +165,8 @@ class HtmlText extends Text {
 		return t;
 	}
 
-	function remainingSize( sizes : Array<Int> ) {
-		var size = 0;
+	function remainingSize( sizes : Array<Float> ) {
+		var size = 0.;
 		for( i in sizePos...sizes.length ) {
 			var s = sizes[i];
 			if( s < 0 ) {
@@ -178,7 +178,7 @@ class HtmlText extends Text {
 		return size;
 	}
 
-	function addNode( e : Xml, font : Font, rebuild : Bool, handleAlign:Bool, sizes : Array<Int>, ?lines : Array<Int> = null ) {
+	function addNode( e : Xml, font : Font, rebuild : Bool, handleAlign:Bool, sizes : Array<Float>, ?lines : Array<Float> = null ) {
 		sizePos++;
 		var calcLines = !handleAlign && !rebuild && lines != null;
 		var align = handleAlign ? textAlign : Left;

+ 1 - 1
h2d/RenderContext.hx

@@ -348,7 +348,7 @@ class RenderContext extends h3d.impl.RenderContext {
 			if( cx < -tr || cy < -tr || cx - tr > curWidth || cy - tr > curHeight ) return false;
 		} else {
 			var xMin = 1e20, yMin = 1e20, xMax = -1e20, yMax = -1e20;
-			inline function calc(x:Int, y:Int) {
+			inline function calc(x:Float, y:Float) {
 				var px = (x + tile.dx) * matA + (y + tile.dy) * matC;
 				var py = (x + tile.dx) * matB + (y + tile.dy) * matD;
 				if( px < xMin ) xMin = px;

+ 2 - 2
h2d/ScaleGrid.hx

@@ -15,8 +15,8 @@ class ScaleGrid extends h2d.TileGroup {
 		super(tile,parent);
 		borderWidth = borderW;
 		borderHeight = borderH;
-		width = tile.width;
-		height = tile.height;
+		width = Std.int(tile.width);
+		height = Std.int(tile.height);
 	}
 
 	function set_tileBorders(b) {

+ 1 - 1
h2d/Scene.hx

@@ -511,7 +511,7 @@ class Scene extends Layers implements h3d.IDrawable implements hxd.SceneEvents.I
 			target = new Tile(tex,0, 0, width, height);
 		}
 		engine.begin();
-		engine.setRenderZone(target.x, target.y, target.width, target.height);
+		engine.setRenderZone(Std.int(target.x), Std.int(target.y), Std.int(target.width), Std.int(target.height));
 
 		var tex = target.getTexture();
 		engine.pushTarget(tex);

+ 17 - 17
h2d/Text.hx

@@ -19,17 +19,17 @@ class Text extends Drawable {
 	public var textWidth(get, null) : Int;
 	public var textHeight(get, null) : Int;
 	public var textAlign(default, set) : Align;
-	public var letterSpacing(default, set) : Int;
-	public var lineSpacing(default,set) : Int;
+	public var letterSpacing(default, set) : Float;
+	public var lineSpacing(default,set) : Float;
 
 	var glyphs : TileGroup;
 
 	var calcDone:Bool;
-	var calcXMin:Int;
-	var calcYMin:Int;
-	var calcWidth:Int;
-	var calcHeight:Int;
-	var calcSizeHeight:Int;
+	var calcXMin:Float;
+	var calcYMin:Float;
+	var calcWidth:Float;
+	var calcHeight:Float;
+	var calcSizeHeight:Float;
 	var constraintWidth:Float = -1;
 	var realMaxWidth:Float = -1;
 
@@ -43,7 +43,7 @@ class Text extends Drawable {
 		this.font = font;
 		textAlign = Left;
 		letterSpacing = 1;
-        lineSpacing = 0;
+		lineSpacing = 0;
 		text = "";
 		textColor = 0xFFFFFF;
 	}
@@ -170,7 +170,7 @@ class Text extends Drawable {
 		}
 	}
 
-	public function splitText( text : hxd.UString, leftMargin = 0, afterData = 0 ) {
+	public function splitText( text : hxd.UString, leftMargin = 0., afterData = 0. ) {
 		if( realMaxWidth < 0 )
 			return text;
 		var lines = [], rest = text, restPos = 0;
@@ -227,25 +227,25 @@ class Text extends Drawable {
 		return lines.join("\n");
 	}
 
-	function initGlyphs( text : hxd.UString, rebuild = true, handleAlign = true, lines : Array<Int> = null ) : Void {
+	function initGlyphs( text : hxd.UString, rebuild = true, handleAlign = true, lines : Array<Float> = null ) : Void {
 		if( rebuild ) glyphs.clear();
-		var x = 0, y = 0, xMax = 0, xMin = 0, prevChar = -1;
+		var x = 0., y = 0., xMax = 0., xMin = 0., prevChar = -1;
 		var align = handleAlign ? textAlign : Left;
 		switch( align ) {
 		case Center, Right, MultilineCenter, MultilineRight:
 			lines = [];
 			initGlyphs(text, false, false, lines);
 			var max = if( align == MultilineCenter || align == MultilineRight ) calcWidth else realMaxWidth < 0 ? 0 : Std.int(realMaxWidth);
-			var k = align == Center || align == MultilineCenter ? 1 : 0;
+			var k = align == Center || align == MultilineCenter ? 0.5 : 1;
 			for( i in 0...lines.length )
-				lines[i] = (max - lines[i]) >> k;
+				lines[i] = (max - lines[i]) * k;
 			x = lines.shift();
 			xMin = x;
 		default:
 		}
 		var dl = font.lineHeight + lineSpacing;
 		var calcLines = !handleAlign && !rebuild && lines != null;
-		var yMin = 0;
+		var yMin = 0.;
 		var t = splitText(text);
 		for( i in 0...t.length ) {
 			var cc = t.charCodeAt(i);
@@ -292,12 +292,12 @@ class Text extends Drawable {
 
 	function get_textHeight() {
 		updateSize();
-		return calcHeight;
+		return Math.ceil(calcHeight);
 	}
 
 	function get_textWidth() {
 		updateSize();
-		return calcWidth;
+		return Math.ceil(calcWidth);
 	}
 
 	function set_maxWidth(w) {
@@ -334,7 +334,7 @@ class Text extends Drawable {
 		var x, y, w : Float, h;
 		if ( forSize ) {
 			x = calcXMin;  // TODO: Should be 0 as well for consistency, but currently causes problems with Flows
-			y = 0;
+			y = 0.;
 			w = calcWidth;
 			h = calcSizeHeight;
 		} else {

+ 5 - 5
h2d/TextInput.hx

@@ -17,13 +17,13 @@ class TextInput extends Text {
 
 	var interactive : h2d.Interactive;
 	var cursorText : String;
-	var cursorX : Int;
+	var cursorX : Float;
 	var cursorXIndex : Int;
 	var cursorBlink = 0.;
 	var cursorScroll = 0;
-	var scrollX = 0;
-	var selectionPos : Int;
-	var selectionSize : Int;
+	var scrollX = 0.;
+	var selectionPos : Float;
+	var selectionSize : Float;
 	var undo : Array<TextHistoryElement> = [];
 	var redo : Array<TextHistoryElement> = [];
 	var lastChange = 0.;
@@ -259,7 +259,7 @@ class TextInput extends Text {
 		return f;
 	}
 
-	override function initGlyphs(text:hxd.UString, rebuild = true, handleAlign = true, lines:Array<Int> = null):Void {
+	override function initGlyphs(text:hxd.UString, rebuild = true, handleAlign = true, lines:Array<Float> = null):Void {
 		super.initGlyphs(text, rebuild, handleAlign, lines);
 		if( rebuild ) {
 			this.calcWidth += cursorTile.width; // cursor end pos

+ 19 - 19
h2d/Tile.hx

@@ -10,14 +10,14 @@ class Tile {
 	var u2 : Float;
 	var v2 : Float;
 
-	public var dx : Int;
-	public var dy : Int;
-	public var x(default,null) : Int;
-	public var y(default,null) : Int;
-	public var width(default,null) : Int;
-	public var height(default,null) : Int;
-
-	function new(tex : h3d.mat.Texture, x : Int, y : Int, w : Int, h : Int, dx=0, dy=0) {
+	public var dx : Float;
+	public var dy : Float;
+	public var x(default,null) : Float;
+	public var y(default,null) : Float;
+	public var width(default,null) : Float;
+	public var height(default,null) : Float;
+
+	function new(tex : h3d.mat.Texture, x : Float, y : Float, w : Float, h : Float, dx : Float=0, dy : Float=0) {
 		this.innerTex = tex;
 		this.x = x;
 		this.y = y;
@@ -50,17 +50,17 @@ class Tile {
 		setTexture(t.innerTex);
 	}
 
-	public function sub( x : Int, y : Int, w : Int, h : Int, dx = 0, dy = 0 ) : Tile {
+	public function sub( x : Float, y : Float, w : Float, h : Float, dx = 0., dy = 0. ) : Tile {
 		return new Tile(innerTex, this.x + x, this.y + y, w, h, dx, dy);
 	}
 
 	public function center():Tile {
-		return sub(0, 0, width, height, -(width>>1), -(height>>1));
+		return sub(0, 0, width, height, -(width * .5), -(height * .5));
 	}
 
 	public inline function setCenterRatio(?px:Float=0.5, ?py:Float=0.5) : Void {
-		dx = -Std.int(px*width);
-		dy = -Std.int(py*height);
+		dx = -(px*width);
+		dy = -(py*height);
 	}
 
 	public function flipX() : Void {
@@ -73,7 +73,7 @@ class Tile {
 		dy = -dy - height;
 	}
 
-	public function setPosition(x : Int, y : Int) : Void {
+	public function setPosition(x : Float, y : Float) : Void {
 		this.x = x;
 		this.y = y;
 		var tex = innerTex;
@@ -85,7 +85,7 @@ class Tile {
 		}
 	}
 
-	public function setSize(w : Int, h : Int) : Void {
+	public function setSize(w : Float, h : Float) : Void {
 		this.width = w;
 		this.height = h;
 		var tex = innerTex;
@@ -95,7 +95,7 @@ class Tile {
 		}
 	}
 
-	public function scaleToSize( w : Int, h : Int ) : Void {
+	public function scaleToSize( w : Float, h : Float ) : Void {
 		this.width = w;
 		this.height = h;
 	}
@@ -106,8 +106,8 @@ class Tile {
 		v -= dy / tex.height;
 		u2 += dx / tex.width;
 		v2 -= dy / tex.height;
-		x = Std.int(u * tex.width);
-		y = Std.int(v * tex.height);
+		x = u * tex.width;
+		y = v * tex.height;
 	}
 
 	public function dispose() : Void {
@@ -150,14 +150,14 @@ class Tile {
 		Split the tile into a list of tiles of Size x Size pixels.
 		Unlike grid which is X/Y ordered, gridFlatten returns a single dimensional array ordered in Y/X.
 	**/
-	public function gridFlatten( size : Int, dx = 0, dy = 0 ) : Array<Tile> {
+	public function gridFlatten( size : Int, dx = 0., dy = 0. ) : Array<Tile> {
 		return [for( y in 0...Std.int(height / size) ) for( x in 0...Std.int(width / size) ) sub(x * size, y * size, size, size, dx, dy)];
 	}
 
 	/**
 		Split the tile into a list of tiles of Size x Size pixels.
 	**/
-	public function grid( size : Int, dx = 0, dy = 0 ) : Array<Array<Tile>> {
+	public function grid( size : Int, dx = 0., dy = 0. ) : Array<Array<Tile>> {
 		return [for( x in 0...Std.int(width / size) ) [for( y in 0...Std.int(height / size) ) sub(x * size, y * size, size, size, dx, dy)]];
 	}
 

+ 7 - 7
h2d/TileGroup.hx

@@ -30,11 +30,11 @@ private class TileLayerContent extends h3d.prim.Primitive {
 		return if( buffer == null ) tmp.length >> 4 else buffer.totalVertices() >> 1;
 	}
 
-	public inline function addColor( x : Int, y : Int, color : h3d.Vector, t : Tile ) {
+	public inline function addColor( x : Float, y : Float, color : h3d.Vector, t : Tile ) {
 		add(x, y, color.r, color.g, color.b, color.a, t);
 	}
 
-	public function add( x : Int, y : Int, r : Float, g : Float, b : Float, a : Float, t : Tile ) {
+	public function add( x : Float, y : Float, r : Float, g : Float, b : Float, a : Float, t : Tile ) {
 		var sx = x + t.dx;
 		var sy = y + t.dy;
 		tmp.push(sx);
@@ -79,7 +79,7 @@ private class TileLayerContent extends h3d.prim.Primitive {
 		if( y > yMax ) yMax = y;
 	}
 
-	public function addTransform( x : Int, y : Int, sx : Float, sy : Float, r : Float, c : h3d.Vector, t : Tile ) {
+	public function addTransform( x : Float, y : Float, sx : Float, sy : Float, r : Float, c : h3d.Vector, t : Tile ) {
 
 		var ca = Math.cos(r), sa = Math.sin(r);
 		var hx = t.width, hy = t.height;
@@ -437,19 +437,19 @@ class TileGroup extends Drawable {
 		curColor.w = alpha;
 	}
 
-	public inline function add(x : Int, y : Int, t : h2d.Tile) {
+	public inline function add(x : Float, y : Float, t : h2d.Tile) {
 		content.add(x, y, curColor.x, curColor.y, curColor.z, curColor.w, t);
 	}
 
-	public inline function addColor( x : Int, y : Int, r : Float, g : Float, b : Float, a : Float, t : Tile) {
+	public inline function addColor( x : Float, y : Float, r : Float, g : Float, b : Float, a : Float, t : Tile) {
 		content.add(x, y, r, g, b, a, t);
 	}
 
-	public inline function addAlpha(x : Int, y : Int, a : Float, t : h2d.Tile) {
+	public inline function addAlpha(x : Float, y : Float, a : Float, t : h2d.Tile) {
 		content.add(x, y, curColor.x, curColor.y, curColor.z, a, t);
 	}
 
-	public inline function addTransform(x : Int, y : Int, sx : Float, sy : Float, r : Float, t : Tile) {
+	public inline function addTransform(x : Float, y : Float, sx : Float, sy : Float, r : Float, t : Tile) {
 		content.addTransform(x, y, sx, sy, r, curColor, t);
 	}
 

+ 1 - 1
h2d/filter/ColorMatrix.hx

@@ -16,7 +16,7 @@ class ColorMatrix extends Filter {
 	inline function set_matrix(m) return pass.matrix = m;
 
 	override function draw( ctx : RenderContext, t : h2d.Tile ) {
-		var tout = ctx.textures.allocTarget("colorMatrixOut", t.width, t.height, false);
+		var tout = ctx.textures.allocTarget("colorMatrixOut", Std.int(t.width), Std.int(t.height), false);
 		pass.apply(t.getTexture(), tout);
 		return h2d.Tile.fromTexture(tout);
 	}

+ 1 - 1
h2d/filter/Displacement.hx

@@ -28,7 +28,7 @@ class Displacement extends Filter {
 	}
 
 	override function draw( ctx : RenderContext, t : h2d.Tile ) {
-		var out = ctx.textures.allocTarget("displacementOutput", t.width, t.height, false);
+		var out = ctx.textures.allocTarget("displacementOutput", Std.int(t.width), Std.int(t.height), false);
 		ctx.engine.pushTarget(out);
 		var s = disp.shader;
 		s.texture = t.getTexture();

+ 1 - 1
h2d/filter/DropShadow.hx

@@ -21,7 +21,7 @@ class DropShadow extends Glow {
 
 	override function draw( ctx : RenderContext, t : h2d.Tile ) {
 		setParams();
-		var save = ctx.textures.allocTarget("glowSave", t.width, t.height, false);
+		var save = ctx.textures.allocTarget("glowSave", Std.int(t.width), Std.int(t.height), false);
 		h3d.pass.Copy.run(t.getTexture(), save, None);
 		pass.apply(ctx, save);
 		var dx = Math.round(Math.cos(angle) * distance);

+ 1 - 1
h2d/filter/Glow.hx

@@ -25,7 +25,7 @@ class Glow extends Blur {
 		setParams();
 		var tex = t.getTexture();
 		var old = tex.filter;
-		var save = ctx.textures.allocTarget("glowSave", t.width, t.height, false);
+		var save = ctx.textures.allocTarget("glowSave", Std.int(t.width), Std.int(t.height), false);
 		h3d.pass.Copy.run(tex, save, None);
 		tex.filter = Linear;
 		pass.apply(ctx, tex);

+ 1 - 1
h2d/filter/Mask.hx

@@ -42,7 +42,7 @@ class Mask extends AbstractMask {
 		var mask = getMaskTexture(t);
 		if( mask == null )
 			throw "Mask should be rendered before masked object";
-		var out = ctx.textures.allocTarget("maskTmp", t.width, t.height, false);
+		var out = ctx.textures.allocTarget("maskTmp", Std.int(t.width), Std.int(t.height), false);
 		ctx.engine.pushTarget(out);
 		pass.shader.texture = t.getTexture();
 		pass.shader.mask = getMaskTexture(t);

+ 2 - 2
hxd/fmt/bfnt/FontParser.hx

@@ -260,10 +260,10 @@ class FontParser {
 		font.tile = tile;
 
 		if ( font.baseLine == 0 ) {
-			var padding = 0;
+			var padding : Float = 0;
 			var space = glyphs.get(" ".code);
 			if( space != null )
-				padding = (space.t.height >> 1);
+				padding = (space.t.height * .5);
 
 			var a = glyphs.get("A".code);
 			if( a == null )

+ 10 - 10
hxd/fmt/bfnt/Writer.hx

@@ -30,8 +30,8 @@ class Writer {
 		writeString(font.name);
 		out.writeInt16(font.size);
 		writeString(font.tilePath);
-		out.writeInt16(font.lineHeight);
-		out.writeInt16(font.baseLine);
+		out.writeInt16(Std.int(font.lineHeight));
+		out.writeInt16(Std.int(font.baseLine));
 		if (font.defaultChar != font.nullChar) {
 			var found = false;
 			for ( k in font.glyphs.keys() ) {
@@ -53,18 +53,18 @@ class Writer {
 			var glyph = font.glyphs.get(id);
 			var t = glyph.t;
 			out.writeInt32(id);
-			out.writeUInt16(t.x);
-			out.writeUInt16(t.y);
-			out.writeUInt16(t.width);
-			out.writeUInt16(t.height);
-			out.writeInt16(t.dx);
-			out.writeInt16(t.dy);
-			out.writeInt16(glyph.width);
+			out.writeUInt16(Std.int(t.x));
+			out.writeUInt16(Std.int(t.y));
+			out.writeUInt16(Std.int(t.width));
+			out.writeUInt16(Std.int(t.height));
+			out.writeInt16(Std.int(t.dx));
+			out.writeInt16(Std.int(t.dy));
+			out.writeInt16(Std.int(glyph.width));
 			var kern = @:privateAccess glyph.kerning;
 			while ( kern != null ) {
 				if (kern.prevChar != 0) {
 					out.writeInt32(kern.prevChar);
-					out.writeInt16(kern.offset);
+					out.writeInt16(Std.int(kern.offset));
 				}
 				kern = kern.next;
 			}