Skip to content

Commit

Permalink
Adds configurable output path for generated font files, Resolves #128
Browse files Browse the repository at this point in the history
  • Loading branch information
maechler committed Oct 23, 2019
1 parent c71d8d2 commit 04a4d27
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 6 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,3 @@

/.Build
/composer.lock

/Resources/Private/PHP/tcpdf/fonts/opensans*
/Resources/Private/PHP/tcpdf/fonts/roboto*
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog for TYPO3 CMS Extension pdfviewhelpers

## 2.2.0 - Not yet released

- Adds configurable output path for generated font files, [#128](https://github.com/bithost-gmbh/pdfviewhelpers/issues/128)

## 2.1.0 - April 30, 2019
- Adds paragraph line feed to textual ViewHelpers, [#107](https://github.com/bithost-gmbh/pdfviewhelpers/issues/107) (Thanks [@emmemme](https://github.com/emmemme))
- Adds image processing to ImageViewHelper, [#104](https://github.com/bithost-gmbh/pdfviewhelpers/issues/104)
Expand Down
30 changes: 30 additions & 0 deletions Classes/Model/BasePDF.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ class BasePDF extends Fpdi
const SCOPE_THIS_PAGE_INCLUDING_PAGE_BREAKS = 'thisPageIncludingPageBreaks';
const SCOPE_DOCUMENT = 'document';

/**
* Storing the path of custom fonts to use them on setFont
*
* @var array
*/
protected $customFontFilePaths = [];

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -278,6 +285,29 @@ public function setPageFormat($format, $orientation = 'P')
parent::setPageFormat($format, $orientation);
}

/**
* Overwrite SetFont in order to automatically provide paths to custom fonts
*
* @inheritdoc
*/
public function SetFont($family, $style='', $size=null, $fontfile='', $subset='default', $out=true)
{
if (empty($fontfile) && isset($this->customFontFilePaths[$family])) {
$fontfile = $this->customFontFilePaths[$family];
}

parent::SetFont($family, $style, $size, $fontfile, $subset, $out);
}

/**
* @param $fontName
* @param $fontFilePath
*/
public function addCustomFontFilePath($fontName, $fontFilePath)
{
$this->customFontFilePaths[$fontName] = $fontFilePath;
}

/**
* @return integer
*/
Expand Down
18 changes: 15 additions & 3 deletions Classes/ViewHelpers/DocumentViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,30 @@ protected function loadTcpdfLanguageSettings()
/**
* @return void
*
* @throws ValidationException
* @throws Exception
*/
protected function loadCustomFonts()
{
if (empty($this->settings['config']['fonts']['addTTFFont'])) {
return;
}

$outputPath = GeneralUtility::getFileAbsFileName($this->settings['config']['fonts']['outputPath']);
$outputPath = rtrim($outputPath, '/') . '/';

if (!is_dir($outputPath)) {
GeneralUtility::mkdir_deep($outputPath);
}

foreach ($this->settings['config']['fonts']['addTTFFont'] as $ttfFontName => $ttfFont) {
$path = GeneralUtility::getFileAbsFileName($ttfFont['path']);
$type = isset($ttfFont['type']) ? $ttfFont['type'] : '';

$fontName = \TCPDF_FONTS::addTTFfont($path, $type);
$fontName = \TCPDF_FONTS::addTTFfont($path, $type, '', 32, $outputPath);

if ($fontName === false) {
throw new ValidationException('Font "' . $ttfFontName . '" could not be added. ERROR: 1492808000', 1492808000);
} else {
$this->getPDF()->addCustomFontFilePath($fontName, $outputPath . $fontName . '.php');
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Configuration/TypoScript/setup.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ plugin.tx_pdfviewhelpers.settings {
}
fonts {
subset = 1
outputPath = typo3temp/pdfviewhelpers/fonts/
addTTFFont {
# roboto {
# path = EXT:pdfviewhelpers/Resources/Public/Examples/FullFeatureShowCase/Roboto.ttf
Expand Down
10 changes: 10 additions & 0 deletions Documentation/ConfigurationReference/TypoScriptReference/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Properties in plugin.tx_pdfviewhelpers.settings
config.allowedImageTypes_ Array *See static TypoScript template*
config.fonts.subset_ :ref:`t3tsref:data-type-boolean` 1
config.fonts.addTTFFont_ Array *See static TypoScript template*
config.fonts.outputPath_ :ref:`t3tsref:data-type-string` typo3temp/pdfviewhelpers/fonts/
document.title_ :ref:`t3tsref:data-type-string`
document.subject_ :ref:`t3tsref:data-type-string`
document.author_ :ref:`t3tsref:data-type-string`
Expand Down Expand Up @@ -236,6 +237,15 @@ config.fonts.addTTFFont

Possibility to add custom fonts, please have a look at the dedicated chapter Custom Fonts.

.. _config.fonts.outputPath:

config.fonts.outputPath
"""""""""""""""""""""""

:typoscript:`plugin.tx_pdfviewhelpers.settings.config.fonts.outputPath =` :ref:`t3tsref:data-type-string`

Path to directory where font files of custom fonts should be stored. This folder can safely be deleted and will automatically be re/created if it does not exist.

.. _document.title:

document.title
Expand Down

0 comments on commit 04a4d27

Please sign in to comment.