WPS sandbox
%%% (c) 2009 Tomas Hlavaty
currentdict/systemdict currentdict put
systemdict/{/mark cvx put
systemdict/[/mark cvx put
systemdict/]
/counttomark cvx
/array cvx
/astore cvx
/exch cvx
/pop cvx
5 array astore cvx put
systemdict/}/] cvx/cvx cvx 2 array astore cvx put
systemdict/def{currentdict 2 index 2 index put pop pop}put
/maxlength 1000 def % TODO
/.bdef{bind def}bind def
/.xdef{exch def}.bdef
/dup{0 index}.bdef
/load{dup where pop exch get}.bdef
/.ldef{load def}.bdef
/if{{}ifelse}.bdef
/cleartomark{array pop}.bdef
/known{exch begin where{currentdict eq}{false}if end}.bdef
/store{1 index where{3 1 roll put}{def}ifelse}.bdef
/not{{false}{true}ifelse}.bdef
/.logand{{{true}{false}ifelse}{pop false}ifelse}.bdef
/and/.logand .ldef % TODO numeric and
/.logor{{pop true}{{true}{false}ifelse}ifelse}.bdef
/or/.logor .ldef % TODO numeric or
/ne{eq not}.bdef
/ge{lt not}.bdef
/le{1 index 1 index eq 3 1 roll lt or}.bdef
/gt{le not}.bdef
/.repeat{1 1 4 2 roll for}.bdef
%% math
/floor{.math(floor)1 .call}.bdef
/neg{0 exch sub}.bdef
/add{neg sub}.bdef
/idiv{div floor}.bdef
/abs{.math(abs)1 .call}.bdef
/.acos{.math(acos)1 .call}.bdef
/.asin{.math(asin)1 .call}.bdef
/atan{exch .math(atan)1 .call}.bdef
/.atan2{.math(atan2)2 .call}.bdef
/ceiling{.math(ceil)1 .call}.bdef
/cos{.math(cos)1 .call}.bdef
/.exp{.math(exp)1 .call}.bdef
/log{.math(log)1 .call}.bdef
/.max{.math(max)2 .call}.bdef
/.min{.math(min)2 .call}.bdef
/.pow{.math(pow)2 .call}.bdef
/.random{.math(random)0 .call}.bdef
/rand{.random}.bdef % TODO follow spec
/round{.math(round)1 .call}.bdef
/sin{.math(sin)1 .call}.bdef
/sqrt{.math(sqrt)1 .call}.bdef
/.tan{.math(tan)1 .call}.bdef
/truncate{.math(truncate)1 .call}.bdef % TODO Math.truncate does not exist!
/.e{.math(E)get}.bdef
/.ln2{.math(LN2)get}.bdef
/.ln10{.math(LN10)get}.bdef
/.log2e{.math(LOG2E)get}.bdef
/.log10e{.math(LOG10E)get}.bdef
/.pi{.math(PI)get}.bdef
/.sqrt1_2{.math(SQRT1_2)get}.bdef
/.sqrt2{.math(SQRT2)get}.bdef
%% html
/.setTimeout{.window(setTimeout)2 .call}.bdef % cb ms -- id
/.clearTimeout{.window(clearTimeout)1 .call pop}.bdef % id --
/.setInterval{.window(setInterval)2 .call}.bdef % cb ms -- id
/.clearInterval{.window(clearInterval)1 .call pop}.bdef % id --
/.document{.window(document)get}.bdef % -- document
/.getElementById{.document(getElementById)1 .call}.bdef % id -- w
/.hook{put}.bdef % e k cb --
%% canvas
/.setGc{.getElementById(2d)exch(getContext)1 .call/.$gc .xdef}.bdef
/.gc{/.$gc load}.bdef
/.gget{.gc exch get}.bdef
/.gput{.gc 3 1 roll exch put}.bdef
/.gcall0{.gc 3 1 roll .call pop}.bdef
/.gcall1{.gc 3 1 roll .call}.bdef
/.gcanvas{(canvas).gget}.bdef
/.gdim{.gcanvas exch(height)exch put .gcanvas exch(width)exch put}.bdef
/.gbox{.gdim pop pop}.bdef % TODO compute properly
/.save{(save)0 .gcall0}.bdef
/.restore{(restore)0 .gcall0}.bdef
/.scale{(scale)2 .gcall0}.bdef
/.rotate{(rotate)1 .gcall0}.bdef
/.translate{(translate)2 .gcall0}.bdef
/.transform{(transform)6 .gcall0}.bdef
/.setTransform{(setTransform)6 .gcall0}.bdef
/.createLinearGradient{(createLinearGradient)4 .gcall1}.bdef
/.createRadialGradient{(createRadialGradient)6 .gcall1}.bdef
/.createPattern{(createPattern)2 .gcall1}.bdef
/.clearRect{(clearRect)4 .gcall0}.bdef
/.fillRect{(fillRect)4 .gcall0}.bdef
/.strokeRect{(strokeRect)4 .gcall0}.bdef
/.beginPath{(beginPath)0 .gcall0}.bdef
/.closePath{(closePath)0 .gcall0}.bdef
/.moveTo{(moveTo)2 .gcall0}.bdef
/.lineTo{(lineTo)2 .gcall0}.bdef
/.quadraticCurveTo{(quadraticCurveTo)4 .gcall0}.bdef
/.bezierCurveTo{(bezierCurveTo)6 .gcall0}.bdef
/.arcTo{(arcTo)5 .gcall0}.bdef
/.rect{(rect)4 .gcall0}.bdef
/.arc{(arc)6 .gcall0}.bdef
/.fill{(fill)0 .gcall0}.bdef
/.stroke{(stroke)0 .gcall0}.bdef
/.clip{(clip)0 .gcall0}.bdef
/.isPointInPath{(isPointInPath)2 .gcall1}.bdef
/.fillText{(fillText)4 .gcall0}.bdef
/.fillText{}.bdef % TODO not working in Firefox
/.strokeText{(strokeText)4 .gcall0}.bdef
/.strokeText{}.bdef % TODO not working in Firefox
/.measureText{(measureText)1 .gcall1}.bdef
/.drawImage1{(drawImage1)5 .gcall0}.bdef
/.drawImage2{(drawImage2)9 .gcall0}.bdef
/.createImageData1{(createImageData1)1 .gcall1}.bdef
/.createImageData2{(createImageData2)2 .gcall1}.bdef
/.getImageData{(getImageData)4 .gcall1}.bdef
/.putImageData{(putImageData)7 .gcall0}.bdef
/.getGlobalAlpha{(globalAlpha).gget}.bdef
/.getGlobalCompositeOperation{(globalCompositeOperation).gget}.bdef
/.getStrokeStyle{(strokeStyle).gget}.bdef
/.getFillStyle{(fillStyle).gget}.bdef
/.getLineWidth{(lineWidth).gget}.bdef
/.getLineCap{(lineCap).gget}.bdef
/.getLineJoin{(lineJoin).gget}.bdef
/.getMiterLimit{(miterLimit).gget}.bdef
/.getShadowOffsetX{(shadowOffsetX).gget}.bdef
/.getShadowOffsetY{(shadowOffsetY).gget}.bdef
/.getShadowBlur{(shadowBlur).gget}.bdef
/.getShadowColor{(shadowColor).gget}.bdef
/.getFont{(font).gget}.bdef
/.getTextAlign{(textAlign).gget}.bdef
/.getTextBaseline{(textBaseline).gget}.bdef
/.setGlobalAlpha{(globalAlpha).gput}.bdef
/.setGlobalCompositeOperation{(globalCompositeOperation).gput}.bdef
/.setStrokeStyle{(strokeStyle).gput}.bdef
/.setFillStyle{(fillStyle).gput}.bdef
/.setLineWidth{(lineWidth).gput}.bdef
/.setLineCap{(lineCap).gput}.bdef
/.setLineJoin{(lineJoin).gput}.bdef
/.setLineCap{pop}.bdef % TODO remove this later (Firefox throws)
/.setLineJoin{pop}.bdef % TODO remove this later (Firefox throws)
/.setMiterLimit{(miterLimit).gput}.bdef
/.setShadowOffsetX{(shadowOffsetX).gput}.bdef
/.setShadowOffsetY{(shadowOffsetY).gput}.bdef
/.setShadowBlur{(shadowBlur).gput}.bdef
/.setShadowColor{(shadowColor).gput}.bdef
/.setFont{(font).gput}.bdef
/.setTextAlign{(textAlign).gput}.bdef
/.setTextBaseline{(textBaseline).gput}.bdef
%% PostScript
/.deg2rad{.pi 180 div mul}.bdef
/.rad2deg{180 .pi div mul}.bdef
/.$cx 0 def
/.$cy 0 def
/.$px 0 def
/.$py 0 def
/.setPoint{/.$cy .xdef/.$cx .xdef}.bdef
/.setPath{/.$py .xdef/.$px .xdef}.bdef
/currentpoint{/.$cx load /.$cy load}.bdef
/.getPath{/.$px load /.$py load}.bdef
/identmatrix{pop [1 0 0 1 0 0]}.bdef % TODO fill
/matrix{6 array identmatrix}.bdef
/setmatrix{/.$tm .xdef}.bdef
/defaultmatrix{pop matrix}.bdef % TODO fill
/initmatrix{matrix defaultmatrix setmatrix}.bdef
/currentmatrix{pop /.$tm load}.bdef % TODO fill
initmatrix
/.getTmd{/.$tmd load}.bdef
/.setTmd{/.$tmd .xdef}.bdef
/.resetTmd{matrix .setTmd}.bdef
.resetTmd
/.update{ % m --
currentpoint 2 index % m .$cx .$cy m
.xy .setPoint % m
dup .getTmd exch .mmul .setTmd % (.$tmd x m)
dup currentmatrix exch .mmul setmatrix % = .$tm x m
}.bdef
/transform{dup type(arraytype)ne{.getTmd}if .xy}.bdef
/itransform{dup type(arraytype)ne{.getTmd}if .minv .xy}.bdef
/.scaleM{0 0 3 2 roll 0 0 6 array astore}.bdef % x y -- [x 0 0 y 0 0]
/.scale3{pop .scaleM}.bdef
/.scale2{2 copy .scaleM .update .scale}.bdef
/scale{dup type(arraytype)eq{.scale3}{.scale2}ifelse}.bdef
/.translateM{1 0 0 1 6 4 roll 6 array astore}.bdef % x y -- [1 0 0 1 x y]
/.translate3{pop .translateM}.bdef
/.translate2{2 copy .translateM .update .translate}.bdef
/translate{dup type(arraytype)eq{.translate3}{.translate2}ifelse}.bdef
/.rotateM{dup cos exch sin dup neg 2 index 0 0 6 array astore}.bdef % a -- [c s -s c 0 0]
/.rotate2{pop .deg2rad .rotateM}.bdef
/.rotate1{.deg2rad dup .rotateM .update .rotate}.bdef
/rotate{dup type(arraytype)eq{.rotate2}{.rotate1}ifelse}.bdef
%matrix concat – Replace CTM by matrix ´ CTM
%matrix1 matrix2 matrix3 concatmatrix matrix3 Fill matrix3 with matrix1 ´ matrix2
%dx dy dtransform dx¢ dy¢ Transform distance (dx, dy) by CTM
%dx dy matrix dtransform dx¢ dy¢ Transform distance (dx, dy) by matrix
%dx¢ dy¢ idtransform dx dy Perform inverse transform of distance (dx¢, dy¢) by CTM
%dx¢ dy¢ matrix idtransform dx dy Perform inverse transform of distance (dx¢, dy¢) by matrix
%matrix1 matrix2 invertmatrix matrix2 Fill matrix2 with inverse of matrix1
/gsave{.save}.bdef
/grestore{.restore}.bdef
/clip{.clip}.bdef
/rectclip{.clearRect}.bdef
/rectfill{.fillRect}.bdef
/rectstroke{.strokeRect}.bdef
/newpath{.beginPath}.bdef
/closepath{.closePath}.bdef
/moveto{2 copy .setPoint 2 copy .setPath .resetTmd .moveTo}.bdef
/lineto{2 copy .setPoint 2 copy .setPath .resetTmd .lineTo}.bdef
/arcto{.arcTo}.bdef
/setlinewidth{.setLineWidth}.bdef
/setlinecap{.setLineCap}.bdef % TODO
/setlinejoin{.setLineJoin}.bdef % TODO
/setmiterlimit{.setMiterLimit}.bdef
/currentlinewidth{.getLineWidth}.bdef
/currentlinecap{<</butt 0/round 1/square 2>> .getLineCap get}.bdef
/currentlinejoin{<</miter 0/round 1/bevel 2>> .getLineJoin get}.bdef
/currentmiterlimit{.getMiterLimit}.bdef
/setgray{255 mul dup dup .rgb dup .setStrokeStyle .setFillStyle}.bdef
/setrgbcolor{3{255 mul round 3 1 roll}repeat .rgb dup .setStrokeStyle .setFillStyle}.bdef
/setcmykcolor{setrgbcolor pop}.bdef % TODO
/sethsbcolor{setrgbcolor}.bdef % TODO
/clippath{0 0 .gcanvas(width)get .gcanvas(height)get .rect}.bdef % TODO
/show{currentpoint 3 2 roll 3 copy .fillText .strokeText}.bdef % TODO
/rlineto{.getTmd .xy /.$py load add exch /.$px load add exch .getTmd .minv .xy lineto}.bdef
/curveto{2 copy .setPoint 2 copy .setPath .resetTmd .bezierCurveTo}.bdef
/currentflat{42}.bdef % TODO
/setflat{pop}.bdef % TODO
/arc{.deg2rad exch .deg2rad exch true .arc}.bdef % TODO currentpoint
/arcn{.deg2rad exch .deg2rad exch false .arc}.bdef % TODO currentpoint
/fill{.fill newpath currentpoint .moveTo}.bdef % TODO
/setdash{pop pop}.bdef % TODO
/stroke{.stroke newpath currentpoint .moveTo}.bdef
/showpage{}.bdef % TODO
/grestoreall{}.bdef % TODO
/readonly{}.bdef % TODO
/currentfile{(url?)}.bdef % TODO
/eexec{pop}.bdef % TODO
/findfont{}.bdef % TODO
/scalefont{pop}.bdef % TODO
/setfont{pop}.bdef % TODO C.font = N + "pt " + F.V;
/stopped{}.bdef % TODO
/loop{}.bdef % TODO !!!
/string{}.bdef % TODO
/cvi{}.bdef % TODO
/pathbbox{}.bdef % TODO
/urx{}.bdef % TODO
/ury{}.bdef % TODO
/llx{}.bdef % TODO
/lly{}.bdef % TODO
/pagewidth{}.bdef % TODO
/pageheight{}.bdef % TODO
/inwidth{}.bdef % TODO
/inheight{}.bdef % TODO
/usertime{}.bdef % TODO
/srand{}.bdef % TODO
%% PDF
/w{setlinewidth}.bdef
/J{setlinecap}.bdef % TODO
/j{setlinejoin}.bdef % TODO
/M{setmiterlimit}.bdef
/d{setdash}.bdef % TODO
/ri{}.bdef % TODO
/i{1 .min setflat}.bdef
/gs{}.bdef % TODO
/q{gsave}.bdef
/Q{grestore}.bdef
/cm{.transform}.bdef
/m{newpath moveto}.bdef % TODO only if not m previously
/l{lineto}.bdef
/c{.bezierCurveTo}.bdef
/v{currentpoint 6 2 roll c}.bdef
/y{2 copy c}.bdef
/h{closepath}.bdef % TODO
/re{.rect}.bdef % TODO really, or x y m , x+w y l , x+w y+h l , x y+h l , h
/S{stroke}.bdef
/s{h S}.bdef
/f{fill}.bdef % TODO
/F{f}.bdef
/f*{}.bdef % TODO
/B{f S}.bdef
/B*{f* S}.bdef
/b{h B}.bdef
/b*{h B*}.bdef
/n{}.bdef % TODO
/W{clip}.bdef % TODO
/W*{clip}.bdef % TODO
/BT{}.bdef % TODO
/ET{}.bdef % TODO
/Tc{}.bdef % TODO
/Tw{}.bdef % TODO
/Tz{}.bdef % TODO
/TL{}.bdef % TODO
/Tf{setfont}.bdef % TODO
/Tr{}.bdef % TODO
/Ts{}.bdef % TODO
/Td{translate 0 0 moveto}.bdef
/TD{}.bdef % TODO
/Tm{}.bdef % TODO
/T*{}.bdef % TODO
/Tj{show}.bdef % TODO
/TJ{}.bdef % TODO
/'{}.bdef % TODO
/"{}.bdef % TODO
/d0{}.bdef % TODO
/d1{}.bdef % TODO
/CS{}.bdef % TODO
/cs{}.bdef % TODO
%/SC/setcolor .ldef
/SCN{}.bdef % TODO
%/sc/setcolor .ldef
/scn{}.bdef % TODO
/G{}.bdef % TODO
/g{}.bdef % TODO
/RG{}.bdef % TODO
/rg{setrgbcolor}.bdef % TODO
/K{}.bdef % TODO
/k{}.bdef % TODO
/sh{}.bdef % TODO
/BI{}.bdef % TODO
/ID{}.bdef % TODO
/EI{}.bdef % TODO
/Do{}.bdef % TODO
/MP{}.bdef % TODO
/DP{}.bdef % TODO
/BMC{}.bdef % TODO
/BDC{}.bdef % TODO
/EMC{}.bdef % TODO
/BX{}.bdef % TODO
/EX{}.bdef % TODO
%% finish
false .strictBind
/userdict 1000 dict def
userdict begin
Sandbox:
code from sandbox.

