1a25f0a04SGreg Roach<?php 2a25f0a04SGreg Roach/** 3a25f0a04SGreg Roach * webtrees: online genealogy 41062a142SGreg Roach * Copyright (C) 2018 webtrees development team 5a25f0a04SGreg Roach * This program is free software: you can redistribute it and/or modify 6a25f0a04SGreg Roach * it under the terms of the GNU General Public License as published by 7a25f0a04SGreg Roach * the Free Software Foundation, either version 3 of the License, or 8a25f0a04SGreg Roach * (at your option) any later version. 9a25f0a04SGreg Roach * This program is distributed in the hope that it will be useful, 10a25f0a04SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 11a25f0a04SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12a25f0a04SGreg Roach * GNU General Public License for more details. 13a25f0a04SGreg Roach * You should have received a copy of the GNU General Public License 14a25f0a04SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 15a25f0a04SGreg Roach */ 16e7f56f2aSGreg Roachdeclare(strict_types=1); 17e7f56f2aSGreg Roach 1876692c8bSGreg Roachnamespace Fisharebest\Webtrees\Report; 19a25f0a04SGreg Roach 20a25f0a04SGreg Roach/** 21a25f0a04SGreg Roach * Class ReportPdfImage 22a25f0a04SGreg Roach */ 23c1010edaSGreg Roachclass ReportPdfImage extends ReportBaseImage 24c1010edaSGreg Roach{ 25a25f0a04SGreg Roach /** 26a25f0a04SGreg Roach * PDF image renderer 27a25f0a04SGreg Roach * 28adc8b18aSGreg Roach * @param ReportTcpdf $renderer 29c7ff4153SGreg Roach * 30c7ff4153SGreg Roach * @return void 31a25f0a04SGreg Roach */ 32c1010edaSGreg Roach public function render($renderer) 33c1010edaSGreg Roach { 34c8f6f5b5SGreg Roach static $lastpicbottom, $lastpicpage, $lastpicleft, $lastpicright; 35a25f0a04SGreg Roach 36a25f0a04SGreg Roach // Check for a pagebreak first 37a25f0a04SGreg Roach if ($renderer->checkPageBreakPDF($this->height + 5)) { 38a25f0a04SGreg Roach $this->y = $renderer->GetY(); 39a25f0a04SGreg Roach } 40a25f0a04SGreg Roach 41a25f0a04SGreg Roach $curx = $renderer->GetX(); 4283cdc021SGreg Roach 4383cdc021SGreg Roach // Get the current positions 44c21bdddcSGreg Roach if ($this->x === ReportBaseElement::CURRENT_POSITION) { 45a25f0a04SGreg Roach $this->x = $renderer->GetX(); 46ce15a17aSGreg Roach } else { 47ce15a17aSGreg Roach // For static position add margin 48a25f0a04SGreg Roach $this->x = $renderer->addMarginX($this->x); 49a25f0a04SGreg Roach $renderer->SetX($curx); 50a25f0a04SGreg Roach } 51c21bdddcSGreg Roach if ($this->y === ReportBaseElement::CURRENT_POSITION) { 52a25f0a04SGreg Roach //-- first check for a collision with the last picture 53a25f0a04SGreg Roach if (isset($lastpicbottom)) { 54a25f0a04SGreg Roach if (($renderer->PageNo() == $lastpicpage) && ($lastpicbottom >= $renderer->GetY()) && ($this->x >= $lastpicleft) && ($this->x <= $lastpicright) 55a25f0a04SGreg Roach ) { 56a25f0a04SGreg Roach $renderer->SetY($lastpicbottom + 5); 57a25f0a04SGreg Roach } 58a25f0a04SGreg Roach } 59a25f0a04SGreg Roach $this->y = $renderer->GetY(); 60a25f0a04SGreg Roach } else { 61a25f0a04SGreg Roach $renderer->SetY($this->y); 62a25f0a04SGreg Roach } 63a25f0a04SGreg Roach if ($renderer->getRTL()) { 64a25f0a04SGreg Roach $renderer->Image( 65a25f0a04SGreg Roach $this->file, 66a25f0a04SGreg Roach $renderer->getPageWidth() - $this->x, 67a25f0a04SGreg Roach $this->y, 68a25f0a04SGreg Roach $this->width, 69a25f0a04SGreg Roach $this->height, 707a6ee1acSGreg Roach '', 717a6ee1acSGreg Roach '', 72a25f0a04SGreg Roach $this->line, 73a25f0a04SGreg Roach false, 74a25f0a04SGreg Roach 72, 75a25f0a04SGreg Roach $this->align 76a25f0a04SGreg Roach ); 77a25f0a04SGreg Roach } else { 78a25f0a04SGreg Roach $renderer->Image( 79a25f0a04SGreg Roach $this->file, 80a25f0a04SGreg Roach $this->x, 81a25f0a04SGreg Roach $this->y, 82a25f0a04SGreg Roach $this->width, 83a25f0a04SGreg Roach $this->height, 847a6ee1acSGreg Roach '', 857a6ee1acSGreg Roach '', 86a25f0a04SGreg Roach $this->line, 87a25f0a04SGreg Roach false, 88a25f0a04SGreg Roach 72, 89a25f0a04SGreg Roach $this->align 90a25f0a04SGreg Roach ); 91a25f0a04SGreg Roach } 92a25f0a04SGreg Roach $lastpicpage = $renderer->PageNo(); 93a25f0a04SGreg Roach $renderer->lastpicpage = $renderer->getPage(); 94a25f0a04SGreg Roach $lastpicleft = $this->x; 95a25f0a04SGreg Roach $lastpicright = $this->x + $this->width; 96a25f0a04SGreg Roach $lastpicbottom = $this->y + $this->height; 97a25f0a04SGreg Roach // Setup for the next line 98044416d2SGreg Roach if ($this->line === 'N') { 99a25f0a04SGreg Roach $renderer->SetY($lastpicbottom); 100a25f0a04SGreg Roach } 101a25f0a04SGreg Roach } 102a25f0a04SGreg Roach 103a25f0a04SGreg Roach /** 104a25f0a04SGreg Roach * Get the image height 105a25f0a04SGreg Roach * 106*67c69ce5SGreg Roach * @param ReportTcpdf $renderer 107a25f0a04SGreg Roach * 108a25f0a04SGreg Roach * @return float 109a25f0a04SGreg Roach */ 110*67c69ce5SGreg Roach public function getHeight($renderer): float 111c1010edaSGreg Roach { 112a25f0a04SGreg Roach return $this->height; 113a25f0a04SGreg Roach } 114a25f0a04SGreg Roach 115a25f0a04SGreg Roach /** 11676692c8bSGreg Roach * Get the image width. 11776692c8bSGreg Roach * 118*67c69ce5SGreg Roach * @param $renderer 119a25f0a04SGreg Roach * 1208ba2e626SGreg Roach * @return float|array 121a25f0a04SGreg Roach */ 122*67c69ce5SGreg Roach public function getWidth($renderer) 123c1010edaSGreg Roach { 124a25f0a04SGreg Roach return $this->width; 125a25f0a04SGreg Roach } 126a25f0a04SGreg Roach} 127