diff options
author | Robin Watts <robin.watts@artifex.com> | 2014-01-03 16:50:41 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2014-01-07 10:25:42 +0000 |
commit | 7f009acebb75ff88c1ee934b03fa2d15f7785b32 (patch) | |
tree | 7be547523d730d104c62e4b5d43685dd8bb5bd40 /source/img/muimage.c | |
parent | 016adfa063293281a0896c62bf22e406b09ddf21 (diff) | |
download | mupdf-7f009acebb75ff88c1ee934b03fa2d15f7785b32.tar.xz |
Introduce 'document handlers'.
We define a document handler for each file type (2 in the case of PDF, one
to handle files with the ability to 'run' them, and one without).
We then register these handlers with the context at startup, and then
call fz_open_document... as usual. This enables people to select the
document types they want at will (and even to extend the library with more
document types should they wish).
Diffstat (limited to 'source/img/muimage.c')
-rw-r--r-- | source/img/muimage.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/source/img/muimage.c b/source/img/muimage.c index 26f4a0f3..300d6603 100644 --- a/source/img/muimage.c +++ b/source/img/muimage.c @@ -154,3 +154,34 @@ image_init_document(image_document *doc) doc->super.meta = (fz_document_meta_fn *)image_meta; doc->super.rebind = (fz_document_rebind_fn *)image_rebind; } + +static int +image_recognize(fz_context *doc, const char *magic) +{ + char *ext = strrchr(magic, '.'); + + if (ext) + { + if (!fz_strcasecmp(ext, ".png") || !fz_strcasecmp(ext, ".jpg") || + !fz_strcasecmp(ext, ".jpeg") || !fz_strcasecmp(ext, ".jfif") || + !fz_strcasecmp(ext, ".jfif-tbnl") || !fz_strcasecmp(ext, ".jpe") || + !fz_strcasecmp(ext, ".tif") || !fz_strcasecmp(ext, ".tiff")) + return 100; + } + if (!strcmp(magic, "png") || !strcmp(magic, "image/png") || + !strcmp(magic, "jpg") || !strcmp(magic, "image/jpeg") || + !strcmp(magic, "jpeg") || !strcmp(magic, "image/pjpeg") || + !strcmp(magic, "jpe") || !strcmp(magic, "jfif") || + !strcmp(magic, "tif") || !strcmp(magic, "image/tiff") || + !strcmp(magic, "tiff") || !strcmp(magic, "image/x-tiff")) + return 100; + + return 0; +} + +fz_document_handler img_document_handler = +{ + (fz_document_recognize_fn *)&image_recognize, + (fz_document_open_fn *)&image_open_document, + (fz_document_open_with_stream_fn *)&image_open_document_with_stream +}; |