xref: /webtrees/app/Report/ReportBaseElement.php (revision cfe766af61e4d860f17afd91dc1b2e538caffa79)
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 */
16namespace Fisharebest\Webtrees\Report;
17
18/**
19 * Class ReportBaseElement
20 */
21class ReportBaseElement
22{
23    /** @var string Text */
24    public $text = '';
25
26    /**
27     * Element renderer
28     *
29     * @param ReportHtml|ReportTcpdf $renderer
30     *
31     * @return void
32     */
33    public function render($renderer)
34    {
35        //-- to be implemented in inherited classes
36    }
37
38    /**
39     * Get the height.
40     *
41     * @param ReportHtml|ReportTcpdf $renderer
42     *
43     * @return float
44     */
45    public function getHeight($renderer): float
46    {
47        return 0.0;
48    }
49
50    /**
51     * Get the width.
52     *
53     * @param ReportHtml|ReportTcpdf $renderer
54     *
55     * @return float|array
56     */
57    public function getWidth($renderer)
58    {
59        return 0.0;
60    }
61
62    /**
63     * Add text.
64     *
65     * @param string $t
66     *
67     * @return int
68     */
69    public function addText($t): int
70    {
71        $t          = trim($t, "\r\n\t");
72        $t          = str_replace([
73            '<br>',
74            '&nbsp;',
75        ], [
76            "\n",
77            ' ',
78        ], $t);
79        $t          = strip_tags($t);
80        $t          = htmlspecialchars_decode($t);
81        $this->text .= $t;
82
83        return 0;
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    public function renderFootnote($renderer)
127    {
128    }
129
130    /**
131     * Set the text.
132     *
133     * @param $text
134     */
135    public function setText($text)
136    {
137        $this->text = $text;
138    }
139}
140