sandbox.html (14708B)
1 <?xml version="1.0" encoding="iso-8859-1"?> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 4 <html xmlns="http://www.w3.org/1999/xhtml" 5 lang="en" xml:lang="en"> 6 <head> 7 <title>WPS Sandbox</title> 8 <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"/> 9 <meta name="generator" content="Org-mode"/> 10 <meta name="generated" content="2009-07-21 11:33:22 CEST"/> 11 <meta name="author" content="Tomas Hlavaty"/> 12 <meta name="description" content="PostScript and PDF interpreter for HTML 5 canvas"/> 13 <meta name="keywords" content="PostScript, PDF, interpreter, HTML 5, canvas, JavaScript"/> 14 15 <link rel="stylesheet" href="../../logand.css" type="text/css"/> 16 <link rel="icon" href="../../favicon.ico" type="image/x-icon"/> 17 <link rel="shortcut icon" href="../../favicon.ico" type="image/x-icon"/> 18 <script type="text/javascript"> 19 <!--/*--><![CDATA[/*><!--*/ 20 function CodeHighlightOn(elem, id) 21 { 22 var target = document.getElementById(id); 23 if(null != target) { 24 elem.cacheClassElem = elem.className; 25 elem.cacheClassTarget = target.className; 26 target.className = "code-highlighted"; 27 elem.className = "code-highlighted"; 28 } 29 } 30 function CodeHighlightOff(elem, id) 31 { 32 var target = document.getElementById(id); 33 if(elem.cacheClassElem) 34 elem.className = elem.cacheClassElem; 35 if(elem.cacheClassTarget) 36 target.className = elem.cacheClassTarget; 37 } 38 /*]]>*///--> 39 </script> 40 </head> 41 <body> 42 <div id="content"> 43 44 <div id="menu"> 45 <div> 46 <table width="100%"> 47 <tr> 48 <td> 49 <table> 50 <tr> 51 <td><img src="../../logand1.png" alt="logo"/></td> 52 <td align="center"> 53 <img src="../../logand2.png" alt="url"/><br/> 54 web & software development 55 </td> 56 </tr> 57 </table> 58 </td> 59 <td class="menu3"> 60 <span> 61 <a href="../../index.html">Home</a> 62 | <a href="../../sw/index.html">Software</a> 63 | <a href="../../blog/index.html">Blog</a> 64 | <a href="../../contact.html">Contact</a> 65 </span> 66 </td> 67 </tr> 68 </table> 69 </div> 70 </div> 71 <div> 72 73 74 <div id="outline-container-1" class="outline-1"> 75 <h1 id="sec-1">WPS sandbox </h1> 76 <div class="outline-text-1" id="text-1"> 77 78 79 80 81 <div id="wps" style="display:none"> 82 83 <pre class="src src-text"> 84 %%% (c) 2009 Tomas Hlavaty 85 86 currentdict/systemdict currentdict put 87 systemdict/{/mark cvx put 88 systemdict/[/mark cvx put 89 systemdict/] 90 /counttomark cvx 91 /array cvx 92 /astore cvx 93 /exch cvx 94 /pop cvx 95 5 array astore cvx put 96 systemdict/}/] cvx/cvx cvx 2 array astore cvx put 97 systemdict/def{currentdict 2 index 2 index put pop pop}put 98 99 /maxlength 1000 def % TODO 100 /.bdef{bind def}bind def 101 /.xdef{exch def}.bdef 102 /dup{0 index}.bdef 103 /load{dup where pop exch get}.bdef 104 /.ldef{load def}.bdef 105 /if{{}ifelse}.bdef 106 /cleartomark{array pop}.bdef 107 /known{exch begin where{currentdict eq}{false}if end}.bdef 108 /store{1 index where{3 1 roll put}{def}ifelse}.bdef 109 /not{{false}{true}ifelse}.bdef 110 /.logand{{{true}{false}ifelse}{pop false}ifelse}.bdef 111 /and/.logand .ldef % TODO numeric and 112 /.logor{{pop true}{{true}{false}ifelse}ifelse}.bdef 113 /or/.logor .ldef % TODO numeric or 114 /ne{eq not}.bdef 115 /ge{lt not}.bdef 116 /le{1 index 1 index eq 3 1 roll lt or}.bdef 117 /gt{le not}.bdef 118 /.repeat{1 1 4 2 roll for}.bdef 119 120 %% math 121 122 /floor{.math(floor)1 .call}.bdef 123 124 /neg{0 exch sub}.bdef 125 /add{neg sub}.bdef 126 /idiv{div floor}.bdef 127 128 /abs{.math(abs)1 .call}.bdef 129 /.acos{.math(acos)1 .call}.bdef 130 /.asin{.math(asin)1 .call}.bdef 131 /atan{exch .math(atan)1 .call}.bdef 132 /.atan2{.math(atan2)2 .call}.bdef 133 /ceiling{.math(ceil)1 .call}.bdef 134 /cos{.math(cos)1 .call}.bdef 135 /.exp{.math(exp)1 .call}.bdef 136 /log{.math(log)1 .call}.bdef 137 /.max{.math(max)2 .call}.bdef 138 /.min{.math(min)2 .call}.bdef 139 /.pow{.math(pow)2 .call}.bdef 140 /.random{.math(random)0 .call}.bdef 141 /rand{.random}.bdef % TODO follow spec 142 /round{.math(round)1 .call}.bdef 143 /sin{.math(sin)1 .call}.bdef 144 /sqrt{.math(sqrt)1 .call}.bdef 145 /.tan{.math(tan)1 .call}.bdef 146 /truncate{.math(truncate)1 .call}.bdef % TODO Math.truncate does not exist! 147 148 /.e{.math(E)get}.bdef 149 /.ln2{.math(LN2)get}.bdef 150 /.ln10{.math(LN10)get}.bdef 151 /.log2e{.math(LOG2E)get}.bdef 152 /.log10e{.math(LOG10E)get}.bdef 153 /.pi{.math(PI)get}.bdef 154 /.sqrt1_2{.math(SQRT1_2)get}.bdef 155 /.sqrt2{.math(SQRT2)get}.bdef 156 157 %% html 158 159 /.setTimeout{.window(setTimeout)2 .call}.bdef % cb ms -- id 160 /.clearTimeout{.window(clearTimeout)1 .call pop}.bdef % id -- 161 /.setInterval{.window(setInterval)2 .call}.bdef % cb ms -- id 162 /.clearInterval{.window(clearInterval)1 .call pop}.bdef % id -- 163 /.document{.window(document)get}.bdef % -- document 164 /.getElementById{.document(getElementById)1 .call}.bdef % id -- w 165 /.hook{put}.bdef % e k cb -- 166 167 %% canvas 168 169 /.setGc{.getElementById(2d)exch(getContext)1 .call/.$gc .xdef}.bdef 170 /.gc{/.$gc load}.bdef 171 /.gget{.gc exch get}.bdef 172 /.gput{.gc 3 1 roll exch put}.bdef 173 /.gcall0{.gc 3 1 roll .call pop}.bdef 174 /.gcall1{.gc 3 1 roll .call}.bdef 175 /.gcanvas{(canvas).gget}.bdef 176 /.gdim{.gcanvas exch(height)exch put .gcanvas exch(width)exch put}.bdef 177 /.gbox{.gdim pop pop}.bdef % TODO compute properly 178 179 /.save{(save)0 .gcall0}.bdef 180 /.restore{(restore)0 .gcall0}.bdef 181 /.scale{(scale)2 .gcall0}.bdef 182 /.rotate{(rotate)1 .gcall0}.bdef 183 /.translate{(translate)2 .gcall0}.bdef 184 /.transform{(transform)6 .gcall0}.bdef 185 /.setTransform{(setTransform)6 .gcall0}.bdef 186 /.createLinearGradient{(createLinearGradient)4 .gcall1}.bdef 187 /.createRadialGradient{(createRadialGradient)6 .gcall1}.bdef 188 /.createPattern{(createPattern)2 .gcall1}.bdef 189 /.clearRect{(clearRect)4 .gcall0}.bdef 190 /.fillRect{(fillRect)4 .gcall0}.bdef 191 /.strokeRect{(strokeRect)4 .gcall0}.bdef 192 /.beginPath{(beginPath)0 .gcall0}.bdef 193 /.closePath{(closePath)0 .gcall0}.bdef 194 /.moveTo{(moveTo)2 .gcall0}.bdef 195 /.lineTo{(lineTo)2 .gcall0}.bdef 196 /.quadraticCurveTo{(quadraticCurveTo)4 .gcall0}.bdef 197 /.bezierCurveTo{(bezierCurveTo)6 .gcall0}.bdef 198 /.arcTo{(arcTo)5 .gcall0}.bdef 199 /.rect{(rect)4 .gcall0}.bdef 200 /.arc{(arc)6 .gcall0}.bdef 201 /.fill{(fill)0 .gcall0}.bdef 202 /.stroke{(stroke)0 .gcall0}.bdef 203 /.clip{(clip)0 .gcall0}.bdef 204 /.isPointInPath{(isPointInPath)2 .gcall1}.bdef 205 /.fillText{(fillText)4 .gcall0}.bdef 206 /.fillText{}.bdef % TODO not working in Firefox 207 /.strokeText{(strokeText)4 .gcall0}.bdef 208 /.strokeText{}.bdef % TODO not working in Firefox 209 /.measureText{(measureText)1 .gcall1}.bdef 210 /.drawImage1{(drawImage1)5 .gcall0}.bdef 211 /.drawImage2{(drawImage2)9 .gcall0}.bdef 212 /.createImageData1{(createImageData1)1 .gcall1}.bdef 213 /.createImageData2{(createImageData2)2 .gcall1}.bdef 214 /.getImageData{(getImageData)4 .gcall1}.bdef 215 /.putImageData{(putImageData)7 .gcall0}.bdef 216 217 /.getGlobalAlpha{(globalAlpha).gget}.bdef 218 /.getGlobalCompositeOperation{(globalCompositeOperation).gget}.bdef 219 /.getStrokeStyle{(strokeStyle).gget}.bdef 220 /.getFillStyle{(fillStyle).gget}.bdef 221 /.getLineWidth{(lineWidth).gget}.bdef 222 /.getLineCap{(lineCap).gget}.bdef 223 /.getLineJoin{(lineJoin).gget}.bdef 224 /.getMiterLimit{(miterLimit).gget}.bdef 225 /.getShadowOffsetX{(shadowOffsetX).gget}.bdef 226 /.getShadowOffsetY{(shadowOffsetY).gget}.bdef 227 /.getShadowBlur{(shadowBlur).gget}.bdef 228 /.getShadowColor{(shadowColor).gget}.bdef 229 /.getFont{(font).gget}.bdef 230 /.getTextAlign{(textAlign).gget}.bdef 231 /.getTextBaseline{(textBaseline).gget}.bdef 232 233 /.setGlobalAlpha{(globalAlpha).gput}.bdef 234 /.setGlobalCompositeOperation{(globalCompositeOperation).gput}.bdef 235 /.setStrokeStyle{(strokeStyle).gput}.bdef 236 /.setFillStyle{(fillStyle).gput}.bdef 237 /.setLineWidth{(lineWidth).gput}.bdef 238 /.setLineCap{(lineCap).gput}.bdef 239 /.setLineJoin{(lineJoin).gput}.bdef 240 /.setLineCap{pop}.bdef % TODO remove this later (Firefox throws) 241 /.setLineJoin{pop}.bdef % TODO remove this later (Firefox throws) 242 /.setMiterLimit{(miterLimit).gput}.bdef 243 /.setShadowOffsetX{(shadowOffsetX).gput}.bdef 244 /.setShadowOffsetY{(shadowOffsetY).gput}.bdef 245 /.setShadowBlur{(shadowBlur).gput}.bdef 246 /.setShadowColor{(shadowColor).gput}.bdef 247 /.setFont{(font).gput}.bdef 248 /.setTextAlign{(textAlign).gput}.bdef 249 /.setTextBaseline{(textBaseline).gput}.bdef 250 251 %% PostScript 252 253 /.deg2rad{.pi 180 div mul}.bdef 254 /.rad2deg{180 .pi div mul}.bdef 255 256 /.$cx 0 def 257 /.$cy 0 def 258 /.$px 0 def 259 /.$py 0 def 260 /.setPoint{/.$cy .xdef/.$cx .xdef}.bdef 261 /.setPath{/.$py .xdef/.$px .xdef}.bdef 262 /currentpoint{/.$cx load /.$cy load}.bdef 263 /.getPath{/.$px load /.$py load}.bdef 264 265 /identmatrix{pop [1 0 0 1 0 0]}.bdef % TODO fill 266 /matrix{6 array identmatrix}.bdef 267 /setmatrix{/.$tm .xdef}.bdef 268 /defaultmatrix{pop matrix}.bdef % TODO fill 269 /initmatrix{matrix defaultmatrix setmatrix}.bdef 270 /currentmatrix{pop /.$tm load}.bdef % TODO fill 271 initmatrix 272 273 /.getTmd{/.$tmd load}.bdef 274 /.setTmd{/.$tmd .xdef}.bdef 275 /.resetTmd{matrix .setTmd}.bdef 276 .resetTmd 277 278 /.update{ % m -- 279 currentpoint 2 index % m .$cx .$cy m 280 .xy .setPoint % m 281 dup .getTmd exch .mmul .setTmd % (.$tmd x m) 282 dup currentmatrix exch .mmul setmatrix % = .$tm x m 283 }.bdef 284 285 /transform{dup type(arraytype)ne{.getTmd}if .xy}.bdef 286 /itransform{dup type(arraytype)ne{.getTmd}if .minv .xy}.bdef 287 288 /.scaleM{0 0 3 2 roll 0 0 6 array astore}.bdef % x y -- [x 0 0 y 0 0] 289 /.scale3{pop .scaleM}.bdef 290 /.scale2{2 copy .scaleM .update .scale}.bdef 291 /scale{dup type(arraytype)eq{.scale3}{.scale2}ifelse}.bdef 292 293 /.translateM{1 0 0 1 6 4 roll 6 array astore}.bdef % x y -- [1 0 0 1 x y] 294 /.translate3{pop .translateM}.bdef 295 /.translate2{2 copy .translateM .update .translate}.bdef 296 /translate{dup type(arraytype)eq{.translate3}{.translate2}ifelse}.bdef 297 298 /.rotateM{dup cos exch sin dup neg 2 index 0 0 6 array astore}.bdef % a -- [c s -s c 0 0] 299 /.rotate2{pop .deg2rad .rotateM}.bdef 300 /.rotate1{.deg2rad dup .rotateM .update .rotate}.bdef 301 /rotate{dup type(arraytype)eq{.rotate2}{.rotate1}ifelse}.bdef 302 303 %matrix concat – Replace CTM by matrix ´ CTM 304 %matrix1 matrix2 matrix3 concatmatrix matrix3 Fill matrix3 with matrix1 ´ matrix2 305 306 %dx dy dtransform dx¢ dy¢ Transform distance (dx, dy) by CTM 307 %dx dy matrix dtransform dx¢ dy¢ Transform distance (dx, dy) by matrix 308 309 %dx¢ dy¢ idtransform dx dy Perform inverse transform of distance (dx¢, dy¢) by CTM 310 %dx¢ dy¢ matrix idtransform dx dy Perform inverse transform of distance (dx¢, dy¢) by matrix 311 312 %matrix1 matrix2 invertmatrix matrix2 Fill matrix2 with inverse of matrix1 313 314 /gsave{.save}.bdef 315 /grestore{.restore}.bdef 316 /clip{.clip}.bdef 317 /rectclip{.clearRect}.bdef 318 /rectfill{.fillRect}.bdef 319 /rectstroke{.strokeRect}.bdef 320 /newpath{.beginPath}.bdef 321 /closepath{.closePath}.bdef 322 /moveto{2 copy .setPoint 2 copy .setPath .resetTmd .moveTo}.bdef 323 /lineto{2 copy .setPoint 2 copy .setPath .resetTmd .lineTo}.bdef 324 /arcto{.arcTo}.bdef 325 326 /setlinewidth{.setLineWidth}.bdef 327 /setlinecap{.setLineCap}.bdef % TODO 328 /setlinejoin{.setLineJoin}.bdef % TODO 329 /setmiterlimit{.setMiterLimit}.bdef 330 331 /currentlinewidth{.getLineWidth}.bdef 332 /currentlinecap{<</butt 0/round 1/square 2>> .getLineCap get}.bdef 333 /currentlinejoin{<</miter 0/round 1/bevel 2>> .getLineJoin get}.bdef 334 /currentmiterlimit{.getMiterLimit}.bdef 335 336 /setgray{255 mul dup dup .rgb dup .setStrokeStyle .setFillStyle}.bdef 337 /setrgbcolor{3{255 mul round 3 1 roll}repeat .rgb dup .setStrokeStyle .setFillStyle}.bdef 338 /setcmykcolor{setrgbcolor pop}.bdef % TODO 339 /sethsbcolor{setrgbcolor}.bdef % TODO 340 /clippath{0 0 .gcanvas(width)get .gcanvas(height)get .rect}.bdef % TODO 341 /show{currentpoint 3 2 roll 3 copy .fillText .strokeText}.bdef % TODO 342 343 /rlineto{.getTmd .xy /.$py load add exch /.$px load add exch .getTmd .minv .xy lineto}.bdef 344 /curveto{2 copy .setPoint 2 copy .setPath .resetTmd .bezierCurveTo}.bdef 345 346 /currentflat{42}.bdef % TODO 347 /setflat{pop}.bdef % TODO 348 349 /arc{.deg2rad exch .deg2rad exch true .arc}.bdef % TODO currentpoint 350 /arcn{.deg2rad exch .deg2rad exch false .arc}.bdef % TODO currentpoint 351 352 /fill{.fill newpath currentpoint .moveTo}.bdef % TODO 353 354 /setdash{pop pop}.bdef % TODO 355 356 /stroke{.stroke newpath currentpoint .moveTo}.bdef 357 358 /showpage{}.bdef % TODO 359 /grestoreall{}.bdef % TODO 360 /readonly{}.bdef % TODO 361 /currentfile{(url?)}.bdef % TODO 362 /eexec{pop}.bdef % TODO 363 /findfont{}.bdef % TODO 364 /scalefont{pop}.bdef % TODO 365 /setfont{pop}.bdef % TODO C.font = N + "pt " + F.V; 366 /stopped{}.bdef % TODO 367 /loop{}.bdef % TODO !!! 368 /string{}.bdef % TODO 369 /cvi{}.bdef % TODO 370 /pathbbox{}.bdef % TODO 371 /urx{}.bdef % TODO 372 /ury{}.bdef % TODO 373 /llx{}.bdef % TODO 374 /lly{}.bdef % TODO 375 /pagewidth{}.bdef % TODO 376 /pageheight{}.bdef % TODO 377 /inwidth{}.bdef % TODO 378 /inheight{}.bdef % TODO 379 /usertime{}.bdef % TODO 380 /srand{}.bdef % TODO 381 382 %% PDF 383 384 /w{setlinewidth}.bdef 385 /J{setlinecap}.bdef % TODO 386 /j{setlinejoin}.bdef % TODO 387 /M{setmiterlimit}.bdef 388 /d{setdash}.bdef % TODO 389 /ri{}.bdef % TODO 390 /i{1 .min setflat}.bdef 391 /gs{}.bdef % TODO 392 /q{gsave}.bdef 393 /Q{grestore}.bdef 394 /cm{.transform}.bdef 395 /m{newpath moveto}.bdef % TODO only if not m previously 396 /l{lineto}.bdef 397 /c{.bezierCurveTo}.bdef 398 /v{currentpoint 6 2 roll c}.bdef 399 /y{2 copy c}.bdef 400 /h{closepath}.bdef % TODO 401 /re{.rect}.bdef % TODO really, or x y m , x+w y l , x+w y+h l , x y+h l , h 402 /S{stroke}.bdef 403 /s{h S}.bdef 404 /f{fill}.bdef % TODO 405 /F{f}.bdef 406 /f*{}.bdef % TODO 407 /B{f S}.bdef 408 /B*{f* S}.bdef 409 /b{h B}.bdef 410 /b*{h B*}.bdef 411 /n{}.bdef % TODO 412 /W{clip}.bdef % TODO 413 /W*{clip}.bdef % TODO 414 /BT{}.bdef % TODO 415 /ET{}.bdef % TODO 416 /Tc{}.bdef % TODO 417 /Tw{}.bdef % TODO 418 /Tz{}.bdef % TODO 419 /TL{}.bdef % TODO 420 /Tf{setfont}.bdef % TODO 421 /Tr{}.bdef % TODO 422 /Ts{}.bdef % TODO 423 /Td{translate 0 0 moveto}.bdef 424 /TD{}.bdef % TODO 425 /Tm{}.bdef % TODO 426 /T*{}.bdef % TODO 427 /Tj{show}.bdef % TODO 428 /TJ{}.bdef % TODO 429 /'{}.bdef % TODO 430 /"{}.bdef % TODO 431 /d0{}.bdef % TODO 432 /d1{}.bdef % TODO 433 /CS{}.bdef % TODO 434 /cs{}.bdef % TODO 435 %/SC/setcolor .ldef 436 /SCN{}.bdef % TODO 437 %/sc/setcolor .ldef 438 /scn{}.bdef % TODO 439 /G{}.bdef % TODO 440 /g{}.bdef % TODO 441 /RG{}.bdef % TODO 442 /rg{setrgbcolor}.bdef % TODO 443 /K{}.bdef % TODO 444 /k{}.bdef % TODO 445 /sh{}.bdef % TODO 446 /BI{}.bdef % TODO 447 /ID{}.bdef % TODO 448 /EI{}.bdef % TODO 449 /Do{}.bdef % TODO 450 /MP{}.bdef % TODO 451 /DP{}.bdef % TODO 452 /BMC{}.bdef % TODO 453 /BDC{}.bdef % TODO 454 /EMC{}.bdef % TODO 455 /BX{}.bdef % TODO 456 /EX{}.bdef % TODO 457 458 %% finish 459 460 false .strictBind 461 462 /userdict 1000 dict def 463 userdict begin 464 </pre> 465 466 467 468 </div> 469 470 <style>canvas {width:12em;height:12em;border:1px dashed black}</style> 471 <script type="text/javascript" src="wps.js"></script> 472 <script> 473 function $(Id) {return document.getElementById(Id);} 474 function $$(Id) {return $(Id).textContent;} 475 </script> 476 <canvas id="xsandbox"></canvas> 477 <p>Sandbox:</p> 478 <p> 479 <textarea id="sandbox" style="width:100%" rows="18"> 480 /n 10 def 481 /w 25 def 482 483 0 0 n w mul dup .gbox 484 485 4 dict begin 486 0 1 n 1 sub { 487 /i exch def 488 /ii 1 1 n div i mul sub def 489 0 1 n 1 sub { 490 /j exch def 491 /jj 1 1 n div j mul sub def 492 ii jj 0 setrgbcolor 493 w j mul w i mul w w rectfill 494 } for 495 } for 496 end 497 </textarea> 498 </p> 499 <script> 500 function sandbox() {(new Wps).parse($$("wps"), "(xsandbox) .setGc", $("sandbox").value);} 501 </script> 502 <button onclick="javascript:sandbox();">Run</button> code from sandbox. 503 </div> 504 </div> 505 </div> 506 </div> 507 </body> 508 </html>