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