]> mj.ucw.cz Git - paperjam.git/commitdiff
xform_page() is now a part of pdf.cc
authorMartin Mares <mj@ucw.cz>
Sat, 20 Aug 2022 11:15:05 +0000 (13:15 +0200)
committerMartin Mares <mj@ucw.cz>
Sun, 21 Aug 2022 11:18:48 +0000 (13:18 +0200)
It also remembers the name of the transform for better debug messages.

cmds.cc
jam.h
pdf.cc

diff --git a/cmds.cc b/cmds.cc
index 719058ad367b70e02daaf38e452cf829ee7e74c8..a2ac331fca4377cbbf5c427cf7b0af7096b291dc 100644 (file)
--- a/cmds.cc
+++ b/cmds.cc
@@ -1,7 +1,7 @@
 /*
  *     PaperJam -- Commands
  *
- *     (c) 2018 Martin Mares <mj@ucw.cz>
+ *     (c) 2018--2022 Martin Mares <mj@ucw.cz>
  */
 
 #include <cassert>
@@ -25,41 +25,6 @@ static const arg_def no_args[] = {
 
 /*** Generic routines ***/
 
-// Transformed page
-
-class xform_page : public page {
-  page *orig_page;
-  pdf_matrix xform;
-public:
-  void render(out_context *out, pdf_matrix xform) override;
-  void debug_dump() override
-    {
-      debug("Transform [%s]", xform.to_string().c_str());
-      orig_page->debug_dump();
-    }
-  xform_page(page *p, pdf_matrix xf);
-};
-
-xform_page::xform_page(page *p, pdf_matrix xf)
-{
-  orig_page = p;
-  index = p->index;
-  xform = xf;
-
-  BBox media(p->width, p->height);
-  media.transform(xf);
-  width = media.width();
-  height = media.height();
-
-  image_box = p->image_box;
-  image_box.transform(xf);
-}
-
-void xform_page::render(out_context *out, pdf_matrix parent_xform)
-{
-  orig_page->render(out, xform * parent_xform);
-}
-
 // Commands acting on individual pages
 
 class cmd_exec_simple : public cmd_exec {
@@ -434,7 +399,7 @@ public:
     {
       pdf_matrix m;
       m.shift(x, y);
-      return new xform_page(p, m);
+      return new xform_page(p, "move", m);
     }
 };
 
@@ -458,7 +423,7 @@ public:
     {
       pdf_matrix m;
       m.scale(x_factor, y_factor);
-      return new xform_page(p, m);
+      return new xform_page(p, "scale", m);
     }
 };
 
@@ -483,7 +448,7 @@ public:
     }
   page *process_page(page *p) override
     {
-      return new xform_page(p, pdf_rotation_matrix(deg, p->width, p->height));
+      return new xform_page(p, "rotate", pdf_rotation_matrix(deg, p->width, p->height));
     }
 };
 
@@ -518,7 +483,7 @@ public:
          m.scale(-1, 1);
          m.shift(p->width, 0);
        }
-      return new xform_page(p, m);
+      return new xform_page(p, "flip", m);
     }
 };
 
@@ -797,7 +762,7 @@ public:
     {
       BBox paper_box = BBox(paper.w, paper.h);
       pdf_matrix xf = pos.place(p->image_box, paper_box);
-      page *q = new xform_page(p, xf);
+      page *q = new xform_page(p, "paper", xf);
       q->width = paper.w;
       q->height = paper.h;
       return q;
@@ -825,7 +790,7 @@ public:
       xf.scale(scale_to_fit(orig_box, paper_box));
       orig_box.transform(xf);
       xf.concat(pos.place(orig_box, paper_box));
-      page *q = new xform_page(p, xf);
+      page *q = new xform_page(p, "scaleto", xf);
       q->width = paper.w;
       q->height = paper.h;
       return q;
@@ -860,7 +825,7 @@ public:
          xf.scale(scale_to_fit(orig_box, paper_box));
          orig_box.transform(xf);
          xf.concat(pos.place(orig_box, paper_box));
-         q = new xform_page(p, xf);
+         q = new xform_page(p, "fit", xf);
          q->width = paper.w;
          q->height = paper.h;
        }
