1a25f0a04SGreg Roach<?php 2a25f0a04SGreg Roach/** 3a25f0a04SGreg Roach * webtrees: online genealogy 41062a142SGreg 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 */ 16e7f56f2aSGreg Roachdeclare(strict_types=1); 17e7f56f2aSGreg Roach 1876692c8bSGreg Roachnamespace Fisharebest\Webtrees\Report; 19a25f0a04SGreg Roach 20a25f0a04SGreg Roach/** 21a25f0a04SGreg Roach * Class ReportHtmlCell 22a25f0a04SGreg Roach */ 23c1010edaSGreg Roachclass ReportHtmlCell extends ReportBaseCell 24c1010edaSGreg Roach{ 25a25f0a04SGreg Roach /** 26a25f0a04SGreg Roach * HTML Cell renderer 27a25f0a04SGreg Roach * 28a25f0a04SGreg Roach * @param ReportHtml $renderer 29c7ff4153SGreg Roach * 30c7ff4153SGreg Roach * @return void 31a25f0a04SGreg Roach */ 32c1010edaSGreg Roach public function render($renderer) 33c1010edaSGreg Roach { 347a6ee1acSGreg Roach if (strpos($this->text, '{{:ptp:}}') !== false) { 35a25f0a04SGreg Roach return; 36a25f0a04SGreg Roach } 37*8a4ee39cSGreg Roach $temptext = str_replace('#PAGENUM#', (string) $renderer->pageNo(), $this->text); 38a25f0a04SGreg Roach // underline «title» part of Source item 39c1010edaSGreg Roach $temptext = str_replace([ 40c1010edaSGreg Roach '«', 41c1010edaSGreg Roach '»', 42c1010edaSGreg Roach ], [ 43c1010edaSGreg Roach '<u>', 44c1010edaSGreg Roach '</u>', 45c1010edaSGreg Roach ], $temptext); 46a25f0a04SGreg Roach 47a25f0a04SGreg Roach // Setup the style name 48a25f0a04SGreg Roach if ($renderer->getCurrentStyle() != $this->styleName) { 49a25f0a04SGreg Roach $renderer->setCurrentStyle($this->styleName); 50a25f0a04SGreg Roach } 51a25f0a04SGreg Roach 52a25f0a04SGreg Roach // If (Future-feature-enable/disable cell padding) 53a25f0a04SGreg Roach $cP = $renderer->cPadding; 54a25f0a04SGreg Roach 55a25f0a04SGreg Roach // Adjust the positions 567a6ee1acSGreg Roach if ($this->left == '.') { 57a25f0a04SGreg Roach $this->left = $renderer->getX(); 58a25f0a04SGreg Roach } else { 59a25f0a04SGreg Roach $renderer->setX($this->left); 60a25f0a04SGreg Roach } 61a25f0a04SGreg Roach 627a6ee1acSGreg Roach if ($this->top == '.') { 63a25f0a04SGreg Roach $this->top = $renderer->getY(); 64a25f0a04SGreg Roach } else { 65a25f0a04SGreg Roach $renderer->setY($this->top); 66a25f0a04SGreg Roach } 67a25f0a04SGreg Roach 68a25f0a04SGreg Roach // Start collecting the HTML code 697a6ee1acSGreg Roach echo '<div class="', $this->styleName, '" style="position:absolute;top:', $this->top, 'pt;'; 70a25f0a04SGreg Roach // Use Cell around padding to support RTL also 717a6ee1acSGreg Roach echo 'padding:', $cP, 'pt;'; 72a25f0a04SGreg Roach // LTR (left) or RTL (right) 737a6ee1acSGreg Roach echo $renderer->alignRTL, ':', $this->left, 'pt;'; 74a25f0a04SGreg Roach // Background color 75a25f0a04SGreg Roach if (!empty($this->bgcolor)) { 767a6ee1acSGreg Roach echo 'background-color:', $this->bgcolor, ';'; 77a25f0a04SGreg Roach } 78a25f0a04SGreg Roach // Border setup 79a25f0a04SGreg Roach $bpixX = 0; 80a25f0a04SGreg Roach $bpixY = 0; 81a25f0a04SGreg Roach if (!empty($this->border)) { 82a25f0a04SGreg Roach // Border all around 83a25f0a04SGreg Roach if ($this->border == 1) { 847a6ee1acSGreg Roach echo ' border:solid '; 85a25f0a04SGreg Roach if (!empty($this->bocolor)) { 86a25f0a04SGreg Roach echo $this->bocolor; 87a25f0a04SGreg Roach } else { 887a6ee1acSGreg Roach echo 'black'; 89a25f0a04SGreg Roach } 907a6ee1acSGreg Roach echo ' 1pt;'; 91a25f0a04SGreg Roach $bpixX = 1; 92a25f0a04SGreg Roach $bpixY = 1; 93a25f0a04SGreg Roach } else { 947a6ee1acSGreg Roach if (stripos($this->border, 'T') !== false) { 957a6ee1acSGreg Roach echo ' border-top:solid '; 96a25f0a04SGreg Roach if (!empty($this->bocolor)) { 97a25f0a04SGreg Roach echo $this->bocolor; 98a25f0a04SGreg Roach } else { 997a6ee1acSGreg Roach echo 'black'; 100a25f0a04SGreg Roach } 1017a6ee1acSGreg Roach echo ' 1pt;'; 102a25f0a04SGreg Roach $bpixY = 1; 103a25f0a04SGreg Roach } 1047a6ee1acSGreg Roach if (stripos($this->border, 'B') !== false) { 1057a6ee1acSGreg Roach echo ' border-bottom:solid '; 106a25f0a04SGreg Roach if (!empty($this->bocolor)) { 107a25f0a04SGreg Roach echo $this->bocolor; 108a25f0a04SGreg Roach } else { 1097a6ee1acSGreg Roach echo 'black'; 110a25f0a04SGreg Roach } 1117a6ee1acSGreg Roach echo ' 1pt;'; 112a25f0a04SGreg Roach $bpixY = 1; 113a25f0a04SGreg Roach } 1147a6ee1acSGreg Roach if (stripos($this->border, 'R') !== false) { 1157a6ee1acSGreg Roach echo ' border-right:solid '; 116a25f0a04SGreg Roach if (!empty($this->bocolor)) { 117a25f0a04SGreg Roach echo $this->bocolor; 118a25f0a04SGreg Roach } else { 1197a6ee1acSGreg Roach echo 'black'; 120a25f0a04SGreg Roach } 1217a6ee1acSGreg Roach echo ' 1pt;'; 122a25f0a04SGreg Roach $bpixX = 1; 123a25f0a04SGreg Roach } 1247a6ee1acSGreg Roach if (stripos($this->border, 'L') !== false) { 1257a6ee1acSGreg Roach echo ' border-left:solid '; 126a25f0a04SGreg Roach if (!empty($this->bocolor)) { 127a25f0a04SGreg Roach echo $this->bocolor; 128a25f0a04SGreg Roach } else { 1297a6ee1acSGreg Roach echo 'black'; 130a25f0a04SGreg Roach } 1317a6ee1acSGreg Roach echo ' 1pt;'; 132a25f0a04SGreg Roach $bpixX = 1; 133a25f0a04SGreg Roach } 134a25f0a04SGreg Roach } 135a25f0a04SGreg Roach } 136a25f0a04SGreg Roach // Check the width if set to page wide OR set by xml to larger then page wide 137a25f0a04SGreg Roach if ($this->width == 0 || $this->width > $renderer->getRemainingWidth()) { 138a25f0a04SGreg Roach $this->width = $renderer->getRemainingWidth(); 139a25f0a04SGreg Roach } 140a25f0a04SGreg Roach // We have to calculate a different width for the padding, counting on both side 141a25f0a04SGreg Roach $cW = $this->width - ($cP * 2); 142a25f0a04SGreg Roach 143a25f0a04SGreg Roach // If there is any text 144a25f0a04SGreg Roach if (!empty($temptext)) { 145a25f0a04SGreg Roach // Wrap the text 146a25f0a04SGreg Roach $temptext = $renderer->textWrap($temptext, $cW); 147a25f0a04SGreg Roach $tmph = $renderer->getTextCellHeight($temptext); 148a25f0a04SGreg Roach // Add some cell padding 149a25f0a04SGreg Roach $this->height += $cP; 150a25f0a04SGreg Roach if ($tmph > $this->height) { 151a25f0a04SGreg Roach $this->height = $tmph; 152a25f0a04SGreg Roach } 153a25f0a04SGreg Roach } 154a25f0a04SGreg Roach // Check the last cell height and ajust with the current cell height 155a25f0a04SGreg Roach if ($renderer->lastCellHeight > $this->height) { 156a25f0a04SGreg Roach $this->height = $renderer->lastCellHeight; 157a25f0a04SGreg Roach } 1587a6ee1acSGreg Roach echo ' width:', $cW - $bpixX, 'pt;height:', $this->height - $bpixY, 'pt;'; 159a25f0a04SGreg Roach 160a25f0a04SGreg Roach // Text alignment 161a25f0a04SGreg Roach switch ($this->align) { 1627a6ee1acSGreg Roach case 'C': 1637a6ee1acSGreg Roach echo ' text-align:center;'; 164a25f0a04SGreg Roach break; 1657a6ee1acSGreg Roach case 'L': 1667a6ee1acSGreg Roach echo ' text-align:left;'; 167a25f0a04SGreg Roach break; 1687a6ee1acSGreg Roach case 'R': 1697a6ee1acSGreg Roach echo ' text-align:right;'; 170a25f0a04SGreg Roach break; 171a25f0a04SGreg Roach } 172a25f0a04SGreg Roach 173a25f0a04SGreg Roach // Print the collected HTML code 1747a6ee1acSGreg Roach echo '">'; 175a25f0a04SGreg Roach 176a25f0a04SGreg Roach // Print URL 177a25f0a04SGreg Roach if (!empty($this->url)) { 1787a6ee1acSGreg Roach echo '<a href="', $this->url, '">'; 179a25f0a04SGreg Roach } 180a25f0a04SGreg Roach // Print any text if exists 181a25f0a04SGreg Roach if (!empty($temptext)) { 182a25f0a04SGreg Roach $renderer->write($temptext, $this->tcolor, false); 183a25f0a04SGreg Roach } 184a25f0a04SGreg Roach if (!empty($this->url)) { 1857a6ee1acSGreg Roach echo '</a>'; 186a25f0a04SGreg Roach } 187a25f0a04SGreg Roach // Finish the cell printing and start to clean up 188a25f0a04SGreg Roach echo "</div>\n"; 189ce15a17aSGreg Roach 190a25f0a04SGreg Roach // Where to place the next position 191a25f0a04SGreg Roach if ($this->newline == 0) { 192ce15a17aSGreg Roach // -> Next to this cell in the same line 193a25f0a04SGreg Roach $renderer->setXy($this->left + $this->width, $this->top); 194a25f0a04SGreg Roach $renderer->lastCellHeight = $this->height; 195ce15a17aSGreg Roach } elseif ($this->newline == 1) { 196ce15a17aSGreg Roach // -> On a new line at the margin - Default 197a25f0a04SGreg Roach $renderer->setXy(0, $renderer->getY() + $this->height + ($cP * 2)); 198a25f0a04SGreg Roach // Reset the last cell height for the next line 199a25f0a04SGreg Roach $renderer->lastCellHeight = 0; 200ce15a17aSGreg Roach } elseif ($this->newline == 2) { 201ce15a17aSGreg Roach // -> On a new line at the end of this cell 202a25f0a04SGreg Roach $renderer->setXy($renderer->getX() + $this->width, $renderer->getY() + $this->height + ($cP * 2)); 203a25f0a04SGreg Roach // Reset the last cell height for the next line 204a25f0a04SGreg Roach $renderer->lastCellHeight = 0; 205a25f0a04SGreg Roach } 206a25f0a04SGreg Roach } 207a25f0a04SGreg Roach} 208