summaryrefslogtreecommitdiff
path: root/platform/java
diff options
context:
space:
mode:
authorSebastian Rasmussen <sebras@gmail.com>2017-11-21 01:21:54 +0100
committerTor Andersson <tor.andersson@artifex.com>2017-11-22 23:09:51 +0100
commit52b6e193ba376f46dec2ae3b8c316f2e08fefc13 (patch)
treecad41705e88dfef3a421476788eabd3695dfef1a /platform/java
parentc01e1a267bac0e053b78fba6ebbd0c199c9adabe (diff)
downloadmupdf-52b6e193ba376f46dec2ae3b8c316f2e08fefc13.tar.xz
jni/js: Add interfaces for creating UTF-16BE and PDF byte strings.
This mirrors the existing PDFObject.asByteString().
Diffstat (limited to 'platform/java')
-rw-r--r--platform/java/mupdf_native.c47
-rw-r--r--platform/java/mupdf_native.h8
-rw-r--r--platform/java/src/com/artifex/mupdf/fitz/PDFDocument.java1
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();