diff options
Diffstat (limited to 'platform')
-rw-r--r-- | platform/java/mupdf_native.c | 47 | ||||
-rw-r--r-- | platform/java/mupdf_native.h | 8 | ||||
-rw-r--r-- | platform/java/src/com/artifex/mupdf/fitz/PDFDocument.java | 1 |
3 files changed, 55 insertions, 1 deletions
diff --git a/platform/java/mupdf_native.c b/platform/java/mupdf_native.c index 96d7f742..95f6e9b6 100644 --- a/platform/java/mupdf_native.c +++ b/platform/java/mupdf_native.c @@ -6152,7 +6152,7 @@ FUN(PDFDocument_newString)(JNIEnv *env, jobject self, jstring jstring) if (!s) return NULL; fz_try(ctx) - obj = pdf_new_string(ctx, pdf, s, strlen(s)); + obj = pdf_new_text_string(ctx, pdf, s); fz_always(ctx) (*env)->ReleaseStringUTFChars(env, jstring, s); fz_catch(ctx) @@ -6168,6 +6168,51 @@ FUN(PDFDocument_newString)(JNIEnv *env, jobject self, jstring jstring) } JNIEXPORT jobject JNICALL +FUN(PDFDocument_newByteString)(JNIEnv *env, jobject self, jobject jbs) +{ + fz_context *ctx = get_context(env); + pdf_document *pdf = from_PDFDocument(env, self); + pdf_obj *obj = NULL; + jbyte *bs; + size_t bslen; + jobject jobj; + + if (!ctx || !pdf) return NULL; + if (!jbs) { jni_throw_arg(env, "bs must not be null"); return NULL; } + + bslen = (*env)->GetArrayLength(env, jbs); + + fz_try(ctx) + bs = fz_malloc(ctx, bslen); + fz_catch(ctx) + { + jni_rethrow(env, ctx); + return NULL; + } + + (*env)->GetByteArrayRegion(env, jbs, 0, bslen, bs); + if ((*env)->ExceptionCheck(env)) { + fz_free(ctx, bs); + return NULL; + } + + fz_try(ctx) + obj = pdf_new_string(ctx, pdf, (char *) bs, bslen); + fz_always(ctx) + fz_free(ctx, bs); + fz_catch(ctx) + { + jni_rethrow(env, ctx); + return NULL; + } + + jobj = (*env)->NewObject(env, cls_PDFObject, mid_PDFObject_init, jlong_cast(obj), self); + if (!jobj) + pdf_drop_obj(ctx, obj); + return jobj; +} + +JNIEXPORT jobject JNICALL FUN(PDFDocument_newName)(JNIEnv *env, jobject self, jstring jname) { fz_context *ctx = get_context(env); diff --git a/platform/java/mupdf_native.h b/platform/java/mupdf_native.h index 42bb594d..2a139e02 100644 --- a/platform/java/mupdf_native.h +++ b/platform/java/mupdf_native.h @@ -1693,6 +1693,14 @@ JNIEXPORT jobject JNICALL Java_com_artifex_mupdf_fitz_PDFDocument_newString /* * Class: com_artifex_mupdf_fitz_PDFDocument + * Method: newByteString + * Signature: ([B)Lcom/artifex/mupdf/fitz/PDFObject; + */ +JNIEXPORT jobject JNICALL Java_com_artifex_mupdf_fitz_PDFDocument_newByteString + (JNIEnv *, jobject, jbyteArray); + +/* + * Class: com_artifex_mupdf_fitz_PDFDocument * Method: newName * Signature: (Ljava/lang/String;)Lcom/artifex/mupdf/fitz/PDFObject; */ diff --git a/platform/java/src/com/artifex/mupdf/fitz/PDFDocument.java b/platform/java/src/com/artifex/mupdf/fitz/PDFDocument.java index 62dd9f6d..68835aaa 100644 --- a/platform/java/src/com/artifex/mupdf/fitz/PDFDocument.java +++ b/platform/java/src/com/artifex/mupdf/fitz/PDFDocument.java @@ -30,6 +30,7 @@ public class PDFDocument extends Document public native PDFObject newInteger(int i); public native PDFObject newReal(float f); public native PDFObject newString(String s); + public native PDFObject newByteString(byte[] bs); public native PDFObject newName(String name); public native PDFObject newIndirect(int num, int gen); public native PDFObject newArray(); |