summaryrefslogtreecommitdiff
path: root/source/tools/murun.c
diff options
context:
space:
mode:
authorSebastian Rasmussen <sebras@gmail.com>2017-04-15 00:03:17 +0800
committerSebastian Rasmussen <sebras@gmail.com>2017-04-20 19:47:03 +0800
commit96b76d2b9748551df1ef50db0688b39d4670e23a (patch)
tree494f22c85889f4527506698b38dacaf66e1ed33c /source/tools/murun.c
parent23eddfa1032bd0111b03a8295544c4009be5ead3 (diff)
downloadmupdf-96b76d2b9748551df1ef50db0688b39d4670e23a.tar.xz
js: Push annotation error handling down to library.
This makes is possible for JNI code to depend on the library for error handling.
Diffstat (limited to 'source/tools/murun.c')
-rw-r--r--source/tools/murun.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/source/tools/murun.c b/source/tools/murun.c
index 3ee41764..85cb521d 100644
--- a/source/tools/murun.c
+++ b/source/tools/murun.c
@@ -3786,11 +3786,13 @@ static void ffi_PDFPage_createAnnotation(js_State *J)
pdf_page *page = js_touserdata(J, 0, "pdf_page");
const char *name = js_tostring(J, 1);
pdf_annot *annot;
- int subtype = pdf_annot_type_from_string(name);
- if (subtype < 0)
- js_error(J, "unknown PDF annotation subtype: %s", name);
+ int subtype;
+
fz_try(ctx)
+ {
+ subtype = pdf_annot_type_from_string(ctx, name);
annot = pdf_create_annot(ctx, page, subtype);
+ }
fz_catch(ctx)
rethrow(J);
ffi_pushannot(J, (fz_annot*)annot);
@@ -3811,12 +3813,16 @@ static void ffi_PDFAnnotation_getType(js_State *J)
{
fz_context *ctx = js_getcontext(J);
pdf_annot *annot = js_touserdata(J, 0, "pdf_annot");
- int subtype;
+ int type;
+ const char *subtype;
fz_try(ctx)
- subtype = pdf_annot_type(ctx, annot);
+ {
+ type = pdf_annot_type(ctx, annot);
+ subtype = pdf_string_from_annot_type(ctx, type);
+ }
fz_catch(ctx)
rethrow(J);
- js_pushstring(J, pdf_string_from_annot_type(subtype));
+ js_pushstring(J, subtype);
}
static void ffi_PDFAnnotation_getFlags(js_State *J)
@@ -3934,9 +3940,7 @@ static void ffi_PDFAnnotation_setColor(js_State *J)
pdf_annot *annot = js_touserdata(J, 0, "pdf_annot");
int i, n = js_getlength(J, 1);
float color[4];
- if (n != 0 && n != 1 && n != 3 && n != 4)
- js_error(J, "color must be 0, 1, 3, or 4 components");
- for (i = 0; i < n; ++i) {
+ for (i = 0; i < n && i < 4; ++i) {
js_getindex(J, 1, i);
color[i] = js_tonumber(J, -1);
js_pop(J, 1);
@@ -3970,9 +3974,7 @@ static void ffi_PDFAnnotation_setInteriorColor(js_State *J)
pdf_annot *annot = js_touserdata(J, 0, "pdf_annot");
int i, n = js_getlength(J, 1);
float color[4];
- if (n != 0 && n != 1 && n != 3 && n != 4)
- js_error(J, "color must be 0, 1, 3, or 4 components");
- for (i = 0; i < n; ++i) {
+ for (i = 0; i < n && i < 4; ++i) {
js_getindex(J, 1, i);
color[i] = js_tonumber(J, -1);
js_pop(J, 1);