1a25f0a04SGreg Roach<?php 2a25f0a04SGreg Roach/** 3a25f0a04SGreg Roach * webtrees: online genealogy 4*8fcd0d32SGreg Roach * Copyright (C) 2019 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 } 378a4ee39cSGreg 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 4767c69ce5SGreg Roach // Set up the text style 4867c69ce5SGreg 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 56c21bdddcSGreg Roach if ($this->left === ReportBaseElement::CURRENT_POSITION) { 57a25f0a04SGreg Roach $this->left = $renderer->getX(); 58a25f0a04SGreg Roach } else { 59a25f0a04SGreg Roach $renderer->setX($this->left); 60a25f0a04SGreg Roach } 61a25f0a04SGreg Roach 62c21bdddcSGreg Roach if ($this->top === ReportBaseElement::CURRENT_POSITION) { 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;'; 7467c69ce5SGreg Roach 75a25f0a04SGreg Roach // Background color 76a25f0a04SGreg Roach if (!empty($this->bgcolor)) { 777a6ee1acSGreg Roach echo 'background-color:', $this->bgcolor, ';'; 78a25f0a04SGreg Roach } 7967c69ce5SGreg Roach 8067c69ce5SGreg Roach // Borders 81a25f0a04SGreg Roach $bpixX = 0; 82a25f0a04SGreg Roach $bpixY = 0; 83a25f0a04SGreg Roach if (!empty($this->border)) { 84a25f0a04SGreg Roach // Border all around 85a25f0a04SGreg Roach if ($this->border == 1) { 867a6ee1acSGreg Roach echo ' border:solid '; 87a25f0a04SGreg Roach if (!empty($this->bocolor)) { 88a25f0a04SGreg Roach echo $this->bocolor; 89a25f0a04SGreg Roach } else { 907a6ee1acSGreg Roach echo 'black'; 91a25f0a04SGreg Roach } 927a6ee1acSGreg Roach echo ' 1pt;'; 93a25f0a04SGreg Roach $bpixX = 1; 94a25f0a04SGreg Roach $bpixY = 1; 95a25f0a04SGreg Roach } else { 967a6ee1acSGreg Roach if (stripos($this->border, 'T') !== false) { 977a6ee1acSGreg Roach echo ' border-top:solid '; 98a25f0a04SGreg Roach if (!empty($this->bocolor)) { 99a25f0a04SGreg Roach echo $this->bocolor; 100a25f0a04SGreg Roach } else { 1017a6ee1acSGreg Roach echo 'black'; 102a25f0a04SGreg Roach } 1037a6ee1acSGreg Roach echo ' 1pt;'; 104a25f0a04SGreg Roach $bpixY = 1; 105a25f0a04SGreg Roach } 1067a6ee1acSGreg Roach if (stripos($this->border, 'B') !== false) { 1077a6ee1acSGreg Roach echo ' border-bottom:solid '; 108a25f0a04SGreg Roach if (!empty($this->bocolor)) { 109a25f0a04SGreg Roach echo $this->bocolor; 110a25f0a04SGreg Roach } else { 1117a6ee1acSGreg Roach echo 'black'; 112a25f0a04SGreg Roach } 1137a6ee1acSGreg Roach echo ' 1pt;'; 114a25f0a04SGreg Roach $bpixY = 1; 115a25f0a04SGreg Roach } 1167a6ee1acSGreg Roach if (stripos($this->border, 'R') !== false) { 1177a6ee1acSGreg Roach echo ' border-right:solid '; 118a25f0a04SGreg Roach if (!empty($this->bocolor)) { 119a25f0a04SGreg Roach echo $this->bocolor; 120a25f0a04SGreg Roach } else { 1217a6ee1acSGreg Roach echo 'black'; 122a25f0a04SGreg Roach } 1237a6ee1acSGreg Roach echo ' 1pt;'; 124a25f0a04SGreg Roach $bpixX = 1; 125a25f0a04SGreg Roach } 1267a6ee1acSGreg Roach if (stripos($this->border, 'L') !== false) { 1277a6ee1acSGreg Roach echo ' border-left:solid '; 128a25f0a04SGreg Roach if (!empty($this->bocolor)) { 129a25f0a04SGreg Roach echo $this->bocolor; 130a25f0a04SGreg Roach } else { 1317a6ee1acSGreg Roach echo 'black'; 132a25f0a04SGreg Roach } 1337a6ee1acSGreg Roach echo ' 1pt;'; 134a25f0a04SGreg Roach $bpixX = 1; 135a25f0a04SGreg Roach } 136a25f0a04SGreg Roach } 137a25f0a04SGreg Roach } 138a25f0a04SGreg Roach // Check the width if set to page wide OR set by xml to larger then page wide 139a25f0a04SGreg Roach if ($this->width == 0 || $this->width > $renderer->getRemainingWidth()) { 140a25f0a04SGreg Roach $this->width = $renderer->getRemainingWidth(); 141a25f0a04SGreg Roach } 142a25f0a04SGreg Roach // We have to calculate a different width for the padding, counting on both side 143a25f0a04SGreg Roach $cW = $this->width - ($cP * 2); 144a25f0a04SGreg Roach 145a25f0a04SGreg Roach // If there is any text 146a25f0a04SGreg Roach if (!empty($temptext)) { 147a25f0a04SGreg Roach // Wrap the text 148a25f0a04SGreg Roach $temptext = $renderer->textWrap($temptext, $cW); 149a25f0a04SGreg Roach $tmph = $renderer->getTextCellHeight($temptext); 150a25f0a04SGreg Roach // Add some cell padding 151a25f0a04SGreg Roach $this->height += $cP; 152a25f0a04SGreg Roach if ($tmph > $this->height) { 153a25f0a04SGreg Roach $this->height = $tmph; 154a25f0a04SGreg Roach } 155a25f0a04SGreg Roach } 15667c69ce5SGreg Roach // Check the last cell height and adjust the current cell height if needed 157a25f0a04SGreg Roach if ($renderer->lastCellHeight > $this->height) { 158a25f0a04SGreg Roach $this->height = $renderer->lastCellHeight; 159a25f0a04SGreg Roach } 1607a6ee1acSGreg Roach echo ' width:', $cW - $bpixX, 'pt;height:', $this->height - $bpixY, 'pt;'; 161a25f0a04SGreg Roach 162a25f0a04SGreg Roach // Text alignment 163a25f0a04SGreg Roach switch ($this->align) { 1647a6ee1acSGreg Roach case 'C': 1657a6ee1acSGreg Roach echo ' text-align:center;'; 166a25f0a04SGreg Roach break; 1677a6ee1acSGreg Roach case 'L': 1687a6ee1acSGreg Roach echo ' text-align:left;'; 169a25f0a04SGreg Roach break; 1707a6ee1acSGreg Roach case 'R': 1717a6ee1acSGreg Roach echo ' text-align:right;'; 172a25f0a04SGreg Roach break; 173a25f0a04SGreg Roach } 174a25f0a04SGreg Roach 175a25f0a04SGreg Roach // Print the collected HTML code 1767a6ee1acSGreg Roach echo '">'; 177a25f0a04SGreg Roach 178a25f0a04SGreg Roach // Print URL 179a25f0a04SGreg Roach if (!empty($this->url)) { 1807a6ee1acSGreg Roach echo '<a href="', $this->url, '">'; 181a25f0a04SGreg Roach } 182a25f0a04SGreg Roach // Print any text if exists 183a25f0a04SGreg Roach if (!empty($temptext)) { 184a25f0a04SGreg Roach $renderer->write($temptext, $this->tcolor, false); 185a25f0a04SGreg Roach } 186a25f0a04SGreg Roach if (!empty($this->url)) { 1877a6ee1acSGreg Roach echo '</a>'; 188a25f0a04SGreg Roach } 189a25f0a04SGreg Roach // Finish the cell printing and start to clean up 190a25f0a04SGreg Roach echo "</div>\n"; 191ce15a17aSGreg Roach 192a25f0a04SGreg Roach // Where to place the next position 193a25f0a04SGreg Roach if ($this->newline == 0) { 194ce15a17aSGreg Roach // -> Next to this cell in the same line 195a25f0a04SGreg Roach $renderer->setXy($this->left + $this->width, $this->top); 196a25f0a04SGreg Roach $renderer->lastCellHeight = $this->height; 197ce15a17aSGreg Roach } elseif ($this->newline == 1) { 198ce15a17aSGreg Roach // -> On a new line at the margin - Default 199a25f0a04SGreg Roach $renderer->setXy(0, $renderer->getY() + $this->height + ($cP * 2)); 200a25f0a04SGreg Roach // Reset the last cell height for the next line 201a25f0a04SGreg Roach $renderer->lastCellHeight = 0; 202ce15a17aSGreg Roach } elseif ($this->newline == 2) { 203ce15a17aSGreg Roach // -> On a new line at the end of this cell 204a25f0a04SGreg Roach $renderer->setXy($renderer->getX() + $this->width, $renderer->getY() + $this->height + ($cP * 2)); 205a25f0a04SGreg Roach // Reset the last cell height for the next line 206a25f0a04SGreg Roach $renderer->lastCellHeight = 0; 207a25f0a04SGreg Roach } 208a25f0a04SGreg Roach } 209a25f0a04SGreg Roach} 210