xref: /webtrees/app/Report/ReportPdfImage.php (revision 8ba2e6268c47e6eaf578c571d83b4eab25c35320)
1a25f0a04SGreg Roach<?php
2a25f0a04SGreg Roach/**
3a25f0a04SGreg Roach * webtrees: online genealogy
41062a142SGreg Roach * Copyright (C) 2018 webtrees development team
5a25f0a04SGreg Roach * This program is free software: you can redistribute it and/or modify
6a25f0a04SGreg Roach * it under the terms of the GNU General Public License as published by
7a25f0a04SGreg Roach * the Free Software Foundation, either version 3 of the License, or
8a25f0a04SGreg Roach * (at your option) any later version.
9a25f0a04SGreg Roach * This program is distributed in the hope that it will be useful,
10a25f0a04SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
11a25f0a04SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12a25f0a04SGreg Roach * GNU General Public License for more details.
13a25f0a04SGreg Roach * You should have received a copy of the GNU General Public License
14a25f0a04SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
15a25f0a04SGreg Roach */
1676692c8bSGreg Roachnamespace Fisharebest\Webtrees\Report;
17a25f0a04SGreg Roach
18a25f0a04SGreg Roach/**
19a25f0a04SGreg Roach * Class ReportPdfImage
20a25f0a04SGreg Roach */
21c1010edaSGreg Roachclass ReportPdfImage extends ReportBaseImage
22c1010edaSGreg Roach{
23a25f0a04SGreg Roach    /**
24a25f0a04SGreg Roach     * PDF image renderer
25a25f0a04SGreg Roach     *
26adc8b18aSGreg Roach     * @param ReportTcpdf $renderer
27a25f0a04SGreg Roach     */
28c1010edaSGreg Roach    public function render($renderer)
29c1010edaSGreg Roach    {
30a25f0a04SGreg Roach        global $lastpicbottom, $lastpicpage, $lastpicleft, $lastpicright;
31a25f0a04SGreg Roach
32a25f0a04SGreg Roach        // Check for a pagebreak first
33a25f0a04SGreg Roach        if ($renderer->checkPageBreakPDF($this->height + 5)) {
34a25f0a04SGreg Roach            $this->y = $renderer->GetY();
35a25f0a04SGreg Roach        }
36a25f0a04SGreg Roach
37a25f0a04SGreg Roach        $curx = $renderer->GetX();
38a25f0a04SGreg Roach        // If current position (left)set "."
397a6ee1acSGreg Roach        if ($this->x == '.') {
40a25f0a04SGreg Roach            $this->x = $renderer->GetX();
41ce15a17aSGreg Roach        } else {
42ce15a17aSGreg Roach            // For static position add margin
43a25f0a04SGreg Roach            $this->x = $renderer->addMarginX($this->x);
44a25f0a04SGreg Roach            $renderer->SetX($curx);
45a25f0a04SGreg Roach        }
467a6ee1acSGreg Roach        if ($this->y == '.') {
47a25f0a04SGreg Roach            //-- first check for a collision with the last picture
48a25f0a04SGreg Roach            if (isset($lastpicbottom)) {
49a25f0a04SGreg Roach                if (($renderer->PageNo() == $lastpicpage) && ($lastpicbottom >= $renderer->GetY()) && ($this->x >= $lastpicleft) && ($this->x <= $lastpicright)
50a25f0a04SGreg Roach                ) {
51a25f0a04SGreg Roach                    $renderer->SetY($lastpicbottom + 5);
52a25f0a04SGreg Roach                }
53a25f0a04SGreg Roach            }
54a25f0a04SGreg Roach            $this->y = $renderer->GetY();
55a25f0a04SGreg Roach        } else {
56a25f0a04SGreg Roach            $renderer->SetY($this->y);
57a25f0a04SGreg Roach        }
58a25f0a04SGreg Roach        if ($renderer->getRTL()) {
59a25f0a04SGreg Roach            $renderer->Image(
60a25f0a04SGreg Roach                $this->file,
61a25f0a04SGreg Roach                $renderer->getPageWidth() - $this->x,
62a25f0a04SGreg Roach                $this->y,
63a25f0a04SGreg Roach                $this->width,
64a25f0a04SGreg Roach                $this->height,
657a6ee1acSGreg Roach                '',
667a6ee1acSGreg Roach                '',
67a25f0a04SGreg Roach                $this->line,
68a25f0a04SGreg Roach                false,
69a25f0a04SGreg Roach                72,
70a25f0a04SGreg Roach                $this->align
71a25f0a04SGreg Roach            );
72a25f0a04SGreg Roach        } else {
73a25f0a04SGreg Roach            $renderer->Image(
74a25f0a04SGreg Roach                $this->file,
75a25f0a04SGreg Roach                $this->x,
76a25f0a04SGreg Roach                $this->y,
77a25f0a04SGreg Roach                $this->width,
78a25f0a04SGreg Roach                $this->height,
797a6ee1acSGreg Roach                '',
807a6ee1acSGreg Roach                '',
81a25f0a04SGreg Roach                $this->line,
82a25f0a04SGreg Roach                false,
83a25f0a04SGreg Roach                72,
84a25f0a04SGreg Roach                $this->align
85a25f0a04SGreg Roach            );
86a25f0a04SGreg Roach        }
87a25f0a04SGreg Roach        $lastpicpage           = $renderer->PageNo();
88a25f0a04SGreg Roach        $renderer->lastpicpage = $renderer->getPage();
89a25f0a04SGreg Roach        $lastpicleft           = $this->x;
90a25f0a04SGreg Roach        $lastpicright          = $this->x + $this->width;
91a25f0a04SGreg Roach        $lastpicbottom         = $this->y + $this->height;
92a25f0a04SGreg Roach        // Setup for the next line
937a6ee1acSGreg Roach        if ($this->line == 'N') {
94a25f0a04SGreg Roach            $renderer->SetY($lastpicbottom);
95a25f0a04SGreg Roach        }
96a25f0a04SGreg Roach    }
97a25f0a04SGreg Roach
98a25f0a04SGreg Roach    /**
99a25f0a04SGreg Roach     * Get the image height
100a25f0a04SGreg Roach     *
101adc8b18aSGreg Roach     * @param ReportTcpdf $pdf
102a25f0a04SGreg Roach     *
103a25f0a04SGreg Roach     * @return float
104a25f0a04SGreg Roach     */
1058f53f488SRico Sonntag    public function getHeight($pdf): float
106c1010edaSGreg Roach    {
107a25f0a04SGreg Roach        return $this->height;
108a25f0a04SGreg Roach    }
109a25f0a04SGreg Roach
110a25f0a04SGreg Roach    /**
11176692c8bSGreg Roach     * Get the image width.
11276692c8bSGreg Roach     *
113a25f0a04SGreg Roach     * @param $pdf
114a25f0a04SGreg Roach     *
115*8ba2e626SGreg Roach     * @return float|array
116a25f0a04SGreg Roach     */
117*8ba2e626SGreg Roach    public function getWidth($pdf)
118c1010edaSGreg Roach    {
119a25f0a04SGreg Roach        return $this->width;
120a25f0a04SGreg Roach    }
121a25f0a04SGreg Roach}
122