Change mechanism used for pdf_document_from_fz_document.
authorRobin Watts <[email protected]>
Thu, 11 Jul 2024 10:45:53 +0000 (11:45 +0100)
committerRobin Watts <[email protected]>
Tue, 23 Jul 2024 19:02:02 +0000 (20:02 +0100)
(And pdf_specifics, which is the old name for the same thing).

Rather than comparing a function pointer, implement this using
a function. This means that so_doc_handler can implement this
too, so people can get a pdf_document handle to the converted
file.

include/mupdf/fitz/document.h
source/pdf/pdf-xref.c

index 78450c1372b239937c12dc23b34d5191a4531167..bf2f728c5b2df05ddfa986bae17ca63bd804f133 100644 (file)
@@ -233,6 +233,13 @@ typedef void (fz_document_output_accelerator_fn)(fz_context *ctx, fz_document *d
 */
 typedef void (fz_document_run_structure_fn)(fz_context *ctx, fz_document *doc, fz_device *dev, fz_cookie *cookie);
 
+/**
+       Get a handle to this document as PDF.
+
+       Returns a borrowed handle.
+*/
+typedef fz_document *(fz_document_as_pdf)(fz_context *ctx, fz_document *doc);
+
 /**
        Type for a function to make
        a bookmark. See fz_make_bookmark for more information.
@@ -1056,6 +1063,7 @@ struct fz_document
        fz_document_output_intent_fn *get_output_intent;
        fz_document_output_accelerator_fn *output_accelerator;
        fz_document_run_structure_fn *run_structure;
+       fz_document_as_pdf *as_pdf;
        int did_layout;
        int is_reflowable;
 
index 8cd35b0183b29f33198a5d6a4bcf4170a0db8d41..7aadc559e20346d17ef898e20bb5a1f6ec644a62 100644 (file)
@@ -3112,6 +3112,12 @@ char *pdf_format_link_uri(fz_context *ctx, fz_document *doc, fz_link_dest dest)
        return pdf_new_uri_from_explicit_dest(ctx, dest);
 }
 
+static fz_document *
+as_pdf(fz_context *ctx, fz_document *doc)
+{
+       return doc;
+}
+
 /*
        Initializers for the fz_document interface.
 
@@ -3186,9 +3192,10 @@ pdf_new_document(fz_context *ctx, fz_stream *file)
        doc->super.count_pages = pdf_count_pages_imp;
        doc->super.load_page = pdf_load_page_imp;
        doc->super.page_label = pdf_page_label_imp;
-       doc->super.lookup_metadata = pdf_lookup_metadata_imp;
-       doc->super.set_metadata = pdf_set_metadata_imp;
-       doc->super.run_structure = pdf_run_document_structure_imp;
+       doc->super.lookup_metadata = (fz_document_lookup_metadata_fn*)pdf_lookup_metadata;
+       doc->super.set_metadata = (fz_document_set_metadata_fn*)pdf_set_metadata;
+       doc->super.run_structure = (fz_document_run_structure_fn *)pdf_run_document_structure;
+       doc->super.as_pdf = (fz_document_as_pdf *)as_pdf;
 
        pdf_lexbuf_init(ctx, &doc->lexbuf.base, PDF_LEXBUF_LARGE);
        doc->file = fz_keep_stream(ctx, file);
@@ -3607,7 +3614,9 @@ pdf_obj *pdf_progressive_advance(fz_context *ctx, pdf_document *doc, int pagenum
 
 pdf_document *pdf_document_from_fz_document(fz_context *ctx, fz_document *ptr)
 {
-       return (pdf_document *)((ptr && ptr->count_pages == pdf_count_pages_imp) ? ptr : NULL);
+       if (!ptr || !ptr->as_pdf)
+               return NULL;
+       return ptr->as_pdf(ctx, ptr);
 }
 
 pdf_page *pdf_page_from_fz_page(fz_context *ctx, fz_page *page)