xref: /webtrees/app/Report/ReportHtmlImage.php (revision c7ff415313b94d2d6d06ec673249f39fae9865e9)
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 */
16namespace Fisharebest\Webtrees\Report;
17
18/**
19 * Class ReportHtmlImage
20 */
21class ReportHtmlImage extends ReportBaseImage
22{
23    /**
24     * Image renderer
25     *
26     * @param ReportHtml $renderer
27     *
28     * @return void
29     */
30    public function render($renderer)
31    {
32        global $lastpicbottom, $lastpicpage, $lastpicleft, $lastpicright;
33
34        // Get the current positions
35        if ($this->x == '.') {
36            $this->x = $renderer->getX();
37        }
38        if ($this->y == '.') {
39            //-- first check for a collision with the last picture
40            if (isset($lastpicbottom)) {
41                if (($renderer->pageNo() == $lastpicpage) && ($lastpicbottom >= $renderer->getY()) && ($this->x >= $lastpicleft) && ($this->x <= $lastpicright)) {
42                    $renderer->setY($lastpicbottom + ($renderer->cPadding * 2));
43                }
44            }
45            $this->y = $renderer->getY();
46        }
47
48        // Image alignment
49        switch ($this->align) {
50            case 'L':
51                echo '<div style="position:absolute;top:', $this->y, 'pt;left:0pt;width:', $renderer->getRemainingWidth(), "pt;text-align:left;\">\n";
52                echo '<img src="', $this->file, '" style="width:', $this->width, 'pt;height:', $this->height, "pt;\" alt=\"\">\n</div>\n";
53                break;
54            case 'C':
55                echo '<div style="position:absolute;top:', $this->y, 'pt;left:0pt;width:', $renderer->getRemainingWidth(), "pt;text-align:center;\">\n";
56                echo '<img src="', $this->file, '" style="width:', $this->width, 'pt;height:', $this->height, "pt;\" alt=\"\">\n</div>\n";
57                break;
58            case 'R':
59                echo '<div style="position:absolute;top:', $this->y, 'pt;left:0pt;width:', $renderer->getRemainingWidth(), "pt;text-align:right;\">\n";
60                echo '<img src="', $this->file, '" style="width:', $this->width, 'pt;height:', $this->height, "pt;\" alt=\"\">\n</div>\n";
61                break;
62            default:
63                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";
64        }
65
66        $lastpicpage   = $renderer->pageNo();
67        $lastpicleft   = $this->x;
68        $lastpicright  = $this->x + $this->width;
69        $lastpicbottom = $this->y + $this->height;
70        // Setup for the next line
71        if ($this->line == 'N') {
72            $renderer->setY($lastpicbottom);
73        }
74        // Keep max Y updated
75        $renderer->addMaxY($lastpicbottom);
76    }
77
78    /**
79     * Get the image height
80     * This would be called from the TextBox only for multiple images
81     * so we add a bit bottom space between the images
82     *
83     * @param ReportHtml $html
84     *
85     * @return float
86     */
87    public function getHeight($html): float
88    {
89        return $this->height + ($html->cPadding * 2);
90    }
91}
92