Debian Codegraph @

dojox/gfx/tests/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 <script type="text/javascript" src="../../../dojo/dojo.js"
10 data-dojo-config="isDebug: false"></script>
11 <script type="text/javascript">
12 dojo.require("dojox.gfx");
13 dojo.require("dojox.gfx.VectorText");
14
15 var bg="#181818", fill="#464b44", padding=32;
16
17 function makeShapes(surface){
18 var url = dojo.moduleUrl("dojox", "gfx/resources/Gillius.svg");
19 var f = new dojox.gfx.VectorFont(url);
20
21 // draw out the glyphs for testing.
22 var rect = surface.createRect({ x: 0, y: 0, width: 500, height: 560 })
23 .setFill(bg);
24 var g = surface.createGroup(), cx=0, count=0;
25 for(var gl in f.glyphs){
26 var glyph = f.glyphs[gl];
27 var t = g.createGroup();
28 if(glyph.path){
29 var p = t.createPath(glyph.path).setFill(fill);
30 }
31 t.setTransform([
32 dojox.gfx.matrix.flipY,
33 dojox.gfx.matrix.translate(cx, -f.viewbox.height-f.descent)
34 ]);
35 cx += glyph.xAdvance, count++;
36 g.createLine({
37 x1: cx, x2: cx, y1: 0, y2: f.viewbox.height
38 }).setStroke({color:"#409953", style:"Dash", width:1 });
39 }
40 cx -= glyph.xAdvance;
41 var factor = (500/f.viewbox.height)/2;
42 g.setTransform(dojox.gfx.matrix.scale(factor));
43 surface.setDimensions(cx*factor, (f.viewbox.height*factor)+padding*2);
44 rect.setShape({ x:0, y:0, width:cx*factor, height: (f.viewbox.height*factor)+padding*2 });
45 dojo.byId("test").style.height = Math.round(f.viewbox.height*factor)+padding*2+"px";
46
47 // try to find the baseline
48 surface.createLine({ x1: 0, x2: cx*factor,
49 y1: factor*(f.viewbox.height+f.descent), y2:factor*(f.viewbox.height+f.descent)
50 }).setStroke({ color: "#a36e2c" });
51
52 // lets do some measuring lines.
53 var s = "#70657e", axis = surface.createGroup();
54 // measurement axis
55 axis.createLine({ x1: 0, x2: cx*factor, y1: factor*f.viewbox.height+padding*2-1, y2: factor*f.viewbox.height+padding*2-1 })
56 .setStroke(s);
57
58 var major=50, minor=10, yMajor=20, yMinor=10, tick=5, steps=Math.floor(cx/minor);
59 for(var i=0; i<steps; i++){
60 // ticks
61 var xpos = i*minor, y2 = padding*2+factor*f.viewbox.height, y1 = (xpos%major==0)?y2-yMajor:y2-yMinor;
62 axis.createLine({ x1: xpos, x2: xpos, y1: y1, y2: y2 }).setStroke(s);
63 if(xpos%major==0){
64 axis.createText({ x: xpos, y: y1-4, text: xpos.toString(), align: "middle" })
65 .setFont({ family: "sans-serif", size:"8pt"})
66 .setFill(s);
67 }
68 }
69 }
70
71 function createSurface(){
72 var surface = dojox.gfx.createSurface("test", 500, 560);
73 surface.whenLoaded(makeShapes);
74 }
75
76 dojo.ready(createSurface);
77 </script>
78 </head>
79 <body>
80 <h1>dojox.gfx Vector Text test: loading a font</h1>
81 <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>
82 <div id="test" style="width: 500px; height: 560px;"></div>
83 </body>
84 </html>