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 03714b4 commit 985e349
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/papaya_pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* updf super class
*/
/** @noinspection PhpIncludeInspection */
require_once(dirname(__FILE__).'/external/fpdf/ufpdf.php');
require_once __DIR__.'/external/fpdf/ufpdf.php';

/**
* Implement FPDF/FPDI for papaya CMS
Expand Down Expand Up @@ -539,22 +539,20 @@ 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 ($nb == 0) {
if (0 === $nb) {
return;
}
$lru = array();
$level = 0;
//header('Content-type: text/plain');
foreach ($this->outlines as $i => $o) {
//fix indent if here is a level missing
if ($o['l'] > 0 && $o['l'] - 1 >= $level) {
$o['l'] = $level + 1;
$this->outlines[$i] = $o;
}
if ($o['l'] > 0) {
if ($o['l'] > 0 && isset($lru[$o['l'] - 1])) {
$parent = $lru[$o['l'] - 1];
//Set parent and last pointers
$this->outlines[$i]['parent'] = $parent;
Expand All @@ -566,7 +564,7 @@ function prepareBookmarks() {
} else {
$this->outlines[$i]['parent'] = $nb;
}
if ($o['l'] <= $level && $i > 0) {
if ($i > 0 && $o['l'] <= $level && isset($lru[$o['l']])) {
//Set prev and next pointers
$prev = $lru[$o['l']];
$this->outlines[$prev]['next'] = $i;
Expand Down

0 comments on commit 985e349

Please sign in to comment.