From 3a9cf20b438e9ffd4be63d24d165cca840738c50 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 6 Apr 2018 23:03:37 +0200 Subject: [PATCH] "draw-bbox" replaced by "debug" --- cmds.cc | 67 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 23 deletions(-) diff --git a/cmds.cc b/cmds.cc index b6c8eed..802e193 100644 --- a/cmds.cc +++ b/cmds.cc @@ -230,8 +230,12 @@ public: // Colors class color_spec { - double rgb[3]; public: + double rgb[3]; + color_spec() + { + rgb[0] = rgb[1] = rgb[2] = 0; + } color_spec(string s) { if (s.length() != 6) @@ -261,6 +265,7 @@ public: // Cropmarks class cropmark_spec { +public: enum mark_type { MARK_NONE, MARK_BOX, @@ -272,10 +277,15 @@ class cropmark_spec { double pen_width; double arm_length; double offset; - string crop_cross(double x, double y, uint mask); - QPDFObjectHandle egstate; color_spec color; -public: + cropmark_spec() + { + type = MARK_NONE; + pen_width = 0.2; + arm_length = 5*mm; + offset = 0; + egstate = QPDFObjectHandle::newNull(); + } cropmark_spec(cmd *c, const string prefix="", const string def_type="cross") : color(c->arg(prefix + "color")->as_string("000000")) { string t = c->arg(prefix + "mark")->as_string(def_type); @@ -301,6 +311,9 @@ public: } bool is_bg() { return (type == MARK_BG); } string pdf_stream(out_context *out, BBox &box, pdf_matrix &xform); +private: + string crop_cross(double x, double y, uint mask); + QPDFObjectHandle egstate; }; string cropmark_spec::crop_cross(double x, double y, uint mask) @@ -695,35 +708,43 @@ static const arg_def modulo_args[] = { { NULL, 0 } }; -/*** draw-bbox ***/ +/*** debug ***/ -class draw_bbox_page : public page { +class debug_page : public page { page *orig_page; + cropmark_spec *page_cm, *image_cm; public: - void render(out_context *out, pdf_matrix xform) override; - draw_bbox_page(page *p) : page(p) { orig_page = p; } + debug_page(page *p, cropmark_spec *page_cms, cropmark_spec *image_cms) : page(p), orig_page(p), page_cm(page_cms), image_cm(image_cms) { } + void render(out_context *out, pdf_matrix xform) override + { + orig_page->render(out, xform); + BBox page_bbox = BBox(0, 0, width, height); + out->contents += page_cm->pdf_stream(out, page_bbox, xform); + out->contents += image_cm->pdf_stream(out, image_box, xform); + } }; -class draw_bbox_cmd : public cmd_exec_simple { +class debug_cmd : public cmd_exec_simple { + cropmark_spec page_cmarks; + cropmark_spec image_cmarks; public: - draw_bbox_cmd(cmd *c UNUSED) { } + debug_cmd(cmd *c UNUSED) + { + page_cmarks.type = cropmark_spec::MARK_BOX; + page_cmarks.color.rgb[0] = 1; + page_cmarks.color.rgb[1] = 0; + page_cmarks.color.rgb[2] = 0; + image_cmarks.type = cropmark_spec::MARK_BOX; + image_cmarks.color.rgb[0] = 0; + image_cmarks.color.rgb[1] = 1; + image_cmarks.color.rgb[2] = 0; + } page *process_page(page *p) override { - return new draw_bbox_page(p); + return new debug_page(p, &page_cmarks, &image_cmarks); } }; -void draw_bbox_page::render(out_context *out, pdf_matrix xform) -{ - orig_page->render(out, xform); - out->contents += - "q " + - xform.to_string() + " cm " + - "0 1 0 RG " + - image_box.to_rect() + " re S " + - "Q "; -} - /*** merge ***/ class merge_cmd : public cmd_exec { @@ -1375,7 +1396,7 @@ const cmd_def cmd_table[] = { { "select", no_args, 1, &ctor }, { "apply", no_args, 1, &ctor }, { "modulo", modulo_args, 1, &ctor }, - { "draw-bbox",no_args, 0, &ctor }, + { "debug", no_args, 0, &ctor }, { "merge", no_args, 0, &ctor }, { "paper", paper_args, 0, &ctor }, { "scaleto", scaleto_args, 0, &ctor }, -- 2.39.2