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