@@ -869,7 +834,7 @@ public:
          // No paper given: adjust paper to fit image
          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 = new xform_page(p, "fit", xf);
          q->width = p->image_box.width() + marg.l + marg.r;
          q->height = p->image_box.height() + marg.t + marg.b;
        }
@@ -895,7 +860,7 @@ public:
     {
       pdf_matrix xf;
       xf.shift(marg.l, marg.b);
-      page *q = new xform_page(p, xf);
+      page *q = new xform_page(p, "expand", xf);
       q->width = p->width + marg.l + marg.r;
       q->height = p->height + marg.t + marg.b;
       if (q->width < 0.001 || q->height < 0.001)
@@ -918,7 +883,7 @@ public:
   margins_cmd(cmd *c) : marg(c, "size", "") { }
   page *process_page(page *p) override
     {
-      page *q = new xform_page(p, pdf_matrix());
+      page *q = new xform_page(p, "margins", pdf_matrix());
       q->image_box = BBox(marg.l, marg.t, p->width - marg.r, p->height - marg.b);
       if (q->image_box.width() < 0.001 || q->image_box.height() < 0.001)
        err("Margins must result in positive image dimensions");
@@ -1449,7 +1414,7 @@ class common_cmd : public cmd_exec {
       vector<page *> out;
       for (auto p: pages)
        {
-         page *q = new xform_page(p, pdf_matrix());
+         page *q = new xform_page(p, "common", pdf_matrix());
          q->width = pbox.width();
          q->height = pbox.height();
          q->image_box = ibox;
@@ -1502,7 +1467,7 @@ vector<page *> slice_cmd::process(vector<page *> &pages)
            pdf_matrix xf = placement;
            xf.shift(-c*pw, -(rows-1-r)*ph);
            xf.shift(margin.l, margin.t);
-           page *q = new xform_page(p, xf);
+           page *q = new xform_page(p, "slice", xf);
            q->width = paper.w;
            q->height = paper.h;
            BBox slice_box = BBox(margin.l, margin.t, paper.w - margin.r, paper.h - margin.b);
diff --git a/jam.h b/jam.h
index ae563337e7ca890a9af239951a694de64dd6404f..fa1e13b164eb98d865112b45a59de4d414584f41 100644 (file)
--- a/jam.h
+++ b/jam.h
@@ -175,3 +175,13 @@ void debug_pages(vector<page *> &pages);
 void process(list<cmd *> &cmds);
 vector<page *> run_command_list(list<cmd *> &cmds, vector<page *> &pages);
 vector<BBox> gs_bboxes(const char *in);
+
+class xform_page : public page {
+  page *orig_page;
+  pdf_matrix xform;
+  const char *description;
+public:
+  void render(out_context *out, pdf_matrix xform) override;
+  void debug_dump() override;
+  xform_page(page *p, const char *desc, pdf_matrix xf);
+};
diff --git a/pdf.cc b/pdf.cc
index ff7a8b03aa4578c9bf9a11ab658e48d136befccc..bcbfb5d00ff8cdbbeb39aeb21e827d1e7b27329a 100644 (file)
--- a/pdf.cc
+++ b/pdf.cc
@@ -282,3 +282,32 @@ static void do_recalc_bbox(vector<page *> &pages, const char *in_name)
   for (size_t i=0; i<pages.size(); i++)
     pages[i]->image_box = bboxes[i];
 }
+
+// Transformed page
+
+xform_page::xform_page(page *p, const char *desc, pdf_matrix xf)
+{
+  orig_page = p;
+  index = p->index;
+  description = desc;
+  xform = xf;
+
+  BBox media(p->width, p->height);
+  media.transform(xf);
+  width = media.width();
+  height = media.height();
+
+  image_box = p->image_box;
+  image_box.transform(xf);
+}
+
+void xform_page::debug_dump()
+{
+  debug("Transform (%s): [%s]", description, xform.to_string().c_str());
+  orig_page->debug_dump();
+}
+
+void xform_page::render(out_context *out, pdf_matrix parent_xform)
+{
+  orig_page->render(out, xform * parent_xform);
+}