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