PDF-Bogen: Notizen je Eintrag mitdrucken
- Fertigkeiten, Waffen, Rüstungen und Inventar zeigen ihre Notiz klein und gedämpft direkt hinter dem Namen - Zauber/Liturgien führen die Notiz in Klammern hinter dem Namen - neues WsPdf::fit() kürzt Text passend zur verfügbaren Breite mit Ellipse
This commit is contained in:
parent
929aa52c73
commit
de7c5f57fc
2 changed files with 68 additions and 5 deletions
|
|
@ -172,6 +172,28 @@ final class WsPdf
|
|||
return $lines;
|
||||
}
|
||||
|
||||
/** Text auf eine Breite kürzen und mit Auslassungszeichen versehen. */
|
||||
public static function fit(string $text, float $size, string $font, float $maxWidth): string
|
||||
{
|
||||
$text = trim(preg_replace('/\s+/u', ' ', $text) ?? '');
|
||||
if ($text === '' || $maxWidth <= 0) {
|
||||
return '';
|
||||
}
|
||||
if (self::textWidth($text, $size, $font) <= $maxWidth) {
|
||||
return $text;
|
||||
}
|
||||
$ellipsis = '…';
|
||||
$reserve = self::textWidth($ellipsis, $size, $font);
|
||||
$result = '';
|
||||
foreach (preg_split('//u', $text, -1, PREG_SPLIT_NO_EMPTY) ?: [] as $char) {
|
||||
if (self::textWidth($result . $char, $size, $font) + $reserve > $maxWidth) {
|
||||
break;
|
||||
}
|
||||
$result .= $char;
|
||||
}
|
||||
return rtrim($result) . $ellipsis;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bettet ein JPEG ein (DCTDecode, keine Neukodierung nötig).
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue