summaryrefslogtreecommitdiff
path: root/platform/java
diff options
context:
space:
mode:
Diffstat (limited to 'platform/java')
-rw-r--r--platform/java/example/Viewer.java4
-rw-r--r--platform/java/mupdf_native.c36
-rw-r--r--platform/java/mupdf_native.h16
-rw-r--r--platform/java/src/com/artifex/mupdf/fitz/Document.java3
4 files changed, 57 insertions, 2 deletions
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
@@ -683,6 +683,22 @@ JNIEXPORT void JNICALL Java_com_artifex_mupdf_fitz_Document_layout
/*
* 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
* 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 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();