[gs-commits] mupdf 1.16.1.105 jni: Expose API for saving document acce
[email protected] (Tor Andersson) Tue, 22 Oct 2019 11:29:12 +0000 (UTC)
| Newsgroups | gmane.comp.printing.ghostscript.cvs |
|---|---|
| Message-ID | <[email protected]> |
commit 2f1914e3ff50aedb69beca136de3758cf25224a4 Author: Sebastian Rasmussen <[email protected]> Date: Fri Oct 18 20:39:09 2019 +0200 jni: Expose API for saving document accelerator. diff --git a/platform/java/mupdf_native.c b/platform/java/mupdf_native.c index efbab59..5063398 100644 --- a/platform/java/mupdf_native.c +++ b/platform/java/mupdf_native.c @@ -5415,6 +5415,86 @@ FUN(Document_recognize)(JNIEnv *env, jclass self, jstring jmagic) return recognized; } +JNIEXPORT void JNICALL +FUN(Document_saveAccelerator)(JNIEnv *env, jobject self, jstring jfilename) +{ + fz_context *ctx = get_context(env); + fz_document *doc = from_Document(env, self); + const char *filename = "null"; + + if (!ctx || !doc) return; + if (!jfilename) { jni_throw_arg(env, "filename must not be null"); return; } + + filename = (*env)->GetStringUTFChars(env, jfilename, NULL); + if (!filename) return; + + fz_try(ctx) + fz_save_accelerator(ctx, doc, filename); + fz_always(ctx) + (*env)->ReleaseStringUTFChars(env, jfilename, filename); + fz_catch(ctx) + jni_rethrow(env, ctx); +} + +JNIEXPORT void JNICALL +FUN(Document_outputAccelerator)(JNIEnv *env, jobject self, jobject jstream) +{ + fz_context *ctx = get_context(env); + fz_document *doc = from_Document(env, self); + SeekableStreamState *state = NULL; + jobject stream = NULL; + jbyteArray array = NULL; + fz_output *out; + + fz_var(state); + fz_var(out); + fz_var(stream); + fz_var(array); + + stream = (*env)->NewGlobalRef(env, jstream); + if (!stream) + return; + + array = (*env)->NewByteArray(env, sizeof state->buffer); + if (array) + array = (*env)->NewGlobalRef(env, array); + if (!array) + { + (*env)->DeleteGlobalRef(env, stream); + return; + } + + fz_try(ctx) + { + state = fz_malloc(ctx, sizeof(SeekableStreamState)); + state->stream = stream; + state->array = array; + + out = fz_new_output(ctx, 8192, state, SeekableOutputStream_write, NULL, SeekableOutputStream_drop); + out->seek = SeekableOutputStream_seek; + out->tell = SeekableOutputStream_tell; + + /* these are now owned by 'out' */ + state = NULL; + stream = NULL; + array = NULL; + + fz_output_accelerator(ctx, doc, out); + fz_close_output(ctx, out); + } + fz_always(ctx) + { + fz_drop_output(ctx, out); + } + fz_catch(ctx) + { + (*env)->DeleteGlobalRef(env, stream); + (*env)->DeleteGlobalRef(env, array); + fz_free(ctx, state); + jni_rethrow(env, ctx); + } +} + JNIEXPORT jboolean JNICALL FUN(Document_needsPassword)(JNIEnv *env, jobject self) { diff --git a/platform/java/mupdf_native.h b/platform/java/mupdf_native.h index a67d631..555ba50 100644 --- a/platform/java/mupdf_native.h +++ b/platform/java/mupdf_native.h @@ -476,6 +476,22 @@ JNIEXPORT jboolean JNICALL Java_com_artifex_mupdf_fitz_Document_recognize /* * Class: com_artifex_mupdf_fitz_Document + * Method: saveAccelerator + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Document_saveAccelerator + (JNIEnv *, jobject, jstring); + +/* + * Class: com_artifex_mupdf_fitz_Document + * Method: outputAccelerator + * Signature: (Lcom/artifex/mupdf/fitz/SeekableOutputStream;)V + */ +JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Document_outputAccelerator + (JNIEnv *, jobject, jobject); + +/* + * Class: com_artifex_mupdf_fitz_Document * Method: needsPassword * Signature: ()Z */ diff --git a/platform/java/src/com/artifex/mupdf/fitz/Document.java b/platform/java/src/com/artifex/mupdf/fitz/Document.java index 1d8ab10..19eef4f 100644 --- a/platform/java/src/com/artifex/mupdf/fitz/Document.java +++ b/platform/java/src/com/artifex/mupdf/fitz/Document.java @@ -59,10 +59,12 @@ public class Document public static native boolean recognize(String magic); + public native void saveAccelerator(String filename); + public native void outputAccelerator(SeekableOutputStream stream); + public native boolean needsPassword(); public native boolean authenticatePassword(String password); - public native int countChapters(); public native int countPages(int chapter); public native Page loadPage(int chapter, int number); http://git.ghostscript.com/?p=mupdf.git;a=commit;h=2f1914e3ff50aedb69beca136de3758cf25224a4 -- MuPDF library Artifex Software, Inc.