diff options
author | Robin Watts <robin.watts@artifex.com> | 2014-01-03 16:50:41 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2014-01-07 10:25:42 +0000 |
commit | 7f009acebb75ff88c1ee934b03fa2d15f7785b32 (patch) | |
tree | 7be547523d730d104c62e4b5d43685dd8bb5bd40 /source/pdf | |
parent | 016adfa063293281a0896c62bf22e406b09ddf21 (diff) | |
download | mupdf-7f009acebb75ff88c1ee934b03fa2d15f7785b32.tar.xz |
Introduce 'document handlers'.
We define a document handler for each file type (2 in the case of PDF, one
to handle files with the ability to 'run' them, and one without).
We then register these handlers with the context at startup, and then
call fz_open_document... as usual. This enables people to select the
document types they want at will (and even to extend the library with more
document types should they wish).
Diffstat (limited to 'source/pdf')
-rw-r--r-- | source/pdf/pdf-xref-aux.c | 7 | ||||
-rw-r--r-- | source/pdf/pdf-xref.c | 24 |
2 files changed, 31 insertions, 0 deletions
diff --git a/source/pdf/pdf-xref-aux.c b/source/pdf/pdf-xref-aux.c index 968a8f9f..aac323de 100644 --- a/source/pdf/pdf-xref-aux.c +++ b/source/pdf/pdf-xref-aux.c @@ -27,3 +27,10 @@ pdf_open_document(fz_context *ctx, const char *filename) doc->update_appearance = pdf_update_appearance; return doc; } + +fz_document_handler pdf_document_handler = +{ + (fz_document_recognize_fn *)&pdf_recognize, + (fz_document_open_fn *)&pdf_open_document, + (fz_document_open_with_stream_fn *)&pdf_open_document_with_stream +}; diff --git a/source/pdf/pdf-xref.c b/source/pdf/pdf-xref.c index d7c5cd1b..2afe4de8 100644 --- a/source/pdf/pdf-xref.c +++ b/source/pdf/pdf-xref.c @@ -1,4 +1,5 @@ #include "mupdf/pdf.h" +#include "mupdf/fitz/document.h" #undef DEBUG_PROGESSIVE_ADVANCE @@ -2417,3 +2418,26 @@ pdf_document *pdf_create_document(fz_context *ctx) } return doc; } + +int +pdf_recognize(fz_context *doc, const char *magic) +{ + char *ext = strrchr(magic, '.'); + + if (ext) + { + if (!fz_strcasecmp(ext, ".pdf")) + return 100; + } + if (!strcmp(magic, "pdf") || !strcmp(magic, "application/pdf")) + return 100; + + return 1; +} + +fz_document_handler pdf_no_run_document_handler = +{ + (fz_document_recognize_fn *)&pdf_recognize, + (fz_document_open_fn *)&pdf_open_document_no_run, + (fz_document_open_with_stream_fn *)&pdf_open_document_no_run_with_stream +}; |