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).
|
||||
*
|
||||
|
|
|
|||
|
|
@ -207,7 +207,16 @@ function character_pdf(array $c, array $extra): string
|
|||
$y += 4;
|
||||
foreach ($weapons as $weapon) {
|
||||
$ensure(13);
|
||||
$pdf->text($M, $y + 8.5, 8.6, 'F3', $ink, shorten((string) $weapon['name'], 40));
|
||||
$weaponName = shorten((string) $weapon['name'], 40);
|
||||
$pdf->text($M, $y + 8.5, 8.6, 'F3', $ink, $weaponName);
|
||||
$weaponNote = trim((string) ($weapon['note'] ?? ''));
|
||||
if ($weaponNote !== '') {
|
||||
$noteX = $M + WsPdf::textWidth($weaponName, 8.6, 'F3') + 6;
|
||||
$noteLimit = $M + 194;
|
||||
if ($noteLimit - $noteX > 26) {
|
||||
$pdf->text($noteX, $y + 8.5, 6.8, 'F1', $soft, WsPdf::fit($weaponNote, 6.8, 'F1', $noteLimit - $noteX));
|
||||
}
|
||||
}
|
||||
$pdf->text($M + 200, $y + 8.5, 7.6, 'F1', $soft, (string) $weapon['category']);
|
||||
$pdf->textRight($M + $inner - 74, $y + 8.5, 8.6, 'F2', $ink, signed(weapon_attack_total($c, $weapon)));
|
||||
$pdf->textRight($M + $inner, $y + 8.5, 8.6, 'F3', $ink, weapon_damage_total($c, $weapon));
|
||||
|
|
@ -230,7 +239,16 @@ function character_pdf(array $c, array $extra): string
|
|||
$y += 4;
|
||||
foreach ($armors as $armor) {
|
||||
$ensure(13);
|
||||
$pdf->text($M, $y + 8.5, 8.6, 'F3', $ink, shorten((string) $armor['name'], 40));
|
||||
$armorName = shorten((string) $armor['name'], 40);
|
||||
$pdf->text($M, $y + 8.5, 8.6, 'F3', $ink, $armorName);
|
||||
$armorNote = trim((string) ($armor['note'] ?? ''));
|
||||
if ($armorNote !== '') {
|
||||
$noteX = $M + WsPdf::textWidth($armorName, 8.6, 'F3') + 6;
|
||||
$noteLimit = $M + 194;
|
||||
if ($noteLimit - $noteX > 26) {
|
||||
$pdf->text($noteX, $y + 8.5, 6.8, 'F1', $soft, WsPdf::fit($armorNote, 6.8, 'F1', $noteLimit - $noteX));
|
||||
}
|
||||
}
|
||||
$pdf->text($M + 200, $y + 8.5, 7.6, 'F1', $soft, (string) $armor['kind']);
|
||||
$pdf->textRight($M + $inner - 60, $y + 8.5, 8.6, 'F2', $ink, signed((int) $armor['ac_bonus']));
|
||||
$pdf->textRight($M + $inner, $y + 8.5, 7.6, 'F1', $soft, (int) $armor['equipped'] === 1 ? 'angelegt' : 'abgelegt');
|
||||
|
|
@ -273,7 +291,16 @@ function character_pdf(array $c, array $extra): string
|
|||
$skill = $rows[$index];
|
||||
$cx = $M + $col * ($colW + 16);
|
||||
$mod = skill_attribute_modifier($c, $skill);
|
||||
$pdf->text($cx, $y + 8.5, 8.4, 'F3', $ink, shorten((string) $skill['name'], 34));
|
||||
$skillName = shorten((string) $skill['name'], 34);
|
||||
$pdf->text($cx, $y + 8.5, 8.4, 'F3', $ink, $skillName);
|
||||
$skillNote = trim((string) ($skill['note'] ?? ''));
|
||||
if ($skillNote !== '') {
|
||||
$noteX = $cx + WsPdf::textWidth($skillName, 8.4, 'F3') + 6;
|
||||
$noteLimit = $cx + $colW - 84;
|
||||
if ($noteLimit - $noteX > 26) {
|
||||
$pdf->text($noteX, $y + 8.4, 6.8, 'F1', $soft, WsPdf::fit($skillNote, 6.8, 'F1', $noteLimit - $noteX));
|
||||
}
|
||||
}
|
||||
$pdf->text($cx + $colW - 64, $y + 8.2, 6.6, 'F1', $soft, trim((string) ($skill['attribute'] ?? '')));
|
||||
$pdf->textRight($cx + $colW - 28, $y + 8.2, 6.8, 'F1', $soft, $mod === null ? '–' : signed($mod));
|
||||
$pdf->textRight($cx + $colW, $y + 8.5, 8.4, 'F2', $gold, (string) max(0, (int) $skill['bonus']));
|
||||
|
|
@ -304,7 +331,12 @@ function character_pdf(array $c, array $extra): string
|
|||
foreach ($byGrade as $grade => $entries) {
|
||||
$names = [];
|
||||
foreach ($entries as $entry) {
|
||||
$names[] = (string) $entry['name'];
|
||||
$spellName = (string) $entry['name'];
|
||||
$spellNote = trim((string) ($entry['note'] ?? ''));
|
||||
if ($spellNote !== '') {
|
||||
$spellName .= ' (' . shorten($spellNote, 48) . ')';
|
||||
}
|
||||
$names[] = $spellName;
|
||||
}
|
||||
foreach (WsPdf::wrap('Grad ' . $grade . ': ' . implode(', ', $names), 8.6, 'F3', $inner - 6) as $i => $line) {
|
||||
$ensure(12);
|
||||
|
|
@ -332,8 +364,17 @@ function character_pdf(array $c, array $extra): string
|
|||
$y += 4;
|
||||
foreach ($items as $item) {
|
||||
$ensure(12);
|
||||
$itemName = shorten((string) $item['name'], 56);
|
||||
$pdf->text($M, $y + 8, 8.4, 'F1', $ink, ((int) $item['qty']) . '×');
|
||||
$pdf->text($M + 52, $y + 8, 8.6, 'F3', $ink, shorten((string) $item['name'], 56));
|
||||
$pdf->text($M + 52, $y + 8, 8.6, 'F3', $ink, $itemName);
|
||||
$itemNote = trim((string) ($item['note'] ?? ''));
|
||||
if ($itemNote !== '') {
|
||||
$noteX = $M + 52 + WsPdf::textWidth($itemName, 8.6, 'F3') + 6;
|
||||
$noteLimit = $M + $inner - 96;
|
||||
if ($noteLimit - $noteX > 26) {
|
||||
$pdf->text($noteX, $y + 8, 6.8, 'F1', $soft, WsPdf::fit($itemNote, 6.8, 'F1', $noteLimit - $noteX));
|
||||
}
|
||||
}
|
||||
$pdf->text($M + $inner - 78, $y + 8, 7.4, 'F1', $soft, (string) $item['category']);
|
||||
$pdf->textRight($M + $inner, $y + 8, 8.2, 'F3', $ink, (string) ($item['value'] !== '' ? $item['value'] : '–'));
|
||||
$pdf->line($M, $y + 10.4, $M + $inner, $y + 10.4, $goldLight, 0.22);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue