summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--platform/java/mupdf_native.c153
-rw-r--r--platform/java/mupdf_native.h48
-rw-r--r--platform/java/src/com/artifex/mupdf/fitz/PDFObject.java28
3 files changed, 209 insertions, 20 deletions
diff --git a/platform/java/mupdf_native.c b/platform/java/mupdf_native.c
index 0dfe1f4e..b2a58ef2 100644
--- a/platform/java/mupdf_native.c
+++ b/platform/java/mupdf_native.c
@@ -6802,10 +6802,7 @@ FUN(PDFObject_putArrayBoolean)(JNIEnv *env, jobject self, jint index, jboolean b
return;
fz_try(ctx)
- if (index == pdf_array_len(ctx, arr))
- pdf_array_push(ctx, arr, pdf_new_bool(ctx, pdf, b));
- else
- pdf_array_put(ctx, arr, index, pdf_new_bool(ctx, pdf, b));
+ pdf_array_put(ctx, arr, index, pdf_new_bool(ctx, pdf, b));
fz_catch(ctx)
jni_rethrow(env, ctx);
}
@@ -6822,10 +6819,7 @@ FUN(PDFObject_putArrayInteger)(JNIEnv *env, jobject self, jint index, jint i)
return;
fz_try(ctx)
- if (index == pdf_array_len(ctx, arr))
- pdf_array_push(ctx, arr, pdf_new_int(ctx, pdf, i));
- else
- pdf_array_put(ctx, arr, index, pdf_new_int(ctx, pdf, i));
+ pdf_array_put(ctx, arr, index, pdf_new_int(ctx, pdf, i));
fz_catch(ctx)
jni_rethrow(env, ctx);
}
@@ -6842,10 +6836,7 @@ FUN(PDFObject_putArrayFloat)(JNIEnv *env, jobject self, jint index, jfloat f)
return;
fz_try(ctx)
- if (index == pdf_array_len(ctx, arr))
- pdf_array_push(ctx, arr, pdf_new_real(ctx, pdf, f));
- else
- pdf_array_put(ctx, arr, index, pdf_new_real(ctx, pdf, f));
+ pdf_array_put(ctx, arr, index, pdf_new_real(ctx, pdf, f));
fz_catch(ctx)
jni_rethrow(env, ctx);
}
@@ -6870,10 +6861,7 @@ FUN(PDFObject_putArrayString)(JNIEnv *env, jobject self, jint index, jstring jst
}
fz_try(ctx)
- if (index == pdf_array_len(ctx, arr))
- pdf_array_push(ctx, arr, pdf_new_string(ctx, pdf, str, strlen(str)));
- else
- pdf_array_put(ctx, arr, index, pdf_new_string(ctx, pdf, str, strlen(str)));
+ pdf_array_put(ctx, arr, index, pdf_new_string(ctx, pdf, str, strlen(str)));
fz_always(ctx)
if (str)
(*env)->ReleaseStringUTFChars(env, jstr, str);
@@ -6893,10 +6881,7 @@ FUN(PDFObject_putArrayPDFObject)(JNIEnv *env, jobject self, jint index, jobject
return;
fz_try(ctx)
- if (index == pdf_array_len(ctx, arr))
- pdf_array_push(ctx, arr, obj);
- else
- pdf_array_put(ctx, arr, index, obj);
+ pdf_array_put(ctx, arr, index, obj);
fz_catch(ctx)
jni_rethrow(env, ctx);
}
@@ -7301,6 +7286,134 @@ FUN(PDFObject_toByteString)(JNIEnv *env, jobject self)
return jbs;
}
+JNIEXPORT int JNICALL
+FUN(PDFObject_size)(JNIEnv *env, jobject self)
+{
+ fz_context *ctx = get_context(env);
+ pdf_obj *arr = from_PDFObject(env, self);
+ int len;
+
+ if (!ctx) return 0;
+
+ fz_try(ctx)
+ len = pdf_array_len(ctx, arr);
+ fz_catch(ctx)
+ jni_rethrow(env, ctx);
+
+ return len;
+}
+
+JNIEXPORT void JNICALL
+FUN(PDFObject_pushBoolean)(JNIEnv *env, jobject self, jboolean b)
+{
+ fz_context *ctx = get_context(env);
+ pdf_obj *arr = from_PDFObject(env, self);
+ pdf_obj *item = NULL;
+
+ if (!ctx) return;
+
+ fz_try(ctx)
+ {
+ pdf_document *pdf = pdf_get_bound_document(ctx, arr);
+ item = pdf_new_bool(ctx, pdf, b);
+ pdf_array_push(ctx, arr, item);
+ }
+ fz_always(ctx)
+ pdf_drop_obj(ctx, item);
+ fz_catch(ctx)
+ jni_rethrow(env, ctx);
+}
+
+JNIEXPORT void JNICALL
+FUN(PDFObject_pushInteger)(JNIEnv *env, jobject self, jint i)
+{
+ fz_context *ctx = get_context(env);
+ pdf_obj *arr = from_PDFObject(env, self);
+ pdf_obj *item = NULL;
+
+ if (!ctx) return;
+
+ fz_try(ctx)
+ {
+ pdf_document *pdf = pdf_get_bound_document(ctx, arr);
+ item = pdf_new_int(ctx, pdf, i);
+ pdf_array_push(ctx, arr, item);
+ }
+ fz_always(ctx)
+ pdf_drop_obj(ctx, item);
+ fz_catch(ctx)
+ jni_rethrow(env, ctx);
+}
+
+JNIEXPORT void JNICALL
+FUN(PDFObject_pushFloat)(JNIEnv *env, jobject self, jfloat f)
+{
+ fz_context *ctx = get_context(env);
+ pdf_obj *arr = from_PDFObject(env, self);
+ pdf_obj *item = NULL;
+
+ if (!ctx) return;
+
+ fz_try(ctx)
+ {
+ pdf_document *pdf = pdf_get_bound_document(ctx, arr);
+ item = pdf_new_real(ctx, pdf, f);
+ pdf_array_push(ctx, arr, item);
+ }
+ fz_always(ctx)
+ pdf_drop_obj(ctx, item);
+ fz_catch(ctx)
+ jni_rethrow(env, ctx);
+}
+
+JNIEXPORT void JNICALL
+FUN(PDFObject_pushString)(JNIEnv *env, jobject self, jstring jstr)
+{
+ fz_context *ctx = get_context(env);
+ pdf_obj *arr = from_PDFObject(env, self);
+ const char *str = NULL;
+ pdf_obj *item = NULL;
+
+ if (!ctx) return;
+ if (jstr)
+ {
+ str = (*env)->GetStringUTFChars(env, jstr, NULL);
+ if (!str) return;
+ }
+
+ fz_try(ctx)
+ {
+ pdf_document *pdf = pdf_get_bound_document(ctx, arr);
+ item = str ? pdf_new_string(ctx, pdf, str, strlen(str)) : NULL;
+ pdf_array_push(ctx, arr, item);
+ }
+ fz_always(ctx)
+ {
+ pdf_drop_obj(ctx, item);
+ if (str)
+ (*env)->ReleaseStringUTFChars(env, jstr, str);
+ }
+ fz_catch(ctx)
+ jni_rethrow(env, ctx);
+}
+
+JNIEXPORT void JNICALL
+FUN(PDFObject_pushPDFObject)(JNIEnv *env, jobject self, jobject jitem)
+{
+ fz_context *ctx = get_context(env);
+ pdf_obj *arr = from_PDFObject(env, self);
+ pdf_obj *item = from_PDFObject(env, jitem);
+
+ if (!ctx) return;
+
+ fz_try(ctx)
+ pdf_array_push(ctx, arr, item);
+ fz_always(ctx)
+ pdf_drop_obj(ctx, item);
+ fz_catch(ctx)
+ jni_rethrow(env, ctx);
+}
+
JNIEXPORT jstring JNICALL
FUN(PDFObject_toString)(JNIEnv *env, jobject self, jboolean tight)
{
diff --git a/platform/java/mupdf_native.h b/platform/java/mupdf_native.h
index e64885f6..c01e10a0 100644
--- a/platform/java/mupdf_native.h
+++ b/platform/java/mupdf_native.h
@@ -1946,6 +1946,54 @@ JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_PDFObject_deleteDictionaryStr
JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_PDFObject_deleteDictionaryPDFObject
(JNIEnv *, jobject, jobject);
+/*
+ * Class: com_artifex_mupdf_fitz_PDFObject
+ * Method: size
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_com_artifex_mupdf_fitz_PDFObject_size
+ (JNIEnv *, jobject);
+
+/*
+ * Class: com_artifex_mupdf_fitz_PDFObject
+ * Method: pushBoolean
+ * Signature: (Z)V
+ */
+JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_PDFObject_pushBoolean
+ (JNIEnv *, jobject, jboolean);
+
+/*
+ * Class: com_artifex_mupdf_fitz_PDFObject
+ * Method: pushInteger
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_PDFObject_pushInteger
+ (JNIEnv *, jobject, jint);
+
+/*
+ * Class: com_artifex_mupdf_fitz_PDFObject
+ * Method: pushFloat
+ * Signature: (F)V
+ */
+JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_PDFObject_pushFloat
+ (JNIEnv *, jobject, jfloat);
+
+/*
+ * Class: com_artifex_mupdf_fitz_PDFObject
+ * Method: pushString
+ * Signature: (Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_PDFObject_pushString
+ (JNIEnv *, jobject, jstring);
+
+/*
+ * Class: com_artifex_mupdf_fitz_PDFObject
+ * Method: pushPDFObject
+ * Signature: (Lcom/artifex/mupdf/fitz/PDFObject;)V
+ */
+JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_PDFObject_pushPDFObject
+ (JNIEnv *, jobject, jobject);
+
#ifdef __cplusplus
}
#endif
diff --git a/platform/java/src/com/artifex/mupdf/fitz/PDFObject.java b/platform/java/src/com/artifex/mupdf/fitz/PDFObject.java
index a099b438..10a0e7a8 100644
--- a/platform/java/src/com/artifex/mupdf/fitz/PDFObject.java
+++ b/platform/java/src/com/artifex/mupdf/fitz/PDFObject.java
@@ -173,4 +173,32 @@ public class PDFObject
public void delete(PDFObject name) {
deleteDictionaryPDFObject(name);
}
+
+ public native int size();
+
+ private native void pushBoolean(boolean b);
+ private native void pushInteger(int i);
+ private native void pushFloat(float f);
+ private native void pushString(String s);
+ private native void pushPDFObject(PDFObject item);
+
+ public void push(boolean b) {
+ pushBoolean(b);
+ }
+
+ public void push(int i) {
+ pushInteger(i);
+ }
+
+ public void push(float f) {
+ pushFloat(f);
+ }
+
+ public void push(String s) {
+ pushString(s);
+ }
+
+ public void push(PDFObject obj) {
+ pushPDFObject(obj);
+ }
}