diff options
author | Robin Watts <robin.watts@artifex.com> | 2013-07-17 18:42:33 +0100 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2013-07-19 19:54:27 +0100 |
commit | f5f7c0e4dd83257f526b158e3998970717852a0e (patch) | |
tree | c34ee93ab7773e4fbe48506c97fb515c03707e57 /source/pdf/pdf-interpret.c | |
parent | 3c559928d88fccfe17da4953ea1c93ceb42a90cb (diff) | |
download | mupdf-f5f7c0e4dd83257f526b158e3998970717852a0e.tar.xz |
Initial work on progressive loading
We are testing this using a new -p flag to mupdf that sets a bitrate at
which data will appear to arrive progressively as time goes on. For
example:
mupdf -p 102400 pdf_reference17.pdf
Details of the scheme used here are presented in docs/progressive.txt
Diffstat (limited to 'source/pdf/pdf-interpret.c')
-rw-r--r-- | source/pdf/pdf-interpret.c | 60 |
1 files changed, 51 insertions, 9 deletions
diff --git a/source/pdf/pdf-interpret.c b/source/pdf/pdf-interpret.c index cec0d1e5..515a87fa 100644 --- a/source/pdf/pdf-interpret.c +++ b/source/pdf/pdf-interpret.c @@ -372,7 +372,7 @@ begin_softmask(pdf_csi * csi, softmask_save *save) } fz_catch(ctx) { - /* FIXME: TryLater */ + fz_rethrow_if(ctx, FZ_ERROR_TRYLATER); /* FIXME: Ignore error - nasty, but if we throw from * here the clip stack would be messed up. */ if (csi->cookie) @@ -1188,7 +1188,7 @@ pdf_grestore(pdf_csi *csi) } fz_catch(ctx) { - /* FIXME: TryLater */ + fz_rethrow_if(ctx, FZ_ERROR_TRYLATER); /* Silently swallow the problem */ } clip_depth--; @@ -1590,6 +1590,31 @@ pdf_run_xobject(pdf_csi *csi, pdf_obj *resources, pdf_xobject *xobj, const fz_ma } +static pdf_font_desc * +load_font_or_hail_mary(pdf_csi *csi, pdf_obj *rdb, pdf_obj *font, int depth) +{ + pdf_document *doc = csi->doc; + fz_context *ctx = doc->ctx; + pdf_font_desc *desc; + + fz_try(ctx) + { + desc = pdf_load_font(doc, rdb, font, depth); + } + fz_catch(ctx) + { + if (fz_caught(ctx) != FZ_ERROR_TRYLATER) + fz_rethrow(ctx); + if (!csi->cookie || !csi->cookie->incomplete_ok) + fz_rethrow(ctx); + desc = NULL; + csi->cookie->incomplete++; + } + if (desc == NULL) + desc = pdf_load_hail_mary_font(doc); + return desc; +} + static void pdf_run_extgstate(pdf_csi *csi, pdf_obj *rdb, pdf_obj *extgstate) { @@ -1619,7 +1644,7 @@ pdf_run_extgstate(pdf_csi *csi, pdf_obj *rdb, pdf_obj *extgstate) gstate->font = NULL; } - gstate->font = pdf_load_font(csi->doc, rdb, font, csi->nested_depth); + gstate->font = load_font_or_hail_mary(csi, rdb, font, csi->nested_depth); if (!gstate->font) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find font in store"); gstate->size = pdf_to_real(pdf_array_get(val, 1)); @@ -2191,7 +2216,7 @@ static void pdf_run_Tf(pdf_csi *csi, pdf_obj *rdb) if (!obj) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find font resource: '%s'", csi->name); - gstate->font = pdf_load_font(csi->doc, rdb, obj, csi->nested_depth); + gstate->font = load_font_or_hail_mary(csi, rdb, obj, csi->nested_depth); } static void pdf_run_Tr(pdf_csi *csi) @@ -2855,10 +2880,21 @@ pdf_run_stream(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, pdf_lexbuf *buf) } fz_catch(ctx) { - /* FIXME: TryLater */ - /* Swallow the error */ - if (csi->cookie) - csi->cookie->errors++; + if (!csi->cookie) + { + fz_rethrow_if(ctx, FZ_ERROR_TRYLATER); + } + else if (fz_caught(ctx) == FZ_ERROR_TRYLATER) + { + if (csi->cookie->incomplete_ok) + csi->cookie->incomplete++; + else + fz_rethrow(ctx); + } + else + { + csi->cookie->errors++; + } if (!ignoring_errors) { fz_warn(ctx, "Ignoring errors during rendering"); @@ -2901,7 +2937,7 @@ pdf_run_contents_stream(pdf_csi *csi, pdf_obj *rdb, fz_stream *file) } fz_catch(ctx) { - /* FIXME: TryLater */ + fz_rethrow_if(ctx, FZ_ERROR_TRYLATER); fz_warn(ctx, "Content stream parsing error - rendering truncated"); } while (csi->gtop > csi->gbot) @@ -3000,6 +3036,8 @@ static void pdf_run_page_contents_with_usage(pdf_document *doc, pdf_page *page, void pdf_run_page_contents(pdf_document *doc, pdf_page *page, fz_device *dev, const fz_matrix *ctm, fz_cookie *cookie) { pdf_run_page_contents_with_usage(doc, page, dev, ctm, "View", cookie); + if (page->incomplete & PDF_PAGE_INCOMPLETE_CONTENTS) + fz_throw(doc->ctx, FZ_ERROR_TRYLATER, "incomplete rendering"); } static void pdf_run_annot_with_usage(pdf_document *doc, pdf_page *page, pdf_annot *annot, fz_device *dev, const fz_matrix *ctm, char *event, fz_cookie *cookie) @@ -3047,6 +3085,8 @@ static void pdf_run_annot_with_usage(pdf_document *doc, pdf_page *page, pdf_anno void pdf_run_annot(pdf_document *doc, pdf_page *page, pdf_annot *annot, fz_device *dev, const fz_matrix *ctm, fz_cookie *cookie) { pdf_run_annot_with_usage(doc, page, annot, dev, ctm, "View", cookie); + if (page->incomplete & PDF_PAGE_INCOMPLETE_ANNOTS) + fz_throw(doc->ctx, FZ_ERROR_TRYLATER, "incomplete rendering"); } static void pdf_run_page_annots_with_usage(pdf_document *doc, pdf_page *page, fz_device *dev, const fz_matrix *ctm, char *event, fz_cookie *cookie) @@ -3080,6 +3120,8 @@ pdf_run_page_with_usage(pdf_document *doc, pdf_page *page, fz_device *dev, const { pdf_run_page_contents_with_usage(doc, page, dev, ctm, event, cookie); pdf_run_page_annots_with_usage(doc, page, dev, ctm, event, cookie); + if (page->incomplete) + fz_throw(doc->ctx, FZ_ERROR_TRYLATER, "incomplete rendering"); } void |