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