]> mj.ucw.cz Git - paperjam.git/commitdiff
Implemented book
authorMartin Mares <mj@ucw.cz>
Wed, 4 Apr 2018 11:24:55 +0000 (13:24 +0200)
committerMartin Mares <mj@ucw.cz>
Wed, 4 Apr 2018 11:24:55 +0000 (13:24 +0200)
TODO
cmds.cc

diff --git a/TODO b/TODO
index a155a81a77292907b68325a11b165c1be2ec86d5..8d36b9c466921a209f62fbdbd6778770d4d578e2 100644 (file)
--- a/TODO
+++ b/TODO
@@ -3,6 +3,7 @@
 - Better error messages from instantiation
 - page->index: use or remove
 - rename page->bbox to page->image_box?
+- "-f" switch
 
 | # Position bbox on a new paper
 | paper("a4")
 | margins ... params like expand
 
 cropmarks
-       style=box       # Box around image
-       style=cross     # Crosses in the corners
-       style=halfcross # Half-crosses in the corners (default)
+       mark=box        # Box around image
+       mark=cross      # Crosses in the corners
+       mark=out        # Out-pointing half-crosses in the corners (default)
+       mark=in         # In-pointing half-crosses
        pen=1pt         # Line width
        len=5mm         # Cross arm length
        dist=5mm        # Distance from border
@@ -44,6 +46,7 @@ book
 crop
        bleed=5mm       # Allow bleeding over the image box
 
+# Can be written as: mix(cat) { modulo(2){1}, modulo(2){2} }
 duplex
        long-edge
 
@@ -61,6 +64,7 @@ modulo
 #      - paper size + margins
 #      - scale + margins
 nup(hnum, vnum)
+       by=row/column   # Filling order (default: row)
        paper / w / h   # Specify paper size, default=copy from 1st image
        + fit options (*margin, pos)
        crop            # Crop to image
@@ -69,3 +73,9 @@ nup(hnum, vnum)
        tile            # Tile with copies of a single page
        hspace / vspace / space # Distance between tiles
        + cropmarks?
+
+# Send pages to multiple pipes and merge their results
+mix { ..., ..., ...}
+       cat             # Concatenate results (default is interleave)
+       cycle           # When one pipe ends earlier, cycle it from start
+       pad             # When one pipe ends earlier, add blank pages
diff --git a/cmds.cc b/cmds.cc
index 65a9c4159ac534c96686459ac2faca8a75207482..a0e0548eb3fb1ec3d5d814b7b464eeecfb7cb012 100644 (file)
--- a/cmds.cc
+++ b/cmds.cc
@@ -789,6 +789,52 @@ static const arg_def add_blank_args[] = {
   { NULL,      0 }
 };
 
+/*** book ***/
+
+class book_cmd : public cmd_exec {
+  int n;
+public:
+  book_cmd(cmd *c)
+    {
+      n = c->arg("n")->as_int(0);
+      if (n % 4)
+        die("Number of pages per signature must be divisible by 4");
+    }
+  vector<page *> process(vector<page *> &pages) override;
+};
+
+vector<page *> book_cmd::process(vector<page *> &pages)
+{
+  vector<page *> in, out;
+
+  in = pages;
+  while (in.size() % 4)
+    in.push_back(new empty_page(in[0]->width, in[0]->height));
+
+  int i = 0;
+  while (i < (int) in.size())
+    {
+      int sig = in.size() - i;
+      if (n)
+       sig = min(sig, n);
+      for (int j=0; j<sig/2; j+=2)
+       {
+         out.push_back(in[i + sig-1-j]);
+         out.push_back(in[i + j]);
+         out.push_back(in[i + j+1]);
+         out.push_back(in[i + sig-2-j]);
+       }
+      i += sig;
+    }
+
+  return out;
+}
+
+static const arg_def book_args[] = {
+  { "n",       AT_INT | AT_POSITIONAL },
+  { NULL,      0 }
+};
+
 /*** Command table ***/
 
 template<typename T> cmd_exec *ctor(cmd *c) { return new T(c); }
@@ -810,5 +856,6 @@ const cmd_def cmd_table[] = {
   { "expand",  expand_args,    0,      &ctor<expand_cmd>       },
   { "margins", margins_args,   0,      &ctor<margins_cmd>      },
   { "add-blank",add_blank_args,        0,      &ctor<add_blank_cmd>    },
+  { "book",    book_args,      0,      &ctor<book_cmd>         },
   { NULL,      NULL,           0,      NULL    }
 };