From commits-return-14224-archive-asf-public=cust-asf.ponee.io@pdfbox.apache.org Tue Feb 12 18:07:53 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 72ABD180675 for ; Tue, 12 Feb 2019 19:07:52 +0100 (CET) Received: (qmail 64549 invoked by uid 500); 12 Feb 2019 18:07:51 -0000 Mailing-List: contact commits-help@pdfbox.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@pdfbox.apache.org Delivered-To: mailing list commits@pdfbox.apache.org Received: (qmail 64540 invoked by uid 99); 12 Feb 2019 18:07:51 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 Feb 2019 18:07:51 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 197613A0917 for ; Tue, 12 Feb 2019 18:07:51 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1853463 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/documentnavigation/destination/PDPageDestination.java Date: Tue, 12 Feb 2019 18:07:51 -0000 To: commits@pdfbox.apache.org From: tilman@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20190212180751.197613A0917@svn01-us-west.apache.org> Author: tilman Date: Tue Feb 12 18:07:50 2019 New Revision: 1853463 URL: http://svn.apache.org/viewvc?rev=1853463&view=rev Log: PDFBOX-4459: make sure we have hit a pages node (previous code returned 0 on an isolated page) Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/documentnavigation/destination/PDPageDestination.java Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/documentnavigation/destination/PDPageDestination.java URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/documentnavigation/destination/PDPageDestination.java?rev=1853463&r1=1853462&r2=1853463&view=diff ============================================================================== --- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/documentnavigation/destination/PDPageDestination.java (original) +++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/documentnavigation/destination/PDPageDestination.java Tue Feb 12 18:07:50 2019 @@ -165,20 +165,29 @@ public abstract class PDPageDestination } else if (page instanceof COSDictionary) { - //TODO make this a static utility method of PDPageTree? - COSBase parent = page; - while (((COSDictionary) parent).getDictionaryObject(COSName.PARENT, COSName.P) != null) - { - parent = ((COSDictionary) parent).getDictionaryObject(COSName.PARENT, COSName.P); - } - // now parent is the pages node - PDPageTree pages = new PDPageTree((COSDictionary) parent); - return pages.indexOf(new PDPage((COSDictionary) page)); + return indexOfPageTree((COSDictionary) page); } } return retval; } + // climb up the page tree up to the top to be able to call PageTree.indexOf for a page dictionary + private int indexOfPageTree(COSDictionary pageDict) + { + COSDictionary parent = pageDict; + while (parent.getDictionaryObject(COSName.PARENT, COSName.P) instanceof COSDictionary) + { + parent = (COSDictionary) parent.getDictionaryObject(COSName.PARENT, COSName.P); + } + if (parent.containsKey(COSName.KIDS) && COSName.PAGES.equals(parent.getItem(COSName.TYPE))) + { + // now parent is the highest pages node + PDPageTree pages = new PDPageTree(parent); + return pages.indexOf(new PDPage(pageDict)); + } + return -1; + } + /** * Set the page number for a remote destination. For an internal destination, call * {@link #setPage(PDPage) setPage(PDPage page)}.