class draw_bbox_page : public page {
page *orig_page;
public:
- void render(out_context *out, pdf_matrix xform);
+ void render(out_context *out, pdf_matrix xform) override;
draw_bbox_page(page *p) : page(p) { orig_page = p; }
};
return out;
}
+/*** merge ***/
+
+class merge_cmd : public cmd_exec {
+public:
+ merge_cmd(cmd *c UNUSED) { }
+ vector<page *> process(vector<page *> &pages);
+};
+
+class merge_page : public page {
+ vector<page *> orig_pages;
+public:
+ merge_page(vector<page *> &orig) : page(0, 0)
+ {
+ orig_pages = orig;
+ bool first = true;
+ for (auto p: orig)
+ {
+ if (first)
+ {
+ width = p->width;
+ height = p->height;
+ bbox = p->bbox;
+ first = false;
+ }
+ else
+ {
+ if (abs(width-p->width) > 0.001 || abs(height-p->height) > 0.001)
+ die("All pages participating in a merge must have the same dimensions");
+ bbox.join(p->bbox);
+ }
+ }
+ }
+ void render(out_context *out, pdf_matrix xform) override
+ {
+ for (auto p: orig_pages)
+ p->render(out, xform);
+ }
+};
+
+vector<page *> merge_cmd::process(vector<page *> &pages)
+{
+ vector<page *> out;
+ if (pages.size())
+ out.push_back(new merge_page(pages));
+ return out;
+}
+
/*** Command table ***/
template<typename T> cmd_exec *ctor(cmd *c) { return new T(c); }
{ "apply", no_args, 1, &ctor<apply_cmd> },
{ "modulo", modulo_args, 1, &ctor<modulo_cmd> },
{ "draw_bbox",no_args, 0, &ctor<draw_bbox_cmd> },
+ { "merge", no_args, 0, &ctor<merge_cmd> },
{ NULL, NULL, 0, NULL }
};
double height;
BBox bbox; // Bounds useful contents
virtual void render(out_context *out UNUSED, pdf_matrix xform UNUSED) { abort(); }
- page(double _w=0, double _h=0) : width(_w), height(_h) { }
- page(page *p) {
- index = p->index;
- width = p->width;
- height = p->height;
- bbox = p->bbox;
- }
+ page(double _w=0, double _h=0) : index(0), width(_w), height(_h), bbox() { }
+ page(page *p)
+ {
+ index = p->index;
+ width = p->width;
+ height = p->height;
+ bbox = p->bbox;
+ }
};
struct empty_page : public page {
{ "debug", 0, 0, 'd' },
{ "help", 0, 0, OPT_HELP },
{ "version", 0, 0, OPT_VERSION },
+ { "bbox", 0, 0, 'b' },
{ 0, 0, 0, 0 }
};
swap(y_min, y_max);
}
+void BBox::join(BBox &with)
+{
+ x_min = min(x_min, with.x_min);
+ x_max = max(x_max, with.x_max);
+ y_min = min(y_min, with.y_min);
+ y_max = max(y_max, with.y_max);
+}
+
/*** Unicode strings ***/
// Construct PDF representation of a UTF-8 string