summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2015-07-14 16:35:12 +0100
committerRobin Watts <robin.watts@artifex.com>2015-07-20 17:19:04 +0100
commit28432abe9a2fcdb47750c0e49cb484c615f5a883 (patch)
treefdc545552883f44558d0aea3bc2fbbfb346e455f /platform
parent269fdfce2527cbba02e68d658af3f4b92ef40be0 (diff)
downloadmupdf-28432abe9a2fcdb47750c0e49cb484c615f5a883.tar.xz
Add Proofing button to Android UI.
Hit the proofing button, and we create a new temporary .gproof file. We invoke a new version of MuPDF on that. When that finishes control returns to us, and we delete the .gproof file. Currently the new version of MuPDF loads the .gproof file, but fails to generate any pages from it, as we have no version of ghostscript on the system. Generating this new ghostscript is the next job.
Diffstat (limited to 'platform')
-rw-r--r--platform/android/jni/mupdf.c92
-rw-r--r--platform/android/res/drawable-ldpi/ic_proof.pngbin0 -> 1229 bytes
-rw-r--r--platform/android/res/drawable-mdpi/ic_proof.pngbin0 -> 1244 bytes
-rw-r--r--platform/android/res/layout/buttons.xml11
-rw-r--r--platform/android/res/values/strings.xml1
-rw-r--r--platform/android/src/com/artifex/mupdfdemo/MuPDFActivity.java17
-rw-r--r--platform/android/src/com/artifex/mupdfdemo/MuPDFCore.java11
7 files changed, 132 insertions, 0 deletions
diff --git a/platform/android/jni/mupdf.c b/platform/android/jni/mupdf.c
index 7a5b90f8..add5598e 100644
--- a/platform/android/jni/mupdf.c
+++ b/platform/android/jni/mupdf.c
@@ -36,6 +36,7 @@
#define LINE_THICKNESS (0.07f)
#define INK_THICKNESS (4.0f)
#define SMALL_FLOAT (0.00001)
+#define PROOF_RESOLUTION (300)
enum
{
@@ -2675,3 +2676,94 @@ JNI_FN(MuPDFCore_abortCookie)(JNIEnv * env, jobject thiz, jlong cookiePtr)
if (cookie != NULL)
cookie->abort = 1;
}
+
+static char *tmp_gproof_path(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
+JNI_FN(MuPDFCore_startProofInternal)(JNIEnv * env, jobject thiz)
+{
+ globals *glo = get_globals(env, thiz);
+ fz_context *ctx = glo->ctx;
+ char *tmp;
+ jstring ret;
+
+ if (!glo->doc || !glo->current_path)
+ return NULL;
+
+ tmp = tmp_gproof_path(glo->current_path);
+ if (!tmp)
+ return NULL;
+
+ fz_try(ctx)
+ {
+ fz_write_gproof_file(ctx, glo->current_path, glo->doc, tmp, PROOF_RESOLUTION);
+
+ LOGE("Creating %s\n", tmp);
+ ret = (*env)->NewStringUTF(env, tmp);
+ }
+ fz_always(ctx)
+ {
+ free(tmp);
+ }
+ fz_catch(ctx)
+ {
+ ret = NULL;
+ }
+ return ret;
+}
+
+JNIEXPORT void JNICALL
+JNI_FN(MuPDFCore_endProofInternal)(JNIEnv * env, jobject thiz, jstring jfilename)
+{
+ globals *glo = get_globals(env, thiz);
+ fz_context *ctx = glo->ctx;
+ const char *tmp;
+
+ if (!glo->doc || !glo->current_path || jfilename == NULL)
+ return;
+
+ tmp = (*env)->GetStringUTFChars(env, jfilename, NULL);
+ if (tmp)
+ {
+ LOGE("Deleting %s\n", tmp);
+
+ unlink(tmp);
+ (*env)->ReleaseStringUTFChars(env, jfilename, tmp);
+ }
+}
diff --git a/platform/android/res/drawable-ldpi/ic_proof.png b/platform/android/res/drawable-ldpi/ic_proof.png
new file mode 100644
index 00000000..fee26a7b
--- /dev/null
+++ b/platform/android/res/drawable-ldpi/ic_proof.png
Binary files differ
diff --git a/platform/android/res/drawable-mdpi/ic_proof.png b/platform/android/res/drawable-mdpi/ic_proof.png
new file mode 100644
index 00000000..61d94587
--- /dev/null
+++ b/platform/android/res/drawable-mdpi/ic_proof.png
Binary files differ
diff --git a/platform/android/res/layout/buttons.xml b/platform/android/res/layout/buttons.xml
index 98eddc22..12de40c6 100644
--- a/platform/android/res/layout/buttons.xml
+++ b/platform/android/res/layout/buttons.xml
@@ -259,6 +259,17 @@
android:src="@drawable/ic_cancel" />
<ImageButton
+ android:id="@+id/proofButton"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_centerVertical="true"
+ android:layout_toLeftOf="@+id/printButton"
+ android:contentDescription="@string/proof"
+ android:background="@drawable/button"
+ android:onClick="OnProofButtonClick"
+ android:src="@drawable/ic_proof" />
+
+ <ImageButton
android:id="@+id/printButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
diff --git a/platform/android/res/values/strings.xml b/platform/android/res/values/strings.xml
index f20316e2..dcff35f4 100644
--- a/platform/android/res/values/strings.xml
+++ b/platform/android/res/values/strings.xml
@@ -25,6 +25,7 @@
<string name="edit_annotations">Edit annotations</string>
<string name="ink">Ink</string>
<string name="save">Save</string>
+ <string name="proof">Proof</string>
<string name="print">Print</string>
<string name="dismiss">Dismiss</string>
<string name="parent_directory">[Up one level]</string>
diff --git a/platform/android/src/com/artifex/mupdfdemo/MuPDFActivity.java b/platform/android/src/com/artifex/mupdfdemo/MuPDFActivity.java
index 58ea1aa3..172c189a 100644
--- a/platform/android/src/com/artifex/mupdfdemo/MuPDFActivity.java
+++ b/platform/android/src/com/artifex/mupdfdemo/MuPDFActivity.java
@@ -50,6 +50,7 @@ public class MuPDFActivity extends Activity implements FilePicker.FilePickerSupp
private final int OUTLINE_REQUEST=0;
private final int PRINT_REQUEST=1;
private final int FILEPICK_REQUEST=2;
+ private final int PROOF_REQUEST=3;
private MuPDFCore core;
private String mFileName;
private MuPDFReaderView mDocView;
@@ -83,6 +84,7 @@ public class MuPDFActivity extends Activity implements FilePicker.FilePickerSupp
private AsyncTask<Void,Void,MuPDFAlert> mAlertTask;
private AlertDialog mAlertDialog;
private FilePicker mFilePicker;
+ private String mProofFile;
public void createAlertWaiter() {
mAlertsActive = true;
@@ -621,6 +623,12 @@ public class MuPDFActivity extends Activity implements FilePicker.FilePickerSupp
case FILEPICK_REQUEST:
if (mFilePicker != null && resultCode == RESULT_OK)
mFilePicker.onPick(data.getData());
+ case PROOF_REQUEST:
+ if (mProofFile != null)
+ {
+ core.endProof(mProofFile);
+ mProofFile = null;
+ }
}
super.onActivityResult(requestCode, resultCode, data);
}
@@ -899,6 +907,15 @@ public class MuPDFActivity extends Activity implements FilePicker.FilePickerSupp
printDoc();
}
+ public void OnProofButtonClick(View v) {
+ mProofFile = core.startProof();
+ Uri uri = Uri.parse("file://"+mProofFile);
+ Intent intent = new Intent(this,MuPDFActivity.class);
+ intent.setAction(Intent.ACTION_VIEW);
+ intent.setData(uri);
+ startActivityForResult(intent, PROOF_REQUEST);
+ }
+
public void OnCopyTextButtonClick(View v) {
mTopBarMode = TopBarMode.Accept;
mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal());
diff --git a/platform/android/src/com/artifex/mupdfdemo/MuPDFCore.java b/platform/android/src/com/artifex/mupdfdemo/MuPDFCore.java
index be6f6fbf..ffab6782 100644
--- a/platform/android/src/com/artifex/mupdfdemo/MuPDFCore.java
+++ b/platform/android/src/com/artifex/mupdfdemo/MuPDFCore.java
@@ -6,6 +6,7 @@ import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.PointF;
import android.graphics.RectF;
+import android.content.Intent;
public class MuPDFCore
{
@@ -77,6 +78,8 @@ public class MuPDFCore
private native long createCookie();
private native void destroyCookie(long cookie);
private native void abortCookie(long cookie);
+ private native String startProofInternal();
+ private native void endProofInternal(String filename);
public native boolean javascriptSupported();
@@ -346,4 +349,12 @@ public class MuPDFCore
public synchronized void save() {
saveInternal();
}
+
+ public synchronized String startProof() {
+ return startProofInternal();
+ }
+
+ public synchronized void endProof(String filename) {
+ endProofInternal(filename);
+ }
}