summaryrefslogtreecommitdiff
path: root/platform/java/mupdf_native.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 /platform/java/mupdf_native.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 'platform/java/mupdf_native.c')
-rw-r--r--platform/java/mupdf_native.c55
1 files changed, 52 insertions, 3 deletions
diff --git a/platform/java/mupdf_native.c b/platform/java/mupdf_native.c
index 95f6e9b6..890bc6b1 100644
--- a/platform/java/mupdf_native.c
+++ b/platform/java/mupdf_native.c
@@ -8213,19 +8213,22 @@ FUN(PDFAnnotation_getContents)(JNIEnv *env, jobject self)
{
fz_context *ctx = get_context(env);
pdf_annot *annot = from_PDFAnnotation(env, self);
- const char *contents = NULL;
+ char *contents = NULL;
+ jstring result;
if (!ctx || !annot) return NULL;
fz_try(ctx)
- contents = pdf_annot_contents(ctx, annot);
+ contents = pdf_copy_annot_contents(ctx, annot);
fz_catch(ctx)
{
jni_rethrow(env, ctx);
return NULL;
}
- return (*env)->NewStringUTF(env, contents);
+ result = (*env)->NewStringUTF(env, contents);
+ fz_free(ctx, contents);
+ return result;
}
JNIEXPORT void JNICALL
@@ -8251,6 +8254,52 @@ FUN(PDFAnnotation_setContents)(JNIEnv *env, jobject self, jstring jcontents)
jni_rethrow(env, ctx);
}
+JNIEXPORT jstring JNICALL
+FUN(PDFAnnotation_getAuthor)(JNIEnv *env, jobject self)
+{
+ fz_context *ctx = get_context(env);
+ pdf_annot *annot = from_PDFAnnotation(env, self);
+ char *author = NULL;
+ jstring result;
+
+ if (!ctx || !annot) return NULL;
+
+ fz_try(ctx)
+ author = pdf_copy_annot_author(ctx, annot);
+ fz_catch(ctx)
+ {
+ jni_rethrow(env, ctx);
+ return NULL;
+ }
+
+ result = (*env)->NewStringUTF(env, author);
+ fz_free(ctx, author);
+ return result;
+}
+
+JNIEXPORT void JNICALL
+FUN(PDFAnnotation_setAuthor)(JNIEnv *env, jobject self, jstring jauthor)
+{
+ fz_context *ctx = get_context(env);
+ pdf_annot *annot = from_PDFAnnotation(env, self);
+ const char *author = NULL;
+
+ if (!ctx || !annot) return;
+ if (jauthor)
+ {
+ author = (*env)->GetStringUTFChars(env, jauthor, NULL);
+ if (!author) return;
+ }
+
+ fz_try(ctx)
+ pdf_set_annot_author(ctx, annot, author);
+ fz_always(ctx)
+ if (author)
+ (*env)->ReleaseStringUTFChars(env, jauthor, author);
+ fz_catch(ctx)
+ jni_rethrow(env, ctx);
+}
+
JNIEXPORT jobject JNICALL
FUN(PDFAnnotation_getRect)(JNIEnv *env, jobject self)
{