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 ReportPdfImage 23 */ 24class ReportPdfImage extends ReportBaseImage 25{ 26 /** 27 * PDF image renderer 28 * 29 * @param ReportTcpdf $renderer 30 * 31 * @return void 32 */ 33 public function render($renderer) 34 { 35 static $lastpicbottom, $lastpicpage, $lastpicleft, $lastpicright; 36 37 // Check for a pagebreak first 38 if ($renderer->checkPageBreakPDF($this->height + 5)) { 39 $this->y = $renderer->GetY(); 40 } 41 42 $curx = $renderer->GetX(); 43 44 // Get the current positions 45 if ($this->x === ReportBaseElement::CURRENT_POSITION) { 46 $this->x = $renderer->GetX(); 47 } else { 48 // For static position add margin 49 $this->x = $renderer->addMarginX($this->x); 50 $renderer->SetX($curx); 51 } 52 if ($this->y === ReportBaseElement::CURRENT_POSITION) { 53 //-- first check for a collision with the last picture 54 if (isset($lastpicbottom)) { 55 if ($renderer->PageNo() === $lastpicpage && $lastpicbottom >= $renderer->GetY() && $this->x >= $lastpicleft && $this->x <= $lastpicright) { 56 $renderer->SetY($lastpicbottom + 5); 57 } 58 } 59 $this->y = $renderer->GetY(); 60 } else { 61 $renderer->SetY($this->y); 62 } 63 if ($renderer->getRTL()) { 64 $renderer->Image( 65 $this->file, 66 $renderer->getPageWidth() - $this->x, 67 $this->y, 68 $this->width, 69 $this->height, 70 '', 71 '', 72 $this->line, 73 false, 74 72, 75 $this->align 76 ); 77 } else { 78 $renderer->Image( 79 $this->file, 80 $this->x, 81 $this->y, 82 $this->width, 83 $this->height, 84 '', 85 '', 86 $this->line, 87 false, 88 72, 89 $this->align 90 ); 91 } 92 $lastpicpage = $renderer->PageNo(); 93 $renderer->lastpicpage = $renderer->getPage(); 94 $lastpicleft = $this->x; 95 $lastpicright = $this->x + $this->width; 96 $lastpicbottom = $this->y + $this->height; 97 // Setup for the next line 98 if ($this->line === 'N') { 99 $renderer->SetY($lastpicbottom); 100 } 101 } 102 103 /** 104 * Get the image height 105 * 106 * @param ReportTcpdf $renderer 107 * 108 * @return float 109 */ 110 public function getHeight($renderer): float 111 { 112 return $this->height; 113 } 114 115 /** 116 * Get the image width. 117 * 118 * @param $renderer 119 * 120 * @return float|array 121 */ 122 public function getWidth($renderer) 123 { 124 return $this->width; 125 } 126} 127