11ef68647SAndreas Gohr<?php 25db42babSAndreas Gohr/** 35db42babSAndreas Gohr * Wrapper around the mpdf library class 45db42babSAndreas Gohr * 55db42babSAndreas Gohr * This class overrides some functions to make mpdf make use of DokuWiki' 65db42babSAndreas Gohr * standard tools instead of its own. 75db42babSAndreas Gohr * 85db42babSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 95db42babSAndreas Gohr */ 10c1acf1feSGerrit Uitslagglobal $conf; 111c9fae9eSAndreas Gohrif(!defined('_MPDF_TEMP_PATH')) define('_MPDF_TEMP_PATH', $conf['tmpdir'] . '/dwpdf/' . rand(1, 1000) . '/'); 12b2853a2aSAndreas Gohrif(!defined('_MPDF_TTFONTDATAPATH')) define('_MPDF_TTFONTDATAPATH', $conf['cachedir'] . '/mpdf_ttf/'); 13ca0441e7SGerrit Uitslag 140119ca25SAndreas Gohrrequire_once __DIR__ . '/vendor/autoload.php'; 15*0576bb86SMichael Großerequire __DIR__ . '/DokuImageProcessorDecorator.class.php'; 161ef68647SAndreas Gohr 17ca0441e7SGerrit Uitslag/** 18ca0441e7SGerrit Uitslag * Class DokuPDF 19ca0441e7SGerrit Uitslag * Some DokuWiki specific extentions 20ca0441e7SGerrit Uitslag */ 210119ca25SAndreas Gohrclass DokuPDF extends \Mpdf\Mpdf { 221ef68647SAndreas Gohr 23f8f1ee5aSAndreas Gohr function __construct($pagesize = 'A4', $orientation = 'portrait', $fontsize = 11) { 245bd9be9cSGerrit Uitslag global $conf; 255bd9be9cSGerrit Uitslag 26b2853a2aSAndreas Gohr io_mkdir_p(_MPDF_TTFONTDATAPATH); 271c9fae9eSAndreas Gohr io_mkdir_p(_MPDF_TEMP_PATH); 281ef68647SAndreas Gohr 296ea88a05SAndreas Gohr $format = $pagesize; 30acf3824dSGerrit Uitslag if($orientation == 'landscape') { 31acf3824dSGerrit Uitslag $format .= '-L'; 32acf3824dSGerrit Uitslag } 336ea88a05SAndreas Gohr 345bd9be9cSGerrit Uitslag switch($conf['lang']) { 355bd9be9cSGerrit Uitslag case 'zh': 365bd9be9cSGerrit Uitslag case 'zh-tw': 375bd9be9cSGerrit Uitslag case 'ja': 385bd9be9cSGerrit Uitslag case 'ko': 395bd9be9cSGerrit Uitslag $mode = '+aCJK'; 405bd9be9cSGerrit Uitslag break; 415bd9be9cSGerrit Uitslag default: 425bd9be9cSGerrit Uitslag $mode = 'UTF-8-s'; 435bd9be9cSGerrit Uitslag 445bd9be9cSGerrit Uitslag } 455bd9be9cSGerrit Uitslag 461ef68647SAndreas Gohr // we're always UTF-8 470119ca25SAndreas Gohr parent::__construct( 480119ca25SAndreas Gohr array( 490119ca25SAndreas Gohr 'mode' => $mode, 50f8f1ee5aSAndreas Gohr 'format' => $format, 51*0576bb86SMichael Große 'fontsize' => $fontsize, 52*0576bb86SMichael Große 'ImageProcessorClass' => DokuImageProcessorDecorator::class, 530119ca25SAndreas Gohr ) 540119ca25SAndreas Gohr ); 55*0576bb86SMichael Große 56c00b769aSLarsDW223 $this->autoScriptToLang = true; 57c00b769aSLarsDW223 $this->baseScript = 1; 58c00b769aSLarsDW223 $this->autoVietnamese = true; 59c00b769aSLarsDW223 $this->autoArabic = true; 60c00b769aSLarsDW223 $this->autoLangToFont = true; 61c00b769aSLarsDW223 621ef68647SAndreas Gohr $this->ignore_invalid_utf8 = true; 632585efdfSKlap-in $this->tabSpaces = 4; 641c9fae9eSAndreas Gohr } 651ef68647SAndreas Gohr 661c9fae9eSAndreas Gohr /** 671c9fae9eSAndreas Gohr * Cleanup temp dir 681c9fae9eSAndreas Gohr */ 691c9fae9eSAndreas Gohr function __destruct() { 70acf3824dSGerrit Uitslag io_rmdir(_MPDF_TEMP_PATH, true); 711ef68647SAndreas Gohr } 721ef68647SAndreas Gohr 73a06728a6SAndreas Gohr /** 74a06728a6SAndreas Gohr * Decode all paths, since DokuWiki uses XHTML compliant URLs 75a06728a6SAndreas Gohr */ 76a06728a6SAndreas Gohr function GetFullPath(&$path, $basepath = '') { 77a06728a6SAndreas Gohr $path = htmlspecialchars_decode($path); 78a06728a6SAndreas Gohr parent::GetFullPath($path, $basepath); 79a06728a6SAndreas Gohr } 801ef68647SAndreas Gohr} 81