diff --git a/src/PsSpecialHandler.hpp b/src/PsSpecialHandler.hpp index a84f0741..44d1341d 100644 --- a/src/PsSpecialHandler.hpp +++ b/src/PsSpecialHandler.hpp @@ -107,7 +107,7 @@ class PsSpecialHandler : public SpecialHandler, public DVIEndPageListener, prote void processLatticeTriangularPatchMesh (ColorSpace colorSpace, VectorIterator &it); /// scale given value by current PS scale factors - double scale (double v) const {return v*(_sx*_cos*_cos + _sy*(1-_cos*_cos));} + double scale (double v) const {return v*(_sx*(1-_cos*_cos) + _sy*_cos*_cos);} void applyscalevals (std::vector &p) override {_sx = p[0]; _sy = p[1]; _cos = p[2];} void clip (std::vector &p) override {clip(p, false);} diff --git a/src/psdefs.cpp b/src/psdefs.cpp index 0f126be8..9e76c0cb 100644 --- a/src/psdefs.cpp +++ b/src/psdefs.cpp @@ -34,66 +34,66 @@ const char *PSInterpreter::PSDEFS = "}forall}put @SD/defpr{[exch[/copy @SD]cvxall 5 -1 roll dup 6 1 roll[/get/exec]" "cvxall 6 -1 roll dup 7 1 roll 4 -1 roll dup 5 1 roll dup length string cvs/prc" "md cvx]cvx def}put @SD/querypos{{currentpoint}stopped{$error/newerror false pu" -"t}{2(querypos)prcmd}ifelse}put @SD/applyscalevals{1 0 transform 0 0 transform " -"3 -1 roll sub dup mul 3 1 roll sub dup mul add sqrt 0 1 transform 0 0 transfor" -"m 3 -1 roll sub dup mul 3 1 roll sub dup mul add sqrt 1 0 transform dup mul ex" -"ch dup dup mul 3 -1 roll add sqrt div 3(applyscalevals)prcmd}put @SD/prpath{{2" -"(moveto)prcmd}{2(lineto)prcmd}{6(curveto)prcmd}{0(closepath)prcmd}pathforall}p" -"ut @SD/charpath{/@dodraw false store :charpath/@dodraw true store}put @SD/show" -"{@dodraw{dup :gsave currentpoint 2{50 mul exch}repeat :newpath moveto 50 50/sc" -"ale sysexec true charpath eofill :grestore/@dodraw false store :show/@dodraw t" -"rue store}{pop}ifelse}put @SD/awidthshow{{1 string dup 0 5 index put :gsave sh" -"ow :grestore pop 0 rmoveto 3 index eq{4 index 4 index rmoveto}if 1 index 1 ind" -"ex rmoveto}exch cshow 5{pop}repeat}put @SD/widthshow{0 0 3 -1 roll pstack awid" -"thshow}put @SD/ashow{0 0 0 6 3 roll awidthshow}put @SD/newpath{:newpath 0 1(ne" -"wpath)prcmd}put @SD/stroke{@dodraw{1 1(newpath)prcmd prpath 0(stroke)prcmd :ne" -"wpath}{:stroke}ifelse}put @SD/fill{@dodraw{1 1(newpath)prcmd prpath 0(fill)prc" -"md :newpath}{:fill}ifelse}put @SD/eofill{@dodraw{1 1(newpath)prcmd prpath 0(eo" -"fill)prcmd :newpath}{:eofill}ifelse}put @SD/clip{:clip 0 1(newpath)prcmd prpat" -"h 0(clip)prcmd}put @SD/eoclip{:eoclip 1 1(newpath)prcmd prpath 0(eoclip)prcmd}" -"put @SD/shfill{begin currentdict/ShadingType known currentdict/ColorSpace know" -"n and currentdict/DataSource known and currentdict/Function known not and Shad" -"ingType 4 ge and DataSource type/arraytype eq and{<>begin currentdict ColorSpace known{ShadingType ColorSpace load bgknown{1 B" -"ackground aload pop}{0}ifelse bbknown{1 BBox aload pop}{0}ifelse ShadingType 5" -" eq{VerticesPerRow}if DataSource aload length 4 add bgknown{ColorSpace load ad" -"d}if bbknown{4 add}if ShadingType 5 eq{1 add}if(shfill)prcmd}if end}if end}put" -"/@rect{4 -2 roll moveto exch dup 0 rlineto exch 0 exch rlineto neg 0 rlineto c" -"losepath}bind def/@rectcc{4 -2 roll moveto 2 copy 0 lt exch 0 lt xor{dup 0 exc" -"h rlineto exch 0 rlineto neg 0 exch rlineto}{exch dup 0 rlineto exch 0 exch rl" -"ineto neg 0 rlineto}ifelse closepath}bind def @SD/rectclip{:newpath dup type/a" -"rraytype eq{aload length 4 idiv{@rectcc}repeat}{@rectcc}ifelse clip :newpath}p" -"ut @SD/rectfill{gsave :newpath dup type/arraytype eq{aload length 4 idiv{@rect" -"cc}repeat}{@rectcc}ifelse fill grestore}put @SD/rectstroke{gsave :newpath dup " -"type/arraytype eq{aload length 4 idiv{@rect}repeat}{@rect}ifelse stroke gresto" -"re}put false setglobal @SD readonly pop/initclip 0 defpr/clippath 0 defpr/syse" -"xec{@SD exch get exec}def/adddot{dup length 1 add string dup 0 46 put dup 3 -1" -" roll 1 exch putinterval}def/setlinewidth{dup/setlinewidth sysexec applyscalev" -"als 1(setlinewidth)prcmd}def/setlinecap 1 defpr/setlinejoin 1 defpr/setmiterli" -"mit 1 defpr/setdash{mark 3 1 roll 2 copy/setdash sysexec applyscalevals exch a" -"load length 1 add -1 roll counttomark(setdash)prcmd pop}def/setgstate{currentl" -"inewidth 1(setlinewidth)prcmd currentlinecap 1(setlinecap)prcmd currentlinejoi" -"n 1(setlinejoin)prcmd currentmiterlimit 1(setmiterlimit)prcmd currentrgbcolor " -"3(setrgbcolor)prcmd 6 array currentmatrix aload pop 6(setmatrix)prcmd applysca" -"levals currentdash mark 3 1 roll exch aload length 1 add -1 roll counttomark(s" -"etdash)prcmd pop}def/save{@UD begin/@saveID vmstatus pop pop def end :save @sa" -"veID 1(save)prcmd}def/restore{:restore setgstate @UD/@saveID known{@UD begin @" -"saveID end}{0}ifelse 1(restore)prcmd}def/gsave 0 defpr/grestore{:grestore setg" -"state 0(grestore)prcmd}def/grestoreall{:grestoreall setstate 0(grestoreall)prc" -"md}def/rotate{dup type/arraytype ne{dup 1(rotate)prcmd}if/rotate sysexec}def/s" -"cale{dup type/arraytype ne{2 copy 2(scale)prcmd}if/scale sysexec}def/translate" -"{dup type/arraytype ne{2 copy 2(translate)prcmd}if/translate sysexec}def/setma" -"trix{dup/setmatrix sysexec aload pop applyscalevals 6(setmatrix)prcmd}def/init" -"matrix{matrix setmatrix}def/concat{matrix currentmatrix matrix concatmatrix se" -"tmatrix}def/makepattern{gsave<>begin dup/XUID[1000000 @patcnt]p" -"ut mx/makepattern sysexec dup dup begin PatternType @patcnt BBox aload pop XSt" -"ep YStep PaintType mx aload pop 15(makepattern)prcmd :newpath matrix setmatrix" -" PaintProc 0 1(makepattern)prcmd end/@patcnt @patcnt 1 add store end grestore}" -"def/setpattern{begin PatternType 1 eq{PaintType 1 eq{XUID aload pop exch pop 1" -"}{:gsave[currentcolorspace aload length -1 roll pop]setcolorspace/setcolor sys" -"exec XUID aload pop exch pop currentrgbcolor :grestore 4}ifelse(setpattern)prc" -"md}{/setpattern sysexec}ifelse end}def/setcolor{dup type/dicttype eq{setpatter" -"n}{/setcolor sysexec/currentrgbcolor sysexec setrgbcolor}ifelse}def/setgray 1 " -"defpr/setcmykcolor 4 defpr/sethsbcolor 3 defpr/setrgbcolor 3 defpr/.setopacity" -"alpha{dup/.setopacityalpha sysexec 1(setopacityalpha)prcmd}def "; +"t}{2(querypos)prcmd}ifelse}put @SD/applyscalevals{1 0 dtransform exch dup mul " +"exch dup mul add sqrt 0 1 dtransform exch dup mul exch dup mul add sqrt 1 0 dt" +"ransform dup mul exch dup dup mul 3 -1 roll add dup 0 eq{pop}{sqrt div}ifelse " +"3(applyscalevals)prcmd}put @SD/prpath{{2(moveto)prcmd}{2(lineto)prcmd}{6(curve" +"to)prcmd}{0(closepath)prcmd}pathforall}put @SD/charpath{/@dodraw false store :" +"charpath/@dodraw true store}put @SD/show{@dodraw{dup :gsave currentpoint 2{50 " +"mul exch}repeat :newpath moveto 50 50/scale sysexec true charpath eofill :gres" +"tore/@dodraw false store :show/@dodraw true store}{pop}ifelse}put @SD/awidthsh" +"ow{{1 string dup 0 5 index put :gsave show :grestore pop 0 rmoveto 3 index eq{" +"4 index 4 index rmoveto}if 1 index 1 index rmoveto}exch cshow 5{pop}repeat}put" +" @SD/widthshow{0 0 3 -1 roll pstack awidthshow}put @SD/ashow{0 0 0 6 3 roll aw" +"idthshow}put @SD/newpath{:newpath 0 1(newpath)prcmd}put @SD/stroke{@dodraw{1 1" +"(newpath)prcmd prpath 0(stroke)prcmd :newpath}{:stroke}ifelse}put @SD/fill{@do" +"draw{1 1(newpath)prcmd prpath 0(fill)prcmd :newpath}{:fill}ifelse}put @SD/eofi" +"ll{@dodraw{1 1(newpath)prcmd prpath 0(eofill)prcmd :newpath}{:eofill}ifelse}pu" +"t @SD/clip{:clip 0 1(newpath)prcmd prpath 0(clip)prcmd}put @SD/eoclip{:eoclip " +"1 1(newpath)prcmd prpath 0(eoclip)prcmd}put @SD/shfill{begin currentdict/Shadi" +"ngType known currentdict/ColorSpace known and currentdict/DataSource known and" +" currentdict/Function known not and ShadingType 4 ge and DataSource type/array" +"type eq and{<>begin currentdict ColorSpace known" +"{ShadingType ColorSpace load bgknown{1 Background aload pop}{0}ifelse bbknown{" +"1 BBox aload pop}{0}ifelse ShadingType 5 eq{VerticesPerRow}if DataSource aload" +" length 4 add bgknown{ColorSpace load add}if bbknown{4 add}if ShadingType 5 eq" +"{1 add}if(shfill)prcmd}if end}if end}put/@rect{4 -2 roll moveto exch dup 0 rli" +"neto exch 0 exch rlineto neg 0 rlineto closepath}bind def/@rectcc{4 -2 roll mo" +"veto 2 copy 0 lt exch 0 lt xor{dup 0 exch rlineto exch 0 rlineto neg 0 exch rl" +"ineto}{exch dup 0 rlineto exch 0 exch rlineto neg 0 rlineto}ifelse closepath}b" +"ind def @SD/rectclip{:newpath dup type/arraytype eq{aload length 4 idiv{@rectc" +"c}repeat}{@rectcc}ifelse clip :newpath}put @SD/rectfill{gsave :newpath dup typ" +"e/arraytype eq{aload length 4 idiv{@rectcc}repeat}{@rectcc}ifelse fill grestor" +"e}put @SD/rectstroke{gsave :newpath dup type/arraytype eq{aload length 4 idiv{" +"@rect}repeat}{@rect}ifelse stroke grestore}put false setglobal @SD readonly po" +"p/initclip 0 defpr/clippath 0 defpr/sysexec{@SD exch get exec}def/adddot{dup l" +"ength 1 add string dup 0 46 put dup 3 -1 roll 1 exch putinterval}def/setlinewi" +"dth{dup/setlinewidth sysexec 1(setlinewidth)prcmd}def/setlinecap 1 defpr/setli" +"nejoin 1 defpr/setmiterlimit 1 defpr/setdash{mark 3 1 roll 2 copy/setdash syse" +"xec exch aload length 1 add -1 roll counttomark(setdash)prcmd pop}def/setgstat" +"e{currentlinewidth 1(setlinewidth)prcmd currentlinecap 1(setlinecap)prcmd curr" +"entlinejoin 1(setlinejoin)prcmd currentmiterlimit 1(setmiterlimit)prcmd curren" +"trgbcolor 3(setrgbcolor)prcmd 6 array currentmatrix aload pop 6(setmatrix)prcm" +"d applyscalevals currentdash mark 3 1 roll exch aload length 1 add -1 roll cou" +"nttomark(setdash)prcmd pop}def/save{@UD begin/@saveID vmstatus pop pop def end" +" :save @saveID 1(save)prcmd}def/restore{:restore setgstate @UD/@saveID known{@" +"UD begin @saveID end}{0}ifelse 1(restore)prcmd}def/gsave 0 defpr/grestore{:gre" +"store setgstate 0(grestore)prcmd}def/grestoreall{:grestoreall setstate 0(grest" +"oreall)prcmd}def/rotate{dup type/arraytype ne{dup 1(rotate)prcmd}if/rotate sys" +"exec applyscalevals}def/scale{dup type/arraytype ne{2 copy 2(scale)prcmd}if/sc" +"ale sysexec applyscalevals}def/translate{dup type/arraytype ne{2 copy 2(transl" +"ate)prcmd}if/translate sysexec}def/setmatrix{dup/setmatrix sysexec aload pop 6" +"(setmatrix)prcmd applyscalevals}def/initmatrix{matrix setmatrix}def/concat{mat" +"rix currentmatrix matrix concatmatrix setmatrix}def/makepattern{gsave<>begin dup/XUID[1000000 @patcnt]put mx/makepattern sysexec dup dup begi" +"n PatternType @patcnt BBox aload pop XStep YStep PaintType mx aload pop 15(mak" +"epattern)prcmd :newpath matrix setmatrix PaintProc 0 1(makepattern)prcmd end/@" +"patcnt @patcnt 1 add store end grestore}def/setpattern{begin PatternType 1 eq{" +"PaintType 1 eq{XUID aload pop exch pop 1}{:gsave[currentcolorspace aload lengt" +"h -1 roll pop]setcolorspace/setcolor sysexec XUID aload pop exch pop currentrg" +"bcolor :grestore 4}ifelse(setpattern)prcmd}{/setpattern sysexec}ifelse end}def" +"/setcolor{dup type/dicttype eq{setpattern}{/setcolor sysexec/currentrgbcolor s" +"ysexec setrgbcolor}ifelse}def/setgray 1 defpr/setcmykcolor 4 defpr/sethsbcolor" +" 3 defpr/setrgbcolor 3 defpr/.setopacityalpha{dup/.setopacityalpha sysexec 1(s" +"etopacityalpha)prcmd}def "; diff --git a/tests/PSInterpreterTest.cpp b/tests/PSInterpreterTest.cpp index d7ce74c3..4be16df8 100644 --- a/tests/PSInterpreterTest.cpp +++ b/tests/PSInterpreterTest.cpp @@ -86,7 +86,7 @@ TEST(PSInterpreterTest, init) { PSTestActions actions; PSInterpreter psi(&actions); ASSERT_TRUE(psi.active()); - ASSERT_EQ(actions.result(), ""); + EXPECT_EQ(actions.result(), ""); } @@ -94,19 +94,19 @@ TEST(PSInterpreterTest, gsave_grestore) { PSTestActions actions; PSInterpreter psi(&actions); psi.execute("gsave "); - ASSERT_EQ(actions.result(), "gsave;"); + EXPECT_EQ(actions.result(), "gsave;"); actions.clear(); psi.execute("grestore "); - ASSERT_EQ(actions.result(), "setlinewidth 1;setlinecap 0;setlinejoin 0;setmiterlimit 10;setrgbcolor 0 0 0;setmatrix 1 0 0 1 0 0;applyscalevals 1 1 1;setdash 0;grestore;"); + EXPECT_EQ(actions.result(), "setlinewidth 1;setlinecap 0;setlinejoin 0;setmiterlimit 10;setrgbcolor 0 0 0;setmatrix 1 0 0 1 0 0;applyscalevals 1 1 1;setdash 0;grestore;"); actions.clear(); psi.execute("1 setlinecap 5 setmiterlimit 0 1 0 setrgbcolor gsave 0 setlinecap 10 setmiterlimit "); - ASSERT_EQ(actions.result(), "setlinecap 1;setmiterlimit 5;setrgbcolor 0 1 0;gsave;setlinecap 0;setmiterlimit 10;"); + EXPECT_EQ(actions.result(), "setlinecap 1;setmiterlimit 5;setrgbcolor 0 1 0;gsave;setlinecap 0;setmiterlimit 10;"); actions.clear(); psi.execute("grestore "); - ASSERT_EQ(actions.result(), "setlinewidth 1;setlinecap 1;setlinejoin 0;setmiterlimit 5;setrgbcolor 0 1 0;setmatrix 1 0 0 1 0 0;applyscalevals 1 1 1;setdash 0;grestore;"); + EXPECT_EQ(actions.result(), "setlinewidth 1;setlinecap 1;setlinejoin 0;setmiterlimit 5;setrgbcolor 0 1 0;setmatrix 1 0 0 1 0 0;applyscalevals 1 1 1;setdash 0;grestore;"); } @@ -114,11 +114,11 @@ TEST(PSInterpreterTest, stroke_fill) { PSTestActions actions; PSInterpreter psi(&actions); psi.execute("0 0 moveto 10 10 lineto 0 10 lineto closepath stroke "); - ASSERT_EQ(actions.result(), "newpath 1;moveto 0 0;lineto 10 10;lineto 0 10;closepath;stroke;"); + EXPECT_EQ(actions.result(), "newpath 1;moveto 0 0;lineto 10 10;lineto 0 10;closepath;stroke;"); actions.clear(); psi.execute("0 0 moveto 10 10 lineto 0 10 lineto closepath fill "); - ASSERT_EQ(actions.result(), "newpath 1;moveto 0 0;lineto 10 10;lineto 0 10;closepath;fill;"); + EXPECT_EQ(actions.result(), "newpath 1;moveto 0 0;lineto 10 10;lineto 0 10;closepath;fill;"); } @@ -126,11 +126,11 @@ TEST(PSInterpreterTest, clip) { PSTestActions actions; PSInterpreter psi(&actions); psi.execute("initclip "); - ASSERT_EQ(actions.result(), "initclip;"); + EXPECT_EQ(actions.result(), "initclip;"); actions.clear(); psi.execute("0 0 moveto 10 10 lineto 0 10 lineto closepath clip "); - ASSERT_EQ(actions.result(), "newpath 0;moveto 0 0;lineto 10 10;lineto 0 10;closepath;clip;"); + EXPECT_EQ(actions.result(), "newpath 0;moveto 0 0;lineto 10 10;lineto 0 10;closepath;clip;"); } @@ -138,7 +138,7 @@ TEST(PSInterpreterTest, transform) { PSTestActions actions; PSInterpreter psi(&actions); psi.execute("10 10 scale 90 rotate 100 -100 translate "); - ASSERT_EQ(actions.result(), "scale 10 10;rotate 90;translate 100 -100;"); + EXPECT_EQ(actions.result(), "scale 10 10;applyscalevals 10 10 1;rotate 90;applyscalevals 10 10 0;translate 100 -100;"); } @@ -146,7 +146,7 @@ TEST(PSInterpreterTest, calculate) { PSTestActions actions; PSInterpreter psi(&actions); psi.execute("2 3 add 4 mul 5 div rotate "); - ASSERT_EQ(actions.result(), "rotate 4;"); + ASSERT_EQ(actions.result(), "rotate 4;applyscalevals 1 1 0.997564;"); } @@ -154,19 +154,19 @@ TEST(PSInterpreterTest, setlinewidth) { PSTestActions actions; PSInterpreter psi(&actions); psi.execute("10 setlinewidth "); - ASSERT_EQ(actions.result(), "applyscalevals 1 1 1;setlinewidth 10;"); + EXPECT_EQ(actions.result(), "setlinewidth 10;"); actions.clear(); psi.execute("5 5 scale 10 setlinewidth "); - ASSERT_EQ(actions.result(), "scale 5 5;applyscalevals 5 5 1;setlinewidth 10;"); + EXPECT_EQ(actions.result(), "scale 5 5;applyscalevals 5 5 1;setlinewidth 10;"); actions.clear(); psi.execute("90 rotate 10 setlinewidth "); - ASSERT_EQ(actions.result(), "rotate 90;applyscalevals 5 5 0;setlinewidth 10;"); + EXPECT_EQ(actions.result(), "rotate 90;applyscalevals 5 5 0;setlinewidth 10;"); actions.clear(); psi.execute("-30 rotate 10 setlinewidth "); - ASSERT_EQ(actions.result(), "rotate -30;applyscalevals 5 5 0.5;setlinewidth 10;"); + EXPECT_EQ(actions.result(), "rotate -30;applyscalevals 5 5 0.5;setlinewidth 10;"); } @@ -174,8 +174,8 @@ TEST(PSInterpreterTest, matrix) { PSTestActions actions; PSInterpreter psi(&actions); psi.execute("matrix setmatrix "); - ASSERT_EQ(actions.result(), "applyscalevals 1 1 1;setmatrix 1 0 0 1 0 0;"); + EXPECT_EQ(actions.result(), "setmatrix 1 0 0 1 0 0;applyscalevals 1 1 1;"); actions.clear(); psi.execute("10 100 translate 30 rotate matrix currentmatrix setmatrix "); - ASSERT_EQ(actions.result(), "translate 10 100;rotate 30;applyscalevals 1 1 0.107493;setmatrix 0.866025 0.5 -0.5 0.866025 10 100;"); + EXPECT_EQ(actions.result(), "translate 10 100;rotate 30;applyscalevals 1 1 0.866025;setmatrix 0.866025 0.5 -0.5 0.866025 10 100;applyscalevals 1 1 0.866025;"); }