1a25f0a04SGreg Roach<?php 2a25f0a04SGreg Roach/** 3a25f0a04SGreg Roach * webtrees: online genealogy 4*1062a142SGreg 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 */ 1676692c8bSGreg 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) { 287a6ee1acSGreg Roach if (strpos($this->text, '{{:ptp:}}') !== false) { 29a25f0a04SGreg Roach return; 30a25f0a04SGreg Roach } 317a6ee1acSGreg Roach $temptext = str_replace('#PAGENUM#', $renderer->pageNo(), $this->text); 32a25f0a04SGreg Roach // underline «title» part of Source item 3313abd6f3SGreg Roach $temptext = str_replace(['«', '»'], ['<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 447a6ee1acSGreg Roach if ($this->left == '.') { 45a25f0a04SGreg Roach $this->left = $renderer->getX(); 46a25f0a04SGreg Roach } else { 47a25f0a04SGreg Roach $renderer->setX($this->left); 48a25f0a04SGreg Roach } 49a25f0a04SGreg Roach 507a6ee1acSGreg 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 577a6ee1acSGreg Roach echo '<div class="', $this->styleName, '" style="position:absolute;top:', $this->top, 'pt;'; 58a25f0a04SGreg Roach // Use Cell around padding to support RTL also 597a6ee1acSGreg Roach echo 'padding:', $cP, 'pt;'; 60a25f0a04SGreg Roach // LTR (left) or RTL (right) 617a6ee1acSGreg Roach echo $renderer->alignRTL, ':', $this->left, 'pt;'; 62a25f0a04SGreg Roach // Background color 63a25f0a04SGreg Roach if (!empty($this->bgcolor)) { 647a6ee1acSGreg 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) { 727a6ee1acSGreg Roach echo ' border:solid '; 73a25f0a04SGreg Roach if (!empty($this->bocolor)) { 74a25f0a04SGreg Roach echo $this->bocolor; 75a25f0a04SGreg Roach } else { 767a6ee1acSGreg Roach echo 'black'; 77a25f0a04SGreg Roach } 787a6ee1acSGreg Roach echo ' 1pt;'; 79a25f0a04SGreg Roach $bpixX = 1; 80a25f0a04SGreg Roach $bpixY = 1; 81a25f0a04SGreg Roach } else { 827a6ee1acSGreg Roach if (stripos($this->border, 'T') !== false) { 837a6ee1acSGreg Roach echo ' border-top:solid '; 84a25f0a04SGreg Roach if (!empty($this->bocolor)) { 85a25f0a04SGreg Roach echo $this->bocolor; 86a25f0a04SGreg Roach } else { 877a6ee1acSGreg Roach echo 'black'; 88a25f0a04SGreg Roach } 897a6ee1acSGreg Roach echo ' 1pt;'; 90a25f0a04SGreg Roach $bpixY = 1; 91a25f0a04SGreg Roach } 927a6ee1acSGreg Roach if (stripos($this->border, 'B') !== false) { 937a6ee1acSGreg Roach echo ' border-bottom:solid '; 94a25f0a04SGreg Roach if (!empty($this->bocolor)) { 95a25f0a04SGreg Roach echo $this->bocolor; 96a25f0a04SGreg Roach } else { 977a6ee1acSGreg Roach echo 'black'; 98a25f0a04SGreg Roach } 997a6ee1acSGreg Roach echo ' 1pt;'; 100a25f0a04SGreg Roach $bpixY = 1; 101a25f0a04SGreg Roach } 1027a6ee1acSGreg Roach if (stripos($this->border, 'R') !== false) { 1037a6ee1acSGreg Roach echo ' border-right:solid '; 104a25f0a04SGreg Roach if (!empty($this->bocolor)) { 105a25f0a04SGreg Roach echo $this->bocolor; 106a25f0a04SGreg Roach } else { 1077a6ee1acSGreg Roach echo 'black'; 108a25f0a04SGreg Roach } 1097a6ee1acSGreg Roach echo ' 1pt;'; 110a25f0a04SGreg Roach $bpixX = 1; 111a25f0a04SGreg Roach } 1127a6ee1acSGreg Roach if (stripos($this->border, 'L') !== false) { 1137a6ee1acSGreg Roach echo ' border-left:solid '; 114a25f0a04SGreg Roach if (!empty($this->bocolor)) { 115a25f0a04SGreg Roach echo $this->bocolor; 116a25f0a04SGreg Roach } else { 1177a6ee1acSGreg Roach echo 'black'; 118a25f0a04SGreg Roach } 1197a6ee1acSGreg 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 } 1467a6ee1acSGreg Roach echo ' width:', $cW - $bpixX, 'pt;height:', $this->height - $bpixY, 'pt;'; 147a25f0a04SGreg Roach 148a25f0a04SGreg Roach // Text alignment 149a25f0a04SGreg Roach switch ($this->align) { 1507a6ee1acSGreg Roach case 'C': 1517a6ee1acSGreg Roach echo ' text-align:center;'; 152a25f0a04SGreg Roach break; 1537a6ee1acSGreg Roach case 'L': 1547a6ee1acSGreg Roach echo ' text-align:left;'; 155a25f0a04SGreg Roach break; 1567a6ee1acSGreg Roach case 'R': 1577a6ee1acSGreg Roach echo ' text-align:right;'; 158a25f0a04SGreg Roach break; 159a25f0a04SGreg Roach } 160a25f0a04SGreg Roach 161a25f0a04SGreg Roach // Print the collected HTML code 1627a6ee1acSGreg Roach echo '">'; 163a25f0a04SGreg Roach 164a25f0a04SGreg Roach // Print URL 165a25f0a04SGreg Roach if (!empty($this->url)) { 1667a6ee1acSGreg 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)) { 1737a6ee1acSGreg 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