xref: /webtrees/app/Report/ReportPdfImage.php (revision 1062a1429914c995339f502856821457aa975a5a)
1a25f0a04SGreg Roach<?php
2a25f0a04SGreg Roach/**
3a25f0a04SGreg Roach * webtrees: online genealogy
4*1062a142SGreg 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 */
21a25f0a04SGreg Roachclass ReportPdfImage extends ReportBaseImage {
22a25f0a04SGreg Roach	/**
23a25f0a04SGreg Roach	 * PDF image renderer
24a25f0a04SGreg Roach	 *
25adc8b18aSGreg Roach	 * @param ReportTcpdf $renderer
26a25f0a04SGreg Roach	 */
27ffd703eaSGreg Roach	public function render($renderer) {
28a25f0a04SGreg Roach		global $lastpicbottom, $lastpicpage, $lastpicleft, $lastpicright;
29a25f0a04SGreg Roach
30a25f0a04SGreg Roach		// Check for a pagebreak first
31a25f0a04SGreg Roach		if ($renderer->checkPageBreakPDF($this->height + 5)) {
32a25f0a04SGreg Roach			$this->y = $renderer->GetY();
33a25f0a04SGreg Roach		}
34a25f0a04SGreg Roach
35a25f0a04SGreg Roach		$curx = $renderer->GetX();
36a25f0a04SGreg Roach		// If current position (left)set "."
377a6ee1acSGreg Roach		if ($this->x == '.') {
38a25f0a04SGreg Roach			$this->x = $renderer->GetX();
39a25f0a04SGreg Roach		} // For static position add margin
40a25f0a04SGreg Roach		else {
41a25f0a04SGreg Roach			$this->x = $renderer->addMarginX($this->x);
42a25f0a04SGreg Roach			$renderer->SetX($curx);
43a25f0a04SGreg Roach		}
447a6ee1acSGreg Roach		if ($this->y == '.') {
45a25f0a04SGreg Roach			//-- first check for a collision with the last picture
46a25f0a04SGreg Roach			if (isset($lastpicbottom)) {
47a25f0a04SGreg Roach				if (($renderer->PageNo() == $lastpicpage) && ($lastpicbottom >= $renderer->GetY()) && ($this->x >= $lastpicleft) && ($this->x <= $lastpicright)
48a25f0a04SGreg Roach				) {
49a25f0a04SGreg Roach					$renderer->SetY($lastpicbottom + 5);
50a25f0a04SGreg Roach				}
51a25f0a04SGreg Roach			}
52a25f0a04SGreg Roach			$this->y = $renderer->GetY();
53a25f0a04SGreg Roach		} else {
54a25f0a04SGreg Roach			$renderer->SetY($this->y);
55a25f0a04SGreg Roach		}
56a25f0a04SGreg Roach		if ($renderer->getRTL()) {
57a25f0a04SGreg Roach			$renderer->Image(
58a25f0a04SGreg Roach				$this->file,
59a25f0a04SGreg Roach				$renderer->getPageWidth() - $this->x,
60a25f0a04SGreg Roach				$this->y,
61a25f0a04SGreg Roach				$this->width,
62a25f0a04SGreg Roach				$this->height,
637a6ee1acSGreg Roach				'',
647a6ee1acSGreg Roach				'',
65a25f0a04SGreg Roach				$this->line,
66a25f0a04SGreg Roach				false,
67a25f0a04SGreg Roach				72,
68a25f0a04SGreg Roach				$this->align
69a25f0a04SGreg Roach			);
70a25f0a04SGreg Roach		} else {
71a25f0a04SGreg Roach			$renderer->Image(
72a25f0a04SGreg Roach				$this->file,
73a25f0a04SGreg Roach				$this->x,
74a25f0a04SGreg Roach				$this->y,
75a25f0a04SGreg Roach				$this->width,
76a25f0a04SGreg Roach				$this->height,
777a6ee1acSGreg Roach				'',
787a6ee1acSGreg Roach				'',
79a25f0a04SGreg Roach				$this->line,
80a25f0a04SGreg Roach				false,
81a25f0a04SGreg Roach				72,
82a25f0a04SGreg Roach				$this->align
83a25f0a04SGreg Roach			);
84a25f0a04SGreg Roach		}
85a25f0a04SGreg Roach		$lastpicpage           = $renderer->PageNo();
86a25f0a04SGreg Roach		$renderer->lastpicpage = $renderer->getPage();
87a25f0a04SGreg Roach		$lastpicleft           = $this->x;
88a25f0a04SGreg Roach		$lastpicright          = $this->x + $this->width;
89a25f0a04SGreg Roach		$lastpicbottom         = $this->y + $this->height;
90a25f0a04SGreg Roach		// Setup for the next line
917a6ee1acSGreg Roach		if ($this->line == 'N') {
92a25f0a04SGreg Roach			$renderer->SetY($lastpicbottom);
93a25f0a04SGreg Roach		}
94a25f0a04SGreg Roach	}
95a25f0a04SGreg Roach
96a25f0a04SGreg Roach	/**
97a25f0a04SGreg Roach	 * Get the image height
98a25f0a04SGreg Roach	 *
99adc8b18aSGreg Roach	 * @param ReportTcpdf $pdf
100a25f0a04SGreg Roach	 *
101a25f0a04SGreg Roach	 * @return float
102a25f0a04SGreg Roach	 */
103ffd703eaSGreg Roach	public function getHeight($pdf) {
104a25f0a04SGreg Roach		return $this->height;
105a25f0a04SGreg Roach	}
106a25f0a04SGreg Roach
107a25f0a04SGreg Roach	/**
10876692c8bSGreg Roach	 * Get the image width.
10976692c8bSGreg Roach	 *
110a25f0a04SGreg Roach	 * @param $pdf
111a25f0a04SGreg Roach	 *
112a25f0a04SGreg Roach	 * @return float
113a25f0a04SGreg Roach	 */
114ffd703eaSGreg Roach	public function getWidth($pdf) {
115a25f0a04SGreg Roach		return $this->width;
116a25f0a04SGreg Roach	}
117a25f0a04SGreg Roach}
118