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/svg/svg-doc.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'source/svg') diff --git a/source/svg/svg-doc.c b/source/svg/svg-doc.c index c7f8add8..2a9f061e 100644 --- a/source/svg/svg-doc.c +++ b/source/svg/svg-doc.c @@ -121,16 +121,6 @@ svg_open_document_with_stream(fz_context *ctx, fz_stream *file) return doc; } -static int -svg_recognize(fz_context *ctx, const char *magic) -{ - char *ext = strrchr(magic, '.'); - if (ext && !fz_strcasecmp(ext, ".svg")) - return 100; - if (!strcmp(magic, "svg") || !strcmp(magic, "image/svg+xml")) - return 100; - return 0; -} fz_display_list * fz_new_display_list_from_svg(fz_context *ctx, fz_buffer *buf, float *w, float *h) @@ -170,9 +160,23 @@ fz_new_image_from_svg(fz_context *ctx, fz_buffer *buf) return image; } +static const char *svg_extensions[] = +{ + "svg", + NULL +}; + +static const char *svg_mimetypes[] = +{ + "image/svg+xml", + NULL +}; + fz_document_handler svg_document_handler = { - svg_recognize, NULL, - svg_open_document_with_stream + NULL, + svg_open_document_with_stream, + svg_extensions, + svg_mimetypes }; -- cgit v1.2.3