summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2016-07-05 16:28:04 +0200
committerTor Andersson <tor.andersson@artifex.com>2016-07-06 15:49:55 +0200
commitc3944e2e1cfb4ac86a8580829376357e1d5bccda (patch)
tree974a632f212a9af950146a211825c5e8b361cef3
parent467af4f7b516b97ca082be794c8c462e4dea41ad (diff)
downloadmupdf-c3944e2e1cfb4ac86a8580829376357e1d5bccda.tar.xz
Add fitz to pdf downcasting functions for pages and annotations.
-rw-r--r--docs/mutool/run.html4
-rw-r--r--include/mupdf/pdf/document.h13
-rw-r--r--source/pdf/pdf-xref.c17
3 files changed, 32 insertions, 2 deletions
diff --git a/docs/mutool/run.html b/docs/mutool/run.html
index 19433681..c6bc80e5 100644
--- a/docs/mutool/run.html
+++ b/docs/mutool/run.html
@@ -197,6 +197,8 @@ If alpha is true, the page will be drawn on a transparent background, otherwise
<dd>Search for 'needle' text on the page, and return an array with rectangles of all matches found.
<dt>Page#getAnnotations()
<dd>Return array of all annotations on the page.
+<dt>Page#toPDF()
+<dd>Returns the PDFObject/PDFPage for the page, if the document is a PDF file.
</dl>
<dl>
@@ -208,6 +210,8 @@ If alpha is true, the page will be drawn on a transparent background, otherwise
<dd>Render the annotation into a Pixmap, using the transform and colorspace.
<dt>Annotation#toDisplayList()
<dd>Record the contents of the annotation into a DisplayList.
+<dt>Annotation#toPDF()
+<dd>Returns the PDFObject/PDFAnnotation for the annotation, if the document is a PDF file.
</dl>
<h2>
diff --git a/include/mupdf/pdf/document.h b/include/mupdf/pdf/document.h
index 0bec12b0..8a8fdd40 100644
--- a/include/mupdf/pdf/document.h
+++ b/include/mupdf/pdf/document.h
@@ -96,11 +96,22 @@ pdf_document *pdf_open_document_with_stream(fz_context *ctx, fz_stream *file);
void pdf_drop_document(fz_context *ctx, pdf_document *doc);
/*
- pdf_specific: down-cast an fz_document to a pdf_document.
+ pdf_specifics: down-cast an fz_document to a pdf_document.
Returns NULL if underlying document is not PDF
*/
pdf_document *pdf_specifics(fz_context *ctx, fz_document *doc);
+/*
+ pdf_document_from_fz_document,
+ pdf_page_from_fz_page,
+ pdf_annot_from_fz_annot:
+ Down-cast generic fitz objects into pdf specific variants.
+ Returns NULL if the objects are not from a PDF document.
+*/
+pdf_document *pdf_document_from_fz_document(fz_context *ctx, fz_document *ptr);
+pdf_page *pdf_page_from_fz_page(fz_context *ctx, fz_page *ptr);
+pdf_annot *pdf_annot_from_fz_annot(fz_context *ctx, fz_annot *ptr);
+
int pdf_needs_password(fz_context *ctx, pdf_document *doc);
int pdf_authenticate_password(fz_context *ctx, pdf_document *doc, const char *pw);
diff --git a/source/pdf/pdf-xref.c b/source/pdf/pdf-xref.c
index 19b1f4f7..82fe7db1 100644
--- a/source/pdf/pdf-xref.c
+++ b/source/pdf/pdf-xref.c
@@ -2698,9 +2698,24 @@ pdf_obj *pdf_progressive_advance(fz_context *ctx, pdf_document *doc, int pagenum
return doc->linear_page_refs[pagenum];
}
+pdf_document *pdf_document_from_fz_document(fz_context *ctx, fz_document *ptr)
+{
+ return (pdf_document *)((ptr && ptr->count_pages == (void*)pdf_count_pages) ? ptr : NULL);
+}
+
+pdf_page *pdf_page_from_fz_page(fz_context *ctx, fz_page *ptr)
+{
+ return (pdf_page *)((ptr && ptr->bound_page == (void*)pdf_bound_page) ? ptr : NULL);
+}
+
+pdf_annot *pdf_annot_from_fz_annot(fz_context *ctx, fz_annot *ptr)
+{
+ return (pdf_annot *)((ptr && ptr->bound_annot == (void*)pdf_bound_annot) ? ptr : NULL);
+}
+
pdf_document *pdf_specifics(fz_context *ctx, fz_document *doc)
{
- return (pdf_document *)((doc && doc->close == (fz_document_close_fn *)pdf_close_document) ? doc : NULL);
+ return pdf_document_from_fz_document(ctx, doc);
}
pdf_obj *