summaryrefslogtreecommitdiff
path: root/platform/java
diff options
context:
space:
mode:
authorSebastian Rasmussen <sebras@gmail.com>2016-07-17 16:55:17 +0800
committerSebastian Rasmussen <sebras@gmail.com>2016-07-17 22:33:52 +0800
commit014fb58f887086ea34f74dcdb0d91dbec05966d1 (patch)
tree7097cdb9854360e3579592fd8df0135907e5ffb3 /platform/java
parentbbb324fad31db437d668eb4891473231c3520792 (diff)
downloadmupdf-014fb58f887086ea34f74dcdb0d91dbec05966d1.tar.xz
JNI: When adding stream/page contents, accept String.
This is for easy of use, in addition to accepting Buffer.
Diffstat (limited to 'platform/java')
-rw-r--r--platform/java/mupdf_native.c86
-rw-r--r--platform/java/mupdf_native.h24
-rw-r--r--platform/java/src/com/artifex/mupdf/fitz/PDFDocument.java23
3 files changed, 125 insertions, 8 deletions
diff --git a/platform/java/mupdf_native.c b/platform/java/mupdf_native.c
index 762e59c9..26f31b66 100644
--- a/platform/java/mupdf_native.c
+++ b/platform/java/mupdf_native.c
@@ -5260,7 +5260,7 @@ FUN(PDFDocument_deleteObject)(JNIEnv *env, jobject self, jint num)
}
JNIEXPORT jobject JNICALL
-FUN(PDFDocument_addStream)(JNIEnv *env, jobject self, jobject jbuf)
+FUN(PDFDocument_addStreamBuffer)(JNIEnv *env, jobject self, jobject jbuf)
{
fz_context *ctx = get_context(env);
pdf_document *pdf = from_PDFDocument(env, self);
@@ -5279,7 +5279,48 @@ FUN(PDFDocument_addStream)(JNIEnv *env, jobject self, jobject jbuf)
}
JNIEXPORT jobject JNICALL
-FUN(PDFDocument_addPage)(JNIEnv *env, jobject self, jobject jmediabox, jint rotate, jobject jresources, jobject jcontents)
+FUN(PDFDocument_addStreamString)(JNIEnv *env, jobject self, jstring jbuf)
+{
+ fz_context *ctx = get_context(env);
+ pdf_document *pdf = from_PDFDocument(env, self);
+ fz_buffer *buf = NULL;
+ const char *sbuf = NULL;
+ unsigned char *data = NULL;
+ pdf_obj *ind = NULL;
+
+ if (ctx == NULL || pdf == NULL || jbuf == NULL)
+ return NULL;
+
+ sbuf = (*env)->GetStringUTFChars(env, jbuf, NULL);
+ if (sbuf == NULL)
+ return NULL;
+
+ fz_var(data);
+
+ fz_try(ctx)
+ {
+ int len = strlen(sbuf);
+ data = fz_malloc(ctx, len);
+ memcpy(data, sbuf, len);
+ buf = fz_new_buffer_from_data(ctx, data, len);
+ data = NULL;
+ ind = pdf_add_stream(ctx, pdf, buf);
+ }
+ fz_always(ctx)
+ {
+ fz_drop_buffer(ctx, buf);
+ fz_free(ctx, data);
+ (*env)->ReleaseStringUTFChars(env, jbuf, sbuf);
+ }
+ fz_catch(ctx)
+ jni_rethrow(env, ctx);
+
+ return to_PDFObject_safe_own(ctx, env, self, ind);
+}
+
+
+JNIEXPORT jobject JNICALL
+FUN(PDFDocument_addPageBuffer)(JNIEnv *env, jobject self, jobject jmediabox, jint rotate, jobject jresources, jobject jcontents)
{
fz_context *ctx = get_context(env);
pdf_document *pdf = from_PDFDocument(env, self);
@@ -5299,6 +5340,47 @@ FUN(PDFDocument_addPage)(JNIEnv *env, jobject self, jobject jmediabox, jint rota
return to_PDFObject_safe_own(ctx, env, self, ind);
}
+JNIEXPORT jobject JNICALL
+FUN(PDFDocument_addPageString)(JNIEnv *env, jobject self, jobject jmediabox, jint rotate, jobject jresources, jstring jcontents)
+{
+ fz_context *ctx = get_context(env);
+ pdf_document *pdf = from_PDFDocument(env, self);
+ fz_rect mediabox = from_Rect(env, jmediabox);
+ pdf_obj *resources = from_PDFObject(env, jresources);
+ const char *scontents = NULL;
+ fz_buffer *contents = NULL;
+ unsigned char *data = NULL;
+ pdf_obj *ind = NULL;
+
+ if (ctx == NULL || pdf == NULL || resources == NULL || jcontents == NULL)
+ return NULL;
+
+ scontents = (*env)->GetStringUTFChars(env, jcontents, NULL);
+ if (scontents == NULL)
+ return NULL;
+
+ fz_var(data);
+
+ fz_try(ctx)
+ {
+ int len = strlen(scontents);
+ data = fz_malloc(ctx, len);
+ contents = fz_new_buffer_from_data(ctx, data, len);
+ data = NULL;
+ ind = pdf_add_page(ctx, pdf, &mediabox, rotate, resources, contents);
+ }
+ fz_always(ctx)
+ {
+ fz_drop_buffer(ctx, contents);
+ fz_free(ctx, data);
+ (*env)->ReleaseStringUTFChars(env, jcontents, scontents);
+ }
+ fz_catch(ctx)
+ jni_rethrow(env, ctx);
+
+ return to_PDFObject_safe_own(ctx, env, self, ind);
+}
+
JNIEXPORT void JNICALL
FUN(PDFDocument_insertPage)(JNIEnv *env, jobject self, jint jat, jobject jpage)
{
diff --git a/platform/java/mupdf_native.h b/platform/java/mupdf_native.h
index 3756eae9..9cebff90 100644
--- a/platform/java/mupdf_native.h
+++ b/platform/java/mupdf_native.h
@@ -1454,22 +1454,38 @@ JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_PDFDocument_deleteObject
/*
* Class: com_artifex_mupdf_fitz_PDFDocument
- * Method: addStream
+ * Method: addStreamBuffer
* Signature: (Lcom/artifex/mupdf/fitz/Buffer;)Lcom/artifex/mupdf/fitz/PDFObject;
*/
-JNIEXPORT jobject JNICALL Java_com_artifex_mupdf_fitz_PDFDocument_addStream
+JNIEXPORT jobject JNICALL Java_com_artifex_mupdf_fitz_PDFDocument_addStreamBuffer
(JNIEnv *, jobject, jobject);
/*
* Class: com_artifex_mupdf_fitz_PDFDocument
- * Method: addPage
+ * Method: addStreamString
+ * Signature: (Ljava/lang/String;)Lcom/artifex/mupdf/fitz/PDFObject;
+ */
+JNIEXPORT jobject JNICALL Java_com_artifex_mupdf_fitz_PDFDocument_addStreamString
+ (JNIEnv *, jobject, jstring);
+
+/*
+ * Class: com_artifex_mupdf_fitz_PDFDocument
+ * Method: addPageBuffer
* Signature: (Lcom/artifex/mupdf/fitz/Rect;ILcom/artifex/mupdf/fitz/PDFObject;Lcom/artifex/mupdf/fitz/Buffer;)Lcom/artifex/mupdf/fitz/PDFObject;
*/
-JNIEXPORT jobject JNICALL Java_com_artifex_mupdf_fitz_PDFDocument_addPage
+JNIEXPORT jobject JNICALL Java_com_artifex_mupdf_fitz_PDFDocument_addPageBuffer
(JNIEnv *, jobject, jobject, jint, jobject, jobject);
/*
* Class: com_artifex_mupdf_fitz_PDFDocument
+ * Method: addPageString
+ * Signature: (Lcom/artifex/mupdf/fitz/Rect;ILcom/artifex/mupdf/fitz/PDFObject;Ljava/lang/String;)Lcom/artifex/mupdf/fitz/PDFObject;
+ */
+JNIEXPORT jobject JNICALL Java_com_artifex_mupdf_fitz_PDFDocument_addPageString
+ (JNIEnv *, jobject, jobject, jint, jobject, jstring);
+
+/*
+ * Class: com_artifex_mupdf_fitz_PDFDocument
* Method: insertPage
* Signature: (ILcom/artifex/mupdf/fitz/PDFObject;)V
*/
diff --git a/platform/java/src/com/artifex/mupdf/fitz/PDFDocument.java b/platform/java/src/com/artifex/mupdf/fitz/PDFDocument.java
index 58a3e3a6..c049d336 100644
--- a/platform/java/src/com/artifex/mupdf/fitz/PDFDocument.java
+++ b/platform/java/src/com/artifex/mupdf/fitz/PDFDocument.java
@@ -41,9 +41,28 @@ public class PDFDocument
public native PDFObject createObject();
public native void deleteObject(int i);
- public native PDFObject addStream(Buffer buf);
+ public native PDFObject addStreamBuffer(Buffer buf);
+ public native PDFObject addStreamString(String str);
+
+ public PDFObject addStream(Buffer buf) {
+ return addStreamBuffer(buf);
+ }
+
+ public PDFObject addStream(String str) {
+ return addStreamString(str);
+ }
+
+ public native PDFObject addPageBuffer(Rect mediabox, int rotate, PDFObject resources, Buffer contents);
+ public native PDFObject addPageString(Rect mediabox, int rotate, PDFObject resources, String contents);
+
+ public PDFObject addPage(Rect mediabox, int rotate, PDFObject resources, Buffer contents) {
+ return addPageBuffer(mediabox, rotate, resources, contents);
+ }
+
+ public PDFObject addPage(Rect mediabox, int rotate, PDFObject resources, String contents) {
+ return addPageString(mediabox, rotate, resources, contents);
+ }
- public native PDFObject addPage(Rect mediabox, int rotate, PDFObject resources, Buffer contents);
public native void insertPage(int at, PDFObject page);
public native void deletePage(int at);
public native PDFObject addImage(Image image);