Revision: 1066
Author: allain.lalonde
Date: Wed Sep 1 12:01:18 2010
Log: fixing bug with measurements of text
http://code.google.com/p/piccolo2d/source/detail?r=1066
Modified:
/piccolo2d.js/trunk/piccolo2d.js
/piccolo2d.js/trunk/test.html
=======================================
--- /piccolo2d.js/trunk/piccolo2d.js Tue Aug 31 17:19:56 2010
+++ /piccolo2d.js/trunk/piccolo2d.js Wed Sep 1 12:01:18 2010
@@ -556,14 +556,20 @@
},
recomputeBounds: function() {
- var metric = PText.hiddenContext.measureText(this.text);
+ var metric = PText.hiddenContext.measureText(this.text);
this.bounds.width = metric.width;
this.bounds.height = this.text ? PText.fontSize : 0;
this.invalidateBounds();
}
});
- PText.hiddenContext =
document.createElement("canvas").getContext("2d");
+
PText.fontSize = 20;
+
+ PText.hiddenContext =
document.createElement("canvas").getContext("2d");
+ PText.hiddenContext.font = PText.fontSize + "px Arial";
+ PText.hiddenContext.textBaseline = "top";
+
+
PImage = PNode.extend({
=======================================
--- /piccolo2d.js/trunk/test.html Tue Aug 31 09:02:58 2010
+++ /piccolo2d.js/trunk/test.html Wed Sep 1 12:01:18 2010
@@ -537,6 +537,13 @@
ok(bounds.width != 0, "Bounds should have width when text is not
empty");
ok(bounds.height != 0, "Bounds should have height when text is
not empty");
});
+
+ test("FullBounds is correct", function() {
+ var t = new PText("Hello");
+ var bounds = t.getFullBounds();
+ equal(bounds.width, 43, "width of measured text is incorrect");
+ equal(bounds.height, 20, "height of measured text is incorrect");
+ });
}
function testPImage() {
--
Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en