xref: /webtrees/app/Report/ReportBaseElement.php (revision e7f56f2af615447ab1a7646851f88b465ace9e04)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2018 webtrees development team
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16declare(strict_types=1);
17
18namespace Fisharebest\Webtrees\Report;
19
20/**
21 * Class ReportBaseElement
22 */
23class ReportBaseElement
24{
25    /** @var string Text */
26    public $text = '';
27
28    /**
29     * Element renderer
30     *
31     * @param ReportHtml|ReportTcpdf $renderer
32     *
33     * @return void
34     */
35    public function render($renderer)
36    {
37        //-- to be implemented in inherited classes
38    }
39
40    /**
41     * Get the height.
42     *
43     * @param ReportHtml|ReportTcpdf $renderer
44     *
45     * @return float
46     */
47    public function getHeight($renderer): float
48    {
49        return 0.0;
50    }
51
52    /**
53     * Get the width.
54     *
55     * @param ReportHtml|ReportTcpdf $renderer
56     *
57     * @return float|array
58     */
59    public function getWidth($renderer)
60    {
61        return 0.0;
62    }
63
64    /**
65     * Add text.
66     *
67     * @param string $t
68     *
69     * @return void
70     */
71    public function addText(string $t)
72    {
73        $t          = trim($t, "\r\n\t");
74        $t          = str_replace([
75            '<br>',
76            '&nbsp;',
77        ], [
78            "\n",
79            ' ',
80        ], $t);
81        $t          = strip_tags($t);
82        $t          = htmlspecialchars_decode($t);
83        $this->text .= $t;
84    }
85
86    /**
87     * Add an end-of-line.
88     *
89     * @return int
90     */
91    public function addNewline(): int
92    {
93        $this->text .= "\n";
94
95        return 0;
96    }
97
98    /**
99     * Get the current text.
100     *
101     * @return string
102     */
103    public function getValue(): string
104    {
105        return $this->text;
106    }
107
108    /**
109     * Set the width to wrap text.
110     *
111     * @param $wrapwidth
112     * @param $cellwidth
113     *
114     * @return int
115     */
116    public function setWrapWidth($wrapwidth, $cellwidth): int
117    {
118        return 0;
119    }
120
121    /**
122     * Render the footnotes.
123     *
124     * @param $renderer
125     *
126     * @return void
127     */
128    public function renderFootnote($renderer)
129    {
130    }
131
132    /**
133     * Set the text.
134     *
135     * @param $text
136     *
137     * @return void
138     */
139    public function setText($text)
140    {
141        $this->text = $text;
142    }
143}
144