1<?php 2/** 3 * webtrees: online genealogy 4 * Copyright (C) 2019 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 // Special value for X or Y position, to indicate the current position. 26 public const CURRENT_POSITION = -1.0; 27 28 /** @var string Text */ 29 public $text = ''; 30 31 /** 32 * Element renderer 33 * 34 * @param ReportHtml|ReportTcpdf $renderer 35 * 36 * @return void 37 */ 38 public function render($renderer) 39 { 40 //-- to be implemented in inherited classes 41 } 42 43 /** 44 * Get the height. 45 * 46 * @param ReportHtml|ReportTcpdf $renderer 47 * 48 * @return float 49 */ 50 public function getHeight($renderer): float 51 { 52 return 0.0; 53 } 54 55 /** 56 * Get the width. 57 * 58 * @param ReportHtml|ReportTcpdf $renderer 59 * 60 * @return float|array 61 */ 62 public function getWidth($renderer) 63 { 64 return 0.0; 65 } 66 67 /** 68 * Add text. 69 * 70 * @param string $t 71 * 72 * @return void 73 */ 74 public function addText(string $t) 75 { 76 $t = trim($t, "\r\n\t"); 77 $t = str_replace([ 78 '<br>', 79 ' ', 80 ], [ 81 "\n", 82 ' ', 83 ], $t); 84 $t = strip_tags($t); 85 $t = htmlspecialchars_decode($t); 86 $this->text .= $t; 87 } 88 89 /** 90 * Add an end-of-line. 91 * 92 * @return void 93 */ 94 public function addNewline() 95 { 96 $this->text .= "\n"; 97 } 98 99 /** 100 * Get the current text. 101 * 102 * @return string 103 */ 104 public function getValue(): string 105 { 106 return $this->text; 107 } 108 109 /** 110 * Set the width to wrap text. 111 * 112 * @param float $wrapwidth 113 * @param float $cellwidth 114 * 115 * @return float 116 */ 117 public function setWrapWidth(float $wrapwidth, float $cellwidth): float 118 { 119 return 0; 120 } 121 122 /** 123 * Render the footnotes. 124 * 125 * @param ReportHtml|ReportTcpdf $renderer 126 * 127 * @return void 128 */ 129 public function renderFootnote($renderer) 130 { 131 } 132 133 /** 134 * Set the text. 135 * 136 * @param string $text 137 * 138 * @return void 139 */ 140 public function setText(string $text) 141 { 142 $this->text = $text; 143 } 144} 145