]> mj.ucw.cz Git - paperjam.git/commitdiff
Added debugging dump of page operations
authorMartin Mares <mj@ucw.cz>
Fri, 1 Jun 2018 22:54:58 +0000 (00:54 +0200)
committerMartin Mares <mj@ucw.cz>
Fri, 1 Jun 2018 22:54:58 +0000 (00:54 +0200)
cmds.cc
jam.h
pdf.cc

diff --git a/cmds.cc b/cmds.cc
index f16cd991138ec45ee042331bf12bd50303e11cd1..97c24d58ab1d92bfa788c9563b0af1b909447d02 100644 (file)
--- a/cmds.cc
+++ b/cmds.cc
@@ -32,6 +32,11 @@ class xform_page : public 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);
 };
 
@@ -718,6 +723,11 @@ public:
       out->contents += page_cm->pdf_stream(out, page_bbox, xform);
       out->contents += image_cm->pdf_stream(out, image_box, xform);
     }
+  void debug_dump() override
+    {
+      debug("Draw debugging boxes");
+      orig_page->debug_dump();
+    }
 };
 
 class debug_cmd : public cmd_exec_simple {
@@ -778,6 +788,14 @@ public:
       for (auto p: orig_pages)
        p->render(out, xform);
     }
+  void debug_dump() override
+    {
+      debug("Merge pages");
+      debug_indent += 4;
+      for (auto p: orig_pages)
+       p->debug_dump();
+      debug_indent -= 4;
+    }
 };
 
 vector<page *> merge_cmd::process(vector<page *> &pages)
@@ -1263,6 +1281,14 @@ public:
   cropmark_spec *cmarks;
   void render(out_context *out, pdf_matrix xform) override;
   nup_page(nup_state &st) : page(st.paper_w, st.paper_h) { }
+  void debug_dump() override
+    {
+      debug("N-up printing");
+      debug_indent += 4;
+      for (auto p: orig_pages)
+       p->debug_dump();
+      debug_indent -= 4;
+    }
 };
 
 void nup_page::render(out_context *out, pdf_matrix parent_xform)
@@ -1360,6 +1386,11 @@ public:
       orig_page->render(out, xform);
       out->contents += cm->pdf_stream(out, image_box, xform);
     }
+  void debug_dump() override
+    {
+      debug("Add cropmarks");
+      orig_page->debug_dump();
+    }
   cropmarks_page(page *p, cropmark_spec *cms) : page(p), orig_page(p), cm(cms) { }
 };
 
@@ -1390,6 +1421,11 @@ public:
       orig_page->render(out, xform);
       out->contents += "Q ";
     }
+  void debug_dump() override
+    {
+      debug("Clip [%.3f %.3f %.3f %.3f]", clip_to.x_min, clip_to.y_min, clip_to.x_max, clip_to.y_max);
+      orig_page->debug_dump();
+    }
   clip_page(page *p, BBox &to) : page(p), orig_page(p), clip_to(to) { }
 };
 
diff --git a/jam.h b/jam.h
index 5ee7620d050cd28163062943431bc127b3bda4ad..ae563337e7ca890a9af239951a694de64dd6404f 100644 (file)
--- a/jam.h
+++ b/jam.h
@@ -27,6 +27,13 @@ static inline bool is_equal(double x, double y)
   return is_zero(x-y);
 }
 
+void debug(const char *msg, ...) FORMAT_CHECK(printf, 1, 2);
+void warn(const char *msg, ...) FORMAT_CHECK(printf, 1, 2);
+void die(const char *msg, ...) FORMAT_CHECK(printf, 1, 2) NONRET;
+
+// This one is called during execution of commands and propagated as an exception
+void err(const char *msg, ...) FORMAT_CHECK(printf, 1, 2) NONRET;
+
 #include "pdf-tools.h"
 
 /*** Representation of commands ***/
@@ -79,6 +86,7 @@ struct page {
   double height;
   BBox image_box;      // Bounds useful contents
   virtual void render(out_context *out UNUSED, pdf_matrix xform UNUSED) { abort(); }
+  virtual void debug_dump() = 0;
   page(double _w=0, double _h=0) : index(0), width(_w), height(_h), image_box() { }
   page(page *p)
     {
@@ -91,6 +99,7 @@ struct page {
 
 struct empty_page : public page {
   void render(out_context *out UNUSED, pdf_matrix xform UNUSED) { }
+  void debug_dump() { debug("Empty page"); }
   empty_page(double _w=0, double _h=0) : page(_w, _h) { };
 };
 
@@ -144,13 +153,6 @@ extern bool recalc_bbox;
 extern int debug_level;
 extern int debug_indent;
 
-void debug(const char *msg, ...) FORMAT_CHECK(printf, 1, 2);
-void warn(const char *msg, ...) FORMAT_CHECK(printf, 1, 2);
-void die(const char *msg, ...) FORMAT_CHECK(printf, 1, 2) NONRET;
-
-// This one is called during execution of commands and propagated as an exception
-void err(const char *msg, ...) FORMAT_CHECK(printf, 1, 2) NONRET;
-
 class paperjam_error : public exception {
   string message;
 public:
diff --git a/pdf.cc b/pdf.cc
index 8f46d1674c5ecf112583f9955026058c2a008015..15e6e5da6c820db0d22e0539147f7b3a2889331a 100644 (file)
--- a/pdf.cc
+++ b/pdf.cc
@@ -30,6 +30,7 @@ class in_page : public page {
 public:
   BBox media_box;
   void render(out_context *out, pdf_matrix xform);
+  void debug_dump() { debug("Input page %d", index); }
   in_page(QPDFObjectHandle inpg, int idx);
 };
 
@@ -79,10 +80,19 @@ void debug_pages(vector<page *> &pages)
     return;
 
   for (auto pg: pages)
-    debug("Page #%d: media[%.3f %.3f] image[%.3f %.3f %.3f %.3f]",
-      pg->index,
-      pg->width, pg->height,
-      pg->image_box.x_min, pg->image_box.y_min, pg->image_box.x_max, pg->image_box.y_max);
+    {
+      debug("Page #%d: media[%.3f %.3f] image[%.3f %.3f %.3f %.3f][%.3f %.3f]",
+       pg->index,
+       pg->width, pg->height,
+       pg->image_box.x_min, pg->image_box.y_min, pg->image_box.x_max, pg->image_box.y_max,
+       pg->image_box.width(), pg->image_box.height());
+      if (debug_level > 2)
+       {
+         debug_indent += 4;
+         pg->debug_dump();
+         debug_indent -= 4;
+       }
+    }
 }
 
 vector<page *> run_command_list(list<cmd *> &cmds, vector<page *> &pages)
@@ -158,8 +168,18 @@ void process(list<cmd *> &cmds)
   pages = run_command_list(cmds, pages);
 
   debug("### Writing output");
+  int out_page = 0;
   for (auto pg: pages)
     {
+      ++out_page;
+      if (debug_level > 1)
+       {
+         debug("Page #%d", out_page);
+         debug_indent += 4;
+         pg->debug_dump();
+         debug_indent -= 4;
+       }
+
       out_context out;
       out.pdf = &out_pdf;
       out.resources = QPDFObjectHandle::newDictionary();