From ed28a166dace50d1a555689b9d5353e62a1b1e69 Mon Sep 17 00:00:00 2001 From: Fred Ross-Perry Date: Mon, 13 Nov 2017 17:04:06 -0800 Subject: 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. --- platform/java/mupdf_native.c | 55 ++++++++++++++++++++-- platform/java/mupdf_native.h | 16 +++++++ .../src/com/artifex/mupdf/fitz/PDFAnnotation.java | 2 + 3 files changed, 70 insertions(+), 3 deletions(-) (limited to 'platform/java') 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) { diff --git a/platform/java/mupdf_native.h b/platform/java/mupdf_native.h index 2a139e02..dfc62d85 100644 --- a/platform/java/mupdf_native.h +++ b/platform/java/mupdf_native.h @@ -1504,6 +1504,22 @@ JNIEXPORT jfloatArray JNICALL Java_com_artifex_mupdf_fitz_PDFAnnotation_getInter JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_PDFAnnotation_setInteriorColor (JNIEnv *, jobject, jfloatArray); +/* + * Class: com_artifex_mupdf_fitz_PDFAnnotation + * Method: getAuthor + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_com_artifex_mupdf_fitz_PDFAnnotation_getAuthor + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_PDFAnnotation + * Method: setAuthor + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_PDFAnnotation_setAuthor + (JNIEnv *, jobject, jstring); + /* * Class: com_artifex_mupdf_fitz_PDFAnnotation * Method: getLineEndingStyles diff --git a/platform/java/src/com/artifex/mupdf/fitz/PDFAnnotation.java b/platform/java/src/com/artifex/mupdf/fitz/PDFAnnotation.java index 19ef815f..f836a601 100644 --- a/platform/java/src/com/artifex/mupdf/fitz/PDFAnnotation.java +++ b/platform/java/src/com/artifex/mupdf/fitz/PDFAnnotation.java @@ -60,6 +60,8 @@ public class PDFAnnotation extends Annotation public native void setColor(float[] color); public native float[] getInteriorColor(); public native void setInteriorColor(float[] color); + public native String getAuthor(); + public native void setAuthor(String author); public native int[] getLineEndingStyles(); public native void setLineEndingStyles(int startStyle, int endStyle); -- cgit v1.2.3