xref: /webtrees/app/Report/ReportBaseElement.php (revision 77bab46164e79833b0e2cc2442328cb5f47dd5e6)
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
34*77bab461SGreg 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     */
43*77bab461SGreg 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     *
65*77bab461SGreg 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");
82c1010edaSGreg Roach        $t          = str_replace([
83c1010edaSGreg Roach            '<br>',
84c1010edaSGreg Roach            '&nbsp;',
85c1010edaSGreg Roach        ], [
86c1010edaSGreg Roach            "\n",
87c1010edaSGreg Roach            ' ',
88c1010edaSGreg Roach        ], $t);
89a25f0a04SGreg Roach        $t          = strip_tags($t);
90a25f0a04SGreg Roach        $this->text .= $t;
91a25f0a04SGreg Roach    }
92a25f0a04SGreg Roach
93a25f0a04SGreg Roach    /**
9476692c8bSGreg Roach     * Add an end-of-line.
9576692c8bSGreg Roach     *
96589feda3SGreg Roach     * @return void
97a25f0a04SGreg Roach     */
98b6f35a76SGreg Roach    public function addNewline(): void
99c1010edaSGreg Roach    {
100a25f0a04SGreg Roach        $this->text .= "\n";
101a25f0a04SGreg Roach    }
102a25f0a04SGreg Roach
103a25f0a04SGreg Roach    /**
10476692c8bSGreg Roach     * Get the current text.
10576692c8bSGreg Roach     *
106a25f0a04SGreg Roach     * @return string
107a25f0a04SGreg Roach     */
1088f53f488SRico Sonntag    public function getValue(): string
109c1010edaSGreg Roach    {
110a25f0a04SGreg Roach        return $this->text;
111a25f0a04SGreg Roach    }
112a25f0a04SGreg Roach
113a25f0a04SGreg Roach    /**
11476692c8bSGreg Roach     * Set the width to wrap text.
11576692c8bSGreg Roach     *
116c21bdddcSGreg Roach     * @param float $wrapwidth
117c21bdddcSGreg Roach     * @param float $cellwidth
118a25f0a04SGreg Roach     *
119589feda3SGreg Roach     * @return float
120a25f0a04SGreg Roach     */
121c21bdddcSGreg Roach    public function setWrapWidth(float $wrapwidth, float $cellwidth): float
122c1010edaSGreg Roach    {
123a25f0a04SGreg Roach        return 0;
124a25f0a04SGreg Roach    }
125a25f0a04SGreg Roach
126a25f0a04SGreg Roach    /**
12776692c8bSGreg Roach     * Render the footnotes.
12876692c8bSGreg Roach     *
129b6f35a76SGreg Roach     * @param HtmlRenderer|PdfRenderer $renderer
13018d7a90dSGreg Roach     *
13118d7a90dSGreg Roach     * @return void
132a25f0a04SGreg Roach     */
133b6f35a76SGreg Roach    public function renderFootnote($renderer): void
134c1010edaSGreg Roach    {
135a25f0a04SGreg Roach    }
136a25f0a04SGreg Roach
137a25f0a04SGreg Roach    /**
13876692c8bSGreg Roach     * Set the text.
13976692c8bSGreg Roach     *
140c21bdddcSGreg Roach     * @param string $text
14118d7a90dSGreg Roach     *
14218d7a90dSGreg Roach     * @return void
143a25f0a04SGreg Roach     */
144b6f35a76SGreg Roach    public function setText(string $text): void
145c1010edaSGreg Roach    {
146a25f0a04SGreg Roach        $this->text = $text;
147a25f0a04SGreg Roach    }
148a25f0a04SGreg Roach}
149