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