]> mj.ucw.cz Git - paperjam.git/commitdiff
Implemented add-blank
authorMartin Mares <mj@ucw.cz>
Tue, 3 Apr 2018 21:31:30 +0000 (23:31 +0200)
committerMartin Mares <mj@ucw.cz>
Tue, 3 Apr 2018 21:31:30 +0000 (23:31 +0200)
TODO
cmds.cc
parse.cc

diff --git a/TODO b/TODO
index 289e387e72c48dc37bc81757e9e4d93f29ae4047..a155a81a77292907b68325a11b165c1be2ec86d5 100644 (file)
--- a/TODO
+++ b/TODO
@@ -52,8 +52,10 @@ duplex
 modulo
        half
 
-# Add an empty page after the current one
-add-blank
+| # Add an empty page after the current one
+| add-blank
+|      n=
+|      paper...
 
 # Set either:
 #      - paper size + margins
diff --git a/cmds.cc b/cmds.cc
index 6acb19ce79bebe1719e1aafca156bfcc9d2d2bc4..65a9c4159ac534c96686459ac2faca8a75207482 100644 (file)
--- a/cmds.cc
+++ b/cmds.cc
@@ -372,7 +372,7 @@ public:
     {
       pipe = c->pipe;
     }
-  vector<page *> process(vector<page *> &pages);
+  vector<page *> process(vector<page *> &pages) override;
 };
 
 static int validate_page_index(vector<page *> &pages, int idx)
@@ -414,7 +414,7 @@ public:
     {
       pipe = c->pipe;
     }
-  vector<page *> process(vector<page *> &pages);
+  vector<page *> process(vector<page *> &pages) override;
 };
 
 static pipeline_branch *find_branch(pipeline *pipe, vector <page *> &pages, int idx)
@@ -467,7 +467,7 @@ public:
        die("Modulo must have n > 0");
       pipe = c->pipe;
     }
-  vector<page *> process(vector<page *> &pages);
+  vector<page *> process(vector<page *> &pages) override;
 };
 
 vector<page *> modulo_cmd::process(vector<page *> &pages)
@@ -520,12 +520,12 @@ static const arg_def modulo_args[] = {
   { NULL,      0 }
 };
 
-/*** draw_bbox ***/
+/*** draw-bbox ***/
 
 class draw_bbox_cmd : public cmd_exec {
 public:
   draw_bbox_cmd(cmd *c UNUSED) { }
-  vector<page *> process(vector<page *> &pages);
+  vector<page *> process(vector<page *> &pages) override;
 };
 
 class draw_bbox_page : public page {
@@ -559,7 +559,7 @@ vector<page *> draw_bbox_cmd::process(vector<page *> &pages)
 class merge_cmd : public cmd_exec {
 public:
   merge_cmd(cmd *c UNUSED) { }
-  vector<page *> process(vector<page *> &pages);
+  vector<page *> process(vector<page *> &pages) override;
 };
 
 class merge_page : public page {
@@ -751,6 +751,44 @@ static const arg_def margins_args[] = {
   { NULL,      0 }
 };
 
+/*** add-blank ***/
+
+class add_blank_cmd : public cmd_exec {
+  int n;
+  paper_spec paper;
+public:
+  add_blank_cmd(cmd *c) : paper(c, true)
+    {
+      n = c->arg("n")->as_int(1);
+    }
+  vector<page *> process(vector<page *> &pages) override;
+};
+
+vector<page *> add_blank_cmd::process(vector<page *> &pages)
+{
+  vector<page *> out;
+
+  for (auto p: pages)
+    {
+      out.push_back(p);
+      for (int i=0; i<n; i++)
+       {
+         double w = paper.w, h = paper.h;
+         if (is_zero(w) || is_zero(h))
+           w = p->width, h = p->height;
+         out.push_back(new empty_page(w, h));
+       }
+    }
+
+  return out;
+}
+
+static const arg_def add_blank_args[] = {
+  { "n",       AT_INT | AT_POSITIONAL },
+  PAPER_ARGS,
+  { NULL,      0 }
+};
+
 /*** Command table ***/
 
 template<typename T> cmd_exec *ctor(cmd *c) { return new T(c); }
@@ -764,12 +802,13 @@ const cmd_def cmd_table[] = {
   { "select",  no_args,        1,      &ctor<select_cmd>       },
   { "apply",   no_args,        1,      &ctor<apply_cmd>        },
   { "modulo",  modulo_args,    1,      &ctor<modulo_cmd>       },
-  { "draw_bbox",no_args,       0,      &ctor<draw_bbox_cmd>    },
+  { "draw-bbox",no_args,       0,      &ctor<draw_bbox_cmd>    },
   { "merge",   no_args,        0,      &ctor<merge_cmd>        },
   { "paper",   paper_args,     0,      &ctor<paper_cmd>        },
   { "scaleto", scaleto_args,   0,      &ctor<scaleto_cmd>      },
   { "fit",     fit_args,       0,      &ctor<fit_cmd>          },
   { "expand",  expand_args,    0,      &ctor<expand_cmd>       },
   { "margins", margins_args,   0,      &ctor<margins_cmd>      },
+  { "add-blank",add_blank_args,        0,      &ctor<add_blank_cmd>    },
   { NULL,      NULL,           0,      NULL    }
 };
index 5158eeb72fa3031295f7b752d34d319d15b2da31..b48b2f44c0fc1a4520cb8f82b42a1907d9fc12c0 100644 (file)
--- a/parse.cc
+++ b/parse.cc
@@ -78,7 +78,8 @@ static token_type get_next_token()
       while (*in_pos >= 'A' && *in_pos <= 'Z' ||
             *in_pos >= 'a' && *in_pos <= 'z' ||
             *in_pos >= '0' && *in_pos <= '9' ||
-            *in_pos == '_')
+            *in_pos == '_' ||
+            *in_pos == '-')
        token += *in_pos++;
       return TOK_IDENT;
     }