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 */ 16declare(strict_types=1); 17 18namespace Fisharebest\Webtrees\Report; 19 20/** 21 * Class ReportPdfImage 22 */ 23class ReportPdfImage extends ReportBaseImage 24{ 25 /** 26 * PDF image renderer 27 * 28 * @param ReportTcpdf $renderer 29 * 30 * @return void 31 */ 32 public function render($renderer) 33 { 34 global $lastpicbottom, $lastpicpage, $lastpicleft, $lastpicright; 35 36 // Check for a pagebreak first 37 if ($renderer->checkPageBreakPDF($this->height + 5)) { 38 $this->y = $renderer->GetY(); 39 } 40 41 $curx = $renderer->GetX(); 42 43 // Get the current positions 44 if ($this->x === -1) { 45 $this->x = $renderer->GetX(); 46 } else { 47 // For static position add margin 48 $this->x = $renderer->addMarginX($this->x); 49 $renderer->SetX($curx); 50 } 51 if ($this->y === -1) { 52 //-- first check for a collision with the last picture 53 if (isset($lastpicbottom)) { 54 if (($renderer->PageNo() == $lastpicpage) && ($lastpicbottom >= $renderer->GetY()) && ($this->x >= $lastpicleft) && ($this->x <= $lastpicright) 55 ) { 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 $pdf 107 * 108 * @return float 109 */ 110 public function getHeight($pdf): float 111 { 112 return $this->height; 113 } 114 115 /** 116 * Get the image width. 117 * 118 * @param $pdf 119 * 120 * @return float|array 121 */ 122 public function getWidth($pdf) 123 { 124 return $this->width; 125 } 126} 127