xref: /webtrees/app/Report/ReportBaseElement.php (revision b6f35a76f16ee5da672b7d3d886becc6b838498e)
1a25f0a04SGreg Roach<?php
23976b470SGreg Roach
3a25f0a04SGreg Roach/**
4a25f0a04SGreg Roach * webtrees: online genealogy
58fcd0d32SGreg Roach * Copyright (C) 2019 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
15a25f0a04SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
16a25f0a04SGreg Roach */
17fcfa147eSGreg Roach
18e7f56f2aSGreg Roachdeclare(strict_types=1);
19e7f56f2aSGreg Roach
2076692c8bSGreg Roachnamespace Fisharebest\Webtrees\Report;
21a25f0a04SGreg Roach
22*b6f35a76SGreg Roachuse function htmlspecialchars_decode;
23*b6f35a76SGreg Roachuse function str_replace;
24*b6f35a76SGreg Roachuse function strip_tags;
25*b6f35a76SGreg Roachuse function trim;
26*b6f35a76SGreg Roach
27a25f0a04SGreg Roach/**
28a25f0a04SGreg Roach * Class ReportBaseElement
29a25f0a04SGreg Roach */
30c1010edaSGreg Roachclass ReportBaseElement
31c1010edaSGreg Roach{
32c21bdddcSGreg Roach    // Special value for X or Y position, to indicate the current position.
3316d6367aSGreg Roach    public const CURRENT_POSITION = -1.0;
34c21bdddcSGreg Roach
3576692c8bSGreg Roach    /** @var string Text */
3676692c8bSGreg Roach    public $text = '';
37a25f0a04SGreg Roach
38a25f0a04SGreg Roach    /**
39a25f0a04SGreg Roach     * Element renderer
40a25f0a04SGreg Roach     *
41*b6f35a76SGreg Roach     * @param HtmlRenderer|PdfRenderer $renderer
42c7ff4153SGreg Roach     *
43c7ff4153SGreg Roach     * @return void
44a25f0a04SGreg Roach     */
45c1010edaSGreg Roach    public function render($renderer)
46c1010edaSGreg Roach    {
47a25f0a04SGreg Roach        //-- to be implemented in inherited classes
48a25f0a04SGreg Roach    }
49a25f0a04SGreg Roach
50a25f0a04SGreg Roach    /**
5176692c8bSGreg Roach     * Get the height.
5276692c8bSGreg Roach     *
53*b6f35a76SGreg Roach     * @param HtmlRenderer|PdfRenderer $renderer
54a25f0a04SGreg Roach     *
55a25f0a04SGreg Roach     * @return float
56a25f0a04SGreg Roach     */
578f53f488SRico Sonntag    public function getHeight($renderer): float
58c1010edaSGreg Roach    {
59a25f0a04SGreg Roach        return 0.0;
60a25f0a04SGreg Roach    }
61a25f0a04SGreg Roach
62a25f0a04SGreg Roach    /**
6376692c8bSGreg Roach     * Get the width.
6476692c8bSGreg Roach     *
65*b6f35a76SGreg Roach     * @param HtmlRenderer|PdfRenderer $renderer
66a25f0a04SGreg Roach     *
678ba2e626SGreg Roach     * @return float|array
68a25f0a04SGreg Roach     */
698ba2e626SGreg Roach    public function getWidth($renderer)
70c1010edaSGreg Roach    {
71a25f0a04SGreg Roach        return 0.0;
72a25f0a04SGreg Roach    }
73a25f0a04SGreg Roach
74a25f0a04SGreg Roach    /**
7576692c8bSGreg Roach     * Add text.
7676692c8bSGreg Roach     *
77a25f0a04SGreg Roach     * @param string $t
78a25f0a04SGreg Roach     *
796c1eebecSGreg Roach     * @return void
80a25f0a04SGreg Roach     */
81*b6f35a76SGreg Roach    public function addText(string $t): void
82c1010edaSGreg Roach    {
83a25f0a04SGreg Roach        $t          = trim($t, "\r\n\t");
84c1010edaSGreg Roach        $t          = str_replace([
85c1010edaSGreg Roach            '<br>',
86c1010edaSGreg Roach            '&nbsp;',
87c1010edaSGreg Roach        ], [
88c1010edaSGreg Roach            "\n",
89c1010edaSGreg Roach            ' ',
90c1010edaSGreg Roach        ], $t);
91a25f0a04SGreg Roach        $t          = strip_tags($t);
92a25f0a04SGreg Roach        $t          = htmlspecialchars_decode($t);
93a25f0a04SGreg Roach        $this->text .= $t;
94a25f0a04SGreg Roach    }
95a25f0a04SGreg Roach
96a25f0a04SGreg Roach    /**
9776692c8bSGreg Roach     * Add an end-of-line.
9876692c8bSGreg Roach     *
99589feda3SGreg Roach     * @return void
100a25f0a04SGreg Roach     */
101*b6f35a76SGreg Roach    public function addNewline(): void
102c1010edaSGreg Roach    {
103a25f0a04SGreg Roach        $this->text .= "\n";
104a25f0a04SGreg Roach    }
105a25f0a04SGreg Roach
106a25f0a04SGreg Roach    /**
10776692c8bSGreg Roach     * Get the current text.
10876692c8bSGreg Roach     *
109a25f0a04SGreg Roach     * @return string
110a25f0a04SGreg Roach     */
1118f53f488SRico Sonntag    public function getValue(): string
112c1010edaSGreg Roach    {
113a25f0a04SGreg Roach        return $this->text;
114a25f0a04SGreg Roach    }
115a25f0a04SGreg Roach
116a25f0a04SGreg Roach    /**
11776692c8bSGreg Roach     * Set the width to wrap text.
11876692c8bSGreg Roach     *
119c21bdddcSGreg Roach     * @param float $wrapwidth
120c21bdddcSGreg Roach     * @param float $cellwidth
121a25f0a04SGreg Roach     *
122589feda3SGreg Roach     * @return float
123a25f0a04SGreg Roach     */
124c21bdddcSGreg Roach    public function setWrapWidth(float $wrapwidth, float $cellwidth): float
125c1010edaSGreg Roach    {
126a25f0a04SGreg Roach        return 0;
127a25f0a04SGreg Roach    }
128a25f0a04SGreg Roach
129a25f0a04SGreg Roach    /**
13076692c8bSGreg Roach     * Render the footnotes.
13176692c8bSGreg Roach     *
132*b6f35a76SGreg Roach     * @param HtmlRenderer|PdfRenderer $renderer
13318d7a90dSGreg Roach     *
13418d7a90dSGreg Roach     * @return void
135a25f0a04SGreg Roach     */
136*b6f35a76SGreg Roach    public function renderFootnote($renderer): void
137c1010edaSGreg Roach    {
138a25f0a04SGreg Roach    }
139a25f0a04SGreg Roach
140a25f0a04SGreg Roach    /**
14176692c8bSGreg Roach     * Set the text.
14276692c8bSGreg Roach     *
143c21bdddcSGreg Roach     * @param string $text
14418d7a90dSGreg Roach     *
14518d7a90dSGreg Roach     * @return void
146a25f0a04SGreg Roach     */
147*b6f35a76SGreg Roach    public function setText(string $text): void
148c1010edaSGreg Roach    {
149a25f0a04SGreg Roach        $this->text = $text;
150a25f0a04SGreg Roach    }
151a25f0a04SGreg Roach}
152