1<?php 2/** 3 * Wrapper around the mpdf library class 4 * 5 * This class overrides some functions to make mpdf make use of DokuWiki' 6 * standard tools instead of its own. 7 * 8 * @author Andreas Gohr <andi@splitbrain.org> 9 */ 10 11use dokuwiki\plugin\dw2pdf\DokuImageProcessorDecorator; 12 13require_once __DIR__ . '/vendor/autoload.php'; 14 15/** 16 * Class DokuPDF 17 * Some DokuWiki specific extentions 18 */ 19class DokuPDF extends \Mpdf\Mpdf 20{ 21 22 /** 23 * DokuPDF constructor. 24 * 25 * @param string $pagesize 26 * @param string $orientation 27 * @param int $fontsize 28 */ 29 function __construct($pagesize = 'A4', $orientation = 'portrait', $fontsize = 11, $docLang = 'en') 30 { 31 global $conf; 32 global $lang; 33 34 if (!defined('_MPDF_TEMP_PATH')) define('_MPDF_TEMP_PATH', $conf['tmpdir'] . '/dwpdf/' . rand(1, 1000) . '/'); 35 io_mkdir_p(_MPDF_TEMP_PATH); 36 37 $format = $pagesize; 38 if ($orientation == 'landscape') { 39 $format .= '-L'; 40 } 41 42 switch ($docLang) { 43 case 'zh': 44 case 'zh-tw': 45 case 'ja': 46 case 'ko': 47 $mode = '+aCJK'; 48 break; 49 default: 50 $mode = 'UTF-8-s'; 51 52 } 53 54 parent::__construct([ 55 'mode' => $mode, 56 'format' => $format, 57 'default_font_size' => $fontsize, 58 'ImageProcessorClass' => DokuImageProcessorDecorator::class, 59 'tempDir' => _MPDF_TEMP_PATH, //$conf['tmpdir'] . '/tmp/dwpdf' 60 'SHYlang' => $docLang, 61 ]); 62 63 $this->autoScriptToLang = true; 64 $this->baseScript = 1; 65 $this->autoVietnamese = true; 66 $this->autoArabic = true; 67 $this->autoLangToFont = true; 68 69 $this->ignore_invalid_utf8 = true; 70 $this->tabSpaces = 4; 71 72 // assumed that global language can be used, maybe Bookcreator needs more nuances? 73 $this->SetDirectionality($lang['direction']); 74 } 75 76 /** 77 * Cleanup temp dir 78 */ 79 function __destruct() 80 { 81 io_rmdir(_MPDF_TEMP_PATH, true); 82 } 83 84 /** 85 * Decode all paths, since DokuWiki uses XHTML compliant URLs 86 * 87 * @param string $path 88 * @param string $basepath 89 */ 90 function GetFullPath(&$path, $basepath = '') 91 { 92 $path = htmlspecialchars_decode($path); 93 parent::GetFullPath($path, $basepath); 94 } 95 96 97} 98