Skip to content

Commit

Permalink
Fix bookmarks navigation if parent is missing for child
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasWeinert committed May 9, 2018
1 parent 985e349 commit 78d1ec7
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/papaya_pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,10 @@ function addBookmark($txt, $level = 0, $y = -1, $pageNo = 0) {
/**
* pre process bookmarks, optimize level structure
* @return void
*/ function prepareBookmarks() {
*/
function prepareBookmarks() {
$nb = count($this->outlines);
if (0 === $nb) {
if ($nb == 0) {
return;
}
$lru = array();
Expand All @@ -552,8 +553,8 @@ function addBookmark($txt, $level = 0, $y = -1, $pageNo = 0) {
$o['l'] = $level + 1;
$this->outlines[$i] = $o;
}
if ($o['l'] > 0 && isset($lru[$o['l'] - 1])) {
$parent = $lru[$o['l'] - 1];
$parent = isset($lru[$o['l'] - 1]) ? $lru[$o['l'] - 1] : $nb;
if ($o['l'] > 0 && isset($this->outlines[$parent])) {
//Set parent and last pointers
$this->outlines[$i]['parent'] = $parent;
$this->outlines[$parent]['last'] = $i;
Expand All @@ -564,10 +565,12 @@ function addBookmark($txt, $level = 0, $y = -1, $pageNo = 0) {
} else {
$this->outlines[$i]['parent'] = $nb;
}
if ($i > 0 && $o['l'] <= $level && isset($lru[$o['l']])) {
if ($o['l'] <= $level && $i > 0 && isset($lru[$o['l']])) {
//Set prev and next pointers
$prev = $lru[$o['l']];
$this->outlines[$prev]['next'] = $i;
if (isset($this->outlines[$prev])) {
$this->outlines[$prev]['next'] = $i;
}
$this->outlines[$i]['prev'] = $prev;
}
$lru[$o['l']] = $i;
Expand Down

0 comments on commit 78d1ec7

Please sign in to comment.