From c100c4c77a88782ba5c4634994171db611952d44 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 2 Feb 2017 15:55:40 +0100 Subject: Add bookmarks so we can find a location after reflowing a document. --- platform/java/example/Viewer.java | 4 +-- platform/java/mupdf_native.c | 36 ++++++++++++++++++++++ platform/java/mupdf_native.h | 16 ++++++++++ .../java/src/com/artifex/mupdf/fitz/Document.java | 3 ++ 4 files changed, 57 insertions(+), 2 deletions(-) (limited to 'platform/java') diff --git a/platform/java/example/Viewer.java b/platform/java/example/Viewer.java index 1361a538..a924cf4b 100644 --- a/platform/java/example/Viewer.java +++ b/platform/java/example/Viewer.java @@ -383,12 +383,12 @@ public class Viewer extends Frame implements WindowListener, ActionListener, Ite } if (layoutEm != oldLayoutEm) { - float oldPos = (pageNumber + 0.5f) / (float)pageCount; + long mark = doc.makeBookmark(pageNumber); doc.layout(layoutWidth, layoutHeight, layoutEm); updateOutline(); pageCount = doc.countPages(); pageLabel.setText("/ " + pageCount); - pageNumber = (int)(oldPos * pageCount); + pageNumber = doc.findBookmark(mark); } if (zoomLevel != oldZoomLevel || pageNumber != oldPageNumber || layoutEm != oldLayoutEm || searchHits != oldSearchHits) diff --git a/platform/java/mupdf_native.c b/platform/java/mupdf_native.c index cbb3dd7a..aec932c4 100644 --- a/platform/java/mupdf_native.c +++ b/platform/java/mupdf_native.c @@ -4222,6 +4222,42 @@ FUN(Document_loadOutline)(JNIEnv *env, jobject self) return joutline; } +JNIEXPORT jlong JNICALL +FUN(Document_makeBookmark)(JNIEnv *env, jobject self, jint page) +{ + fz_context *ctx = get_context(env); + fz_document *doc = from_Document(env, self); + fz_bookmark mark = 0; + + fz_try(ctx) + mark = fz_make_bookmark(ctx, doc, page); + fz_catch(ctx) + { + jni_rethrow(env, ctx); + return 0; + } + + return mark; +} + +JNIEXPORT jint JNICALL +FUN(Document_findBookmark)(JNIEnv *env, jobject self, jlong mark) +{ + fz_context *ctx = get_context(env); + fz_document *doc = from_Document(env, self); + int page = -1; + + fz_try(ctx) + page = fz_lookup_bookmark(ctx, doc, mark); + fz_catch(ctx) + { + jni_rethrow(env, ctx); + return -1; + } + + return page; +} + JNIEXPORT jobject JNICALL FUN(Document_toPDFDocument)(JNIEnv *env, jobject self) { diff --git a/platform/java/mupdf_native.h b/platform/java/mupdf_native.h index 3e6c51b3..8b0b2fe3 100644 --- a/platform/java/mupdf_native.h +++ b/platform/java/mupdf_native.h @@ -681,6 +681,22 @@ JNIEXPORT jboolean JNICALL Java_com_artifex_mupdf_fitz_Document_isReflowable JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Document_layout (JNIEnv *, jobject, jfloat, jfloat, jfloat); +/* + * Class: com_artifex_mupdf_fitz_Document + * Method: makeBookmark + * Signature: (I)J + */ +JNIEXPORT jlong JNICALL Java_com_artifex_mupdf_fitz_Document_makeBookmark + (JNIEnv *, jobject, jint); + +/* + * Class: com_artifex_mupdf_fitz_Document + * Method: findBookmark + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_com_artifex_mupdf_fitz_Document_findBookmark + (JNIEnv *, jobject, jlong); + /* * Class: com_artifex_mupdf_fitz_Document * Method: isUnencryptedPDF diff --git a/platform/java/src/com/artifex/mupdf/fitz/Document.java b/platform/java/src/com/artifex/mupdf/fitz/Document.java index 29cad4db..1fc21c13 100644 --- a/platform/java/src/com/artifex/mupdf/fitz/Document.java +++ b/platform/java/src/com/artifex/mupdf/fitz/Document.java @@ -49,6 +49,9 @@ public class Document public native boolean isReflowable(); public native void layout(float width, float height, float em); + public native long makeBookmark(int page); + public native int findBookmark(long mark); + public native boolean isUnencryptedPDF(); public native PDFDocument toPDFDocument(); -- cgit v1.2.3