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