From 356034e375735ec10ea8e0b0b54698c6a297a756 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Wed, 4 Apr 2018 13:24:55 +0200 Subject: [PATCH] Implemented book --- TODO | 16 +++++++++++++--- cmds.cc | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/TODO b/TODO index a155a81..8d36b9c 100644 --- 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") @@ -30,9 +31,10 @@ | 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 65a9c41..a0e0548 100644 --- 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 process(vector &pages) override; +}; + +vector book_cmd::process(vector &pages) +{ + vector 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 cmd_exec *ctor(cmd *c) { return new T(c); } @@ -810,5 +856,6 @@ const cmd_def cmd_table[] = { { "expand", expand_args, 0, &ctor }, { "margins", margins_args, 0, &ctor }, { "add-blank",add_blank_args, 0, &ctor }, + { "book", book_args, 0, &ctor }, { NULL, NULL, 0, NULL } }; -- 2.39.2