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