mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Move outline creation into its own file
This commit is contained in:
parent
247aa959e4
commit
1c22993e00
@ -117,7 +117,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "podofo",
|
"name": "podofo",
|
||||||
"sources": "calibre/utils/podofo/utils.cpp calibre/utils/podofo/output.cpp calibre/utils/podofo/doc.cpp calibre/utils/podofo/outline.cpp calibre/utils/podofo/fonts.cpp calibre/utils/podofo/impose.cpp calibre/utils/podofo/images.cpp calibre/utils/podofo/podofo.cpp",
|
"sources": "calibre/utils/podofo/utils.cpp calibre/utils/podofo/output.cpp calibre/utils/podofo/doc.cpp calibre/utils/podofo/outline.cpp calibre/utils/podofo/fonts.cpp calibre/utils/podofo/impose.cpp calibre/utils/podofo/images.cpp calibre/utils/podofo/outlines.cpp calibre/utils/podofo/podofo.cpp",
|
||||||
"headers": "calibre/utils/podofo/global.h",
|
"headers": "calibre/utils/podofo/global.h",
|
||||||
"libraries": "podofo",
|
"libraries": "podofo",
|
||||||
"lib_dirs": "!podofo_lib",
|
"lib_dirs": "!podofo_lib",
|
||||||
|
@ -286,52 +286,6 @@ PDFDoc_set_box(PDFDoc *self, PyObject *args) {
|
|||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
} // }}}
|
} // }}}
|
||||||
|
|
||||||
// create_outline() {{{
|
|
||||||
static PyObject *
|
|
||||||
PDFDoc_create_outline(PDFDoc *self, PyObject *args) {
|
|
||||||
PDFOutlineItem *ans;
|
|
||||||
PyObject *title_buf;
|
|
||||||
unsigned int pagenum;
|
|
||||||
double left = 0, top = 0, zoom = 0;
|
|
||||||
PdfPage *page;
|
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "UI|ddd", &title_buf, &pagenum, &left, &top, &zoom)) return NULL;
|
|
||||||
|
|
||||||
ans = PyObject_New(PDFOutlineItem, &PDFOutlineItemType);
|
|
||||||
if (ans == NULL) goto error;
|
|
||||||
|
|
||||||
try {
|
|
||||||
PdfString title = podofo_convert_pystring(title_buf);
|
|
||||||
PdfOutlines *outlines = self->doc->GetOutlines();
|
|
||||||
if (outlines == NULL) {PyErr_NoMemory(); goto error;}
|
|
||||||
ans->item = outlines->CreateRoot(title);
|
|
||||||
if (ans->item == NULL) {PyErr_NoMemory(); goto error;}
|
|
||||||
ans->doc = self->doc;
|
|
||||||
try {
|
|
||||||
page = self->doc->GetPage(pagenum - 1);
|
|
||||||
} catch (const PdfError &err) {
|
|
||||||
(void)err;
|
|
||||||
PyErr_Format(PyExc_ValueError, "Invalid page number: %u", pagenum - 1); goto error;
|
|
||||||
}
|
|
||||||
PdfDestination dest(page, left, top, zoom);
|
|
||||||
ans->item->SetDestination(dest);
|
|
||||||
} catch(const PdfError & err) {
|
|
||||||
podofo_set_exception(err); goto error;
|
|
||||||
} catch(const std::exception & err) {
|
|
||||||
PyErr_Format(PyExc_ValueError, "An error occurred while trying to create the outline: %s", err.what());
|
|
||||||
goto error;
|
|
||||||
} catch (...) {
|
|
||||||
PyErr_SetString(PyExc_ValueError, "An unknown error occurred while trying to create the outline");
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (PyObject*)ans;
|
|
||||||
error:
|
|
||||||
Py_XDECREF(ans);
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
} // }}}
|
|
||||||
|
|
||||||
// get_xmp_metadata() {{{
|
// get_xmp_metadata() {{{
|
||||||
static PyObject *
|
static PyObject *
|
||||||
PDFDoc_get_xmp_metadata(PDFDoc *self, PyObject *args) {
|
PDFDoc_get_xmp_metadata(PDFDoc *self, PyObject *args) {
|
||||||
@ -795,7 +749,7 @@ static PyMethodDef PDFDoc_methods[] = {
|
|||||||
{"set_box", (PyCFunction)PDFDoc_set_box, METH_VARARGS,
|
{"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."
|
"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."
|
||||||
},
|
},
|
||||||
{"create_outline", (PyCFunction)PDFDoc_create_outline, METH_VARARGS,
|
{"create_outline", (PyCFunction)py_create_outline, METH_VARARGS,
|
||||||
"create_outline(title, pagenum) -> Create an outline, return the first outline item."
|
"create_outline(title, pagenum) -> Create an outline, return the first outline item."
|
||||||
},
|
},
|
||||||
{"get_xmp_metadata", (PyCFunction)PDFDoc_get_xmp_metadata, METH_VARARGS,
|
{"get_xmp_metadata", (PyCFunction)PDFDoc_get_xmp_metadata, METH_VARARGS,
|
||||||
|
@ -102,6 +102,7 @@ PyObject* py_merge_fonts(PDFDoc *self, PyObject *args);
|
|||||||
PyObject* py_dedup_type3_fonts(PDFDoc *self, PyObject *args);
|
PyObject* py_dedup_type3_fonts(PDFDoc *self, PyObject *args);
|
||||||
PyObject* py_impose(PDFDoc *self, PyObject *args);
|
PyObject* py_impose(PDFDoc *self, PyObject *args);
|
||||||
PyObject* py_dedup_images(PDFDoc *self, PyObject *args);
|
PyObject* py_dedup_images(PDFDoc *self, PyObject *args);
|
||||||
|
PyObject* py_create_outline(PDFDoc *self, PyObject *args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
58
src/calibre/utils/podofo/outlines.cpp
Normal file
58
src/calibre/utils/podofo/outlines.cpp
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* outlines.cpp
|
||||||
|
* Copyright (C) 2019 Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
*
|
||||||
|
* Distributed under terms of the GPL3 license.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "global.h"
|
||||||
|
using namespace pdf;
|
||||||
|
|
||||||
|
|
||||||
|
// create_outline() {{{
|
||||||
|
static PyObject *
|
||||||
|
create_outline(PDFDoc *self, PyObject *args) {
|
||||||
|
PDFOutlineItem *ans;
|
||||||
|
PyObject *title_buf;
|
||||||
|
unsigned int pagenum;
|
||||||
|
double left = 0, top = 0, zoom = 0;
|
||||||
|
PdfPage *page;
|
||||||
|
|
||||||
|
if (!PyArg_ParseTuple(args, "UI|ddd", &title_buf, &pagenum, &left, &top, &zoom)) return NULL;
|
||||||
|
|
||||||
|
ans = PyObject_New(PDFOutlineItem, &PDFOutlineItemType);
|
||||||
|
if (ans == NULL) goto error;
|
||||||
|
|
||||||
|
try {
|
||||||
|
PdfString title = podofo_convert_pystring(title_buf);
|
||||||
|
PdfOutlines *outlines = self->doc->GetOutlines();
|
||||||
|
if (outlines == NULL) {PyErr_NoMemory(); goto error;}
|
||||||
|
ans->item = outlines->CreateRoot(title);
|
||||||
|
if (ans->item == NULL) {PyErr_NoMemory(); goto error;}
|
||||||
|
ans->doc = self->doc;
|
||||||
|
try {
|
||||||
|
page = self->doc->GetPage(pagenum - 1);
|
||||||
|
} catch (const PdfError &err) {
|
||||||
|
(void)err;
|
||||||
|
PyErr_Format(PyExc_ValueError, "Invalid page number: %u", pagenum - 1); goto error;
|
||||||
|
}
|
||||||
|
PdfDestination dest(page, left, top, zoom);
|
||||||
|
ans->item->SetDestination(dest);
|
||||||
|
} catch(const PdfError & err) {
|
||||||
|
podofo_set_exception(err); goto error;
|
||||||
|
} catch(const std::exception & err) {
|
||||||
|
PyErr_Format(PyExc_ValueError, "An error occurred while trying to create the outline: %s", err.what());
|
||||||
|
goto error;
|
||||||
|
} catch (...) {
|
||||||
|
PyErr_SetString(PyExc_ValueError, "An unknown error occurred while trying to create the outline");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (PyObject*)ans;
|
||||||
|
error:
|
||||||
|
Py_XDECREF(ans);
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
} // }}}
|
||||||
|
|
||||||
|
PYWRAP(create_outline)
|
Loading…
x
Reference in New Issue
Block a user