xref: /webtrees/app/Report/ReportBaseElement.php (revision 71378461661e7642e52abe7d41c9cfffb3e5369b)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
16 */
17declare(strict_types=1);
18
19namespace Fisharebest\Webtrees\Report;
20
21/**
22 * Class ReportBaseElement
23 */
24class ReportBaseElement
25{
26    // Special value for X or Y position, to indicate the current position.
27    public const CURRENT_POSITION = -1.0;
28
29    /** @var string Text */
30    public $text = '';
31
32    /**
33     * Element renderer
34     *
35     * @param ReportHtml|ReportTcpdf $renderer
36     *
37     * @return void
38     */
39    public function render($renderer)
40    {
41        //-- to be implemented in inherited classes
42    }
43
44    /**
45     * Get the height.
46     *
47     * @param ReportHtml|ReportTcpdf $renderer
48     *
49     * @return float
50     */
51    public function getHeight($renderer): float
52    {
53        return 0.0;
54    }
55
56    /**
57     * Get the width.
58     *
59     * @param ReportHtml|ReportTcpdf $renderer
60     *
61     * @return float|array
62     */
63    public function getWidth($renderer)
64    {
65        return 0.0;
66    }
67
68    /**
69     * Add text.
70     *
71     * @param string $t
72     *
73     * @return void
74     */
75    public function addText(string $t)
76    {
77        $t          = trim($t, "\r\n\t");
78        $t          = str_replace([
79            '<br>',
80            '&nbsp;',
81        ], [
82            "\n",
83            ' ',
84        ], $t);
85        $t          = strip_tags($t);
86        $t          = htmlspecialchars_decode($t);
87        $this->text .= $t;
88    }
89
90    /**
91     * Add an end-of-line.
92     *
93     * @return void
94     */
95    public function addNewline()
96    {
97        $this->text .= "\n";
98    }
99
100    /**
101     * Get the current text.
102     *
103     * @return string
104     */
105    public function getValue(): string
106    {
107        return $this->text;
108    }
109
110    /**
111     * Set the width to wrap text.
112     *
113     * @param float $wrapwidth
114     * @param float $cellwidth
115     *
116     * @return float
117     */
118    public function setWrapWidth(float $wrapwidth, float $cellwidth): float
119    {
120        return 0;
121    }
122
123    /**
124     * Render the footnotes.
125     *
126     * @param ReportHtml|ReportTcpdf $renderer
127     *
128     * @return void
129     */
130    public function renderFootnote($renderer)
131    {
132    }
133
134    /**
135     * Set the text.
136     *
137     * @param string $text
138     *
139     * @return void
140     */
141    public function setText(string $text)
142    {
143        $this->text = $text;
144    }
145}
146