Erlaube in Kopf und Fuß einer PDF-Vorlage ein Logo links oder rechts
Deploy Test / test (push) Successful in 3m8s
Deploy Test / deploy (push) Successful in 26s

Kopf und Fuß haben je eine Anordnung: Band in voller Seitenbreite (Vorgabe, wie
bisher), Logo links oder Logo rechts am Textrand. Die Logohöhe ist einstellbar
(16 bis 100 Punkt, Vorgabe 40); das Logo ist höchstens halb so breit wie der Text,
der Text beginnt darunter beziehungsweise endet darüber. Die Titelseite bleibt
unberührt. Additive Migration mit Vorgaben; der vorherige Programmstand zeigt jede
Grafik weiter als Band.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Sonnet 5.5 committed 2026-11-24 16:34:17 +01:00
1 parent b942b5331a
commit 9f9370dbf8
10 files changed
+301 -20

No files matched your search

+116
View File
@@ -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<list<array{w: float, h: float, x: float, y: float}>>
*/
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
{