summaryrefslogtreecommitdiff
path: root/pdf
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2012-06-20 11:56:12 +0200
committerTor Andersson <tor.andersson@artifex.com>2012-06-20 11:56:12 +0200
commitacfcf144a708aa3afc739904dfafccbec48e64bb (patch)
tree6f58a2c03924f6bd6b228e7afceba5805ecc7b27 /pdf
parent69bcec1c5204bcc64a9405c818e65cc260fb0078 (diff)
downloadmupdf-acfcf144a708aa3afc739904dfafccbec48e64bb.tar.xz
Reduce amount of boiler plate by casting function pointers to void*.
Remove the shim indirection layer for fz_document. A little less type safe, but a lot less boiler plate.
Diffstat (limited to 'pdf')
-rw-r--r--pdf/pdf_xref.c103
-rw-r--r--pdf/pdf_xref_aux.c9
2 files changed, 19 insertions, 93 deletions
diff --git a/pdf/pdf_xref.c b/pdf/pdf_xref.c
index 054f8edb..8f51c46b 100644
--- a/pdf/pdf_xref.c
+++ b/pdf/pdf_xref.c
@@ -1232,18 +1232,14 @@ pdf_meta(pdf_document *doc, int key, void *ptr, int size)
}
}
-static fz_interactive *pdf_interact_shim(fz_document *doc)
+static fz_interactive *
+pdf_interact(pdf_document *doc)
{
- /*
- Currently pdf is the only supporter of interaction,
- so no need for indirecting interaction through
- function pointers.
- */
return (fz_interactive *)doc;
}
/*
- Wrappers to implement the fz_document interface for pdf_document.
+ Initializers for the fz_document interface.
The functions are split across two files to allow calls to a
version of the constructor that does not link in the interpreter.
@@ -1252,92 +1248,27 @@ static fz_interactive *pdf_interact_shim(fz_document *doc)
saves roughly 6MB of space.
*/
-static void pdf_close_document_shim(fz_document *doc)
-{
- pdf_close_document((pdf_document*)doc);
-}
-
-static int pdf_needs_password_shim(fz_document *doc)
-{
- return pdf_needs_password((pdf_document*)doc);
-}
-
-static int pdf_authenticate_password_shim(fz_document *doc, char *password)
-{
- return pdf_authenticate_password((pdf_document*)doc, password);
-}
-
-static fz_outline *pdf_load_outline_shim(fz_document *doc)
-{
- return pdf_load_outline((pdf_document*)doc);
-}
-
-static int pdf_count_pages_shim(fz_document *doc)
-{
- return pdf_count_pages((pdf_document*)doc);
-}
-
-static fz_page *pdf_load_page_shim(fz_document *doc, int number)
-{
- return (fz_page*) pdf_load_page((pdf_document*)doc, number);
-}
-
-static fz_link *pdf_load_links_shim(fz_document *doc, fz_page *page)
-{
- return pdf_load_links((pdf_document*)doc, (pdf_page*)page);
-}
-
-static fz_rect pdf_bound_page_shim(fz_document *doc, fz_page *page)
-{
- return pdf_bound_page((pdf_document*)doc, (pdf_page*)page);
-}
-
-static fz_annot *pdf_first_annot_shim(fz_document *doc, fz_page *page)
-{
- return (fz_annot *)pdf_first_annot((pdf_document*)doc, (pdf_page*)page);
-}
-
-static fz_annot *pdf_next_annot_shim(fz_document *doc, fz_annot *annot)
-{
- return (fz_annot *)pdf_next_annot((pdf_document*)doc, (pdf_annot*)annot);
-}
-
-static fz_rect pdf_bound_annot_shim(fz_document *doc, fz_annot *annot)
-{
- return pdf_bound_annot((pdf_document*)doc, (pdf_annot*)annot);
-}
-
-static void pdf_free_page_shim(fz_document *doc, fz_page *page)
-{
- pdf_free_page((pdf_document*)doc, (pdf_page*)page);
-}
-
-static int pdf_meta_shim(fz_document *doc, int key, void *ptr, int size)
-{
- return pdf_meta((pdf_document*)doc, key, ptr, size);
-}
-
static pdf_document *
pdf_new_document(fz_stream *file)
{
fz_context *ctx = file->ctx;
pdf_document *doc = fz_malloc_struct(ctx, pdf_document);
- doc->super.close = pdf_close_document_shim;
- doc->super.needs_password = pdf_needs_password_shim;
- doc->super.authenticate_password = pdf_authenticate_password_shim;
- doc->super.load_outline = pdf_load_outline_shim;
- doc->super.count_pages = pdf_count_pages_shim;
- doc->super.load_page = pdf_load_page_shim;
- doc->super.load_links = pdf_load_links_shim;
- doc->super.bound_page = pdf_bound_page_shim;
- doc->super.first_annot = pdf_first_annot_shim;
- doc->super.next_annot = pdf_next_annot_shim;
- doc->super.bound_annot = pdf_bound_annot_shim;
+ doc->super.close = (void*)pdf_close_document;
+ doc->super.needs_password = (void*)pdf_needs_password;
+ doc->super.authenticate_password = (void*)pdf_authenticate_password;
+ doc->super.load_outline = (void*)pdf_load_outline;
+ doc->super.count_pages = (void*)pdf_count_pages;
+ doc->super.load_page = (void*)pdf_load_page;
+ doc->super.load_links = (void*)pdf_load_links;
+ doc->super.bound_page = (void*)pdf_bound_page;
+ doc->super.first_annot = (void*)pdf_first_annot;
+ doc->super.next_annot = (void*)pdf_next_annot;
+ doc->super.bound_annot = (void*)pdf_bound_annot;
doc->super.run_page = NULL; /* see pdf_xref_aux.c */
- doc->super.free_page = pdf_free_page_shim;
- doc->super.meta = pdf_meta_shim;
- doc->super.interact = pdf_interact_shim;
+ doc->super.free_page = (void*)pdf_free_page;
+ doc->super.meta = (void*)pdf_meta;
+ doc->super.interact = (void*)pdf_interact;
doc->lexbuf.base.size = PDF_LEXBUF_LARGE;
doc->file = fz_keep_stream(file);
diff --git a/pdf/pdf_xref_aux.c b/pdf/pdf_xref_aux.c
index 2d760334..9acec96c 100644
--- a/pdf/pdf_xref_aux.c
+++ b/pdf/pdf_xref_aux.c
@@ -9,16 +9,11 @@
resulting executables.
*/
-static void pdf_run_page_shim(fz_document *doc, fz_page *page, fz_device *dev, fz_matrix transform, fz_cookie *cookie)
-{
- pdf_run_page((pdf_document*)doc, (pdf_page*)page, dev, transform, cookie);
-}
-
pdf_document *
pdf_open_document_with_stream(fz_stream *file)
{
pdf_document *doc = pdf_open_document_no_run_with_stream(file);
- doc->super.run_page = pdf_run_page_shim;
+ doc->super.run_page = (void*)pdf_run_page;
return doc;
}
@@ -26,6 +21,6 @@ pdf_document *
pdf_open_document(fz_context *ctx, const char *filename)
{
pdf_document *doc = pdf_open_document_no_run(ctx, filename);
- doc->super.run_page = pdf_run_page_shim;
+ doc->super.run_page = (void*)pdf_run_page;
return doc;
}