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