From 9172100d6d9f2f5aa4594aaa130fbfaef7162afd Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Fri, 5 Sep 2014 20:26:41 +0100 Subject: test-device: Abort interpretation when color found. Add a new class of errors and use them to abort interpretation when the test device detects a color page. --- source/fitz/document.c | 28 ++++++++++++++++++++++++++-- source/fitz/error.c | 30 ++++++++++++++++++------------ source/fitz/list-device.c | 2 ++ source/fitz/test-device.c | 8 ++++++++ 4 files changed, 54 insertions(+), 14 deletions(-) (limited to 'source/fitz') diff --git a/source/fitz/document.c b/source/fitz/document.c index 45da7e90..4bde820c 100644 --- a/source/fitz/document.c +++ b/source/fitz/document.c @@ -244,14 +244,38 @@ void fz_run_page_contents(fz_document *doc, fz_page *page, fz_device *dev, const fz_matrix *transform, fz_cookie *cookie) { if (doc && doc->run_page_contents && page) - doc->run_page_contents(doc, page, dev, transform, cookie); + { + fz_context *ctx = dev->ctx; + + fz_try(ctx) + { + doc->run_page_contents(doc, page, dev, transform, cookie); + } + fz_catch(ctx) + { + if (fz_caught(ctx) != FZ_ERROR_ABORT) + fz_rethrow(ctx); + } + } } void fz_run_annot(fz_document *doc, fz_page *page, fz_annot *annot, fz_device *dev, const fz_matrix *transform, fz_cookie *cookie) { if (doc && doc->run_annot && page && annot) - doc->run_annot(doc, page, annot, dev, transform, cookie); + { + fz_context *ctx = dev->ctx; + + fz_try(ctx) + { + doc->run_annot(doc, page, annot, dev, transform, cookie); + } + fz_catch(ctx) + { + if (fz_caught(ctx) != FZ_ERROR_ABORT) + fz_rethrow(ctx); + } + } } void diff --git a/source/fitz/error.c b/source/fitz/error.c index e8225ee3..414b993f 100644 --- a/source/fitz/error.c +++ b/source/fitz/error.c @@ -140,14 +140,17 @@ void fz_throw(fz_context *ctx, int code, const char *fmt, ...) vsnprintf(ctx->error->message, sizeof ctx->error->message, fmt, args); va_end(args); - fz_flush_warnings(ctx); - fprintf(stderr, "error: %s\n", ctx->error->message); - LOGE("error: %s\n", ctx->error->message); + if (code != FZ_ERROR_ABORT) + { + fz_flush_warnings(ctx); + fprintf(stderr, "error: %s\n", ctx->error->message); + LOGE("error: %s\n", ctx->error->message); #ifdef USE_OUTPUT_DEBUG_STRING - OutputDebugStringA("error: "); - OutputDebugStringA(ctx->error->message); - OutputDebugStringA("\n"); + OutputDebugStringA("error: "); + OutputDebugStringA(ctx->error->message); + OutputDebugStringA("\n"); #endif + } throw(ctx->error); } @@ -168,14 +171,17 @@ void fz_rethrow_message(fz_context *ctx, const char *fmt, ...) vsnprintf(ctx->error->message, sizeof ctx->error->message, fmt, args); va_end(args); - fz_flush_warnings(ctx); - fprintf(stderr, "error: %s\n", ctx->error->message); - LOGE("error: %s\n", ctx->error->message); + if (ctx->error->errcode != FZ_ERROR_ABORT) + { + fz_flush_warnings(ctx); + fprintf(stderr, "error: %s\n", ctx->error->message); + LOGE("error: %s\n", ctx->error->message); #ifdef USE_OUTPUT_DEBUG_STRING - OutputDebugStringA("error: "); - OutputDebugStringA(ctx->error->message); - OutputDebugStringA("\n"); + OutputDebugStringA("error: "); + OutputDebugStringA(ctx->error->message); + OutputDebugStringA("\n"); #endif + } throw(ctx->error); } diff --git a/source/fitz/list-device.c b/source/fitz/list-device.c index 529e0bbf..2bac3034 100644 --- a/source/fitz/list-device.c +++ b/source/fitz/list-device.c @@ -848,6 +848,8 @@ visible: /* Swallow the error */ if (cookie) cookie->errors++; + if (fz_caught(ctx) == FZ_ERROR_ABORT) + break; fz_warn(ctx, "Ignoring error during interpretation"); } } diff --git a/source/fitz/test-device.c b/source/fitz/test-device.c index 32d3a5f6..9c778ce1 100644 --- a/source/fitz/test-device.c +++ b/source/fitz/test-device.c @@ -38,6 +38,7 @@ fz_test_color(fz_device *dev, fz_colorspace *colorspace, const float *color) { *t->is_color = 1; dev->hints |= FZ_IGNORE_IMAGE; + fz_throw(ctx, FZ_ERROR_ABORT, "Page found as color; stopping interpretation"); } } else @@ -48,6 +49,7 @@ fz_test_color(fz_device *dev, fz_colorspace *colorspace, const float *color) { *t->is_color = 1; dev->hints |= FZ_IGNORE_IMAGE; + fz_throw(ctx, FZ_ERROR_ABORT, "Page found as color; stopping interpretation"); } } } @@ -150,6 +152,8 @@ fz_test_fill_image(fz_device *dev, fz_image *image, const fz_matrix *ctm, float { *t->is_color = 1; dev->hints |= FZ_IGNORE_IMAGE; + fz_close(stream); + fz_throw(ctx, FZ_ERROR_ABORT, "Page found as color; stopping interpretation"); break; } } @@ -199,6 +203,8 @@ fz_test_fill_image(fz_device *dev, fz_image *image, const fz_matrix *ctm, float { *t->is_color = 1; dev->hints |= FZ_IGNORE_IMAGE; + fz_drop_pixmap(ctx, pix); + fz_throw(ctx, FZ_ERROR_ABORT, "Page found as color; stopping interpretation"); break; } s += 4; @@ -226,6 +232,8 @@ fz_test_fill_image(fz_device *dev, fz_image *image, const fz_matrix *ctm, float { *t->is_color = 1; dev->hints |= FZ_IGNORE_IMAGE; + fz_drop_pixmap(ctx, pix); + fz_throw(ctx, FZ_ERROR_ABORT, "Page found as color; stopping interpretation"); break; } } -- cgit v1.2.3