/wp-content/plugins/dk-pdf/vendor/mpdf/mpdf/src/TableOfContents.php

https://github.com/livinglab/openlab · PHP · 856 lines · 753 code · 85 blank · 18 comment · 330 complexity · f12340a47acfed5bca16d3c8580811da MD5 · raw file

  1. <?php
  2. namespace Mpdf;
  3. class TableOfContents
  4. {
  5. private $mpdf;
  6. private $sizeConverter;
  7. var $_toc;
  8. var $TOCmark;
  9. var $TOCoutdent; // mPDF 5.6.31
  10. var $TOCpreHTML;
  11. var $TOCpostHTML;
  12. var $TOCbookmarkText;
  13. var $TOCusePaging;
  14. var $TOCuseLinking;
  15. var $TOCorientation;
  16. var $TOC_margin_left;
  17. var $TOC_margin_right;
  18. var $TOC_margin_top;
  19. var $TOC_margin_bottom;
  20. var $TOC_margin_header;
  21. var $TOC_margin_footer;
  22. var $TOC_odd_header_name;
  23. var $TOC_even_header_name;
  24. var $TOC_odd_footer_name;
  25. var $TOC_even_footer_name;
  26. var $TOC_odd_header_value;
  27. var $TOC_even_header_value;
  28. var $TOC_odd_footer_value;
  29. var $TOC_even_footer_value;
  30. var $TOC_page_selector;
  31. var $TOC_resetpagenum; // mPDF 6
  32. var $TOC_pagenumstyle; // mPDF 6
  33. var $TOC_suppress; // mPDF 6
  34. var $TOCsheetsize;
  35. var $m_TOC;
  36. public function __construct(Mpdf $mpdf, SizeConverter $sizeConverter)
  37. {
  38. $this->mpdf = $mpdf;
  39. $this->sizeConverter = $sizeConverter;
  40. $this->_toc = [];
  41. $this->TOCmark = 0;
  42. $this->m_TOC = [];
  43. }
  44. public function TOCpagebreak(
  45. $tocfont = '',
  46. $tocfontsize = '',
  47. $tocindent = '',
  48. $TOCusePaging = true,
  49. $TOCuseLinking = '',
  50. $toc_orientation = '',
  51. $toc_mgl = '',
  52. $toc_mgr = '',
  53. $toc_mgt = '',
  54. $toc_mgb = '',
  55. $toc_mgh = '',
  56. $toc_mgf = '',
  57. $toc_ohname = '',
  58. $toc_ehname = '',
  59. $toc_ofname = '',
  60. $toc_efname = '',
  61. $toc_ohvalue = 0,
  62. $toc_ehvalue = 0,
  63. $toc_ofvalue = 0,
  64. $toc_efvalue = 0,
  65. $toc_preHTML = '',
  66. $toc_postHTML = '',
  67. $toc_bookmarkText = '',
  68. $resetpagenum = '',
  69. $pagenumstyle = '',
  70. $suppress = '',
  71. $orientation = '',
  72. $mgl = '',
  73. $mgr = '',
  74. $mgt = '',
  75. $mgb = '',
  76. $mgh = '',
  77. $mgf = '',
  78. $ohname = '',
  79. $ehname = '',
  80. $ofname = '',
  81. $efname = '',
  82. $ohvalue = 0,
  83. $ehvalue = 0,
  84. $ofvalue = 0,
  85. $efvalue = 0,
  86. $toc_id = 0,
  87. $pagesel = '',
  88. $toc_pagesel = '',
  89. $sheetsize = '',
  90. $toc_sheetsize = '',
  91. $tocoutdent = '',
  92. $toc_resetpagenum = '',
  93. $toc_pagenumstyle = '',
  94. $toc_suppress = ''
  95. ) {
  96. if (strtoupper($toc_id) == 'ALL') {
  97. $toc_id = '_mpdf_all';
  98. } else if (!$toc_id) {
  99. $toc_id = 0;
  100. } else {
  101. $toc_id = strtolower($toc_id);
  102. }
  103. if ($TOCusePaging === false || strtolower($TOCusePaging) == "off" || $TOCusePaging === 0 || $TOCusePaging === "0" || $TOCusePaging === "") {
  104. $TOCusePaging = false;
  105. } else {
  106. $TOCusePaging = true;
  107. }
  108. if (!$TOCuseLinking) {
  109. $TOCuseLinking = false;
  110. }
  111. if ($toc_id) {
  112. $this->m_TOC[$toc_id]['TOCmark'] = $this->mpdf->page;
  113. $this->m_TOC[$toc_id]['TOCoutdent'] = $tocoutdent;
  114. $this->m_TOC[$toc_id]['TOCorientation'] = $toc_orientation;
  115. $this->m_TOC[$toc_id]['TOCuseLinking'] = $TOCuseLinking;
  116. $this->m_TOC[$toc_id]['TOCusePaging'] = $TOCusePaging;
  117. if ($toc_preHTML) {
  118. $this->m_TOC[$toc_id]['TOCpreHTML'] = $toc_preHTML;
  119. }
  120. if ($toc_postHTML) {
  121. $this->m_TOC[$toc_id]['TOCpostHTML'] = $toc_postHTML;
  122. }
  123. if ($toc_bookmarkText) {
  124. $this->m_TOC[$toc_id]['TOCbookmarkText'] = $toc_bookmarkText;
  125. }
  126. $this->m_TOC[$toc_id]['TOC_margin_left'] = $toc_mgl;
  127. $this->m_TOC[$toc_id]['TOC_margin_right'] = $toc_mgr;
  128. $this->m_TOC[$toc_id]['TOC_margin_top'] = $toc_mgt;
  129. $this->m_TOC[$toc_id]['TOC_margin_bottom'] = $toc_mgb;
  130. $this->m_TOC[$toc_id]['TOC_margin_header'] = $toc_mgh;
  131. $this->m_TOC[$toc_id]['TOC_margin_footer'] = $toc_mgf;
  132. $this->m_TOC[$toc_id]['TOC_odd_header_name'] = $toc_ohname;
  133. $this->m_TOC[$toc_id]['TOC_even_header_name'] = $toc_ehname;
  134. $this->m_TOC[$toc_id]['TOC_odd_footer_name'] = $toc_ofname;
  135. $this->m_TOC[$toc_id]['TOC_even_footer_name'] = $toc_efname;
  136. $this->m_TOC[$toc_id]['TOC_odd_header_value'] = $toc_ohvalue;
  137. $this->m_TOC[$toc_id]['TOC_even_header_value'] = $toc_ehvalue;
  138. $this->m_TOC[$toc_id]['TOC_odd_footer_value'] = $toc_ofvalue;
  139. $this->m_TOC[$toc_id]['TOC_even_footer_value'] = $toc_efvalue;
  140. $this->m_TOC[$toc_id]['TOC_page_selector'] = $toc_pagesel;
  141. $this->m_TOC[$toc_id]['TOC_resetpagenum'] = $toc_resetpagenum; // mPDF 6
  142. $this->m_TOC[$toc_id]['TOC_pagenumstyle'] = $toc_pagenumstyle; // mPDF 6
  143. $this->m_TOC[$toc_id]['TOC_suppress'] = $toc_suppress; // mPDF 6
  144. $this->m_TOC[$toc_id]['TOCsheetsize'] = $toc_sheetsize;
  145. } else {
  146. $this->TOCmark = $this->mpdf->page;
  147. $this->TOCoutdent = $tocoutdent;
  148. $this->TOCorientation = $toc_orientation;
  149. $this->TOCuseLinking = $TOCuseLinking;
  150. $this->TOCusePaging = $TOCusePaging;
  151. if ($toc_preHTML) {
  152. $this->TOCpreHTML = $toc_preHTML;
  153. }
  154. if ($toc_postHTML) {
  155. $this->TOCpostHTML = $toc_postHTML;
  156. }
  157. if ($toc_bookmarkText) {
  158. $this->TOCbookmarkText = $toc_bookmarkText;
  159. }
  160. $this->TOC_margin_left = $toc_mgl;
  161. $this->TOC_margin_right = $toc_mgr;
  162. $this->TOC_margin_top = $toc_mgt;
  163. $this->TOC_margin_bottom = $toc_mgb;
  164. $this->TOC_margin_header = $toc_mgh;
  165. $this->TOC_margin_footer = $toc_mgf;
  166. $this->TOC_odd_header_name = $toc_ohname;
  167. $this->TOC_even_header_name = $toc_ehname;
  168. $this->TOC_odd_footer_name = $toc_ofname;
  169. $this->TOC_even_footer_name = $toc_efname;
  170. $this->TOC_odd_header_value = $toc_ohvalue;
  171. $this->TOC_even_header_value = $toc_ehvalue;
  172. $this->TOC_odd_footer_value = $toc_ofvalue;
  173. $this->TOC_even_footer_value = $toc_efvalue;
  174. $this->TOC_page_selector = $toc_pagesel;
  175. $this->TOC_resetpagenum = $toc_resetpagenum; // mPDF 6
  176. $this->TOC_pagenumstyle = $toc_pagenumstyle; // mPDF 6
  177. $this->TOC_suppress = $toc_suppress; // mPDF 6
  178. $this->TOCsheetsize = $toc_sheetsize;
  179. }
  180. }
  181. /**
  182. * Initiate, and Mark a place for the Table of Contents to be inserted
  183. */
  184. public function TOC(
  185. $tocfont = '',
  186. $tocfontsize = 0,
  187. $tocindent = 0,
  188. $resetpagenum = '',
  189. $pagenumstyle = '',
  190. $suppress = '',
  191. $toc_orientation = '',
  192. $TOCusePaging = true,
  193. $TOCuseLinking = false,
  194. $toc_id = 0,
  195. $tocoutdent = '',
  196. $toc_resetpagenum = '',
  197. $toc_pagenumstyle = '',
  198. $toc_suppress = ''
  199. ) {
  200. if (strtoupper($toc_id) == 'ALL') {
  201. $toc_id = '_mpdf_all';
  202. } else if (!$toc_id) {
  203. $toc_id = 0;
  204. } else {
  205. $toc_id = strtolower($toc_id);
  206. }
  207. // To use odd and even pages
  208. // Cannot start table of contents on an even page
  209. if (($this->mpdf->mirrorMargins) && (($this->mpdf->page) % 2 == 0)) { // EVEN
  210. if ($this->mpdf->ColActive) {
  211. if (count($this->mpdf->columnbuffer)) {
  212. $this->mpdf->printcolumnbuffer();
  213. }
  214. }
  215. $this->mpdf->AddPage($this->mpdf->CurOrientation, '', $resetpagenum, $pagenumstyle, $suppress);
  216. } else {
  217. $this->mpdf->PageNumSubstitutions[] = ['from' => $this->mpdf->page, 'reset' => $resetpagenum, 'type' => $pagenumstyle, 'suppress' => $suppress];
  218. }
  219. if ($toc_id) {
  220. $this->m_TOC[$toc_id]['TOCmark'] = $this->mpdf->page;
  221. $this->m_TOC[$toc_id]['TOCoutdent'] = $tocoutdent;
  222. $this->m_TOC[$toc_id]['TOCorientation'] = $toc_orientation;
  223. $this->m_TOC[$toc_id]['TOCuseLinking'] = $TOCuseLinking;
  224. $this->m_TOC[$toc_id]['TOCusePaging'] = $TOCusePaging;
  225. $this->m_TOC[$toc_id]['TOC_resetpagenum'] = $toc_resetpagenum; // mPDF 6
  226. $this->m_TOC[$toc_id]['TOC_pagenumstyle'] = $toc_pagenumstyle; // mPDF 6
  227. $this->m_TOC[$toc_id]['TOC_suppress'] = $toc_suppress; // mPDF 6
  228. } else {
  229. $this->TOCmark = $this->mpdf->page;
  230. $this->TOCoutdent = $tocoutdent;
  231. $this->TOCorientation = $toc_orientation;
  232. $this->TOCuseLinking = $TOCuseLinking;
  233. $this->TOCusePaging = $TOCusePaging;
  234. $this->TOC_resetpagenum = $toc_resetpagenum; // mPDF 6
  235. $this->TOC_pagenumstyle = $toc_pagenumstyle; // mPDF 6
  236. $this->TOC_suppress = $toc_suppress; // mPDF 6
  237. }
  238. }
  239. public function insertTOC()
  240. {
  241. $notocs = 0;
  242. if ($this->TOCmark) {
  243. $notocs = 1;
  244. }
  245. $notocs += count($this->m_TOC);
  246. if ($notocs == 0) {
  247. return;
  248. }
  249. if (count($this->m_TOC)) {
  250. reset($this->m_TOC);
  251. }
  252. $added_toc_pages = 0;
  253. if ($this->mpdf->ColActive) {
  254. $this->mpdf->SetColumns(0);
  255. }
  256. if (($this->mpdf->mirrorMargins) && (($this->mpdf->page) % 2 == 1)) { // ODD
  257. $this->mpdf->AddPage($this->mpdf->CurOrientation);
  258. $extrapage = true;
  259. } else {
  260. $extrapage = false;
  261. }
  262. for ($toci = 0; $toci < $notocs; $toci++) {
  263. if ($toci == 0 && $this->TOCmark) {
  264. $toc_id = 0;
  265. $toc_page = $this->TOCmark;
  266. $tocoutdent = $this->TOCoutdent;
  267. $toc_orientation = $this->TOCorientation;
  268. $TOCuseLinking = $this->TOCuseLinking;
  269. $TOCusePaging = $this->TOCusePaging;
  270. $toc_preHTML = $this->TOCpreHTML;
  271. $toc_postHTML = $this->TOCpostHTML;
  272. $toc_bookmarkText = $this->TOCbookmarkText;
  273. $toc_mgl = $this->TOC_margin_left;
  274. $toc_mgr = $this->TOC_margin_right;
  275. $toc_mgt = $this->TOC_margin_top;
  276. $toc_mgb = $this->TOC_margin_bottom;
  277. $toc_mgh = $this->TOC_margin_header;
  278. $toc_mgf = $this->TOC_margin_footer;
  279. $toc_ohname = $this->TOC_odd_header_name;
  280. $toc_ehname = $this->TOC_even_header_name;
  281. $toc_ofname = $this->TOC_odd_footer_name;
  282. $toc_efname = $this->TOC_even_footer_name;
  283. $toc_ohvalue = $this->TOC_odd_header_value;
  284. $toc_ehvalue = $this->TOC_even_header_value;
  285. $toc_ofvalue = $this->TOC_odd_footer_value;
  286. $toc_efvalue = $this->TOC_even_footer_value;
  287. $toc_page_selector = $this->TOC_page_selector;
  288. $toc_resetpagenum = $this->TOC_resetpagenum; // mPDF 6
  289. $toc_pagenumstyle = $this->TOC_pagenumstyle; // mPDF 6
  290. $toc_suppress = $this->TOC_suppress; // mPDF 6
  291. $toc_sheet_size = (isset($this->TOCsheetsize) ? $this->TOCsheetsize : '');
  292. } else {
  293. $arr = current($this->m_TOC);
  294. $toc_id = key($this->m_TOC);
  295. $toc_page = $this->m_TOC[$toc_id]['TOCmark'];
  296. $tocoutdent = $this->m_TOC[$toc_id]['TOCoutdent'];
  297. $toc_orientation = $this->m_TOC[$toc_id]['TOCorientation'];
  298. $TOCuseLinking = $this->m_TOC[$toc_id]['TOCuseLinking'];
  299. $TOCusePaging = $this->m_TOC[$toc_id]['TOCusePaging'];
  300. if (isset($this->m_TOC[$toc_id]['TOCpreHTML'])) {
  301. $toc_preHTML = $this->m_TOC[$toc_id]['TOCpreHTML'];
  302. } else {
  303. $toc_preHTML = '';
  304. }
  305. if (isset($this->m_TOC[$toc_id]['TOCpostHTML'])) {
  306. $toc_postHTML = $this->m_TOC[$toc_id]['TOCpostHTML'];
  307. } else {
  308. $toc_postHTML = '';
  309. }
  310. if (isset($this->m_TOC[$toc_id]['TOCbookmarkText'])) {
  311. $toc_bookmarkText = $this->m_TOC[$toc_id]['TOCbookmarkText'];
  312. } else {
  313. $toc_bookmarkText = '';
  314. } // *BOOKMARKS*
  315. $toc_mgl = $this->m_TOC[$toc_id]['TOC_margin_left'];
  316. $toc_mgr = $this->m_TOC[$toc_id]['TOC_margin_right'];
  317. $toc_mgt = $this->m_TOC[$toc_id]['TOC_margin_top'];
  318. $toc_mgb = $this->m_TOC[$toc_id]['TOC_margin_bottom'];
  319. $toc_mgh = $this->m_TOC[$toc_id]['TOC_margin_header'];
  320. $toc_mgf = $this->m_TOC[$toc_id]['TOC_margin_footer'];
  321. $toc_ohname = $this->m_TOC[$toc_id]['TOC_odd_header_name'];
  322. $toc_ehname = $this->m_TOC[$toc_id]['TOC_even_header_name'];
  323. $toc_ofname = $this->m_TOC[$toc_id]['TOC_odd_footer_name'];
  324. $toc_efname = $this->m_TOC[$toc_id]['TOC_even_footer_name'];
  325. $toc_ohvalue = $this->m_TOC[$toc_id]['TOC_odd_header_value'];
  326. $toc_ehvalue = $this->m_TOC[$toc_id]['TOC_even_header_value'];
  327. $toc_ofvalue = $this->m_TOC[$toc_id]['TOC_odd_footer_value'];
  328. $toc_efvalue = $this->m_TOC[$toc_id]['TOC_even_footer_value'];
  329. $toc_page_selector = $this->m_TOC[$toc_id]['TOC_page_selector'];
  330. $toc_resetpagenum = $this->m_TOC[$toc_id]['TOC_resetpagenum']; // mPDF 6
  331. $toc_pagenumstyle = $this->m_TOC[$toc_id]['TOC_pagenumstyle']; // mPDF 6
  332. $toc_suppress = $this->m_TOC[$toc_id]['TOC_suppress']; // mPDF 6
  333. $toc_sheet_size = (isset($this->m_TOC[$toc_id]['TOCsheetsize']) ? $this->m_TOC[$toc_id]['TOCsheetsize'] : '');
  334. next($this->m_TOC);
  335. }
  336. // mPDF 5.6.31
  337. if (!$toc_orientation) {
  338. $toc_orientation = $this->mpdf->DefOrientation;
  339. }
  340. // mPDF 6 number style and suppress now picked up from section preceding ToC
  341. list($tp_pagenumstyle, $tp_suppress, $tp_reset) = $this->mpdf->docPageSettings($toc_page - 1);
  342. if ($toc_resetpagenum) {
  343. $tp_reset = $toc_resetpagenum; // mPDF 6
  344. }
  345. if ($toc_pagenumstyle) {
  346. $tp_pagenumstyle = $toc_pagenumstyle; // mPDF 6
  347. }
  348. if ($toc_suppress || $toc_suppress === '0') {
  349. $tp_suppress = $toc_suppress; // mPDF 6
  350. }
  351. $this->mpdf->AddPage($toc_orientation, '', $tp_reset, $tp_pagenumstyle, $tp_suppress, $toc_mgl, $toc_mgr, $toc_mgt, $toc_mgb, $toc_mgh, $toc_mgf, $toc_ohname, $toc_ehname, $toc_ofname, $toc_efname, $toc_ohvalue, $toc_ehvalue, $toc_ofvalue, $toc_efvalue, $toc_page_selector, $toc_sheet_size); // mPDF 6
  352. $this->mpdf->writingToC = true; // mPDF 5.6.38
  353. // mPDF 5.6.31
  354. $tocstart = count($this->mpdf->pages);
  355. if (isset($toc_preHTML) && $toc_preHTML) {
  356. $this->mpdf->WriteHTML($toc_preHTML);
  357. }
  358. // mPDF 5.6.19
  359. $html = '<div class="mpdf_toc" id="mpdf_toc_' . $toc_id . '">';
  360. foreach ($this->_toc as $t) {
  361. if ($t['toc_id'] === '_mpdf_all' || $t['toc_id'] === $toc_id) {
  362. $html .= '<div class="mpdf_toc_level_' . $t['l'] . '">';
  363. if ($TOCuseLinking) {
  364. $html .= '<a class="mpdf_toc_a" href="#__mpdfinternallink_' . $t['link'] . '">';
  365. }
  366. $html .= '<span class="mpdf_toc_t_level_' . $t['l'] . '">' . $t['t'] . '</span>';
  367. if ($TOCuseLinking) {
  368. $html .= '</a>';
  369. }
  370. if (!$tocoutdent) {
  371. $tocoutdent = '0';
  372. }
  373. if ($TOCusePaging) {
  374. $html .= ' <dottab outdent="' . $tocoutdent . '" /> ';
  375. if ($TOCuseLinking) {
  376. $html .= '<a class="mpdf_toc_a" href="#__mpdfinternallink_' . $t['link'] . '">';
  377. }
  378. $html .= '<span class="mpdf_toc_p_level_' . $t['l'] . '">' . $this->mpdf->docPageNum($t['p']) . '</span>';
  379. if ($TOCuseLinking) {
  380. $html .= '</a>';
  381. }
  382. }
  383. $html .= '</div>';
  384. }
  385. }
  386. $html .= '</div>';
  387. $this->mpdf->WriteHTML($html);
  388. if (isset($toc_postHTML) && $toc_postHTML) {
  389. $this->mpdf->WriteHTML($toc_postHTML);
  390. }
  391. $this->mpdf->writingToC = false; // mPDF 5.6.38
  392. $this->mpdf->AddPage($toc_orientation, 'E');
  393. $n_toc = $this->mpdf->page - $tocstart + 1;
  394. if ($toci == 0 && $this->TOCmark) {
  395. $TOC_start = $tocstart;
  396. $TOC_end = $this->mpdf->page;
  397. $TOC_npages = $n_toc;
  398. } else {
  399. $this->m_TOC[$toc_id]['start'] = $tocstart;
  400. $this->m_TOC[$toc_id]['end'] = $this->mpdf->page;
  401. $this->m_TOC[$toc_id]['npages'] = $n_toc;
  402. }
  403. }
  404. $s = '';
  405. $s .= $this->mpdf->PrintBodyBackgrounds();
  406. $s .= $this->mpdf->PrintPageBackgrounds();
  407. $this->mpdf->pages[$this->mpdf->page] = preg_replace('/(___BACKGROUND___PATTERNS' . $this->mpdf->uniqstr . ')/', "\n" . $s . "\n" . '\\1', $this->mpdf->pages[$this->mpdf->page]);
  408. $this->mpdf->pageBackgrounds = [];
  409. //Page footer
  410. $this->mpdf->InFooter = true;
  411. $this->mpdf->Footer();
  412. $this->mpdf->InFooter = false;
  413. // 2nd time through to move pages etc.
  414. $added_toc_pages = 0;
  415. if (count($this->m_TOC)) {
  416. reset($this->m_TOC);
  417. }
  418. for ($toci = 0; $toci < $notocs; $toci++) {
  419. if ($toci == 0 && $this->TOCmark) {
  420. $toc_id = 0;
  421. $toc_page = $this->TOCmark + $added_toc_pages;
  422. $toc_orientation = $this->TOCorientation;
  423. $TOCuseLinking = $this->TOCuseLinking;
  424. $TOCusePaging = $this->TOCusePaging;
  425. $toc_bookmarkText = $this->TOCbookmarkText; // *BOOKMARKS*
  426. $tocstart = $TOC_start;
  427. $tocend = $n = $TOC_end;
  428. $n_toc = $TOC_npages;
  429. } else {
  430. $arr = current($this->m_TOC);
  431. $toc_id = key($this->m_TOC);
  432. $toc_page = $this->m_TOC[$toc_id]['TOCmark'] + $added_toc_pages;
  433. $toc_orientation = $this->m_TOC[$toc_id]['TOCorientation'];
  434. $TOCuseLinking = $this->m_TOC[$toc_id]['TOCuseLinking'];
  435. $TOCusePaging = $this->m_TOC[$toc_id]['TOCusePaging'];
  436. $toc_bookmarkText = $this->m_TOC[$toc_id]['TOCbookmarkText']; // *BOOKMARKS*
  437. $tocstart = $this->m_TOC[$toc_id]['start'];
  438. $tocend = $n = $this->m_TOC[$toc_id]['end'];
  439. $n_toc = $this->m_TOC[$toc_id]['npages'];
  440. next($this->m_TOC);
  441. }
  442. // Now pages moved
  443. $added_toc_pages += $n_toc;
  444. $this->mpdf->MovePages($toc_page, $tocstart, $tocend);
  445. $this->mpdf->pgsIns[$toc_page] = $tocend - $tocstart + 1;
  446. /* -- BOOKMARKS -- */
  447. // Insert new Bookmark for Bookmark
  448. if ($toc_bookmarkText) {
  449. $insert = -1;
  450. foreach ($this->mpdf->BMoutlines as $i => $o) {
  451. if ($o['p'] < $toc_page) { // i.e. before point of insertion
  452. $insert = $i;
  453. }
  454. }
  455. $txt = $this->mpdf->purify_utf8_text($toc_bookmarkText);
  456. if ($this->mpdf->text_input_as_HTML) {
  457. $txt = $this->mpdf->all_entities_to_utf8($txt);
  458. }
  459. $newBookmark[0] = ['t' => $txt, 'l' => 0, 'y' => 0, 'p' => $toc_page];
  460. array_splice($this->mpdf->BMoutlines, ($insert + 1), 0, $newBookmark);
  461. }
  462. /* -- END BOOKMARKS -- */
  463. }
  464. // Delete empty page that was inserted earlier
  465. if ($extrapage) {
  466. unset($this->mpdf->pages[count($this->mpdf->pages)]);
  467. $this->mpdf->page--; // Reset page pointer
  468. }
  469. }
  470. public function openTagTOC($attr)
  471. {
  472. if (isset($attr['OUTDENT']) && $attr['OUTDENT']) {
  473. $tocoutdent = $attr['OUTDENT'];
  474. } else {
  475. $tocoutdent = '';
  476. } // mPDF 5.6.19
  477. if (isset($attr['RESETPAGENUM']) && $attr['RESETPAGENUM']) {
  478. $resetpagenum = $attr['RESETPAGENUM'];
  479. } else {
  480. $resetpagenum = '';
  481. }
  482. if (isset($attr['PAGENUMSTYLE']) && $attr['PAGENUMSTYLE']) {
  483. $pagenumstyle = $attr['PAGENUMSTYLE'];
  484. } else {
  485. $pagenumstyle = '';
  486. }
  487. if (isset($attr['SUPPRESS']) && $attr['SUPPRESS']) {
  488. $suppress = $attr['SUPPRESS'];
  489. } else {
  490. $suppress = '';
  491. }
  492. if (isset($attr['TOC-ORIENTATION']) && $attr['TOC-ORIENTATION']) {
  493. $toc_orientation = $attr['TOC-ORIENTATION'];
  494. } else {
  495. $toc_orientation = '';
  496. }
  497. if (isset($attr['PAGING']) && (strtoupper($attr['PAGING']) == 'OFF' || $attr['PAGING'] === '0')) {
  498. $paging = false;
  499. } else {
  500. $paging = true;
  501. }
  502. if (isset($attr['LINKS']) && (strtoupper($attr['LINKS']) == 'ON' || $attr['LINKS'] == 1)) {
  503. $links = true;
  504. } else {
  505. $links = false;
  506. }
  507. if (isset($attr['NAME']) && $attr['NAME']) {
  508. $toc_id = strtolower($attr['NAME']);
  509. } else {
  510. $toc_id = 0;
  511. }
  512. $this->TOC('', 0, 0, $resetpagenum, $pagenumstyle, $suppress, $toc_orientation, $paging, $links, $toc_id, $tocoutdent); // mPDF 5.6.19 5.6.31
  513. }
  514. public function openTagTOCPAGEBREAK($attr)
  515. {
  516. if (isset($attr['NAME']) && $attr['NAME']) {
  517. $toc_id = strtolower($attr['NAME']);
  518. } else {
  519. $toc_id = 0;
  520. }
  521. if ($toc_id) {
  522. if (isset($attr['OUTDENT']) && $attr['OUTDENT']) {
  523. $this->m_TOC[$toc_id]['TOCoutdent'] = $attr['OUTDENT'];
  524. } else {
  525. $this->m_TOC[$toc_id]['TOCoutdent'] = '';
  526. } // mPDF 5.6.19
  527. if (isset($attr['TOC-ORIENTATION']) && $attr['TOC-ORIENTATION']) {
  528. $this->m_TOC[$toc_id]['TOCorientation'] = $attr['TOC-ORIENTATION'];
  529. } else {
  530. $this->m_TOC[$toc_id]['TOCorientation'] = '';
  531. }
  532. if (isset($attr['PAGING']) && (strtoupper($attr['PAGING']) == 'OFF' || $attr['PAGING'] === '0')) {
  533. $this->m_TOC[$toc_id]['TOCusePaging'] = false;
  534. } else {
  535. $this->m_TOC[$toc_id]['TOCusePaging'] = true;
  536. }
  537. if (isset($attr['LINKS']) && (strtoupper($attr['LINKS']) == 'ON' || $attr['LINKS'] == 1)) {
  538. $this->m_TOC[$toc_id]['TOCuseLinking'] = true;
  539. } else {
  540. $this->m_TOC[$toc_id]['TOCuseLinking'] = false;
  541. }
  542. $this->m_TOC[$toc_id]['TOC_margin_left'] = $this->m_TOC[$toc_id]['TOC_margin_right'] = $this->m_TOC[$toc_id]['TOC_margin_top'] = $this->m_TOC[$toc_id]['TOC_margin_bottom'] = $this->m_TOC[$toc_id]['TOC_margin_header'] = $this->m_TOC[$toc_id]['TOC_margin_footer'] = '';
  543. if (isset($attr['TOC-MARGIN-RIGHT'])) {
  544. $this->m_TOC[$toc_id]['TOC_margin_right'] = $this->sizeConverter->convert($attr['TOC-MARGIN-RIGHT'], $this->mpdf->w, $this->mpdf->FontSize, false);
  545. }
  546. if (isset($attr['TOC-MARGIN-LEFT'])) {
  547. $this->m_TOC[$toc_id]['TOC_margin_left'] = $this->sizeConverter->convert($attr['TOC-MARGIN-LEFT'], $this->mpdf->w, $this->mpdf->FontSize, false);
  548. }
  549. if (isset($attr['TOC-MARGIN-TOP'])) {
  550. $this->m_TOC[$toc_id]['TOC_margin_top'] = $this->sizeConverter->convert($attr['TOC-MARGIN-TOP'], $this->mpdf->w, $this->mpdf->FontSize, false);
  551. }
  552. if (isset($attr['TOC-MARGIN-BOTTOM'])) {
  553. $this->m_TOC[$toc_id]['TOC_margin_bottom'] = $this->sizeConverter->convert($attr['TOC-MARGIN-BOTTOM'], $this->mpdf->w, $this->mpdf->FontSize, false);
  554. }
  555. if (isset($attr['TOC-MARGIN-HEADER'])) {
  556. $this->m_TOC[$toc_id]['TOC_margin_header'] = $this->sizeConverter->convert($attr['TOC-MARGIN-HEADER'], $this->mpdf->w, $this->mpdf->FontSize, false);
  557. }
  558. if (isset($attr['TOC-MARGIN-FOOTER'])) {
  559. $this->m_TOC[$toc_id]['TOC_margin_footer'] = $this->sizeConverter->convert($attr['TOC-MARGIN-FOOTER'], $this->mpdf->w, $this->mpdf->FontSize, false);
  560. }
  561. $this->m_TOC[$toc_id]['TOC_odd_header_name'] = $this->m_TOC[$toc_id]['TOC_even_header_name'] = $this->m_TOC[$toc_id]['TOC_odd_footer_name'] = $this->m_TOC[$toc_id]['TOC_even_footer_name'] = '';
  562. if (isset($attr['TOC-ODD-HEADER-NAME']) && $attr['TOC-ODD-HEADER-NAME']) {
  563. $this->m_TOC[$toc_id]['TOC_odd_header_name'] = $attr['TOC-ODD-HEADER-NAME'];
  564. }
  565. if (isset($attr['TOC-EVEN-HEADER-NAME']) && $attr['TOC-EVEN-HEADER-NAME']) {
  566. $this->m_TOC[$toc_id]['TOC_even_header_name'] = $attr['TOC-EVEN-HEADER-NAME'];
  567. }
  568. if (isset($attr['TOC-ODD-FOOTER-NAME']) && $attr['TOC-ODD-FOOTER-NAME']) {
  569. $this->m_TOC[$toc_id]['TOC_odd_footer_name'] = $attr['TOC-ODD-FOOTER-NAME'];
  570. }
  571. if (isset($attr['TOC-EVEN-FOOTER-NAME']) && $attr['TOC-EVEN-FOOTER-NAME']) {
  572. $this->m_TOC[$toc_id]['TOC_even_footer_name'] = $attr['TOC-EVEN-FOOTER-NAME'];
  573. }
  574. $this->m_TOC[$toc_id]['TOC_odd_header_value'] = $this->m_TOC[$toc_id]['TOC_even_header_value'] = $this->m_TOC[$toc_id]['TOC_odd_footer_value'] = $this->m_TOC[$toc_id]['TOC_even_footer_value'] = 0;
  575. if (isset($attr['TOC-ODD-HEADER-VALUE']) && ($attr['TOC-ODD-HEADER-VALUE'] == '1' || strtoupper($attr['TOC-ODD-HEADER-VALUE']) == 'ON')) {
  576. $this->m_TOC[$toc_id]['TOC_odd_header_value'] = 1;
  577. } else if (isset($attr['TOC-ODD-HEADER-VALUE']) && ($attr['TOC-ODD-HEADER-VALUE'] == '-1' || strtoupper($attr['TOC-ODD-HEADER-VALUE']) == 'OFF')) {
  578. $this->m_TOC[$toc_id]['TOC_odd_header_value'] = -1;
  579. }
  580. if (isset($attr['TOC-EVEN-HEADER-VALUE']) && ($attr['TOC-EVEN-HEADER-VALUE'] == '1' || strtoupper($attr['TOC-EVEN-HEADER-VALUE']) == 'ON')) {
  581. $this->m_TOC[$toc_id]['TOC_even_header_value'] = 1;
  582. } else if (isset($attr['TOC-EVEN-HEADER-VALUE']) && ($attr['TOC-EVEN-HEADER-VALUE'] == '-1' || strtoupper($attr['TOC-EVEN-HEADER-VALUE']) == 'OFF')) {
  583. $this->m_TOC[$toc_id]['TOC_even_header_value'] = -1;
  584. }
  585. if (isset($attr['TOC-ODD-FOOTER-VALUE']) && ($attr['TOC-ODD-FOOTER-VALUE'] == '1' || strtoupper($attr['TOC-ODD-FOOTER-VALUE']) == 'ON')) {
  586. $this->m_TOC[$toc_id]['TOC_odd_footer_value'] = 1;
  587. } else if (isset($attr['TOC-ODD-FOOTER-VALUE']) && ($attr['TOC-ODD-FOOTER-VALUE'] == '-1' || strtoupper($attr['TOC-ODD-FOOTER-VALUE']) == 'OFF')) {
  588. $this->m_TOC[$toc_id]['TOC_odd_footer_value'] = -1;
  589. }
  590. if (isset($attr['TOC-EVEN-FOOTER-VALUE']) && ($attr['TOC-EVEN-FOOTER-VALUE'] == '1' || strtoupper($attr['TOC-EVEN-FOOTER-VALUE']) == 'ON')) {
  591. $this->m_TOC[$toc_id]['TOC_even_footer_value'] = 1;
  592. } else if (isset($attr['TOC-EVEN-FOOTER-VALUE']) && ($attr['TOC-EVEN-FOOTER-VALUE'] == '-1' || strtoupper($attr['TOC-EVEN-FOOTER-VALUE']) == 'OFF')) {
  593. $this->m_TOC[$toc_id]['TOC_even_footer_value'] = -1;
  594. }
  595. if (isset($attr['TOC-RESETPAGENUM']) && $attr['TOC-RESETPAGENUM']) {
  596. $this->m_TOC[$toc_id]['TOC_resetpagenum'] = $attr['TOC-RESETPAGENUM'];
  597. } else {
  598. $this->m_TOC[$toc_id]['TOC_resetpagenum'] = '';
  599. } // mPDF 6
  600. if (isset($attr['TOC-PAGENUMSTYLE']) && $attr['TOC-PAGENUMSTYLE']) {
  601. $this->m_TOC[$toc_id]['TOC_pagenumstyle'] = $attr['TOC-PAGENUMSTYLE'];
  602. } else {
  603. $this->m_TOC[$toc_id]['TOC_pagenumstyle'] = '';
  604. } // mPDF 6
  605. if (isset($attr['TOC-SUPPRESS']) && ($attr['TOC-SUPPRESS'] || $attr['TOC-SUPPRESS'] === '0')) {
  606. $this->m_TOC[$toc_id]['TOC_suppress'] = $attr['TOC-SUPPRESS'];
  607. } else {
  608. $this->m_TOC[$toc_id]['TOC_suppress'] = '';
  609. } // mPDF 6
  610. if (isset($attr['TOC-PAGE-SELECTOR']) && $attr['TOC-PAGE-SELECTOR']) {
  611. $this->m_TOC[$toc_id]['TOC_page_selector'] = $attr['TOC-PAGE-SELECTOR'];
  612. } else {
  613. $this->m_TOC[$toc_id]['TOC_page_selector'] = '';
  614. }
  615. if (isset($attr['TOC-SHEET-SIZE']) && $attr['TOC-SHEET-SIZE']) {
  616. $this->m_TOC[$toc_id]['TOCsheetsize'] = $attr['TOC-SHEET-SIZE'];
  617. } else {
  618. $this->m_TOC[$toc_id]['TOCsheetsize'] = '';
  619. }
  620. if (isset($attr['TOC-PREHTML']) && $attr['TOC-PREHTML']) {
  621. $this->m_TOC[$toc_id]['TOCpreHTML'] = htmlspecialchars_decode($attr['TOC-PREHTML'], ENT_QUOTES);
  622. }
  623. if (isset($attr['TOC-POSTHTML']) && $attr['TOC-POSTHTML']) {
  624. $this->m_TOC[$toc_id]['TOCpostHTML'] = htmlspecialchars_decode($attr['TOC-POSTHTML'], ENT_QUOTES);
  625. }
  626. if (isset($attr['TOC-BOOKMARKTEXT']) && $attr['TOC-BOOKMARKTEXT']) {
  627. $this->m_TOC[$toc_id]['TOCbookmarkText'] = htmlspecialchars_decode($attr['TOC-BOOKMARKTEXT'], ENT_QUOTES);
  628. } // *BOOKMARKS*
  629. } else {
  630. if (isset($attr['OUTDENT']) && $attr['OUTDENT']) {
  631. $this->TOCoutdent = $attr['OUTDENT'];
  632. } else {
  633. $this->TOCoutdent = '';
  634. } // mPDF 5.6.19
  635. if (isset($attr['TOC-ORIENTATION']) && $attr['TOC-ORIENTATION']) {
  636. $this->TOCorientation = $attr['TOC-ORIENTATION'];
  637. } else {
  638. $this->TOCorientation = '';
  639. }
  640. if (isset($attr['PAGING']) && (strtoupper($attr['PAGING']) == 'OFF' || $attr['PAGING'] === '0')) {
  641. $this->TOCusePaging = false;
  642. } else {
  643. $this->TOCusePaging = true;
  644. }
  645. if (isset($attr['LINKS']) && (strtoupper($attr['LINKS']) == 'ON' || $attr['LINKS'] == 1)) {
  646. $this->TOCuseLinking = true;
  647. } else {
  648. $this->TOCuseLinking = false;
  649. }
  650. $this->TOC_margin_left = $this->TOC_margin_right = $this->TOC_margin_top = $this->TOC_margin_bottom = $this->TOC_margin_header = $this->TOC_margin_footer = '';
  651. if (isset($attr['TOC-MARGIN-RIGHT'])) {
  652. $this->TOC_margin_right = $this->sizeConverter->convert($attr['TOC-MARGIN-RIGHT'], $this->mpdf->w, $this->mpdf->FontSize, false);
  653. }
  654. if (isset($attr['TOC-MARGIN-LEFT'])) {
  655. $this->TOC_margin_left = $this->sizeConverter->convert($attr['TOC-MARGIN-LEFT'], $this->mpdf->w, $this->mpdf->FontSize, false);
  656. }
  657. if (isset($attr['TOC-MARGIN-TOP'])) {
  658. $this->TOC_margin_top = $this->sizeConverter->convert($attr['TOC-MARGIN-TOP'], $this->mpdf->w, $this->mpdf->FontSize, false);
  659. }
  660. if (isset($attr['TOC-MARGIN-BOTTOM'])) {
  661. $this->TOC_margin_bottom = $this->sizeConverter->convert($attr['TOC-MARGIN-BOTTOM'], $this->mpdf->w, $this->mpdf->FontSize, false);
  662. }
  663. if (isset($attr['TOC-MARGIN-HEADER'])) {
  664. $this->TOC_margin_header = $this->sizeConverter->convert($attr['TOC-MARGIN-HEADER'], $this->mpdf->w, $this->mpdf->FontSize, false);
  665. }
  666. if (isset($attr['TOC-MARGIN-FOOTER'])) {
  667. $this->TOC_margin_footer = $this->sizeConverter->convert($attr['TOC-MARGIN-FOOTER'], $this->mpdf->w, $this->mpdf->FontSize, false);
  668. }
  669. $this->TOC_odd_header_name = $this->TOC_even_header_name = $this->TOC_odd_footer_name = $this->TOC_even_footer_name = '';
  670. if (isset($attr['TOC-ODD-HEADER-NAME']) && $attr['TOC-ODD-HEADER-NAME']) {
  671. $this->TOC_odd_header_name = $attr['TOC-ODD-HEADER-NAME'];
  672. }
  673. if (isset($attr['TOC-EVEN-HEADER-NAME']) && $attr['TOC-EVEN-HEADER-NAME']) {
  674. $this->TOC_even_header_name = $attr['TOC-EVEN-HEADER-NAME'];
  675. }
  676. if (isset($attr['TOC-ODD-FOOTER-NAME']) && $attr['TOC-ODD-FOOTER-NAME']) {
  677. $this->TOC_odd_footer_name = $attr['TOC-ODD-FOOTER-NAME'];
  678. }
  679. if (isset($attr['TOC-EVEN-FOOTER-NAME']) && $attr['TOC-EVEN-FOOTER-NAME']) {
  680. $this->TOC_even_footer_name = $attr['TOC-EVEN-FOOTER-NAME'];
  681. }
  682. $this->TOC_odd_header_value = $this->TOC_even_header_value = $this->TOC_odd_footer_value = $this->TOC_even_footer_value = 0;
  683. if (isset($attr['TOC-ODD-HEADER-VALUE']) && ($attr['TOC-ODD-HEADER-VALUE'] == '1' || strtoupper($attr['TOC-ODD-HEADER-VALUE']) == 'ON')) {
  684. $this->TOC_odd_header_value = 1;
  685. } else if (isset($attr['TOC-ODD-HEADER-VALUE']) && ($attr['TOC-ODD-HEADER-VALUE'] == '-1' || strtoupper($attr['TOC-ODD-HEADER-VALUE']) == 'OFF')) {
  686. $this->TOC_odd_header_value = -1;
  687. }
  688. if (isset($attr['TOC-EVEN-HEADER-VALUE']) && ($attr['TOC-EVEN-HEADER-VALUE'] == '1' || strtoupper($attr['TOC-EVEN-HEADER-VALUE']) == 'ON')) {
  689. $this->TOC_even_header_value = 1;
  690. } else if (isset($attr['TOC-EVEN-HEADER-VALUE']) && ($attr['TOC-EVEN-HEADER-VALUE'] == '-1' || strtoupper($attr['TOC-EVEN-HEADER-VALUE']) == 'OFF')) {
  691. $this->TOC_even_header_value = -1;
  692. }
  693. if (isset($attr['TOC-ODD-FOOTER-VALUE']) && ($attr['TOC-ODD-FOOTER-VALUE'] == '1' || strtoupper($attr['TOC-ODD-FOOTER-VALUE']) == 'ON')) {
  694. $this->TOC_odd_footer_value = 1;
  695. } else if (isset($attr['TOC-ODD-FOOTER-VALUE']) && ($attr['TOC-ODD-FOOTER-VALUE'] == '-1' || strtoupper($attr['TOC-ODD-FOOTER-VALUE']) == 'OFF')) {
  696. $this->TOC_odd_footer_value = -1;
  697. }
  698. if (isset($attr['TOC-EVEN-FOOTER-VALUE']) && ($attr['TOC-EVEN-FOOTER-VALUE'] == '1' || strtoupper($attr['TOC-EVEN-FOOTER-VALUE']) == 'ON')) {
  699. $this->TOC_even_footer_value = 1;
  700. } else if (isset($attr['TOC-EVEN-FOOTER-VALUE']) && ($attr['TOC-EVEN-FOOTER-VALUE'] == '-1' || strtoupper($attr['TOC-EVEN-FOOTER-VALUE']) == 'OFF')) {
  701. $this->TOC_even_footer_value = -1;
  702. }
  703. if (isset($attr['TOC-PAGE-SELECTOR']) && $attr['TOC-PAGE-SELECTOR']) {
  704. $this->TOC_page_selector = $attr['TOC-PAGE-SELECTOR'];
  705. } else {
  706. $this->TOC_page_selector = '';
  707. }
  708. if (isset($attr['TOC-RESETPAGENUM']) && $attr['TOC-RESETPAGENUM']) {
  709. $this->TOC_resetpagenum = $attr['TOC-RESETPAGENUM'];
  710. } else {
  711. $this->TOC_resetpagenum = '';
  712. } // mPDF 6
  713. if (isset($attr['TOC-PAGENUMSTYLE']) && $attr['TOC-PAGENUMSTYLE']) {
  714. $this->TOC_pagenumstyle = $attr['TOC-PAGENUMSTYLE'];
  715. } else {
  716. $this->TOC_pagenumstyle = '';
  717. } // mPDF 6
  718. if (isset($attr['TOC-SUPPRESS']) && ($attr['TOC-SUPPRESS'] || $attr['TOC-SUPPRESS'] === '0')) {
  719. $this->TOC_suppress = $attr['TOC-SUPPRESS'];
  720. } else {
  721. $this->TOC_suppress = '';
  722. } // mPDF 6
  723. if (isset($attr['TOC-SHEET-SIZE']) && $attr['TOC-SHEET-SIZE']) {
  724. $this->TOCsheetsize = $attr['TOC-SHEET-SIZE'];
  725. } else {
  726. $this->TOCsheetsize = '';
  727. }
  728. if (isset($attr['TOC-PREHTML']) && $attr['TOC-PREHTML']) {
  729. $this->TOCpreHTML = htmlspecialchars_decode($attr['TOC-PREHTML'], ENT_QUOTES);
  730. }
  731. if (isset($attr['TOC-POSTHTML']) && $attr['TOC-POSTHTML']) {
  732. $this->TOCpostHTML = htmlspecialchars_decode($attr['TOC-POSTHTML'], ENT_QUOTES);
  733. }
  734. if (isset($attr['TOC-BOOKMARKTEXT']) && $attr['TOC-BOOKMARKTEXT']) {
  735. $this->TOCbookmarkText = htmlspecialchars_decode($attr['TOC-BOOKMARKTEXT'], ENT_QUOTES);
  736. }
  737. }
  738. if ($this->mpdf->y == $this->mpdf->tMargin && (!$this->mpdf->mirrorMargins || ($this->mpdf->mirrorMargins && $this->mpdf->page % 2 == 1))) {
  739. if ($toc_id) {
  740. $this->m_TOC[$toc_id]['TOCmark'] = $this->mpdf->page;
  741. } else {
  742. $this->TOCmark = $this->mpdf->page;
  743. }
  744. // Don't add a page
  745. if ($this->mpdf->page == 1 && count($this->mpdf->PageNumSubstitutions) == 0) {
  746. $resetpagenum = '';
  747. $pagenumstyle = '';
  748. $suppress = '';
  749. if (isset($attr['RESETPAGENUM'])) {
  750. $resetpagenum = $attr['RESETPAGENUM'];
  751. }
  752. if (isset($attr['PAGENUMSTYLE'])) {
  753. $pagenumstyle = $attr['PAGENUMSTYLE'];
  754. }
  755. if (isset($attr['SUPPRESS'])) {
  756. $suppress = $attr['SUPPRESS'];
  757. }
  758. if (!$suppress) {
  759. $suppress = 'off';
  760. }
  761. if (!$resetpagenum) {
  762. $resetpagenum = 1;
  763. }
  764. $this->mpdf->PageNumSubstitutions[] = ['from' => 1, 'reset' => $resetpagenum, 'type' => $pagenumstyle, 'suppress' => $suppress];
  765. }
  766. return [true, $toc_id];
  767. }
  768. // No break - continues as PAGEBREAK...
  769. return [false, $toc_id];
  770. }
  771. }