xref: /webtrees/app/Report/ReportPdfImage.php (revision 8d897fd11a9a8845d8456cb9eaad33b9c9d5a225)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
16 */
17declare(strict_types=1);
18
19namespace Fisharebest\Webtrees\Report;
20
21/**
22 * Class ReportPdfImage
23 */
24class ReportPdfImage extends ReportBaseImage
25{
26    /**
27     * PDF image renderer
28     *
29     * @param ReportTcpdf $renderer
30     *
31     * @return void
32     */
33    public function render($renderer)
34    {
35        static $lastpicbottom, $lastpicpage, $lastpicleft, $lastpicright;
36
37        // Check for a pagebreak first
38        if ($renderer->checkPageBreakPDF($this->height + 5)) {
39            $this->y = $renderer->GetY();
40        }
41
42        $curx = $renderer->GetX();
43
44        // Get the current positions
45        if ($this->x === ReportBaseElement::CURRENT_POSITION) {
46            $this->x = $renderer->GetX();
47        } else {
48            // For static position add margin
49            $this->x = $renderer->addMarginX($this->x);
50            $renderer->SetX($curx);
51        }
52        if ($this->y === ReportBaseElement::CURRENT_POSITION) {
53            //-- first check for a collision with the last picture
54            if (isset($lastpicbottom)) {
55                if (($renderer->PageNo() == $lastpicpage) && ($lastpicbottom >= $renderer->GetY()) && ($this->x >= $lastpicleft) && ($this->x <= $lastpicright)
56                ) {
57                    $renderer->SetY($lastpicbottom + 5);
58                }
59            }
60            $this->y = $renderer->GetY();
61        } else {
62            $renderer->SetY($this->y);
63        }
64        if ($renderer->getRTL()) {
65            $renderer->Image(
66                $this->file,
67                $renderer->getPageWidth() - $this->x,
68                $this->y,
69                $this->width,
70                $this->height,
71                '',
72                '',
73                $this->line,
74                false,
75                72,
76                $this->align
77            );
78        } else {
79            $renderer->Image(
80                $this->file,
81                $this->x,
82                $this->y,
83                $this->width,
84                $this->height,
85                '',
86                '',
87                $this->line,
88                false,
89                72,
90                $this->align
91            );
92        }
93        $lastpicpage           = $renderer->PageNo();
94        $renderer->lastpicpage = $renderer->getPage();
95        $lastpicleft           = $this->x;
96        $lastpicright          = $this->x + $this->width;
97        $lastpicbottom         = $this->y + $this->height;
98        // Setup for the next line
99        if ($this->line === 'N') {
100            $renderer->SetY($lastpicbottom);
101        }
102    }
103
104    /**
105     * Get the image height
106     *
107     * @param ReportTcpdf $renderer
108     *
109     * @return float
110     */
111    public function getHeight($renderer): float
112    {
113        return $this->height;
114    }
115
116    /**
117     * Get the image width.
118     *
119     * @param $renderer
120     *
121     * @return float|array
122     */
123    public function getWidth($renderer)
124    {
125        return $this->width;
126    }
127}
128