xref: /webtrees/app/Report/ReportBaseFootnote.php (revision 4d314e6b28a3e57668463e010244449523e91e5c)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2019 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 ReportBaseFootnote
22 */
23class ReportBaseFootnote extends ReportBaseElement
24{
25    /**
26     * The name of the style for this element
27     *
28     * @var string
29     */
30    public $styleName = '';
31
32    /**
33     * Numbers for the links
34     *
35     * @var int
36     */
37    public $num;
38
39    /**
40     * The text that will be printed with the number
41     *
42     * @var string
43     */
44    public $numText = '';
45
46    /**
47     * Remaining width of a cell
48     *
49     * @var float User unit (points)
50     */
51    public $wrapWidthRemaining;
52
53    /**
54     * Original width of a cell
55     *
56     * @var float User unit (points)
57     */
58    public $wrapWidthCell;
59
60    /** @var string A link */
61    public $addlink;
62
63    /**
64     * Createa an element.
65     *
66     * @param string $style
67     */
68    public function __construct($style = '')
69    {
70        $this->text = '';
71        if (!empty($style)) {
72            $this->styleName = $style;
73        } else {
74            $this->styleName = 'footnote';
75        }
76    }
77
78    /**
79     * Add text.
80     *
81     * @param string $t
82     *
83     * @return void
84     */
85    public function addText(string $t)
86    {
87        $t          = trim($t, "\r\n\t");
88        $t          = str_replace([
89            '<br>',
90            '&nbsp;',
91        ], [
92            "\n",
93            ' ',
94        ], $t);
95        $t          = strip_tags($t);
96        $t          = htmlspecialchars_decode($t);
97        $this->text .= $t;
98    }
99
100    /**
101     * Set the width to wrap text.
102     *
103     * @param float $wrapwidth
104     * @param float $cellwidth
105     *
106     * @return float
107     */
108    public function setWrapWidth(float $wrapwidth, float $cellwidth): float
109    {
110        $this->wrapWidthCell = $cellwidth;
111        if (strpos($this->numText, "\n") !== false) {
112            $this->wrapWidthRemaining = $cellwidth;
113        } else {
114            $this->wrapWidthRemaining = $wrapwidth;
115        }
116
117        return $this->wrapWidthRemaining;
118    }
119
120    /**
121     * Set the number.
122     *
123     * @param int $n
124     *
125     * @return void
126     */
127    public function setNum(int $n): void
128    {
129        $this->num     = $n;
130        $this->numText = $n . ' ';
131    }
132
133    /**
134     * Add a link.
135     *
136     * @param string $a
137     *
138     * @return void
139     */
140    public function setAddlink(string $a)
141    {
142        $this->addlink = $a;
143    }
144}
145