BerichtPdf: SetFont-Override routet Hack-Styles auf die richtige Family [deploy]
All checks were successful
Deploy bericht / deploy (push) Successful in 1s
All checks were successful
Deploy bericht / deploy (push) Successful in 1s
TCPDF_FONTS::addTTFfont registriert jede TTF als eigene Family ohne Styles (hackregular, hackbold, hackitalic, hackbolditalic). SetFont(key,'B') suchte dann nach 'hack.php' und brach mit 'Could not include font definition file' ab. Fix: hack_font_styles-Map ['' / B / I / BI] => family, SetFont-Override mapped den angeforderten Style auf die passende Family mit leerem Style und fällt kaskadierend zurück (BI→B→'', I→'').
This commit is contained in:
parent
3a7ed278e5
commit
b338d4e369
1 changed files with 34 additions and 7 deletions
|
|
@ -11,10 +11,11 @@
|
|||
|
||||
trait BerichtPdfTrait
|
||||
{
|
||||
public $hack_font_key = 'helvetica';
|
||||
public $bericht_title = '';
|
||||
public $bericht_company = '';
|
||||
public $bericht_logo = '';
|
||||
public $hack_font_key = 'helvetica';
|
||||
public $hack_font_styles = array(); // style => font-family-key
|
||||
public $bericht_title = '';
|
||||
public $bericht_company = '';
|
||||
public $bericht_logo = '';
|
||||
|
||||
/**
|
||||
* Muss direkt nach der Konstruktion aufgerufen werden.
|
||||
|
|
@ -37,7 +38,6 @@ trait BerichtPdfTrait
|
|||
'I' => 'Hack-Italic.ttf',
|
||||
'BI' => 'Hack-BoldItalic.ttf',
|
||||
);
|
||||
$reg_key = null;
|
||||
foreach ($map as $style => $fn) {
|
||||
$src = $fontdir.$fn;
|
||||
if (!file_exists($src)) continue;
|
||||
|
|
@ -46,21 +46,48 @@ trait BerichtPdfTrait
|
|||
if ($k) {
|
||||
$ffile = $outdir.$k.'.php';
|
||||
if (file_exists($ffile)) {
|
||||
// WICHTIG: Jede TTF wird als eigene Family mit style='' registriert,
|
||||
// sonst sucht TCPDF bei SetFont(..., 'B') nach "hackB.php" und
|
||||
// bricht mit "Could not include font definition file" ab.
|
||||
$this->AddFont($k, '', $ffile);
|
||||
$this->hack_font_styles[$style] = $k;
|
||||
}
|
||||
if ($style === '') $reg_key = $k;
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
error_log('[BerichtPdf] Hack-Font '.$fn.' fehlgeschlagen: '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
if ($reg_key) $this->hack_font_key = $reg_key;
|
||||
if (!empty($this->hack_font_styles[''])) {
|
||||
$this->hack_font_key = $this->hack_font_styles[''];
|
||||
}
|
||||
} else {
|
||||
error_log('[BerichtPdf] Font-Outdir nicht schreibbar: '.$outdir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Leitet SetFont() um, wenn die Family einer unserer Hack-Varianten ist:
|
||||
* ein Style-Wechsel ('B'/'I'/'BI') wird auf die passende Hack-Family mit
|
||||
* leerem Style gemappt. So vermeiden wir den TCPDF-Fallback auf "hack.php".
|
||||
*/
|
||||
public function SetFont($family, $style = '', $size = null, $fontfile = '', $subset = 'default', $out = true)
|
||||
{
|
||||
$fam = strtolower($family);
|
||||
$is_hack = in_array($fam, $this->hack_font_styles, true);
|
||||
if ($is_hack && !empty($this->hack_font_styles)) {
|
||||
$st = strtoupper(str_replace('U', '', (string) $style));
|
||||
if (!isset($this->hack_font_styles[$st])) {
|
||||
// Kaskade: BI → B → '', I → ''
|
||||
if ($st === 'BI' && isset($this->hack_font_styles['B'])) $st = 'B';
|
||||
elseif (isset($this->hack_font_styles[''])) $st = '';
|
||||
}
|
||||
$target = $this->hack_font_styles[$st] ?? $this->hack_font_styles[''] ?? $family;
|
||||
return parent::SetFont($target, '', $size, $fontfile, $subset, $out);
|
||||
}
|
||||
return parent::SetFont($family, $style, $size, $fontfile, $subset, $out);
|
||||
}
|
||||
|
||||
public function Header()
|
||||
{
|
||||
$pageW = $this->getPageWidth();
|
||||
|
|
|
|||
Loading…
Reference in a new issue