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