From f3947006fb98c72d06b52c36317585d757cc984c Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sat, 1 Oct 2016 12:54:47 +0800 Subject: 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. --- source/fitz/document.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'source/fitz') 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 * -- cgit v1.2.3