test_text.html 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <html>
  2. <head>
  3. <title>Testing text</title>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <style type="text/css">
  6. @import "../../../dojo/resources/dojo.css";
  7. @import "../../../dijit/tests/css/dijitTests.css";
  8. </style>
  9. <!--
  10. The next line should include Microsoft's Silverligth.js, if you plan to use the silverlight backend
  11. <script type="text/javascript" src="Silverlight.js"></script>
  12. -->
  13. <script type="text/javascript" src="../../../dojo/dojo.js" djConfig="isDebug: true"></script>
  14. <!--
  15. <script type="text/javascript" src="../common.js"></script>
  16. <script type="text/javascript" src="../shape.js"></script>
  17. -->
  18. <!--<script type="text/javascript" src="../vml.js"></script>-->
  19. <!--<script type="text/javascript" src="../svg.js"></script>-->
  20. <!--<script type="text/javascript" src="../silverlight.js"></script>-->
  21. <script type="text/javascript">
  22. dojo.require("dojox.gfx");
  23. var ROTATION = 30;
  24. var surface = null, t1, t2, t3, t4, t5;
  25. var placeAnchor = function(surface, x, y){
  26. surface.createLine({x1: x - 2, y1: y, x2: x + 2, y2: y}).setStroke("blue");
  27. surface.createLine({x1: x, y1: y - 2, x2: x, y2: y + 2}).setStroke("blue");
  28. };
  29. var makeText = function(surface, text, font, fill, stroke){
  30. var t = surface.createText(text);
  31. if(font) t.setFont(font);
  32. if(fill) t.setFill(fill);
  33. if(stroke) t.setStroke(stroke);
  34. placeAnchor(surface, text.x, text.y);
  35. return t;
  36. };
  37. makeShapes = function(){
  38. surface = dojox.gfx.createSurface("test", 500, 500);
  39. var m = dojox.gfx.matrix;
  40. surface.createLine({x1: 250, y1: 0, x2: 250, y2: 500}).setStroke("green");
  41. t1 = makeText(surface, {x: 250, y: 50, text: "Start", align: "start"},
  42. {family: "Times", size: "36pt", weight: "bold"}, "black", "red")
  43. .setTransform(m.rotategAt(ROTATION, 250, 50))
  44. ;
  45. t2 = makeText(surface, {x: 250, y: 100, text: "Middle", align: "middle"},
  46. {family: "Symbol", size: "24pt"}, "red", "black")
  47. .setTransform(m.rotategAt(ROTATION, 250, 100))
  48. ;
  49. t3 = makeText(surface, {x: 250, y: 150, text: "End", align: "end"},
  50. {family: "Helvetica", style: "italic", size: "18pt", rotated: true}, "#FF8000")
  51. .setTransform(m.rotategAt(ROTATION, 250, 150))
  52. ;
  53. t4 = makeText(surface, {x: 250, y: 200, text: "Define Shuffle Tiff", align: "middle", kerning: true},
  54. {family: "serif", size: "36pt"}, "black")
  55. .setTransform(m.rotategAt(0, 250, 200))
  56. ;
  57. t5 = makeText(surface, {x: 250, y: 250, text: "Define Shuffle Tiff", align: "middle", kerning: false},
  58. {family: "serif", size: "36pt"}, "black")
  59. .setTransform(m.rotategAt(0, 250, 250))
  60. ;
  61. };
  62. getSizes = function(){
  63. var t = [];
  64. dojo.forEach(["t1", "t2", "t3", "t4", "t5"], function(name){
  65. var node = eval("(" + name + ")");
  66. t.push(node.getShape().text + " = " + node.getTextWidth());
  67. });
  68. dojo.byId("sizes").innerHTML = t.join("<br/>");
  69. };
  70. dojo.addOnLoad(makeShapes);
  71. </script>
  72. </head>
  73. <body>
  74. <h1>dojox.gfx Text test</h1>
  75. <div id="test" style="width: 500px; height: 500px;"></div>
  76. <div><button onclick="surface.clear();">Clear</button>&nbsp;<button onclick="getSizes();">Get sizes</button></div>
  77. <p id="sizes">&nbsp;</p>
  78. <p>That's all Folks!</p>
  79. </body>
  80. </html>