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