]> mj.ucw.cz Git - paperjam.git/commitdiff
Nup has acquired a "tpos" option
authorMartin Mares <mj@ucw.cz>
Fri, 6 Apr 2018 08:18:51 +0000 (10:18 +0200)
committerMartin Mares <mj@ucw.cz>
Fri, 6 Apr 2018 08:18:51 +0000 (10:18 +0200)
TODO
cmds.cc

diff --git a/TODO b/TODO
index b6009ca2b7f2f49dfa902f80ab1def75cabeb67d..8686e3bd02921cbfc62416e3fe008a1a8e95b779 100644 (file)
--- a/TODO
+++ b/TODO
@@ -5,7 +5,6 @@
 - rename page->bbox to page->image_box?
 - "-f" switch
 - nup(crop): take max of all bboxes first?
-- nup: apply pos to placement of images in tiles
 
 | # Position bbox on a new paper
 | paper("a4")
@@ -70,6 +69,7 @@ nup(hnum, vnum)
        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
diff --git a/cmds.cc b/cmds.cc
index 4e101b4fad605f13eb07fed4e993eb40cef7d495..a39fe6eb15eb6e3d9d7b5272ef28c5afe296f7ef 100644 (file)
--- a/cmds.cc
+++ b/cmds.cc
@@ -867,6 +867,7 @@ class nup_cmd : public cmd_exec {
   paper_spec paper;
   margin_spec marg;
   pos_spec pos;
+  pos_spec tpos;
   double hspace, vspace;
 
   // Processing state
@@ -877,7 +878,7 @@ class nup_cmd : public cmd_exec {
   bool found_solution;
 
 public:
-  nup_cmd(cmd *c) : paper(c), marg(c, "margin", "margin"), pos(c)
+  nup_cmd(cmd *c) : paper(c), marg(c, "margin", "margin"), pos(c), tpos(c->arg("tpos")->as_string("tl"))
     {
       grid_n = c->arg("n")->as_int(0);
       grid_m = c->arg("m")->as_int(0);
@@ -1046,9 +1047,10 @@ void nup_cmd::find_config(vector<page *> &in, BBox *page_boxes)
        }
     }
 
-  debug_indent -= 4;
   if (!found_solution)
     die("Nup did not find a feasible solution");
+  debug("Best: %dx%d on %.3f x %.3f", best.cols, best.rows, best.paper_w, best.paper_h);
+  debug_indent -= 4;
 }
 
 class nup_page : public page {
@@ -1069,16 +1071,18 @@ page *nup_cmd::process_single(vector<page *> &in)
 {
   BBox page_boxes[num_tiles];
   find_config(in, page_boxes);
+  double tw = best.scale * best.tile_w;
+  double th = best.scale * best.tile_h;
 
-  // Construct transform from paper to window with tiles
+  // Construct transform from paper to grid of tiles
   BBox paper_box(best.paper_w, best.paper_h);
   marg.shrink_box(&paper_box);
-  BBox tile_box(best.cols * best.scale * best.tile_w + (best.cols-1) * hspace,
-                best.rows * best.scale * best.tile_h + (best.rows-1) * vspace);
-  pdf_matrix place_xform = pos.place(tile_box, paper_box);
+  BBox grid_box(best.cols * tw + (best.cols-1) * hspace,
+                best.rows * th + (best.rows-1) * vspace);
+  pdf_matrix place_xform = pos.place(grid_box, paper_box);
 
   nup_page *p = new nup_page(best);
-  p->bbox = tile_box;
+  p->bbox = grid_box;
   p->bbox.transform(place_xform);
 
   for (int i=0; i<num_tiles; i++)
@@ -1096,9 +1100,15 @@ page *nup_cmd::process_single(vector<page *> &in)
        }
 
       pdf_matrix m;
-      m.shift(-page_boxes[i].x_min, -page_boxes[i].y_min);
+      BBox &page_box = page_boxes[i];
+      m.shift(-page_box.x_min, -page_box.y_min);
       m.scale(best.scale);
-      m.shift(c * (best.scale*best.tile_w + hspace), (best.rows-1-r) * (best.scale*best.tile_h + vspace));
+      page_box.transform(m);
+
+      double x = c * (tw + hspace);
+      double y = (best.rows-1-r) * (th + vspace);
+      BBox tile_box = BBox(x, y, x+tw, y+th);
+      m.concat(tpos.place(page_box, tile_box));
 
       p->orig_pages.push_back(in[i]);
       p->xforms.push_back(m * place_xform);
@@ -1118,6 +1128,7 @@ static const arg_def nup_args[] = {
   MARGIN_ARGS1_NAMED("margin"),
   MARGIN_ARGS2("margin"),
   POS_ARGS,
+  { "tpos",    AT_STRING },
   { "space",   AT_DIMEN },
   { "hspace",  AT_DIMEN },
   { "vspace",  AT_DIMEN },