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