Skip to content

Commit

Permalink
properly apply CTM to linewidth (closes #77)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgieseki committed Oct 30, 2017
1 parent 009880e commit af51196
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
5 changes: 2 additions & 3 deletions src/PsSpecialHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
class PSPattern;
class XMLElementNode;

class PsSpecialHandler : public SpecialHandler, public DVIEndPageListener, protected PSActions
{
class PsSpecialHandler : public SpecialHandler, public DVIEndPageListener, protected PSActions {
using Path = GraphicsPath<double>;
using ColorSpace = Color::ColorSpace;

Expand Down Expand Up @@ -139,7 +138,7 @@ class PsSpecialHandler : public SpecialHandler, public DVIEndPageListener, prote
void sethsbcolor (std::vector<double> &hsb) override;
void setlinecap (std::vector<double> &p) override {_linecap = uint8_t(p[0]);}
void setlinejoin (std::vector<double> &p) override {_linejoin = uint8_t(p[0]);}
void setlinewidth (std::vector<double> &p) override {_linewidth = p[0] ? scale(p[0]) : 0.5;}
void setlinewidth (std::vector<double> &p) override {_linewidth = scale(p[0] ? p[0] : 0.5);}
void setmatrix (std::vector<double> &p) override;
void setmiterlimit (std::vector<double> &p) override {_miterlimit = p[0];}
void setopacityalpha (std::vector<double> &p) override {_opacityalpha = p[0];}
Expand Down
44 changes: 22 additions & 22 deletions src/psdefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,25 @@ const char *PSInterpreter::PSDEFS =
"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 currentd"
"ash mark 3 1 roll exch aload length 1 add -1 roll counttomark(setdash)prcmd po"
"p}def/save{@UD begin/@saveID vmstatus pop pop def end :save @saveID 1(save)prc"
"md}def/restore{:restore setgstate @UD/@saveID known{@UD begin @saveID end}{0}i"
"felse 1(restore)prcmd}def/gsave 0 defpr/grestore{:grestore setgstate 0(grestor"
"e)prcmd}def/grestoreall{:grestoreall setstate 0(grestoreall)prcmd}def/rotate{d"
"up type/arraytype ne{dup 1(rotate)prcmd}if/rotate sysexec}def/scale{dup type/a"
"rraytype ne{2 copy 2(scale)prcmd}if/scale sysexec}def/translate{dup type/array"
"type ne{2 copy 2(translate)prcmd}if/translate sysexec}def/setmatrix{dup/setmat"
"rix sysexec aload pop 6(setmatrix)prcmd}def/initmatrix{matrix setmatrix}def/co"
"ncat{matrix currentmatrix matrix concatmatrix setmatrix}def/makepattern{gsave<"
"</mx 3 -1 roll>>begin dup/XUID[1000000 @patcnt]put mx/makepattern sysexec dup "
"dup begin PatternType @patcnt BBox aload pop XStep YStep PaintType mx aload po"
"p 15(makepattern)prcmd :newpath matrix setmatrix PaintProc 0 1(makepattern)prc"
"md end/@patcnt @patcnt 1 add store end grestore}def/setpattern{begin PatternTy"
"pe 1 eq{PaintType 1 eq{XUID aload pop exch pop 1}{:gsave[currentcolorspace alo"
"ad length -1 roll pop]setcolorspace/setcolor sysexec XUID aload pop exch pop c"
"urrentrgbcolor :grestore 4}ifelse(setpattern)prcmd}{/setpattern sysexec}ifelse"
" end}def/setcolor{dup type/dicttype eq{setpattern}{/setcolor sysexec/currentrg"
"bcolor sysexec setrgbcolor}ifelse}def/setgray 1 defpr/setcmykcolor 4 defpr/set"
"hsbcolor 3 defpr/setrgbcolor 3 defpr/.setopacityalpha{dup/.setopacityalpha sys"
"exec 1(setopacityalpha)prcmd}def ";
"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<</mx 3 -1 roll>>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 ";
11 changes: 5 additions & 6 deletions tests/PSInterpreterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@

using namespace std;

class PSTestActions : public PSActions
{
class PSTestActions : public PSActions {
public:
void applyscalevals (vector<double> &p) {print("applyscalevals", p);}
void clip (vector<double> &p) {print("clip", p);}
Expand Down Expand Up @@ -99,15 +98,15 @@ TEST(PSInterpreterTest, gsave_grestore) {
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;setdash 0;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;");
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;");
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;setdash 0;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;");
}


Expand Down Expand Up @@ -175,8 +174,8 @@ TEST(PSInterpreterTest, matrix) {
PSTestActions actions;
PSInterpreter psi(&actions);
psi.execute("matrix setmatrix ");
ASSERT_EQ(actions.result(), "setmatrix 1 0 0 1 0 0;");
ASSERT_EQ(actions.result(), "applyscalevals 1 1 1;setmatrix 1 0 0 1 0 0;");
actions.clear();
psi.execute("10 100 translate 30 rotate matrix currentmatrix setmatrix ");
ASSERT_EQ(actions.result(), "translate 10 100;rotate 30;setmatrix 0.866025 0.5 -0.5 0.866025 10 100;");
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;");
}

0 comments on commit af51196

Please sign in to comment.