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 * @return void 32 */ 33 public function render($renderer) 34 { 35 //-- to be implemented in inherited classes 36 } 37 38 /** 39 * Get the height. 40 * 41 * @param ReportHtml|ReportTcpdf $renderer 42 * 43 * @return float 44 */ 45 public function getHeight($renderer): float 46 { 47 return 0.0; 48 } 49 50 /** 51 * Get the width. 52 * 53 * @param ReportHtml|ReportTcpdf $renderer 54 * 55 * @return float|array 56 */ 57 public function getWidth($renderer) 58 { 59 return 0.0; 60 } 61 62 /** 63 * Add text. 64 * 65 * @param string $t 66 * 67 * @return void 68 */ 69 public function addText(string $t) 70 { 71 $t = trim($t, "\r\n\t"); 72 $t = str_replace([ 73 '<br>', 74 ' ', 75 ], [ 76 "\n", 77 ' ', 78 ], $t); 79 $t = strip_tags($t); 80 $t = htmlspecialchars_decode($t); 81 $this->text .= $t; 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 * @return void 125 */ 126 public function renderFootnote($renderer) 127 { 128 } 129 130 /** 131 * Set the text. 132 * 133 * @param $text 134 * 135 * @return void 136 */ 137 public function setText($text) 138 { 139 $this->text = $text; 140 } 141} 142