From 2a8420aa1fe128f0c2bda016efa658e3fcb7fbd7 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 6 Apr 2018 19:39:46 +0200 Subject: [PATCH] page->bbox renamed to page->image_box We have too many bboxes with different meaning here... --- TODO | 2 -- cmds.cc | 32 ++++++++++++++++---------------- jam.h | 6 +++--- pdf.cc | 20 ++++++++++---------- 4 files changed, 29 insertions(+), 31 deletions(-) diff --git a/TODO b/TODO index 8686e3b..e7d08eb 100644 --- a/TODO +++ b/TODO @@ -1,8 +1,6 @@ - Integrate pdf-tools.cc with the rest of the code - What if an input page specifies /Rotate? - Better error messages from instantiation -- page->index: use or remove -- rename page->bbox to page->image_box? - "-f" switch - nup(crop): take max of all bboxes first? diff --git a/cmds.cc b/cmds.cc index a39fe6e..262ad36 100644 --- a/cmds.cc +++ b/cmds.cc @@ -46,8 +46,8 @@ xform_page::xform_page(page *p, pdf_matrix xf) width = media.width(); height = media.height(); - bbox = p->bbox; - bbox.transform(xf); + image_box = p->image_box; + image_box.transform(xf); } void xform_page::render(out_context *out, pdf_matrix parent_xform) @@ -550,7 +550,7 @@ void draw_bbox_page::render(out_context *out, pdf_matrix xform) "q " + xform.to_string() + " cm " + "0 1 0 RG " + - bbox.to_rect() + " re S " + + image_box.to_rect() + " re S " + "Q "; } @@ -583,14 +583,14 @@ public: { width = p->width; height = p->height; - bbox = p->bbox; + image_box = p->image_box; first = false; } else { if (!is_equal(width, p->width) || !is_equal(height, p->height)) die("All pages participating in a merge must have the same dimensions"); - bbox.join(p->bbox); + image_box.join(p->image_box); } } } @@ -619,7 +619,7 @@ public: page *process_page(page *p) override { BBox paper_box = BBox(paper.w, paper.h); - pdf_matrix xf = pos.place(p->bbox, paper_box); + pdf_matrix xf = pos.place(p->image_box, paper_box); page *q = new xform_page(p, xf); q->width = paper.w; q->height = paper.h; @@ -677,7 +677,7 @@ public: if (!is_zero(paper.w) && !is_zero(paper.h)) { // Paper given: scale image to fit paper - BBox orig_box = p->bbox; + BBox orig_box = p->image_box; BBox paper_box = BBox(paper.w, paper.h); marg.shrink_box(&paper_box); xf.scale(scale_to_fit(orig_box, paper_box)); @@ -690,11 +690,11 @@ public: else { // No paper given: adjust paper to fit image - xf.shift(-p->bbox.x_min, -p->bbox.y_min); + xf.shift(-p->image_box.x_min, -p->image_box.y_min); xf.shift(marg.l, marg.b); q = new xform_page(p, xf); - q->width = p->bbox.width() + marg.l + marg.r; - q->height = p->bbox.height() + marg.t + marg.b; + q->width = p->image_box.width() + marg.l + marg.r; + q->height = p->image_box.height() + marg.t + marg.b; } return q; } @@ -742,11 +742,11 @@ public: page *process_page(page *p) override { pdf_matrix xf; - xf.shift(-p->bbox.x_min, -p->bbox.y_min); + xf.shift(-p->image_box.x_min, -p->image_box.y_min); xf.shift(marg.l, marg.b); page *q = new xform_page(p, xf); - q->width = p->bbox.width() + marg.l + marg.r; - q->height = p->bbox.height() + marg.t + marg.b; + q->width = p->image_box.width() + marg.l + marg.r; + q->height = p->image_box.height() + marg.t + marg.b; if (q->width < 0.001 || q->height < 0.001) die("Margins must result in positive page dimensions"); return q; @@ -983,7 +983,7 @@ void nup_cmd::find_config(vector &in, BBox *page_boxes) for (int i=0; ibbox; + page_boxes[i] = in[i]->image_box; else page_boxes[i] = BBox(in[i]->width, in[i]->height); st.tile_w = max(st.tile_w, page_boxes[i].width()); @@ -1082,8 +1082,8 @@ page *nup_cmd::process_single(vector &in) pdf_matrix place_xform = pos.place(grid_box, paper_box); nup_page *p = new nup_page(best); - p->bbox = grid_box; - p->bbox.transform(place_xform); + p->image_box = grid_box; + p->image_box.transform(place_xform); for (int i=0; iindex; width = p->width; height = p->height; - bbox = p->bbox; + image_box = p->image_box; } }; diff --git a/pdf.cc b/pdf.cc index e40e3f1..cf281f5 100644 --- a/pdf.cc +++ b/pdf.cc @@ -47,14 +47,14 @@ in_page::in_page(QPDFObjectHandle inpg, int idx) if (art_box.isNull()) art_box = inpg.getKey("/CropBox"); if (art_box.isNull()) - bbox = BBox(width, height); + image_box = BBox(width, height); else { - bbox = BBox(art_box); - bbox.x_min -= media_box.x_min; - bbox.x_max -= media_box.x_min; - bbox.y_min -= media_box.y_min; - bbox.y_max -= media_box.y_min; + image_box = BBox(art_box); + image_box.x_min -= media_box.x_min; + image_box.x_max -= media_box.x_min; + image_box.y_min -= media_box.y_min; + image_box.y_max -= media_box.y_min; } } @@ -79,10 +79,10 @@ void debug_pages(vector &pages) return; for (auto pg: pages) - debug("Page #%d: media[%.3f %.3f] bbox[%.3f %.3f %.3f %.3f]", + debug("Page #%d: media[%.3f %.3f] image[%.3f %.3f %.3f %.3f]", pg->index, pg->width, pg->height, - pg->bbox.x_min, pg->bbox.y_min, pg->bbox.x_max, pg->bbox.y_max); + pg->image_box.x_min, pg->image_box.y_min, pg->image_box.x_max, pg->image_box.y_max); } vector run_command_list(list &cmds, vector &pages) @@ -138,7 +138,7 @@ void process(list &cmds) out_page.replaceKey("/Type", QPDFObjectHandle::newName("/Page")); out_page.replaceKey("/MediaBox", BBox(pg->width, pg->height).to_array()); // FIXME: - // out_page.replaceKey("/CropBox", pg->bbox.to_array()); + // out_page.replaceKey("/CropBox", pg->image_box.to_array()); out_page.replaceKey("/Contents", contents); out_page.replaceKey("/Resources", out.resources); out_pdf.addPage(out_page, false); @@ -227,5 +227,5 @@ static void do_recalc_bbox(vector &pages, const char *in_name) die("Ghostscript failed to produce the right number of bboxes"); for (size_t i=0; ibbox = bboxes[i]; + pages[i]->image_box = bboxes[i]; } -- 2.39.5