diff options
author | Sebastian Rasmussen <sebras@gmail.com> | 2016-07-23 16:34:32 +0800 |
---|---|---|
committer | Sebastian Rasmussen <sebras@gmail.com> | 2016-08-02 02:20:45 +0800 |
commit | 147ce438ceb89649028e953bd7456c1fdfd79de2 (patch) | |
tree | 6238ecbabe760b893e1908476010af6a29b9feeb | |
parent | 6d07cc05e97df6b756641cdd24179cfa9934ee41 (diff) | |
download | mupdf-147ce438ceb89649028e953bd7456c1fdfd79de2.tar.xz |
JNI: Add/change PDFDocument.save() related methods.
Added methods:
* PDFDocument.hasUnsavedChanges()
* PDFDocument.canBeSavedIncrementally()
The interface for PDFDocument.save() now returns
the number of errors encountered while saving.
-rw-r--r-- | platform/java/mupdf_native.c | 28 | ||||
-rw-r--r-- | platform/java/mupdf_native.h | 20 | ||||
-rw-r--r-- | platform/java/src/com/artifex/mupdf/fitz/PDFDocument.java | 4 |
3 files changed, 45 insertions, 7 deletions
diff --git a/platform/java/mupdf_native.c b/platform/java/mupdf_native.c index 86731069..f4cf19b8 100644 --- a/platform/java/mupdf_native.c +++ b/platform/java/mupdf_native.c @@ -5886,7 +5886,23 @@ FUN(PDFDocument_addSimpleFont)(JNIEnv *env, jobject self, jobject jfont) return to_PDFObject_safe_own(ctx, env, self, ind); } -JNIEXPORT void JNICALL +JNIEXPORT jboolean JNICALL +FUN(PDFDocument_hasUnsavedChanges)(JNIEnv *env, jobject self) +{ + fz_context *ctx = get_context(env); + pdf_document *pdf = from_PDFDocument(env, self); + return pdf_has_unsaved_changes(ctx, pdf); +} + +JNIEXPORT jboolean JNICALL +FUN(PDFDocument_canBeSavedIncrementally)(JNIEnv *env, jobject self) +{ + fz_context *ctx = get_context(env); + pdf_document *pdf = from_PDFDocument(env, self); + return pdf_can_be_saved_incrementally(ctx, pdf); +} + +JNIEXPORT jint JNICALL FUN(PDFDocument_save)(JNIEnv *env, jobject self, jstring jfilename, jstring joptions) { fz_context *ctx = get_context(env); @@ -5894,24 +5910,26 @@ FUN(PDFDocument_save)(JNIEnv *env, jobject self, jstring jfilename, jstring jopt const char *filename = NULL; const char *options = NULL; pdf_write_options pwo = { 0 }; + int errors = 0; if (ctx == NULL || pdf == NULL || jfilename == NULL) - return; + return 0; filename = (*env)->GetStringUTFChars(env, jfilename, NULL); if (filename == NULL) - return; + return 0; if (joptions != NULL) { options = (*env)->GetStringUTFChars(env, joptions, NULL); if (options == NULL) - return; + return 0; } fz_try(ctx) { pdf_parse_write_options(ctx, &pwo, options); + pwo.errors = &errors; pdf_save_document(ctx, pdf, filename, &pwo); } fz_always(ctx) @@ -5922,6 +5940,8 @@ FUN(PDFDocument_save)(JNIEnv *env, jobject self, jstring jfilename, jstring jopt } fz_catch(ctx) jni_rethrow(env, ctx); + + return errors; } /* PDFObject interface */ diff --git a/platform/java/mupdf_native.h b/platform/java/mupdf_native.h index aad39be2..8fb0ffac 100644 --- a/platform/java/mupdf_native.h +++ b/platform/java/mupdf_native.h @@ -1526,10 +1526,26 @@ JNIEXPORT jobject JNICALL Java_com_artifex_mupdf_fitz_PDFDocument_addFont /* * Class: com_artifex_mupdf_fitz_PDFDocument + * Method: hasUnsavedChanges + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL Java_com_artifex_mupdf_fitz_PDFDocument_hasUnsavedChanges + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_PDFDocument + * Method: canBeSavedIncrementally + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL Java_com_artifex_mupdf_fitz_PDFDocument_canBeSavedIncrementally + (JNIEnv *, jobject); + +/* + * Class: com_artifex_mupdf_fitz_PDFDocument * Method: save - * Signature: (Ljava/lang/String;Ljava/lang/String;)V + * Signature: (Ljava/lang/String;Ljava/lang/String;)I */ -JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_PDFDocument_save +JNIEXPORT jint JNICALL Java_com_artifex_mupdf_fitz_PDFDocument_save (JNIEnv *, jobject, jstring, jstring); #ifdef __cplusplus diff --git a/platform/java/src/com/artifex/mupdf/fitz/PDFDocument.java b/platform/java/src/com/artifex/mupdf/fitz/PDFDocument.java index 507546c5..93fd5ebe 100644 --- a/platform/java/src/com/artifex/mupdf/fitz/PDFDocument.java +++ b/platform/java/src/com/artifex/mupdf/fitz/PDFDocument.java @@ -75,6 +75,8 @@ public class PDFDocument public native PDFObject addImage(Image image); public native PDFObject addSimpleFont(Font font); public native PDFObject addFont(Font font); - public native void save(String filename, String options); + public native boolean hasUnsavedChanges(); + public native boolean canBeSavedIncrementally(); + public native int save(String filename, String options); } |