]> mj.ucw.cz Git - paperjam.git/blobdiff - cmds.cc
Implemented add-blank
[paperjam.git] / cmds.cc
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    }
 };