1a25f0a04SGreg Roach<?php 2*3976b470SGreg Roach 3a25f0a04SGreg Roach/** 4a25f0a04SGreg Roach * webtrees: online genealogy 58fcd0d32SGreg Roach * Copyright (C) 2019 webtrees development team 6a25f0a04SGreg Roach * This program is free software: you can redistribute it and/or modify 7a25f0a04SGreg Roach * it under the terms of the GNU General Public License as published by 8a25f0a04SGreg Roach * the Free Software Foundation, either version 3 of the License, or 9a25f0a04SGreg Roach * (at your option) any later version. 10a25f0a04SGreg Roach * This program is distributed in the hope that it will be useful, 11a25f0a04SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12a25f0a04SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13a25f0a04SGreg Roach * GNU General Public License for more details. 14a25f0a04SGreg Roach * You should have received a copy of the GNU General Public License 15a25f0a04SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 16a25f0a04SGreg Roach */ 17e7f56f2aSGreg Roachdeclare(strict_types=1); 18e7f56f2aSGreg Roach 1976692c8bSGreg Roachnamespace Fisharebest\Webtrees\Report; 20a25f0a04SGreg Roach 21a25f0a04SGreg Roach/** 22a25f0a04SGreg Roach * Class ReportHtmlCell 23a25f0a04SGreg Roach */ 24c1010edaSGreg Roachclass ReportHtmlCell extends ReportBaseCell 25c1010edaSGreg Roach{ 26a25f0a04SGreg Roach /** 27a25f0a04SGreg Roach * HTML Cell renderer 28a25f0a04SGreg Roach * 29a25f0a04SGreg Roach * @param ReportHtml $renderer 30c7ff4153SGreg Roach * 31c7ff4153SGreg Roach * @return void 32a25f0a04SGreg Roach */ 33c1010edaSGreg Roach public function render($renderer) 34c1010edaSGreg Roach { 357a6ee1acSGreg Roach if (strpos($this->text, '{{:ptp:}}') !== false) { 36a25f0a04SGreg Roach return; 37a25f0a04SGreg Roach } 388a4ee39cSGreg Roach $temptext = str_replace('#PAGENUM#', (string) $renderer->pageNo(), $this->text); 39a25f0a04SGreg Roach // underline «title» part of Source item 40c1010edaSGreg Roach $temptext = str_replace([ 41c1010edaSGreg Roach '«', 42c1010edaSGreg Roach '»', 43c1010edaSGreg Roach ], [ 44c1010edaSGreg Roach '<u>', 45c1010edaSGreg Roach '</u>', 46c1010edaSGreg Roach ], $temptext); 47a25f0a04SGreg Roach 4867c69ce5SGreg Roach // Set up the text style 4967c69ce5SGreg Roach if ($renderer->getCurrentStyle() !== $this->styleName) { 50a25f0a04SGreg Roach $renderer->setCurrentStyle($this->styleName); 51a25f0a04SGreg Roach } 52a25f0a04SGreg Roach 53a25f0a04SGreg Roach // If (Future-feature-enable/disable cell padding) 54a25f0a04SGreg Roach $cP = $renderer->cPadding; 55a25f0a04SGreg Roach 56a25f0a04SGreg Roach // Adjust the positions 57c21bdddcSGreg Roach if ($this->left === ReportBaseElement::CURRENT_POSITION) { 58a25f0a04SGreg Roach $this->left = $renderer->getX(); 59a25f0a04SGreg Roach } else { 60a25f0a04SGreg Roach $renderer->setX($this->left); 61a25f0a04SGreg Roach } 62a25f0a04SGreg Roach 63c21bdddcSGreg Roach if ($this->top === ReportBaseElement::CURRENT_POSITION) { 64a25f0a04SGreg Roach $this->top = $renderer->getY(); 65a25f0a04SGreg Roach } else { 66a25f0a04SGreg Roach $renderer->setY($this->top); 67a25f0a04SGreg Roach } 68a25f0a04SGreg Roach 69a25f0a04SGreg Roach // Start collecting the HTML code 707a6ee1acSGreg Roach echo '<div class="', $this->styleName, '" style="position:absolute;top:', $this->top, 'pt;'; 71a25f0a04SGreg Roach // Use Cell around padding to support RTL also 727a6ee1acSGreg Roach echo 'padding:', $cP, 'pt;'; 73a25f0a04SGreg Roach // LTR (left) or RTL (right) 747a6ee1acSGreg Roach echo $renderer->alignRTL, ':', $this->left, 'pt;'; 7567c69ce5SGreg Roach 76a25f0a04SGreg Roach // Background color 77a25f0a04SGreg Roach if (!empty($this->bgcolor)) { 787a6ee1acSGreg Roach echo 'background-color:', $this->bgcolor, ';'; 79a25f0a04SGreg Roach } 8067c69ce5SGreg Roach 8167c69ce5SGreg Roach // Borders 82a25f0a04SGreg Roach $bpixX = 0; 83a25f0a04SGreg Roach $bpixY = 0; 84a25f0a04SGreg Roach if (!empty($this->border)) { 85a25f0a04SGreg Roach // Border all around 86a25f0a04SGreg Roach if ($this->border == 1) { 877a6ee1acSGreg Roach echo ' border:solid '; 88a25f0a04SGreg Roach if (!empty($this->bocolor)) { 89a25f0a04SGreg Roach echo $this->bocolor; 90a25f0a04SGreg Roach } else { 917a6ee1acSGreg Roach echo 'black'; 92a25f0a04SGreg Roach } 937a6ee1acSGreg Roach echo ' 1pt;'; 94a25f0a04SGreg Roach $bpixX = 1; 95a25f0a04SGreg Roach $bpixY = 1; 96a25f0a04SGreg Roach } else { 977a6ee1acSGreg Roach if (stripos($this->border, 'T') !== false) { 987a6ee1acSGreg Roach echo ' border-top:solid '; 99a25f0a04SGreg Roach if (!empty($this->bocolor)) { 100a25f0a04SGreg Roach echo $this->bocolor; 101a25f0a04SGreg Roach } else { 1027a6ee1acSGreg Roach echo 'black'; 103a25f0a04SGreg Roach } 1047a6ee1acSGreg Roach echo ' 1pt;'; 105a25f0a04SGreg Roach $bpixY = 1; 106a25f0a04SGreg Roach } 1077a6ee1acSGreg Roach if (stripos($this->border, 'B') !== false) { 1087a6ee1acSGreg Roach echo ' border-bottom:solid '; 109a25f0a04SGreg Roach if (!empty($this->bocolor)) { 110a25f0a04SGreg Roach echo $this->bocolor; 111a25f0a04SGreg Roach } else { 1127a6ee1acSGreg Roach echo 'black'; 113a25f0a04SGreg Roach } 1147a6ee1acSGreg Roach echo ' 1pt;'; 115a25f0a04SGreg Roach $bpixY = 1; 116a25f0a04SGreg Roach } 1177a6ee1acSGreg Roach if (stripos($this->border, 'R') !== false) { 1187a6ee1acSGreg Roach echo ' border-right:solid '; 119a25f0a04SGreg Roach if (!empty($this->bocolor)) { 120a25f0a04SGreg Roach echo $this->bocolor; 121a25f0a04SGreg Roach } else { 1227a6ee1acSGreg Roach echo 'black'; 123a25f0a04SGreg Roach } 1247a6ee1acSGreg Roach echo ' 1pt;'; 125a25f0a04SGreg Roach $bpixX = 1; 126a25f0a04SGreg Roach } 1277a6ee1acSGreg Roach if (stripos($this->border, 'L') !== false) { 1287a6ee1acSGreg Roach echo ' border-left:solid '; 129a25f0a04SGreg Roach if (!empty($this->bocolor)) { 130a25f0a04SGreg Roach echo $this->bocolor; 131a25f0a04SGreg Roach } else { 1327a6ee1acSGreg Roach echo 'black'; 133a25f0a04SGreg Roach } 1347a6ee1acSGreg Roach echo ' 1pt;'; 135a25f0a04SGreg Roach $bpixX = 1; 136a25f0a04SGreg Roach } 137a25f0a04SGreg Roach } 138a25f0a04SGreg Roach } 139a25f0a04SGreg Roach // Check the width if set to page wide OR set by xml to larger then page wide 140a25f0a04SGreg Roach if ($this->width == 0 || $this->width > $renderer->getRemainingWidth()) { 141a25f0a04SGreg Roach $this->width = $renderer->getRemainingWidth(); 142a25f0a04SGreg Roach } 143a25f0a04SGreg Roach // We have to calculate a different width for the padding, counting on both side 144a25f0a04SGreg Roach $cW = $this->width - ($cP * 2); 145a25f0a04SGreg Roach 146a25f0a04SGreg Roach // If there is any text 147a25f0a04SGreg Roach if (!empty($temptext)) { 148a25f0a04SGreg Roach // Wrap the text 149a25f0a04SGreg Roach $temptext = $renderer->textWrap($temptext, $cW); 150a25f0a04SGreg Roach $tmph = $renderer->getTextCellHeight($temptext); 151a25f0a04SGreg Roach // Add some cell padding 152a25f0a04SGreg Roach $this->height += $cP; 153a25f0a04SGreg Roach if ($tmph > $this->height) { 154a25f0a04SGreg Roach $this->height = $tmph; 155a25f0a04SGreg Roach } 156a25f0a04SGreg Roach } 15767c69ce5SGreg Roach // Check the last cell height and adjust the current cell height if needed 158a25f0a04SGreg Roach if ($renderer->lastCellHeight > $this->height) { 159a25f0a04SGreg Roach $this->height = $renderer->lastCellHeight; 160a25f0a04SGreg Roach } 1617a6ee1acSGreg Roach echo ' width:', $cW - $bpixX, 'pt;height:', $this->height - $bpixY, 'pt;'; 162a25f0a04SGreg Roach 163a25f0a04SGreg Roach // Text alignment 164a25f0a04SGreg Roach switch ($this->align) { 1657a6ee1acSGreg Roach case 'C': 1667a6ee1acSGreg Roach echo ' text-align:center;'; 167a25f0a04SGreg Roach break; 1687a6ee1acSGreg Roach case 'L': 1697a6ee1acSGreg Roach echo ' text-align:left;'; 170a25f0a04SGreg Roach break; 1717a6ee1acSGreg Roach case 'R': 1727a6ee1acSGreg Roach echo ' text-align:right;'; 173a25f0a04SGreg Roach break; 174a25f0a04SGreg Roach } 175a25f0a04SGreg Roach 176a25f0a04SGreg Roach // Print the collected HTML code 1777a6ee1acSGreg Roach echo '">'; 178a25f0a04SGreg Roach 179a25f0a04SGreg Roach // Print URL 180a25f0a04SGreg Roach if (!empty($this->url)) { 1817a6ee1acSGreg Roach echo '<a href="', $this->url, '">'; 182a25f0a04SGreg Roach } 183a25f0a04SGreg Roach // Print any text if exists 184a25f0a04SGreg Roach if (!empty($temptext)) { 185a25f0a04SGreg Roach $renderer->write($temptext, $this->tcolor, false); 186a25f0a04SGreg Roach } 187a25f0a04SGreg Roach if (!empty($this->url)) { 1887a6ee1acSGreg Roach echo '</a>'; 189a25f0a04SGreg Roach } 190a25f0a04SGreg Roach // Finish the cell printing and start to clean up 191a25f0a04SGreg Roach echo "</div>\n"; 192ce15a17aSGreg Roach 193a25f0a04SGreg Roach // Where to place the next position 194a25f0a04SGreg Roach if ($this->newline == 0) { 195ce15a17aSGreg Roach // -> Next to this cell in the same line 196a25f0a04SGreg Roach $renderer->setXy($this->left + $this->width, $this->top); 197a25f0a04SGreg Roach $renderer->lastCellHeight = $this->height; 198ce15a17aSGreg Roach } elseif ($this->newline == 1) { 199ce15a17aSGreg Roach // -> On a new line at the margin - Default 200a25f0a04SGreg Roach $renderer->setXy(0, $renderer->getY() + $this->height + ($cP * 2)); 201a25f0a04SGreg Roach // Reset the last cell height for the next line 202a25f0a04SGreg Roach $renderer->lastCellHeight = 0; 203ce15a17aSGreg Roach } elseif ($this->newline == 2) { 204ce15a17aSGreg Roach // -> On a new line at the end of this cell 205a25f0a04SGreg Roach $renderer->setXy($renderer->getX() + $this->width, $renderer->getY() + $this->height + ($cP * 2)); 206a25f0a04SGreg Roach // Reset the last cell height for the next line 207a25f0a04SGreg Roach $renderer->lastCellHeight = 0; 208a25f0a04SGreg Roach } 209a25f0a04SGreg Roach } 210a25f0a04SGreg Roach} 211