]> mj.ucw.cz Git - paperjam.git/commitdiff
Nup: Merging of boxes and the mixed switch
authorMartin Mares <mj@ucw.cz>
Fri, 6 Apr 2018 17:53:49 +0000 (19:53 +0200)
committerMartin Mares <mj@ucw.cz>
Fri, 6 Apr 2018 17:53:49 +0000 (19:53 +0200)
TODO
cmds.cc

diff --git a/TODO b/TODO
index e7d08eb8d67b009753bb686837a924f0e691a934..a1ce8399ec5615685ca20e6277cacfd3ce1f896b 100644 (file)
--- 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 262ad365feaffeb3f7483d8a2ea495e7d5bb2a9e..aa68e2e97bd38e9cd679c2db36fd5fed24c0c9b9 100644 (file)
--- 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<page *> nup_cmd::process(vector<page *> &pages)
 {
   vector<page *> 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<page *> in;
@@ -982,7 +1002,9 @@ void nup_cmd::find_config(vector<page *> &in, BBox *page_boxes)
   st.tile_w = st.tile_h = 0;
   for (int i=0; i<num_tiles; i++)
     {
-      if (crop)
+      if (!mixed)
+       page_boxes[i] = common_page_box;
+      else if (crop)
        page_boxes[i] = in[i]->image_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,