From 1efe18b438e8c59cef6a419baf788c4df622c1d1 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sat, 2 Jun 2018 00:54:58 +0200 Subject: [PATCH] Added debugging dump of page operations --- cmds.cc | 36 ++++++++++++++++++++++++++++++++++++ jam.h | 16 +++++++++------- pdf.cc | 28 ++++++++++++++++++++++++---- 3 files changed, 69 insertions(+), 11 deletions(-) diff --git a/cmds.cc b/cmds.cc index f16cd99..97c24d5 100644 --- 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 merge_cmd::process(vector &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 5ee7620..ae56333 100644 --- 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 8f46d16..15e6e5d 100644 --- 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 &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 run_command_list(list &cmds, vector &pages) @@ -158,8 +168,18 @@ void process(list &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(); -- 2.39.2