return m;
}
+/*** draw_bbox ***/
+
+class draw_bbox_cmd : public cmd_exec {
+public:
+ vector<page *> process(vector<page *> &pages);
+};
+
+class draw_bbox_page : public page {
+ page *orig_page;
+public:
+ void render(out_context *out, pdf_matrix xform);
+ draw_bbox_page(page *p) : page(p) { orig_page = p; }
+};
+
+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 " +
+ bbox.to_rect() + " re S " +
+ "Q ";
+}
+
+vector<page *> draw_bbox_cmd::process(vector<page *> &pages)
+{
+ vector<page *> out;
+ for (auto p: pages)
+ out.push_back(new draw_bbox_page(p));
+ return out;
+}
+
+static cmd_exec *draw_bbox_ctor(cmd *c UNUSED)
+{
+ draw_bbox_cmd *m = new draw_bbox_cmd;
+ return m;
+}
+
/*** Command table ***/
const cmd_def cmd_table[] = {
{ "select", no_args, 1, select_ctor },
{ "apply", no_args, 1, apply_ctor },
{ "modulo", modulo_args, 1, modulo_ctor },
+ { "draw_bbox",no_args, 0, draw_bbox_ctor },
{ NULL, NULL, 0, NULL }
};
m.shift(-media_box.x_min, -media_box.y_min);
m.concat(xform);
- out->contents += "q " + m.to_string() + " cm " + xobj_res + " Do Q";
+ out->contents += "q " + m.to_string() + " cm " + xobj_res + " Do Q ";
}
static void debug_pages(vector<page *> &pages)
{
while (*in_pos >= 'A' && *in_pos <= 'Z' ||
*in_pos >= 'a' && *in_pos <= 'z' ||
- *in_pos >= '0' && *in_pos <= '9')
+ *in_pos >= '0' && *in_pos <= '9' ||
+ *in_pos == '_')
token += *in_pos++;
return TOK_IDENT;
}
return a;
}
+string BBox::to_rect()
+{
+ char buf[64];
+ snprintf(buf, sizeof(buf), "%.1f %.1f %.1f %.1f", x_min, y_min, width(), height());
+ return string(buf);
+}
+
bool BBox::parse(QPDFObjectHandle h)
{
if (!h.isArray() || h.getArrayNItems() != 4)