xref: /webtrees/app/Report/ReportPdfImage.php (revision da7f6dd728aff7a0c0b922f5fd8849698cf0456d)
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 */
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 ReportTcpdf $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->GetY();
41        }
42
43        $curx = $renderer->GetX();
44
45        // Get the current positions
46        if ($this->x === ReportBaseElement::CURRENT_POSITION) {
47            $this->x = $renderer->GetX();
48        } else {
49            // For static position add margin
50            $this->x = $renderer->addMarginX($this->x);
51            $renderer->SetX($curx);
52        }
53        if ($this->y === ReportBaseElement::CURRENT_POSITION) {
54            //-- first check for a collision with the last picture
55            if (isset($lastpicbottom)) {
56                if ($renderer->PageNo() === $lastpicpage && $lastpicbottom >= $renderer->GetY() && $this->x >= $lastpicleft && $this->x <= $lastpicright) {
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