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