1<?php 2namespace Fisharebest\Webtrees\Report; 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 ReportPdfCell 21 */ 22class ReportPdfCell extends ReportBaseCell { 23 /** 24 * PDF Cell renderer 25 * 26 * @param ReportTcpdf $renderer 27 */ 28 public function render($renderer) { 29 30 // Set up the text style 31 if (($renderer->getCurrentStyle()) != ($this->styleName)) { 32 $renderer->setCurrentStyle($this->styleName); 33 } 34 $temptext = str_replace("#PAGENUM#", $renderer->PageNo(), $this->text); 35 // underline «title» part of Source item 36 $temptext = str_replace(array('«', '»'), array('<u>', '</u>'), $temptext); 37 $match = array(); 38 // Indicates if the cell background must be painted (1) or transparent (0) 39 if ($this->fill == 1) { 40 if (!empty($this->bgcolor)) { 41 // HTML color to RGB 42 if (preg_match("/#?(..)(..)(..)/", $this->bgcolor, $match)) { 43 $r = hexdec($match[1]); 44 $g = hexdec($match[2]); 45 $b = hexdec($match[3]); 46 $renderer->SetFillColor($r, $g, $b); 47 } 48 } // If no color set then don't fill 49 else { 50 $this->fill = 0; 51 } 52 } 53 // Paint the Border color if set 54 if (!empty($this->bocolor)) { 55 // HTML color to RGB 56 if (preg_match("/#?(..)(..)(..)/", $this->bocolor, $match)) { 57 $r = hexdec($match[1]); 58 $g = hexdec($match[2]); 59 $b = hexdec($match[3]); 60 $renderer->SetDrawColor($r, $g, $b); 61 } 62 } 63 // Paint the text color or they might use inherited colors by the previous function 64 if (preg_match("/#?(..)(..)(..)/", $this->tcolor, $match)) { 65 $r = hexdec($match[1]); 66 $g = hexdec($match[2]); 67 $b = hexdec($match[3]); 68 $renderer->SetTextColor($r, $g, $b); 69 } else { 70 $renderer->SetTextColor(0, 0, 0); 71 } 72 73 // If current position (left) 74 if ($this->left == ".") { 75 $cX = $renderer->GetX(); 76 } // For static position add margin (also updates X) 77 else { 78 $cX = $renderer->addMarginX($this->left); 79 } 80 81 // Check the width if set to page wide OR set by xml to larger then page wide 82 if ($this->width == 0 || $this->width > $renderer->getRemainingWidthPDF()) { 83 $this->width = $renderer->getRemainingWidthPDF(); 84 } 85 // For current position 86 if ($this->top == ".") { 87 $this->top = $renderer->GetY(); 88 } else { 89 $renderer->SetY($this->top); 90 } 91 92 // Check the last cell height and adjust the current cell height if needed 93 if ($renderer->lastCellHeight > $this->height) { 94 $this->height = $renderer->lastCellHeight; 95 } 96 // Check for pagebreak 97 if (!empty($temptext)) { 98 $cHT = $renderer->getNumLines($temptext, $this->width); 99 $cHT = $cHT * $renderer->getCellHeightRatio() * $renderer->getCurrentStyleHeight(); 100 $cM = $renderer->getMargins(); 101 // Add padding 102 if (is_array($cM['cell'])) { 103 $cHT += ($cM['padding_bottom'] + $cM['padding_top']); 104 } else { 105 $cHT += ($cM['cell'] * 2); 106 } 107 // Add a new page if needed 108 if ($renderer->checkPageBreakPDF($cHT)) { 109 $this->top = $renderer->GetY(); 110 } 111 $temptext = spanLTRRTL($temptext, "BOTH"); 112 } 113 // HTML ready - last value is true 114 $renderer->MultiCell( 115 $this->width, 116 $this->height, 117 $temptext, 118 $this->border, 119 $this->align, 120 $this->fill, 121 $this->newline, 122 $cX, 123 $this->top, 124 $this->reseth, 125 $this->stretch, 126 true 127 ); 128 // Reset the last cell height for the next line 129 if ($this->newline >= 1) { 130 $renderer->lastCellHeight = 0; 131 } // OR save the last height if heigher then before 132 elseif ($renderer->lastCellHeight < $renderer->getLastH()) { 133 $renderer->lastCellHeight = $renderer->getLastH(); 134 } 135 136 // Set up the url link if exists ontop of the cell 137 if (!empty($this->url)) { 138 $renderer->Link($cX, $this->top, $this->width, $this->height, $this->url); 139 } 140 // Reset the border and the text color to black or they will be inherited 141 $renderer->SetDrawColor(0, 0, 0); 142 $renderer->SetTextColor(0, 0, 0); 143 } 144} 145