out->egstates.replaceKey(egs_res, egstate);
s += egs_res + " gs ";
- BBox b = box;
- b.x_min -= offset;
- b.x_max += offset;
- b.y_min -= offset;
- b.y_max += offset;
+ BBox b = box.enlarged(offset);
switch (type)
{
{
return new cropmarks_page(p, &cm);
}
-
public:
cropmarks_cmd(cmd *c) : cm(c) { }
};
{ NULL, 0 }
};
+/*** clip ***/
+
+class clip_page : public page {
+ page *orig_page;
+ BBox clip_to;
+public:
+ void render(out_context *out, pdf_matrix xform) override
+ {
+ out->contents += "q " + clip_to.transformed(xform).to_rect() + " re W n ";
+ orig_page->render(out, xform);
+ out->contents += "Q ";
+ }
+ clip_page(page *p, BBox &to) : page(p), orig_page(p), clip_to(to) { }
+};
+
+class clip_cmd : public cmd_exec_simple {
+ double bleed;
+ page *process_page(page *p) override
+ {
+ BBox to = p->image_box.enlarged(bleed);
+ return new clip_page(p, to);
+ }
+public:
+ clip_cmd(cmd *c)
+ {
+ bleed = c->arg("bleed")->as_double(0);
+ }
+};
+
+static const arg_def clip_args[] = {
+ { "bleed", AT_DIMEN },
+ { NULL, 0 }
+};
+
/*** Command table ***/
template<typename T> cmd_exec *ctor(cmd *c) { return new T(c); }
{ "book", book_args, 0, &ctor<book_cmd> },
{ "nup", nup_args, 0, &ctor<nup_cmd> },
{ "cropmarks",cropmarks_args, 0, &ctor<cropmarks_cmd> },
+ { "clip", clip_args, 0, &ctor<clip_cmd> },
{ NULL, NULL, 0, NULL }
};