Update document handler recogniser/opener interface.
authorRobin Watts <[email protected]>
Thu, 11 Jul 2024 15:46:00 +0000 (16:46 +0100)
committerRobin Watts <[email protected]>
Tue, 23 Jul 2024 19:02:02 +0000 (20:02 +0100)
Allow the recogniser to pass back state that can be reused in
the opener.

12 files changed:
include/mupdf/fitz/document.h
source/cbz/mucbz.c
source/cbz/muimg.c
source/fitz/document.c
source/fitz/gz-doc.c
source/html/epub-doc.c
source/html/html-doc.c
source/html/office.c
source/html/txt.c
source/pdf/pdf-xref.c
source/svg/svg-doc.c
source/xps/xps-doc.c

index 24af6a3d530d0feecd85c4b0cbef988c4efa47b5..eca2a70905f6a68cccc123e3b080a6de41faba61 100644 (file)
@@ -341,9 +341,13 @@ typedef void (fz_page_delete_link_fn)(fz_context *ctx, fz_page *page, fz_link *l
        associated content from (like images for an html stream
        will be loaded from this). Maybe NULL. May be ignored.
 
+       recognize_state: NULL, or a state pointer passed back from the call
+       to recognise_content_fn. Ownership does not pass in. The
+       caller remains responsible for freeing state.
+
        Pointer to opened document. Throws exception in case of error.
 */
-typedef fz_document *(fz_document_open_fn)(fz_context *ctx, const fz_document_handler *handler, fz_stream *stream, fz_stream *accel, fz_archive *dir);
+typedef fz_document *(fz_document_open_fn)(fz_context *ctx, const fz_document_handler *handler, fz_stream *stream, fz_stream *accel, fz_archive *dir, void *recognize_state);
 
 /**
        Recognize a document type from
@@ -360,6 +364,8 @@ typedef fz_document *(fz_document_open_fn)(fz_context *ctx, const fz_document_ha
 */
 typedef int (fz_document_recognize_fn)(fz_context *ctx, const fz_document_handler *handler, const char *magic);
 
+typedef void (fz_document_recognize_state_free_fn)(fz_context *ctx, void *state);
+
 /**
        Recognize a document type from stream contents.
 
@@ -370,11 +376,20 @@ typedef int (fz_document_recognize_fn)(fz_context *ctx, const fz_document_handle
 
        dir: directory context from which stream is loaded.
 
+       recognize_state: pointer to retrieve opaque state that may be used
+       by the open routine, or NULL.
+
+       free_recognize_state: pointer to retrieve a function pointer to
+       free the opaque state, or NULL.
+
+       Note: state and free_state should either both be NULL or
+       both be non-NULL!
+
        Returns a number between 0 (not recognized) and 100
        (fully recognized) based on how certain the recognizer
        is that this is of the required type.
 */
-typedef int (fz_document_recognize_content_fn)(fz_context *ctx, const fz_document_handler *handler, fz_stream *stream, fz_archive *dir);
+typedef int (fz_document_recognize_content_fn)(fz_context *ctx, const fz_document_handler *handler, fz_stream *stream, fz_archive *dir, void **recognize_state, fz_document_recognize_state_free_fn **free_recognize_state);
 
 /**
        Finalise a document handler.
index bbd26924f21af7336aa7eeae837d38c0fe094143..8b3a977d72b24880bdaa5e1213b42032e12daa09 100644 (file)
@@ -276,7 +276,7 @@ cbz_lookup_metadata(fz_context *ctx, fz_document *doc_, const char *key, char *b
 }
 
 static fz_document *
-cbz_open_document(fz_context *ctx, const fz_document_handler *handler, fz_stream *file, fz_stream *accel, fz_archive *dir)
+cbz_open_document(fz_context *ctx, const fz_document_handler *handler, fz_stream *file, fz_stream *accel, fz_archive *dir, void *state)
 {
        cbz_document *doc = fz_new_derived_document(ctx, cbz_document);
 
@@ -330,7 +330,7 @@ static const char *cbz_mimetypes[] =
 };
 
 static int
-cbz_recognize_doc_content(fz_context *ctx, const fz_document_handler *handler, fz_stream *stream, fz_archive *dir)
+cbz_recognize_doc_content(fz_context *ctx, const fz_document_handler *handler, fz_stream *stream, fz_archive *dir, void **state, fz_document_recognize_state_free_fn **freestate)
 {
        fz_archive *arch = NULL;
        int ret = 0;
index 9745bfa54cb11829b8960281416a02bb58c673d6..30906103f26ceeb0afa2853bf19b6f4c8b984372 100644 (file)
@@ -172,7 +172,7 @@ img_lookup_metadata(fz_context *ctx, fz_document *doc_, const char *key, char *b
 }
 
 static fz_document *
-img_open_document(fz_context *ctx, const fz_document_handler *handler, fz_stream *file, fz_stream *accel, fz_archive *dir)
+img_open_document(fz_context *ctx, const fz_document_handler *handler, fz_stream *file, fz_stream *accel, fz_archive *dir, void *state)
 {
        img_document *doc = fz_new_derived_document(ctx, img_document);
 
@@ -234,7 +234,7 @@ img_open_document(fz_context *ctx, const fz_document_handler *handler, fz_stream
 }
 
 static int
-img_recognize_content(fz_context *ctx, const fz_document_handler *handler, fz_stream *stream, fz_archive *dir)
+img_recognize_content(fz_context *ctx, const fz_document_handler *handler, fz_stream *stream, fz_archive *dir, void **state, fz_document_recognize_state_free_fn **free_state)
 {
        unsigned char data[8];
        size_t n;
@@ -243,6 +243,11 @@ img_recognize_content(fz_context *ctx, const fz_document_handler *handler, fz_st
        if (stream == NULL)
                return 0;
 
+       if (state)
+               *state = NULL;
+       if (free_state)
+               *free_state = NULL;
+
        n = fz_read(ctx, stream, data, 8);
 
        if (n != 8)
index 95c78efbfb15d13246879a7657f8e890e8a83f57..da32b6e1ba098763b9727b7d3f6c6d84b1a2988b 100644 (file)
@@ -224,14 +224,21 @@ fz_recognize_document_stream_content(fz_context *ctx, fz_stream *stream, const c
 }
 
 const fz_document_handler *
-do_recognize_document_stream_and_dir_content(fz_context *ctx, fz_stream **streamp, fz_archive *dir, const char *magic)
+do_recognize_document_stream_and_dir_content(fz_context *ctx, fz_stream **streamp, fz_archive *dir, const char *magic, void **handler_state, fz_document_recognize_state_free_fn **handler_free_state)
 {
        fz_document_handler_context *dc;
        int i, best_score, best_i;
+       void *best_state = NULL;
+       fz_document_recognize_state_free_fn *best_free_state = NULL;
        const char *ext;
        int drop_stream = 0;
        fz_stream *stream = *streamp;
 
+       if (handler_state)
+               *handler_state = NULL;
+       if (handler_free_state)
+               *handler_free_state = NULL;
+
        dc = ctx->handler;
        if (dc->count == 0)
                fz_throw(ctx, FZ_ERROR_ARGUMENT, "No document handlers registered");
@@ -269,6 +276,8 @@ do_recognize_document_stream_and_dir_content(fz_context *ctx, fz_stream **stream
                {
                        for (i = 0; i < dc->count; i++)
                        {
+                               void *state = NULL;
+                               fz_document_recognize_state_free_fn *free_state = NULL;
                                int score = 0;
 
                                if (dc->handler[i]->recognize_content)
@@ -277,7 +286,7 @@ do_recognize_document_stream_and_dir_content(fz_context *ctx, fz_stream **stream
                                                fz_seek(ctx, stream, 0, SEEK_SET);
                                        fz_try(ctx)
                                        {
-                                               score = dc->handler[i]->recognize_content(ctx, dc->handler[i], stream, dir);
+                                               score = dc->handler[i]->recognize_content(ctx, dc->handler[i], stream, dir, &state, &free_state);
                                        }
                                        fz_catch(ctx)
                                        {
@@ -291,7 +300,13 @@ do_recognize_document_stream_and_dir_content(fz_context *ctx, fz_stream **stream
                                {
                                        best_score = score;
                                        best_i = i;
+                                       if (best_free_state)
+                                               best_free_state(ctx, best_state);
+                                       best_free_state = free_state;
+                                       best_state = state;
                                }
+                               else if (free_state)
+                                       free_state(ctx, state);
                        }
                        if (stream)
                                fz_seek(ctx, stream, 0, SEEK_SET);
@@ -334,6 +349,8 @@ do_recognize_document_stream_and_dir_content(fz_context *ctx, fz_stream **stream
        }
        fz_catch(ctx)
        {
+               if (best_free_state)
+                       best_free_state(ctx, best_state);
                if (drop_stream)
                        fz_drop_stream(ctx, stream);
                fz_rethrow(ctx);
@@ -349,6 +366,15 @@ do_recognize_document_stream_and_dir_content(fz_context *ctx, fz_stream **stream
        /* Only if we found a handler, do we make our modified stream available to the
         * caller. */
        *streamp = stream;
+
+       if (handler_state && handler_free_state)
+       {
+               *handler_state = best_state;
+               *handler_free_state = best_free_state;
+       }
+       else if (best_free_state)
+               best_free_state(ctx, best_state);
+
        return dc->handler[best_i];
 }
 
