xref: /webtrees/app/Report/ReportHtmlImage.php (revision c21bdddc89b941099aac7bad64af11da73acab4e)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2018 webtrees development team
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16declare(strict_types=1);
17
18namespace Fisharebest\Webtrees\Report;
19
20/**
21 * Class ReportHtmlImage
22 */
23class ReportHtmlImage extends ReportBaseImage
24{
25    /**
26     * Image renderer
27     *
28     * @param ReportHtml $renderer
29     *
30     * @return void
31     */
32    public function render($renderer)
33    {
34        global $lastpicbottom, $lastpicpage, $lastpicleft, $lastpicright;
35
36        // Get the current positions
37        if ($this->x === ReportBaseElement::CURRENT_POSITION) {
38            $this->x = $renderer->getX();
39        }
40        if ($this->y === ReportBaseElement::CURRENT_POSITION) {
41            //-- first check for a collision with the last picture
42            if (isset($lastpicbottom)) {
43                if (($renderer->pageNo() == $lastpicpage) && ($lastpicbottom >= $renderer->getY()) && ($this->x >= $lastpicleft) && ($this->x <= $lastpicright)) {
44                    $renderer->setY($lastpicbottom + ($renderer->cPadding * 2));
45                }
46            }
47            $this->y = $renderer->getY();
48        }
49
50        // Image alignment
51        switch ($this->align) {
52            case 'L':
53                echo '<div style="position:absolute;top:', $this->y, 'pt;left:0pt;width:', $renderer->getRemainingWidth(), "pt;text-align:left;\">\n";
54                echo '<img src="', $this->file, '" style="width:', $this->width, 'pt;height:', $this->height, "pt;\" alt=\"\">\n</div>\n";
55                break;
56            case 'C':
57                echo '<div style="position:absolute;top:', $this->y, 'pt;left:0pt;width:', $renderer->getRemainingWidth(), "pt;text-align:center;\">\n";
58                echo '<img src="', $this->file, '" style="width:', $this->width, 'pt;height:', $this->height, "pt;\" alt=\"\">\n</div>\n";
59                break;
60            case 'R':
61                echo '<div style="position:absolute;top:', $this->y, 'pt;left:0pt;width:', $renderer->getRemainingWidth(), "pt;text-align:right;\">\n";
62                echo '<img src="', $this->file, '" style="width:', $this->width, 'pt;height:', $this->height, "pt;\" alt=\"\">\n</div>\n";
63                break;
64            default:
65                echo '<img src="', $this->file, '" style="position:absolute;', $renderer->alignRTL, ':', $this->x, 'pt;top:', $this->y, 'pt;width:', $this->width, 'pt;height:', $this->height, "pt;\" alt=\"\">\n";
66        }
67
68        $lastpicpage   = $renderer->pageNo();
69        $lastpicleft   = $this->x;
70        $lastpicright  = $this->x + $this->width;
71        $lastpicbottom = $this->y + $this->height;
72        // Setup for the next line
73        if ($this->line === 'N') {
74            $renderer->setY($lastpicbottom);
75        }
76        // Keep max Y updated
77        $renderer->addMaxY($lastpicbottom);
78    }
79
80    /**
81     * Get the image height
82     * This would be called from the TextBox only for multiple images
83     * so we add a bit bottom space between the images
84     *
85     * @param ReportHtml $html
86     *
87     * @return float
88     */
89    public function getHeight($html): float
90    {
91        return $this->height + ($html->cPadding * 2);
92    }
93}
94