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 */ 16declare(strict_types=1); 17 18namespace Fisharebest\Webtrees\Report; 19 20/** 21 * Class ReportBaseElement 22 */ 23class ReportBaseElement 24{ 25 /** @var string Text */ 26 public $text = ''; 27 28 /** 29 * Element renderer 30 * 31 * @param ReportHtml|ReportTcpdf $renderer 32 * 33 * @return void 34 */ 35 public function render($renderer) 36 { 37 //-- to be implemented in inherited classes 38 } 39 40 /** 41 * Get the height. 42 * 43 * @param ReportHtml|ReportTcpdf $renderer 44 * 45 * @return float 46 */ 47 public function getHeight($renderer): float 48 { 49 return 0.0; 50 } 51 52 /** 53 * Get the width. 54 * 55 * @param ReportHtml|ReportTcpdf $renderer 56 * 57 * @return float|array 58 */ 59 public function getWidth($renderer) 60 { 61 return 0.0; 62 } 63 64 /** 65 * Add text. 66 * 67 * @param string $t 68 * 69 * @return void 70 */ 71 public function addText(string $t) 72 { 73 $t = trim($t, "\r\n\t"); 74 $t = str_replace([ 75 '<br>', 76 ' ', 77 ], [ 78 "\n", 79 ' ', 80 ], $t); 81 $t = strip_tags($t); 82 $t = htmlspecialchars_decode($t); 83 $this->text .= $t; 84 } 85 86 /** 87 * Add an end-of-line. 88 * 89 * @return void 90 */ 91 public function addNewline() 92 { 93 $this->text .= "\n"; 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 float 113 */ 114 public function setWrapWidth($wrapwidth, $cellwidth): float 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