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