]> mj.ucw.cz Git - paperjam.git/commitdiff
page->bbox renamed to page->image_box
authorMartin Mares <mj@ucw.cz>
Fri, 6 Apr 2018 17:39:46 +0000 (19:39 +0200)
committerMartin Mares <mj@ucw.cz>
Fri, 6 Apr 2018 17:39:46 +0000 (19:39 +0200)
We have too many bboxes with different meaning here...

TODO
cmds.cc
jam.h
pdf.cc

diff --git a/TODO b/TODO
index 8686e3bd02921cbfc62416e3fe008a1a8e95b779..e7d08eb8d67b009753bb686837a924f0e691a934 100644 (file)
--- 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 a39fe6eb15eb6e3d9d7b5272ef28c5afe296f7ef..262ad365feaffeb3f7483d8a2ea495e7d5bb2a9e 100644 (file)
--- 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<page *> &in, BBox *page_boxes)
   for (int i=0; i<num_tiles; i++)
     {
       if (crop)
-       page_boxes[i] = in[i]->bbox;
+       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<page *> &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; i<num_tiles; i++)
     {
diff --git a/jam.h b/jam.h
index 0653c2506904286e94449c5ed8c64ab8857f69d2..e7e2099c7fb9ac70aeb9f7c70e81174c5b604165 100644 (file)
--- a/jam.h
+++ b/jam.h
@@ -74,15 +74,15 @@ struct page {
   int index;
   double width;                // Physical dimensions of media
   double height;
-  BBox bbox;           // Bounds useful contents
+  BBox image_box;      // Bounds useful contents
   virtual void render(out_context *out UNUSED, pdf_matrix xform UNUSED) { abort(); }
-  page(double _w=0, double _h=0) : index(0), width(_w), height(_h), bbox() { }
+  page(double _w=0, double _h=0) : index(0), width(_w), height(_h), image_box() { }
   page(page *p)
     {
       index = p->index;
       width = p->width;
       height = p->height;
-      bbox = p->bbox;
+      image_box = p->image_box;
     }
 };
 
diff --git a/pdf.cc b/pdf.cc
index e40e3f1c2e388356bf1d64372e33f6a2ca2085e7..cf281f50dcfcb6191e608cce842521bb10bbc7e5 100644 (file)
--- 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<page *> &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<page *> run_command_list(list<cmd *> &cmds, vector<page *> &pages)
@@ -138,7 +138,7 @@ void process(list<cmd *> &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<page *> &pages, const char *in_name)
     die("Ghostscript failed to produce the right number of bboxes");
 
   for (size_t i=0; i<pages.size(); i++)
-    pages[i]->bbox = bboxes[i];
+    pages[i]->image_box = bboxes[i];
 }