1a25f0a04SGreg Roach<?php 23976b470SGreg Roach 3a25f0a04SGreg Roach/** 4a25f0a04SGreg Roach * webtrees: online genealogy 5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 6a25f0a04SGreg Roach * This program is free software: you can redistribute it and/or modify 7a25f0a04SGreg Roach * it under the terms of the GNU General Public License as published by 8a25f0a04SGreg Roach * the Free Software Foundation, either version 3 of the License, or 9a25f0a04SGreg Roach * (at your option) any later version. 10a25f0a04SGreg Roach * This program is distributed in the hope that it will be useful, 11a25f0a04SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12a25f0a04SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13a25f0a04SGreg Roach * GNU General Public License for more details. 14a25f0a04SGreg Roach * You should have received a copy of the GNU General Public License 1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 16a25f0a04SGreg Roach */ 17fcfa147eSGreg Roach 18e7f56f2aSGreg Roachdeclare(strict_types=1); 19e7f56f2aSGreg Roach 2076692c8bSGreg Roachnamespace Fisharebest\Webtrees\Report; 21a25f0a04SGreg Roach 22b6f35a76SGreg Roachuse function strip_tags; 23b6f35a76SGreg Roachuse function trim; 24b6f35a76SGreg Roach 25a25f0a04SGreg Roach/** 26a25f0a04SGreg Roach * Class ReportBaseElement 27a25f0a04SGreg Roach */ 28c1010edaSGreg Roachclass ReportBaseElement 29c1010edaSGreg Roach{ 30c21bdddcSGreg Roach // Special value for X or Y position, to indicate the current position. 3116d6367aSGreg Roach public const CURRENT_POSITION = -1.0; 32c21bdddcSGreg Roach 3377bab461SGreg Roach public string $text = ''; 34a25f0a04SGreg Roach 35a25f0a04SGreg Roach /** 36a25f0a04SGreg Roach * Element renderer 37a25f0a04SGreg Roach * 38b6f35a76SGreg Roach * @param HtmlRenderer|PdfRenderer $renderer 39c7ff4153SGreg Roach * 40c7ff4153SGreg Roach * @return void 41a25f0a04SGreg Roach */ 4249528f2bSGreg Roach public function render($renderer): void 43c1010edaSGreg Roach { 44a25f0a04SGreg Roach //-- to be implemented in inherited classes 45a25f0a04SGreg Roach } 46a25f0a04SGreg Roach 47a25f0a04SGreg Roach /** 4876692c8bSGreg Roach * Get the height. 4976692c8bSGreg Roach * 50b6f35a76SGreg Roach * @param HtmlRenderer|PdfRenderer $renderer 51a25f0a04SGreg Roach * 52a25f0a04SGreg Roach * @return float 53a25f0a04SGreg Roach */ 5449528f2bSGreg Roach public function getHeight($renderer): float 55c1010edaSGreg Roach { 56a25f0a04SGreg Roach return 0.0; 57a25f0a04SGreg Roach } 58a25f0a04SGreg Roach 59a25f0a04SGreg Roach /** 6076692c8bSGreg Roach * Get the width. 6176692c8bSGreg Roach * 62b6f35a76SGreg Roach * @param HtmlRenderer|PdfRenderer $renderer 63a25f0a04SGreg Roach * 6477bab461SGreg Roach * @return array{0:float,1:int,2:float} 65a25f0a04SGreg Roach */ 6649528f2bSGreg Roach public function getWidth($renderer): array 67c1010edaSGreg Roach { 6841cfb9e2SGreg Roach return [0.0, 1, 0.0]; 69a25f0a04SGreg Roach } 70a25f0a04SGreg Roach 71a25f0a04SGreg Roach /** 7276692c8bSGreg Roach * Add text. 7376692c8bSGreg Roach * 74a25f0a04SGreg Roach * @param string $t 75a25f0a04SGreg Roach * 766c1eebecSGreg Roach * @return void 77a25f0a04SGreg Roach */ 78b6f35a76SGreg Roach public function addText(string $t): void 79c1010edaSGreg Roach { 80a25f0a04SGreg Roach $t = trim($t, "\r\n\t"); 814fedbbe7SGreg Roach $t = strtr($t, ['<br>' => "\n", ' ' => ' ']); 824fedbbe7SGreg Roach 834fedbbe7SGreg Roach $this->text .= strip_tags($t); 84a25f0a04SGreg Roach } 85a25f0a04SGreg Roach 86a25f0a04SGreg Roach /** 8776692c8bSGreg Roach * Add an end-of-line. 8876692c8bSGreg Roach * 89589feda3SGreg Roach * @return void 90a25f0a04SGreg Roach */ 91b6f35a76SGreg Roach public function addNewline(): void 92c1010edaSGreg Roach { 93a25f0a04SGreg Roach $this->text .= "\n"; 94a25f0a04SGreg Roach } 95a25f0a04SGreg Roach 96a25f0a04SGreg Roach /** 9776692c8bSGreg Roach * Get the current text. 9876692c8bSGreg Roach * 99a25f0a04SGreg Roach * @return string 100a25f0a04SGreg Roach */ 1018f53f488SRico Sonntag public function getValue(): string 102c1010edaSGreg Roach { 103a25f0a04SGreg Roach return $this->text; 104a25f0a04SGreg Roach } 105a25f0a04SGreg Roach 106a25f0a04SGreg Roach /** 10776692c8bSGreg Roach * Set the width to wrap text. 10876692c8bSGreg Roach * 109c21bdddcSGreg Roach * @param float $wrapwidth 110c21bdddcSGreg Roach * @param float $cellwidth 111a25f0a04SGreg Roach * 112589feda3SGreg Roach * @return float 113a25f0a04SGreg Roach */ 11449528f2bSGreg Roach public function setWrapWidth(float $wrapwidth, float $cellwidth): float 115c1010edaSGreg Roach { 116a25f0a04SGreg Roach return 0; 117a25f0a04SGreg Roach } 118a25f0a04SGreg Roach 119a25f0a04SGreg Roach /** 12076692c8bSGreg Roach * Render the footnotes. 12176692c8bSGreg Roach * 122b6f35a76SGreg Roach * @param HtmlRenderer|PdfRenderer $renderer 12318d7a90dSGreg Roach * 12418d7a90dSGreg Roach * @return void 125a25f0a04SGreg Roach */ 12649528f2bSGreg Roach public function renderFootnote($renderer): void 127c1010edaSGreg Roach { 128a25f0a04SGreg Roach } 129a25f0a04SGreg Roach 130a25f0a04SGreg Roach /** 13176692c8bSGreg Roach * Set the text. 13276692c8bSGreg Roach * 133c21bdddcSGreg Roach * @param string $text 13418d7a90dSGreg Roach * 13518d7a90dSGreg Roach * @return void 136a25f0a04SGreg Roach */ 137b6f35a76SGreg Roach public function setText(string $text): void 138c1010edaSGreg Roach { 139a25f0a04SGreg Roach $this->text = $text; 140a25f0a04SGreg Roach } 141a25f0a04SGreg Roach} 142