xref: /webtrees/app/Report/ReportHtmlCell.php (revision ffd703ea1e658c7dcb5e5f1f9ef137a420f2d167)
1<?php
2namespace Fisharebest\Webtrees;
3
4/**
5 * webtrees: online genealogy
6 * Copyright (C) 2015 webtrees development team
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/**
20 * Class ReportHtmlCell
21 */
22class ReportHtmlCell extends ReportBaseCell {
23	/**
24	 * HTML Cell renderer
25	 *
26	 * @param ReportHtml $renderer
27	 *
28	 * @return void
29	 */
30	public function render($renderer) {
31		if (strpos($this->text, "{{:ptp:}}") !== false) {
32			return;
33		}
34		$temptext = str_replace("#PAGENUM#", $renderer->pageNo(), $this->text);
35		// underline «title» part of Source item
36		$temptext = str_replace(array('«', '»'), array('<u>', '</u>'), $temptext);
37
38		// Setup the style name
39		if ($renderer->getCurrentStyle() != $this->styleName) {
40			$renderer->setCurrentStyle($this->styleName);
41		}
42
43		// If (Future-feature-enable/disable cell padding)
44		$cP = $renderer->cPadding;
45
46		// Adjust the positions
47		if ($this->left == ".") {
48			$this->left = $renderer->getX();
49		} else {
50			$renderer->setX($this->left);
51		}
52
53		if ($this->top == ".") {
54			$this->top = $renderer->getY();
55		} else {
56			$renderer->setY($this->top);
57		}
58
59		// Start collecting the HTML code
60		echo "<div class=\"", $this->styleName, "\" style=\"position:absolute;top:", $this->top, "pt;";
61		// Use Cell around padding to support RTL also
62		echo "padding:", $cP, "pt;";
63		// LTR (left) or RTL (right)
64		echo $renderer->alignRTL, ":", $this->left, "pt;";
65		// Background color
66		if (!empty($this->bgcolor)) {
67			echo "background-color:", $this->bgcolor, ";";
68		}
69		// Border setup
70		$bpixX = 0;
71		$bpixY = 0;
72		if (!empty($this->border)) {
73			// Border all around
74			if ($this->border == 1) {
75				echo " border:solid ";
76				if (!empty($this->bocolor)) {
77					echo $this->bocolor;
78				} else {
79					echo "black";
80				}
81				echo " 1pt;";
82				$bpixX = 1;
83				$bpixY = 1;
84			} else {
85				if (stripos($this->border, "T") !== false) {
86					echo " border-top:solid ";
87					if (!empty($this->bocolor)) {
88						echo $this->bocolor;
89					} else {
90						echo "black";
91					}
92					echo " 1pt;";
93					$bpixY = 1;
94				}
95				if (stripos($this->border, "B") !== false) {
96					echo " border-bottom:solid ";
97					if (!empty($this->bocolor)) {
98						echo $this->bocolor;
99					} else {
100						echo "black";
101					}
102					echo " 1pt;";
103					$bpixY = 1;
104				}
105				if (stripos($this->border, "R") !== false) {
106					echo " border-right:solid ";
107					if (!empty($this->bocolor)) {
108						echo $this->bocolor;
109					} else {
110						echo "black";
111					}
112					echo " 1pt;";
113					$bpixX = 1;
114				}
115				if (stripos($this->border, "L") !== false) {
116					echo " border-left:solid ";
117					if (!empty($this->bocolor)) {
118						echo $this->bocolor;
119					} else {
120						echo "black";
121					}
122					echo " 1pt;";
123					$bpixX = 1;
124				}
125			}
126		}
127		// Check the width if set to page wide OR set by xml to larger then page wide
128		if ($this->width == 0 || $this->width > $renderer->getRemainingWidth()) {
129			$this->width = $renderer->getRemainingWidth();
130		}
131		// We have to calculate a different width for the padding, counting on both side
132		$cW = $this->width - ($cP * 2);
133
134		// If there is any text
135		if (!empty($temptext)) {
136			// Wrap the text
137			$temptext = $renderer->textWrap($temptext, $cW);
138			$tmph = $renderer->getTextCellHeight($temptext);
139			// Add some cell padding
140			$this->height += $cP;
141			if ($tmph > $this->height) {
142				$this->height = $tmph;
143			}
144		}
145		// Check the last cell height and ajust with the current cell height
146		if ($renderer->lastCellHeight > $this->height) {
147			$this->height = $renderer->lastCellHeight;
148		}
149		echo " width:", $cW - $bpixX, "pt;height:", $this->height - $bpixY, "pt;";
150
151		// Text alignment
152		switch ($this->align) {
153		case "C":
154			echo " text-align:center;";
155			break;
156		case "L":
157			echo " text-align:left;";
158			break;
159		case "R":
160			echo " text-align:right;";
161			break;
162		}
163
164		// Print the collected HTML code
165		echo "\">";
166
167		// Print URL
168		if (!empty($this->url)) {
169			echo "<a href=\"", $this->url, "\">";
170		}
171		// Print any text if exists
172		if (!empty($temptext)) {
173			$renderer->write($temptext, $this->tcolor, false);
174		}
175		if (!empty($this->url)) {
176			echo "</a>";
177		}
178		// Finish the cell printing and start to clean up
179		echo "</div>\n";
180		// Where to place the next position
181		// -> Next to this cell in the same line
182		if ($this->newline == 0) {
183			$renderer->setXy($this->left + $this->width, $this->top);
184			$renderer->lastCellHeight = $this->height;
185		} // -> On a new line at the margin - Default
186		elseif ($this->newline == 1) {
187			$renderer->setXy(0, $renderer->getY() + $this->height + ($cP * 2));
188			// Reset the last cell height for the next line
189			$renderer->lastCellHeight = 0;
190		} // -> On a new line at the end of this cell
191		elseif ($this->newline == 2) {
192			$renderer->setXy($renderer->getX() + $this->width, $renderer->getY() + $this->height + ($cP * 2));
193			// Reset the last cell height for the next line
194			$renderer->lastCellHeight = 0;
195		}
196	}
197}
198