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