From 7f009acebb75ff88c1ee934b03fa2d15f7785b32 Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Fri, 3 Jan 2014 16:50:41 +0000 Subject: 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). --- source/pdf/pdf-xref-aux.c | 7 +++++++ source/pdf/pdf-xref.c | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+) (limited to 'source/pdf') 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 +}; -- cgit v1.2.3