| 1 |
<?xml version="1.0" standalone="no"?> |
| 2 |
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" |
| 3 |
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> |
| 4 |
|
| 5 |
<!-- |
| 6 |
|
| 7 |
Licensed to the Apache Software Foundation (ASF) under one or more |
| 8 |
contributor license agreements. See the NOTICE file distributed with |
| 9 |
this work for additional information regarding copyright ownership. |
| 10 |
The ASF licenses this file to You under the Apache License, Version 2.0 |
| 11 |
(the "License"); you may not use this file except in compliance with |
| 12 |
the License. You may obtain a copy of the License at |
| 13 |
|
| 14 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 15 |
|
| 16 |
Unless required by applicable law or agreed to in writing, software |
| 17 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 18 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 19 |
See the License for the specific language governing permissions and |
| 20 |
limitations under the License. |
| 21 |
|
| 22 |
--> |
| 23 |
<!-- ====================================================================== --> |
| 24 |
<!-- Test of getting/setting current Scale and Translate. --> |
| 25 |
<!-- --> |
| 26 |
<!-- @author [email protected] --> |
| 27 |
<!-- @version $Id$ --> |
| 28 |
<!-- ====================================================================== --> |
| 29 |
|
| 30 |
<?xml-stylesheet type="text/css" href="../../resources/style/test.css" ?> |
| 31 |
|
| 32 |
<svg id="body" width="450" height="500" viewBox="0 0 450 500" |
| 33 |
onload="setScaleTrans(2, 50, 50), update()" |
| 34 |
xmlns="http://www.w3.org/2000/svg" |
| 35 |
xmlns:xlink="http://www.w3.org/1999/xlink"> |
| 36 |
|
| 37 |
<title>svg current scale/translate modification</title> |
| 38 |
|
| 39 |
<script type="text/ecmascript"><![CDATA[ |
| 40 |
var count = 1; |
| 41 |
function setScaleTrans(scale, newX, newY) { |
| 42 |
document.getRootElement().currentScale = scale; |
| 43 |
var pt = document.getRootElement().currentTranslate; |
| 44 |
pt.x = newX; |
| 45 |
pt.y = newX; |
| 46 |
} |
| 47 |
|
| 48 |
function update() { |
| 49 |
if ((count%10) == 0) { |
| 50 |
var scale = 1+((count/10)%10)/4; |
| 51 |
document.getRootElement().currentScale = scale; |
| 52 |
} |
| 53 |
|
| 54 |
var t; |
| 55 |
var mat; |
| 56 |
t = document.getElementById('cnt'); |
| 57 |
t.firstChild.data = ("Count: " + count); |
| 58 |
|
| 59 |
mat = t.getScreenCTM(); |
| 60 |
t = document.getElementById('foo'); |
| 61 |
t.firstChild.data = |
| 62 |
"The ScrnCTM is: (" + mat.a +","+ mat.b +","+ mat.c +","+ mat.d +","+ mat.e +","+ mat.f +")"; |
| 63 |
|
| 64 |
mat = t.getCTM(); |
| 65 |
t = document.getElementById('bar'); |
| 66 |
t.firstChild.data = |
| 67 |
"The CTM is: (" + mat.a +","+ mat.b +","+ mat.c +","+ mat.d +","+ mat.e +","+ mat.f +")"; |
| 68 |
|
| 69 |
var scale = document.getRootElement().currentScale; |
| 70 |
t = document.getElementById('baz'); |
| 71 |
t.firstChild.data = "The Scale is: "+scale; |
| 72 |
|
| 73 |
var trans = document.getRootElement().currentTranslate; |
| 74 |
t = document.getElementById('bat'); |
| 75 |
t.firstChild.data = "The Trans is ["+trans.x+", " +trans.y+"]"; |
| 76 |
|
| 77 |
t = document.getElementById('vp'); |
| 78 |
var vp = document.rootElement.viewport; |
| 79 |
t.firstChild.data = ("Viewport: ["+ vp.x+", " +vp.y+", " + |
| 80 |
vp.width+", " +vp.height+"]"); |
| 81 |
|
| 82 |
count++; |
| 83 |
setTimeout('update()', 1000); |
| 84 |
} |
| 85 |
|
| 86 |
function mouseOver(evt) { |
| 87 |
t = document.getElementById('rec'); |
| 88 |
var x = evt.getClientX(); |
| 89 |
var y = evt.getClientY(); |
| 90 |
mat = t.getScreenCTM(); |
| 91 |
imat = mat.inverse(); |
| 92 |
var pt = document.getRootElement().createSVGPoint(); |
| 93 |
pt.x = x; |
| 94 |
pt.y = y; |
| 95 |
pt = pt.matrixTransform(imat); |
| 96 |
t.firstChild.data = ("Loc: [" + evt.getClientX() + ", " + |
| 97 |
evt.getClientY() + "] [" + |
| 98 |
pt.x + ", " + pt.y + "]"); |
| 99 |
} |
| 100 |
]]></script> |
| 101 |
|
| 102 |
<g id="test-content"> |
| 103 |
<rect x="0" y="0" width="450" height="500" |
| 104 |
fill="lightgrey" stroke="black" |
| 105 |
onmousemove="mouseOver(evt)"/> |
| 106 |
<text id="cnt" x="10" y=" 80">test</text> |
| 107 |
<text id="foo" x="10" y="100">test</text> |
| 108 |
<text id="bar" x="10" y="120">test</text> |
| 109 |
<text id="baz" x="10" y="140">test</text> |
| 110 |
<text id="bat" x="10" y="160">test</text> |
| 111 |
<text id="vp" x="10" y="180">test</text> |
| 112 |
<text id="rec" x="10" y="200">test</text> |
| 113 |
</g> |
| 114 |
</svg> |