summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--platform/android/jni/Android.mk2
-rw-r--r--platform/android/jni/Core.mk2
-rw-r--r--platform/android/jni/mupdf.c42
3 files changed, 33 insertions, 13 deletions
diff --git a/platform/android/jni/Android.mk b/platform/android/jni/Android.mk
index d7ce897f..81be571a 100644
--- a/platform/android/jni/Android.mk
+++ b/platform/android/jni/Android.mk
@@ -20,7 +20,7 @@ LOCAL_C_INCLUDES := \
LOCAL_CFLAGS :=
LOCAL_MODULE := mupdf
LOCAL_SRC_FILES := mupdf.c
-LOCAL_STATIC_LIBRARIES := mupdfcore mupdfcore2 mupdfthirdparty
+LOCAL_STATIC_LIBRARIES := mupdfcore mupdfthirdparty
ifdef NDK_PROFILER
LOCAL_CFLAGS += -pg -DNDK_PROFILER
LOCAL_STATIC_LIBRARIES += andprof
diff --git a/platform/android/jni/Core.mk b/platform/android/jni/Core.mk
index 71ebb8e7..6a5b2365 100644
--- a/platform/android/jni/Core.mk
+++ b/platform/android/jni/Core.mk
@@ -55,7 +55,7 @@ LOCAL_SRC_FILES := \
$(wildcard $(MY_ROOT)/source/tiff/*.c)
LOCAL_SRC_FILES += \
$(MY_ROOT)/source/pdf/js/pdf-js.c \
- $(MY_ROOT)/source/pdf/js/pdf-jsimp-mu.cpp
+ $(MY_ROOT)/source/pdf/js/pdf-jsimp-mu.c
ifdef MEMENTO
LOCAL_SRC_FILES += $(MY_ROOT)/fitz/memento.c
endif
diff --git a/platform/android/jni/mupdf.c b/platform/android/jni/mupdf.c
index 15470509..d9252842 100644
--- a/platform/android/jni/mupdf.c
+++ b/platform/android/jni/mupdf.c
@@ -335,12 +335,21 @@ JNI_FN(MuPDFCore_openFile)(JNIEnv * env, jobject thiz, jstring jfilename)
return (jlong)(void *)glo;
}
-static int bufferStreamRead(fz_stream *stream, unsigned char *buf, int len)
+typedef struct buffer_state_s
{
- globals *glo = (globals *)stream->state;
+ globals *globals;
+ char buffer[4096];
+}
+buffer_state;
+
+static int bufferStreamNext(fz_stream *stream, int max)
+{
+ buffer_state *bs = (buffer_state *)stream->state;
+ globals *glo = bs->globals;
JNIEnv *env = glo->env;
jbyteArray array = (jbyteArray)(void *)((*env)->GetObjectField(env, glo->thiz, buffer_fid));
int arrayLength = (*env)->GetArrayLength(env, array);
+ int len = sizeof(bs->buffer);
if (stream->pos > arrayLength)
stream->pos = arrayLength;
@@ -349,19 +358,25 @@ static int bufferStreamRead(fz_stream *stream, unsigned char *buf, int len)
if (len + stream->pos > arrayLength)
len = arrayLength - stream->pos;
- (*env)->GetByteArrayRegion(env, array, stream->pos, len, buf);
+ (*env)->GetByteArrayRegion(env, array, stream->pos, len, bs->buffer);
(*env)->DeleteLocalRef(env, array);
- return len;
+
+ stream->rp = bs->buffer;
+ stream->wp = stream->rp + len;
+ if (len == 0)
+ return EOF;
+ return *stream->rp++;
}
static void bufferStreamClose(fz_context *ctx, void *state)
{
- /* Nothing to do */
+ fz_free(ctx, state);
}
static void bufferStreamSeek(fz_stream *stream, int offset, int whence)
{
- globals *glo = (globals *)stream->state;
+ buffer_state *bs = (buffer_state *)stream->state;
+ globals *glo = bs->globals;
JNIEnv *env = glo->env;
jbyteArray array = (jbyteArray)(void *)((*env)->GetObjectField(env, glo->thiz, buffer_fid));
int arrayLength = (*env)->GetArrayLength(env, array);
@@ -380,8 +395,7 @@ static void bufferStreamSeek(fz_stream *stream, int offset, int whence)
if (stream->pos < 0)
stream->pos = 0;
- stream->rp = stream->bp;
- stream->wp = stream->bp;
+ stream->wp = stream->rp;
}
JNIEXPORT jlong JNICALL
@@ -390,7 +404,8 @@ JNI_FN(MuPDFCore_openBuffer)(JNIEnv * env, jobject thiz)
globals *glo;
fz_context *ctx;
jclass clazz;
- fz_stream *stream;
+ fz_stream *stream = NULL;
+ buffer_state *bs;
#ifdef NDK_PROFILER
monstartup("libmupdf.so");
@@ -417,10 +432,14 @@ JNI_FN(MuPDFCore_openBuffer)(JNIEnv * env, jobject thiz)
return 0;
}
+ fz_var(stream);
+
glo->doc = NULL;
fz_try(ctx)
{
- stream = fz_new_stream(ctx, glo, bufferStreamRead, bufferStreamClose, NULL);
+ bs = fz_malloc_struct(ctx, buffer_state);
+ bs->globals = glo;
+ stream = fz_new_stream(ctx, bs, bufferStreamNext, bufferStreamClose, NULL);
stream->seek = bufferStreamSeek;
glo->colorspace = fz_device_rgb(ctx);
@@ -576,7 +595,8 @@ JNIEXPORT jboolean JNICALL
JNI_FN(MuPDFCore_javascriptSupported)(JNIEnv *env, jobject thiz)
{
globals *glo = get_globals(env, thiz);
- return pdf_js_supported(glo->doc);
+ pdf_document *idoc = pdf_specifics(glo->doc);
+ return pdf_js_supported(idoc);
}
static void update_changed_rects(globals *glo, page_cache *pc, pdf_document *idoc)