1<?php 2 3// phpcs:disable: PSR1.Methods.CamelCapsMethodName.NotCamelCaps 4 5use Mpdf\Mpdf; 6use dokuwiki\plugin\dw2pdf\DokuImageProcessorDecorator; 7 8/** 9 * Wrapper around the mpdf library class 10 * 11 * This class overrides some functions to make mpdf make use of DokuWiki' 12 * standard tools instead of its own. 13 * 14 * @author Andreas Gohr <andi@splitbrain.org> 15 */ 16class DokuPDF extends Mpdf 17{ 18 /** 19 * DokuPDF constructor. 20 * 21 * @param string $pagesize 22 * @param string $orientation 23 * @param int $fontsize 24 */ 25 public function __construct($pagesize = 'A4', $orientation = 'portrait', $fontsize = 11, $docLang = 'en') 26 { 27 global $conf; 28 global $lang; 29 30 require_once __DIR__ . '/vendor/autoload.php'; 31 32 if (!defined('_MPDF_TEMP_PATH')) { 33 define('_MPDF_TEMP_PATH', $conf['tmpdir'] . '/dwpdf/' . random_int(1, 1000) . '/'); 34 } 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 parent::__construct([ 54 'mode' => $mode, 55 'format' => $format, 56 'default_font_size' => $fontsize, 57 'ImageProcessorClass' => DokuImageProcessorDecorator::class, 58 'tempDir' => _MPDF_TEMP_PATH, //$conf['tmpdir'] . '/tmp/dwpdf' 59 'SHYlang' => $docLang, 60 ]); 61 62 $this->autoScriptToLang = true; 63 $this->baseScript = 1; 64 $this->autoVietnamese = true; 65 $this->autoArabic = true; 66 $this->autoLangToFont = true; 67 68 $this->ignore_invalid_utf8 = true; 69 $this->tabSpaces = 4; 70 71 // assumed that global language can be used, maybe Bookcreator needs more nuances? 72 $this->SetDirectionality($lang['direction']); 73 } 74 75 /** 76 * Cleanup temp dir 77 */ 78 public function __destruct() 79 { 80 io_rmdir(_MPDF_TEMP_PATH, true); 81 } 82 83 /** 84 * Decode all paths, since DokuWiki uses XHTML compliant URLs 85 * 86 * @param string $path 87 * @param string $basepath 88 */ 89 public function GetFullPath(&$path, $basepath = '') 90 { 91 $path = htmlspecialchars_decode($path); 92 parent::GetFullPath($path, $basepath); 93 } 94} 95