1a25f0a04SGreg Roach<?php 20e62c4b8SGreg Roachnamespace Fisharebest\Webtrees\Report; 3a25f0a04SGreg Roach 4a25f0a04SGreg Roach/** 5a25f0a04SGreg Roach * webtrees: online genealogy 6a25f0a04SGreg Roach * Copyright (C) 2015 webtrees development team 7a25f0a04SGreg Roach * This program is free software: you can redistribute it and/or modify 8a25f0a04SGreg Roach * it under the terms of the GNU General Public License as published by 9a25f0a04SGreg Roach * the Free Software Foundation, either version 3 of the License, or 10a25f0a04SGreg Roach * (at your option) any later version. 11a25f0a04SGreg Roach * This program is distributed in the hope that it will be useful, 12a25f0a04SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 13a25f0a04SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14a25f0a04SGreg Roach * GNU General Public License for more details. 15a25f0a04SGreg Roach * You should have received a copy of the GNU General Public License 16a25f0a04SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 17a25f0a04SGreg Roach */ 18a25f0a04SGreg Roach 19a25f0a04SGreg Roach/** 20a25f0a04SGreg Roach * Class ReportPdfCell 21a25f0a04SGreg Roach */ 22a25f0a04SGreg Roachclass ReportPdfCell extends ReportBaseCell { 23a25f0a04SGreg Roach /** 24a25f0a04SGreg Roach * PDF Cell renderer 25a25f0a04SGreg Roach * 26*adc8b18aSGreg Roach * @param ReportTcpdf $renderer 27a25f0a04SGreg Roach */ 28ffd703eaSGreg Roach public function render($renderer) { 29a25f0a04SGreg Roach 30a25f0a04SGreg Roach // Set up the text style 31a25f0a04SGreg Roach if (($renderer->getCurrentStyle()) != ($this->styleName)) { 32a25f0a04SGreg Roach $renderer->setCurrentStyle($this->styleName); 33a25f0a04SGreg Roach } 34a25f0a04SGreg Roach $temptext = str_replace("#PAGENUM#", $renderer->PageNo(), $this->text); 35a25f0a04SGreg Roach // underline «title» part of Source item 36a25f0a04SGreg Roach $temptext = str_replace(array('«', '»'), array('<u>', '</u>'), $temptext); 37a25f0a04SGreg Roach $match = array(); 38a25f0a04SGreg Roach // Indicates if the cell background must be painted (1) or transparent (0) 39a25f0a04SGreg Roach if ($this->fill == 1) { 40a25f0a04SGreg Roach if (!empty($this->bgcolor)) { 41a25f0a04SGreg Roach // HTML color to RGB 42a25f0a04SGreg Roach if (preg_match("/#?(..)(..)(..)/", $this->bgcolor, $match)) { 43a25f0a04SGreg Roach $r = hexdec($match[1]); 44a25f0a04SGreg Roach $g = hexdec($match[2]); 45a25f0a04SGreg Roach $b = hexdec($match[3]); 46a25f0a04SGreg Roach $renderer->SetFillColor($r, $g, $b); 47a25f0a04SGreg Roach } 48a25f0a04SGreg Roach } // If no color set then don't fill 49a25f0a04SGreg Roach else { 50a25f0a04SGreg Roach $this->fill = 0; 51a25f0a04SGreg Roach } 52a25f0a04SGreg Roach } 53a25f0a04SGreg Roach // Paint the Border color if set 54a25f0a04SGreg Roach if (!empty($this->bocolor)) { 55a25f0a04SGreg Roach // HTML color to RGB 56a25f0a04SGreg Roach if (preg_match("/#?(..)(..)(..)/", $this->bocolor, $match)) { 57a25f0a04SGreg Roach $r = hexdec($match[1]); 58a25f0a04SGreg Roach $g = hexdec($match[2]); 59a25f0a04SGreg Roach $b = hexdec($match[3]); 60a25f0a04SGreg Roach $renderer->SetDrawColor($r, $g, $b); 61a25f0a04SGreg Roach } 62a25f0a04SGreg Roach } 63a25f0a04SGreg Roach // Paint the text color or they might use inherited colors by the previous function 64a25f0a04SGreg Roach if (preg_match("/#?(..)(..)(..)/", $this->tcolor, $match)) { 65a25f0a04SGreg Roach $r = hexdec($match[1]); 66a25f0a04SGreg Roach $g = hexdec($match[2]); 67a25f0a04SGreg Roach $b = hexdec($match[3]); 68a25f0a04SGreg Roach $renderer->SetTextColor($r, $g, $b); 69a25f0a04SGreg Roach } else { 70a25f0a04SGreg Roach $renderer->SetTextColor(0, 0, 0); 71a25f0a04SGreg Roach } 72a25f0a04SGreg Roach 73a25f0a04SGreg Roach // If current position (left) 74a25f0a04SGreg Roach if ($this->left == ".") { 75a25f0a04SGreg Roach $cX = $renderer->GetX(); 76a25f0a04SGreg Roach } // For static position add margin (also updates X) 77a25f0a04SGreg Roach else { 78a25f0a04SGreg Roach $cX = $renderer->addMarginX($this->left); 79a25f0a04SGreg Roach } 80a25f0a04SGreg Roach 81a25f0a04SGreg Roach // Check the width if set to page wide OR set by xml to larger then page wide 82a25f0a04SGreg Roach if ($this->width == 0 || $this->width > $renderer->getRemainingWidthPDF()) { 83a25f0a04SGreg Roach $this->width = $renderer->getRemainingWidthPDF(); 84a25f0a04SGreg Roach } 85a25f0a04SGreg Roach // For current position 86a25f0a04SGreg Roach if ($this->top == ".") { 87a25f0a04SGreg Roach $this->top = $renderer->GetY(); 88a25f0a04SGreg Roach } else { 89a25f0a04SGreg Roach $renderer->SetY($this->top); 90a25f0a04SGreg Roach } 91a25f0a04SGreg Roach 92a25f0a04SGreg Roach // Check the last cell height and adjust the current cell height if needed 93a25f0a04SGreg Roach if ($renderer->lastCellHeight > $this->height) { 94a25f0a04SGreg Roach $this->height = $renderer->lastCellHeight; 95a25f0a04SGreg Roach } 96a25f0a04SGreg Roach // Check for pagebreak 97a25f0a04SGreg Roach if (!empty($temptext)) { 98a25f0a04SGreg Roach $cHT = $renderer->getNumLines($temptext, $this->width); 99a25f0a04SGreg Roach $cHT = $cHT * $renderer->getCellHeightRatio() * $renderer->getCurrentStyleHeight(); 100a25f0a04SGreg Roach $cM = $renderer->getMargins(); 101a25f0a04SGreg Roach // Add padding 102a25f0a04SGreg Roach if (is_array($cM['cell'])) { 103a25f0a04SGreg Roach $cHT += ($cM['padding_bottom'] + $cM['padding_top']); 104a25f0a04SGreg Roach } else { 105a25f0a04SGreg Roach $cHT += ($cM['cell'] * 2); 106a25f0a04SGreg Roach } 107a25f0a04SGreg Roach // Add a new page if needed 108a25f0a04SGreg Roach if ($renderer->checkPageBreakPDF($cHT)) { 109a25f0a04SGreg Roach $this->top = $renderer->GetY(); 110a25f0a04SGreg Roach } 111a25f0a04SGreg Roach $temptext = spanLTRRTL($temptext, "BOTH"); 112a25f0a04SGreg Roach } 113a25f0a04SGreg Roach // HTML ready - last value is true 114a25f0a04SGreg Roach $renderer->MultiCell( 115a25f0a04SGreg Roach $this->width, 116a25f0a04SGreg Roach $this->height, 117a25f0a04SGreg Roach $temptext, 118a25f0a04SGreg Roach $this->border, 119a25f0a04SGreg Roach $this->align, 120a25f0a04SGreg Roach $this->fill, 121a25f0a04SGreg Roach $this->newline, 122a25f0a04SGreg Roach $cX, 123a25f0a04SGreg Roach $this->top, 124a25f0a04SGreg Roach $this->reseth, 125a25f0a04SGreg Roach $this->stretch, 126a25f0a04SGreg Roach true 127a25f0a04SGreg Roach ); 128a25f0a04SGreg Roach // Reset the last cell height for the next line 129a25f0a04SGreg Roach if ($this->newline >= 1) { 130a25f0a04SGreg Roach $renderer->lastCellHeight = 0; 131a25f0a04SGreg Roach } // OR save the last height if heigher then before 132a25f0a04SGreg Roach elseif ($renderer->lastCellHeight < $renderer->getLastH()) { 133a25f0a04SGreg Roach $renderer->lastCellHeight = $renderer->getLastH(); 134a25f0a04SGreg Roach } 135a25f0a04SGreg Roach 136a25f0a04SGreg Roach // Set up the url link if exists ontop of the cell 137a25f0a04SGreg Roach if (!empty($this->url)) { 138a25f0a04SGreg Roach $renderer->Link($cX, $this->top, $this->width, $this->height, $this->url); 139a25f0a04SGreg Roach } 140a25f0a04SGreg Roach // Reset the border and the text color to black or they will be inherited 141a25f0a04SGreg Roach $renderer->SetDrawColor(0, 0, 0); 142a25f0a04SGreg Roach $renderer->SetTextColor(0, 0, 0); 143a25f0a04SGreg Roach } 144a25f0a04SGreg Roach} 145