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 }
};
y_max = max(y_max, with.y_max);
}
+void BBox::enlarge(double by)
+{
+ x_min -= by;
+ x_max += by;
+ y_min -= by;
+ y_max += by;
+}
+
+BBox BBox::enlarged(double by)
+{
+ BBox b = *this;
+ b.enlarge(by);
+ return b;
+}
+
/*** Unicode strings ***/
// Construct PDF representation of a UTF-8 string
double height() { return y_max - y_min; }
void transform(pdf_matrix &m);
BBox transformed(pdf_matrix &m);
+ void enlarge(double by);
+ BBox enlarged(double by);
void join(BBox &with);
private:
bool parse(QPDFObjectHandle h);