summaryrefslogtreecommitdiff
path: root/source/tools/murun.c
diff options
context:
space:
mode:
authorFred Ross-Perry <fred.ross-perry@artifex.com>2017-11-13 17:04:06 -0800
committerTor Andersson <tor.andersson@artifex.com>2017-11-22 23:09:51 +0100
commited28a166dace50d1a555689b9d5353e62a1b1e69 (patch)
tree67dca9996a83d5939b7e3e4a91da8685a4764291 /source/tools/murun.c
parent52b6e193ba376f46dec2ae3b8c316f2e08fefc13 (diff)
downloadmupdf-ed28a166dace50d1a555689b9d5353e62a1b1e69.tar.xz
jni/js: Use correct text encoding in annotation author and contents.
Also clarify that a copy of author/contents is returned, and that the caller must free them.
Diffstat (limited to 'source/tools/murun.c')
-rw-r--r--source/tools/murun.c48
1 files changed, 46 insertions, 2 deletions
diff --git a/source/tools/murun.c b/source/tools/murun.c
index e90821c4..69765164 100644
--- a/source/tools/murun.c
+++ b/source/tools/murun.c
@@ -3988,12 +3988,21 @@ static void ffi_PDFAnnotation_getContents(js_State *J)
{
fz_context *ctx = js_getcontext(J);
pdf_annot *annot = js_touserdata(J, 0, "pdf_annot");
- const char *contents = NULL;
+ char *contents = NULL;
+
fz_try(ctx)
- contents = pdf_annot_contents(ctx, annot);
+ contents = pdf_copy_annot_contents(ctx, annot);
fz_catch(ctx)
rethrow(J);
+
+ if (js_try(J)) {
+ fz_free(ctx, contents);
+ js_throw(J);
+ }
js_pushstring(J, contents);
+ js_endtry(J);
+
+ fz_free(ctx, contents);
}
static void ffi_PDFAnnotation_setContents(js_State *J)
@@ -4270,6 +4279,39 @@ static void ffi_PDFAnnotation_setInkList(js_State *J)
rethrow(J);
}
+static void ffi_PDFAnnotation_getAuthor(js_State *J)
+{
+ fz_context *ctx = js_getcontext(J);
+ pdf_annot *annot = js_touserdata(J, 0, "pdf_annot");
+ char *author = NULL;
+
+ fz_try(ctx)
+ author = pdf_copy_annot_author(ctx, annot);
+ fz_catch(ctx)
+ rethrow(J);
+
+ if (js_try(J)) {
+ fz_free(ctx, author);
+ js_throw(J);
+ }
+ js_pushstring(J, author);
+ js_endtry(J);
+
+ fz_free(ctx, author);
+}
+
+static void ffi_PDFAnnotation_setAuthor(js_State *J)
+{
+ fz_context *ctx = js_getcontext(J);
+ pdf_annot *annot = js_touserdata(J, 0, "pdf_annot");
+ const char *author = js_tostring(J, 1);
+
+ fz_try(ctx)
+ pdf_set_annot_author(ctx, annot, author);
+ fz_catch(ctx)
+ rethrow(J);
+}
+
static void ffi_PDFAnnotation_updateAppearance(js_State *J)
{
fz_context *ctx = js_getcontext(J);
@@ -4599,6 +4641,8 @@ int murun_main(int argc, char **argv)
jsB_propfun(J, "PDFAnnotation.setQuadPoints", ffi_PDFAnnotation_setQuadPoints, 1);
jsB_propfun(J, "PDFAnnotation.getInkList", ffi_PDFAnnotation_getInkList, 0);
jsB_propfun(J, "PDFAnnotation.setInkList", ffi_PDFAnnotation_setInkList, 1);
+ jsB_propfun(J, "PDFAnnotation.getAuthor", ffi_PDFAnnotation_getAuthor, 0);
+ jsB_propfun(J, "PDFAnnotation.setAuthor", ffi_PDFAnnotation_setAuthor, 1);
jsB_propfun(J, "PDFAnnotation.updateAppearance", ffi_PDFAnnotation_updateAppearance, 0);
}
js_setregistry(J, "pdf_annot");