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