From 0cd7f2e8397e2caf47f3d46ef635358fa0ba194c Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Tue, 28 Mar 2017 20:14:53 +0800 Subject: Move extension/mimetype detection to common function. A document handler normally only exposes a list of extensions and mimetypes. Only formats that use some kind of extra detection mechnism need to supply a recognize() callback, such as xps that can handle .xps-files unpacked into a directory. --- source/xps/xps-doc.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'source/xps/xps-doc.c') diff --git a/source/xps/xps-doc.c b/source/xps/xps-doc.c index 5c91a591..23ecf17c 100644 --- a/source/xps/xps-doc.c +++ b/source/xps/xps-doc.c @@ -465,26 +465,31 @@ xps_load_page(fz_context *ctx, xps_document *doc, int number) static int xps_recognize(fz_context *ctx, const char *magic) { - char *ext = strrchr(magic, '.'); - - if (ext) - { - if (!fz_strcasecmp(ext, ".xps") || !fz_strcasecmp(ext, ".oxps")) - return 100; - } if (strstr(magic, "/_rels/.rels") || strstr(magic, "\\_rels\\.rels")) return 100; - if (!strcmp(magic, "xps") || !strcmp(magic, "oxps") || - !strcmp(magic, "application/vnd.ms-xpsdocument") || - !strcmp(magic, "application/xps") || - !strcmp(magic, "application/oxps")) - return 100; return 0; } +static const char *xps_extensions[] = +{ + "oxps", + "xps", + NULL +}; + +static const char *xps_mimetypes[] = +{ + "application/oxps", + "application/vnd.ms-xpsdocument", + "application/xps", + NULL +}; + 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 + (fz_document_open_with_stream_fn *) xps_open_document_with_stream, + xps_extensions, + xps_mimetypes }; -- cgit v1.2.3