From 0a22c291b745cad59f915f65eb583671d9857ba1 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 27 Aug 2012 17:17:33 +0530 Subject: [PATCH] ... --- src/calibre/utils/podofo/doc.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/calibre/utils/podofo/doc.cpp b/src/calibre/utils/podofo/doc.cpp index 8e59efdeaf..26951fcdce 100644 --- a/src/calibre/utils/podofo/doc.cpp +++ b/src/calibre/utils/podofo/doc.cpp @@ -170,6 +170,30 @@ PDFDoc_append(PDFDoc *self, PyObject *args) { Py_RETURN_NONE; } // }}} +// set_box() {{{ +static PyObject * +PDFDoc_set_box(PDFDoc *self, PyObject *args) { + int num = 0; + double left, bottom, width, height; + char *box; + if (!PyArg_ParseTuple(args, "isdddd", &num, &box, &left, &bottom, &width, &height)) return NULL; + + try { + PdfRect r(left, bottom, width, height); + PdfObject o; + r.ToVariant(o); + self->doc->GetPage(num)->GetObject()->GetDictionary().AddKey(PdfName(box), o); + } catch(const PdfError & err) { + podofo_set_exception(err); + return NULL; + } catch (...) { + PyErr_SetString(PyExc_ValueError, "An unknown error occurred while trying to set the box"); + return NULL; + } + + Py_RETURN_NONE; +} // }}} + // Properties {{{ static PyObject * @@ -403,6 +427,9 @@ static PyMethodDef PDFDoc_methods[] = { {"append", (PyCFunction)PDFDoc_append, METH_VARARGS, "append(doc) -> Append doc (which must be a PDFDoc) to this document." }, + {"set_box", (PyCFunction)PDFDoc_set_box, METH_VARARGS, + "set_box(page_num, box, left, bottom, width, height) -> Set the PDF bounding box for the page numbered nu, box must be one of: MediaBox, CropBox, TrimBox, BleedBox, ArtBox. The numbers are interpreted as pts." + }, {NULL} /* Sentinel */