/usr/share/doc/libjs-excanvas/examples/example3.html is in libjs-excanvas 0.r3-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | <!DOCTYPE html>
<!--
Copyright 2006 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!--[if IE]><script type="text/javascript" src="../excanvas.js"></script><![endif]-->
<style type="text/css">
body {
overflow: hidden;
width: 100%;
height: 100%;
margin: 0;
}
#image-rotator {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
}
#image-rotator .tool-bar {
text-align: center;
}
.tool-bar button {
margin: 0.5em 0.5em 0 0;
}
#image-rotator img,
#image-rotator canvas {
position: absolute;
}
</style>
<script type="text/javascript">
function sawFunc(a) {
var PI = Math.PI;
var PI2 = PI / 2;
// make sure a is within 0 to PI
a = a % PI;
if (a < 0) {
a += PI;
}
if (a < PI2) {
return a / PI2;
} else {
return (PI - a) / PI2;
}
}
function easeInEaseOut(t) {
var t2 = t * t;
return 3 * t2 - 2 * t * t2;
}
function ImageRotator(el, src, w, h) {
this.element = el;
this.toolBar = el.getElementsByTagName("div")[0];
this.canvas = el.getElementsByTagName("canvas")[0];
var images = el.getElementsByTagName("img");
this.image = images[images.length - 1];
var btns = el.getElementsByTagName("button");
this.btnCw = btns[0];
this.btnCcw = btns[1];
var self = this;
this.btnCcw.onclick = function () {
self.rotateCcw();
};
this.btnCw.onclick = function () {
self.rotateCw();
};
this.image.onload = function (e) {
self.onImageLoad(e);
};
this.image.onerror = function (e) {
self.onImageError(e);
};
this.image.onabort = function (e) {
self.onImageAbort(e);
};
this.setImage(src, w, h);
this.layout();
var onResize = function () {
self.layout();
};
var onLoad = function () {
self.onWindowLoad();
};
if (window.addEventListener) {
window.addEventListener("resize", onResize, false);
window.addEventListener("load", onLoad, false);
} else if (window.attachEvent) {
window.attachEvent("onresize", onResize);
window.attachEvent("onload", onLoad);
}
}
ImageRotator.prototype = {
getLoaded: function () {
return this.imageLoaded && this.windowLoaded;
},
setImage: function (src, w, h) {
this.imageLoaded = false;
this.image.src = src;
this.imageWidth = w;
this.imageHeight = h;
},
layout: function () {
var PI2 = Math.PI / 2;
var h = this.element.clientHeight;
var w = this.element.clientWidth;
var th = this.toolBar.offsetHeight;
h -= this.toolBar.offsetHeight;
if (!this.ctx || !this.getLoaded()) {
this.btnCw.disabled = true;
this.btnCcw.disabled = true;
this.canvas.style.display = "none";
this.image.style.display = "block";
var ratio = Math.min(w / this.imageWidth, h / this.imageHeight, 1);
var imgW = this.imageWidth * ratio;
var imgH = this.imageHeight * ratio;
var y = th + (h - imgH) / 2;
var x = (w - imgW) / 2;
this.image.style.left = Math.round(x) + "px";
this.image.style.top = Math.round(y) + "px";
this.image.style.width = Math.round(imgW) + "px";
this.image.style.height = Math.round(imgH) + "px";
} else {
this.btnCw.disabled = this.isAnimating_;
this.btnCcw.disabled = this.isAnimating_;
this.canvas.style.display = "block";
this.image.style.display = "none";
this.canvas.style.left = 0 + "px";
this.canvas.style.top = th + "px";
this.canvas.style.width = w + "px";
this.canvas.width = w;
this.canvas.style.height = h + "px";
this.canvas.height = h;
this.ctx.save();
this.ctx.clearRect(0, 0, w, h);
this.ctx.translate(w / 2, h / 2);
this.ctx.rotate(this.rotation);
// 0 -> 1, sin(0) = 0
// PI / 2 -> H / W, sin(PI/2) = 1
// sin(PI/2) = 1 -> limit factor is w and imgH
var iw = this.imageWidth;
var ih = this.imageHeight;
var scale;
if (iw <= w && iw <= h && ih <= h && ih <= w) {
scale = 1;
} else {
var sinr = sawFunc(this.rotation);
var cosr = sawFunc(this.rotation + PI2);
var ratio1 = sinr * Math.min(w / ih, h / iw);
var ratio2 = cosr * Math.min(w / iw, h / ih);
var ratio = Math.min(1, ratio1 + ratio2);
scale = ratio;
}
this.ctx.scale(scale, scale);
this.ctx.translate(-iw / 2, -ih / 2);
this.ctx.drawImage(this.image, 0, 0, iw, ih);
this.ctx.restore();
}
},
rotation: 0,
animationDuration: 500,
rotateCcw: function () {
if (!this.isAnimating_) {
this.startTime_ = (new Date).valueOf();
this.currentAngle_ = this.rotation;
this.deltaAngle_ = Math.PI / 2;
this.isAnimating_ = true;
this.animCounter_ = 0;
this.rotate_();
}
},
rotateCw: function () {
if (!this.isAnimating_) {
this.startTime_ = (new Date).valueOf();
this.currentAngle_ = this.rotation;
this.deltaAngle_ = -Math.PI / 2;
this.isAnimating_ = true;
this.animCounter_ = 0;
this.rotate_();
}
},
rotate_: function () {
if (this.isAnimating_) {
var t = easeInEaseOut(Math.min(1, (new Date - this.startTime_) /
this.animationDuration));
this.rotation = t * this.deltaAngle_ + this.currentAngle_;
if (t < 1) {
var self = this;
window.setTimeout(function () {
self.rotate_();
}, 10);
} else {
this.isAnimating_ = false;
}
this.layout();
}
},
onImageLoad: function (e) {
this.imageLoaded = true;
this.initCanvas();
},
onImageError: function (e) {
this.imageLoaded = false;
},
onImageAbort: function (e) {
this.imageLoaded = false;
},
onWindowLoad: function (e) {
this.windowLoaded = true;
this.initCanvas();
},
initCanvas: function () {
if (!this.ctx && this.getLoaded()) {
// IE recreates the element?
this.canvas = this.element.getElementsByTagName("canvas")[0];
this.ctx = this.canvas.getContext("2d");
if (!this.ctx) {
return;
}
this.layout();
}
}
};
</script>
</head>
<body>
<div id="image-rotator">
<div class="tool-bar">
<button>Rotate Left</button><button>Rotate Right</button>
</div>
<canvas id="c"></canvas>
<img src="" alt="">
</div>
<script type="text/javascript">
new ImageRotator(document.getElementById("image-rotator"),
"ff.jpg", 608, 380);
</script>
</body>
</html>
|