summaryrefslogtreecommitdiff
path: root/pdf
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2013-06-18 20:14:40 +0100
committerRobin Watts <robin.watts@artifex.com>2013-06-19 11:52:11 +0100
commit8a22a7a76be8d9b439ee73383edbdf9d554bf3eb (patch)
tree116733ff35f20dddb247c412c842256cef68f5af /pdf
parentfe0be86de83b44ace49ceb540fc7f9e4db8253fb (diff)
downloadmupdf-8a22a7a76be8d9b439ee73383edbdf9d554bf3eb.tar.xz
Exception handling changes
In preparation for work on progressive loading, update the exception handling scheme slightly. Until now, exceptions (as thrown with fz_throw, and caught with fz_try/fz_catch) have merely had an informative string. They have never had anything that can be compared to see if an error is of a particular type. We now introduce error codes; when we fz_throw, we now always give an error code, and can optionally (using fz_throw_message) give both an error code and an informative string. When we fz_rethrow from within a fz_catch, both the error code and the error message is maintained. Using fz_rethrow_message we can 'improve' the error message, but the code is maintained. The error message can be read out using fz_caught_message() and the error code can be read as fz_caught(). Currently we only define a 'generic' error. This will expand in future versions to include other error types that may be tested for.
Diffstat (limited to 'pdf')
-rw-r--r--pdf/pdf_annot.c4
-rw-r--r--pdf/pdf_cmap_load.c14
-rw-r--r--pdf/pdf_cmap_parse.c26
-rw-r--r--pdf/pdf_colorspace.c16
-rw-r--r--pdf/pdf_crypt.c40
-rw-r--r--pdf/pdf_device.c1
-rw-r--r--pdf/pdf_font.c28
-rw-r--r--pdf/pdf_form.c4
-rw-r--r--pdf/pdf_function.c52
-rw-r--r--pdf/pdf_image.c14
-rw-r--r--pdf/pdf_interpret.c78
-rw-r--r--pdf/pdf_js.c8
-rw-r--r--pdf/pdf_jsimp_cpp.c38
-rw-r--r--pdf/pdf_object.c5
-rw-r--r--pdf/pdf_page.c8
-rw-r--r--pdf/pdf_parse.c28
-rw-r--r--pdf/pdf_pattern.c2
-rw-r--r--pdf/pdf_repair.c29
-rw-r--r--pdf/pdf_shade.c18
-rw-r--r--pdf/pdf_stream.c13
-rw-r--r--pdf/pdf_type3.c11
-rw-r--r--pdf/pdf_write.c9
-rw-r--r--pdf/pdf_xobject.c6
-rw-r--r--pdf/pdf_xref.c109
24 files changed, 295 insertions, 266 deletions
diff --git a/pdf/pdf_annot.c b/pdf/pdf_annot.c
index 208d93e7..c50bbba2 100644
--- a/pdf/pdf_annot.c
+++ b/pdf/pdf_annot.c
@@ -327,6 +327,7 @@ pdf_load_link_annots(pdf_document *xref, pdf_obj *annots, const fz_matrix *page_
}
fz_catch(xref->ctx)
{
+ /* FIXME: TryLater */
link = NULL;
}
@@ -502,6 +503,7 @@ pdf_load_annots(pdf_document *xref, pdf_obj *annots, pdf_page *page)
}
fz_catch(ctx)
{
+ /* FIXME: TryLater */
ap = NULL;
is_dict = 0;
}
@@ -564,6 +566,7 @@ pdf_load_annots(pdf_document *xref, pdf_obj *annots, pdf_page *page)
{
pdf_free_annot(ctx, annot);
fz_warn(ctx, "ignoring broken annotation");
+ /* FIXME: TryLater */
}
}
@@ -618,6 +621,7 @@ pdf_update_annot(pdf_document *xref, pdf_annot *annot)
fz_catch(ctx)
{
fz_warn(ctx, "ignoring broken annotation");
+ /* FIXME: TryLater */
}
}
}
diff --git a/pdf/pdf_cmap_load.c b/pdf/pdf_cmap_load.c
index 340f914b..5fcae15d 100644
--- a/pdf/pdf_cmap_load.c
+++ b/pdf/pdf_cmap_load.c
@@ -31,7 +31,7 @@ pdf_load_embedded_cmap(pdf_document *xref, pdf_obj *stmobj)
fz_var(cmap);
if (pdf_obj_marked(stmobj))
- fz_throw(ctx, "Recursion in embedded cmap");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "Recursion in embedded cmap");
if ((cmap = pdf_find_item(ctx, pdf_free_cmap_imp, stmobj)))
{
@@ -77,16 +77,16 @@ pdf_load_embedded_cmap(pdf_document *xref, pdf_obj *stmobj)
if (cmap)
pdf_drop_cmap(ctx, cmap);
if (phase < 1)
- fz_throw(ctx, "cannot open cmap stream (%d %d R)", pdf_to_num(stmobj), pdf_to_gen(stmobj));
+ fz_rethrow_message(ctx, "cannot open cmap stream (%d %d R)", pdf_to_num(stmobj), pdf_to_gen(stmobj));
else if (phase < 2)
- fz_throw(ctx, "cannot parse cmap stream (%d %d R)", pdf_to_num(stmobj), pdf_to_gen(stmobj));
+ fz_rethrow_message(ctx, "cannot parse cmap stream (%d %d R)", pdf_to_num(stmobj), pdf_to_gen(stmobj));
else if (phase < 3)
- fz_throw(ctx, "cannot load system usecmap '%s'", pdf_to_name(obj));
+ fz_rethrow_message(ctx, "cannot load system usecmap '%s'", pdf_to_name(obj));
else
{
if (phase == 3)
pdf_obj_unmark(obj);
- fz_throw(ctx, "cannot load embedded usecmap (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj));
+ fz_rethrow_message(ctx, "cannot load embedded usecmap (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj));
}
}
@@ -127,13 +127,13 @@ pdf_load_system_cmap(fz_context *ctx, char *cmap_name)
cmap = pdf_load_builtin_cmap(ctx, cmap_name);
if (!cmap)
- fz_throw(ctx, "no builtin cmap file: %s", cmap_name);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "no builtin cmap file: %s", cmap_name);
if (cmap->usecmap_name[0] && !cmap->usecmap)
{
usecmap = pdf_load_builtin_cmap(ctx, cmap->usecmap_name);
if (!usecmap)
- fz_throw(ctx, "nu builtin cmap file: %s", cmap->usecmap_name);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "nu builtin cmap file: %s", cmap->usecmap_name);
pdf_set_usecmap(ctx, cmap, usecmap);
}
diff --git a/pdf/pdf_cmap_parse.c b/pdf/pdf_cmap_parse.c
index 85b89939..361c512f 100644
--- a/pdf/pdf_cmap_parse.c
+++ b/pdf/pdf_cmap_parse.c
@@ -67,7 +67,7 @@ pdf_parse_codespace_range(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_
else break;
}
- fz_throw(ctx, "expected string or endcodespacerange");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "expected string or endcodespacerange");
}
static void
@@ -84,19 +84,19 @@ pdf_parse_cid_range(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_lexbuf
return;
else if (tok != PDF_TOK_STRING)
- fz_throw(ctx, "expected string or endcidrange");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "expected string or endcidrange");
lo = pdf_code_from_string(buf->scratch, buf->len);
tok = pdf_lex(file, buf);
if (tok != PDF_TOK_STRING)
- fz_throw(ctx, "expected string");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "expected string");
hi = pdf_code_from_string(buf->scratch, buf->len);
tok = pdf_lex(file, buf);
if (tok != PDF_TOK_INT)
- fz_throw(ctx, "expected integer");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "expected integer");
dst = buf->i;
@@ -118,13 +118,13 @@ pdf_parse_cid_char(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_lexbuf
return;
else if (tok != PDF_TOK_STRING)
- fz_throw(ctx, "expected string or endcidchar");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "expected string or endcidchar");
src = pdf_code_from_string(buf->scratch, buf->len);
tok = pdf_lex(file, buf);
if (tok != PDF_TOK_INT)
- fz_throw(ctx, "expected integer");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "expected integer");
dst = buf->i;
@@ -148,7 +148,7 @@ pdf_parse_bf_range_array(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_l
/* Note: does not handle [ /Name /Name ... ] */
else if (tok != PDF_TOK_STRING)
- fz_throw(ctx, "expected string or ]");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "expected string or ]");
if (buf->len / 2)
{
@@ -177,13 +177,13 @@ pdf_parse_bf_range(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_lexbuf
return;
else if (tok != PDF_TOK_STRING)
- fz_throw(ctx, "expected string or endbfrange");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "expected string or endbfrange");
lo = pdf_code_from_string(buf->scratch, buf->len);
tok = pdf_lex(file, buf);
if (tok != PDF_TOK_STRING)
- fz_throw(ctx, "expected string");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "expected string");
hi = pdf_code_from_string(buf->scratch, buf->len);
if (lo < 0 || lo > 65535 || hi < 0 || hi > 65535 || lo > hi)
@@ -229,7 +229,7 @@ pdf_parse_bf_range(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_lexbuf
else
{
- fz_throw(ctx, "expected string or array or endbfrange");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "expected string or array or endbfrange");
}
}
}
@@ -250,14 +250,14 @@ pdf_parse_bf_char(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_lexbuf *
return;
else if (tok != PDF_TOK_STRING)
- fz_throw(ctx, "expected string or endbfchar");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "expected string or endbfchar");
src = pdf_code_from_string(buf->scratch, buf->len);
tok = pdf_lex(file, buf);
/* Note: does not handle /dstName */
if (tok != PDF_TOK_STRING)
- fz_throw(ctx, "expected string");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "expected string");
if (buf->len / 2)
{
@@ -337,7 +337,7 @@ pdf_load_cmap(fz_context *ctx, fz_stream *file)
fz_catch(ctx)
{
pdf_drop_cmap(ctx, cmap);
- fz_throw(ctx, "syntaxerror in cmap");
+ fz_rethrow_message(ctx, "syntaxerror in cmap");
}
return cmap;
diff --git a/pdf/pdf_colorspace.c b/pdf/pdf_colorspace.c
index fc1ff541..84b3e847 100644
--- a/pdf/pdf_colorspace.c
+++ b/pdf/pdf_colorspace.c
@@ -16,7 +16,7 @@ load_icc_based(pdf_document *xref, pdf_obj *dict)
case 4: return fz_device_cmyk(xref->ctx);
}
- fz_throw(xref->ctx, "syntaxerror: ICCBased must have 1, 3 or 4 components");
+ fz_throw(xref->ctx, FZ_ERROR_GENERIC, "syntaxerror: ICCBased must have 1, 3 or 4 components");
return NULL; /* Stupid MSVC */
}
@@ -111,7 +111,7 @@ load_separation(pdf_document *xref, pdf_obj *array)
n = 1;
if (n > FZ_MAX_COLORS)
- fz_throw(ctx, "too many components in colorspace");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "too many components in colorspace");
base = pdf_load_colorspace(xref, baseobj);
@@ -188,12 +188,12 @@ load_indexed(pdf_document *xref, pdf_obj *array)
}
fz_catch(ctx)
{
- fz_throw(ctx, "cannot open colorspace lookup table (%d 0 R)", pdf_to_num(lookupobj));
+ fz_rethrow_message(ctx, "cannot open colorspace lookup table (%d 0 R)", pdf_to_num(lookupobj));
}
}
else
{
- fz_throw(ctx, "cannot parse colorspace lookup table");
+ fz_rethrow_message(ctx, "cannot parse colorspace lookup table");
}
cs = fz_new_indexed_colorspace(ctx, base, high, lookup);
@@ -216,7 +216,7 @@ pdf_load_colorspace_imp(pdf_document *xref, pdf_obj *obj)
fz_context *ctx = xref->ctx;
if (pdf_obj_marked(obj))
- fz_throw(ctx, "Recursion in colorspace definition");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "Recursion in colorspace definition");
if (pdf_is_name(obj))
{
@@ -236,7 +236,7 @@ pdf_load_colorspace_imp(pdf_document *xref, pdf_obj *obj)
else if (!strcmp(str, "DeviceCMYK"))
return fz_device_cmyk(ctx);
else
- fz_throw(ctx, "unknown colorspace: %s", pdf_to_name(obj));
+ fz_throw(ctx, FZ_ERROR_GENERIC, "unknown colorspace: %s", pdf_to_name(obj));
}
else if (pdf_is_array(obj))
@@ -300,7 +300,7 @@ pdf_load_colorspace_imp(pdf_document *xref, pdf_obj *obj)
cs = pdf_load_colorspace(xref, pobj);
}
else
- fz_throw(ctx, "syntaxerror: unknown colorspace %s", str);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "syntaxerror: unknown colorspace %s", str);
}
fz_always(ctx)
{
@@ -315,7 +315,7 @@ pdf_load_colorspace_imp(pdf_document *xref, pdf_obj *obj)
}
}
- fz_throw(xref->ctx, "syntaxerror: could not parse color space (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj));
+ fz_throw(xref->ctx, FZ_ERROR_GENERIC, "syntaxerror: could not parse color space (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj));
return NULL; /* Stupid MSVC */
}
diff --git a/pdf/pdf_crypt.c b/pdf/pdf_crypt.c
index 9ffce0e1..5128473c 100644
--- a/pdf/pdf_crypt.c
+++ b/pdf/pdf_crypt.c
@@ -60,12 +60,12 @@ pdf_new_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id)
if (!pdf_is_name(obj))
{
pdf_free_crypt(ctx, crypt);
- fz_throw(ctx, "unspecified encryption handler");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "unspecified encryption handler");
}
if (strcmp(pdf_to_name(obj), "Standard") != 0)
{
pdf_free_crypt(ctx, crypt);
- fz_throw(ctx, "unknown encryption handler: '%s'", pdf_to_name(obj));
+ fz_throw(ctx, FZ_ERROR_GENERIC, "unknown encryption handler: '%s'", pdf_to_name(obj));
}
crypt->v = 0;
@@ -75,7 +75,7 @@ pdf_new_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id)
if (crypt->v != 1 && crypt->v != 2 && crypt->v != 4 && crypt->v != 5)
{
pdf_free_crypt(ctx, crypt);
- fz_throw(ctx, "unknown encryption version");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "unknown encryption version");
}
/* Standard security handler (PDF 1.7 table 3.19) */
@@ -96,7 +96,7 @@ pdf_new_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id)
else
{
pdf_free_crypt(ctx, crypt);
- fz_throw(ctx, "encryption dictionary missing version and revision value");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "encryption dictionary missing version and revision value");
}
obj = pdf_dict_gets(dict, "O");
@@ -108,7 +108,7 @@ pdf_new_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id)
else
{
pdf_free_crypt(ctx, crypt);
- fz_throw(ctx, "encryption dictionary missing owner password");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "encryption dictionary missing owner password");
}
obj = pdf_dict_gets(dict, "U");
@@ -125,7 +125,7 @@ pdf_new_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id)
else
{
pdf_free_crypt(ctx, crypt);
- fz_throw(ctx, "encryption dictionary missing user password");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "encryption dictionary missing user password");
}
obj = pdf_dict_gets(dict, "P");
@@ -143,7 +143,7 @@ pdf_new_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id)
if (!pdf_is_string(obj) || pdf_to_str_len(obj) != 32)
{
pdf_free_crypt(ctx, crypt);
- fz_throw(ctx, "encryption dictionary missing owner encryption key");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "encryption dictionary missing owner encryption key");
}
memcpy(crypt->oe, pdf_to_str_buf(obj), 32);
@@ -151,7 +151,7 @@ pdf_new_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id)
if (!pdf_is_string(obj) || pdf_to_str_len(obj) != 32)
{
pdf_free_crypt(ctx, crypt);
- fz_throw(ctx, "encryption dictionary missing user encryption key");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "encryption dictionary missing user encryption key");
}
memcpy(crypt->ue, pdf_to_str_buf(obj), 32);
}
@@ -188,12 +188,12 @@ pdf_new_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id)
if (crypt->length % 8 != 0)
{
pdf_free_crypt(ctx, crypt);
- fz_throw(ctx, "invalid encryption key length");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "invalid encryption key length");
}
if (crypt->length < 0 || crypt->length > 256)
{
pdf_free_crypt(ctx, crypt);
- fz_throw(ctx, "invalid encryption key length");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "invalid encryption key length");
}
}
@@ -240,7 +240,7 @@ pdf_new_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id)
fz_catch(ctx)
{
pdf_free_crypt(ctx, crypt);
- fz_throw(ctx, "cannot parse string crypt filter (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj));
+ fz_rethrow_message(ctx, "cannot parse string crypt filter (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj));
}
/* in crypt revision 4, the crypt filter determines the key length */
@@ -272,7 +272,7 @@ pdf_parse_crypt_filter(fz_context *ctx, pdf_crypt_filter *cf, pdf_crypt *crypt,
int is_stdcf = (!is_identity && (strcmp(name, "StdCF") == 0));
if (!is_identity && !is_stdcf)
- fz_throw(ctx, "Crypt Filter not Identity or StdCF (%d %d R)", pdf_to_num(crypt->cf), pdf_to_gen(crypt->cf));
+ fz_throw(ctx, FZ_ERROR_GENERIC, "Crypt Filter not Identity or StdCF (%d %d R)", pdf_to_num(crypt->cf), pdf_to_gen(crypt->cf));
cf->method = PDF_CRYPT_NONE;
cf->length = crypt->length;
@@ -285,7 +285,7 @@ pdf_parse_crypt_filter(fz_context *ctx, pdf_crypt_filter *cf, pdf_crypt *crypt,
dict = pdf_dict_gets(crypt->cf, name);
if (!pdf_is_dict(dict))
- fz_throw(ctx, "cannot parse crypt filter (%d %d R)", pdf_to_num(crypt->cf), pdf_to_gen(crypt->cf));
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot parse crypt filter (%d %d R)", pdf_to_num(crypt->cf), pdf_to_gen(crypt->cf));
obj = pdf_dict_gets(dict, "CFM");
if (pdf_is_name(obj))
@@ -311,13 +311,13 @@ pdf_parse_crypt_filter(fz_context *ctx, pdf_crypt_filter *cf, pdf_crypt *crypt,
cf->length = cf->length * 8;
if ((cf->length % 8) != 0)
- fz_throw(ctx, "invalid key length: %d", cf->length);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "invalid key length: %d", cf->length);
if ((crypt->r == 1 || crypt->r == 2 || crypt->r == 4) &&
(cf->length < 0 || cf->length > 128))
- fz_throw(ctx, "invalid key length: %d", cf->length);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "invalid key length: %d", cf->length);
if ((crypt->r == 5 || crypt->r == 6) && cf->length != 256)
- fz_throw(ctx, "invalid key length: %d", cf->length);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "invalid key length: %d", cf->length);
}
/*
@@ -439,7 +439,7 @@ pdf_compute_encryption_key_r5(fz_context *ctx, pdf_crypt *crypt, unsigned char *
/* clear password buffer and use it as iv */
memset(buffer + 32, 0, sizeof(buffer) - 32);
if (aes_setkey_dec(&aes, buffer, crypt->length))
- fz_throw(ctx, "AES key init failed (keylen=%d)", crypt->length);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "AES key init failed (keylen=%d)", crypt->length);
aes_crypt_cbc(&aes, AES_DECRYPT, 32, buffer + 32, ownerkey ? crypt->oe : crypt->ue, crypt->key);
}
@@ -484,7 +484,7 @@ pdf_compute_hardened_hash_r6(fz_context *ctx, unsigned char *password, int pwlen
/* Step 3: encrypt data using data block as key and iv */
if (aes_setkey_enc(&aes, block, 128))
- fz_throw(ctx, "AES key init failed (keylen=%d)", 128);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "AES key init failed (keylen=%d)", 128);
aes_crypt_cbc(&aes, AES_ENCRYPT, data_len * 64, block + 16, data, data);
/* Step 4: determine SHA-2 hash size for this round */
@@ -535,7 +535,7 @@ pdf_compute_encryption_key_r6(fz_context *ctx, pdf_crypt *crypt, unsigned char *
memset(iv, 0, sizeof(iv));
if (aes_setkey_dec(&aes, hash, 256))
- fz_throw(ctx, "AES key init failed (keylen=256)");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "AES key init failed (keylen=256)");
aes_crypt_cbc(&aes, AES_DECRYPT, 32, iv,
ownerkey ? crypt->oe : crypt->ue, crypt->key);
}
@@ -901,7 +901,7 @@ pdf_crypt_obj_imp(fz_context *ctx, pdf_crypt *crypt, pdf_obj *obj, unsigned char
fz_aes aes;
memcpy(iv, s, 16);
if (aes_setkey_dec(&aes, key, keylen * 8))
- fz_throw(ctx, "AES key init failed (keylen=%d)", keylen * 8);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "AES key init failed (keylen=%d)", keylen * 8);
aes_crypt_cbc(&aes, AES_DECRYPT, n - 16, iv, s + 16, s);
/* delete space used for iv and padding bytes at end */
if (s[n - 17] < 1 || s[n - 17] > 16)
diff --git a/pdf/pdf_device.c b/pdf/pdf_device.c
index ecd3cd3f..602a778f 100644
--- a/pdf/pdf_device.c
+++ b/pdf/pdf_device.c
@@ -813,6 +813,7 @@ pdf_dev_new_form(pdf_obj **form_ref, pdf_device *pdev, const fz_rect *bbox, int
}
fz_catch(ctx)
{
+ pdf_drop_obj(form);
fz_rethrow(ctx);
}
diff --git a/pdf/pdf_font.c b/pdf/pdf_font.c
index 65589c94..1c2beb7b 100644
--- a/pdf/pdf_font.c
+++ b/pdf/pdf_font.c
@@ -182,7 +182,7 @@ pdf_load_builtin_font(fz_context *ctx, pdf_font_desc *fontdesc, char *fontname)
data = pdf_lookup_builtin_font(fontname, &len);
if (!data)
- fz_throw(ctx, "cannot find builtin font: '%s'", fontname);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find builtin font: '%s'", fontname);
fontdesc->font = fz_new_font_from_memory(ctx, fontname, data, len, 0, 1);
@@ -198,7 +198,7 @@ pdf_load_substitute_font(fz_context *ctx, pdf_font_desc *fontdesc, char *fontnam
data = pdf_lookup_substitute_font(mono, serif, bold, italic, &len);
if (!data)
- fz_throw(ctx, "cannot find substitute font");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find substitute font");
fontdesc->font = fz_new_font_from_memory(ctx, fontname, data, len, 0, 1);
@@ -215,7 +215,7 @@ pdf_load_substitute_cjk_font(fz_context *ctx, pdf_font_desc *fontdesc, char *fon
data = pdf_lookup_substitute_cjk_font(ros, serif, &len);
if (!data)
- fz_throw(ctx, "cannot find builtin CJK font");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find builtin CJK font");
/* a glyph bbox cache is too big for droid sans fallback (51k glyphs!) */
fontdesc->font = fz_new_font_from_memory(ctx, fontname, data, len, 0, 0);
@@ -282,7 +282,7 @@ pdf_load_embedded_font(pdf_document *xref, pdf_font_desc *fontdesc, char *fontna
}
fz_catch(ctx)
{
- fz_throw(ctx, "cannot load font stream (%d %d R)", pdf_to_num(stmref), pdf_to_gen(stmref));
+ fz_rethrow_message(ctx, "cannot load font stream (%d %d R)", pdf_to_num(stmref), pdf_to_gen(stmref));
}
fz_try(ctx)
@@ -292,7 +292,7 @@ pdf_load_embedded_font(pdf_document *xref, pdf_font_desc *fontdesc, char *fontna
fz_catch(ctx)
{
fz_drop_buffer(ctx, buf);
- fz_throw(ctx, "cannot load embedded font (%d %d R)", pdf_to_num(stmref), pdf_to_gen(stmref));
+ fz_rethrow_message(ctx, "cannot load embedded font (%d %d R)", pdf_to_num(stmref), pdf_to_gen(stmref));
}
fontdesc->size += buf->len;
@@ -688,6 +688,7 @@ pdf_load_simple_font(pdf_document *xref, pdf_obj *dict)
}
fz_catch(ctx)
{
+ /* FIXME: TryLater */
fz_warn(ctx, "cannot load ToUnicode CMap");
}
@@ -738,7 +739,7 @@ pdf_load_simple_font(pdf_document *xref, pdf_obj *dict)
if (fontdesc && etable != fontdesc->cid_to_gid)
fz_free(ctx, etable);
pdf_drop_font(ctx, fontdesc);
- fz_throw(ctx, "cannot load simple font (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict));
+ fz_rethrow_message(ctx, "cannot load simple font (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict));
}
return fontdesc;
}
@@ -777,7 +778,7 @@ load_cid_font(pdf_document *xref, pdf_obj *dict, pdf_obj *encoding, pdf_obj *to_
cidinfo = pdf_dict_gets(dict, "CIDSystemInfo");
if (!cidinfo)
- fz_throw(ctx, "cid font is missing info");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cid font is missing info");
obj = pdf_dict_gets(cidinfo, "Registry");
tmplen = fz_mini(sizeof tmpstr - 1, pdf_to_str_len(obj));
@@ -800,7 +801,7 @@ load_cid_font(pdf_document *xref, pdf_obj *dict, pdf_obj *encoding, pdf_obj *to_
descriptor = pdf_dict_gets(dict, "FontDescriptor");
if (!descriptor)
- fz_throw(ctx, "syntaxerror: missing font descriptor");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "syntaxerror: missing font descriptor");
pdf_load_font_descriptor(fontdesc, xref, descriptor, collection, basefont, 1);
face = fontdesc->font->ft_face;
@@ -823,7 +824,7 @@ load_cid_font(pdf_document *xref, pdf_obj *dict, pdf_obj *encoding, pdf_obj *to_
}
else
{
- fz_throw(ctx, "syntaxerror: font missing encoding");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "syntaxerror: font missing encoding");
}
fontdesc->size += pdf_cmap_size(ctx, fontdesc->encoding);
@@ -857,7 +858,7 @@ load_cid_font(pdf_document *xref, pdf_obj *dict, pdf_obj *encoding, pdf_obj *to_
fterr = FT_Select_Charmap(face, ft_encoding_unicode);
if (fterr)
{
- fz_throw(ctx, "fonterror: no unicode cmap when emulating CID font: %s", ft_error_string(fterr));
+ fz_throw(ctx, FZ_ERROR_GENERIC, "fonterror: no unicode cmap when emulating CID font: %s", ft_error_string(fterr));
}
if (!strcmp(collection, "Adobe-CNS1"))
@@ -982,7 +983,7 @@ load_cid_font(pdf_document *xref, pdf_obj *dict, pdf_obj *encoding, pdf_obj *to_
fz_catch(ctx)
{
pdf_drop_font(ctx, fontdesc);
- fz_throw(ctx, "cannot load cid font (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict));
+ fz_rethrow_message(ctx, "cannot load cid font (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict));
}
return fontdesc;
@@ -999,7 +1000,7 @@ pdf_load_type0_font(pdf_document *xref, pdf_obj *dict)
dfonts = pdf_dict_gets(dict, "DescendantFonts");
if (!dfonts)
- fz_throw(xref->ctx, "cid font is missing descendant fonts");
+ fz_throw(xref->ctx, FZ_ERROR_GENERIC, "cid font is missing descendant fonts");
dfont = pdf_array_get(dfonts, 0);
@@ -1012,7 +1013,7 @@ pdf_load_type0_font(pdf_document *xref, pdf_obj *dict)
else if (pdf_is_name(subtype) && !strcmp(pdf_to_name(subtype), "CIDFontType2"))
return load_cid_font(xref, dfont, encoding, to_unicode);
else
- fz_throw(xref->ctx, "syntaxerror: unknown cid font type");
+ fz_throw(xref->ctx, FZ_ERROR_GENERIC, "syntaxerror: unknown cid font type");
return NULL; /* Stupid MSVC */
}
@@ -1056,6 +1057,7 @@ pdf_load_font_descriptor(pdf_font_desc *fontdesc, pdf_document *xref, pdf_obj *d
}
fz_catch(ctx)
{
+ /* FIXME: TryLater */
fz_warn(ctx, "ignored error when loading embedded font; attempting to load system font");
if (origname != fontname && !iscidfont)
pdf_load_builtin_font(ctx, fontdesc, fontname);
diff --git a/pdf/pdf_form.c b/pdf/pdf_form.c
index 9b58c07b..6e1d26ce 100644
--- a/pdf/pdf_form.c
+++ b/pdf/pdf_form.c
@@ -305,7 +305,7 @@ static void get_font_info(pdf_document *doc, pdf_obj *dr, char *da, font_info *f
parse_da(ctx, da, &font_rec->da_rec);
if (font_rec->da_rec.font_name == NULL)
- fz_throw(ctx, "No font name in default appearance");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "No font name in default appearance");
font_rec->font = pdf_load_font(doc, dr, pdf_dict_gets(pdf_dict_gets(dr, "Font"), font_rec->da_rec.font_name), 0);
}
@@ -2602,7 +2602,7 @@ void pdf_field_set_text_color(pdf_document *doc, pdf_obj *field, pdf_obj *col)
}
fz_catch(ctx)
{
- fz_warn(ctx, "%s", ctx->error->message);
+ fz_warn(ctx, "%s", fz_caught_message(ctx));
}
}
diff --git a/pdf/pdf_function.c b/pdf/pdf_function.c
index 368c1415..4771fbfd 100644
--- a/pdf/pdf_function.c
+++ b/pdf/pdf_function.c
@@ -707,7 +707,7 @@ parse_code(pdf_function *func, fz_stream *stream, int *codeptr, pdf_lexbuf *buf)
switch (tok)
{
case PDF_TOK_EOF:
- fz_throw(ctx, "truncated calculator function");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "truncated calculator function");
case PDF_TOK_INT:
resize_code(ctx, func, *codeptr);
@@ -761,12 +761,12 @@ parse_code(pdf_function *func, fz_stream *stream, int *codeptr, pdf_lexbuf *buf)
}
if (tok != PDF_TOK_KEYWORD)
- fz_throw(ctx, "missing keyword in 'if-else' context");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "missing keyword in 'if-else' context");
if (!strcmp(buf->scratch, "if"))
{
if (elseptr >= 0)
- fz_throw(ctx, "too many branches for 'if'");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "too many branches for 'if'");
func->u.p.code[opptr].type = PS_OPERATOR;
func->u.p.code[opptr].u.op = PS_OP_IF;
func->u.p.code[opptr+2].type = PS_BLOCK;
@@ -777,7 +777,7 @@ parse_code(pdf_function *func, fz_stream *stream, int *codeptr, pdf_lexbuf *buf)
else if (!strcmp(buf->scratch, "ifelse"))
{
if (elseptr < 0)
- fz_throw(ctx, "not enough branches for 'ifelse'");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "not enough branches for 'ifelse'");
func->u.p.code[opptr].type = PS_OPERATOR;
func->u.p.code[opptr].u.op = PS_OP_IFELSE;
func->u.p.code[opptr+1].type = PS_BLOCK;
@@ -789,7 +789,7 @@ parse_code(pdf_function *func, fz_stream *stream, int *codeptr, pdf_lexbuf *buf)
}
else
{
- fz_throw(ctx, "unknown keyword in 'if-else' context: '%s'", buf->scratch);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "unknown keyword in 'if-else' context: '%s'", buf->scratch);
}
break;
@@ -816,7 +816,7 @@ parse_code(pdf_function *func, fz_stream *stream, int *codeptr, pdf_lexbuf *buf)
a = b = mid;
}
if (cmp != 0)
- fz_throw(ctx, "unknown operator: '%s'", buf->scratch);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "unknown operator: '%s'", buf->scratch);
resize_code(ctx, func, *codeptr);
func->u.p.code[*codeptr].type = PS_OPERATOR;
@@ -825,7 +825,7 @@ parse_code(pdf_function *func, fz_stream *stream, int *codeptr, pdf_lexbuf *buf)
break;
default:
- fz_throw(ctx, "calculator function syntax error");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "calculator function syntax error");
}
}
}
@@ -852,7 +852,7 @@ load_postscript_func(pdf_function *func, pdf_document *xref, pdf_obj *dict, int
tok = pdf_lex(stream, &buf);
if (tok != PDF_TOK_OPEN_BRACE)
{
- fz_throw(ctx, "stream is not a calculator function");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "stream is not a calculator function");
}
func->u.p.code = NULL;
@@ -868,7 +868,7 @@ load_postscript_func(pdf_function *func, pdf_document *xref, pdf_obj *dict, int
}
fz_catch(ctx)
{
- fz_throw(ctx, "cannot parse calculator function (%d %d R)", num, gen);
+ fz_rethrow_message(ctx, "cannot parse calculator function (%d %d R)", num, gen);
}
func->base.size += func->u.p.cap * sizeof(psobj);
@@ -918,7 +918,7 @@ load_sample_func(pdf_function *func, pdf_document *xref, pdf_obj *dict, int num,
obj = pdf_dict_gets(dict, "Size");
if (pdf_array_len(obj) < func->base.m)
- fz_throw(ctx, "too few sample function dimension sizes");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "too few sample function dimension sizes");
if (pdf_array_len(obj) > func->base.m)
fz_warn(ctx, "too many sample function dimension sizes");
for (i = 0; i < func->base.m; i++)
@@ -977,7 +977,7 @@ load_sample_func(pdf_function *func, pdf_document *xref, pdf_obj *dict, int num,
samplecount *= func->u.sa.size[i];
if (samplecount > MAX_SAMPLE_FUNCTION_SIZE)
- fz_throw(ctx, "sample function too large");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "sample function too large");
func->u.sa.samples = fz_malloc_array(ctx, samplecount, sizeof(float));
func->base.size += samplecount * sizeof(float);
@@ -993,7 +993,7 @@ load_sample_func(pdf_function *func, pdf_document *xref, pdf_obj *dict, int num,
if (fz_is_eof_bits(stream))
{
fz_close(stream);
- fz_throw(ctx, "truncated sample function stream");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "truncated sample function stream");
}
switch (bps)
@@ -1023,7 +1023,7 @@ load_sample_func(pdf_function *func, pdf_document *xref, pdf_obj *dict, int num,
break;
default:
fz_close(stream);
- fz_throw(ctx, "sample stream bit depth %d unsupported", bps);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "sample stream bit depth %d unsupported", bps);
}
func->u.sa.samples[i] = s;
@@ -1227,7 +1227,7 @@ load_stitching_func(pdf_function *func, pdf_document *xref, pdf_obj *dict)
obj = pdf_dict_gets(dict, "Functions");
if (!pdf_is_array(obj))
- fz_throw(ctx, "stitching function has no input functions");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "stitching function has no input functions");
fz_try(ctx)
{
@@ -1264,10 +1264,10 @@ load_stitching_func(pdf_function *func, pdf_document *xref, pdf_obj *dict)
obj = pdf_dict_gets(dict, "Bounds");
if (!pdf_is_array(obj))
- fz_throw(ctx, "stitching function has no bounds");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "stitching function has no bounds");
{
if (pdf_array_len(obj) < k - 1)
- fz_throw(ctx, "too few subfunction boundaries");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "too few subfunction boundaries");
if (pdf_array_len(obj) > k)
fz_warn(ctx, "too many subfunction boundaries");
@@ -1276,7 +1276,7 @@ load_stitching_func(pdf_function *func, pdf_document *xref, pdf_obj *dict)
num = pdf_array_get(obj, i);
func->u.st.bounds[i] = pdf_to_real(num);
if (i && func->u.st.bounds[i - 1] > func->u.st.bounds[i])
- fz_throw(ctx, "subfunction %d boundary out of range", i);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "subfunction %d boundary out of range", i);
}
if (k > 1 && (func->domain[0][0] > func->u.st.bounds[0] ||
@@ -1624,7 +1624,7 @@ pdf_load_function(pdf_document *xref, pdf_obj *dict, int in, int out)
int i;
if (pdf_obj_marked(dict))
- fz_throw(ctx, "Recursion in function definition");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "Recursion in function definition");
if ((func = pdf_find_item(ctx, pdf_free_function_imp, dict)))
{
@@ -1696,7 +1696,7 @@ pdf_load_function(pdf_document *xref, pdf_obj *dict, int in, int out)
default:
fz_free(ctx, func);
- fz_throw(ctx, "unknown function type (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict));
+ fz_throw(ctx, FZ_ERROR_GENERIC, "unknown function type (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict));
}
pdf_store_item(ctx, dict, func, func->base.size);
@@ -1705,13 +1705,13 @@ pdf_load_function(pdf_document *xref, pdf_obj *dict, int in, int out)
{
int type = func->type;
fz_drop_function(ctx, (fz_function *)func);
- fz_throw(ctx, "cannot load %s function (%d %d R)",
- type == SAMPLE ? "sampled" :
- type == EXPONENTIAL ? "exponential" :
- type == STITCHING ? "stitching" :
- type == POSTSCRIPT ? "calculator" :
- "unknown",
- pdf_to_num(dict), pdf_to_gen(dict));
+ fz_rethrow_message(ctx, "cannot load %s function (%d %d R)",
+ type == SAMPLE ? "sampled" :
+ type == EXPONENTIAL ? "exponential" :
+ type == STITCHING ? "stitching" :
+ type == POSTSCRIPT ? "calculator" :
+ "unknown",
+ pdf_to_num(dict), pdf_to_gen(dict));
}
return (fz_function *)func;
diff --git a/pdf/pdf_image.c b/pdf/pdf_image.c
index a75e6a73..719841d5 100644
--- a/pdf/pdf_image.c
+++ b/pdf/pdf_image.c
@@ -37,7 +37,7 @@ pdf_load_image_imp(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict, fz_stream *c
{
fz_pixmap *mask_pixmap;
if (image->n != 2)
- fz_throw(ctx, "soft mask must be grayscale");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "soft mask must be grayscale");
mask_pixmap = fz_alpha_from_gray(ctx, image->tile, 1);
fz_drop_pixmap(ctx, image->tile);
image->tile = mask_pixmap;
@@ -61,17 +61,17 @@ pdf_load_image_imp(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict, fz_stream *c
bpc = 1;
if (w <= 0)
- fz_throw(ctx, "image width is zero (or less)");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "image width is zero (or less)");
if (h <= 0)
- fz_throw(ctx, "image height is zero (or less)");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "image height is zero (or less)");
if (bpc <= 0)
- fz_throw(ctx, "image depth is zero (or less)");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "image depth is zero (or less)");
if (bpc > 16)
- fz_throw(ctx, "image depth is too large: %d", bpc);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "image depth is too large: %d", bpc);
if (w > (1 << 16))
- fz_throw(ctx, "image is too wide");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "image is too wide");
if (h > (1 << 16))
- fz_throw(ctx, "image is too high");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "image is too high");
obj = pdf_dict_getsa(dict, "ColorSpace", "CS");
if (obj && !imagemask && !forcemask)
diff --git a/pdf/pdf_interpret.c b/pdf/pdf_interpret.c
index ab883021..43a6d466 100644
--- a/pdf/pdf_interpret.c
+++ b/pdf/pdf_interpret.c
@@ -372,6 +372,7 @@ begin_softmask(pdf_csi * csi, softmask_save *save)
}
fz_catch(ctx)
{
+ /* FIXME: TryLater */
/* FIXME: Ignore error - nasty, but if we throw from
* here the clip stack would be messed up. */
if (csi->cookie)
@@ -1187,6 +1188,7 @@ pdf_grestore(pdf_csi *csi)
}
fz_catch(ctx)
{
+ /* FIXME: TryLater */
/* Silently swallow the problem */
}
clip_depth--;
@@ -1472,7 +1474,7 @@ pdf_show_pattern(pdf_csi *csi, pdf_pattern *pat, pdf_gstate *pat_gstate, const f
}
fz_catch(ctx)
{
- fz_throw(ctx, "cannot render pattern tile");
+ fz_rethrow_message(ctx, "cannot render pattern tile");
}
}
}
@@ -1619,11 +1621,11 @@ pdf_run_extgstate(pdf_csi *csi, pdf_obj *rdb, pdf_obj *extgstate)
gstate->font = pdf_load_font(csi->xref, rdb, font, csi->nested_depth);
if (!gstate->font)
- fz_throw(ctx, "cannot find font in store");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find font in store");
gstate->size = pdf_to_real(pdf_array_get(val, 1));
}
else
- fz_throw(ctx, "malformed /Font dictionary");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "malformed /Font dictionary");
}
else if (!strcmp(s, "LC"))
@@ -1666,7 +1668,7 @@ pdf_run_extgstate(pdf_csi *csi, pdf_obj *rdb, pdf_obj *extgstate)
gstate->stroke_state->dash_phase = pdf_to_real(pdf_array_get(val, 1));
}
else
- fz_throw(ctx, "malformed /D");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "malformed /D");
}
else if (!strcmp(s, "CA"))
@@ -1697,7 +1699,7 @@ pdf_run_extgstate(pdf_csi *csi, pdf_obj *rdb, pdf_obj *extgstate)
group = pdf_dict_gets(val, "G");
if (!group)
- fz_throw(ctx, "cannot load softmask xobject (%d %d R)", pdf_to_num(val), pdf_to_gen(val));
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot load softmask xobject (%d %d R)", pdf_to_num(val), pdf_to_gen(val));
xobj = pdf_load_xobject(csi->xref, group);
colorspace = xobj->colorspace;
@@ -1825,7 +1827,7 @@ static void pdf_run_BI(pdf_csi *csi, pdf_obj *rdb, fz_stream *file)
ch = fz_read_byte(file);
ch = fz_read_byte(file);
if (ch != 'I')
- fz_throw(ctx, "syntax error after inline image");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "syntax error after inline image");
}
static void pdf_run_B(pdf_csi *csi)
@@ -1883,10 +1885,10 @@ static void pdf_run_cs_imp(pdf_csi *csi, pdf_obj *rdb, int what)
{
dict = pdf_dict_gets(rdb, "ColorSpace");
if (!dict)
- fz_throw(ctx, "cannot find ColorSpace dictionary");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find ColorSpace dictionary");
obj = pdf_dict_gets(dict, csi->name);
if (!obj)
- fz_throw(ctx, "cannot find colorspace resource '%s'", csi->name);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find colorspace resource '%s'", csi->name);
colorspace = pdf_load_colorspace(csi->xref, obj);
}
@@ -1923,15 +1925,15 @@ static void pdf_run_Do(pdf_csi *csi, pdf_obj *rdb)
dict = pdf_dict_gets(rdb, "XObject");
if (!dict)
- fz_throw(ctx, "cannot find XObject dictionary when looking for: '%s'", csi->name);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find XObject dictionary when looking for: '%s'", csi->name);
obj = pdf_dict_gets(dict, csi->name);
if (!obj)
- fz_throw(ctx, "cannot find xobject resource: '%s'", csi->name);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find xobject resource: '%s'", csi->name);
subtype = pdf_dict_gets(obj, "Subtype");
if (!pdf_is_name(subtype))
- fz_throw(ctx, "no XObject subtype specified");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "no XObject subtype specified");
if (pdf_is_hidden_ocg(pdf_dict_gets(obj, "OC"), csi, rdb))
return;
@@ -1959,7 +1961,7 @@ static void pdf_run_Do(pdf_csi *csi, pdf_obj *rdb)
}
fz_catch(ctx)
{
- fz_throw(ctx, "cannot draw xobject (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj));
+ fz_rethrow_message(ctx, "cannot draw xobject (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj));
}
}
@@ -1991,7 +1993,7 @@ static void pdf_run_Do(pdf_csi *csi, pdf_obj *rdb)
else
{
- fz_throw(ctx, "unknown XObject subtype: '%s'", pdf_to_name(subtype));
+ fz_throw(ctx, FZ_ERROR_GENERIC, "unknown XObject subtype: '%s'", pdf_to_name(subtype));
}
}
@@ -2086,7 +2088,7 @@ static void pdf_run_SC_imp(pdf_csi *csi, pdf_obj *rdb, int what, pdf_material *m
switch (kind)
{
case PDF_MAT_NONE:
- fz_throw(ctx, "cannot set color in mask objects");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot set color in mask objects");
case PDF_MAT_COLOR:
pdf_set_color(csi, what, csi->stack);
@@ -2095,11 +2097,11 @@ static void pdf_run_SC_imp(pdf_csi *csi, pdf_obj *rdb, int what, pdf_material *m
case PDF_MAT_PATTERN:
dict = pdf_dict_gets(rdb, "Pattern");
if (!dict)
- fz_throw(ctx, "cannot find Pattern dictionary");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find Pattern dictionary");
obj = pdf_dict_gets(dict, csi->name);
if (!obj)
- fz_throw(ctx, "cannot find pattern resource '%s'", csi->name);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find pattern resource '%s'", csi->name);
patterntype = pdf_dict_gets(obj, "PatternType");
@@ -2119,12 +2121,12 @@ static void pdf_run_SC_imp(pdf_csi *csi, pdf_obj *rdb, int what, pdf_material *m
}
else
{
- fz_throw(ctx, "unknown pattern type: %d", pdf_to_int(patterntype));
+ fz_throw(ctx, FZ_ERROR_GENERIC, "unknown pattern type: %d", pdf_to_int(patterntype));
}
break;
case PDF_MAT_SHADE:
- fz_throw(ctx, "cannot set color in shade objects");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot set color in shade objects");
}
mat->gstate_num = csi->gparent;
}
@@ -2183,11 +2185,11 @@ static void pdf_run_Tf(pdf_csi *csi, pdf_obj *rdb)
dict = pdf_dict_gets(rdb, "Font");
if (!dict)
- fz_throw(ctx, "cannot find Font dictionary");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find Font dictionary");
obj = pdf_dict_gets(dict, csi->name);
if (!obj)
- fz_throw(ctx, "cannot find font resource: '%s'", csi->name);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find font resource: '%s'", csi->name);
gstate->font = pdf_load_font(csi->xref, rdb, obj, csi->nested_depth);
}
@@ -2365,11 +2367,11 @@ static void pdf_run_gs(pdf_csi *csi, pdf_obj *rdb)
dict = pdf_dict_gets(rdb, "ExtGState");
if (!dict)
- fz_throw(ctx, "cannot find ExtGState dictionary");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find ExtGState dictionary");
obj = pdf_dict_gets(dict, csi->name);
if (!obj)
- fz_throw(ctx, "cannot find extgstate resource '%s'", csi->name);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find extgstate resource '%s'", csi->name);
pdf_run_extgstate(csi, rdb, obj);
}
@@ -2466,11 +2468,11 @@ static void pdf_run_sh(pdf_csi *csi, pdf_obj *rdb)
dict = pdf_dict_gets(rdb, "Shading");
if (!dict)
- fz_throw(ctx, "cannot find shading dictionary");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find shading dictionary");
obj = pdf_dict_gets(dict, csi->name);
if (!obj)
- fz_throw(ctx, "cannot find shading resource: '%s'", csi->name);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find shading resource: '%s'", csi->name);
if ((csi->dev->hints & FZ_IGNORE_SHADE) == 0)
{
@@ -2593,7 +2595,7 @@ pdf_run_keyword(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, char *buf)
}
fz_catch(ctx)
{
- fz_throw(ctx, "cannot draw xobject/image");
+ fz_rethrow_message(ctx, "cannot draw xobject/image");
}
break;
case C('E','M','C'): pdf_run_EMC(csi); break;
@@ -2623,7 +2625,7 @@ pdf_run_keyword(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, char *buf)
}
fz_catch(ctx)
{
- fz_throw(ctx, "cannot set font");
+ fz_rethrow_message(ctx, "cannot set font");
}
break;
case B('T','j'): pdf_run_Tj(csi); break;
@@ -2652,7 +2654,7 @@ pdf_run_keyword(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, char *buf)
}
fz_catch(ctx)
{
- fz_throw(ctx, "cannot set graphics state");
+ fz_rethrow_message(ctx, "cannot set graphics state");
}
break;
case A('h'): pdf_run_h(csi); break;
@@ -2676,7 +2678,7 @@ pdf_run_keyword(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, char *buf)
}
fz_catch(ctx)
{
- fz_throw(ctx, "cannot draw shading");
+ fz_rethrow_message(ctx, "cannot draw shading");
}
break;
case A('v'): pdf_run_v(csi); break;
@@ -2758,12 +2760,12 @@ pdf_run_stream(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, pdf_lexbuf *buf)
if (!strcmp(buf->scratch, "Tw") || !strcmp(buf->scratch, "Tc"))
fz_warn(ctx, "ignoring keyword '%s' inside array", buf->scratch);
else
- fz_throw(ctx, "syntax error in array");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "syntax error in array");
}
else if (tok == PDF_TOK_EOF)
break;
else
- fz_throw(ctx, "syntax error in array");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "syntax error in array");
}
else switch (tok)
@@ -2808,7 +2810,7 @@ pdf_run_stream(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, pdf_lexbuf *buf)
csi->top ++;
}
else
- fz_throw(ctx, "stack overflow");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "stack overflow");
break;
case PDF_TOK_REAL:
@@ -2817,7 +2819,7 @@ pdf_run_stream(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, pdf_lexbuf *buf)
csi->top ++;
}
else
- fz_throw(ctx, "stack overflow");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "stack overflow");
break;
case PDF_TOK_STRING:
@@ -2846,13 +2848,14 @@ pdf_run_stream(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, pdf_lexbuf *buf)
break;
default:
- fz_throw(ctx, "syntax error in content stream");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "syntax error in content stream");
}
}
while (tok != PDF_TOK_EOF);
}
fz_catch(ctx)
{
+ /* FIXME: TryLater */
/* Swallow the error */
if (csi->cookie)
csi->cookie->errors++;
@@ -2898,6 +2901,7 @@ pdf_run_contents_stream(pdf_csi *csi, pdf_obj *rdb, fz_stream *file)
}
fz_catch(ctx)
{
+ /* FIXME: TryLater */
fz_warn(ctx, "Content stream parsing error - rendering truncated");
}
while (csi->gtop > csi->gbot)
@@ -2986,7 +2990,7 @@ static void pdf_run_page_contents_with_usage(pdf_document *xref, pdf_page *page,
}
fz_catch(ctx)
{
- fz_throw(ctx, "cannot parse page content stream");
+ fz_rethrow_message(ctx, "cannot parse page content stream");
}
if (page->transparency)
@@ -3034,7 +3038,7 @@ static void pdf_run_annot_with_usage(pdf_document *xref, pdf_page *page, pdf_ann
while (csi->gtop > 0)
pdf_grestore(csi);
pdf_free_csi(csi);
- fz_throw(ctx, "cannot parse annotation appearance stream");
+ fz_rethrow_message(ctx, "cannot parse annotation appearance stream");
}
}
pdf_free_csi(csi);
@@ -3093,7 +3097,7 @@ pdf_run_glyph(pdf_document *xref, pdf_obj *resources, fz_buffer *contents, fz_de
fz_try(ctx)
{
if (nested_depth > 10)
- fz_throw(ctx, "Too many nestings of Type3 glyphs");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "Too many nestings of Type3 glyphs");
pdf_run_contents_buffer(csi, resources, contents);
}
fz_always(ctx)
@@ -3102,6 +3106,6 @@ pdf_run_glyph(pdf_document *xref, pdf_obj *resources, fz_buffer *contents, fz_de
}
fz_catch(ctx)
{
- fz_throw(ctx, "cannot parse glyph content stream");
+ fz_rethrow_message(ctx, "cannot parse glyph content stream");
}
}
diff --git a/pdf/pdf_js.c b/pdf/pdf_js.c
index e0bdc755..4a2313f1 100644
--- a/pdf/pdf_js.c
+++ b/pdf/pdf_js.c
@@ -493,7 +493,8 @@ static pdf_jsimp_obj *doc_getField(void *jsctx, void *obj, int argc, pdf_jsimp_o
}
fz_catch(ctx)
{
- fz_warn(ctx, "doc_getField failed: %s", ctx->error->message);
+ /* FIXME: TryLater ? */
+ fz_warn(ctx, "doc_getField failed: %s", fz_caught_message(ctx));
dict = NULL;
}
@@ -591,7 +592,7 @@ static pdf_jsimp_obj *doc_resetForm(void *jsctx, void *obj, int argc, pdf_jsimp_
}
fz_catch(ctx)
{
- fz_warn(ctx, "doc_resetForm failed: %s", ctx->error->message);
+ fz_warn(ctx, "doc_resetForm failed: %s", fz_caught_message(ctx));
}
return NULL;
@@ -832,7 +833,8 @@ void pdf_js_load_document_level(pdf_js *js)
}
fz_catch(ctx)
{
- fz_warn(ctx, "Warning: %s", ctx->error->message);
+ /* FIXME: TryLater ? */
+ fz_warn(ctx, "Warning: %s", fz_caught_message(ctx));
}
}
}
diff --git a/pdf/pdf_jsimp_cpp.c b/pdf/pdf_jsimp_cpp.c
index 10fd835b..59cc4dd9 100644
--- a/pdf/pdf_jsimp_cpp.c
+++ b/pdf/pdf_jsimp_cpp.c
@@ -10,7 +10,7 @@ pdf_jsimp *pdf_new_jsimp(fz_context *ctx, void *jsctx)
pdf_jsimp *jsi = NULL;
const char *err = pdf_new_jsimp_cpp(ctx, jsctx, &jsi);
if (err != NULL)
- fz_throw(ctx, "%s", err);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "%s", err);
return jsi;
}
@@ -31,7 +31,7 @@ pdf_jsimp_type *pdf_jsimp_new_type(pdf_jsimp *imp, pdf_jsimp_dtr *dtr)
pdf_jsimp_type *type = NULL;
const char *err = pdf_jsimp_new_type_cpp(imp, dtr, &type);
if (err != NULL)
- fz_throw(pdf_jsimp_ctx_cpp(imp), "%s", err);
+ fz_throw(pdf_jsimp_ctx_cpp(imp), FZ_ERROR_GENERIC, "%s", err);
return type;
}
@@ -47,21 +47,21 @@ void pdf_jsimp_addmethod(pdf_jsimp *imp, pdf_jsimp_type *type, char *name, pdf_j
{
const char *err = pdf_jsimp_addmethod_cpp(imp, type, name, meth);
if (err != NULL)
- fz_throw(pdf_jsimp_ctx_cpp(imp), "%s", err);
+ fz_throw(pdf_jsimp_ctx_cpp(imp), FZ_ERROR_GENERIC, "%s", err);
}
void pdf_jsimp_addproperty(pdf_jsimp *imp, pdf_jsimp_type *type, char *name, pdf_jsimp_getter *get, pdf_jsimp_setter *set)
{
const char *err = pdf_jsimp_addproperty_cpp(imp, type, name, get, set);
if (err != NULL)
- fz_throw(pdf_jsimp_ctx_cpp(imp), "%s", err);
+ fz_throw(pdf_jsimp_ctx_cpp(imp), FZ_ERROR_GENERIC, "%s", err);
}
void pdf_jsimp_set_global_type(pdf_jsimp *imp, pdf_jsimp_type *type)
{
const char *err = pdf_jsimp_set_global_type_cpp(imp, type);
if (err != NULL)
- fz_throw(pdf_jsimp_ctx_cpp(imp), "%s", err);
+ fz_throw(pdf_jsimp_ctx_cpp(imp), FZ_ERROR_GENERIC, "%s", err);
}
pdf_jsimp_obj *pdf_jsimp_new_obj(pdf_jsimp *imp, pdf_jsimp_type *type, void *natobj)
@@ -69,7 +69,7 @@ pdf_jsimp_obj *pdf_jsimp_new_obj(pdf_jsimp *imp, pdf_jsimp_type *type, void *nat
pdf_jsimp_obj *obj = NULL;
const char *err = pdf_jsimp_new_obj_cpp(imp, type, natobj, &obj);
if (err != NULL)
- fz_throw(pdf_jsimp_ctx_cpp(imp), "%s", err);
+ fz_throw(pdf_jsimp_ctx_cpp(imp), FZ_ERROR_GENERIC, "%s", err);
return obj;
}
@@ -86,7 +86,7 @@ int pdf_jsimp_to_type(pdf_jsimp *imp, pdf_jsimp_obj *obj)
int type = 0;
const char *err = pdf_jsimp_to_type_cpp(imp, obj, &type);
if (err != NULL)
- fz_throw(pdf_jsimp_ctx_cpp(imp), "%s", err);
+ fz_throw(pdf_jsimp_ctx_cpp(imp), FZ_ERROR_GENERIC, "%s", err);
return type;
}
@@ -96,7 +96,7 @@ pdf_jsimp_obj *pdf_jsimp_from_string(pdf_jsimp *imp, char *str)
pdf_jsimp_obj *obj = NULL;
const char *err = pdf_jsimp_from_string_cpp(imp, str, &obj);
if (err != NULL)
- fz_throw(pdf_jsimp_ctx_cpp(imp), "%s", err);
+ fz_throw(pdf_jsimp_ctx_cpp(imp), FZ_ERROR_GENERIC, "%s", err);
return obj;
}
@@ -106,7 +106,7 @@ char *pdf_jsimp_to_string(pdf_jsimp *imp, pdf_jsimp_obj *obj)
char *str = NULL;
const char *err = pdf_jsimp_to_string_cpp(imp, obj, &str);
if (err != NULL)
- fz_throw(pdf_jsimp_ctx_cpp(imp), "%s", err);
+ fz_throw(pdf_jsimp_ctx_cpp(imp), FZ_ERROR_GENERIC, "%s", err);
return str;
}
@@ -116,7 +116,7 @@ pdf_jsimp_obj *pdf_jsimp_from_number(pdf_jsimp *imp, double num)
pdf_jsimp_obj *obj = NULL;
const char *err = pdf_jsimp_from_number_cpp(imp, num, &obj);
if (err != NULL)
- fz_throw(pdf_jsimp_ctx_cpp(imp), "%s", err);
+ fz_throw(pdf_jsimp_ctx_cpp(imp), FZ_ERROR_GENERIC, "%s", err);
return obj;
}
@@ -126,7 +126,7 @@ double pdf_jsimp_to_number(pdf_jsimp *imp, pdf_jsimp_obj *obj)
double num;
const char *err = pdf_jsimp_to_number_cpp(imp, obj, &num);
if (err != NULL)
- fz_throw(pdf_jsimp_ctx_cpp(imp), "%s", err);
+ fz_throw(pdf_jsimp_ctx_cpp(imp), FZ_ERROR_GENERIC, "%s", err);
return num;
}
@@ -136,7 +136,7 @@ int pdf_jsimp_array_len(pdf_jsimp *imp, pdf_jsimp_obj *obj)
int len = 0;
const char *err = pdf_jsimp_array_len_cpp(imp, obj, &len);
if (err != NULL)
- fz_throw(pdf_jsimp_ctx_cpp(imp), "%s", err);
+ fz_throw(pdf_jsimp_ctx_cpp(imp), FZ_ERROR_GENERIC, "%s", err);
return len;
}
@@ -146,7 +146,7 @@ pdf_jsimp_obj *pdf_jsimp_array_item(pdf_jsimp *imp, pdf_jsimp_obj *obj, int i)
pdf_jsimp_obj *item = NULL;
const char *err = pdf_jsimp_array_item_cpp(imp, obj, i, &item);
if (err != NULL)
- fz_throw(pdf_jsimp_ctx_cpp(imp), "%s", err);
+ fz_throw(pdf_jsimp_ctx_cpp(imp), FZ_ERROR_GENERIC, "%s", err);
return item;
}
@@ -156,7 +156,7 @@ pdf_jsimp_obj *pdf_jsimp_property(pdf_jsimp *imp, pdf_jsimp_obj *obj, char *prop
pdf_jsimp_obj *pobj = NULL;
const char *err = pdf_jsimp_property_cpp(imp, obj, prop, &pobj);
if (err != NULL)
- fz_throw(pdf_jsimp_ctx_cpp(imp), "%s", err);
+ fz_throw(pdf_jsimp_ctx_cpp(imp), FZ_ERROR_GENERIC, "%s", err);
return pobj;
}
@@ -165,14 +165,14 @@ void pdf_jsimp_execute(pdf_jsimp *imp, char *code)
{
const char *err = pdf_jsimp_execute_cpp(imp, code);
if (err != NULL)
- fz_throw(pdf_jsimp_ctx_cpp(imp), "%s", err);
+ fz_throw(pdf_jsimp_ctx_cpp(imp), FZ_ERROR_GENERIC, "%s", err);
}
void pdf_jsimp_execute_count(pdf_jsimp *imp, char *code, int count)
{
const char *err = pdf_jsimp_execute_count_cpp(imp, code, count);
if (err != NULL)
- fz_throw(pdf_jsimp_ctx_cpp(imp), "%s", err);
+ fz_throw(pdf_jsimp_ctx_cpp(imp), FZ_ERROR_GENERIC, "%s", err);
}
pdf_jsimp_obj *pdf_jsimp_call_method(pdf_jsimp *imp, pdf_jsimp_method *meth, void *jsctx, void *obj, int argc, pdf_jsimp_obj *args[])
{
@@ -186,7 +186,7 @@ pdf_jsimp_obj *pdf_jsimp_call_method(pdf_jsimp *imp, pdf_jsimp_method *meth, voi
fz_catch(ctx)
{
res = NULL;
- fz_warn(ctx, "%s", ctx->error->message);
+ fz_warn(ctx, "%s", fz_caught_message(ctx));
}
return res;
@@ -204,7 +204,7 @@ pdf_jsimp_obj *pdf_jsimp_call_getter(pdf_jsimp *imp, pdf_jsimp_getter *get, void
fz_catch(ctx)
{
res = NULL;
- fz_warn(ctx, "%s", ctx->error->message);
+ fz_warn(ctx, "%s", fz_caught_message(ctx));
}
return res;
@@ -220,6 +220,6 @@ void pdf_jsimp_call_setter(pdf_jsimp *imp, pdf_jsimp_setter *set, void *jsctx, v
}
fz_catch(ctx)
{
- fz_warn(ctx, "%s", ctx->error->message);
+ fz_warn(ctx, "%s", fz_caught_message(ctx));
}
}
diff --git a/pdf/pdf_object.c b/pdf/pdf_object.c
index c07f4bef..8e5cf419 100644
--- a/pdf/pdf_object.c
+++ b/pdf/pdf_object.c
@@ -867,7 +867,7 @@ pdf_dict_getp(pdf_obj *obj, const char *keys)
char *k, *e;
if (strlen(keys)+1 > 256)
- fz_throw(obj->ctx, "buffer overflow in pdf_dict_getp");
+ fz_throw(obj->ctx, FZ_ERROR_GENERIC, "buffer overflow in pdf_dict_getp");
strcpy(buf, keys);
@@ -1021,7 +1021,7 @@ pdf_dict_putp(pdf_obj *obj, const char *keys, pdf_obj *val)
pdf_obj *cobj = NULL;
if (strlen(keys)+1 > 256)
- fz_throw(obj->ctx, "buffer overflow in pdf_dict_getp");
+ fz_throw(obj->ctx, FZ_ERROR_GENERIC, "buffer overflow in pdf_dict_getp");
strcpy(buf, keys);
@@ -1227,6 +1227,7 @@ pdf_obj *pdf_new_obj_from_str(fz_context *ctx, const char *src)
}
fz_catch(ctx)
{
+ /* FIXME: TryLater */
return NULL;
}
diff --git a/pdf/pdf_page.c b/pdf/pdf_page.c
index df75ff51..8a12b67b 100644
--- a/pdf/pdf_page.c
+++ b/pdf/pdf_page.c
@@ -161,9 +161,9 @@ pdf_load_page_tree(pdf_document *xref)
count = pdf_dict_gets(pages, "Count");
if (!pdf_is_dict(pages))
- fz_throw(ctx, "missing page tree");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "missing page tree");
if (!pdf_is_int(count) || pdf_to_int(count) < 0)
- fz_throw(ctx, "missing page count");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "missing page count");
xref->page_cap = pdf_to_int(count);
xref->page_len = 0;
@@ -343,7 +343,7 @@ pdf_load_page(pdf_document *xref, int number)
pdf_load_page_tree(xref);
if (number < 0 || number >= xref->page_len)
- fz_throw(ctx, "cannot find page %d", number + 1);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find page %d", number + 1);
pageobj = xref->page_objs[number];
pageref = xref->page_refs[number];
@@ -440,7 +440,7 @@ pdf_load_page(pdf_document *xref, int number)
fz_catch(ctx)
{
pdf_free_page(xref, page);
- fz_throw(ctx, "cannot load page %d contents (%d 0 R)", number + 1, pdf_to_num(pageref));
+ fz_rethrow_message(ctx, "cannot load page %d contents (%d 0 R)", number + 1, pdf_to_num(pageref));
}
return page;
diff --git a/pdf/pdf_parse.c b/pdf/pdf_parse.c
index b50e1094..18ab3113 100644
--- a/pdf/pdf_parse.c
+++ b/pdf/pdf_parse.c
@@ -292,7 +292,7 @@ pdf_parse_array(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf)
case PDF_TOK_R:
if (n != 2)
- fz_throw(ctx, "cannot parse indirect reference in array");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot parse indirect reference in array");
obj = pdf_new_indirect(ctx, a, b, xref);
pdf_array_push(ary, obj);
pdf_drop_obj(obj);
@@ -352,7 +352,7 @@ pdf_parse_array(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf)
break;
default:
- fz_throw(ctx, "cannot parse token in array");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot parse token in array");
}
}
end:
@@ -362,7 +362,7 @@ end:
{
pdf_drop_obj(obj);
pdf_drop_obj(ary);
- fz_throw(ctx, "cannot parse array");
+ fz_rethrow_message(ctx, "cannot parse array");
}
return op;
}
@@ -396,7 +396,7 @@ pdf_parse_dict(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf)
break;
if (tok != PDF_TOK_NAME)
- fz_throw(ctx, "invalid key in dict");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "invalid key in dict");
key = pdf_new_name(ctx, buf->scratch);
@@ -444,10 +444,10 @@ pdf_parse_dict(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf)
break;
}
}
- fz_throw(ctx, "invalid indirect reference in dict");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "invalid indirect reference in dict");
default:
- fz_throw(ctx, "unknown token in dict");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "unknown token in dict");
}
pdf_dict_put(dict, key, val);
@@ -462,7 +462,7 @@ pdf_parse_dict(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf)
pdf_drop_obj(dict);
pdf_drop_obj(key);
pdf_drop_obj(val);
- fz_throw(ctx, "cannot parse dict");
+ fz_rethrow_message(ctx, "cannot parse dict");
}
return dict;
}
@@ -488,7 +488,7 @@ pdf_parse_stm_obj(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf)
case PDF_TOK_FALSE: return pdf_new_bool(ctx, 0); break;
case PDF_TOK_NULL: return pdf_new_null(ctx); break;
case PDF_TOK_INT: return pdf_new_int(ctx, buf->i); break;
- default: fz_throw(ctx, "unknown token in object stream");
+ default: fz_throw(ctx, FZ_ERROR_GENERIC, "unknown token in object stream");
}
return NULL; /* Stupid MSVC */
}
@@ -508,17 +508,17 @@ pdf_parse_ind_obj(pdf_document *xref,
tok = pdf_lex(file, buf);
if (tok != PDF_TOK_INT)
- fz_throw(ctx, "expected object number");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "expected object number");
num = buf->i;
tok = pdf_lex(file, buf);
if (tok != PDF_TOK_INT)
- fz_throw(ctx, "expected generation number (%d ? obj)", num);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "expected generation number (%d ? obj)", num);
gen = buf->i;
tok = pdf_lex(file, buf);
if (tok != PDF_TOK_OBJ)
- fz_throw(ctx, "expected 'obj' keyword (%d %d ?)", num, gen);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "expected 'obj' keyword (%d %d ?)", num, gen);
tok = pdf_lex(file, buf);
@@ -558,14 +558,14 @@ pdf_parse_ind_obj(pdf_document *xref,
break;
}
}
- fz_throw(ctx, "expected 'R' keyword (%d %d R)", num, gen);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "expected 'R' keyword (%d %d R)", num, gen);
case PDF_TOK_ENDOBJ:
obj = pdf_new_null(ctx);
goto skip;
default:
- fz_throw(ctx, "syntax error in object (%d %d R)", num, gen);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "syntax error in object (%d %d R)", num, gen);
}
fz_try(ctx)
@@ -575,7 +575,7 @@ pdf_parse_ind_obj(pdf_document *xref,
fz_catch(ctx)
{
pdf_drop_obj(obj);
- fz_throw(ctx, "cannot parse indirect object (%d %d R)", num, gen);
+ fz_rethrow_message(ctx, "cannot parse indirect object (%d %d R)", num, gen);
}
skip:
diff --git a/pdf/pdf_pattern.c b/pdf/pdf_pattern.c
index 15d0b942..622705b2 100644
--- a/pdf/pdf_pattern.c
+++ b/pdf/pdf_pattern.c
@@ -77,7 +77,7 @@ pdf_load_pattern(pdf_document *xref, pdf_obj *dict)
{
pdf_remove_item(ctx, pdf_free_pattern_imp, dict);
pdf_drop_pattern(ctx, pat);
- fz_throw(ctx, "cannot load pattern stream (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict));
+ fz_rethrow_message(ctx, "cannot load pattern stream (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict));
}
return pat;
}
diff --git a/pdf/pdf_repair.c b/pdf/pdf_repair.c
index e482ec3a..421696a2 100644
--- a/pdf/pdf_repair.c
+++ b/pdf/pdf_repair.c
@@ -44,9 +44,10 @@ pdf_repair_obj(fz_stream *file, pdf_lexbuf *buf, int *stmofsp, int *stmlenp, pdf
}
fz_catch(ctx)
{
+ /* FIXME: TryLater */
/* Don't let a broken object at EOF overwrite a good one */
if (file->eof)
- fz_throw(ctx, "broken object at EOF ignored");
+ fz_rethrow_message(ctx, "broken object at EOF ignored");
/* Silently swallow the error */
dict = pdf_new_dict(ctx, 2);
}
@@ -84,7 +85,7 @@ pdf_repair_obj(fz_stream *file, pdf_lexbuf *buf, int *stmofsp, int *stmlenp, pdf
{
*tmpofs = fz_tell(file);
if (*tmpofs < 0)
- fz_throw(ctx, "cannot tell in file");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot tell in file");
tok = pdf_lex(file, buf);
}
@@ -99,7 +100,7 @@ pdf_repair_obj(fz_stream *file, pdf_lexbuf *buf, int *stmofsp, int *stmlenp, pdf
*stmofsp = fz_tell(file);
if (*stmofsp < 0)
- fz_throw(ctx, "cannot seek in file");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot seek in file");
if (stm_len > 0)
{
@@ -110,6 +111,7 @@ pdf_repair_obj(fz_stream *file, pdf_lexbuf *buf, int *stmofsp, int *stmlenp, pdf
}
fz_catch(ctx)
{
+ /* FIXME: TryLater */
fz_warn(ctx, "cannot find endstream token, falling back to scanning");
}
if (tok == PDF_TOK_ENDSTREAM)
@@ -119,7 +121,7 @@ pdf_repair_obj(fz_stream *file, pdf_lexbuf *buf, int *stmofsp, int *stmlenp, pdf
n = fz_read(file, (unsigned char *) buf->scratch, 9);
if (n < 0)
- fz_throw(ctx, "cannot read from file");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot read from file");
while (memcmp(buf->scratch, "endstream", 9) != 0)
{
@@ -135,7 +137,7 @@ pdf_repair_obj(fz_stream *file, pdf_lexbuf *buf, int *stmofsp, int *stmlenp, pdf
atobjend:
*tmpofs = fz_tell(file);
if (*tmpofs < 0)
- fz_throw(ctx, "cannot tell in file");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot tell in file");
tok = pdf_lex(file, buf);
if (tok != PDF_TOK_ENDOBJ)
fz_warn(ctx, "object missing 'endobj' token");
@@ -144,7 +146,7 @@ atobjend:
/* Read another token as we always return the next one */
*tmpofs = fz_tell(file);
if (*tmpofs < 0)
- fz_throw(ctx, "cannot tell in file");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot tell in file");
tok = pdf_lex(file, buf);
}
}
@@ -181,7 +183,7 @@ pdf_repair_obj_stm(pdf_document *xref, int num, int gen)
tok = pdf_lex(stm, &buf);
if (tok != PDF_TOK_INT)
- fz_throw(ctx, "corrupt object stream (%d %d R)", num, gen);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "corrupt object stream (%d %d R)", num, gen);
n = buf.i;
if (n < 0)
@@ -205,7 +207,7 @@ pdf_repair_obj_stm(pdf_document *xref, int num, int gen)
tok = pdf_lex(stm, &buf);
if (tok != PDF_TOK_INT)
- fz_throw(ctx, "corrupt object stream (%d %d R)", num, gen);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "corrupt object stream (%d %d R)", num, gen);
}
}
fz_always(ctx)
@@ -215,7 +217,7 @@ pdf_repair_obj_stm(pdf_document *xref, int num, int gen)
}
fz_catch(ctx)
{
- fz_throw(ctx, "cannot load object stream object (%d %d R)", num, gen);
+ fz_rethrow_message(ctx, "cannot load object stream object (%d %d R)", num, gen);
}
}
@@ -266,7 +268,7 @@ pdf_repair_xref(pdf_document *xref, pdf_lexbuf *buf)
/* look for '%PDF' version marker within first kilobyte of file */
n = fz_read(xref->file, (unsigned char *)buf->scratch, fz_mini(buf->size, 1024));
if (n < 0)
- fz_throw(ctx, "cannot read from file");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot read from file");
fz_seek(xref->file, 0, 0);
for (i = 0; i < n - 4; i++)
@@ -289,7 +291,7 @@ pdf_repair_xref(pdf_document *xref, pdf_lexbuf *buf)
{
tmpofs = fz_tell(xref->file);
if (tmpofs < 0)
- fz_throw(ctx, "cannot tell in file");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot tell in file");
fz_try(ctx)
{
@@ -297,6 +299,7 @@ pdf_repair_xref(pdf_document *xref, pdf_lexbuf *buf)
}
fz_catch(ctx)
{
+ /* FIXME: TryLater */
fz_warn(ctx, "ignoring the rest of the file");
break;
}
@@ -322,6 +325,7 @@ pdf_repair_xref(pdf_document *xref, pdf_lexbuf *buf)
}
fz_catch(ctx)
{
+ /* FIXME: TryLater */
/* If we haven't seen a root yet, there is nothing
* we can do, but give up. Otherwise, we'll make
* do. */
@@ -372,6 +376,7 @@ pdf_repair_xref(pdf_document *xref, pdf_lexbuf *buf)
}
fz_catch(ctx)
{
+ /* FIXME: TryLater */
/* If we haven't seen a root yet, there is nothing
* we can do, but give up. Otherwise, we'll make
* do. */
@@ -577,6 +582,6 @@ pdf_repair_obj_stms(pdf_document *xref)
pdf_xref_entry *entry = pdf_get_populating_xref_entry(xref, i);
if (entry->type == 'o' && pdf_get_populating_xref_entry(xref, entry->ofs)->type != 'n')
- fz_throw(xref->ctx, "invalid reference to non-object-stream: %d (%d 0 R)", entry->ofs, i);
+ fz_throw(xref->ctx, FZ_ERROR_GENERIC, "invalid reference to non-object-stream: %d (%d 0 R)", entry->ofs, i);
}
}
diff --git a/pdf/pdf_shade.c b/pdf/pdf_shade.c
index 04c50b03..41ddcc1a 100644
--- a/pdf/pdf_shade.c
+++ b/pdf/pdf_shade.c
@@ -346,7 +346,7 @@ pdf_load_shading_dict(pdf_document *xref, pdf_obj *dict, const fz_matrix *transf
obj = pdf_dict_gets(dict, "ColorSpace");
if (!obj)
- fz_throw(ctx, "shading colorspace is missing");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "shading colorspace is missing");
shade->colorspace = pdf_load_colorspace(xref, obj);
obj = pdf_dict_gets(dict, "Background");
@@ -374,7 +374,7 @@ pdf_load_shading_dict(pdf_document *xref, pdf_obj *dict, const fz_matrix *transf
func[0] = pdf_load_function(xref, obj, in, out);
if (!func[0])
- fz_throw(ctx, "cannot load shading function (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj));
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot load shading function (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj));
}
else if (pdf_is_array(obj))
{
@@ -382,12 +382,12 @@ pdf_load_shading_dict(pdf_document *xref, pdf_obj *dict, const fz_matrix *transf
if (funcs != 1 && funcs != shade->colorspace->n)
{
funcs = 0;
- fz_throw(ctx, "incorrect number of shading functions");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "incorrect number of shading functions");
}
if (funcs > FZ_MAX_COLORS)
{
funcs = 0;
- fz_throw(ctx, "too many shading functions");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "too many shading functions");
}
if (type == 1)
@@ -400,13 +400,13 @@ pdf_load_shading_dict(pdf_document *xref, pdf_obj *dict, const fz_matrix *transf
{
func[i] = pdf_load_function(xref, pdf_array_get(obj, i), in, out);
if (!func[i])
- fz_throw(ctx, "cannot load shading function (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj));
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot load shading function (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj));
}
}
else if (type < 4)
{
/* Functions are compulsory for types 1,2,3 */
- fz_throw(ctx, "cannot load shading function (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj));
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot load shading function (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj));
}
shade->type = type;
@@ -420,7 +420,7 @@ pdf_load_shading_dict(pdf_document *xref, pdf_obj *dict, const fz_matrix *transf
case 6: pdf_load_type6_shade(shade, xref, dict, funcs, func); break;
case 7: pdf_load_type7_shade(shade, xref, dict, funcs, func); break;
default:
- fz_throw(ctx, "unknown shading type: %d", type);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "unknown shading type: %d", type);
}
}
fz_always(ctx)
@@ -433,7 +433,7 @@ pdf_load_shading_dict(pdf_document *xref, pdf_obj *dict, const fz_matrix *transf
{
fz_drop_shade(ctx, shade);
- fz_throw(ctx, "cannot load shading type %d (%d %d R)", type, pdf_to_num(dict), pdf_to_gen(dict));
+ fz_rethrow_message(ctx, "cannot load shading type %d (%d %d R)", type, pdf_to_num(dict), pdf_to_gen(dict));
}
return shade;
}
@@ -481,7 +481,7 @@ pdf_load_shading(pdf_document *xref, pdf_obj *dict)
obj = pdf_dict_gets(dict, "Shading");
if (!obj)
- fz_throw(ctx, "syntaxerror: missing shading dictionary");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "syntaxerror: missing shading dictionary");
shade = pdf_load_shading_dict(xref, obj, &mat);
}
diff --git a/pdf/pdf_stream.c b/pdf/pdf_stream.c
index 7c1f4a6c..7e74b666 100644
--- a/pdf/pdf_stream.c
+++ b/pdf/pdf_stream.c
@@ -329,14 +329,14 @@ pdf_open_raw_renumbered_stream(pdf_document *xref, int num, int gen, int orig_nu
pdf_xref_entry *x;
if (num < 0 || num >= pdf_xref_len(xref))
- fz_throw(xref->ctx, "object id out of range (%d %d R)", num, gen);
+ fz_throw(xref->ctx, FZ_ERROR_GENERIC, "object id out of range (%d %d R)", num, gen);
x = pdf_get_xref_entry(xref, num);
pdf_cache_object(xref, num, gen);
if (x->stm_ofs == 0)
- fz_throw(xref->ctx, "object is not a stream");
+ fz_throw(xref->ctx, FZ_ERROR_GENERIC, "object is not a stream");
return pdf_open_raw_filter(xref->file, xref, x->obj, num, orig_num, orig_gen, x->stm_ofs);
}
@@ -347,14 +347,14 @@ pdf_open_image_stream(pdf_document *xref, int num, int gen, int orig_num, int or
pdf_xref_entry *x;
if (num < 0 || num >= pdf_xref_len(xref))
- fz_throw(xref->ctx, "object id out of range (%d %d R)", num, gen);
+ fz_throw(xref->ctx, FZ_ERROR_GENERIC, "object id out of range (%d %d R)", num, gen);
x = pdf_get_xref_entry(xref, num);
pdf_cache_object(xref, num, gen);
if (x->stm_ofs == 0 && x->stm_buf == NULL)
- fz_throw(xref->ctx, "object is not a stream");
+ fz_throw(xref->ctx, FZ_ERROR_GENERIC, "object is not a stream");
return pdf_open_filter(xref->file, xref, x->obj, orig_num, orig_gen, x->stm_ofs, params);
}
@@ -374,7 +374,7 @@ fz_stream *
pdf_open_stream_with_offset(pdf_document *xref, int num, int gen, pdf_obj *dict, int stm_ofs)
{
if (stm_ofs == 0)
- fz_throw(xref->ctx, "object is not a stream");
+ fz_throw(xref->ctx, FZ_ERROR_GENERIC, "object is not a stream");
return pdf_open_filter(xref->file, xref, dict, num, gen, stm_ofs, NULL);
}
@@ -477,7 +477,7 @@ pdf_load_image_stream(pdf_document *xref, int num, int gen, int orig_num, int or
}
fz_catch(ctx)
{
- fz_throw(ctx, "cannot read raw stream (%d %d R)", num, gen);
+ fz_rethrow_message(ctx, "cannot read raw stream (%d %d R)", num, gen);
}
return buf;
@@ -536,6 +536,7 @@ pdf_open_object_array(pdf_document *xref, pdf_obj *list)
}
fz_catch(ctx)
{
+ /* FIXME: TryLater */
fz_warn(ctx, "cannot load content stream part %d/%d", i + 1, n);
continue;
}
diff --git a/pdf/pdf_type3.c b/pdf/pdf_type3.c
index bb952ff7..d85d9f11 100644
--- a/pdf/pdf_type3.c
+++ b/pdf/pdf_type3.c
@@ -60,7 +60,7 @@ pdf_load_type3_font(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict)
encoding = pdf_dict_gets(dict, "Encoding");
if (!encoding)
{
- fz_throw(ctx, "syntaxerror: Type3 font missing Encoding");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "syntaxerror: Type3 font missing Encoding");
}
if (pdf_is_name(encoding))
@@ -108,7 +108,7 @@ pdf_load_type3_font(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict)
widths = pdf_dict_gets(dict, "Widths");
if (!widths)
{
- fz_throw(ctx, "syntaxerror: Type3 font missing Widths");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "syntaxerror: Type3 font missing Widths");
}
for (i = first; i <= last; i++)
@@ -140,7 +140,7 @@ pdf_load_type3_font(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict)
charprocs = pdf_dict_gets(dict, "CharProcs");
if (!charprocs)
{
- fz_throw(ctx, "syntaxerror: Type3 font missing CharProcs");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "syntaxerror: Type3 font missing CharProcs");
}
for (i = 0; i < 256; i++)
@@ -161,7 +161,7 @@ pdf_load_type3_font(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict)
{
if (fontdesc)
pdf_drop_font(ctx, fontdesc);
- fz_throw(ctx, "cannot load type3 font (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict));
+ fz_rethrow_message(ctx, "cannot load type3 font (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict));
}
return fontdesc;
}
@@ -184,6 +184,7 @@ void pdf_load_type3_glyphs(pdf_document *xref, pdf_font_desc *fontdesc, int nest
}
fz_catch(ctx)
{
- fz_warn(ctx, "Type3 glyph load failed: %s", fz_caught(ctx));
+ /* FIXME: TryLater */
+ fz_warn(ctx, "Type3 glyph load failed: %s", fz_caught_message(ctx));
}
}
diff --git a/pdf/pdf_write.c b/pdf/pdf_write.c
index 9ca4607e..a423edef 100644
--- a/pdf/pdf_write.c
+++ b/pdf/pdf_write.c
@@ -531,6 +531,7 @@ static pdf_obj *sweepref(pdf_document *xref, pdf_write_options *opts, pdf_obj *o
}
fz_catch(ctx)
{
+ /* FIXME: TryLater */
/* Leave broken */
}
@@ -1642,12 +1643,13 @@ static void writeobject(pdf_document *xref, pdf_write_options *opts, int num, in
}
fz_catch(ctx)
{
+ /* FIXME: TryLater ? */
if (opts->continue_on_error)
{
fprintf(opts->out, "%d %d obj\nnull\nendobj\n", num, gen);
if (opts->errors)
(*opts->errors)++;
- fz_warn(ctx, "%s", fz_caught(ctx));
+ fz_warn(ctx, "%s", fz_caught_message(ctx));
return;
}
else
@@ -1723,12 +1725,13 @@ static void writeobject(pdf_document *xref, pdf_write_options *opts, int num, in
}
fz_catch(ctx)
{
+ /* FIXME: TryLater ? */
if (opts->continue_on_error)
{
fprintf(opts->out, "%d %d obj\nnull\nendobj\n", num, gen);
if (opts->errors)
(*opts->errors)++;
- fz_warn(ctx, "%s", fz_caught(ctx));
+ fz_warn(ctx, "%s", fz_caught_message(ctx));
}
else
{
@@ -2229,7 +2232,7 @@ void pdf_write_document(pdf_document *xref, char *filename, fz_write_options *fz
opts.out = fopen(filename, "wb");
if (!opts.out)
- fz_throw(ctx, "cannot open output file '%s'", filename);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open output file '%s'", filename);
fz_try(ctx)
{
diff --git a/pdf/pdf_xobject.c b/pdf/pdf_xobject.c
index a47ea687..61fc876a 100644
--- a/pdf/pdf_xobject.c
+++ b/pdf/pdf_xobject.c
@@ -88,7 +88,7 @@ pdf_load_xobject(pdf_document *xref, pdf_obj *dict)
{
form->colorspace = pdf_load_colorspace(xref, obj);
if (!form->colorspace)
- fz_throw(ctx, "cannot load xobject colorspace");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot load xobject colorspace");
}
}
@@ -102,7 +102,7 @@ pdf_load_xobject(pdf_document *xref, pdf_obj *dict)
{
pdf_remove_item(ctx, pdf_free_xobject_imp, dict);
pdf_drop_xobject(ctx, form);
- fz_throw(ctx, "cannot load xobject content stream (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict));
+ fz_rethrow_message(ctx, "cannot load xobject content stream (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict));
}
form->me = pdf_keep_obj(dict);
@@ -217,7 +217,7 @@ pdf_new_xobject(pdf_document *xref, const fz_rect *bbox, const fz_matrix *mat)
pdf_drop_obj(dict);
pdf_drop_obj(idict);
pdf_drop_xobject(ctx, form);
- fz_throw(ctx, "failed to create xobject)");
+ fz_rethrow_message(ctx, "failed to create xobject)");
}
return idict;
diff --git a/pdf/pdf_xref.c b/pdf/pdf_xref.c
index 9b3d6653..9224d515 100644
--- a/pdf/pdf_xref.c
+++ b/pdf/pdf_xref.c
@@ -205,7 +205,7 @@ pdf_load_version(pdf_document *xref)
fz_seek(xref->file, 0, SEEK_SET);
fz_read_line(xref->file, buf, sizeof buf);
if (memcmp(buf, "%PDF-", 5) != 0)
- fz_throw(xref->ctx, "cannot recognize version marker");
+ fz_throw(xref->ctx, FZ_ERROR_GENERIC, "cannot recognize version marker");
xref->version = atoi(buf + 5) * 10 + atoi(buf + 7);
}
@@ -226,7 +226,7 @@ pdf_read_start_xref(pdf_document *xref)
n = fz_read(xref->file, buf, sizeof buf);
if (n < 0)
- fz_throw(xref->ctx, "cannot read from file");
+ fz_throw(xref->ctx, FZ_ERROR_GENERIC, "cannot read from file");
for (i = n - 9; i >= 0; i--)
{
@@ -242,7 +242,7 @@ pdf_read_start_xref(pdf_document *xref)
}
}
- fz_throw(xref->ctx, "cannot find startxref");
+ fz_throw(xref->ctx, FZ_ERROR_GENERIC, "cannot find startxref");
}
/*
@@ -265,7 +265,7 @@ pdf_xref_size_from_old_trailer(pdf_document *xref, pdf_lexbuf *buf)
fz_read_line(xref->file, buf->scratch, buf->size);
if (strncmp(buf->scratch, "xref", 4) != 0)
- fz_throw(xref->ctx, "cannot find xref marker");
+ fz_throw(xref->ctx, FZ_ERROR_GENERIC, "cannot find xref marker");
while (1)
{
@@ -277,7 +277,7 @@ pdf_xref_size_from_old_trailer(pdf_document *xref, pdf_lexbuf *buf)
s = buf->scratch;
fz_strsep(&s, " "); /* ignore ofs */
if (!s)
- fz_throw(xref->ctx, "invalid range marker in xref");
+ fz_throw(xref->ctx, FZ_ERROR_GENERIC, "invalid range marker in xref");
len = fz_atoi(fz_strsep(&s, " "));
/* broken pdfs where the section is not on a separate line */
@@ -286,7 +286,7 @@ pdf_xref_size_from_old_trailer(pdf_document *xref, pdf_lexbuf *buf)
t = fz_tell(xref->file);
if (t < 0)
- fz_throw(xref->ctx, "cannot tell in file");
+ fz_throw(xref->ctx, FZ_ERROR_GENERIC, "cannot tell in file");
fz_seek(xref->file, t + 20 * len, SEEK_SET);
}
@@ -296,23 +296,23 @@ pdf_xref_size_from_old_trailer(pdf_document *xref, pdf_lexbuf *buf)
pdf_obj *trailer;
tok = pdf_lex(xref->file, buf);
if (tok != PDF_TOK_TRAILER)
- fz_throw(xref->ctx, "expected trailer marker");
+ fz_throw(xref->ctx, FZ_ERROR_GENERIC, "expected trailer marker");
tok = pdf_lex(xref->file, buf);
if (tok != PDF_TOK_OPEN_DICT)
- fz_throw(xref->ctx, "expected trailer dictionary");
+ fz_throw(xref->ctx, FZ_ERROR_GENERIC, "expected trailer dictionary");
trailer = pdf_parse_dict(xref, xref->file, buf);
size = pdf_to_int(pdf_dict_gets(trailer, "Size"));
if (!size)
- fz_throw(xref->ctx, "trailer missing Size entry");
+ fz_throw(xref->ctx, FZ_ERROR_GENERIC, "trailer missing Size entry");
pdf_drop_obj(trailer);
}
fz_catch(xref->ctx)
{
- fz_throw(xref->ctx, "cannot parse trailer");
+ fz_rethrow_message(xref->ctx, "cannot parse trailer");
}
fz_seek(xref->file, ofs, SEEK_SET);
@@ -345,7 +345,7 @@ pdf_read_old_xref(pdf_document *xref, pdf_lexbuf *buf)
fz_read_line(xref->file, buf->scratch, buf->size);
if (strncmp(buf->scratch, "xref", 4) != 0)
- fz_throw(xref->ctx, "cannot find xref marker");
+ fz_throw(xref->ctx, FZ_ERROR_GENERIC, "cannot find xref marker");
while (1)
{
@@ -366,7 +366,7 @@ pdf_read_old_xref(pdf_document *xref, pdf_lexbuf *buf)
}
if (ofs < 0)
- fz_throw(xref->ctx, "out of range object num in xref: %d", ofs);
+ fz_throw(xref->ctx, FZ_ERROR_GENERIC, "out of range object num in xref: %d", ofs);
/* broken pdfs where size in trailer undershoots entries in xref sections */
if (ofs + len > xref_len)
@@ -381,7 +381,7 @@ pdf_read_old_xref(pdf_document *xref, pdf_lexbuf *buf)
pdf_xref_entry *entry = pdf_get_populating_xref_entry(xref, i);
n = fz_read(xref->file, (unsigned char *) buf->scratch, 20);
if (n < 0)
- fz_throw(xref->ctx, "cannot read xref table");
+ fz_throw(xref->ctx, FZ_ERROR_GENERIC, "cannot read xref table");
if (!entry->type)
{
s = buf->scratch;
@@ -394,7 +394,7 @@ pdf_read_old_xref(pdf_document *xref, pdf_lexbuf *buf)
entry->gen = atoi(s + 11);
entry->type = s[17];
if (s[17] != 'f' && s[17] != 'n' && s[17] != 'o')
- fz_throw(xref->ctx, "unexpected xref type: %#x (%d %d R)", s[17], i, entry->gen);
+ fz_throw(xref->ctx, FZ_ERROR_GENERIC, "unexpected xref type: %#x (%d %d R)", s[17], i, entry->gen);
}
}
}
@@ -403,17 +403,17 @@ pdf_read_old_xref(pdf_document *xref, pdf_lexbuf *buf)
{
tok = pdf_lex(xref->file, buf);
if (tok != PDF_TOK_TRAILER)
- fz_throw(xref->ctx, "expected trailer marker");
+ fz_throw(xref->ctx, FZ_ERROR_GENERIC, "expected trailer marker");
tok = pdf_lex(xref->file, buf);
if (tok != PDF_TOK_OPEN_DICT)
- fz_throw(xref->ctx, "expected trailer dictionary");
+ fz_throw(xref->ctx, FZ_ERROR_GENERIC, "expected trailer dictionary");
trailer = pdf_parse_dict(xref, xref->file, buf);
}
fz_catch(xref->ctx)
{
- fz_throw(xref->ctx, "cannot parse trailer");
+ fz_rethrow_message(xref->ctx, "cannot parse trailer");
}
return trailer;
}
@@ -424,9 +424,9 @@ pdf_read_new_xref_section(pdf_document *xref, fz_stream *stm, int i0, int i1, in
int i, n;
if (i0 < 0 || i1 < 0)
- fz_throw(xref->ctx, "negative xref stream entry index");
+ fz_throw(xref->ctx, FZ_ERROR_GENERIC, "negative xref stream entry index");
if (i0 + i1 > pdf_xref_len(xref))
- fz_throw(xref->ctx, "xref stream has too many entries");
+ fz_throw(xref->ctx, FZ_ERROR_GENERIC, "xref stream has too many entries");
for (i = i0; i < i0 + i1; i++)
{
@@ -436,7 +436,7 @@ pdf_read_new_xref_section(pdf_document *xref, fz_stream *stm, int i0, int i1, in
int c = 0;
if (fz_is_eof(stm))
- fz_throw(xref->ctx, "truncated xref stream");
+ fz_throw(xref->ctx, FZ_ERROR_GENERIC, "truncated xref stream");
for (n = 0; n < w0; n++)
a = (a << 8) + fz_read_byte(stm);
@@ -486,25 +486,25 @@ pdf_read_new_xref(pdf_document *xref, pdf_lexbuf *buf)
}
fz_catch(ctx)
{
- fz_throw(ctx, "cannot parse compressed xref stream object");
+ fz_rethrow_message(ctx, "cannot parse compressed xref stream object");
}
fz_try(ctx)
{
obj = pdf_dict_gets(trailer, "Size");
if (!obj)
- fz_throw(ctx, "xref stream missing Size entry (%d %d R)", num, gen);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "xref stream missing Size entry (%d %d R)", num, gen);
size = pdf_to_int(obj);
/* Access xref entry to assure table size */
(void)pdf_get_populating_xref_entry(xref, size-1);
if (num < 0 || num >= pdf_xref_len(xref))
- fz_throw(ctx, "object id (%d %d R) out of range (0..%d)", num, gen, pdf_xref_len(xref) - 1);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "object id (%d %d R) out of range (0..%d)", num, gen, pdf_xref_len(xref) - 1);
obj = pdf_dict_gets(trailer, "W");
if (!obj)
- fz_throw(ctx, "xref stream missing W entry (%d %d R)", num, gen);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "xref stream missing W entry (%d %d R)", num, gen);
w0 = pdf_to_int(pdf_array_get(obj, 0));
w1 = pdf_to_int(pdf_array_get(obj, 1));
w2 = pdf_to_int(pdf_array_get(obj, 2));
@@ -573,11 +573,11 @@ pdf_read_xref(pdf_document *xref, int ofs, pdf_lexbuf *buf)
else if (c >= '0' && c <= '9')
trailer = pdf_read_new_xref(xref, buf);
else
- fz_throw(ctx, "cannot recognize xref format");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot recognize xref format");
}
fz_catch(ctx)
{
- fz_throw(ctx, "cannot read xref (ofs=%d)", ofs);
+ fz_rethrow_message(ctx, "cannot read xref (ofs=%d)", ofs);
}
return trailer;
}
@@ -631,7 +631,7 @@ read_xref_section(pdf_document *xref, int ofs, pdf_lexbuf *buf, ofs_list *offset
if (xrefstmofs)
{
if (xrefstmofs < 0)
- fz_throw(ctx, "negative xref stream offset");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "negative xref stream offset");
/*
Read the XRefStm stream, but throw away the resulting trailer. We do not
@@ -643,15 +643,16 @@ read_xref_section(pdf_document *xref, int ofs, pdf_lexbuf *buf, ofs_list *offset
prevofs = pdf_to_int(pdf_dict_gets(trailer, "Prev"));
if (prevofs < 0)
- fz_throw(ctx, "negative xref stream offset for previous xref stream");
-
+ fz_throw(ctx, FZ_ERROR_GENERIC, "negative xref stream offset for previous xref stream");
+ }
+ fz_always(ctx)
+ {
pdf_drop_obj(trailer);
trailer = NULL;
}
fz_catch(ctx)
{
- pdf_drop_obj(trailer);
- fz_throw(ctx, "cannot read xref at offset %d", ofs);
+ fz_rethrow_message(ctx, "cannot read xref at offset %d", ofs);
}
return prevofs;
@@ -705,7 +706,7 @@ pdf_load_xref(pdf_document *xref, pdf_lexbuf *buf)
/* broken pdfs where first object is not free */
if (pdf_get_xref_entry(xref, 0)->type != 'f')
- fz_throw(ctx, "first object in xref is not free");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "first object in xref is not free");
/* broken pdfs where object offsets are out of range */
xref_len = pdf_xref_len(xref);
@@ -719,11 +720,11 @@ pdf_load_xref(pdf_document *xref, pdf_lexbuf *buf)
if (entry->ofs == 0)
entry->type = 'f';
else if (entry->ofs <= 0 || entry->ofs >= xref->file_size)
- fz_throw(ctx, "object offset out of range: %d (%d 0 R)", entry->ofs, i);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "object offset out of range: %d (%d 0 R)", entry->ofs, i);
}
if (entry->type == 'o')
if (entry->ofs <= 0 || entry->ofs >= xref_len || pdf_get_xref_entry(xref, entry->ofs)->type != 'n')
- fz_throw(ctx, "invalid reference to an objstm that does not exist: %d (%d 0 R)", entry->ofs, i);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "invalid reference to an objstm that does not exist: %d (%d 0 R)", entry->ofs, i);
}
}
@@ -741,19 +742,19 @@ pdf_ocg_set_config(pdf_document *xref, int config)
if (config == 0)
return;
else
- fz_throw(xref->ctx, "Unknown OCG config (None known!)");
+ fz_throw(xref->ctx, FZ_ERROR_GENERIC, "Unknown OCG config (None known!)");
}
if (config == 0)
{
cobj = pdf_dict_gets(obj, "D");
if (!cobj)
- fz_throw(xref->ctx, "No default OCG config");
+ fz_throw(xref->ctx, FZ_ERROR_GENERIC, "No default OCG config");
}
else
{
cobj = pdf_array_get(pdf_dict_gets(obj, "Configs"), config);
if (!cobj)
- fz_throw(xref->ctx, "Illegal OCG config");
+ fz_throw(xref->ctx, FZ_ERROR_GENERIC, "Illegal OCG config");
}
pdf_drop_obj(desc->intent);
@@ -910,6 +911,7 @@ pdf_init_document(pdf_document *xref)
}
fz_catch(ctx)
{
+ /* FIXME: TryLater ? */
pdf_free_xref_sections(xref);
fz_warn(xref->ctx, "trying to repair broken xref");
repaired = 1;
@@ -950,6 +952,7 @@ pdf_init_document(pdf_document *xref)
}
fz_catch(ctx)
{
+ /* FIXME: TryLater ? */
fz_warn(ctx, "ignoring broken object (%d 0 R)", i);
continue;
}
@@ -989,7 +992,7 @@ pdf_init_document(pdf_document *xref)
pdf_drop_obj(dict);
pdf_drop_obj(nobj);
pdf_close_document(xref);
- fz_throw(ctx, "cannot open document");
+ fz_rethrow_message(ctx, "cannot open document");
}
fz_try(ctx)
@@ -998,6 +1001,7 @@ pdf_init_document(pdf_document *xref)
}
fz_catch(ctx)
{
+ /* FIXME: TryLater ? */
fz_warn(ctx, "Ignoring Broken Optional Content");
}
}
@@ -1096,9 +1100,9 @@ pdf_load_obj_stm(pdf_document *xref, int num, int gen, pdf_lexbuf *buf)
first = pdf_to_int(pdf_dict_gets(objstm, "First"));
if (count < 0)
- fz_throw(ctx, "negative number of objects in object stream");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "negative number of objects in object stream");
if (first < 0)
- fz_throw(ctx, "first object in object stream resides outside stream");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "first object in object stream resides outside stream");
numbuf = fz_calloc(ctx, count, sizeof(int));
ofsbuf = fz_calloc(ctx, count, sizeof(int));
@@ -1108,12 +1112,12 @@ pdf_load_obj_stm(pdf_document *xref, int num, int gen, pdf_lexbuf *buf)
{
tok = pdf_lex(stm, buf);
if (tok != PDF_TOK_INT)
- fz_throw(ctx, "corrupt object stream (%d %d R)", num, gen);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "corrupt object stream (%d %d R)", num, gen);
numbuf[i] = buf->i;
tok = pdf_lex(stm, buf);
if (tok != PDF_TOK_INT)
- fz_throw(ctx, "corrupt object stream (%d %d R)", num, gen);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "corrupt object stream (%d %d R)", num, gen);
ofsbuf[i] = buf->i;
}
@@ -1130,7 +1134,7 @@ pdf_load_obj_stm(pdf_document *xref, int num, int gen, pdf_lexbuf *buf)
if (numbuf[i] < 1 || numbuf[i] >= xref_len)
{
pdf_drop_obj(obj);
- fz_throw(ctx, "object id (%d 0 R) out of range (0..%d)", numbuf[i], xref_len - 1);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "object id (%d 0 R) out of range (0..%d)", numbuf[i], xref_len - 1);
}
entry = pdf_get_xref_entry(xref, numbuf[i]);
@@ -1165,7 +1169,7 @@ pdf_load_obj_stm(pdf_document *xref, int num, int gen, pdf_lexbuf *buf)
}
fz_catch(ctx)
{
- fz_throw(ctx, "cannot open object stream (%d %d R)", num, gen);
+ fz_rethrow_message(ctx, "cannot open object stream (%d %d R)", num, gen);
}
}
@@ -1181,7 +1185,7 @@ pdf_cache_object(pdf_document *xref, int num, int gen)
fz_context *ctx = xref->ctx;
if (num < 0 || num >= pdf_xref_len(xref))
- fz_throw(ctx, "object out of range (%d %d R); xref size %d", num, gen, pdf_xref_len(xref));
+ fz_throw(ctx, FZ_ERROR_GENERIC, "object out of range (%d %d R); xref size %d", num, gen, pdf_xref_len(xref));
x = pdf_get_xref_entry(xref, num);
@@ -1204,14 +1208,14 @@ pdf_cache_object(pdf_document *xref, int num, int gen)
}
fz_catch(ctx)
{
- fz_throw(ctx, "cannot parse object (%d %d R)", num, gen);
+ fz_rethrow_message(ctx, "cannot parse object (%d %d R)", num, gen);
}
if (rnum != num)
{
pdf_drop_obj(x->obj);
x->obj = NULL;
- fz_throw(ctx, "found object (%d %d R) instead of (%d %d R)", rnum, rgen, num, gen);
+ fz_rethrow_message(ctx, "found object (%d %d R) instead of (%d %d R)", rnum, rgen, num, gen);
}
if (xref->crypt)
@@ -1227,15 +1231,15 @@ pdf_cache_object(pdf_document *xref, int num, int gen)
}
fz_catch(ctx)
{
- fz_throw(ctx, "cannot load object stream containing object (%d %d R)", num, gen);
+ fz_rethrow_message(ctx, "cannot load object stream containing object (%d %d R)", num, gen);
}
if (!x->obj)
- fz_throw(ctx, "object (%d %d R) was not found in its object stream", num, gen);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "object (%d %d R) was not found in its object stream", num, gen);
}
}
else
{
- fz_throw(ctx, "cannot find object in xref (%d %d R)", num, gen);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find object in xref (%d %d R)", num, gen);
}
}
@@ -1251,7 +1255,7 @@ pdf_load_object(pdf_document *xref, int num, int gen)
}
fz_catch(ctx)
{
- fz_throw(ctx, "cannot load object (%d %d R) into cache", num, gen);
+ fz_rethrow_message(ctx, "cannot load object (%d %d R) into cache", num, gen);
}
entry = pdf_get_xref_entry(xref, num);
@@ -1290,6 +1294,7 @@ pdf_resolve_indirect(pdf_obj *ref)
}
fz_catch(ctx)
{
+ /* FIXME: TryLater ? */
fz_warn(ctx, "cannot load object (%d %d R) into cache", num, gen);
return NULL;
}
@@ -1536,7 +1541,7 @@ pdf_open_document_no_run(fz_context *ctx, const char *filename)
}
fz_catch(ctx)
{
- fz_throw(ctx, "cannot load document '%s'", filename);
+ fz_rethrow_message(ctx, "cannot load document '%s'", filename);
}
return doc;
}