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 */ 1676692c8bSGreg Roachnamespace Fisharebest\Webtrees\Report; 17a25f0a04SGreg Roach 18a25f0a04SGreg Roach/** 19a25f0a04SGreg Roach * Class ReportPdfImage 20a25f0a04SGreg Roach */ 21c1010edaSGreg Roachclass ReportPdfImage extends ReportBaseImage 22c1010edaSGreg Roach{ 23a25f0a04SGreg Roach /** 24a25f0a04SGreg Roach * PDF image renderer 25a25f0a04SGreg Roach * 26adc8b18aSGreg Roach * @param ReportTcpdf $renderer 27c7ff4153SGreg Roach * 28c7ff4153SGreg Roach * @return void 29a25f0a04SGreg Roach */ 30c1010edaSGreg Roach public function render($renderer) 31c1010edaSGreg Roach { 32a25f0a04SGreg Roach global $lastpicbottom, $lastpicpage, $lastpicleft, $lastpicright; 33a25f0a04SGreg Roach 34a25f0a04SGreg Roach // Check for a pagebreak first 35a25f0a04SGreg Roach if ($renderer->checkPageBreakPDF($this->height + 5)) { 36a25f0a04SGreg Roach $this->y = $renderer->GetY(); 37a25f0a04SGreg Roach } 38a25f0a04SGreg Roach 39a25f0a04SGreg Roach $curx = $renderer->GetX(); 40*83cdc021SGreg Roach 41*83cdc021SGreg Roach // Get the current positions 42*83cdc021SGreg Roach if ($this->x === -1) { 43a25f0a04SGreg Roach $this->x = $renderer->GetX(); 44ce15a17aSGreg Roach } else { 45ce15a17aSGreg Roach // For static position add margin 46a25f0a04SGreg Roach $this->x = $renderer->addMarginX($this->x); 47a25f0a04SGreg Roach $renderer->SetX($curx); 48a25f0a04SGreg Roach } 49*83cdc021SGreg Roach if ($this->y === -1) { 50a25f0a04SGreg Roach //-- first check for a collision with the last picture 51a25f0a04SGreg Roach if (isset($lastpicbottom)) { 52a25f0a04SGreg Roach if (($renderer->PageNo() == $lastpicpage) && ($lastpicbottom >= $renderer->GetY()) && ($this->x >= $lastpicleft) && ($this->x <= $lastpicright) 53a25f0a04SGreg Roach ) { 54a25f0a04SGreg Roach $renderer->SetY($lastpicbottom + 5); 55a25f0a04SGreg Roach } 56a25f0a04SGreg Roach } 57a25f0a04SGreg Roach $this->y = $renderer->GetY(); 58a25f0a04SGreg Roach } else { 59a25f0a04SGreg Roach $renderer->SetY($this->y); 60a25f0a04SGreg Roach } 61a25f0a04SGreg Roach if ($renderer->getRTL()) { 62a25f0a04SGreg Roach $renderer->Image( 63a25f0a04SGreg Roach $this->file, 64a25f0a04SGreg Roach $renderer->getPageWidth() - $this->x, 65a25f0a04SGreg Roach $this->y, 66a25f0a04SGreg Roach $this->width, 67a25f0a04SGreg Roach $this->height, 687a6ee1acSGreg Roach '', 697a6ee1acSGreg Roach '', 70a25f0a04SGreg Roach $this->line, 71a25f0a04SGreg Roach false, 72a25f0a04SGreg Roach 72, 73a25f0a04SGreg Roach $this->align 74a25f0a04SGreg Roach ); 75a25f0a04SGreg Roach } else { 76a25f0a04SGreg Roach $renderer->Image( 77a25f0a04SGreg Roach $this->file, 78a25f0a04SGreg Roach $this->x, 79a25f0a04SGreg Roach $this->y, 80a25f0a04SGreg Roach $this->width, 81a25f0a04SGreg Roach $this->height, 827a6ee1acSGreg Roach '', 837a6ee1acSGreg Roach '', 84a25f0a04SGreg Roach $this->line, 85a25f0a04SGreg Roach false, 86a25f0a04SGreg Roach 72, 87a25f0a04SGreg Roach $this->align 88a25f0a04SGreg Roach ); 89a25f0a04SGreg Roach } 90a25f0a04SGreg Roach $lastpicpage = $renderer->PageNo(); 91a25f0a04SGreg Roach $renderer->lastpicpage = $renderer->getPage(); 92a25f0a04SGreg Roach $lastpicleft = $this->x; 93a25f0a04SGreg Roach $lastpicright = $this->x + $this->width; 94a25f0a04SGreg Roach $lastpicbottom = $this->y + $this->height; 95a25f0a04SGreg Roach // Setup for the next line 967a6ee1acSGreg Roach if ($this->line == 'N') { 97a25f0a04SGreg Roach $renderer->SetY($lastpicbottom); 98a25f0a04SGreg Roach } 99a25f0a04SGreg Roach } 100a25f0a04SGreg Roach 101a25f0a04SGreg Roach /** 102a25f0a04SGreg Roach * Get the image height 103a25f0a04SGreg Roach * 104adc8b18aSGreg Roach * @param ReportTcpdf $pdf 105a25f0a04SGreg Roach * 106a25f0a04SGreg Roach * @return float 107a25f0a04SGreg Roach */ 1088f53f488SRico Sonntag public function getHeight($pdf): float 109c1010edaSGreg Roach { 110a25f0a04SGreg Roach return $this->height; 111a25f0a04SGreg Roach } 112a25f0a04SGreg Roach 113a25f0a04SGreg Roach /** 11476692c8bSGreg Roach * Get the image width. 11576692c8bSGreg Roach * 116a25f0a04SGreg Roach * @param $pdf 117a25f0a04SGreg Roach * 1188ba2e626SGreg Roach * @return float|array 119a25f0a04SGreg Roach */ 1208ba2e626SGreg Roach public function getWidth($pdf) 121c1010edaSGreg Roach { 122a25f0a04SGreg Roach return $this->width; 123a25f0a04SGreg Roach } 124a25f0a04SGreg Roach} 125