Permalink
Browse files

Merge branch 'master' of github.com:dojo/dojox

  • Loading branch information...
kriszyp committed Feb 11, 2014
2 parents 8f3d699 + 12774a9 commit 44927a0cc614b03b014af04a9c90a2c2eb757a4e
Showing with 59 additions and 33 deletions.
  1. +8 −5 gfx/_base.js
  2. +3 −1 gfx/path.js
  3. +48 −27 gfx/tests/test_textbbox.html
View
@@ -101,12 +101,13 @@ function(kernel, lang, Color, has, win, arr, dom, domConstruct, domGeom){
/*Object*/ style,
/*String?*/ className){
var m, s, al = arguments.length;
- var i;
+ var i, box;
if(!measuringNode){
measuringNode = domConstruct.create("div", {style: {
position: "absolute",
top: "-10000px",
- left: "0"
+ left: "0",
+ visibility: "hidden"
}}, win.body());
}
m = measuringNode;
@@ -131,12 +132,14 @@ function(kernel, lang, Color, has, win, arr, dom, domConstruct, domGeom){
// take a measure
m.innerHTML = text;
- if(m["getBoundingClientRect"]){
+ if(m.getBoundingClientRect){
var bcr = m.getBoundingClientRect();
- return {l: bcr.left, t: bcr.top, w: bcr.width || (bcr.right - bcr.left), h: bcr.height || (bcr.bottom - bcr.top)};
+ box = {l: bcr.left, t: bcr.top, w: bcr.width || (bcr.right - bcr.left), h: bcr.height || (bcr.bottom - bcr.top)};
}else{
- return domGeom.getMarginBox(m);
+ box = domGeom.getMarginBox(m);
}
+ m.innerHTML = "";
+ return box;
};
b._computeTextLocation = function(/*g.defaultTextShape*/textShape, /*Number*/width, /*Number*/height, /*Boolean*/fixHeight) {
View
@@ -211,7 +211,9 @@ define(["./_base", "dojo/_base/lang","dojo/_base/declare", "./matrix", "./shape"
if(typeof this.shape.path == "string"){
this.shape.path += path.join("");
}else{
- Array.prototype.push.apply(this.shape.path, path); //FIXME: why not simple push()?
+ for(i = 0, l = path.length; i < l; ++i){
+ this.shape.path.push(path[i]);
+ }
}
},
@@ -7,10 +7,11 @@
require([
"doh/runner",
"dojo/ready",
+ "dojo/_base/window",
"dojox/gfx",
"dojox/gfx/shape",
"dojox/gfx/matrix"],
- function(doh, ready, gfx, gfxshape, matrix){
+ function(doh, ready, win, gfx, gfxshape, matrix){
var textShape = { x:20, y:40, text:"Hello !"};
@@ -61,32 +62,52 @@
surface.clear();
}
},{
- name: "getBoundingBox (orphan)",
- timeout: 1000,
- setUp: function(){
- if(surface){
- surface.destroy();
- surface = null;
- }
- checkSurface();
- },
- runTest: function(t){
- var text = surface.createText(textShape).setFill("black");
- text.removeShape();
- var bbox = text.getBoundingBox();
- t.assertTrue(bbox != null, "Unexpected bbox.");
- t.assertTrue(bbox.x==0 && bbox.y==0 && bbox.width==0 && bbox.height==0, "Unexpected non empty bbox.");
- var g = surface.createGroup();
- text = g.createText(textShape);
- g.removeShape();
- bbox = text.getBoundingBox();
- t.assertTrue(bbox != null, "Unexpected bbox [2].");
- t.assertTrue(bbox.x==0 && bbox.y==0 && bbox.width==0 && bbox.height==0, "Unexpected non empty bbox.[2]");
- },
- tearDown: function(){
- surface.clear();
- }
- }
+ name: "getBoundingBox (orphan)",
+ timeout: 1000,
+ setUp: function(){
+ if(surface){
+ surface.destroy();
+ surface = null;
+ }
+ checkSurface();
+ },
+ runTest: function(t){
+ var text = surface.createText(textShape).setFill("black");
+ text.removeShape();
+ var bbox = text.getBoundingBox();
+ t.assertTrue(bbox != null, "Unexpected bbox.");
+ t.assertTrue(bbox.x==0 && bbox.y==0 && bbox.width==0 && bbox.height==0, "Unexpected non empty bbox.");
+ var g = surface.createGroup();
+ text = g.createText(textShape);
+ g.removeShape();
+ bbox = text.getBoundingBox();
+ t.assertTrue(bbox != null, "Unexpected bbox [2].");
+ t.assertTrue(bbox.x==0 && bbox.y==0 && bbox.width==0 && bbox.height==0, "Unexpected non empty bbox.[2]");
+ },
+ tearDown: function(){
+ surface.clear();
+ }
+ },{
+ name: "_getTextBox",
+ timeout: 1000,
+ runTest: function(t){
+ var bbox = gfx._base._getTextBox(textShape.text);
+ t.assertTrue(bbox !== null, "Unexpected null bbox.");
+ // it's impossible to test for bbox coordinates as it varies depending on the browser...
+ // but at least verify that it is a {l,t,w,h} object
+ t.assertTrue("l" in bbox, "Not a bbox");
+ t.assertTrue("t" in bbox, "Not a bbox");
+ t.assertTrue("w" in bbox, "Not a bbox");
+ t.assertTrue("h" in bbox, "Not a bbox");
+ t.assertTrue(bbox.w > 0, "Not a bbox");
+ t.assertTrue(bbox.h > 0, "Not a bbox");
+ // and that the measuring node is invisible and empty after calling the function
+ t.assertEqual("hidden", win.body().lastChild.style.visibility,
+ "Document's last child should be invisible");
+ t.assertEqual("", win.body().lastChild.innerHTML,
+ "Document's last child should be empty");
+ }
+ }
]);

0 comments on commit 44927a0

Please sign in to comment.