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