| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>Test text bbox</title> |
| 5 | <script type="text/javascript" src="../../../dojo/dojo.js" data-dojo-config="isDebug: true, packageMap:[{name:'doh',location:'util/doh'}]"></script> |
| 6 | <script type="text/javascript"> |
| 7 | require([ |
| 8 | "doh/runner", |
| 9 | "dojo/ready", |
| 10 | "dojo/_base/window", |
| 11 | "dojox/gfx", |
| 12 | "dojox/gfx/shape", |
| 13 | "dojox/gfx/matrix"], |
| 14 | function(doh, ready, win, gfx, gfxshape, matrix){ |
| 15 | |
| 16 | var textShape = { x:20, y:40, text:"Hello !"}; |
| 17 | |
| 18 | ready(function(){ |
| 19 | var surface, r, |
| 20 | checkSurface = function(){ |
| 21 | if(!surface){ |
| 22 | surface = gfx.createSurface("gfxObject", 300, 300); |
| 23 | } |
| 24 | }; |
| 25 | |
| 26 | doh.register("text.getBoundingBox", [ |
| 27 | { |
| 28 | name: "text.getBoundingBox", |
| 29 | timeout: 1000, |
| 30 | setUp: function(){ |
| 31 | if(surface){ |
| 32 | surface.destroy(); |
| 33 | surface = null; |
| 34 | } |
| 35 | checkSurface(); |
| 36 | }, |
| 37 | runTest: function(t){ |
| 38 | var text = surface.createText(textShape).setFill("black"); |
| 39 | var bbox = text.getBoundingBox(); |
| 40 | t.assertTrue(bbox !== null, "Unexpected null bbox."); |
| 41 | // it's impossible to test for bbox coordinates as it varies depending on the browser... |
| 42 | }, |
| 43 | tearDown: function(){ |
| 44 | surface.clear(); |
| 45 | } |
| 46 | },{ |
| 47 | name: "getBoundingBox (empty string)", |
| 48 | timeout: 1000, |
| 49 | setUp: function(){ |
| 50 | if(surface){ |
| 51 | surface.destroy(); |
| 52 | surface = null; |
| 53 | } |
| 54 | checkSurface(); |
| 55 | }, |
| 56 | runTest: function(t){ |
| 57 | var text = surface.createText().setFill("black"); |
| 58 | var bbox = text.getBoundingBox(); |
| 59 | t.assertTrue(bbox == null, "Unexpected non-null bbox."); |
| 60 | }, |
| 61 | tearDown: function(){ |
| 62 | surface.clear(); |
| 63 | } |
| 64 | },{ |
| 65 | name: "getBoundingBox (orphan)", |
| 66 | timeout: 1000, |
| 67 | setUp: function(){ |
| 68 | if(surface){ |
| 69 | surface.destroy(); |
| 70 | surface = null; |
| 71 | } |
| 72 | checkSurface(); |
| 73 | }, |
| 74 | runTest: function(t){ |
| 75 | var text = surface.createText(textShape).setFill("black"); |
| 76 | text.removeShape(); |
| 77 | var bbox = text.getBoundingBox(); |
| 78 | t.assertTrue(bbox != null, "Unexpected bbox."); |
| 79 | t.assertTrue(bbox.x==0 && bbox.y==0 && bbox.width==0 && bbox.height==0, "Unexpected non empty bbox."); |
| 80 | var g = surface.createGroup(); |
| 81 | text = g.createText(textShape); |
| 82 | g.removeShape(); |
| 83 | bbox = text.getBoundingBox(); |
| 84 | t.assertTrue(bbox != null, "Unexpected bbox [2]."); |
| 85 | t.assertTrue(bbox.x==0 && bbox.y==0 && bbox.width==0 && bbox.height==0, "Unexpected non empty bbox.[2]"); |
| 86 | }, |
| 87 | tearDown: function(){ |
| 88 | surface.clear(); |
| 89 | } |
| 90 | },{ |
| 91 | name: "_getTextBox", |
| 92 | timeout: 1000, |
| 93 | runTest: function(t){ |
| 94 | var bbox = gfx._base._getTextBox(textShape.text); |
| 95 | t.assertTrue(bbox !== null, "Unexpected null bbox."); |
| 96 | // it's impossible to test for bbox coordinates as it varies depending on the browser... |
| 97 | // but at least verify that it is a {l,t,w,h} object |
| 98 | t.assertTrue("l" in bbox, "Not a bbox"); |
| 99 | t.assertTrue("t" in bbox, "Not a bbox"); |
| 100 | t.assertTrue("w" in bbox, "Not a bbox"); |
| 101 | t.assertTrue("h" in bbox, "Not a bbox"); |
| 102 | t.assertTrue(bbox.w > 0, "Not a bbox"); |
| 103 | t.assertTrue(bbox.h > 0, "Not a bbox"); |
| 104 | // and that the measuring node is invisible and empty after calling the function |
| 105 | t.assertEqual("hidden", win.body().lastChild.style.visibility, |
| 106 | "Document's last child should be invisible"); |
| 107 | t.assertEqual("", win.body().lastChild.innerHTML, |
| 108 | "Document's last child should be empty"); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | |
| 113 | ]); |
| 114 | doh.run(); |
| 115 | }); |
| 116 | }); |
| 117 | </script> |
| 118 | </head> |
| 119 | <body> |
| 120 | <div id="gfxObject" style="width: 500px; height: 500px;font-weight:bold;"></div> |
| 121 | </body> |
| 122 | </html> |