summaryrefslogtreecommitdiff
path: root/source/fitz/document.c
diff options
context:
space:
mode:
authorSebastian Rasmussen <sebras@gmail.com>2016-10-01 12:54:47 +0800
committerSebastian Rasmussen <sebras@gmail.com>2016-10-09 13:18:47 +0800
commitf3947006fb98c72d06b52c36317585d757cc984c (patch)
treef8f8b796da387e7f0afb3ae3008114388ea1cd9c /source/fitz/document.c
parentd34d3b123fa404e57c6b64d89a61a8f28c05ae5b (diff)
downloadmupdf-f3947006fb98c72d06b52c36317585d757cc984c.tar.xz
Open document file in fz_open_document().
This relieves all document formats from reimplementing opening a fz_stream unless the format wants to do something more than just opening the raw file.
Diffstat (limited to 'source/fitz/document.c')
-rw-r--r--source/fitz/document.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/source/fitz/document.c b/source/fitz/document.c
index 54245f2c..4c02f1c4 100644
--- a/source/fitz/document.c
+++ b/source/fitz/document.c
@@ -103,6 +103,8 @@ fz_open_document(fz_context *ctx, const char *filename)
int i, score;
int best_i, best_score;
fz_document_handler_context *dc;
+ fz_stream *file;
+ fz_document *doc;
if (ctx == NULL)
return NULL;
@@ -125,10 +127,22 @@ fz_open_document(fz_context *ctx, const char *filename)
}
}
- if (best_i >= 0)
+ if (best_i < 0)
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find document handler for file: '%s'", filename);
+
+ if (dc->handler[best_i]->open)
return dc->handler[best_i]->open(ctx, filename);
- fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find document handler for file: '%s'", filename);
+ file = fz_open_file(ctx, filename);
+
+ fz_try(ctx)
+ doc = dc->handler[best_i]->open_with_stream(ctx, file);
+ fz_always(ctx)
+ fz_drop_stream(ctx, file);
+ fz_catch(ctx)
+ fz_rethrow(ctx);
+
+ return doc;
}
void *