xref: /webtrees/app/Report/ReportBaseElement.php (revision fcfa147e10aaa6c7ff580c29bd6e5b88666befc1)
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 */
17*fcfa147eSGreg Roach
18e7f56f2aSGreg Roachdeclare(strict_types=1);
19e7f56f2aSGreg Roach
2076692c8bSGreg Roachnamespace Fisharebest\Webtrees\Report;
21a25f0a04SGreg Roach
22a25f0a04SGreg Roach/**
23a25f0a04SGreg Roach * Class ReportBaseElement
24a25f0a04SGreg Roach */
25c1010edaSGreg Roachclass ReportBaseElement
26c1010edaSGreg Roach{
27c21bdddcSGreg Roach    // Special value for X or Y position, to indicate the current position.
2816d6367aSGreg Roach    public const CURRENT_POSITION = -1.0;
29c21bdddcSGreg Roach
3076692c8bSGreg Roach    /** @var string Text */
3176692c8bSGreg Roach    public $text = '';
32a25f0a04SGreg Roach
33a25f0a04SGreg Roach    /**
34a25f0a04SGreg Roach     * Element renderer
35a25f0a04SGreg Roach     *
36729ce104SGreg Roach     * @param ReportHtml|ReportTcpdf $renderer
37c7ff4153SGreg Roach     *
38c7ff4153SGreg Roach     * @return void
39a25f0a04SGreg Roach     */
40c1010edaSGreg Roach    public function render($renderer)
41c1010edaSGreg Roach    {
42a25f0a04SGreg Roach        //-- to be implemented in inherited classes
43a25f0a04SGreg Roach    }
44a25f0a04SGreg Roach
45a25f0a04SGreg Roach    /**
4676692c8bSGreg Roach     * Get the height.
4776692c8bSGreg Roach     *
48729ce104SGreg Roach     * @param ReportHtml|ReportTcpdf $renderer
49a25f0a04SGreg Roach     *
50a25f0a04SGreg Roach     * @return float
51a25f0a04SGreg Roach     */
528f53f488SRico Sonntag    public function getHeight($renderer): float
53c1010edaSGreg Roach    {
54a25f0a04SGreg Roach        return 0.0;
55a25f0a04SGreg Roach    }
56a25f0a04SGreg Roach
57a25f0a04SGreg Roach    /**
5876692c8bSGreg Roach     * Get the width.
5976692c8bSGreg Roach     *
60729ce104SGreg Roach     * @param ReportHtml|ReportTcpdf $renderer
61a25f0a04SGreg Roach     *
628ba2e626SGreg Roach     * @return float|array
63a25f0a04SGreg Roach     */
648ba2e626SGreg Roach    public function getWidth($renderer)
65c1010edaSGreg Roach    {
66a25f0a04SGreg Roach        return 0.0;
67a25f0a04SGreg Roach    }
68a25f0a04SGreg Roach
69a25f0a04SGreg Roach    /**
7076692c8bSGreg Roach     * Add text.
7176692c8bSGreg Roach     *
72a25f0a04SGreg Roach     * @param string $t
73a25f0a04SGreg Roach     *
746c1eebecSGreg Roach     * @return void
75a25f0a04SGreg Roach     */
766c1eebecSGreg Roach    public function addText(string $t)
77c1010edaSGreg Roach    {
78a25f0a04SGreg Roach        $t          = trim($t, "\r\n\t");
79c1010edaSGreg Roach        $t          = str_replace([
80c1010edaSGreg Roach            '<br>',
81c1010edaSGreg Roach            '&nbsp;',
82c1010edaSGreg Roach        ], [
83c1010edaSGreg Roach            "\n",
84c1010edaSGreg Roach            ' ',
85c1010edaSGreg Roach        ], $t);
86a25f0a04SGreg Roach        $t          = strip_tags($t);
87a25f0a04SGreg Roach        $t          = htmlspecialchars_decode($t);
88a25f0a04SGreg Roach        $this->text .= $t;
89a25f0a04SGreg Roach    }
90a25f0a04SGreg Roach
91a25f0a04SGreg Roach    /**
9276692c8bSGreg Roach     * Add an end-of-line.
9376692c8bSGreg Roach     *
94589feda3SGreg Roach     * @return void
95a25f0a04SGreg Roach     */
96589feda3SGreg Roach    public function addNewline()
97c1010edaSGreg Roach    {
98a25f0a04SGreg Roach        $this->text .= "\n";
99a25f0a04SGreg Roach    }
100a25f0a04SGreg Roach
101a25f0a04SGreg Roach    /**
10276692c8bSGreg Roach     * Get the current text.
10376692c8bSGreg Roach     *
104a25f0a04SGreg Roach     * @return string
105a25f0a04SGreg Roach     */
1068f53f488SRico Sonntag    public function getValue(): string
107c1010edaSGreg Roach    {
108a25f0a04SGreg Roach        return $this->text;
109a25f0a04SGreg Roach    }
110a25f0a04SGreg Roach
111a25f0a04SGreg Roach    /**
11276692c8bSGreg Roach     * Set the width to wrap text.
11376692c8bSGreg Roach     *
114c21bdddcSGreg Roach     * @param float $wrapwidth
115c21bdddcSGreg Roach     * @param float $cellwidth
116a25f0a04SGreg Roach     *
117589feda3SGreg Roach     * @return float
118a25f0a04SGreg Roach     */
119c21bdddcSGreg Roach    public function setWrapWidth(float $wrapwidth, float $cellwidth): float
120c1010edaSGreg Roach    {
121a25f0a04SGreg Roach        return 0;
122a25f0a04SGreg Roach    }
123a25f0a04SGreg Roach
124a25f0a04SGreg Roach    /**
12576692c8bSGreg Roach     * Render the footnotes.
12676692c8bSGreg Roach     *
1279ae7af99SGreg Roach     * @param ReportHtml|ReportTcpdf $renderer
12818d7a90dSGreg Roach     *
12918d7a90dSGreg Roach     * @return void
130a25f0a04SGreg Roach     */
131c1010edaSGreg Roach    public function renderFootnote($renderer)
132c1010edaSGreg Roach    {
133a25f0a04SGreg Roach    }
134a25f0a04SGreg Roach
135a25f0a04SGreg Roach    /**
13676692c8bSGreg Roach     * Set the text.
13776692c8bSGreg Roach     *
138c21bdddcSGreg Roach     * @param string $text
13918d7a90dSGreg Roach     *
14018d7a90dSGreg Roach     * @return void
141a25f0a04SGreg Roach     */
142c21bdddcSGreg Roach    public function setText(string $text)
143c1010edaSGreg Roach    {
144a25f0a04SGreg Roach        $this->text = $text;
145a25f0a04SGreg Roach    }
146a25f0a04SGreg Roach}
147