diff --git a/AGENTS.md b/AGENTS.md index 572b41e..2514997 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -106,7 +106,10 @@ zauberturm.de: Nachtblau/Schwarz/Gold, Pergament, Animationen. hochladen und in einer frischen Installation einspielen. - **PDF-Export:** eigener kleiner PDF-Writer (`app/pdf.php` + `app/sheet.php`), A4-Pergamentbogen mit Goldrahmen – kein Composer, keine externen Dienste. - JPEG-Bilder werden als XObject eingebettet. + JPEG-Bilder werden als XObject eingebettet. Die Notizen je Eintrag (Fertigkeit, + Waffe, Rüstung, Inventar) stehen klein hinter dem Namen; Zauber/Liturgien + erscheinen je Grad als Tabelle mit Reichweite, Dauer und gekürzter + Beschreibung (`WsPdf::fit()`/`wrap()` kürzen auf die Spaltenbreite). - **Porträts:** Upload im Bogen (`POST /characters/{id}/portrait`), serverseitig per GD neu als JPEG kodiert (max. 900 px) nach `uploads/portraits/` (gitignored, PHP-Ausführung dort gesperrt). Ohne Upload greift diff --git a/westreiche_website/app/sheet.php b/westreiche_website/app/sheet.php index ec387fb..d061cd7 100644 --- a/westreiche_website/app/sheet.php +++ b/westreiche_website/app/sheet.php @@ -318,6 +318,42 @@ function character_pdf(array $c, array $extra): string 'arkan' => ['Arkane Zauber', $spells['arkan'] ?? []], 'klerikal' => ['Göttliche Liturgien', $spells['klerikal'] ?? []], ]; + + // Spalten des Zauberverzeichnisses (A4-Innenbreite rund 527 pt) + $spellCols = [ + 'name' => [$M, 142.0], + 'range' => [$M + 146.0, 78.0], + 'duration' => [$M + 228.0, 100.0], + 'summary' => [$M + 332.0, $inner - 332.0], + ]; + + // Zelleninhalt auf n Zeilen umbrechen, letzte Zeile bei Bedarf kürzen. + $cellLines = static function (string $text, float $width, int $maxLines): array { + $text = trim(preg_replace('/\s+/u', ' ', $text) ?? ''); + if ($text === '') { + return ['–']; + } + $wrapped = WsPdf::wrap($text, 7.4, 'F1', $width); + if (count($wrapped) > $maxLines) { + $lines = array_slice($wrapped, 0, $maxLines - 1); + $lines[] = WsPdf::fit(implode(' ', array_slice($wrapped, $maxLines - 1)), 7.4, 'F1', $width); + return $lines; + } + return $wrapped; + }; + + // Kopf je Grad – wird nach einem Seitenumbruch erneut gesetzt. + $spellHead = static function (int $grade, string $firstHead) use (&$y, $pdf, $gold, $soft, $spellCols, $M, $inner): void { + $pdf->text($M, $y + 8, 7.8, 'F4', $gold, 'Grad ' . $grade); + $y += 11; + foreach ([[$firstHead, 'name'], ['REICHWEITE', 'range'], ['DAUER', 'duration'], ['BESCHREIBUNG', 'summary']] as [$headLabel, $colKey]) { + $pdf->text($spellCols[$colKey][0], $y + 6.5, 6.4, 'F2', $soft, $headLabel); + } + $y += 9; + $pdf->line($M, $y, $M + $inner, $y, $gold, 0.4); + $y += 3.5; + }; + foreach ($spellBlocks as $key => [$label, $list]) { if ($list === []) { continue; @@ -328,25 +364,45 @@ function character_pdf(array $c, array $extra): string $byGrade[(int) $spell['grade']][] = $spell; } ksort($byGrade); + $firstHead = $key === 'klerikal' ? 'LITURGIE' : 'ZAUBER'; foreach ($byGrade as $grade => $entries) { - $names = []; + $ensure(44); + $spellHead((int) $grade, $firstHead); foreach ($entries as $entry) { - $spellName = (string) $entry['name']; - $spellNote = trim((string) ($entry['note'] ?? '')); - if ($spellNote !== '') { - $spellName .= ' (' . shorten($spellNote, 48) . ')'; + $range = trim((string) ($entry['range_text'] ?? '')); + $duration = trim((string) ($entry['duration'] ?? '')); + $summary = trim((string) ($entry['summary'] ?? '')); + $note = trim((string) ($entry['note'] ?? '')); + if ($note !== '') { + $summary = $summary === '' ? $note : $summary . ' · ' . $note; } - $names[] = $spellName; - } - foreach (WsPdf::wrap('Grad ' . $grade . ': ' . implode(', ', $names), 8.6, 'F3', $inner - 6) as $i => $line) { - $ensure(12); - if ($i === 0) { - $pdf->text($M, $y + 8.5, 8.6, 'F2', $gold, ''); + + // Reichweite und Dauer zwei Zeilen, Beschreibung drei Zeilen. + $rangeLines = $cellLines($range, $spellCols['range'][1] - 6, 2); + $durationLines = $cellLines($duration, $spellCols['duration'][1] - 6, 2); + $descLines = $cellLines($summary, $spellCols['summary'][1], 3); + $lineCount = max(count($rangeLines), count($durationLines), count($descLines)); + $rowHeight = max(12.0, $lineCount * 8.6 + 4.0); + + if ($y + $rowHeight > $H - 70) { + $newPage(); + $spellHead((int) $grade, $firstHead); } - $pdf->text($M + 2, $y + 8.5, 8.6, 'F3', $ink, $line); - $y += 11.6; + + $pdf->text($spellCols['name'][0], $y + 8, 8.2, 'F3', $ink, WsPdf::fit((string) $entry['name'], 8.2, 'F3', $spellCols['name'][1] - 6)); + foreach ($rangeLines as $i => $line) { + $pdf->text($spellCols['range'][0], $y + 8 + $i * 8.6, 7.4, 'F1', $soft, $line); + } + foreach ($durationLines as $i => $line) { + $pdf->text($spellCols['duration'][0], $y + 8 + $i * 8.6, 7.4, 'F1', $soft, $line); + } + foreach ($descLines as $i => $line) { + $pdf->text($spellCols['summary'][0], $y + 8 + $i * 8.6, 7.4, 'F1', $soft, $line); + } + $y += $rowHeight; + $pdf->line($M, $y - 1.6, $M + $inner, $y - 1.6, $goldLight, 0.22); } - $y += 2; + $y += 6; } $y += 2; }