1<?php 2/** 3 * webtrees: online genealogy 4 * Copyright (C) 2018 webtrees development team 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 */ 16namespace Fisharebest\Webtrees\Report; 17 18/** 19 * Class ReportBaseElement 20 */ 21class ReportBaseElement 22{ 23 /** @var string Text */ 24 public $text = ''; 25 26 /** 27 * Element renderer 28 * 29 * @param ReportHtml|ReportTcpdf $renderer 30 */ 31 public function render($renderer) 32 { 33 //-- to be implemented in inherited classes 34 } 35 36 /** 37 * Get the height. 38 * 39 * @param ReportHtml|ReportTcpdf $renderer 40 * 41 * @return float 42 */ 43 public function getHeight($renderer): float 44 { 45 return 0.0; 46 } 47 48 /** 49 * Get the width. 50 * 51 * @param ReportHtml|ReportTcpdf $renderer 52 * 53 * @return float|array 54 */ 55 public function getWidth($renderer) 56 { 57 return 0.0; 58 } 59 60 /** 61 * Add text. 62 * 63 * @param string $t 64 * 65 * @return int 66 */ 67 public function addText($t): int 68 { 69 $t = trim($t, "\r\n\t"); 70 $t = str_replace([ 71 '<br>', 72 ' ', 73 ], [ 74 "\n", 75 ' ', 76 ], $t); 77 $t = strip_tags($t); 78 $t = htmlspecialchars_decode($t); 79 $this->text .= $t; 80 81 return 0; 82 } 83 84 /** 85 * Add an end-of-line. 86 * 87 * @return int 88 */ 89 public function addNewline(): int 90 { 91 $this->text .= "\n"; 92 93 return 0; 94 } 95 96 /** 97 * Get the current text. 98 * 99 * @return string 100 */ 101 public function getValue(): string 102 { 103 return $this->text; 104 } 105 106 /** 107 * Set the width to wrap text. 108 * 109 * @param $wrapwidth 110 * @param $cellwidth 111 * 112 * @return int 113 */ 114 public function setWrapWidth($wrapwidth, $cellwidth): int 115 { 116 return 0; 117 } 118 119 /** 120 * Render the footnotes. 121 * 122 * @param $renderer 123 */ 124 public function renderFootnote($renderer) 125 { 126 } 127 128 /** 129 * Set the text. 130 * 131 * @param $text 132 */ 133 public function setText($text) 134 { 135 $this->text = $text; 136 } 137} 138