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