summaryrefslogtreecommitdiff
path: root/platform/java
diff options
context:
space:
mode:
authorfred ross-perry <fredross-perry@Fred-Ross-Perrys-Computer.local>2016-09-01 10:28:20 -0700
committerfred ross-perry <fredross-perry@Fred-Ross-Perrys-Computer.local>2016-09-14 09:10:04 -0700
commit2369a34a21788e3d330d329ca077f7cbaa4571e5 (patch)
tree82351d9f7a9aadcfa057d10faf5f03201918fde0 /platform/java
parentffbe3db71ea0f96b408e22418547a8ff898f380e (diff)
downloadmupdf-2369a34a21788e3d330d329ca077f7cbaa4571e5.tar.xz
Android example - Add proofing support.
Diffstat (limited to 'platform/java')
-rw-r--r--platform/java/mupdf_native.c203
-rw-r--r--platform/java/mupdf_native.h51
-rw-r--r--platform/java/src/com/artifex/mupdf/fitz/Context.java1
-rw-r--r--platform/java/src/com/artifex/mupdf/fitz/Document.java11
-rw-r--r--platform/java/src/com/artifex/mupdf/fitz/Page.java5
-rw-r--r--platform/java/src/com/artifex/mupdf/fitz/Separation.java15
6 files changed, 286 insertions, 0 deletions
diff --git a/platform/java/mupdf_native.c b/platform/java/mupdf_native.c
index 1b21d3c0..3427e021 100644
--- a/platform/java/mupdf_native.c
+++ b/platform/java/mupdf_native.c
@@ -697,6 +697,16 @@ FUN(Context_initNative)(JNIEnv *env, jclass cls)
return 0;
}
+JNIEXPORT jint JNICALL
+FUN(Context_gprfSupportedNative)(JNIEnv * env, jclass class)
+{
+#ifdef FZ_ENABLE_GPRF
+ return JNI_TRUE;
+#else
+ return JNI_FALSE;
+#endif
+}
+
/* Conversion functions: C to Java. These all throw fitz exceptions. */
static inline jobject to_Annotation(fz_context *ctx, JNIEnv *env, fz_annot *annot)
@@ -3658,6 +3668,118 @@ FUN(Annotation_toDisplayList)(JNIEnv *env, jobject self)
/* Document interface */
+static char *tmp_gproof_path(const char *path)
+{
+ FILE *f;
+ int i;
+ char *buf = malloc(strlen(path) + 20 + 1);
+ if (!buf)
+ return NULL;
+
+ for (i = 0; i < 10000; i++)
+ {
+ sprintf(buf, "%s.%d.gproof", path, i);
+
+ LOGE("Trying for %s\n", buf);
+ f = fopen(buf, "r");
+ if (f != NULL)
+ {
+ fclose(f);
+ continue;
+ }
+
+ f = fopen(buf, "w");
+ if (f != NULL)
+ {
+ fclose(f);
+ break;
+ }
+ }
+ if (i == 10000)
+ {
+ LOGE("Failed to find temp gproof name");
+ free(buf);
+ return NULL;
+ }
+
+ LOGE("Rewritten to %s\n", buf);
+ return buf;
+}
+
+JNIEXPORT jstring JNICALL
+FUN(Document_proofNative)(JNIEnv *env, jobject self, jstring jCurrentPath, jstring jPrintProfile, jstring jDisplayProfile, int inResolution)
+{
+#ifdef FZ_ENABLE_GPRF
+
+ fz_context *ctx = get_context(env);
+ fz_document *doc = from_Document(env, self);
+
+ char *tmp;
+ jstring ret;
+ const char *currentPath = NULL;
+ const char *printProfile = NULL;
+ const char *displayProfile = NULL;
+
+ if (ctx == NULL || doc == NULL || jCurrentPath == NULL || jPrintProfile == NULL || jDisplayProfile == NULL)
+ return NULL;
+
+ currentPath = (*env)->GetStringUTFChars(env, jCurrentPath, NULL);
+ if (currentPath == NULL)
+ {
+ jni_throw(env, FZ_ERROR_GENERIC, "Document_proofNative failed");
+ return NULL;
+ }
+
+ printProfile = (*env)->GetStringUTFChars(env, jPrintProfile, NULL);
+ if (printProfile == NULL)
+ {
+ jni_throw(env, FZ_ERROR_GENERIC, "Document_proofNative failed");
+ (*env)->ReleaseStringUTFChars(env, jCurrentPath, currentPath);
+ return NULL;
+ }
+
+ displayProfile = (*env)->GetStringUTFChars(env, jDisplayProfile, NULL);
+ if (displayProfile == NULL)
+ {
+ (*env)->ReleaseStringUTFChars(env, jCurrentPath, currentPath);
+ (*env)->ReleaseStringUTFChars(env, jPrintProfile, printProfile);
+ jni_throw(env, FZ_ERROR_GENERIC, "Document_proofNative failed");
+ return NULL;
+ }
+
+ tmp = tmp_gproof_path(currentPath);
+ if (!tmp)
+ {
+ (*env)->ReleaseStringUTFChars(env, jCurrentPath, currentPath);
+ (*env)->ReleaseStringUTFChars(env, jPrintProfile, printProfile);
+ (*env)->ReleaseStringUTFChars(env, jDisplayProfile, displayProfile);
+ return NULL;
+ }
+
+ fz_try(ctx)
+ {
+ LOGE("Creating %s\n", tmp);
+ fz_save_gproof(ctx, currentPath, doc, tmp, inResolution, printProfile, displayProfile);
+ ret = (*env)->NewStringUTF(env, tmp);
+ }
+ fz_always(ctx)
+ {
+ free(tmp);
+ (*env)->ReleaseStringUTFChars(env, jCurrentPath, currentPath);
+ (*env)->ReleaseStringUTFChars(env, jPrintProfile, printProfile);
+ (*env)->ReleaseStringUTFChars(env, jDisplayProfile, displayProfile);
+ }
+ fz_catch(ctx)
+ {
+ jni_rethrow(env, ctx);
+ return NULL;
+ }
+ return ret;
+#else
+ return NULL;
+#endif
+}
+
JNIEXPORT void JNICALL
FUN(Document_finalize)(JNIEnv *env, jobject self)
{
@@ -3928,6 +4050,87 @@ FUN(Page_finalize)(JNIEnv *env, jobject self)
fz_drop_page(ctx, page);
}
+JNIEXPORT int 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==NULL || page==NULL)
+ {
+ LOGI("Page_countSeparations fail %x %x", (unsigned int)ctx, (unsigned int)page);
+ return 0;
+ }
+
+ nSep = fz_count_separations_on_page(ctx, page);
+
+ LOGI("Page_countSeparations %d", nSep);
+
+ return nSep;
+}
+
+JNIEXPORT void JNICALL
+FUN(Page_enableSeparation)(JNIEnv *env, jobject self, int sep, jboolean enable)
+{
+ fz_context *ctx = get_context(env);
+ fz_page *page = from_Page(env, self);
+ int i;
+
+ if (ctx==NULL || page==NULL)
+ {
+ LOGI("Page_enableSeparation fail %x %x", (unsigned int)ctx, (unsigned int)page);
+ return;
+ }
+
+ fz_control_separation_on_page(ctx, page, sep, !enable);
+}
+
+JNIEXPORT jobject JNICALL
+FUN(Page_getSeparation)(JNIEnv *env, jobject self, int sep)
+{
+ 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;
+ jclass sepClass;
+ jmethodID ctor;
+ int i;
+ int err;
+
+ if (ctx==NULL || page==NULL)
+ {
+ LOGI("Page_getSeparation fail %x %x", (unsigned int)ctx, (unsigned int)page);
+ return 0;
+ }
+
+ err = 0;
+ sepClass = get_class(&err, env, PKG"Separation");
+ if (sepClass == NULL)
+ {
+ LOGI("Page_getSeparation failed to get class for Separation");
+ return NULL;
+ }
+
+ ctor = (*env)->GetMethodID(env, sepClass, "<init>", "(Ljava/lang/String;II)V");
+ if (ctor == NULL)
+ {
+ LOGI("Page_getSeparation failed to get ctor for Separation");
+ return NULL;
+ }
+
+ /* 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);
+ jname = name ? (*env)->NewStringUTF(env, name) : NULL;
+
+ return (*env)->NewObject(env, sepClass, ctor, jname, bgra, cmyk);
+}
+
JNIEXPORT jobject JNICALL
FUN(Page_toPixmap)(JNIEnv *env, jobject self, jobject jctm, jobject jcs, jboolean alpha)
{
diff --git a/platform/java/mupdf_native.h b/platform/java/mupdf_native.h
index d674c715..6807d27c 100644
--- a/platform/java/mupdf_native.h
+++ b/platform/java/mupdf_native.h
@@ -282,6 +282,14 @@ extern "C" {
JNIEXPORT jint JNICALL Java_com_artifex_mupdf_fitz_Context_initNative
(JNIEnv *, jclass);
+/*
+ * Class: com_artifex_mupdf_fitz_Context
+ * Method: gprfSupportedNative
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_com_artifex_mupdf_fitz_Context_gprfSupportedNative
+ (JNIEnv *, jclass);
+
#ifdef __cplusplus
}
#endif
@@ -689,6 +697,14 @@ JNIEXPORT jboolean JNICALL Java_com_artifex_mupdf_fitz_Document_isUnencryptedPDF
JNIEXPORT jobject JNICALL Java_com_artifex_mupdf_fitz_Document_toPDFDocument
(JNIEnv *, jobject);
+/*
+ * Class: com_artifex_mupdf_fitz_Document
+ * Method: proofNative
+ * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_com_artifex_mupdf_fitz_Document_proofNative
+ (JNIEnv *, jobject, jstring, jstring, jstring, jint);
+
#ifdef __cplusplus
}
#endif
@@ -2093,6 +2109,30 @@ JNIEXPORT jobjectArray JNICALL Java_com_artifex_mupdf_fitz_Page_search
JNIEXPORT jbyteArray JNICALL Java_com_artifex_mupdf_fitz_Page_textAsHtml
(JNIEnv *, jobject);
+/*
+ * Class: com_artifex_mupdf_fitz_Page
+ * Method: countSeparations
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_com_artifex_mupdf_fitz_Page_countSeparations
+ (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
@@ -2419,6 +2459,17 @@ extern "C" {
}
#endif
#endif
+/* Header for class com_artifex_mupdf_fitz_Separation */
+
+#ifndef _Included_com_artifex_mupdf_fitz_Separation
+#define _Included_com_artifex_mupdf_fitz_Separation
+#ifdef __cplusplus
+extern "C" {
+#endif
+#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/Context.java b/platform/java/src/com/artifex/mupdf/fitz/Context.java
index 3614e65f..d8edf378 100644
--- a/platform/java/src/com/artifex/mupdf/fitz/Context.java
+++ b/platform/java/src/com/artifex/mupdf/fitz/Context.java
@@ -10,6 +10,7 @@ public class Context
{
private static boolean inited = false;
private static native int initNative();
+ public static native int gprfSupportedNative();
public static void init() {
if (!inited) {
diff --git a/platform/java/src/com/artifex/mupdf/fitz/Document.java b/platform/java/src/com/artifex/mupdf/fitz/Document.java
index b3c42e35..d619f4a2 100644
--- a/platform/java/src/com/artifex/mupdf/fitz/Document.java
+++ b/platform/java/src/com/artifex/mupdf/fitz/Document.java
@@ -24,7 +24,10 @@ public class Document
private native long newNativeWithBuffer(byte buffer[], String magic);
// private native long newNativeWithRandomAccessFile(RandomAccessFile file, String magic);
+ private String mPath=null;
+ public String getPath() {return mPath;}
public Document(String filename) {
+ mPath = filename;
pointer = newNativeWithPath(filename);
}
@@ -49,4 +52,12 @@ public class Document
public native boolean isUnencryptedPDF();
public native PDFDocument toPDFDocument();
+
+ public String makeProof (String currentPath, String printProfile, String displayProfile, int resolution)
+ {
+ String proofFile = proofNative( currentPath, printProfile, displayProfile, resolution);
+ return proofFile;
+ }
+
+ public native String proofNative (String currentPath, String printProfile, String displayProfile, int resolution);
}
diff --git a/platform/java/src/com/artifex/mupdf/fitz/Page.java b/platform/java/src/com/artifex/mupdf/fitz/Page.java
index b42935c5..85a3aca8 100644
--- a/platform/java/src/com/artifex/mupdf/fitz/Page.java
+++ b/platform/java/src/com/artifex/mupdf/fitz/Page.java
@@ -38,4 +38,9 @@ public class Page
public native Rect[] search(String needle);
public native byte[] textAsHtml();
+
+ public native int countSeparations();
+ public native Separation getSeparation(int index);
+ public native void enableSeparation(int index, boolean enabled);
+
}
diff --git a/platform/java/src/com/artifex/mupdf/fitz/Separation.java b/platform/java/src/com/artifex/mupdf/fitz/Separation.java
new file mode 100644
index 00000000..5da7157b
--- /dev/null
+++ b/platform/java/src/com/artifex/mupdf/fitz/Separation.java
@@ -0,0 +1,15 @@
+package com.artifex.mupdf.fitz;
+
+public class Separation
+{
+ public String name;
+ public int rgba;
+ public int cmyk;
+
+ public Separation(String name, int rgba, int cmyk)
+ {
+ this.name = name;
+ this.rgba = rgba;
+ this.cmyk = cmyk;
+ }
+}