diff --git a/src/DokuMpdf.php b/src/DokuMpdf.php index 2dac481..0266cc6 100644 --- a/src/DokuMpdf.php +++ b/src/DokuMpdf.php @@ -32,6 +32,23 @@ public function __construct(Config $config, string $lang) $initConfig = $config->getMPdfConfig(); $initConfig['mode'] = $this->lang2mode($lang); + $tplfonts = DOKU_PLUGIN . 'dw2pdf/tpl/' . $config->getTemplateName() . '/fonts'; + if (file_exists($tplfonts . '.php')) { + $defaultFontConfig = (new \Mpdf\Config\FontVariables())->getDefaults(); + $fontData = $initConfig['fontdata'] ?? $defaultFontConfig['fontdata']; + + $defaultConfig = (new \Mpdf\Config\ConfigVariables())->getDefaults(); + $fontDirs = $initConfig['fontDir'] ?? $defaultConfig['fontDir']; + + $fontDirs[] = $tplfonts; + + $fontDefs = array($fontData, include($tplfonts . '.php')); + $fontData = array_reduce($fontDefs, 'array_merge', array()); + + $initConfig['fontDir'] = $fontDirs; + $initConfig['fontdata'] = $fontData; + } + $http = new HttpClient(); $container = new SimpleContainer([ diff --git a/tpl/default/README.txt b/tpl/default/README.txt index 60216e4..58233a9 100644 --- a/tpl/default/README.txt +++ b/tpl/default/README.txt @@ -67,3 +67,20 @@ Custom stylings can be provided in the following file of your dw2pdf-template fo You can use all the CSS that is understood by mpdf (See http://mpdf1.com/manual/index.php?tid=34) +===== Fonts ===== + +You can use custom fonts with your template by creating file ''fonts.php'' within your template folder. E.g.: + + + [ + 'R' => 'Frutiger-Normal.ttf', + 'I' => 'FrutigerObl-Normal.ttf', + ] +]; + + +Copy the font files to the ''fonts/'' subfolder within your template folder. + +You can use them on your template by using CSS style ''font-family: frutiger'', where "frutiger" is the name of the font on your ''fonts.php'' file.