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