@@ -358,7 +384,7 @@ fz_recognize_document_stream_and_dir_content(fz_context *ctx, fz_stream *stream,
        fz_stream *stm = stream;
        const fz_document_handler *res;
 
-       res = do_recognize_document_stream_and_dir_content(ctx, &stm, dir, magic);
+       res = do_recognize_document_stream_and_dir_content(ctx, &stm, dir, magic, NULL, NULL);
 
        if (stm != stream)
                fz_drop_stream(ctx, stm);
@@ -366,21 +392,25 @@ fz_recognize_document_stream_and_dir_content(fz_context *ctx, fz_stream *stream,
        return res;
 }
 
-const fz_document_handler *fz_recognize_document_content(fz_context *ctx, const char *filename)
+static const fz_document_handler *do_recognize_document_content(fz_context *ctx, const char *filename, void **handler_state, fz_document_recognize_state_free_fn **handler_free_state)
 {
        fz_stream *stream = NULL;
        const fz_document_handler *handler = NULL;
        fz_archive *zip = NULL;
+       fz_stream *stm;
 
        if (fz_is_directory(ctx, filename))
                zip = fz_open_directory(ctx, filename);
        else
                stream  = fz_open_file(ctx, filename);
 
+       stm = stream;
        fz_try(ctx)
-               handler = fz_recognize_document_stream_and_dir_content(ctx, stream, zip, filename);
+               handler = do_recognize_document_stream_and_dir_content(ctx, &stm, zip, filename, handler_state, handler_free_state);
        fz_always(ctx)
        {
+               if (stm != stream)
+                       fz_drop_stream(ctx, stm);
                fz_drop_stream(ctx, stream);
                fz_drop_archive(ctx, zip);
        }
@@ -390,6 +420,11 @@ const fz_document_handler *fz_recognize_document_content(fz_context *ctx, const
        return handler;
 }
 
+const fz_document_handler *fz_recognize_document_content(fz_context* ctx, const char* filename)
+{
+       return do_recognize_document_content(ctx, filename, NULL, NULL);
+}
+
 const fz_document_handler *
 fz_recognize_document(fz_context *ctx, const char *magic)
 {
@@ -406,6 +441,8 @@ fz_open_accelerated_document_with_stream_and_dir(fz_context *ctx, const char *ma
        const fz_document_handler *handler;
        fz_stream *wrapped_stream = stream;
        fz_document *ret;
+       void *state = NULL;
+       fz_document_recognize_state_free_fn *free_state = NULL;
 
        if (stream == NULL && dir == NULL)
                fz_throw(ctx, FZ_ERROR_ARGUMENT, "no document to open");
@@ -414,15 +451,17 @@ fz_open_accelerated_document_with_stream_and_dir(fz_context *ctx, const char *ma
 
        /* If this finds a handler, then this might wrap stream. If it does, we reuse the wrapped one in
         * the open call (hence avoiding us having to 'file-back' a stream twice), but we must free it. */
-       handler = do_recognize_document_stream_and_dir_content(ctx, &wrapped_stream, dir, magic);
+       handler = do_recognize_document_stream_and_dir_content(ctx, &wrapped_stream, dir, magic, &state, &free_state);
        if (!handler)
                fz_throw(ctx, FZ_ERROR_UNSUPPORTED, "cannot find document handler for file type: '%s'", magic);
        fz_try(ctx)
-               ret = handler->open(ctx, handler, wrapped_stream, accel, dir);
+               ret = handler->open(ctx, handler, wrapped_stream, accel, dir, state);
        fz_always(ctx)
        {
                if (wrapped_stream != stream)
                        fz_drop_stream(ctx, wrapped_stream);
+               if (free_state && state)
+                       free_state(ctx, state);
        }
        fz_catch(ctx)
                fz_rethrow(ctx);
@@ -466,21 +505,17 @@ fz_document *
 fz_open_accelerated_document(fz_context *ctx, const char *filename, const char *accel)
 {
        const fz_document_handler *handler;
-       fz_stream *file;
+       fz_stream *file = NULL;
        fz_stream *afile = NULL;
        fz_document *doc = NULL;
        fz_archive *dir = NULL;
        char dirname[PATH_MAX];
-
-       fz_var(afile);
+       void *state = NULL;
+       fz_document_recognize_state_free_fn *free_state = NULL;
 
        if (filename == NULL)
                fz_throw(ctx, FZ_ERROR_ARGUMENT, "no document to open");
 
-       handler = fz_recognize_document_content(ctx, filename);
-       if (!handler)
-               fz_throw(ctx, FZ_ERROR_UNSUPPORTED, "cannot find document handler for file: %s", filename);
-
        if (fz_is_directory(ctx, filename))
        {
                /* Cannot accelerate directories, currently. */
@@ -496,10 +531,17 @@ fz_open_accelerated_document(fz_context *ctx, const char *filename, const char *
                return doc;
        }
 
-       file = fz_open_file(ctx, filename);
+       handler = do_recognize_document_content(ctx, filename, &state, &free_state);
+       if (!handler)
+               fz_throw(ctx, FZ_ERROR_UNSUPPORTED, "cannot find document handler for file: %s", filename);
+
+       fz_var(afile);
+       fz_var(file);
 
        fz_try(ctx)
        {
+               file = fz_open_file(ctx, filename);
+
                if (accel)
                        afile = fz_open_file(ctx, accel);
                if (handler->wants_dir)
@@ -507,10 +549,12 @@ fz_open_accelerated_document(fz_context *ctx, const char *filename, const char *
                        fz_dirname(dirname, filename, sizeof dirname);
                        dir = fz_open_directory(ctx, dirname);
                }
-               doc = handler->open(ctx, handler, file, afile, dir);
+               doc = handler->open(ctx, handler, file, afile, dir, state);
        }
        fz_always(ctx)
        {
+               if (free_state)
+                       free_state(ctx, state);
                fz_drop_archive(ctx, dir);
                fz_drop_stream(ctx, afile);
                fz_drop_stream(ctx, file);
index c48c3e0d861cccb94d5043e8a1d5febf384d1137..e5af5639fc25d09b72ea3ec3eddedd99d5d0194e 100644 (file)
@@ -27,7 +27,7 @@
 #endif
 
 static fz_document *
-gz_open_document(fz_context *ctx, const fz_document_handler *handler, fz_stream *ostm, fz_stream *accel, fz_archive *dir)
+gz_open_document(fz_context *ctx, const fz_document_handler *handler, fz_stream *ostm, fz_stream *accel, fz_archive *dir, void *state)
 {
        fz_stream *stm = fz_open_flated(ctx, ostm, 16 + MAX_WBITS);
        fz_buffer *buf = NULL;
@@ -66,11 +66,16 @@ static const char *gz_mimetypes[] =
 };
 
 static int
-gz_recognize_doc_content(fz_context *ctx, const fz_document_handler *handler, fz_stream *stream, fz_archive *dir)
+gz_recognize_doc_content(fz_context *ctx, const fz_document_handler *handler, fz_stream *stream, fz_archive *dir, void **state, fz_document_recognize_state_free_fn **free_state)
 {
        int ret = 0;
        uint8_t data[10];
 
+       if (state)
+               *state = NULL;
+       if (free_state)
+               *free_state = NULL;
+
        if (stream == NULL)
                return 0;
 
index 2465f9773ec19e5dfb43aa0cfb1d6257f5d7f987..1ffff28d201affeb98134ce6cbae839d2641fe19 100644 (file)
@@ -1036,7 +1036,7 @@ epub_init(fz_context *ctx, fz_archive *zip, fz_stream *accel)
 }
 
 static fz_document *
-epub_open_document(fz_context *ctx, const fz_document_handler *handler, fz_stream *file, fz_stream *accel, fz_archive *dir)
+epub_open_document(fz_context *ctx, const fz_document_handler *handler, fz_stream *file, fz_stream *accel, fz_archive *dir, void *state)
 {
        fz_stream *file2 = NULL;
        fz_document *doc;
@@ -1079,7 +1079,7 @@ epub_recognize(fz_context *doc, const fz_document_handler *handler, const char *
 }
 
 static int
-epub_recognize_content(fz_context *ctx, const fz_document_handler *handler, fz_stream *stream, fz_archive *dir)
+epub_recognize_content(fz_context *ctx, const fz_document_handler *handler, fz_stream *stream, fz_archive *dir, void **state, fz_document_recognize_state_free_fn **free_state)
 {
        fz_archive *arch = NULL;
        int ret = 0;
@@ -1087,6 +1087,11 @@ epub_recognize_content(fz_context *ctx, const fz_document_handler *handler, fz_s
        fz_var(arch);
        fz_var(ret);
 
+       if (state)
+               *state = NULL;
+       if (free_state)
+               *free_state = NULL;
+
        fz_try(ctx)
        {
                if (stream == NULL)
index 5d972dc37364e0ab673f4ab606ae79acf2ba5107..1d724af1826b6e954f703ea4426aec05e91b7cc3 100644 (file)
@@ -271,7 +271,7 @@ static int isws(int c)
        return c == 32 || c == 9 || c == 10 || c == 13 || c == 12;
 }
 
-int htdoc_recognize_html_content(fz_context *ctx, const fz_document_handler *handler, fz_stream *stream, fz_archive *dir)
+int htdoc_recognize_html_content(fz_context *ctx, const fz_document_handler *handler, fz_stream *stream, fz_archive *dir, void **hstate, fz_document_recognize_state_free_fn **free_state)
 {
        uint8_t buffer[4096];
        size_t i, n, m;
@@ -288,6 +288,11 @@ int htdoc_recognize_html_content(fz_context *ctx, const fz_document_handler *han
        int state = state_top;
        int type = 0;
 
+       if (hstate)
+               *hstate = NULL;
+       if (free_state)
+               *free_state = NULL;
+
        if (stream == NULL)
                return 0;
 
@@ -438,7 +443,7 @@ static const fz_htdoc_format_t fz_htdoc_html5 =
 };
 
 static fz_document *
-htdoc_open_document(fz_context *ctx, const fz_document_handler *handler, fz_stream *file, fz_stream *accel, fz_archive *dir)
+htdoc_open_document(fz_context *ctx, const fz_document_handler *handler, fz_stream *file, fz_stream *accel, fz_archive *dir, void *state)
 {
        return fz_htdoc_open_document_with_stream_and_dir(ctx, file, dir, &fz_htdoc_html5);
 }
@@ -476,7 +481,7 @@ static const fz_htdoc_format_t fz_htdoc_xhtml =
 };
 
 static fz_document *
-xhtdoc_open_document(fz_context *ctx, const fz_document_handler *handler, fz_stream *file, fz_stream *accel, fz_archive *dir)
+xhtdoc_open_document(fz_context *ctx, const fz_document_handler *handler, fz_stream *file, fz_stream *accel, fz_archive *dir, void *state)
 {
        return fz_htdoc_open_document_with_stream_and_dir(ctx, file, dir, &fz_htdoc_xhtml);
 }
@@ -513,7 +518,7 @@ static const fz_htdoc_format_t fz_htdoc_fb2 =
 };
 
 static fz_document *
-fb2doc_open_document(fz_context *ctx, const fz_document_handler *handler, fz_stream *file, fz_stream *accel, fz_archive *dir)
+fb2doc_open_document(fz_context *ctx, const fz_document_handler *handler, fz_stream *file, fz_stream *accel, fz_archive *dir, void *state)
 {
        return fz_htdoc_open_document_with_stream_and_dir(ctx, file, dir, &fz_htdoc_fb2);
 }
@@ -576,7 +581,7 @@ mobi_open_document_with_buffer(fz_context *ctx, fz_buffer *mobi)
 }
 
 static fz_document *
-mobi_open_document(fz_context *ctx, const fz_document_handler *handler, fz_stream *file, fz_stream *accel, fz_archive *dir)
+mobi_open_document(fz_context *ctx, const fz_document_handler *handler, fz_stream *file, fz_stream *accel, fz_archive *dir, void *state)
 {
        return mobi_open_document_with_buffer(ctx, fz_read_all(ctx, file, 0));
 }
index 2ee08d70fcea2779fee1ebe45853adccd6e60946..80a4ed30a4c447dee09f758330d9a1202c1eed24 100644 (file)
@@ -1225,7 +1225,7 @@ static const fz_htdoc_format_t fz_htdoc_office =
 };
 
 static fz_document *
-office_open_document(fz_context *ctx, const fz_document_handler *handler, fz_stream *file, fz_stream *accel, fz_archive *zip)
+office_open_document(fz_context *ctx, const fz_document_handler *handler, fz_stream *file, fz_stream *accel, fz_archive *zip, void *state)
 {
        return fz_htdoc_open_document_with_stream_and_dir(ctx, file, zip, &fz_htdoc_office);
 }
@@ -1256,12 +1256,17 @@ static const char *office_mimetypes[] =
 /* We are only ever 75% sure here, to allow a 'better' handler, such as sodochandler
  * to override us by returning 100. */
 static int
-office_recognize_doc_content(fz_context *ctx, const fz_document_handler *handler, fz_stream *stream, fz_archive *zip)
+office_recognize_doc_content(fz_context *ctx, const fz_document_handler *handler, fz_stream *stream, fz_archive *zip, void **state, fz_document_recognize_state_free_fn **free_state)
 {
        fz_archive *arch = NULL;
        int ret = 0;
        fz_xml *xml = NULL;
 
+       if (state)
+               *state = NULL;
+       if (free_state)
+               *free_state = NULL;
+
        fz_var(arch);
        fz_var(ret);
        fz_var(xml);
index 37ce47d16c665313ef3056634d825abf193591c0..99e823a0f2ef89b7494485343ca45c24df4030fb 100644 (file)
@@ -228,7 +228,7 @@ static const fz_htdoc_format_t fz_htdoc_txt =
 };
 
 static fz_document *
-txt_open_document(fz_context *ctx, const fz_document_handler *handler, fz_stream *file, fz_stream *accel, fz_archive *zip)
+txt_open_document(fz_context *ctx, const fz_document_handler *handler, fz_stream *file, fz_stream *accel, fz_archive *zip, void *state)
 {
        return fz_htdoc_open_document_with_stream_and_dir(ctx, file, zip, &fz_htdoc_txt);
 }
index 950ea06cea72249f5f0001a40337465952dc3951..9b511238737d813bed5e9a4ce22d781f33b9cc09 100644 (file)
@@ -3752,13 +3752,18 @@ static const char *pdf_mimetypes[] =
 };
 
 static int
-pdf_recognize_doc_content(fz_context *ctx, const fz_document_handler *handler, fz_stream *stream, fz_archive *dir)
+pdf_recognize_doc_content(fz_context *ctx, const fz_document_handler *handler, fz_stream *stream, fz_archive *dir, void **state, fz_document_recognize_state_free_fn **free_state)
 {
        const char *match = "%PDF-";
        int pos = 0;
        int n = 4096+5;
        int c;
 
+       if (state)
+               *state = NULL;
+       if (free_state)
+               *free_state = NULL;
+
        if (stream == NULL)
                return 0;
 
@@ -3785,7 +3790,7 @@ pdf_recognize_doc_content(fz_context *ctx, const fz_document_handler *handler, f
 }
 
 static fz_document *
-open_document(fz_context *ctx, const fz_document_handler *handler, fz_stream *file, fz_stream *accel, fz_archive *zip)
+open_document(fz_context *ctx, const fz_document_handler *handler, fz_stream *file, fz_stream *accel, fz_archive *zip, void *state)
 {
        if (file == NULL)
                return NULL;
index 8b5410301f4de6cefaa1e7f1385ac99ffd117515..82798844264ee57d9aa7979a3bef439459e1d3af 100644 (file)
@@ -163,7 +163,7 @@ svg_open_document_with_buffer(fz_context *ctx, fz_buffer *buf, const char *base_
 }
 
 static fz_document *
-svg_open_document(fz_context *ctx, const fz_document_handler *handler, fz_stream *file, fz_stream *accel, fz_archive *zip)
+svg_open_document(fz_context *ctx, const fz_document_handler *handler, fz_stream *file, fz_stream *accel, fz_archive *zip, void *state)
 {
        fz_buffer *buf = fz_read_all(ctx, file, 0);
        fz_document *doc = NULL;
@@ -267,7 +267,7 @@ static const char *svg_mimetypes[] =
 };
 
 static int
-svg_recognize_doc_content(fz_context *ctx, const fz_document_handler *handler, fz_stream *stm, fz_archive *dir)
+svg_recognize_doc_content(fz_context *ctx, const fz_document_handler *handler, fz_stream *stm, fz_archive *dir, void **state, fz_document_recognize_state_free_fn **free_state)
 {
        // A standalone SVG document is an XML document with an <svg> root element.
        //
@@ -281,6 +281,11 @@ svg_recognize_doc_content(fz_context *ctx, const fz_document_handler *handler, f
 
        int c;
 
+       if (state)
+               *state = NULL;
+       if (free_state)
+               *free_state = NULL;
+
        if (stm == NULL)
                return 0;
 
index 9a4db0e6ad4933b588acbf66595387086347772a..37724aa567f9706f12b532c1a1ef4240324f29e7 100644 (file)
@@ -522,13 +522,18 @@ static const char *xps_mimetypes[] =
 };
 
 static int
-xps_recognize_doc_content(fz_context *ctx, const fz_document_handler *handler, fz_stream *stream, fz_archive *dir)
+xps_recognize_doc_content(fz_context *ctx, const fz_document_handler *handler, fz_stream *stream, fz_archive *dir, void **state, fz_document_recognize_state_free_fn **free_state)
 {
        fz_archive *arch = NULL;
        int ret = 0;
        fz_xml *xml = NULL;
        fz_xml *pos;
 
+       if (state)
+               *state = NULL;
+       if (free_state)
+               *free_state = NULL;
+
        fz_var(arch);
        fz_var(ret);
        fz_var(xml);
@@ -567,7 +572,7 @@ xps_recognize_doc_content(fz_context *ctx, const fz_document_handler *handler, f
 }
 
 static fz_document *
-xps_open(fz_context *ctx, const fz_document_handler *handler, fz_stream *file, fz_stream *accel, fz_archive *dir)
+xps_open(fz_context *ctx, const fz_document_handler *handler, fz_stream *file, fz_stream *accel, fz_archive *dir, void *state)
 {
        if (file)
                return xps_open_document_with_stream(ctx, file);