From b07e0d4fa40e70246e9ffe202d7941a6d410fdc0 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 6 Apr 2018 19:53:49 +0200 Subject: [PATCH] Nup: Merging of boxes and the mixed switch --- TODO | 28 ++++++++++++++-------------- cmds.cc | 27 +++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/TODO b/TODO index e7d08eb..a1ce839 100644 --- a/TODO +++ b/TODO @@ -2,7 +2,6 @@ - What if an input page specifies /Rotate? - Better error messages from instantiation - "-f" switch -- nup(crop): take max of all bboxes first? | # Position bbox on a new paper | paper("a4") @@ -59,19 +58,20 @@ duplex | n= | paper... -# Set either: -# - paper size + margins -# - scale + margins -nup(hnum, vnum) - by=rows/cols # Filling order (default: rows) - by=tile # Tile with copies of a single page - paper / w / h # Specify paper size, default=copy from 1st image - + fit options (*margin, pos) - tpos=... # Position of images inside their tiles (default: tl) - crop # Crop to image - rotate=1 # Override rotation decision - scale=1 # Override scaling factor - hspace / vspace / space # Distance between tiles +| # Set either: +| # - paper size + margins +| # - scale + margins +| nup(hnum, vnum) +| by=rows/cols # Filling order (default: rows) +| by=tile # Tile with copies of a single page +| paper / w / h # Specify paper size, default=copy from 1st image +| + fit options (*margin, pos) +| tpos=... # Position of images inside their tiles (default: tl) +| crop # Crop to image +| mixed # Allow images of different sizes +| rotate=1 # Override rotation decision +| scale=1 # Override scaling factor +| hspace / vspace / space # Distance between tiles + cropmarks? # Send pages to multiple pipes and merge their results diff --git a/cmds.cc b/cmds.cc index 262ad36..aa68e2e 100644 --- a/cmds.cc +++ b/cmds.cc @@ -862,6 +862,7 @@ class nup_cmd : public cmd_exec { BY_TILE, } fill_by; bool crop; + bool mixed; int rotate; double scale; paper_spec paper; @@ -876,6 +877,7 @@ class nup_cmd : public cmd_exec { void try_config(nup_state &st); nup_state best; bool found_solution; + BBox common_page_box; public: nup_cmd(cmd *c) : paper(c), marg(c, "margin", "margin"), pos(c), tpos(c->arg("tpos")->as_string("tl")) @@ -900,6 +902,7 @@ public: die("Parameter \"by\" must be rows/cols/tile"); crop = c->arg("crop")->as_int(0); + mixed = c->arg("mixed")->as_int(0); rotate = c->arg("rotate")->as_int(-1); scale = c->arg("scale")->as_double(0); @@ -919,8 +922,25 @@ public: vector nup_cmd::process(vector &pages) { vector out; - int i = 0; + // Unless mixed is given, find the common page size + if (!mixed) + { + for (int i=0; i < (int) pages.size(); i++) + { + page *p = pages[i]; + BBox pb = crop ? p->image_box : BBox(p->width, p->height); + if (!i) + common_page_box = pb; + else + common_page_box.join(pb); + } + debug("NUP: Common page box [%.3f %.3f]-[%.3f %.3f]", + common_page_box.x_min, common_page_box.y_min, common_page_box.x_max, common_page_box.y_max); + } + + // Process one tile set after another + int i = 0; while (i < (int) pages.size()) { vector in; @@ -982,7 +1002,9 @@ void nup_cmd::find_config(vector &in, BBox *page_boxes) st.tile_w = st.tile_h = 0; for (int i=0; iimage_box; else page_boxes[i] = BBox(in[i]->width, in[i]->height); @@ -1122,6 +1144,7 @@ static const arg_def nup_args[] = { { "m", AT_INT | AT_POSITIONAL }, { "by", AT_STRING }, { "crop", AT_SWITCH }, + { "mixed", AT_SWITCH }, { "rotate", AT_SWITCH }, { "scale", AT_DOUBLE }, PAPER_ARGS, -- 2.39.2