summaryrefslogtreecommitdiff
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
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.
-rw-r--r--cbz/mucbz.c57
-rw-r--r--pdf/pdf_xref.c103
-rw-r--r--pdf/pdf_xref_aux.c9
-rw-r--r--xps/xps_zip.c69
4 files changed, 39 insertions, 199 deletions
diff --git a/cbz/mucbz.c b/cbz/mucbz.c
index e8e8faa3..a8a1097a 100644
--- a/cbz/mucbz.c
+++ b/cbz/mucbz.c
@@ -458,44 +458,9 @@ cbz_run_page(cbz_document *doc, cbz_page *page, fz_device *dev, fz_matrix ctm, f
fz_fill_image(dev, &image->base, ctm, 1);
}
-/* Document interface wrappers */
-
-static void cbz_close_document_shim(fz_document *doc)
-{
- cbz_close_document((cbz_document*)doc);
-}
-
-static int cbz_count_pages_shim(fz_document *doc)
-{
- return cbz_count_pages((cbz_document*)doc);
-}
-
-static fz_page *cbz_load_page_shim(fz_document *doc, int number)
-{
- return (fz_page*) cbz_load_page((cbz_document*)doc, number);
-}
-
-static fz_rect cbz_bound_page_shim(fz_document *doc, fz_page *page)
-{
- return cbz_bound_page((cbz_document*)doc, (cbz_page*)page);
-}
-
-static void cbz_run_page_shim(fz_document *doc, fz_page *page, fz_device *dev, fz_matrix transform, fz_cookie *cookie)
-{
- cbz_run_page((cbz_document*)doc, (cbz_page*)page, dev, transform, cookie);
-}
-
-static void cbz_free_page_shim(fz_document *doc, fz_page *page)
-{
- cbz_free_page((cbz_document*)doc, (cbz_page*)page);
-}
-
-static int cbz_meta(fz_document *doc_, int key, void *ptr, int size)
+static int
+cbz_meta(cbz_document *doc, int key, void *ptr, int size)
{
- cbz_document *doc = (cbz_document *)doc_;
-
- doc = doc;
-
switch(key)
{
case FZ_META_FORMAT_INFO:
@@ -509,15 +474,11 @@ static int cbz_meta(fz_document *doc_, int key, void *ptr, int size)
static void
cbz_init_document(cbz_document *doc)
{
- doc->super.close = cbz_close_document_shim;
- doc->super.needs_password = NULL;
- doc->super.authenticate_password = NULL;
- doc->super.load_outline = NULL;
- doc->super.count_pages = cbz_count_pages_shim;
- doc->super.load_page = cbz_load_page_shim;
- doc->super.load_links = NULL;
- doc->super.bound_page = cbz_bound_page_shim;
- doc->super.run_page = cbz_run_page_shim;
- doc->super.free_page = cbz_free_page_shim;
- doc->super.meta = cbz_meta;
+ doc->super.close = (void*)cbz_close_document;
+ doc->super.count_pages = (void*)cbz_count_pages;
+ doc->super.load_page = (void*)cbz_load_page;
+ doc->super.bound_page = (void*)cbz_bound_page;
+ doc->super.run_page = (void*)cbz_run_page;
+ doc->super.free_page = (void*)cbz_free_page;
+ doc->super.meta = (void*)cbz_meta;
}
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;
}
diff --git a/xps/xps_zip.c b/xps/xps_zip.c
index bb6857ee..f82343bc 100644
--- a/xps/xps_zip.c
+++ b/xps/xps_zip.c
@@ -668,54 +668,9 @@ xps_close_document(xps_document *doc)
fz_free(doc->ctx, doc);
}
-/* Document interface wrappers */
-
-static void xps_close_document_shim(fz_document *doc)
-{
- xps_close_document((xps_document*)doc);
-}
-
-static fz_outline *xps_load_outline_shim(fz_document *doc)
-{
- return xps_load_outline((xps_document*)doc);
-}
-
-static int xps_count_pages_shim(fz_document *doc)
-{
- return xps_count_pages((xps_document*)doc);
-}
-
-static fz_page *xps_load_page_shim(fz_document *doc, int number)
-{
- return (fz_page*) xps_load_page((xps_document*)doc, number);
-}
-
-static fz_link *xps_load_links_shim(fz_document *doc, fz_page *page)
-{
- return xps_load_links((xps_document*)doc, (xps_page*)page);
-}
-
-static fz_rect xps_bound_page_shim(fz_document *doc, fz_page *page)
-{
- return xps_bound_page((xps_document*)doc, (xps_page*)page);
-}
-
-static void xps_run_page_shim(fz_document *doc, fz_page *page, fz_device *dev, fz_matrix transform, fz_cookie *cookie)
-{
- xps_run_page((xps_document*)doc, (xps_page*)page, dev, transform, cookie);
-}
-
-static void xps_free_page_shim(fz_document *doc, fz_page *page)
-{
- xps_free_page((xps_document*)doc, (xps_page*)page);
-}
-
-static int xps_meta(fz_document *doc_, int key, void *ptr, int size)
+static int
+xps_meta(xps_document *doc, int key, void *ptr, int size)
{
- xps_document *doc = (xps_document *)doc_;
-
- doc = doc;
-
switch(key)
{
case FZ_META_FORMAT_INFO:
@@ -729,15 +684,13 @@ static int xps_meta(fz_document *doc_, int key, void *ptr, int size)
static void
xps_init_document(xps_document *doc)
{
- doc->super.close = xps_close_document_shim;
- doc->super.needs_password = NULL;
- doc->super.authenticate_password = NULL;
- doc->super.load_outline = xps_load_outline_shim;
- doc->super.count_pages = xps_count_pages_shim;
- doc->super.load_page = xps_load_page_shim;
- doc->super.load_links = xps_load_links_shim;
- doc->super.bound_page = xps_bound_page_shim;
- doc->super.run_page = xps_run_page_shim;
- doc->super.free_page = xps_free_page_shim;
- doc->super.meta = xps_meta;
+ doc->super.close = (void*)xps_close_document;
+ doc->super.load_outline = (void*)xps_load_outline;
+ doc->super.count_pages = (void*)xps_count_pages;
+ doc->super.load_page = (void*)xps_load_page;
+ doc->super.load_links = (void*)xps_load_links;
+ doc->super.bound_page = (void*)xps_bound_page;
+ doc->super.run_page = (void*)xps_run_page;
+ doc->super.free_page = (void*)xps_free_page;
+ doc->super.meta = (void*)xps_meta;
}