tocontents.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. <?php
  2. class tocontents {
  3. var $mpdf = null;
  4. var $_toc;
  5. var $TOCmark;
  6. var $TOCfont;
  7. var $TOCfontsize;
  8. var $TOCindent;
  9. var $TOCheader;
  10. var $TOCfooter;
  11. var $TOCpreHTML;
  12. var $TOCpostHTML;
  13. var $TOCbookmarkText;
  14. var $TOCusePaging;
  15. var $TOCuseLinking;
  16. var $TOCorientation;
  17. var $TOC_margin_left;
  18. var $TOC_margin_right;
  19. var $TOC_margin_top;
  20. var $TOC_margin_bottom;
  21. var $TOC_margin_header;
  22. var $TOC_margin_footer;
  23. var $TOC_odd_header_name;
  24. var $TOC_even_header_name;
  25. var $TOC_odd_footer_name;
  26. var $TOC_even_footer_name;
  27. var $TOC_odd_header_value;
  28. var $TOC_even_header_value;
  29. var $TOC_odd_footer_value;
  30. var $TOC_even_footer_value;
  31. var $TOC_page_selector;
  32. var $m_TOC;
  33. function tocontents(&$mpdf) {
  34. $this->mpdf = $mpdf;
  35. $this->_toc=array();
  36. $this->TOCmark = 0;
  37. $this->m_TOC=array();
  38. }
  39. function TOCpagebreak($tocfont='', $tocfontsize='', $tocindent='', $TOCusePaging=true, $TOCuseLinking='', $toc_orientation='', $toc_mgl='',$toc_mgr='',$toc_mgt='',$toc_mgb='',$toc_mgh='',$toc_mgf='',$toc_ohname='',$toc_ehname='',$toc_ofname='',$toc_efname='',$toc_ohvalue=0,$toc_ehvalue=0,$toc_ofvalue=0, $toc_efvalue=0, $toc_preHTML='', $toc_postHTML='', $toc_bookmarkText='', $resetpagenum='', $pagenumstyle='', $suppress='', $orientation='', $mgl='',$mgr='',$mgt='',$mgb='',$mgh='',$mgf='',$ohname='',$ehname='',$ofname='',$efname='',$ohvalue=0,$ehvalue=0,$ofvalue=0,$efvalue=0, $toc_id=0, $pagesel='', $toc_pagesel='', $sheetsize='', $toc_sheetsize='') {
  40. if (strtoupper($toc_id)=='ALL') { $toc_id = '_mpdf_all'; }
  41. else if (!$toc_id) { $toc_id = 0; }
  42. else { $toc_id = strtolower($toc_id); }
  43. if (!$tocfont) { $tocfont = $this->mpdf->default_font; }
  44. if (!$tocfontsize) { $tocfontsize = $this->mpdf->default_font_size; }
  45. if (!$tocindent && $tocindent !== 0) { $tocindent = 5; }
  46. if ($TOCusePaging === false || strtolower($TOCusePaging) == "off" || $TOCusePaging === 0 || $TOCusePaging === "0" || $TOCusePaging === "") { $TOCusePaging = false; }
  47. else { $TOCusePaging = true; }
  48. if (!$TOCuseLinking) { $TOCuseLinking = false; }
  49. if ($toc_id) {
  50. $this->m_TOC[$toc_id]['TOCmark'] = $this->mpdf->page;
  51. $this->m_TOC[$toc_id]['TOCfont'] = $tocfont;
  52. $this->m_TOC[$toc_id]['TOCfontsize'] = $tocfontsize;
  53. $this->m_TOC[$toc_id]['TOCindent'] = $tocindent;
  54. $this->m_TOC[$toc_id]['TOCorientation'] = $toc_orientation;
  55. $this->m_TOC[$toc_id]['TOCuseLinking'] = $TOCuseLinking;
  56. $this->m_TOC[$toc_id]['TOCusePaging'] = $TOCusePaging;
  57. if ($toc_preHTML) { $this->m_TOC[$toc_id]['TOCpreHTML'] = $toc_preHTML; }
  58. if ($toc_postHTML) { $this->m_TOC[$toc_id]['TOCpostHTML'] = $toc_postHTML; }
  59. if ($toc_bookmarkText) { $this->m_TOC[$toc_id]['TOCbookmarkText'] = $toc_bookmarkText; }
  60. $this->m_TOC[$toc_id]['TOC_margin_left'] = $toc_mgl;
  61. $this->m_TOC[$toc_id]['TOC_margin_right'] = $toc_mgr;
  62. $this->m_TOC[$toc_id]['TOC_margin_top'] = $toc_mgt;
  63. $this->m_TOC[$toc_id]['TOC_margin_bottom'] = $toc_mgb;
  64. $this->m_TOC[$toc_id]['TOC_margin_header'] = $toc_mgh;
  65. $this->m_TOC[$toc_id]['TOC_margin_footer'] = $toc_mgf;
  66. $this->m_TOC[$toc_id]['TOC_odd_header_name'] = $toc_ohname;
  67. $this->m_TOC[$toc_id]['TOC_even_header_name'] = $toc_ehname;
  68. $this->m_TOC[$toc_id]['TOC_odd_footer_name'] = $toc_ofname;
  69. $this->m_TOC[$toc_id]['TOC_even_footer_name'] = $toc_efname;
  70. $this->m_TOC[$toc_id]['TOC_odd_header_value'] = $toc_ohvalue;
  71. $this->m_TOC[$toc_id]['TOC_even_header_value'] = $toc_ehvalue;
  72. $this->m_TOC[$toc_id]['TOC_odd_footer_value'] = $toc_ofvalue;
  73. $this->m_TOC[$toc_id]['TOC_even_footer_value'] = $toc_efvalue;
  74. $this->m_TOC[$toc_id]['TOC_page_selector'] = $toc_pagesel;
  75. $this->m_TOC[$toc_id]['TOCsheetsize'] = $toc_sheetsize;
  76. }
  77. else {
  78. $this->TOCmark = $this->mpdf->page;
  79. $this->TOCfont = $tocfont;
  80. $this->TOCfontsize = $tocfontsize;
  81. $this->TOCindent = $tocindent;
  82. $this->TOCorientation = $toc_orientation;
  83. $this->TOCuseLinking = $TOCuseLinking;
  84. $this->TOCusePaging = $TOCusePaging;
  85. if ($toc_preHTML) { $this->TOCpreHTML = $toc_preHTML; }
  86. if ($toc_postHTML) { $this->TOCpostHTML = $toc_postHTML; }
  87. if ($toc_bookmarkText) { $this->TOCbookmarkText = $toc_bookmarkText; }
  88. $this->TOC_margin_left = $toc_mgl;
  89. $this->TOC_margin_right = $toc_mgr;
  90. $this->TOC_margin_top = $toc_mgt;
  91. $this->TOC_margin_bottom = $toc_mgb;
  92. $this->TOC_margin_header = $toc_mgh;
  93. $this->TOC_margin_footer = $toc_mgf;
  94. $this->TOC_odd_header_name = $toc_ohname;
  95. $this->TOC_even_header_name = $toc_ehname;
  96. $this->TOC_odd_footer_name = $toc_ofname;
  97. $this->TOC_even_footer_name = $toc_efname;
  98. $this->TOC_odd_header_value = $toc_ohvalue;
  99. $this->TOC_even_header_value = $toc_ehvalue;
  100. $this->TOC_odd_footer_value = $toc_ofvalue;
  101. $this->TOC_even_footer_value = $toc_efvalue;
  102. $this->TOC_page_selector = $toc_pagesel;
  103. $this->TOCsheetsize = $toc_sheetsize;
  104. }
  105. }
  106. // Initiate, and Mark a place for the Table of Contents to be inserted
  107. function TOC($tocfont='', $tocfontsize=8, $tocindent=5, $resetpagenum='', $pagenumstyle='', $suppress='', $toc_orientation='', $TOCusePaging=true, $TOCuseLinking=false, $toc_id=0) {
  108. if (strtoupper($toc_id)=='ALL') { $toc_id = '_mpdf_all'; }
  109. else if (!$toc_id) { $toc_id = 0; }
  110. else { $toc_id = strtolower($toc_id); }
  111. // To use odd and even pages
  112. // Cannot start table of contents on an even page
  113. if (($this->mpdf->mirrorMargins) && (($this->mpdf->page)%2==0)) { // EVEN
  114. if ($this->mpdf->ColActive) {
  115. if (count($this->mpdf->columnbuffer)) { $this->mpdf->printcolumnbuffer(); }
  116. }
  117. $this->mpdf->AddPage($this->mpdf->CurOrientation,'',$resetpagenum, $pagenumstyle, $suppress);
  118. }
  119. else {
  120. $this->mpdf->PageNumSubstitutions[] = array('from'=>$this->mpdf->page, 'reset'=> $resetpagenum, 'type'=>$pagenumstyle, 'suppress'=>$suppress);
  121. }
  122. if (!$tocfont) { $tocfont = $this->mpdf->default_font; }
  123. if (!$tocfontsize) { $tocfontsize = $this->mpdf->default_font_size; }
  124. if ($toc_id) {
  125. $this->m_TOC[$toc_id]['TOCmark'] = $this->mpdf->page;
  126. $this->m_TOC[$toc_id]['TOCfont'] = $tocfont;
  127. $this->m_TOC[$toc_id]['TOCfontsize'] = $tocfontsize;
  128. $this->m_TOC[$toc_id]['TOCindent'] = $tocindent;
  129. $this->m_TOC[$toc_id]['TOCorientation'] = $toc_orientation;
  130. $this->m_TOC[$toc_id]['TOCuseLinking'] = $TOCuseLinking;
  131. $this->m_TOC[$toc_id]['TOCusePaging'] = $TOCusePaging;
  132. }
  133. else {
  134. $this->TOCmark = $this->mpdf->page;
  135. $this->TOCfont = $tocfont;
  136. $this->TOCfontsize = $tocfontsize;
  137. $this->TOCindent = $tocindent;
  138. $this->TOCorientation = $toc_orientation;
  139. $this->TOCuseLinking = $TOCuseLinking;
  140. $this->TOCusePaging = $TOCusePaging;
  141. }
  142. }
  143. function insertTOC() {
  144. $notocs = 0;
  145. if ($this->TOCmark) { $notocs = 1; }
  146. $notocs += count($this->m_TOC);
  147. if ($notocs==0) { return; }
  148. if (count($this->m_TOC)) { reset($this->m_TOC); }
  149. $added_toc_pages = 0;
  150. if ($this->mpdf->ColActive) { $this->mpdf->SetColumns(0); }
  151. if (($this->mpdf->mirrorMargins) && (($this->mpdf->page)%2==1)) { // ODD
  152. $this->mpdf->AddPage($this->mpdf->CurOrientation);
  153. $extrapage = true;
  154. }
  155. else { $extrapage = false; }
  156. for ($toci = 0; $toci<$notocs; $toci++) {
  157. if ($toci==0 && $this->TOCmark) {
  158. $toc_id = 0;
  159. $toc_page = $this->TOCmark;
  160. $tocfont = $this->TOCfont;
  161. $tocfontsize = $this->TOCfontsize;
  162. $tocindent = $this->TOCindent;
  163. $toc_orientation = $this->TOCorientation;
  164. $TOCuseLinking = $this->TOCuseLinking;
  165. $TOCusePaging = $this->TOCusePaging;
  166. $toc_preHTML = $this->TOCpreHTML;
  167. $toc_postHTML = $this->TOCpostHTML;
  168. $toc_bookmarkText = $this->TOCbookmarkText;
  169. $toc_mgl = $this->TOC_margin_left;
  170. $toc_mgr = $this->TOC_margin_right;
  171. $toc_mgt = $this->TOC_margin_top;
  172. $toc_mgb = $this->TOC_margin_bottom;
  173. $toc_mgh = $this->TOC_margin_header;
  174. $toc_mgf = $this->TOC_margin_footer;
  175. $toc_ohname = $this->TOC_odd_header_name;
  176. $toc_ehname = $this->TOC_even_header_name;
  177. $toc_ofname = $this->TOC_odd_footer_name;
  178. $toc_efname = $this->TOC_even_footer_name;
  179. $toc_ohvalue = $this->TOC_odd_header_value;
  180. $toc_ehvalue = $this->TOC_even_header_value;
  181. $toc_ofvalue = $this->TOC_odd_footer_value;
  182. $toc_efvalue = $this->TOC_even_footer_value;
  183. $toc_page_selector = $this->TOC_page_selector;
  184. $toc_sheet_size = $this->TOCsheetsize;
  185. }
  186. else {
  187. $arr = current($this->m_TOC);
  188. $toc_id = key($this->m_TOC);
  189. $toc_page = $this->m_TOC[$toc_id]['TOCmark'];
  190. $tocfont = $this->m_TOC[$toc_id]['TOCfont'];
  191. $tocfontsize = $this->m_TOC[$toc_id]['TOCfontsize'];
  192. $tocindent = $this->m_TOC[$toc_id]['TOCindent'];
  193. $toc_orientation = $this->m_TOC[$toc_id]['TOCorientation'];
  194. $TOCuseLinking = $this->m_TOC[$toc_id]['TOCuseLinking'];
  195. $TOCusePaging = $this->m_TOC[$toc_id]['TOCusePaging'];
  196. if (isset($this->m_TOC[$toc_id]['TOCpreHTML'])) { $toc_preHTML = $this->m_TOC[$toc_id]['TOCpreHTML']; }
  197. else { $toc_preHTML = ''; }
  198. if (isset($this->m_TOC[$toc_id]['TOCpostHTML'])) { $toc_postHTML = $this->m_TOC[$toc_id]['TOCpostHTML']; }
  199. else { $toc_postHTML = ''; }
  200. if (isset($this->m_TOC[$toc_id]['TOCbookmarkText'])) { $toc_bookmarkText = $this->m_TOC[$toc_id]['TOCbookmarkText']; }
  201. else { $toc_bookmarkText = ''; } // *BOOKMARKS*
  202. $toc_mgl = $this->m_TOC[$toc_id]['TOC_margin_left'];
  203. $toc_mgr = $this->m_TOC[$toc_id]['TOC_margin_right'];
  204. $toc_mgt = $this->m_TOC[$toc_id]['TOC_margin_top'];
  205. $toc_mgb = $this->m_TOC[$toc_id]['TOC_margin_bottom'];
  206. $toc_mgh = $this->m_TOC[$toc_id]['TOC_margin_header'];
  207. $toc_mgf = $this->m_TOC[$toc_id]['TOC_margin_footer'];
  208. $toc_ohname = $this->m_TOC[$toc_id]['TOC_odd_header_name'];
  209. $toc_ehname = $this->m_TOC[$toc_id]['TOC_even_header_name'];
  210. $toc_ofname = $this->m_TOC[$toc_id]['TOC_odd_footer_name'];
  211. $toc_efname = $this->m_TOC[$toc_id]['TOC_even_footer_name'];
  212. $toc_ohvalue = $this->m_TOC[$toc_id]['TOC_odd_header_value'];
  213. $toc_ehvalue = $this->m_TOC[$toc_id]['TOC_even_header_value'];
  214. $toc_ofvalue = $this->m_TOC[$toc_id]['TOC_odd_footer_value'];
  215. $toc_efvalue = $this->m_TOC[$toc_id]['TOC_even_footer_value'];
  216. $toc_page_selector = $this->m_TOC[$toc_id]['TOC_page_selector'];
  217. $toc_sheet_size = $this->m_TOC[$toc_id]['TOCsheetsize'];
  218. next($this->m_TOC);
  219. }
  220. if ($this->TOCheader) { $this->mpdf->SetHeader($this->TOCheader); }
  221. else if ($this->TOCheader !== false) { $this->mpdf->SetHeader(); }
  222. if (!$tocindent && $tocindent !== 0) { $tocindent = 5; }
  223. if (!$toc_orientation) { $toc_orientation= $this->mpdf->DefOrientation; }
  224. $this->mpdf->AddPage($toc_orientation, '', '', '', "on", $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 );
  225. if ($this->TOCfooter) { $this->mpdf->SetFooter($this->TOCfooter); }
  226. else if ($this->TOCfooter !== false) { $this->mpdf->SetFooter(); }
  227. $tocstart=count($this->mpdf->pages);
  228. if ($toc_preHTML) { $this->mpdf->WriteHTML($toc_preHTML); }
  229. foreach($this->_toc as $t) {
  230. if ($t['toc_id']==='_mpdf_all' || $t['toc_id']===$toc_id ) {
  231. $tpgno = $this->mpdf->docPageNum($t['p']);
  232. $lineheightcorr = 2-$t['l'];
  233. //Offset
  234. $level=$t['l'];
  235. if ($TOCuseLinking) { $tlink = $t['link']; }
  236. else { $tlink = ''; }
  237. if ($this->mpdf->directionality == 'rtl') {
  238. $weight='';
  239. if($level==0)
  240. $weight='B';
  241. $str=$t['t'];
  242. $fullstr = $str;
  243. $this->mpdf->SetFont($tocfont,$weight,$tocfontsize,true,true);
  244. $PageCellSize=$this->mpdf->GetStringWidth($tpgno )+2;
  245. $strsize=$this->mpdf->GetStringWidth($str);
  246. $repdots = $this->mpdf->GetStringWidth(str_repeat('.',5)); // mPDF 5.3.07
  247. $cw = count(explode(' ',$str));
  248. while (($strsize + $repdots +4 + $PageCellSize) > $this->mpdf->pgwidth && $cw>1) { // mPDF 5.3.07
  249. $str = implode(' ',explode(' ',$str,-1));
  250. $strsize=$this->mpdf->GetStringWidth($str);
  251. $cw = count(explode(' ',$str));
  252. }
  253. $sl = strlen($str);
  254. $rem = substr($fullstr, ($sl+1));
  255. $this->mpdf->magic_reverse_dir($str, true, $this->mpdf->directionality); // *RTL*
  256. if ($TOCusePaging) {
  257. //Page number
  258. $this->mpdf->SetFont($tocfont,'',$tocfontsize);
  259. $this->mpdf->Cell($PageCellSize,$this->mpdf->FontSize+$lineheightcorr,$tpgno ,0,0,'L',0,$tlink);
  260. //Filling dots
  261. $w=$this->mpdf->w-$this->mpdf->lMargin-$this->mpdf->rMargin-$PageCellSize-($level*$tocindent)-($strsize+2);
  262. $nb=intval($w/$this->mpdf->GetCharWidth('.',false)); // mPDF 5.3.04
  263. if ($nb>0) {
  264. $dots=str_repeat('.',$nb);
  265. $this->mpdf->Cell($w+2,$this->mpdf->FontSize+$lineheightcorr,$dots,0,0,'L');
  266. }
  267. // Text
  268. $this->mpdf->SetFont($tocfont,$weight,$tocfontsize);
  269. $this->mpdf->Cell($strsize-($level*$tocindent),$this->mpdf->FontSize+$lineheightcorr,$str,0,1,'R',0,$tlink);
  270. }
  271. else {
  272. // Text
  273. $this->mpdf->SetFont($tocfont,$weight,$tocfontsize);
  274. $this->mpdf->Cell($this->mpdf->pgwidth -($level*$tocindent),$this->mpdf->FontSize+$lineheightcorr,$str,0,1,'R',0,$tlink);
  275. }
  276. if ($rem) {
  277. $this->mpdf->x += 10;
  278. $this->mpdf->SetFont($tocfont,$weight,$tocfontsize,true,true);
  279. $this->mpdf->MultiCell($this->mpdf->pgwidth -($level*$tocindent)-15,$this->mpdf->FontSize+$lineheightcorr,$rem,0,R,0,$tlink,'rtl',true);
  280. }
  281. }
  282. // LTR
  283. else {
  284. // Text
  285. $weight='';
  286. if($level==0)
  287. $weight='B';
  288. $str=$t['t'];
  289. $fullstr = $str;
  290. $this->mpdf->SetFont($tocfont,$weight,$tocfontsize,true,true);
  291. if($level>0 && $tocindent) { $this->mpdf->Cell($level*$tocindent,$this->mpdf->FontSize+$lineheightcorr); }
  292. // Font-specific ligature substitution for Indic fonts
  293. if (isset($this->mpdf->CurrentFont['indic']) && $this->mpdf->CurrentFont['indic']) $this->mpdf->ConvertIndic($str); // *INDIC*
  294. $PageCellSize=$this->mpdf->GetStringWidth($tpgno )+2;
  295. $strsize=$this->mpdf->GetStringWidth($str);
  296. $repdots = $this->mpdf->GetStringWidth(str_repeat('.',5)); // mPDF 5.3.07
  297. $cw = count(explode(' ',$str));
  298. while (($strsize + $repdots +4+ $PageCellSize + ($level*$tocindent)) > $this->mpdf->pgwidth && $cw>1) { // mPDF 5.3.07
  299. $str = implode(' ',explode(' ',$str,-1));
  300. $strsize=$this->mpdf->GetStringWidth($str);
  301. $cw = count(explode(' ',$str));
  302. }
  303. $sl = strlen($str);
  304. $rem = substr($fullstr, ($sl+1));
  305. if ($TOCusePaging) {
  306. // Text
  307. $this->mpdf->Cell($strsize+2,$this->mpdf->FontSize+$lineheightcorr,$str,0,0,'',0,$tlink);
  308. //Filling dots
  309. $this->mpdf->SetFont($tocfont,'',$tocfontsize);
  310. $w=$this->mpdf->w-$this->mpdf->lMargin-$this->mpdf->rMargin-$PageCellSize-($level*$tocindent)-($strsize+2);
  311. $nb=intval($w/$this->mpdf->GetCharWidth('.',false)); // mPDF 5.3.04
  312. if ($nb>0) { $dots=str_repeat('.',$nb); }
  313. else { $this->mpdf->y += $this->mpdf->lineheight; $dots=str_repeat('.',5); } // ..... 5 dots?
  314. $this->mpdf->Cell($w,$this->mpdf->FontSize+$lineheightcorr,$dots,0,0,'R');
  315. //Page number
  316. $this->mpdf->Cell($PageCellSize,$this->mpdf->FontSize+$lineheightcorr,$tpgno ,0,1,'R',0,$tlink);
  317. }
  318. else {
  319. // Text only
  320. $this->mpdf->Cell($strsize+2,$this->mpdf->FontSize+$lineheightcorr,$str,0,1,'',0,$tlink); // forces new line
  321. }
  322. if ($rem) {
  323. $this->mpdf->x += 5 + $PageCellSize + ($level*$tocindent);
  324. $this->mpdf->SetFont($tocfont,$weight,$tocfontsize,true,true);
  325. $this->mpdf->MultiCell($strsize+2,$this->mpdf->FontSize+$lineheightcorr,$rem,0,L,0,$tlink,'ltr',true);
  326. }
  327. } // *RTL*
  328. }
  329. }
  330. if ($toc_postHTML) { $this->mpdf->WriteHTML($toc_postHTML); }
  331. $this->mpdf->AddPage($toc_orientation,'E');
  332. $n_toc = $this->mpdf->page - $tocstart + 1;
  333. if ($toci==0 && $this->TOCmark) {
  334. $TOC_start = $tocstart ;
  335. $TOC_end = $this->mpdf->page;
  336. $TOC_npages = $n_toc;
  337. }
  338. else {
  339. $this->m_TOC[$toc_id]['start'] = $tocstart ;
  340. $this->m_TOC[$toc_id]['end'] = $this->mpdf->page;
  341. $this->m_TOC[$toc_id]['npages'] = $n_toc;
  342. }
  343. }
  344. $s = '';
  345. $s .= $this->mpdf->PrintBodyBackgrounds();
  346. $s .= $this->mpdf->PrintPageBackgrounds();
  347. $this->mpdf->pages[$this->mpdf->page] = preg_replace('/(___BACKGROUND___PATTERNS'.date('jY').')/', "\n".$s."\n".'\\1', $this->mpdf->pages[$this->mpdf->page]);
  348. $this->mpdf->pageBackgrounds = array();
  349. //Page footer
  350. $this->mpdf->InFooter=true;
  351. $this->mpdf->Footer();
  352. $this->mpdf->InFooter=false;
  353. // 2nd time through to move pages etc.
  354. $added_toc_pages = 0;
  355. if (count($this->m_TOC)) { reset($this->m_TOC); }
  356. for ($toci = 0; $toci<$notocs; $toci++) {
  357. if ($toci==0 && $this->TOCmark) {
  358. $toc_id = 0;
  359. $toc_page = $this->TOCmark + $added_toc_pages;
  360. $toc_orientation = $this->TOCorientation;
  361. $TOCuseLinking = $this->TOCuseLinking;
  362. $TOCusePaging = $this->TOCusePaging;
  363. $toc_bookmarkText = $this->TOCbookmarkText; // *BOOKMARKS*
  364. $tocstart = $TOC_start ;
  365. $tocend = $n = $TOC_end;
  366. $n_toc = $TOC_npages;
  367. }
  368. else {
  369. $arr = current($this->m_TOC);
  370. $toc_id = key($this->m_TOC);
  371. $toc_page = $this->m_TOC[$toc_id]['TOCmark'] + $added_toc_pages;
  372. $toc_orientation = $this->m_TOC[$toc_id]['TOCorientation'];
  373. $TOCuseLinking = $this->m_TOC[$toc_id]['TOCuseLinking'];
  374. $TOCusePaging = $this->m_TOC[$toc_id]['TOCusePaging'];
  375. $toc_bookmarkText = $this->m_TOC[$toc_id]['TOCbookmarkText']; // *BOOKMARKS*
  376. $tocstart = $this->m_TOC[$toc_id]['start'] ;
  377. $tocend = $n = $this->m_TOC[$toc_id]['end'] ;
  378. $n_toc = $this->m_TOC[$toc_id]['npages'] ;
  379. next($this->m_TOC);
  380. }
  381. // Now pages moved
  382. $added_toc_pages += $n_toc;
  383. $this->mpdf->MovePages($toc_page, $tocstart, $tocend) ;
  384. $this->mpdf->pgsIns[$toc_page] = $tocend - $tocstart + 1;
  385. /*-- BOOKMARKS --*/
  386. // Insert new Bookmark for Bookmark
  387. if ($toc_bookmarkText) {
  388. $insert = -1;
  389. foreach($this->mpdf->BMoutlines as $i=>$o) {
  390. if($o['p']<$toc_page) { // i.e. before point of insertion
  391. $insert = $i;
  392. }
  393. }
  394. $txt = $this->mpdf->purify_utf8_text($toc_bookmarkText);
  395. if ($this->mpdf->text_input_as_HTML) {
  396. $txt = $this->mpdf->all_entities_to_utf8($txt);
  397. }
  398. $newBookmark[0] = array('t'=>$txt,'l'=>0,'y'=>0,'p'=>$toc_page );
  399. array_splice($this->mpdf->BMoutlines,($insert+1),0,$newBookmark);
  400. }
  401. /*-- END BOOKMARKS --*/
  402. }
  403. // Delete empty page that was inserted earlier
  404. if ($extrapage) {
  405. unset($this->mpdf->pages[count($this->mpdf->pages)]);
  406. $this->mpdf->page--; // Reset page pointer
  407. }
  408. }
  409. function openTagTOC($attr) {
  410. if (isset($attr['FONT-SIZE']) && $attr['FONT-SIZE']) { $tocfontsize = $attr['FONT-SIZE']; } else { $tocfontsize = ''; }
  411. if (isset($attr['FONT']) && $attr['FONT']) { $tocfont = $attr['FONT']; } else { $tocfont = ''; }
  412. if (isset($attr['INDENT']) && $attr['INDENT']) { $tocindent = $attr['INDENT']; } else { $tocindent = ''; }
  413. if (isset($attr['RESETPAGENUM']) && $attr['RESETPAGENUM']) { $resetpagenum = $attr['RESETPAGENUM']; } else { $resetpagenum = ''; }
  414. if (isset($attr['PAGENUMSTYLE']) && $attr['PAGENUMSTYLE']) { $pagenumstyle = $attr['PAGENUMSTYLE']; } else { $pagenumstyle= ''; }
  415. if (isset($attr['SUPPRESS']) && $attr['SUPPRESS']) { $suppress = $attr['SUPPRESS']; } else { $suppress = ''; }
  416. if (isset($attr['TOC-ORIENTATION']) && $attr['TOC-ORIENTATION']) { $toc_orientation = $attr['TOC-ORIENTATION']; } else { $toc_orientation = ''; }
  417. if (isset($attr['PAGING']) && (strtoupper($attr['PAGING'])=='OFF' || $attr['PAGING']==='0')) { $paging = false; }
  418. else { $paging = true; }
  419. if (isset($attr['LINKS']) && (strtoupper($attr['LINKS'])=='ON' || $attr['LINKS']==1)) { $links = true; }
  420. else { $links = false; }
  421. if (isset($attr['NAME']) && $attr['NAME']) { $toc_id = strtolower($attr['NAME']); } else { $toc_id = 0; }
  422. $this->TOC($tocfont,$tocfontsize,$tocindent,$resetpagenum, $pagenumstyle, $suppress, $toc_orientation, $paging, $links, $toc_id);
  423. }
  424. function openTagTOCPAGEBREAK($attr) {
  425. if (isset($attr['NAME']) && $attr['NAME']) { $toc_id = strtolower($attr['NAME']); } else { $toc_id = 0; }
  426. if ($toc_id) {
  427. if (isset($attr['FONT-SIZE'])) { $this->m_TOC[$toc_id]['TOCfontsize'] = $attr['FONT-SIZE']; } else { $this->m_TOC[$toc_id]['TOCfontsize'] = $this->mpdf->default_font_size; }
  428. if (isset($attr['FONT'])) { $this->m_TOC[$toc_id]['TOCfont'] = $attr['FONT']; } else { $this->m_TOC[$toc_id]['TOCfont'] = $this->mpdf->default_font; }
  429. if (isset($attr['INDENT']) && $attr['INDENT']) { $this->m_TOC[$toc_id]['TOCindent'] = $attr['INDENT']; } else { $this->m_TOC[$toc_id]['TOCindent'] = ''; }
  430. if (isset($attr['TOC-ORIENTATION']) && $attr['TOC-ORIENTATION']) { $this->m_TOC[$toc_id]['TOCorientation'] = $attr['TOC-ORIENTATION']; } else { $this->m_TOC[$toc_id]['TOCorientation'] = ''; }
  431. if (isset($attr['PAGING']) && (strtoupper($attr['PAGING'])=='OFF' || $attr['PAGING']==='0')) { $this->m_TOC[$toc_id]['TOCusePaging'] = false; }
  432. else { $this->m_TOC[$toc_id]['TOCusePaging'] = true; }
  433. if (isset($attr['LINKS']) && (strtoupper($attr['LINKS'])=='ON' || $attr['LINKS']==1)) { $this->m_TOC[$toc_id]['TOCuseLinking'] = true; }
  434. else { $this->m_TOC[$toc_id]['TOCuseLinking'] = false; }
  435. $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'] = '';
  436. if (isset($attr['TOC-MARGIN-RIGHT'])) { $this->m_TOC[$toc_id]['TOC_margin_right'] = $this->mpdf->ConvertSize($attr['TOC-MARGIN-RIGHT'],$this->mpdf->w,$this->mpdf->FontSize,false); }
  437. if (isset($attr['TOC-MARGIN-LEFT'])) { $this->m_TOC[$toc_id]['TOC_margin_left'] = $this->mpdf->ConvertSize($attr['TOC-MARGIN-LEFT'],$this->mpdf->w,$this->mpdf->FontSize,false); }
  438. if (isset($attr['TOC-MARGIN-TOP'])) { $this->m_TOC[$toc_id]['TOC_margin_top'] = $this->mpdf->ConvertSize($attr['TOC-MARGIN-TOP'],$this->mpdf->w,$this->mpdf->FontSize,false); }
  439. if (isset($attr['TOC-MARGIN-BOTTOM'])) { $this->m_TOC[$toc_id]['TOC_margin_bottom'] = $this->mpdf->ConvertSize($attr['TOC-MARGIN-BOTTOM'],$this->mpdf->w,$this->mpdf->FontSize,false); }
  440. if (isset($attr['TOC-MARGIN-HEADER'])) { $this->m_TOC[$toc_id]['TOC_margin_header'] = $this->mpdf->ConvertSize($attr['TOC-MARGIN-HEADER'],$this->mpdf->w,$this->mpdf->FontSize,false); }
  441. if (isset($attr['TOC-MARGIN-FOOTER'])) { $this->m_TOC[$toc_id]['TOC_margin_footer'] = $this->mpdf->ConvertSize($attr['TOC-MARGIN-FOOTER'],$this->mpdf->w,$this->mpdf->FontSize,false); }
  442. $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'] = '';
  443. if (isset($attr['TOC-ODD-HEADER-NAME']) && $attr['TOC-ODD-HEADER-NAME']) { $this->m_TOC[$toc_id]['TOC_odd_header_name'] = $attr['TOC-ODD-HEADER-NAME']; }
  444. if (isset($attr['TOC-EVEN-HEADER-NAME']) && $attr['TOC-EVEN-HEADER-NAME']) { $this->m_TOC[$toc_id]['TOC_even_header_name'] = $attr['TOC-EVEN-HEADER-NAME']; }
  445. if (isset($attr['TOC-ODD-FOOTER-NAME']) && $attr['TOC-ODD-FOOTER-NAME']) { $this->m_TOC[$toc_id]['TOC_odd_footer_name'] = $attr['TOC-ODD-FOOTER-NAME']; }
  446. if (isset($attr['TOC-EVEN-FOOTER-NAME']) && $attr['TOC-EVEN-FOOTER-NAME']) { $this->m_TOC[$toc_id]['TOC_even_footer_name'] = $attr['TOC-EVEN-FOOTER-NAME']; }
  447. $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;
  448. if (isset($attr['TOC-ODD-HEADER-VALUE']) && ($attr['TOC-ODD-HEADER-VALUE']=='1' || strtoupper($attr['TOC-ODD-HEADER-VALUE'])=='ON')) { $this->m_TOC[$toc_id]['TOC_odd_header_value'] = 1; }
  449. else if (isset($attr['TOC-ODD-HEADER-VALUE']) && ($attr['TOC-ODD-HEADER-VALUE']=='-1' || strtoupper($attr['TOC-ODD-HEADER-VALUE'])=='OFF')) { $this->m_TOC[$toc_id]['TOC_odd_header_value'] = -1; }
  450. if (isset($attr['TOC-EVEN-HEADER-VALUE']) && ($attr['TOC-EVEN-HEADER-VALUE']=='1' || strtoupper($attr['TOC-EVEN-HEADER-VALUE'])=='ON')) { $this->m_TOC[$toc_id]['TOC_even_header_value'] = 1; }
  451. else if (isset($attr['TOC-EVEN-HEADER-VALUE']) && ($attr['TOC-EVEN-HEADER-VALUE']=='-1' || strtoupper($attr['TOC-EVEN-HEADER-VALUE'])=='OFF')) { $this->m_TOC[$toc_id]['TOC_even_header_value'] = -1; }
  452. if (isset($attr['TOC-ODD-FOOTER-VALUE']) && ($attr['TOC-ODD-FOOTER-VALUE']=='1' || strtoupper($attr['TOC-ODD-FOOTER-VALUE'])=='ON')) { $this->m_TOC[$toc_id]['TOC_odd_footer_value'] = 1; }
  453. else if (isset($attr['TOC-ODD-FOOTER-VALUE']) && ($attr['TOC-ODD-FOOTER-VALUE']=='-1' || strtoupper($attr['TOC-ODD-FOOTER-VALUE'])=='OFF')) { $this->m_TOC[$toc_id]['TOC_odd_footer_value'] = -1; }
  454. if (isset($attr['TOC-EVEN-FOOTER-VALUE']) && ($attr['TOC-EVEN-FOOTER-VALUE']=='1' || strtoupper($attr['TOC-EVEN-FOOTER-VALUE'])=='ON')) { $this->m_TOC[$toc_id]['TOC_even_footer_value'] = 1; }
  455. else if (isset($attr['TOC-EVEN-FOOTER-VALUE']) && ($attr['TOC-EVEN-FOOTER-VALUE']=='-1' || strtoupper($attr['TOC-EVEN-FOOTER-VALUE'])=='OFF')) { $this->m_TOC[$toc_id]['TOC_even_footer_value'] = -1; }
  456. if (isset($attr['TOC-PAGE-SELECTOR']) && $attr['TOC-PAGE-SELECTOR']) { $this->m_TOC[$toc_id]['TOC_page_selector'] = $attr['TOC-PAGE-SELECTOR']; }
  457. else { $this->m_TOC[$toc_id]['TOC_page_selector'] = ''; }
  458. if (isset($attr['TOC-SHEET-SIZE']) && $attr['TOC-SHEET-SIZE']) { $this->m_TOC[$toc_id]['TOCsheetsize'] = $attr['TOC-SHEET-SIZE']; } else { $this->m_TOC[$toc_id]['TOCsheetsize'] = ''; }
  459. if (isset($attr['TOC-PREHTML']) && $attr['TOC-PREHTML']) { $this->m_TOC[$toc_id]['TOCpreHTML'] = htmlspecialchars_decode($attr['TOC-PREHTML'],ENT_QUOTES); }
  460. if (isset($attr['TOC-POSTHTML']) && $attr['TOC-POSTHTML']) { $this->m_TOC[$toc_id]['TOCpostHTML'] = htmlspecialchars_decode($attr['TOC-POSTHTML'],ENT_QUOTES); }
  461. if (isset($attr['TOC-BOOKMARKTEXT']) && $attr['TOC-BOOKMARKTEXT']) { $this->m_TOC[$toc_id]['TOCbookmarkText'] = htmlspecialchars_decode($attr['TOC-BOOKMARKTEXT'],ENT_QUOTES); } // *BOOKMARKS*
  462. }
  463. else {
  464. if (isset($attr['FONT-SIZE'])) { $this->TOCfontsize = $attr['FONT-SIZE']; } else { $this->TOCfontsize = $this->mpdf->default_font_size; }
  465. if (isset($attr['FONT'])) { $this->TOCfont = $attr['FONT']; } else { $this->TOCfont = $this->mpdf->default_font; }
  466. if (isset($attr['INDENT']) && $attr['INDENT']) { $this->TOCindent = $attr['INDENT']; } else { $this->TOCindent = ''; }
  467. if (isset($attr['TOC-ORIENTATION']) && $attr['TOC-ORIENTATION']) { $this->TOCorientation = $attr['TOC-ORIENTATION']; } else { $this->TOCorientation = ''; }
  468. if (isset($attr['PAGING']) && (strtoupper($attr['PAGING'])=='OFF' || $attr['PAGING']==='0')) { $this->TOCusePaging = false; }
  469. else { $this->TOCusePaging = true; }
  470. if (isset($attr['LINKS']) && (strtoupper($attr['LINKS'])=='ON' || $attr['LINKS']==1)) { $this->TOCuseLinking = true; }
  471. else { $this->TOCuseLinking = false; }
  472. $this->TOC_margin_left = $this->TOC_margin_right = $this->TOC_margin_top = $this->TOC_margin_bottom = $this->TOC_margin_header = $this->TOC_margin_footer = '';
  473. if (isset($attr['TOC-MARGIN-RIGHT'])) { $this->TOC_margin_right = $this->mpdf->ConvertSize($attr['TOC-MARGIN-RIGHT'],$this->mpdf->w,$this->mpdf->FontSize,false); }
  474. if (isset($attr['TOC-MARGIN-LEFT'])) { $this->TOC_margin_left = $this->mpdf->ConvertSize($attr['TOC-MARGIN-LEFT'],$this->mpdf->w,$this->mpdf->FontSize,false); }
  475. if (isset($attr['TOC-MARGIN-TOP'])) { $this->TOC_margin_top = $this->mpdf->ConvertSize($attr['TOC-MARGIN-TOP'],$this->mpdf->w,$this->mpdf->FontSize,false); }
  476. if (isset($attr['TOC-MARGIN-BOTTOM'])) { $this->TOC_margin_bottom = $this->mpdf->ConvertSize($attr['TOC-MARGIN-BOTTOM'],$this->mpdf->w,$this->mpdf->FontSize,false); }
  477. if (isset($attr['TOC-MARGIN-HEADER'])) { $this->TOC_margin_header = $this->mpdf->ConvertSize($attr['TOC-MARGIN-HEADER'],$this->mpdf->w,$this->mpdf->FontSize,false); }
  478. if (isset($attr['TOC-MARGIN-FOOTER'])) { $this->TOC_margin_footer = $this->mpdf->ConvertSize($attr['TOC-MARGIN-FOOTER'],$this->mpdf->w,$this->mpdf->FontSize,false); }
  479. $this->TOC_odd_header_name = $this->TOC_even_header_name = $this->TOC_odd_footer_name = $this->TOC_even_footer_name = '';
  480. if (isset($attr['TOC-ODD-HEADER-NAME']) && $attr['TOC-ODD-HEADER-NAME']) { $this->TOC_odd_header_name = $attr['TOC-ODD-HEADER-NAME']; }
  481. if (isset($attr['TOC-EVEN-HEADER-NAME']) && $attr['TOC-EVEN-HEADER-NAME']) { $this->TOC_even_header_name = $attr['TOC-EVEN-HEADER-NAME']; }
  482. if (isset($attr['TOC-ODD-FOOTER-NAME']) && $attr['TOC-ODD-FOOTER-NAME']) { $this->TOC_odd_footer_name = $attr['TOC-ODD-FOOTER-NAME']; }
  483. if (isset($attr['TOC-EVEN-FOOTER-NAME']) && $attr['TOC-EVEN-FOOTER-NAME']) { $this->TOC_even_footer_name = $attr['TOC-EVEN-FOOTER-NAME']; }
  484. $this->TOC_odd_header_value = $this->TOC_even_header_value = $this->TOC_odd_footer_value = $this->TOC_even_footer_value = 0;
  485. if (isset($attr['TOC-ODD-HEADER-VALUE']) && ($attr['TOC-ODD-HEADER-VALUE']=='1' || strtoupper($attr['TOC-ODD-HEADER-VALUE'])=='ON')) { $this->TOC_odd_header_value = 1; }
  486. else if (isset($attr['TOC-ODD-HEADER-VALUE']) && ($attr['TOC-ODD-HEADER-VALUE']=='-1' || strtoupper($attr['TOC-ODD-HEADER-VALUE'])=='OFF')) { $this->TOC_odd_header_value = -1; }
  487. if (isset($attr['TOC-EVEN-HEADER-VALUE']) && ($attr['TOC-EVEN-HEADER-VALUE']=='1' || strtoupper($attr['TOC-EVEN-HEADER-VALUE'])=='ON')) { $this->TOC_even_header_value = 1; }
  488. else if (isset($attr['TOC-EVEN-HEADER-VALUE']) && ($attr['TOC-EVEN-HEADER-VALUE']=='-1' || strtoupper($attr['TOC-EVEN-HEADER-VALUE'])=='OFF')) { $this->TOC_even_header_value = -1; }
  489. if (isset($attr['TOC-ODD-FOOTER-VALUE']) && ($attr['TOC-ODD-FOOTER-VALUE']=='1' || strtoupper($attr['TOC-ODD-FOOTER-VALUE'])=='ON')) { $this->TOC_odd_footer_value = 1; }
  490. else if (isset($attr['TOC-ODD-FOOTER-VALUE']) && ($attr['TOC-ODD-FOOTER-VALUE']=='-1' || strtoupper($attr['TOC-ODD-FOOTER-VALUE'])=='OFF')) { $this->TOC_odd_footer_value = -1; }
  491. if (isset($attr['TOC-EVEN-FOOTER-VALUE']) && ($attr['TOC-EVEN-FOOTER-VALUE']=='1' || strtoupper($attr['TOC-EVEN-FOOTER-VALUE'])=='ON')) { $this->TOC_even_footer_value = 1; }
  492. else if (isset($attr['TOC-EVEN-FOOTER-VALUE']) && ($attr['TOC-EVEN-FOOTER-VALUE']=='-1' || strtoupper($attr['TOC-EVEN-FOOTER-VALUE'])=='OFF')) { $this->TOC_even_footer_value = -1; }
  493. if (isset($attr['TOC-PAGE-SELECTOR']) && $attr['TOC-PAGE-SELECTOR']) { $this->TOC_page_selector = $attr['TOC-PAGE-SELECTOR']; }
  494. else { $this->TOC_page_selector = ''; }
  495. if (isset($attr['TOC-SHEET-SIZE']) && $attr['TOC-SHEET-SIZE']) { $this->TOCsheetsize = $attr['TOC-SHEET-SIZE']; } else { $this->TOCsheetsize = ''; }
  496. if (isset($attr['TOC-PREHTML']) && $attr['TOC-PREHTML']) { $this->TOCpreHTML = htmlspecialchars_decode($attr['TOC-PREHTML'],ENT_QUOTES); }
  497. if (isset($attr['TOC-POSTHTML']) && $attr['TOC-POSTHTML']) { $this->TOCpostHTML = htmlspecialchars_decode($attr['TOC-POSTHTML'],ENT_QUOTES); }
  498. if (isset($attr['TOC-BOOKMARKTEXT']) && $attr['TOC-BOOKMARKTEXT']) { $this->TOCbookmarkText = htmlspecialchars_decode($attr['TOC-BOOKMARKTEXT'],ENT_QUOTES); }
  499. }
  500. if ($this->mpdf->y == $this->mpdf->tMargin && (!$this->mpdf->mirrorMargins ||($this->mpdf->mirrorMargins && $this->mpdf->page % 2==1))) {
  501. if ($toc_id) { $this->m_TOC[$toc_id]['TOCmark'] = $this->mpdf->page; }
  502. else { $this->TOCmark = $this->mpdf->page; }
  503. // Don't add a page
  504. if ($this->mpdf->page==1 && count($this->mpdf->PageNumSubstitutions)==0) {
  505. $resetpagenum = '';
  506. $pagenumstyle = '';
  507. $suppress = '';
  508. if (isset($attr['RESETPAGENUM'])) { $resetpagenum = $attr['RESETPAGENUM']; }
  509. if (isset($attr['PAGENUMSTYLE'])) { $pagenumstyle = $attr['PAGENUMSTYLE']; }
  510. if (isset($attr['SUPPRESS'])) { $suppress = $attr['SUPPRESS']; }
  511. if (!$suppress) { $suppress = 'off'; }
  512. if (!$resetpagenum) { $resetpagenum= 1; }
  513. $this->mpdf->PageNumSubstitutions[] = array('from'=>1, 'reset'=> $resetpagenum, 'type'=>$pagenumstyle, 'suppress'=> $suppress);
  514. }
  515. return array(true, $toc_id);
  516. }
  517. // No break - continues as PAGEBREAK...
  518. return array(false, $toc_id);
  519. }
  520. }
  521. ?>