Debian Codegraph @

dojox/gfx/tests/svgweb/test_vectortext_load.html

raw symbols SCIP
1 <html>
2 <head>
3 <title>DojoX GFX: Vector Text test: load and display a font</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 <!-- SVGWEB { -->
10 <meta name="svg.render.forceflash" content="true"/>
11 <script src="svgweb/src/svg.js" data-path="svgweb/src"></script>
12 <script src="../../../../dojo/dojo.js" data-dojo-config="isDebug:true,forceGfxRenderer:'svg'" type="text/javascript"></script>
13 <!-- } -->
14 <script type="text/javascript">
15 dojo.require("dojox.gfx");
16 dojo.require("dojox.gfx.VectorText");
17
18 var bg="#181818", fill="#464b44", padding=32;
19 dojo.addOnLoad(function(){
20 var url = dojo.moduleUrl("dojox", "gfx/resources/Gillius.svg");
21 var f = new dojox.gfx.VectorFont(url);
22
23 // don't do too much, svgweb is slow~~~
24 for (var i in f.glyphs) {
25 if (i < 'a' || i > 'z') {
26 delete f.glyphs[i];
27 }
28 }
29
30 // draw out the glyphs for testing.
31 var surface = dojox.gfx.createSurface("test", 2500, 560);
32 /* SVGWEB { */
33 surface.whenLoaded(function() {
34 var start = new Date().getTime();
35 var suspendId = surface.rawNode.suspendRedraw(10000000);
36 var rect = surface.createRect({ x: 0, y: 0, width: 2500, height: 560 })
37 .setFill(bg);
38 var g = surface.createGroup(), cx=0, count=0;
39 for(var gl in f.glyphs){
40 var glyph = f.glyphs[gl];
41 var t = g.createGroup();
42 if(glyph.path){
43 var p = t.createPath(glyph.path).setFill(fill);
44 }
45 t.setTransform([
46 dojox.gfx.matrix.flipY,
47 dojox.gfx.matrix.translate(cx, -f.viewbox.height-f.descent)
48 ]);
49 cx += glyph.xAdvance, count++;
50 g.createLine({
51 x1: cx, x2: cx, y1: 0, y2: f.viewbox.height
52 }).setStroke({color:"#409953", style:"Dash", width:1 });
53 }
54 cx -= glyph.xAdvance;
55 var factor = (500/f.viewbox.height)/2;
56 g.setTransform(dojox.gfx.matrix.scale(factor));
57 surface.setDimensions(cx*factor, (f.viewbox.height*factor)+padding*2);
58 rect.setShape({ x:0, y:0, width:cx*factor, height: (f.viewbox.height*factor)+padding*2 });
59 dojo.byId("test").style.height = Math.round(f.viewbox.height*factor)+padding*2+"px";
60
61 // try to find the baseline
62 surface.createLine({ x1: 0, x2: cx*factor,
63 y1: factor*(f.viewbox.height+f.descent), y2:factor*(f.viewbox.height+f.descent)
64 }).setStroke({ color: "#a36e2c" });
65
66 // lets do some measuring lines.
67 var s = "#70657e", axis = surface.createGroup();
68 // measurement axis
69 axis.createLine({ x1: 0, x2: cx*factor, y1: factor*f.viewbox.height+padding*2-1, y2: factor*f.viewbox.height+padding*2-1 })
70 .setStroke(s);
71
72 var major=50, minor=10, yMajor=20, yMinor=10, tick=5, steps=Math.floor(cx/minor);
73 for(var i=0; i<steps; i++){
74 // ticks
75 var xpos = i*minor, y2 = padding*2+factor*f.viewbox.height, y1 = (xpos%major==0)?y2-yMajor:y2-yMinor;
76 axis.createLine({ x1: xpos, x2: xpos, y1: y1, y2: y2 }).setStroke(s);
77 if(xpos%major==0){
78 axis.createText({ x: xpos, y: y1-4, text: xpos.toString(), align: "middle" })
79 .setFont({ family: "sans-serif", size:"8pt"})
80 .setFill(s);
81 }
82 }
83
84 surface.rawNode.unsuspendRedraw(suspendId);
85 alert(new Date().getTime() - start);
86 });
87 /* } */
88
89 });
90 </script>
91 </head>
92 <body>
93 <h1>dojox.gfx Vector Text test: loading a font</h1>
94 <p>This is a test of the new VectorText functionality; we load up an SVG Font definition and use it to render text (as opposed to tapping into a browser's native text capability).</p>
95 <div id="test" style="width: 500px; height: 560px;"></div>
96 </body>
97 </html>