xref: /webtrees/app/Report/ReportPdfImage.php (revision d11be7027e34e3121be11cc025421873364403f9)
1a25f0a04SGreg Roach<?php
23976b470SGreg Roach
3a25f0a04SGreg Roach/**
4a25f0a04SGreg Roach * webtrees: online genealogy
5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team
6a25f0a04SGreg Roach * This program is free software: you can redistribute it and/or modify
7a25f0a04SGreg Roach * it under the terms of the GNU General Public License as published by
8a25f0a04SGreg Roach * the Free Software Foundation, either version 3 of the License, or
9a25f0a04SGreg Roach * (at your option) any later version.
10a25f0a04SGreg Roach * This program is distributed in the hope that it will be useful,
11a25f0a04SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12a25f0a04SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13a25f0a04SGreg Roach * GNU General Public License for more details.
14a25f0a04SGreg Roach * You should have received a copy of the GNU General Public License
1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
16a25f0a04SGreg Roach */
17fcfa147eSGreg Roach
18e7f56f2aSGreg Roachdeclare(strict_types=1);
19e7f56f2aSGreg Roach
2076692c8bSGreg Roachnamespace Fisharebest\Webtrees\Report;
21a25f0a04SGreg Roach
22a25f0a04SGreg Roach/**
23a25f0a04SGreg Roach * Class ReportPdfImage
24a25f0a04SGreg Roach */
25c1010edaSGreg Roachclass ReportPdfImage extends ReportBaseImage
26c1010edaSGreg Roach{
27a25f0a04SGreg Roach    /**
28a25f0a04SGreg Roach     * PDF image renderer
29a25f0a04SGreg Roach     *
30b6f35a76SGreg Roach     * @param PdfRenderer $renderer
31c7ff4153SGreg Roach     *
32c7ff4153SGreg Roach     * @return void
33a25f0a04SGreg Roach     */
3477bab461SGreg Roach    public function render($renderer): void
35c1010edaSGreg Roach    {
36c8f6f5b5SGreg Roach        static $lastpicbottom, $lastpicpage, $lastpicleft, $lastpicright;
37a25f0a04SGreg Roach
38a25f0a04SGreg Roach        // Check for a pagebreak first
39a25f0a04SGreg Roach        if ($renderer->checkPageBreakPDF($this->height + 5)) {
40b6f35a76SGreg Roach            $this->y = $renderer->tcpdf->GetY();
41a25f0a04SGreg Roach        }
42a25f0a04SGreg Roach
43b6f35a76SGreg Roach        $curx = $renderer->tcpdf->GetX();
4483cdc021SGreg Roach
4583cdc021SGreg Roach        // Get the current positions
46c21bdddcSGreg Roach        if ($this->x === ReportBaseElement::CURRENT_POSITION) {
47b6f35a76SGreg Roach            $this->x = $renderer->tcpdf->GetX();
48ce15a17aSGreg Roach        } else {
49ce15a17aSGreg Roach            // For static position add margin
50a25f0a04SGreg Roach            $this->x = $renderer->addMarginX($this->x);
51b4c5c807SGreg Roach            $renderer->tcpdf->setX($curx);
52a25f0a04SGreg Roach        }
53c21bdddcSGreg Roach        if ($this->y === ReportBaseElement::CURRENT_POSITION) {
54a25f0a04SGreg Roach            //-- first check for a collision with the last picture
55b6f35a76SGreg Roach            if ($lastpicbottom !== null && $renderer->tcpdf->PageNo() === $lastpicpage && $lastpicbottom >= $renderer->tcpdf->GetY() && $this->x >= $lastpicleft && $this->x <= $lastpicright) {
56b4c5c807SGreg Roach                $renderer->tcpdf->setY($lastpicbottom + 5);
57a25f0a04SGreg Roach            }
58b6f35a76SGreg Roach            $this->y = $renderer->tcpdf->GetY();
59a25f0a04SGreg Roach        } else {
60b4c5c807SGreg Roach            $renderer->tcpdf->setY($this->y);
61a25f0a04SGreg Roach        }
62b6f35a76SGreg Roach        if ($renderer->tcpdf->getRTL()) {
63b6f35a76SGreg Roach            $renderer->tcpdf->Image(
64a25f0a04SGreg Roach                $this->file,
65b6f35a76SGreg Roach                $renderer->tcpdf->getPageWidth() - $this->x,
66a25f0a04SGreg Roach                $this->y,
67a25f0a04SGreg Roach                $this->width,
68a25f0a04SGreg Roach                $this->height,
697a6ee1acSGreg Roach                '',
707a6ee1acSGreg Roach                '',
71a25f0a04SGreg Roach                $this->line,
72a25f0a04SGreg Roach                false,
73a25f0a04SGreg Roach                72,
74a25f0a04SGreg Roach                $this->align
75a25f0a04SGreg Roach            );
76a25f0a04SGreg Roach        } else {
77b6f35a76SGreg Roach            $renderer->tcpdf->Image(
78a25f0a04SGreg Roach                $this->file,
79a25f0a04SGreg Roach                $this->x,
80a25f0a04SGreg Roach                $this->y,
81a25f0a04SGreg Roach                $this->width,
82a25f0a04SGreg Roach                $this->height,
837a6ee1acSGreg Roach                '',
847a6ee1acSGreg Roach                '',
85a25f0a04SGreg Roach                $this->line,
86a25f0a04SGreg Roach                false,
87a25f0a04SGreg Roach                72,
88a25f0a04SGreg Roach                $this->align
89a25f0a04SGreg Roach            );
90a25f0a04SGreg Roach        }
91b6f35a76SGreg Roach        $lastpicpage           = $renderer->tcpdf->PageNo();
92b6f35a76SGreg Roach        $renderer->lastpicpage = $renderer->tcpdf->getPage();
93a25f0a04SGreg Roach        $lastpicleft           = $this->x;
94a25f0a04SGreg Roach        $lastpicright          = $this->x + $this->width;
95a25f0a04SGreg Roach        $lastpicbottom         = $this->y + $this->height;
96a25f0a04SGreg Roach        // Setup for the next line
97044416d2SGreg Roach        if ($this->line === 'N') {
98b4c5c807SGreg Roach            $renderer->tcpdf->setY($lastpicbottom);
99a25f0a04SGreg Roach        }
100a25f0a04SGreg Roach    }
101a25f0a04SGreg Roach}
102