From 9f4e1d56505a80f3b8f2dc1a9232c29fd6393ed6 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 6 Apr 2018 10:18:51 +0200 Subject: [PATCH] Nup has acquired a "tpos" option --- TODO | 2 +- cmds.cc | 29 ++++++++++++++++++++--------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/TODO b/TODO index b6009ca..8686e3b 100644 --- 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 4e101b4..a39fe6e 100644 --- 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 &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 &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 &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 }, -- 2.39.5