summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--source/tools/murun.c43
4 files changed, 95 insertions, 4 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();
diff --git a/source/tools/murun.c b/source/tools/murun.c
index a4c25791..e90821c4 100644
--- a/source/tools/murun.c
+++ b/source/tools/murun.c
@@ -3370,12 +3370,48 @@ static void ffi_PDFDocument_newString(js_State *J)
{
fz_context *ctx = js_getcontext(J);
pdf_document *pdf = js_touserdata(J, 0, "pdf_document");
- // TODO: convert array of numbers to raw string
- // TODO: convert to UCS-2 or PDFDocEncoding
const char *val = js_tostring(J, 1);
pdf_obj *obj = NULL;
+
+ fz_try(ctx)
+ obj = pdf_new_text_string(ctx, pdf, val);
+ fz_catch(ctx)
+ rethrow(J);
+ ffi_pushobj(J, obj);
+}
+
+static void ffi_PDFDocument_newByteString(js_State *J)
+{
+ fz_context *ctx = js_getcontext(J);
+ pdf_document *pdf = js_touserdata(J, 0, "pdf_document");
+ int n, i;
+ char *buf;
+ pdf_obj *obj = NULL;
+
+ n = js_getlength(J, 1);
+
fz_try(ctx)
- obj = pdf_new_string(ctx, pdf, val, strlen(val));
+ buf = fz_malloc(ctx, n);
+ fz_catch(ctx)
+ rethrow(J);
+
+ if (js_try(J)) {
+ fz_free(ctx, buf);
+ js_throw(J);
+ }
+
+ for (i = 0; i < n; ++i) {
+ js_getindex(J, 1, i);
+ buf[i] = js_tonumber(J, -1);
+ js_pop(J, 1);
+ }
+
+ js_endtry(J);
+
+ fz_try(ctx)
+ obj = pdf_new_string(ctx, pdf, buf, n);
+ fz_always(ctx)
+ fz_free(ctx, buf);
fz_catch(ctx)
rethrow(J);
ffi_pushobj(J, obj);
@@ -4524,6 +4560,7 @@ int murun_main(int argc, char **argv)
jsB_propfun(J, "PDFDocument.newInteger", ffi_PDFDocument_newInteger, 1);
jsB_propfun(J, "PDFDocument.newReal", ffi_PDFDocument_newReal, 1);
jsB_propfun(J, "PDFDocument.newString", ffi_PDFDocument_newString, 1);
+ jsB_propfun(J, "PDFDocument.newByteString", ffi_PDFDocument_newByteString, 1);
jsB_propfun(J, "PDFDocument.newName", ffi_PDFDocument_newName, 1);
jsB_propfun(J, "PDFDocument.newIndirect", ffi_PDFDocument_newIndirect, 2);
jsB_propfun(J, "PDFDocument.newArray", ffi_PDFDocument_newArray, 1);