diff --git a/app/Domain/Catalog/DocumentPdf.php b/app/Domain/Catalog/DocumentPdf.php index 59d8ea0..76e6bf3 100644 --- a/app/Domain/Catalog/DocumentPdf.php +++ b/app/Domain/Catalog/DocumentPdf.php @@ -49,7 +49,7 @@ class DocumentPdf /** Höhe der Fußlinie über dem Seitenrand. */ private float $footerLine = 54.0; - /** @var array{header: ?array, footer: ?array, cover: ?array} */ + /** @var array{header: ?array, footer: ?array, cover: ?array} Grafiken samt Maßen, siehe {@see self::band()} */ private array $bands = ['header' => null, 'footer' => null, 'cover' => null]; /** @var array */ @@ -87,23 +87,26 @@ public function render(array $guide, string $licensee, string $copyId, ?PdfImage private function prepareLayout(?PdfTemplate $template): void { $this->bands = [ - 'header' => $this->band($template?->target('header'), 140.0), - 'footer' => $this->band($template?->target('footer'), 140.0), - 'cover' => $template !== null && $template->show_cover ? $this->band($template->target('cover'), self::PAGE_HEIGHT * 0.4) : null, + 'header' => $this->band($template?->target('header'), 140.0, 'header', $template?->layout('header')), + 'footer' => $this->band($template?->target('footer'), 140.0, 'footer', $template?->layout('footer')), + 'cover' => $template !== null && $template->show_cover ? $this->band($template->target('cover'), self::PAGE_HEIGHT * 0.4, 'cover') : null, ]; - $header = (float) ($this->bands['header']['height'] ?? 0); - $footer = (float) ($this->bands['footer']['height'] ?? 0); + $header = (float) ($this->bands['header']['occupied'] ?? 0); + $footer = (float) ($this->bands['footer']['occupied'] ?? 0); $this->top = $header > 0 ? min(790.0, self::PAGE_HEIGHT - $header - 26.0) : 790.0; $this->footerLine = max(54.0, $footer + 24.0); $this->bottom = $this->footerLine + 18.0; } /** - * Eine Grafik in Seitenbreite, bei zu großer Höhe verkleinert und zentriert. + * Eine Grafik für Kopf, Fuß oder Titelseite. Als Band steht sie in Seitenbreite (bei zu großer Höhe verkleinert und zentriert), + * als Logo hat sie die gewählte Höhe und steht am linken oder rechten Textrand, höchstens halb so breit wie der Text. + * `occupied` ist die Höhe, die sie am Seitenrand belegt; `y` die Unterkante. * - * @return array{jpeg: string, pixelWidth: int, pixelHeight: int, width: float, height: float, x: float}|null + * @param array{align: string, height: int}|null $layout nur für Kopf und Fuß + * @return array{jpeg: string, pixelWidth: int, pixelHeight: int, width: float, height: float, x: float, y: float, occupied: float}|null */ - private function band(?string $target, float $maxHeight): ?array + private function band(?string $target, float $maxHeight, string $edge, ?array $layout = null): ?array { $bytes = TemplateImage::bytes($target); $image = $bytes === null ? null : PdfImage::fromBytes($bytes); @@ -112,15 +115,45 @@ private function band(?string $target, float $maxHeight): ?array return null; } + $ratio = $image['width'] / max(1, $image['height']); + $align = $layout['align'] ?? 'full'; + $common = ['jpeg' => $image['jpeg'], 'pixelWidth' => $image['width'], 'pixelHeight' => $image['height']]; + + if ($edge !== 'cover' && $align !== 'full') { + $height = (float) ($layout['height'] ?? PdfTemplate::LOGO_DEFAULT); + $width = $height * $ratio; + + if ($width > (self::RIGHT - self::LEFT) / 2) { + $width = (self::RIGHT - self::LEFT) / 2; + $height = $width / $ratio; + } + + $padding = $edge === 'header' ? 24.0 : 14.0; + + return $common + [ + 'width' => $width, + 'height' => $height, + 'x' => $align === 'left' ? self::LEFT : self::RIGHT - $width, + 'y' => $edge === 'header' ? self::PAGE_HEIGHT - $padding - $height : $padding, + 'occupied' => $height + $padding, + ]; + } + $width = (float) PdfDocument::WIDTH; - $height = $width * $image['height'] / max(1, $image['width']); + $height = $width / $ratio; if ($height > $maxHeight) { $height = $maxHeight; - $width = $height * $image['width'] / max(1, $image['height']); + $width = $height * $ratio; } - return ['jpeg' => $image['jpeg'], 'pixelWidth' => $image['width'], 'pixelHeight' => $image['height'], 'width' => $width, 'height' => $height, 'x' => (PdfDocument::WIDTH - $width) / 2]; + return $common + [ + 'width' => $width, + 'height' => $height, + 'x' => (PdfDocument::WIDTH - $width) / 2, + 'y' => $edge === 'header' ? self::PAGE_HEIGHT - $height : 0.0, + 'occupied' => $height, + ]; } /** @@ -342,7 +375,7 @@ private function newPage(): void if (! $this->onCover && $this->bands['header'] !== null) { $band = $this->bands['header']; - $this->pdf->image($band['x'], self::PAGE_HEIGHT - $band['height'], $band['width'], $band['height'], $band['jpeg'], $band['pixelWidth'], $band['pixelHeight']); + $this->pdf->image($band['x'], $band['y'], $band['width'], $band['height'], $band['jpeg'], $band['pixelWidth'], $band['pixelHeight']); } } @@ -350,7 +383,7 @@ private function closePage(): void { if (! $this->onCover && $this->bands['footer'] !== null) { $band = $this->bands['footer']; - $this->pdf->image($band['x'], 0, $band['width'], $band['height'], $band['jpeg'], $band['pixelWidth'], $band['pixelHeight']); + $this->pdf->image($band['x'], $band['y'], $band['width'], $band['height'], $band['jpeg'], $band['pixelWidth'], $band['pixelHeight']); } $this->pdf->line(self::LEFT, $this->footerLine, self::RIGHT, $this->footerLine, 0.4); diff --git a/app/Domain/Catalog/PdfTemplate.php b/app/Domain/Catalog/PdfTemplate.php index 80c90d9..7bbff91 100644 --- a/app/Domain/Catalog/PdfTemplate.php +++ b/app/Domain/Catalog/PdfTemplate.php @@ -25,6 +25,10 @@ class PdfTemplate extends Model 'header_element_id', 'footer_element_id', 'cover_element_id', + 'header_align', + 'footer_align', + 'header_logo_height', + 'footer_logo_height', 'publisher', 'copyright', ]; @@ -36,6 +40,38 @@ protected function casts(): array public const SLOTS = ['header', 'footer', 'cover']; + /** Anordnung von Kopf- und Fußgrafik: Band in voller Seitenbreite oder Logo links oder rechts. */ + public const ALIGNMENTS = ['full', 'left', 'right']; + + public const LOGO_MIN = 16; + + public const LOGO_MAX = 100; + + public const LOGO_DEFAULT = 40; + + /** + * Anordnung und Logohöhe (Punkt) von Kopf oder Fuß; ungültige Werte fallen auf die Vorgabe zurück. + * + * @return array{align: string, height: int} + */ + public function layout(string $slot): array + { + return self::normalizeLayout((string) $this->getAttribute($slot.'_align'), (int) $this->getAttribute($slot.'_logo_height')); + } + + /** + * @return array{align: string, height: int} + */ + public static function normalizeLayout(?string $align, int|string|null $height): array + { + $height = (int) $height; + + return [ + 'align' => in_array($align, self::ALIGNMENTS, true) ? (string) $align : 'full', + 'height' => $height < 1 ? self::LOGO_DEFAULT : max(self::LOGO_MIN, min(self::LOGO_MAX, $height)), + ]; + } + /** * Das Bild eines Bildfelds als Ziel des Pickers: `element:`, `medium:` oder null. */ diff --git a/app/Filament/Pages/PdfVorlagen.php b/app/Filament/Pages/PdfVorlagen.php index 42387e3..0db7ee8 100644 --- a/app/Filament/Pages/PdfVorlagen.php +++ b/app/Filament/Pages/PdfVorlagen.php @@ -44,6 +44,20 @@ class PdfVorlagen extends Page public bool $showCover = true; + /** + * Anordnung von Kopf und Fuß: `full` (Band in voller Seitenbreite), `left` oder `right` (Logo). + * + * @var array + */ + public array $anordnung = ['header' => 'full', 'footer' => 'full']; + + /** + * Höhe des Logos in Punkt, wenn Kopf oder Fuß ein Logo tragen. + * + * @var array + */ + public array $logohoehe = ['header' => PdfTemplate::LOGO_DEFAULT, 'footer' => PdfTemplate::LOGO_DEFAULT]; + /** * Die Bilder je Bildfeld (header, footer, cover) als Ziel des Pickers: `element:` oder `medium:`. * @@ -107,14 +121,15 @@ public function changed(): bool $template = $this->templateId > 0 ? PdfTemplate::query()->find($this->templateId) : null; if (! $template instanceof PdfTemplate) { - return $this->name !== '' || $this->publisher !== '' || $this->copyright !== '' || array_filter($this->bilder) !== []; + return $this->name !== '' || $this->publisher !== '' || $this->copyright !== '' || array_filter($this->bilder) !== [] || $this->layouts() !== [PdfTemplate::normalizeLayout(null, null), PdfTemplate::normalizeLayout(null, null)]; } return $this->name !== $template->name || $this->publisher !== (string) $template->publisher || $this->copyright !== (string) $template->copyright || $this->showCover !== (bool) $template->show_cover - || $this->bilder !== $this->templateSlots($template); + || $this->bilder !== $this->templateSlots($template) + || $this->layouts() !== [$template->layout('header'), $template->layout('footer')]; } public function save(): void @@ -144,6 +159,10 @@ public function save(): void ...PdfTemplate::columns('header', $this->bilder['header']), ...PdfTemplate::columns('footer', $this->bilder['footer']), ...PdfTemplate::columns('cover', $this->bilder['cover']), + 'header_align' => $this->layouts()[0]['align'], + 'header_logo_height' => $this->layouts()[0]['height'], + 'footer_align' => $this->layouts()[1]['align'], + 'footer_logo_height' => $this->layouts()[1]['height'], 'publisher' => trim($this->publisher) === '' ? null : trim($this->publisher), 'copyright' => trim($this->copyright) === '' ? null : trim($this->copyright), ]; @@ -303,6 +322,21 @@ private function loadTemplate(PdfTemplate $template): void $this->copyright = (string) $template->copyright; $this->showCover = (bool) $template->show_cover; $this->bilder = $this->templateSlots($template); + $this->anordnung = ['header' => $template->layout('header')['align'], 'footer' => $template->layout('footer')['align']]; + $this->logohoehe = ['header' => $template->layout('header')['height'], 'footer' => $template->layout('footer')['height']]; + } + + /** + * Anordnung und Logohöhe von Kopf und Fuß, ungültige Eingaben auf gültige Werte gebracht. + * + * @return list + */ + private function layouts(): array + { + return [ + PdfTemplate::normalizeLayout($this->anordnung['header'] ?? null, $this->logohoehe['header'] ?? null), + PdfTemplate::normalizeLayout($this->anordnung['footer'] ?? null, $this->logohoehe['footer'] ?? null), + ]; } /** @@ -321,6 +355,8 @@ private function clearForm(): void $this->copyright = ''; $this->showCover = true; $this->bilder = ['header' => null, 'footer' => null, 'cover' => null]; + $this->anordnung = ['header' => 'full', 'footer' => 'full']; + $this->logohoehe = ['header' => PdfTemplate::LOGO_DEFAULT, 'footer' => PdfTemplate::LOGO_DEFAULT]; } protected function pickerExceptId(): int diff --git a/database/migrations/2026_11_30_100000_add_logo_layout_to_pdf_templates.php b/database/migrations/2026_11_30_100000_add_logo_layout_to_pdf_templates.php new file mode 100644 index 0000000..4a15c9f --- /dev/null +++ b/database/migrations/2026_11_30_100000_add_logo_layout_to_pdf_templates.php @@ -0,0 +1,30 @@ +string('header_align', 10)->default('full'); + $table->string('footer_align', 10)->default('full'); + $table->unsignedSmallInteger('header_logo_height')->default(40); + $table->unsignedSmallInteger('footer_logo_height')->default(40); + }); + } + + public function down(): void + { + Schema::table('pdf_templates', function (Blueprint $table) { + $table->dropColumn(['header_align', 'footer_align', 'header_logo_height', 'footer_logo_height']); + }); + } +}; diff --git a/docs/architektur/12_Entscheidungsprotokoll_ADR.md b/docs/architektur/12_Entscheidungsprotokoll_ADR.md index a73b81c..f7f389b 100644 --- a/docs/architektur/12_Entscheidungsprotokoll_ADR.md +++ b/docs/architektur/12_Entscheidungsprotokoll_ADR.md @@ -753,4 +753,6 @@ ## ADR-51 – Dokumente: Kapitel als Texte, Dokumentfassung als Komposition, Tab **Nachtrag (24.11.2026): PDF-Vorlagen für Dokumente.** Ein Dokument kann eine PDF-Vorlage verwenden (`pdf_templates`, Zuordnung `compositions.pdf_template_id`, Verwaltung unter Inhalte → PDF-Vorlagen). Die Vorlage ist reines Layout und legt fest: eine Titelseite, auf der der Titel allein steht (mit Untertitel, Ausgabe, Veröffentlichungsdatum, Herausgeber, Copyright-Vermerk und optional einem Titelbild), und eine Kopf- und eine Fußgrafik in voller Seitenbreite auf allen weiteren Seiten. Die Bilder wählt der gemeinsame Picker aus dem Medienbestand: jedes Bild mit vorhandener Datei, auch ohne Inhaltsfassung (Präsentationsmedien, für die Website freigegebene Bilder; Spalten `*_element_id`, Klasse `TemplateImage`); gedruckt wird die Website-Datei, sonst die Präsentationsdatei. Gestaltung ist kein lizenzierter Inhalt und braucht keine Freigabe der Fassung; nur ein gesperrtes oder archiviertes Bild wird abgelehnt. Die Bindung an freigegebene Bildfassungen gilt allein für Bilder im Text eines Dokuments. Untertitel, Ausgabe, Datum und Copyright-Vermerk sind Inhalt und gehören zur Dokumentfassung (`composition_versions.document_meta`, `DocumentMeta`); der Vermerk der Vorlage gilt nur, wenn die Fassung keinen hat. Eine Vorlage wirkt sofort auf jedes PDF der Dokumente, die sie verwenden, auch auf ältere Fassungen: Layout ist nicht Teil der Bindung. Die Angaben ändern den Änderungsnachweis (`structure_hash`) nur, wenn sie gesetzt sind; ältere Fassungen behalten ihren Nachweis. Ohne Vorlage bleibt das bisherige Layout unverändert. Die Kennzeichnung (Lizenzzeile und „Seite n von m“) steht auch auf der Titelseite. Das Muster-PDF einer Vorlage gibt es ohne Dokument. **Grenzen:** nur Helvetica (bewusst, siehe Lizenzfrage von Schriften im Druck), Grafiken als JPEG oder PNG ohne Transparenz, feste Anordnung der Titelseite. **Folgen:** eine additive Migration; der Rückfall zeigt Dokumente im vorherigen Stand nicht (SupportedKindScope) und kennt die Vorlagen nicht. Eine PDF-Bibliothek mit eigenen Schriften bleibt Option B, sobald eine Marke etabliert ist. Die gleiche Vorlagenverwaltung kann später für Übungs-PDFs und Belege genutzt werden; die Rechnung bleibt an OPEN-06 gebunden. +**Nachtrag (24.11.2026): Logo in Kopf und Fuß.** Kopf und Fuß einer PDF-Vorlage können statt eines Bands in voller Seitenbreite ein Logo links oder rechts am Textrand tragen (`header_align`/`footer_align` = `full`, `left`, `right`; `header_logo_height`/`footer_logo_height` in Punkt, 16 bis 100, Vorgabe 40; höchstens halbe Textbreite). Dasselbe Bild kommt aus dem Medienmanager wie bisher. Die Titelseite bleibt unberührt. **Folgen:** eine additive Migration mit Vorgaben; der vorherige Programmstand kennt die Spalten nicht und zeigt jede Grafik als Band. + **Nachtrag (24.11.2026): Überschriftenebenen im Kapiteltext.** Ein Dokument gliedert sich vor allem durch Kapitel der ersten Ebene und Überschriften im Text. Der Editor bietet dafür `h3` bis `h6` an (Dokumenttitel `h1`, Kapitel `h2`; `h1` und `h2` aus eingefügtem Text werden `h3`). Alle Überschriften des Kapiteltexts stehen automatisch im Inhaltsverzeichnis von Seite und PDF, eingerückt nach Stufe und ohne Nummer, mit Sprungmarken `kapitel--u` (gezählt werden die nicht leeren Überschriften auf oberster Ebene des Texts, nicht die in Tabellen) und, im PDF, mit Seitenzahl, Verweis und verschachtelten Lesezeichen (`PdfDocument::bookmark` kennt jetzt bis zu sechs Ebenen). Die Stufen sind im PDF nach Größe gestaffelt (h6 kursiv). Unter einem Unterkapitel rücken die Überschriften eine Stufe tiefer (höchstens `h6`), damit sie nie auf der Stufe des Unterkapitels stehen; ein Unterkapitel braucht man dafür nicht. **Bewusst offen:** Innerhalb eines Kapitels wird nicht geprüft, ob eine Überschrift im Text eine höhere oder gleiche Stufe wie die vorherige hat (Einzelbearbeitung). Ältere Fassungen behalten ihren Text; die gespeicherten `h3` erscheinen jetzt als `h3` statt `h4` und neu im Verzeichnis. **Folgen:** keine Migration; der Änderungsnachweis (Hash) bleibt unverändert, weil sich der gespeicherte Text nicht ändert. diff --git a/docs/ux/verwaltung/abnahme/pdf-vorlagen.md b/docs/ux/verwaltung/abnahme/pdf-vorlagen.md index 1049fba..a214d0a 100644 --- a/docs/ux/verwaltung/abnahme/pdf-vorlagen.md +++ b/docs/ux/verwaltung/abnahme/pdf-vorlagen.md @@ -28,17 +28,29 @@ ## Bilder ohne Inhaltsfassung | Vorlage mit beiden Bildern ausgefüllt | `08-vorlage-mit-webbildern.png` | | Vorlage gespeichert | `09-webbilder-gespeichert.png` | +## Logo links oder rechts in Kopf und Fuß + +Kopf und Fuß haben je eine **Anordnung**: „Band in voller Seitenbreite“ (Vorgabe, wie bisher), „Logo links“ oder „Logo rechts“. Bei einem Logo erscheint das Feld +„Höhe des Logos (Punkt)“ (16 bis 100, Vorgabe 40). Das Logo steht am Textrand (links 56, rechts 539 Punkt), im Kopf 24 Punkt unter dem oberen Rand, im Fuß 14 Punkt +über dem unteren; es ist höchstens halb so breit wie der Text. Der Text beginnt darunter beziehungsweise endet darüber. Die Titelseite trägt weiterhin nur ihr eigenes Bild. +Lokal geprüft (nicht auf luf-test): neue Vorlage, Kopf „Logo links“ mit Höhe 36, Fuß „Logo rechts“ mit 40, gespeichert, Muster-PDF zeigt beide Logos am Rand. + +| Schritt | Beleg | +|---|---| +| Anordnung und Logohöhe für Kopf und Fuß | `10-logo-anordnung.png` | +| Vorlage gespeichert | `11-logo-gespeichert.png` | + ## Automatisierte Prüfungen (`DokumentVorlageTest`, `DokumentAusgabeTest`, `PdfDocumentTest`) Titelseite mit allen Angaben und ohne Kapitel; Verzeichnis ab Seite 2 mit stimmenden Seitenzahlen; Titelbild nur auf Seite 1, Kopf und Fuß auf allen weiteren; Lizenzzeile auch auf der Titelseite; ohne Vorlage das bisherige Layout; Titelseite abschaltbar; Standard-Vermerk der Vorlage; Angaben je Fassung und Änderungsnachweis; Editor speichert Angaben im Entwurf und bindet sie mit der Fassung; Vorlagenseite (anlegen, ändern, Bilder -über den Picker auch ohne Inhaltsfassung (Präsentations- und Website-Bild), Bild im Entwurf wählbar, gesperrtes Bild, fehlende Datei und Nicht-Bild abgelehnt, löschen); Löschen gibt Dokumente an das einfache Layout zurück; Redaktionsvorschau nutzt Vorlage und Entwurfsangaben. +über den Picker auch ohne Inhaltsfassung (Präsentations- und Website-Bild), Bild im Entwurf wählbar, gesperrtes Bild, fehlende Datei und Nicht-Bild abgelehnt, löschen); Logo links und rechts mit Höhe und Maßen im PDF, breites Logo höchstens halbe Textbreite, Grenzen der Werte, Speichern der Anordnung auf der Seite; Löschen gibt Dokumente an das einfache Layout zurück; Redaktionsvorschau nutzt Vorlage und Entwurfsangaben. ## Abweichungen und offene Punkte - **Nicht auf luf-test geprüft.** Verkauf und Berechtigung der Abnahme wurden lokal per Skript angelegt. - **Nur Helvetica.** Eine Markenschrift braucht eine PDF-Bibliothek (Option B im ADR); die Schriftlizenz für gedruckte Werke bleibt zu klären. -- **Grafiken** als JPEG oder PNG ohne Transparenz (Transparenz wird auf Weiß gesetzt). Kopf und Fuß höchstens 140 Punkt hoch, das Titelbild höchstens 40 % der Seite. +- **Grafiken** als JPEG oder PNG ohne Transparenz (Transparenz wird auf Weiß gesetzt). Kopf und Fuß als Band höchstens 140 Punkt hoch (als Logo 16 bis 100 Punkt), das Titelbild höchstens 40 % der Seite. - **Übungs-PDF und Beleg** nutzen noch keine Vorlage. Die Verwaltung ist so angelegt, dass weitere Arten folgen können (Spalte `kind`). - **Im Bild der Dokumentseite** bleibt das Feld „Herausgeber“ der Vorlagenseite gegenüber dem Vermerkfeld leicht tiefer ausgerichtet (Darstellung der gemeinsamen Raster). diff --git a/docs/ux/verwaltung/abnahme/pdf-vorlagen/10-logo-anordnung.png b/docs/ux/verwaltung/abnahme/pdf-vorlagen/10-logo-anordnung.png new file mode 100644 index 0000000..3a7703e Binary files /dev/null and b/docs/ux/verwaltung/abnahme/pdf-vorlagen/10-logo-anordnung.png differ diff --git a/docs/ux/verwaltung/abnahme/pdf-vorlagen/11-logo-gespeichert.png b/docs/ux/verwaltung/abnahme/pdf-vorlagen/11-logo-gespeichert.png new file mode 100644 index 0000000..9225c09 Binary files /dev/null and b/docs/ux/verwaltung/abnahme/pdf-vorlagen/11-logo-gespeichert.png differ diff --git a/resources/views/filament/pdf/vorlagen.blade.php b/resources/views/filament/pdf/vorlagen.blade.php index 7755420..7696d80 100644 --- a/resources/views/filament/pdf/vorlagen.blade.php +++ b/resources/views/filament/pdf/vorlagen.blade.php @@ -13,8 +13,8 @@ ]; $mehr = $neu ? [] : [['label' => 'Vorlage löschen …', 'wire' => "askConfirmation('delete')", 'hinweis' => 'Dokumente mit dieser Vorlage erzeugen danach wieder das einfache PDF.', 'gefahr' => true]]; $felder = [ - 'header' => ['Kopfgrafik', 'Steht oben auf jeder Seite außer der Titelseite, in voller Seitenbreite. Empfohlen: A4-breit (2480 Pixel bei 300 dpi), JPEG oder PNG ohne Transparenz.', $this->bilder['header']], - 'footer' => ['Fußgrafik', 'Steht unten auf jeder Seite außer der Titelseite, in voller Seitenbreite. Die Lizenzzeile und „Seite n von m“ stehen darüber.', $this->bilder['footer']], + 'header' => ['Kopfgrafik', 'Steht oben auf jeder Seite außer der Titelseite: als Band in voller Seitenbreite (empfohlen: A4-breit, 2480 Pixel bei 300 dpi) oder als Logo links oder rechts am Textrand. JPEG oder PNG; Transparenz wird auf Weiß gesetzt.', $this->bilder['header']], + 'footer' => ['Fußgrafik', 'Steht unten auf jeder Seite außer der Titelseite: als Band in voller Seitenbreite oder als Logo links oder rechts am Textrand. Die Lizenzzeile und „Seite n von m“ stehen darüber.', $this->bilder['footer']], 'cover' => ['Bild der Titelseite', 'Steht oben auf der Titelseite in voller Seitenbreite, höchstens 40 % der Seite hoch. Ohne Bild beginnt die Titelseite mit dem Titel.', $this->bilder['cover']], ]; @endphp @@ -80,6 +80,22 @@ @else

Kein Bild gewählt.

@endif + @if ($feld !== 'cover') +
+ + @if (($this->anordnung[$feld] ?? 'full') !== 'full') + + @endif +
+ @endif
@if ($ziel !== null) diff --git a/tests/Feature/DokumentVorlageTest.php b/tests/Feature/DokumentVorlageTest.php index 435368c..e4e4a1c 100644 --- a/tests/Feature/DokumentVorlageTest.php +++ b/tests/Feature/DokumentVorlageTest.php @@ -253,6 +253,122 @@ public function test_the_staff_preview_of_a_document_uses_its_template_and_the_d $this->assertStringContainsString('Entwurfsausgabe 7', $this->pdfPages($pdf)[0]); } + public function test_a_logo_stands_left_or_right_at_the_text_margin_with_its_own_height_while_the_default_stays_a_full_width_band(): void + { + $template = PdfTemplate::query()->create([ + 'name' => 'Mit Logos', + 'kind' => PdfTemplate::KIND_DOCUMENT, + 'show_cover' => true, + 'header_version_id' => $this->picture('Logo oben '.uniqid(), 400, 200, [20, 80, 60])->id, + 'header_align' => 'left', + 'header_logo_height' => 30, + 'footer_version_id' => $this->picture('Logo unten '.uniqid(), 400, 200, [200, 160, 40])->id, + 'footer_align' => 'right', + 'footer_logo_height' => 50, + ]); + [$article, $release, $member] = $this->sold($template, null); + + $pdf = $this->actingAs($member)->get(route('member.document.pdf', ['article' => $article, 'release' => $release, 'path' => '1']))->assertOk()->getContent(); + $pages = $this->pdfPages($pdf); + $placed = $this->placedImages($pdf); + + $this->assertSame([], $placed[0], 'Die Titelseite trägt kein Logo.'); + + foreach (array_slice($placed, 1) as $page) { + $this->assertCount(2, $page); + [$header, $footer] = $page[0]['y'] > 400 ? [$page[0], $page[1]] : [$page[1], $page[0]]; + + // Kopf: Logo links am Textrand (56), 30 hoch, 24 unter dem oberen Rand. + $this->assertEqualsWithDelta([60.0, 30.0, 56.0, 842.0 - 24.0 - 30.0], [$header['w'], $header['h'], $header['x'], $header['y']], 0.01); + // Fuß: Logo rechts am Textrand (539), 50 hoch, 14 über dem unteren Rand. + $this->assertEqualsWithDelta([100.0, 50.0, 539.0 - 100.0, 14.0], [$footer['w'], $footer['h'], $footer['x'], $footer['y']], 0.01); + } + + $this->assertGreaterThan(1, count($pages)); + $this->assertStringContainsString('Inhaltsverzeichnis', $pages[1]); + + // Das Band in voller Seitenbreite bleibt die Vorgabe und liegt bündig am Rand. + [$article, $release, $member] = $this->sold($this->template(), null); + $band = $this->placedImages($this->actingAs($member)->get(route('member.document.pdf', ['article' => $article, 'release' => $release, 'path' => '1']))->getContent()); + $header = collect($band[1])->firstWhere(fn (array $image): bool => $image['y'] > 400); + $this->assertEqualsWithDelta([595.0, 0.0], [$header['w'], $header['x']], 0.5); + } + + public function test_a_wide_logo_never_takes_more_than_half_the_text_width_and_the_text_starts_below_it(): void + { + $template = PdfTemplate::query()->create([ + 'name' => 'Breites Logo', + 'kind' => PdfTemplate::KIND_DOCUMENT, + 'show_cover' => false, + 'header_version_id' => $this->picture('Breit '.uniqid(), 2480, 300, [20, 80, 60])->id, + 'header_align' => 'right', + 'header_logo_height' => 100, + ]); + [$article, $release, $member] = $this->sold($template, null); + + $pdf = $this->actingAs($member)->get(route('member.document.pdf', ['article' => $article, 'release' => $release, 'path' => '1']))->assertOk()->getContent(); + $logo = $this->placedImages($pdf)[0][0]; + + $this->assertEqualsWithDelta((539.0 - 56.0) / 2, $logo['w'], 0.01, 'Höchstens die halbe Textbreite.'); + $this->assertEqualsWithDelta(539.0, $logo['x'] + $logo['w'], 0.01, 'Bündig am rechten Textrand.'); + $this->assertSame(1, substr_count($pdf, '/Subtype /Image')); + } + + public function test_the_layout_values_are_kept_within_their_limits(): void + { + $this->assertSame(['align' => 'full', 'height' => 40], PdfTemplate::normalizeLayout(null, null)); + $this->assertSame(['align' => 'full', 'height' => 40], PdfTemplate::normalizeLayout('diagonal', 0)); + $this->assertSame(['align' => 'left', 'height' => 16], PdfTemplate::normalizeLayout('left', 3)); + $this->assertSame(['align' => 'right', 'height' => 100], PdfTemplate::normalizeLayout('right', '500')); + + $template = PdfTemplate::query()->create(['name' => 'Ohne Angaben', 'kind' => PdfTemplate::KIND_DOCUMENT]); + $this->assertSame(['align' => 'full', 'height' => 40], $template->fresh()->layout('header'), 'Die Vorgabe ist das Band in voller Seitenbreite.'); + } + + public function test_the_template_page_saves_the_arrangement_and_the_logo_height_for_header_and_footer(): void + { + $logo = $this->picture('Logo', 400, 200); + $component = Livewire::actingAs($this->editor(), 'staff')->test(PdfVorlagen::class) + ->set('name', 'Logos') + ->call('openImagePicker', 'header')->call('markPicker', 'element:'.$logo->id, true)->call('confirmPicker') + ->set('anordnung.header', 'left')->set('logohoehe.header', '500') + ->set('anordnung.footer', 'right')->set('logohoehe.footer', '24'); + $this->assertTrue($component->instance()->changed()); + $component->call('save'); + + $template = PdfTemplate::query()->firstOrFail(); + $this->assertSame(['left', 100, 'right', 24], [$template->header_align, $template->header_logo_height, $template->footer_align, $template->footer_logo_height], 'Die Höhe bleibt in den Grenzen.'); + $this->assertFalse($component->instance()->changed()); + $component->assertSet('anordnung.header', 'left')->assertSet('logohoehe.header', 100); + + $component->set('anordnung.header', 'full'); + $this->assertTrue($component->instance()->changed()); + $component->call('save'); + $this->assertSame('full', $template->fresh()->header_align); + + // Die Seite zeigt die Auswahl und blendet die Logohöhe nur bei einem Logo ein. + $component->assertSee('Logo links')->assertSee('Logo rechts')->assertSee('Band in voller Seitenbreite')->assertSee('Höhe des Logos'); + } + + /** + * Die gesetzten Bilder je Seite aus den Inhaltsströmen: Breite, Höhe, linke und untere Kante in Punkt. + * + * @return list> + */ + private function placedImages(string $pdf): array + { + preg_match_all('/\/Type \/Page \/Parent 2 0 R.*?\/Contents (\d+) 0 R/s', $pdf, $contents); + $pages = []; + + foreach ($contents[1] as $object) { + preg_match('/\n'.$object.' 0 obj\n<< \/Length \d+ >>\nstream\n(.*?)endstream/s', $pdf, $stream); + preg_match_all('/q (\S+) 0 0 (\S+) (\S+) (\S+) cm \/Im\d+ Do Q/', $stream[1] ?? '', $matches, PREG_SET_ORDER); + $pages[] = array_map(fn (array $m): array => ['w' => (float) $m[1], 'h' => (float) $m[2], 'x' => (float) $m[3], 'y' => (float) $m[4]], $matches); + } + + return $pages; + } + /** Legt eine Bilddatei im abgeleiteten Bestand ab und liefert ihren Pfad. */ private function store(string $path, int $width, int $height, array $rgb): string {