xref: /webtrees/app/Report/ReportPdfImage.php (revision 3976b4703df669696105ed6b024b96d433c8fbdb)
1a25f0a04SGreg Roach<?php
2*3976b470SGreg Roach
3a25f0a04SGreg Roach/**
4a25f0a04SGreg Roach * webtrees: online genealogy
58fcd0d32SGreg Roach * Copyright (C) 2019 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
15a25f0a04SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
16a25f0a04SGreg Roach */
17e7f56f2aSGreg Roachdeclare(strict_types=1);
18e7f56f2aSGreg Roach
1976692c8bSGreg Roachnamespace Fisharebest\Webtrees\Report;
20a25f0a04SGreg Roach
21a25f0a04SGreg Roach/**
22a25f0a04SGreg Roach * Class ReportPdfImage
23a25f0a04SGreg Roach */
24c1010edaSGreg Roachclass ReportPdfImage extends ReportBaseImage
25c1010edaSGreg Roach{
26a25f0a04SGreg Roach    /**
27a25f0a04SGreg Roach     * PDF image renderer
28a25f0a04SGreg Roach     *
29adc8b18aSGreg Roach     * @param ReportTcpdf $renderer
30c7ff4153SGreg Roach     *
31c7ff4153SGreg Roach     * @return void
32a25f0a04SGreg Roach     */
33c1010edaSGreg Roach    public function render($renderer)
34c1010edaSGreg Roach    {
35c8f6f5b5SGreg Roach        static $lastpicbottom, $lastpicpage, $lastpicleft, $lastpicright;
36a25f0a04SGreg Roach
37a25f0a04SGreg Roach        // Check for a pagebreak first
38a25f0a04SGreg Roach        if ($renderer->checkPageBreakPDF($this->height + 5)) {
39a25f0a04SGreg Roach            $this->y = $renderer->GetY();
40a25f0a04SGreg Roach        }
41a25f0a04SGreg Roach
42a25f0a04SGreg Roach        $curx = $renderer->GetX();
4383cdc021SGreg Roach
4483cdc021SGreg Roach        // Get the current positions
45c21bdddcSGreg Roach        if ($this->x === ReportBaseElement::CURRENT_POSITION) {
46a25f0a04SGreg Roach            $this->x = $renderer->GetX();
47ce15a17aSGreg Roach        } else {
48ce15a17aSGreg Roach            // For static position add margin
49a25f0a04SGreg Roach            $this->x = $renderer->addMarginX($this->x);
50a25f0a04SGreg Roach            $renderer->SetX($curx);
51a25f0a04SGreg Roach        }
52c21bdddcSGreg Roach        if ($this->y === ReportBaseElement::CURRENT_POSITION) {
53a25f0a04SGreg Roach            //-- first check for a collision with the last picture
54a25f0a04SGreg Roach            if (isset($lastpicbottom)) {
55a25f0a04SGreg Roach                if (($renderer->PageNo() == $lastpicpage) && ($lastpicbottom >= $renderer->GetY()) && ($this->x >= $lastpicleft) && ($this->x <= $lastpicright)
56a25f0a04SGreg Roach                ) {
57a25f0a04SGreg Roach                    $renderer->SetY($lastpicbottom + 5);
58a25f0a04SGreg Roach                }
59a25f0a04SGreg Roach            }
60a25f0a04SGreg Roach            $this->y = $renderer->GetY();
61a25f0a04SGreg Roach        } else {
62a25f0a04SGreg Roach            $renderer->SetY($this->y);
63a25f0a04SGreg Roach        }
64a25f0a04SGreg Roach        if ($renderer->getRTL()) {
65a25f0a04SGreg Roach            $renderer->Image(
66a25f0a04SGreg Roach                $this->file,
67a25f0a04SGreg Roach                $renderer->getPageWidth() - $this->x,
68a25f0a04SGreg Roach                $this->y,
69a25f0a04SGreg Roach                $this->width,
70a25f0a04SGreg Roach                $this->height,
717a6ee1acSGreg Roach                '',
727a6ee1acSGreg Roach                '',
73a25f0a04SGreg Roach                $this->line,
74a25f0a04SGreg Roach                false,
75a25f0a04SGreg Roach                72,
76a25f0a04SGreg Roach                $this->align
77a25f0a04SGreg Roach            );
78a25f0a04SGreg Roach        } else {
79a25f0a04SGreg Roach            $renderer->Image(
80a25f0a04SGreg Roach                $this->file,
81a25f0a04SGreg Roach                $this->x,
82a25f0a04SGreg Roach                $this->y,
83a25f0a04SGreg Roach                $this->width,
84a25f0a04SGreg Roach                $this->height,
857a6ee1acSGreg Roach                '',
867a6ee1acSGreg Roach                '',
87a25f0a04SGreg Roach                $this->line,
88a25f0a04SGreg Roach                false,
89a25f0a04SGreg Roach                72,
90a25f0a04SGreg Roach                $this->align
91a25f0a04SGreg Roach            );
92a25f0a04SGreg Roach        }
93a25f0a04SGreg Roach        $lastpicpage           = $renderer->PageNo();
94a25f0a04SGreg Roach        $renderer->lastpicpage = $renderer->getPage();
95a25f0a04SGreg Roach        $lastpicleft           = $this->x;
96a25f0a04SGreg Roach        $lastpicright          = $this->x + $this->width;
97a25f0a04SGreg Roach        $lastpicbottom         = $this->y + $this->height;
98a25f0a04SGreg Roach        // Setup for the next line
99044416d2SGreg Roach        if ($this->line === 'N') {
100a25f0a04SGreg Roach            $renderer->SetY($lastpicbottom);
101a25f0a04SGreg Roach        }
102a25f0a04SGreg Roach    }
103a25f0a04SGreg Roach
104a25f0a04SGreg Roach    /**
105a25f0a04SGreg Roach     * Get the image height
106a25f0a04SGreg Roach     *
10767c69ce5SGreg Roach     * @param ReportTcpdf $renderer
108a25f0a04SGreg Roach     *
109a25f0a04SGreg Roach     * @return float
110a25f0a04SGreg Roach     */
11167c69ce5SGreg Roach    public function getHeight($renderer): float
112c1010edaSGreg Roach    {
113a25f0a04SGreg Roach        return $this->height;
114a25f0a04SGreg Roach    }
115a25f0a04SGreg Roach
116a25f0a04SGreg Roach    /**
11776692c8bSGreg Roach     * Get the image width.
11876692c8bSGreg Roach     *
11967c69ce5SGreg Roach     * @param $renderer
120a25f0a04SGreg Roach     *
1218ba2e626SGreg Roach     * @return float|array
122a25f0a04SGreg Roach     */
12367c69ce5SGreg Roach    public function getWidth($renderer)
124c1010edaSGreg Roach    {
125a25f0a04SGreg Roach        return $this->width;
126a25f0a04SGreg Roach    }
127a25f0a04SGreg Roach}
128