xref: /webtrees/app/Report/ReportBaseElement.php (revision 4fedbbe79c9187aacded3e24568fdd4ffb86138e)
1a25f0a04SGreg Roach<?php
23976b470SGreg Roach
3a25f0a04SGreg Roach/**
4a25f0a04SGreg Roach * webtrees: online genealogy
589f7189bSGreg Roach * Copyright (C) 2021 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 str_replace;
23b6f35a76SGreg Roachuse function strip_tags;
24b6f35a76SGreg Roachuse function trim;
25b6f35a76SGreg Roach
26a25f0a04SGreg Roach/**
27a25f0a04SGreg Roach * Class ReportBaseElement
28a25f0a04SGreg Roach */
29c1010edaSGreg Roachclass ReportBaseElement
30c1010edaSGreg Roach{
31c21bdddcSGreg Roach    // Special value for X or Y position, to indicate the current position.
3216d6367aSGreg Roach    public const CURRENT_POSITION = -1.0;
33c21bdddcSGreg Roach
3477bab461SGreg Roach    public string $text = '';
35a25f0a04SGreg Roach
36a25f0a04SGreg Roach    /**
37a25f0a04SGreg Roach     * Element renderer
38a25f0a04SGreg Roach     *
39b6f35a76SGreg Roach     * @param HtmlRenderer|PdfRenderer $renderer
40c7ff4153SGreg Roach     *
41c7ff4153SGreg Roach     * @return void
42a25f0a04SGreg Roach     */
4377bab461SGreg Roach    public function render($renderer): void
44c1010edaSGreg Roach    {
45a25f0a04SGreg Roach        //-- to be implemented in inherited classes
46a25f0a04SGreg Roach    }
47a25f0a04SGreg Roach
48a25f0a04SGreg Roach    /**
4976692c8bSGreg Roach     * Get the height.
5076692c8bSGreg Roach     *
51b6f35a76SGreg Roach     * @param HtmlRenderer|PdfRenderer $renderer
52a25f0a04SGreg Roach     *
53a25f0a04SGreg Roach     * @return float
54a25f0a04SGreg Roach     */
558f53f488SRico Sonntag    public function getHeight($renderer): float
56c1010edaSGreg Roach    {
57a25f0a04SGreg Roach        return 0.0;
58a25f0a04SGreg Roach    }
59a25f0a04SGreg Roach
60a25f0a04SGreg Roach    /**
6176692c8bSGreg Roach     * Get the width.
6276692c8bSGreg Roach     *
63b6f35a76SGreg Roach     * @param HtmlRenderer|PdfRenderer $renderer
64a25f0a04SGreg Roach     *
6577bab461SGreg Roach     * @return array{0:float,1:int,2:float}
66a25f0a04SGreg Roach     */
6741cfb9e2SGreg Roach    public function getWidth($renderer): array
68c1010edaSGreg Roach    {
6941cfb9e2SGreg Roach        return [0.0, 1, 0.0];
70a25f0a04SGreg Roach    }
71a25f0a04SGreg Roach
72a25f0a04SGreg Roach    /**
7376692c8bSGreg Roach     * Add text.
7476692c8bSGreg Roach     *
75a25f0a04SGreg Roach     * @param string $t
76a25f0a04SGreg Roach     *
776c1eebecSGreg Roach     * @return void
78a25f0a04SGreg Roach     */
79b6f35a76SGreg Roach    public function addText(string $t): void
80c1010edaSGreg Roach    {
81a25f0a04SGreg Roach        $t = trim($t, "\r\n\t");
82*4fedbbe7SGreg Roach        $t = strtr($t, ['<br>' => "\n", '&nbsp;' => ' ']);
83*4fedbbe7SGreg Roach
84*4fedbbe7SGreg Roach        $this->text .= strip_tags($t);
85a25f0a04SGreg Roach    }
86a25f0a04SGreg Roach
87a25f0a04SGreg Roach    /**
8876692c8bSGreg Roach     * Add an end-of-line.
8976692c8bSGreg Roach     *
90589feda3SGreg Roach     * @return void
91a25f0a04SGreg Roach     */
92b6f35a76SGreg Roach    public function addNewline(): void
93c1010edaSGreg Roach    {
94a25f0a04SGreg Roach        $this->text .= "\n";
95a25f0a04SGreg Roach    }
96a25f0a04SGreg Roach
97a25f0a04SGreg Roach    /**
9876692c8bSGreg Roach     * Get the current text.
9976692c8bSGreg Roach     *
100a25f0a04SGreg Roach     * @return string
101a25f0a04SGreg Roach     */
1028f53f488SRico Sonntag    public function getValue(): string
103c1010edaSGreg Roach    {
104a25f0a04SGreg Roach        return $this->text;
105a25f0a04SGreg Roach    }
106a25f0a04SGreg Roach
107a25f0a04SGreg Roach    /**
10876692c8bSGreg Roach     * Set the width to wrap text.
10976692c8bSGreg Roach     *
110c21bdddcSGreg Roach     * @param float $wrapwidth
111c21bdddcSGreg Roach     * @param float $cellwidth
112a25f0a04SGreg Roach     *
113589feda3SGreg Roach     * @return float
114a25f0a04SGreg Roach     */
115c21bdddcSGreg Roach    public function setWrapWidth(float $wrapwidth, float $cellwidth): float
116c1010edaSGreg Roach    {
117a25f0a04SGreg Roach        return 0;
118a25f0a04SGreg Roach    }
119a25f0a04SGreg Roach
120a25f0a04SGreg Roach    /**
12176692c8bSGreg Roach     * Render the footnotes.
12276692c8bSGreg Roach     *
123b6f35a76SGreg Roach     * @param HtmlRenderer|PdfRenderer $renderer
12418d7a90dSGreg Roach     *
12518d7a90dSGreg Roach     * @return void
126a25f0a04SGreg Roach     */
127b6f35a76SGreg Roach    public function renderFootnote($renderer): void
128c1010edaSGreg Roach    {
129a25f0a04SGreg Roach    }
130a25f0a04SGreg Roach
131a25f0a04SGreg Roach    /**
13276692c8bSGreg Roach     * Set the text.
13376692c8bSGreg Roach     *
134c21bdddcSGreg Roach     * @param string $text
13518d7a90dSGreg Roach     *
13618d7a90dSGreg Roach     * @return void
137a25f0a04SGreg Roach     */
138b6f35a76SGreg Roach    public function setText(string $text): void
139c1010edaSGreg Roach    {
140a25f0a04SGreg Roach        $this->text = $text;
141a25f0a04SGreg Roach    }
142a25f0a04SGreg Roach}
143