]> mj.ucw.cz Git - paperjam.git/commitdiff
Rotate works
authorMartin Mares <mj@ucw.cz>
Sun, 1 Apr 2018 10:34:19 +0000 (12:34 +0200)
committerMartin Mares <mj@ucw.cz>
Sun, 1 Apr 2018 10:34:19 +0000 (12:34 +0200)
TODO
cmds.cc
jam.h
parse.cc

diff --git a/TODO b/TODO
index 5ecb29cf70a54d7fd1a193fcb09c430ce916e79b..c2e744d166d78d2dbfa9d70b48d59acbd68e93c1 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,2 +1,3 @@
 - Integrate pdf-tools.cc with the rest of the code
 - What if an input page specifies /Rotate?
+- Better error messages from instantiation
diff --git a/cmds.cc b/cmds.cc
index 24fae4ebd1685033f09787a53a401bb5a2ca202f..34fd25abd9bdc9b4109bd32173d4b13ba938a475 100644 (file)
--- a/cmds.cc
+++ b/cmds.cc
@@ -114,8 +114,27 @@ vector<page *> rotate_cmd::process(vector<page *> &pages)
   for (auto p: pages)
     {
       xform_page *q = new xform_page(p, p->width, p->height);
-      // FIXME: This does not work yet
-      q->xform.rotate_deg(90);
+      switch (deg)
+       {
+       case 0:
+         break;
+       case 90:
+         q->xform.rotate_deg(-90);
+         q->xform.shift(0, p->width);
+         swap(q->width, q->height);
+         break;
+       case 180:
+         q->xform.rotate_deg(180);
+         q->xform.shift(p->width, p->height);
+         break;
+       case 270:
+         q->xform.rotate_deg(90);
+         q->xform.shift(p->height, 0);
+         swap(q->width, q->height);
+         break;
+       default:
+         abort();
+       }
       out.push_back(q);
     }
   return out;
@@ -129,7 +148,11 @@ static const arg_def rotate_args[] = {
 static cmd_exec *rotate_ctor(cmd *c)
 {
   rotate_cmd *r = new rotate_cmd;
-  r->deg = c->args.at(0)->as_int(0);
+  r->deg = c->args.at(0)->as_int(0) % 360;
+  if (r->deg < 0)
+    r->deg += 360;
+  if (r->deg % 90)
+    die("Rotate requires a multiple of 90 degrees");
   return r;
 }
 
diff --git a/jam.h b/jam.h
index dddaa81fb3e669416b527d44a12fdc0fd73c7c9c..b384ddde38a8d3cff2736dec4153a9df0cdad7a6 100644 (file)
--- a/jam.h
+++ b/jam.h
@@ -31,9 +31,9 @@ struct arg_def {
 class arg_val {
 public:
   virtual bool given() { return false; }
-  int as_int(int def) { return def; }
-  double as_double(double def) { return def; }
-  const string as_string(const string def) { return def; }
+  virtual int as_int(int def) { return def; }
+  virtual double as_double(double def) { return def; }
+  virtual const string as_string(const string def) { return def; }
   virtual string dump() { return "<undef>"; }
 };
 
index a68dd366dd788d0fc9aa351c59231d387bba6a63..ea6d6cda812d1beb92458944b5899075f40646f2 100644 (file)
--- a/parse.cc
+++ b/parse.cc
@@ -160,7 +160,7 @@ public:
   arg_int(int x) { val = x; }
   bool given() { return true; }
   int as_int(int def UNUSED) { return val; }
-  string dump() { return to_string(val); }
+  string dump() { return "<int> " + to_string(val); }
 };
 
 class arg_double : public arg_val {
@@ -169,7 +169,7 @@ public:
   arg_double(double x) { val = x; }
   bool given() { return true; }
   double as_double(double def UNUSED) { return val; }
-  string dump() { return to_string(val); }
+  string dump() { return "<double> " + to_string(val); }
 };
 
 class arg_string : public arg_val {
@@ -177,8 +177,8 @@ class arg_string : public arg_val {
 public:
   arg_string(string x) { val = x; }
   bool given() { return true; }
-  string as_string(string def UNUSED) { return val; }
-  string dump() { return '"' + val + '"'; }
+  const string as_string(string def UNUSED) { return val; }
+  string dump() { return "<string> \"" + val + '"'; }
 };
 
 static arg_val null_arg;