diff options
Diffstat (limited to 'platform/java')
-rw-r--r-- | platform/java/mupdf_native.c | 156 | ||||
-rw-r--r-- | platform/java/mupdf_native.h | 81 | ||||
-rw-r--r-- | platform/java/src/com/artifex/mupdf/fitz/Page.java | 5 | ||||
-rw-r--r-- | platform/java/src/com/artifex/mupdf/fitz/Separations.java | 27 |
4 files changed, 196 insertions, 73 deletions
diff --git a/platform/java/mupdf_native.c b/platform/java/mupdf_native.c index 69208f56..7d068d85 100644 --- a/platform/java/mupdf_native.c +++ b/platform/java/mupdf_native.c @@ -85,6 +85,7 @@ static jclass cls_Point; static jclass cls_Rect; static jclass cls_RuntimeException; static jclass cls_Separation; +static jclass cls_Separations; static jclass cls_Shade; static jclass cls_StrokeState; static jclass cls_StructuredText; @@ -130,6 +131,7 @@ static jfieldID fid_Rect_x0; static jfieldID fid_Rect_x1; static jfieldID fid_Rect_y0; static jfieldID fid_Rect_y1; +static jfieldID fid_Separations_pointer; static jfieldID fid_Shade_pointer; static jfieldID fid_StrokeState_pointer; static jfieldID fid_StructuredText_pointer; @@ -191,6 +193,7 @@ static jmethodID mid_Point_init; static jmethodID mid_Rect_init; static jmethodID mid_Shade_init; static jmethodID mid_Separation_init; +static jmethodID mid_Separations_init; static jmethodID mid_StrokeState_init; static jmethodID mid_StructuredText_init; static jmethodID mid_TextBlock_init; @@ -556,6 +559,10 @@ static int find_fids(JNIEnv *env) cls_Separation = get_class(&err, env, PKG"Separation"); mid_Separation_init = get_method(&err, env, "<init>", "(Ljava/lang/String;II)V"); + cls_Separations = get_class(&err, env, PKG"Separations"); + fid_Separations_pointer = get_field(&err, env, "pointer", "J"); + mid_Separations_init = get_method(&err, env, "<init>", "(J)V"); + cls_StrokeState = get_class(&err, env, PKG"StrokeState"); fid_StrokeState_pointer = get_field(&err, env, "pointer", "J"); mid_StrokeState_init = get_method(&err, env, "<init>", "(J)V"); @@ -649,6 +656,7 @@ static void lose_fids(JNIEnv *env) (*env)->DeleteGlobalRef(env, cls_Rect); (*env)->DeleteGlobalRef(env, cls_RuntimeException); (*env)->DeleteGlobalRef(env, cls_Separation); + (*env)->DeleteGlobalRef(env, cls_Separations); (*env)->DeleteGlobalRef(env, cls_Shade); (*env)->DeleteGlobalRef(env, cls_StrokeState); (*env)->DeleteGlobalRef(env, cls_StructuredText); @@ -1428,6 +1436,19 @@ static inline jobject to_Pixmap_safe_own(fz_context *ctx, JNIEnv *env, fz_pixmap return jobj; } +static inline jobject to_Separations_safe_own(fz_context *ctx, JNIEnv *env, fz_separations *seps) +{ + jobject jseps; + + if (!ctx || !seps) return NULL; + + jseps = (*env)->NewObject(env, cls_Separations, mid_Separations_init, jlong_cast(seps)); + if (!jseps) + fz_drop_separations(ctx, seps); + + return jseps; +} + static inline jobject to_StructuredText_safe_own(fz_context *ctx, JNIEnv *env, fz_stext_page *text) { jobject jtext; @@ -1605,6 +1626,15 @@ static inline fz_pixmap *from_Pixmap(JNIEnv *env, jobject jobj) return pixmap; } +static inline fz_separations *from_Separations(JNIEnv *env, jobject jobj) +{ + fz_separations *seps; + if (!jobj) return NULL; + seps = CAST(fz_separations *, (*env)->GetLongField(env, jobj, fid_Separations_pointer)); + if (!seps) jni_throw_null(env, "cannot use already destroyed Separations"); + return seps; +} + static inline fz_shade *from_Shade(JNIEnv *env, jobject jobj) { fz_shade *shd; @@ -4718,63 +4748,18 @@ FUN(Page_finalize)(JNIEnv *env, jobject self) fz_drop_page(ctx, page); } -JNIEXPORT jint JNICALL -FUN(Page_countSeparations)(JNIEnv *env, jobject self) -{ - fz_context *ctx = get_context(env); - fz_page *page = from_Page(env, self); - int nSep; - - if (!ctx || !page) return 0; - - fz_try(ctx) - nSep = fz_count_separations_on_page(ctx, page); - fz_catch(ctx) - { - jni_rethrow(env, ctx); - return 0; - } - - return nSep; -} - -JNIEXPORT void JNICALL -FUN(Page_enableSeparation)(JNIEnv *env, jobject self, jint sep, jboolean enable) -{ - fz_context *ctx = get_context(env); - fz_page *page = from_Page(env, self); - - if (!ctx || !page) return; - - fz_try(ctx) - fz_control_separation_on_page(ctx, page, sep, !enable); - fz_catch(ctx) - jni_rethrow(env, ctx); -} - JNIEXPORT jobject JNICALL -FUN(Page_getSeparation)(JNIEnv *env, jobject self, jint sep) +FUN(Page_getSeparations)(JNIEnv *env, jobject self) { fz_context *ctx = get_context(env); fz_page *page = from_Page(env, self); - const char *name; - char rgba[4]; - unsigned int bgra; - unsigned int cmyk; - jobject jname = NULL; + fz_separations *seps; - if (!ctx || !page) return NULL; + if (!ctx || !page) return 0; - /* MuPDF returns RGBA as bytes. Android wants a packed BGRA int. */ - name = fz_get_separation_on_page(ctx, page, sep, (unsigned int *)(&rgba[0]), &cmyk); - bgra = (rgba[0] << 16) | (rgba[1]<<8) | rgba[2] | (rgba[3]<<24); - if (name) - { - jname = (*env)->NewStringUTF(env, name); - if (!jname) return NULL; - } + seps = fz_page_separations(ctx, page); - return (*env)->NewObject(env, cls_Separation, mid_Separation_init, jname, bgra, cmyk); + return to_Separations_safe_own(ctx, env, seps); } JNIEXPORT jobject JNICALL @@ -8849,3 +8834,74 @@ FUN(PDFAnnotation_setLineEndingStyles)(JNIEnv *env, jobject self, jint start_sty fz_catch(ctx) jni_rethrow(env, ctx); } + +/* Separations interface */ + +JNIEXPORT jint JNICALL +FUN(Separations_getNumberOfSeparations)(JNIEnv *env, jobject self) +{ + fz_context *ctx = get_context(env); + fz_separations *seps = from_Separations(env, self); + int nSep; + + fz_try(ctx) + nSep = fz_count_separations(ctx, seps); + fz_catch(ctx) + { + jni_rethrow(env, ctx); + return 0; + } + + return nSep; +} + +JNIEXPORT void JNICALL +FUN(Separations_controlSeparation)(JNIEnv *env, jobject self, jint sep, jboolean disable) +{ + fz_context *ctx = get_context(env); + fz_separations *seps = from_Separations(env, self); + + if (!ctx || !seps) return; + + fz_try(ctx) + fz_control_separation(ctx, seps, sep, disable); + fz_catch(ctx) + jni_rethrow(env, ctx); +} + +JNIEXPORT jobject JNICALL +FUN(Separations_getSeparation)(JNIEnv *env, jobject self, jint sep) +{ + fz_context *ctx = get_context(env); + fz_separations *seps = from_Separations(env, self); + const char *name; + char rgba[4]; + unsigned int bgra; + unsigned int cmyk; + jobject jname = NULL; + + if (!ctx || !seps) return NULL; + + /* MuPDF returns RGBA as bytes. Android wants a packed BGRA int. */ + name = fz_get_separation(ctx, seps, sep, (unsigned int *)(&rgba[0]), &cmyk); + bgra = (rgba[0] << 16) | (rgba[1]<<8) | rgba[2] | (rgba[3]<<24); + if (name) + { + jname = (*env)->NewStringUTF(env, name); + if (!jname) return NULL; + } + + return (*env)->NewObject(env, cls_Separation, mid_Separation_init, jname, bgra, cmyk); +} + +JNIEXPORT jboolean JNICALL +FUN(Separations_areSeparationsControllable)(JNIEnv *env, jobject self) +{ + fz_context *ctx = get_context(env); + fz_separations *seps = from_Separations(env, self); + jobject jname = NULL; + + if (!ctx || !seps) return 0; + + return fz_separations_controllable(ctx, seps); +} diff --git a/platform/java/mupdf_native.h b/platform/java/mupdf_native.h index d7355376..991933c0 100644 --- a/platform/java/mupdf_native.h +++ b/platform/java/mupdf_native.h @@ -1418,28 +1418,12 @@ JNIEXPORT jbyteArray JNICALL Java_com_artifex_mupdf_fitz_Page_textAsHtml /* * Class: com_artifex_mupdf_fitz_Page - * Method: countSeparations - * Signature: ()I + * Method: getSeparations + * Signature: ()Lcom/artifex/mupdf/fitz/Separations; */ -JNIEXPORT jint JNICALL Java_com_artifex_mupdf_fitz_Page_countSeparations +JNIEXPORT jobject JNICALL Java_com_artifex_mupdf_fitz_Page_getSeparations (JNIEnv *, jobject); -/* - * Class: com_artifex_mupdf_fitz_Page - * Method: getSeparation - * Signature: (I)Lcom/artifex/mupdf/fitz/Separation; - */ -JNIEXPORT jobject JNICALL Java_com_artifex_mupdf_fitz_Page_getSeparation - (JNIEnv *, jobject, jint); - -/* - * Class: com_artifex_mupdf_fitz_Page - * Method: enableSeparation - * Signature: (IZ)V - */ -JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Page_enableSeparation - (JNIEnv *, jobject, jint, jboolean); - #ifdef __cplusplus } #endif @@ -2840,6 +2824,65 @@ extern "C" { } #endif #endif +/* Header for class com_artifex_mupdf_fitz_Separations */ + +#ifndef _Included_com_artifex_mupdf_fitz_Separations +#define _Included_com_artifex_mupdf_fitz_Separations +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: com_artifex_mupdf_fitz_Separations + * Method: finalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Separations_finalize + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Separations + * Method: getNumberOfSeparations + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_com_artifex_mupdf_fitz_Separations_getNumberOfSeparations + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Separations + * Method: getSeparation + * Signature: (I)Lcom/artifex/mupdf/fitz/Separation; + */ +JNIEXPORT jobject JNICALL Java_com_artifex_mupdf_fitz_Separations_getSeparation + (JNIEnv *, jobject, jint); + +/* + * Class: com_artifex_mupdf_fitz_Separations + * Method: areSeparationsControllable + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL Java_com_artifex_mupdf_fitz_Separations_areSeparationsControllable + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Separations + * Method: disableSeparation + * Signature: (IZ)Z + */ +JNIEXPORT jboolean JNICALL Java_com_artifex_mupdf_fitz_Separations_disableSeparation + (JNIEnv *, jobject, jint, jboolean); + +/* + * Class: com_artifex_mupdf_fitz_Separations + * Method: isSeparationDisabled + * Signature: (I)Z + */ +JNIEXPORT jboolean JNICALL Java_com_artifex_mupdf_fitz_Separations_isSeparationDisabled + (JNIEnv *, jobject, jint); + +#ifdef __cplusplus +} +#endif +#endif /* Header for class com_artifex_mupdf_fitz_Shade */ #ifndef _Included_com_artifex_mupdf_fitz_Shade diff --git a/platform/java/src/com/artifex/mupdf/fitz/Page.java b/platform/java/src/com/artifex/mupdf/fitz/Page.java index 60241355..5475e044 100644 --- a/platform/java/src/com/artifex/mupdf/fitz/Page.java +++ b/platform/java/src/com/artifex/mupdf/fitz/Page.java @@ -43,8 +43,5 @@ public class Page public native byte[] textAsHtml(); - public native int countSeparations(); - public native Separation getSeparation(int index); - public native void enableSeparation(int index, boolean enabled); - + public native Separations getSeparations(); } diff --git a/platform/java/src/com/artifex/mupdf/fitz/Separations.java b/platform/java/src/com/artifex/mupdf/fitz/Separations.java new file mode 100644 index 00000000..6b86f3a4 --- /dev/null +++ b/platform/java/src/com/artifex/mupdf/fitz/Separations.java @@ -0,0 +1,27 @@ +package com.artifex.mupdf.fitz; + +public class Separations +{ + private long pointer; + + protected native void finalize(); + + public void destroy() { + finalize(); + pointer = 0; + } + + protected Separations(long p) { + pointer = p; + } + + public native int getNumberOfSeparations(); + + public native Separation getSeparation(int separation); + + public native boolean areSeparationsControllable(); + + public native boolean disableSeparation(int separation, boolean disable); + + public native boolean isSeparationDisabled(int separation); +} |