From a2b212c3344b2e709dfb5d923029526bb07bf3fb Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sun, 1 Apr 2018 12:34:19 +0200 Subject: [PATCH] Rotate works --- TODO | 1 + cmds.cc | 29 ++++++++++++++++++++++++++--- jam.h | 6 +++--- parse.cc | 8 ++++---- 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/TODO b/TODO index 5ecb29c..c2e744d 100644 --- 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 24fae4e..34fd25a 100644 --- a/cmds.cc +++ b/cmds.cc @@ -114,8 +114,27 @@ vector rotate_cmd::process(vector &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 dddaa81..b384ddd 100644 --- 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 ""; } }; diff --git a/parse.cc b/parse.cc index a68dd36..ea6d6cd 100644 --- 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 " " + 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 " " + 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 " \"" + val + '"'; } }; static arg_val null_arg; -- 2.39.2