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