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