Use PdfDestination to create destinations

This commit is contained in:
Kovid Goyal 2019-07-11 19:38:04 +05:30
parent 27c200ea8d
commit 39dae008c2
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -434,7 +434,6 @@ dictionary_has_key_name(PdfDictionary &d, T key, const char *name) {
static PyObject * static PyObject *
PDFDoc_alter_links(PDFDoc *self, PyObject *args) { PDFDoc_alter_links(PDFDoc *self, PyObject *args) {
int count = 0; int count = 0;
static const PdfName XYZ("XYZ");
PyObject *alter_callback, *py_mark_links; PyObject *alter_callback, *py_mark_links;
if (!PyArg_ParseTuple(args, "OO", &alter_callback, &py_mark_links)) return NULL; if (!PyArg_ParseTuple(args, "OO", &alter_callback, &py_mark_links)) return NULL;
bool mark_links = PyObject_IsTrue(py_mark_links); bool mark_links = PyObject_IsTrue(py_mark_links);
@ -459,8 +458,8 @@ PDFDoc_alter_links(PDFDoc *self, PyObject *args) {
PyObject *ret = PyObject_CallObject(alter_callback, Py_BuildValue("(N)", PyUnicode_DecodeUTF8(uri.c_str(), uri.length(), "replace"))); PyObject *ret = PyObject_CallObject(alter_callback, Py_BuildValue("(N)", PyUnicode_DecodeUTF8(uri.c_str(), uri.length(), "replace")));
if (!ret) { return NULL; } if (!ret) { return NULL; }
if (PyTuple_Check(ret) && PyTuple_GET_SIZE(ret) == 4) { if (PyTuple_Check(ret) && PyTuple_GET_SIZE(ret) == 4) {
int pagenum; double left, top; long long zoom; int pagenum; double left, top, zoom;
if (PyArg_ParseTuple(ret, "iddL", &pagenum, &left, &top, &zoom)) { if (PyArg_ParseTuple(ret, "iddd", &pagenum, &left, &top, &zoom)) {
PdfPage *page = NULL; PdfPage *page = NULL;
try { try {
page = self->doc->GetPage(pagenum - 1); page = self->doc->GetPage(pagenum - 1);
@ -470,15 +469,9 @@ PDFDoc_alter_links(PDFDoc *self, PyObject *args) {
return NULL; return NULL;
} }
if (page) { if (page) {
const PdfReference &pageref = page->GetObject()->Reference(); PdfDestination dest(page, left, top, zoom);
PdfArray dest;
dest.push_back(pageref);
dest.push_back(XYZ);
dest.push_back(left);
dest.push_back(top);
dest.push_back((PoDoFo::pdf_int64)zoom);
link.RemoveKey("A"); link.RemoveKey("A");
link.AddKey("Dest", dest); dest.AddToDictionary(link);
} }
} }
} }