diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2017-04-27 12:43:00 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2017-04-27 15:12:03 +0200 |
commit | c586d072fd786e66851173f5ddd31241ad28f3e6 (patch) | |
tree | d6db1b68dc122f8349513633ae76a73ed353b69b /source/xps | |
parent | ce680b96e207c90429eb702c5ee4b9bec177fdfd (diff) | |
download | mupdf-c586d072fd786e66851173f5ddd31241ad28f3e6.tar.xz |
Avoid typecasting function pointers in subclasses.
Do the typecasting in the functions instead, reducing the risk
of function prototype mismatches.
Diffstat (limited to 'source/xps')
-rw-r--r-- | source/xps/xps-doc.c | 35 | ||||
-rw-r--r-- | source/xps/xps-imp.h | 41 | ||||
-rw-r--r-- | source/xps/xps-link.c | 3 | ||||
-rw-r--r-- | source/xps/xps-outline.c | 5 | ||||
-rw-r--r-- | source/xps/xps-tile.c | 3 | ||||
-rw-r--r-- | source/xps/xps-zip.c | 31 |
6 files changed, 53 insertions, 65 deletions
diff --git a/source/xps/xps-doc.c b/source/xps/xps-doc.c index c4034d48..611e5903 100644 --- a/source/xps/xps-doc.c +++ b/source/xps/xps-doc.c @@ -105,10 +105,11 @@ xps_add_link_target(fz_context *ctx, xps_document *doc, char *name) } int -xps_lookup_link_target(fz_context *ctx, xps_document *doc, char *target_uri, float *xp, float *yp) +xps_lookup_link_target(fz_context *ctx, fz_document *doc_, const char *target_uri, float *xp, float *yp) { + xps_document *doc = (xps_document*)doc_; xps_target *target; - char *needle = strrchr(target_uri, '#'); + const char *needle = strrchr(target_uri, '#'); needle = needle ? needle + 1 : target_uri; for (target = doc->target; target; target = target->next) if (!strcmp(target->name, needle)) @@ -318,8 +319,9 @@ xps_read_page_list(fz_context *ctx, xps_document *doc) } int -xps_count_pages(fz_context *ctx, xps_document *doc) +xps_count_pages(fz_context *ctx, fz_document *doc_) { + xps_document *doc = (xps_document*)doc_; return doc->page_count; } @@ -388,8 +390,9 @@ xps_load_fixed_page(fz_context *ctx, xps_document *doc, xps_fixpage *page) } static fz_rect * -xps_bound_page(fz_context *ctx, xps_page *page, fz_rect *bounds) +xps_bound_page(fz_context *ctx, fz_page *page_, fz_rect *bounds) { + xps_page *page = (xps_page*)page_; bounds->x0 = bounds->y0 = 0; bounds->x1 = page->fix->width * 72.0f / 96.0f; bounds->y1 = page->fix->height * 72.0f / 96.0f; @@ -397,15 +400,17 @@ xps_bound_page(fz_context *ctx, xps_page *page, fz_rect *bounds) } static void -xps_drop_page_imp(fz_context *ctx, xps_page *page) +xps_drop_page_imp(fz_context *ctx, fz_page *page_) { + xps_page *page = (xps_page*)page_; fz_drop_document(ctx, &page->doc->super); fz_drop_xml(ctx, page->root); } -xps_page * -xps_load_page(fz_context *ctx, xps_document *doc, int number) +fz_page * +xps_load_page(fz_context *ctx, fz_document *doc_, int number) { + xps_document *doc = (xps_document*)doc_; xps_page *page = NULL; xps_fixpage *fix; fz_xml *root; @@ -421,12 +426,12 @@ xps_load_page(fz_context *ctx, xps_document *doc, int number) fz_try(ctx) { page = fz_new_derived_page(ctx, xps_page); - page->super.load_links = (fz_page_load_links_fn*)xps_load_links; - page->super.bound_page = (fz_page_bound_page_fn*)xps_bound_page; - page->super.run_page_contents = (fz_page_run_page_contents_fn*)xps_run_page; - page->super.drop_page = (fz_page_drop_page_fn*)xps_drop_page_imp; + page->super.load_links = xps_load_links; + page->super.bound_page = xps_bound_page; + page->super.run_page_contents = xps_run_page; + page->super.drop_page = xps_drop_page_imp; - page->doc = (xps_document*) fz_keep_document(ctx, &doc->super); + page->doc = (xps_document*) fz_keep_document(ctx, (fz_document*)doc); page->fix = fix; page->root = root; } @@ -435,7 +440,7 @@ xps_load_page(fz_context *ctx, xps_document *doc, int number) fz_drop_xml(ctx, root); fz_rethrow(ctx); } - return page; + return (fz_page*)page; } n ++; } @@ -469,8 +474,8 @@ static const char *xps_mimetypes[] = fz_document_handler xps_document_handler = { xps_recognize, - (fz_document_open_fn*)xps_open_document, - (fz_document_open_with_stream_fn*)xps_open_document_with_stream, + xps_open_document, + xps_open_document_with_stream, xps_extensions, xps_mimetypes }; diff --git a/source/xps/xps-imp.h b/source/xps/xps-imp.h index f86f16f1..cac5494a 100644 --- a/source/xps/xps-imp.h +++ b/source/xps/xps-imp.h @@ -5,36 +5,16 @@ typedef struct xps_document_s xps_document; typedef struct xps_page_s xps_page; /* - xps_open_document: Open a document. - - Open a document for reading so the library is able to locate - objects and pages inside the file. - - The returned xps_document should be used when calling most - other functions. Note that it wraps the context, so those - functions implicitly get access to the global state in - context. - - filename: a path to a file as it would be given to open(2). -*/ -xps_document *xps_open_document(fz_context *ctx, const char *filename); - -/* - xps_open_document_with_stream: Opens a document. - - Same as xps_open_document, but takes a stream instead of a - filename to locate the document to open. Increments the - reference count of the stream. See fz_open_file, - fz_open_file_w or fz_open_fd for opening a stream, and - fz_drop_stream for closing an open stream. -*/ -xps_document *xps_open_document_with_stream(fz_context *ctx, fz_stream *file); - -int xps_count_pages(fz_context *ctx, xps_document *doc); -xps_page *xps_load_page(fz_context *ctx, xps_document *doc, int number); -fz_outline *xps_load_outline(fz_context *ctx, xps_document *doc); -void xps_run_page(fz_context *ctx, xps_page *page, fz_device *dev, const fz_matrix *ctm, fz_cookie *cookie); -fz_link *xps_load_links(fz_context *ctx, xps_page *page); + * fz_document api functions + */ +fz_document *xps_open_document(fz_context *ctx, const char *filename); +fz_document *xps_open_document_with_stream(fz_context *ctx, fz_stream *file); +int xps_count_pages(fz_context *ctx, fz_document *doc); +fz_page *xps_load_page(fz_context *ctx, fz_document *doc, int number); +fz_outline *xps_load_outline(fz_context *ctx, fz_document *doc); +void xps_run_page(fz_context *ctx, fz_page *page, fz_device *dev, const fz_matrix *ctm, fz_cookie *cookie); +fz_link *xps_load_links(fz_context *ctx, fz_page *page); +int xps_lookup_link_target(fz_context *ctx, fz_document *doc, const char *target_uri, float *xp, float *yp); /* * Memory, and string functions. @@ -103,7 +83,6 @@ void xps_read_page_list(fz_context *ctx, xps_document *doc); void xps_print_page_list(fz_context *ctx, xps_document *doc); void xps_drop_page_list(fz_context *ctx, xps_document *doc); -int xps_lookup_link_target(fz_context *ctx, xps_document *doc, char *target_uri, float *xp, float *yp); /* * Images, fonts, and colorspaces. diff --git a/source/xps/xps-link.c b/source/xps/xps-link.c index c574fe35..c07e0d76 100644 --- a/source/xps/xps-link.c +++ b/source/xps/xps-link.c @@ -184,8 +184,9 @@ xps_load_links_in_fixed_page(fz_context *ctx, xps_document *doc, const fz_matrix } fz_link * -xps_load_links(fz_context *ctx, xps_page *page) +xps_load_links(fz_context *ctx, fz_page *page_) { + xps_page *page = (xps_page*)page_; fz_matrix ctm; fz_link *link = NULL; fz_scale(&ctm, 72.0f / 96.0f, 72.0f / 96.0f); diff --git a/source/xps/xps-outline.c b/source/xps/xps-outline.c index 6244a83d..63b6326b 100644 --- a/source/xps/xps-outline.c +++ b/source/xps/xps-outline.c @@ -37,7 +37,7 @@ xps_parse_document_outline(fz_context *ctx, xps_document *doc, fz_xml *root) entry = fz_new_outline(ctx); entry->title = fz_strdup(ctx, description); entry->uri = fz_strdup(ctx, target); - entry->page = xps_lookup_link_target(ctx, doc, target, NULL, NULL); + entry->page = xps_lookup_link_target(ctx, (fz_document*)doc, target, NULL, NULL); entry->down = NULL; entry->next = NULL; @@ -119,8 +119,9 @@ xps_load_document_structure(fz_context *ctx, xps_document *doc, xps_fixdoc *fixd } fz_outline * -xps_load_outline(fz_context *ctx, xps_document *doc) +xps_load_outline(fz_context *ctx, fz_document *doc_) { + xps_document *doc = (xps_document*)doc_; xps_fixdoc *fixdoc; fz_outline *head = NULL, *tail, *outline; diff --git a/source/xps/xps-tile.c b/source/xps/xps-tile.c index 53e223ee..e5b3bed7 100644 --- a/source/xps/xps-tile.c +++ b/source/xps/xps-tile.c @@ -366,8 +366,9 @@ xps_parse_fixed_page(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, x } void -xps_run_page(fz_context *ctx, xps_page *page, fz_device *dev, const fz_matrix *ctm, fz_cookie *cookie) +xps_run_page(fz_context *ctx, fz_page *page_, fz_device *dev, const fz_matrix *ctm, fz_cookie *cookie) { + xps_page *page = (xps_page*)page_; xps_document *doc = page->doc; fz_matrix page_ctm = *ctm; diff --git a/source/xps/xps-zip.c b/source/xps/xps-zip.c index 5efccab4..a17894ea 100644 --- a/source/xps/xps-zip.c +++ b/source/xps/xps-zip.c @@ -110,7 +110,7 @@ xps_has_part(fz_context *ctx, xps_document *doc, char *name) return 0; } -static xps_document * +static fz_document * xps_open_document_with_directory(fz_context *ctx, const char *directory) { xps_document *doc; @@ -129,10 +129,10 @@ xps_open_document_with_directory(fz_context *ctx, const char *directory) fz_rethrow(ctx); } - return doc; + return (fz_document*)doc; } -xps_document * +fz_document * xps_open_document_with_stream(fz_context *ctx, fz_stream *file) { xps_document *doc; @@ -151,16 +151,16 @@ xps_open_document_with_stream(fz_context *ctx, fz_stream *file) fz_rethrow(ctx); } - return doc; + return (fz_document*)doc; } -xps_document * +fz_document * xps_open_document(fz_context *ctx, const char *filename) { char buf[2048]; fz_stream *file; char *p; - xps_document *doc; + fz_document *doc; if (strstr(filename, "/_rels/.rels") || strstr(filename, "\\_rels\\.rels")) { @@ -181,12 +181,13 @@ xps_open_document(fz_context *ctx, const char *filename) fz_catch(ctx) fz_rethrow(ctx); - return doc; + return (fz_document*)doc; } static void -xps_drop_document(fz_context *ctx, xps_document *doc) +xps_drop_document(fz_context *ctx, fz_document *doc_) { + xps_document *doc = (xps_document*)doc_; xps_font_cache *font, *next; if (doc->zip) @@ -208,7 +209,7 @@ xps_drop_document(fz_context *ctx, xps_document *doc) } static int -xps_lookup_metadata(fz_context *ctx, xps_document *doc, const char *key, char *buf, int size) +xps_lookup_metadata(fz_context *ctx, fz_document *doc_, const char *key, char *buf, int size) { if (!strcmp(key, "format")) return (int)fz_strlcpy(buf, "XPS", size); @@ -219,10 +220,10 @@ static void xps_init_document(fz_context *ctx, xps_document *doc) { doc->super.refs = 1; - doc->super.drop_document = (fz_document_drop_fn*)xps_drop_document; - doc->super.load_outline = (fz_document_load_outline_fn*)xps_load_outline; - doc->super.resolve_link = (fz_document_resolve_link_fn*)xps_lookup_link_target; - doc->super.count_pages = (fz_document_count_pages_fn*)xps_count_pages; - doc->super.load_page = (fz_document_load_page_fn*)xps_load_page; - doc->super.lookup_metadata = (fz_document_lookup_metadata_fn*)xps_lookup_metadata; + doc->super.drop_document = xps_drop_document; + doc->super.load_outline = xps_load_outline; + doc->super.resolve_link = xps_lookup_link_target; + doc->super.count_pages = xps_count_pages; + doc->super.load_page = xps_load_page; + doc->super.lookup_metadata = xps_lookup_metadata; } |