Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/main/cpp/mainJNILib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,38 @@ JNI_FUNC(jlong, PdfiumCore, nativeGetBookmarkDestIndex)(JNI_ARGS, jlong docPtr,
return FPDFDest_GetDestPageIndex(doc->pdfDocument, dest);
}

JNI_FUNC(jfloatArray, PdfiumCore, nativeGetBookmarkDestCoords)(JNI_ARGS, jlong docPtr, jlong bookmarkPtr) {
DocumentFile *doc = reinterpret_cast<DocumentFile*>(docPtr);
FPDF_BOOKMARK bookmark = reinterpret_cast<FPDF_BOOKMARK>(bookmarkPtr);

FPDF_DEST dest = FPDFBookmark_GetDest(doc->pdfDocument, bookmark);
if (dest == NULL) {
return NULL;
}

FPDF_BOOL hasX, hasY, hasZoom;
FS_FLOAT x, y, zoom;

FPDF_BOOL success = FPDFDest_GetLocationInPage(dest, &hasX, &hasY, &hasZoom, &x, &y, &zoom);
if (!success) {
return NULL;
}

// Return array: [hasX, x, hasY, y, hasZoom, zoom]
jfloatArray result = env->NewFloatArray(6);
if (result == NULL) {
return NULL;
}

jfloat buf[6] = {
(jfloat)hasX, (jfloat)x,
(jfloat)hasY, (jfloat)y,
(jfloat)hasZoom, (jfloat)zoom
};
env->SetFloatArrayRegion(result, 0, 6, buf);
return result;
}

JNI_FUNC(jlongArray, PdfiumCore, nativeGetPageLinks)(JNI_ARGS, jlong pagePtr) {
FPDF_PAGE page = reinterpret_cast<FPDF_PAGE>(pagePtr);
int pos = 0;
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/shockwave/pdfium/PdfDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public static class Bookmark {
long pageIdx;
long mNativePtr;

// Destination coordinates (null if not specified in PDF)
Float destX;
Float destY;
Float destZoom;

public List<Bookmark> getChildren() {
return children;
}
Expand All @@ -75,6 +80,18 @@ public String getTitle() {
public long getPageIdx() {
return pageIdx;
}

public Float getDestX() {
return destX;
}

public Float getDestY() {
return destY;
}

public Float getDestZoom() {
return destZoom;
}
}

public static class Link {
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/shockwave/pdfium/PdfiumCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ private native void nativeRenderPageBitmap(long pagePtr, Bitmap bitmap, int dpi,

private native long nativeGetBookmarkDestIndex(long docPtr, long bookmarkPtr);

private native float[] nativeGetBookmarkDestCoords(long docPtr, long bookmarkPtr);

private native Size nativeGetPageSizeByIndex(long docPtr, int pageIndex, int dpi);

private native long[] nativeGetPageLinks(long pagePtr);
Expand Down Expand Up @@ -376,6 +378,15 @@ private void recursiveGetBookmark(List<PdfDocument.Bookmark> tree, PdfDocument d
bookmark.mNativePtr = bookmarkPtr;
bookmark.title = nativeGetBookmarkTitle(bookmarkPtr);
bookmark.pageIdx = nativeGetBookmarkDestIndex(doc.mNativeDocPtr, bookmarkPtr);

/* If destination coordinates are avaliable, extract them */
float[] coords = nativeGetBookmarkDestCoords(doc.mNativeDocPtr, bookmarkPtr);
if (coords != null && coords.length == 6) {
if (coords[0] != 0) bookmark.destX = coords[1];
if (coords[2] != 0) bookmark.destY = coords[3];
if (coords[4] != 0) bookmark.destZoom = coords[5];
}

tree.add(bookmark);

Long child = nativeGetFirstChildBookmark(doc.mNativeDocPtr, bookmarkPtr);
Expand Down