*/ use dokuwiki\plugin\dw2pdf\DokuImageProcessorDecorator; require_once __DIR__ . '/vendor/autoload.php'; /** * Class DokuPDF * Some DokuWiki specific extentions */ class DokuPDF extends \Mpdf\Mpdf { /** * DokuPDF constructor. * * @param string $pagesize * @param string $orientation * @param int $fontsize */ function __construct($pagesize = 'A4', $orientation = 'portrait', $fontsize = 11) { global $conf; global $lang; global $ID; if (!defined('_MPDF_TEMP_PATH')) define('_MPDF_TEMP_PATH', $conf['tmpdir'] . '/dwpdf/' . rand(1, 1000) . '/'); io_mkdir_p(_MPDF_TEMP_PATH); $format = $pagesize; if ($orientation == 'landscape') { $format .= '-L'; } $docLang = $this->getDocumentLanguage($ID); switch ($docLang) { case 'zh': case 'zh-tw': case 'ja': case 'ko': $mode = '+aCJK'; break; default: $mode = 'UTF-8-s'; } parent::__construct([ 'mode' => $mode, 'format' => $format, 'default_font_size' => $fontsize, 'ImageProcessorClass' => DokuImageProcessorDecorator::class, 'tempDir' => _MPDF_TEMP_PATH, //$conf['tmpdir'] . '/tmp/dwpdf' 'SHYlang' => $docLang, ]); $this->autoScriptToLang = true; $this->baseScript = 1; $this->autoVietnamese = true; $this->autoArabic = true; $this->autoLangToFont = true; $this->ignore_invalid_utf8 = true; $this->tabSpaces = 4; // assumed that global language can be used, maybe Bookcreator needs more nuances? $this->SetDirectionality($lang['direction']); } /** * Cleanup temp dir */ function __destruct() { io_rmdir(_MPDF_TEMP_PATH, true); } /** * Decode all paths, since DokuWiki uses XHTML compliant URLs * * @param string $path * @param string $basepath */ function GetFullPath(&$path, $basepath = '') { $path = htmlspecialchars_decode($path); parent::GetFullPath($path, $basepath); } /** * Get the language of the current document * * Uses the translation plugin if available * @return string */ protected function getDocumentLanguage($pageid) { global $conf; $lang = $conf['lang']; /** @var helper_plugin_translation $trans */ $trans = plugin_load('helper', 'translation'); if ($trans) { $tr = $trans->getLangPart($pageid); if ($tr) $lang = $tr; } return $lang; } }