xref: /webtrees/app/Report/ReportBaseFootnote.php (revision 6c98ae6b812cafb873e62ab73fbb6c86ae009481)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2023 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 <https://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees\Report;
21
22use function str_contains;
23
24/**
25 * Class ReportBaseFootnote
26 */
27class ReportBaseFootnote extends ReportBaseElement
28{
29    // The name of the style for this element
30    public string $styleName = '';
31
32    // Numbers for the links
33    public int $num;
34
35    // The text that will be printed with the number
36    public string $numText = '';
37
38    // Remaining width of a cell
39    public float $wrapWidthRemaining;
40
41    // Original width of a cell (points)
42    public float $wrapWidthCell;
43
44    // A link
45    public string $addlink;
46
47    /**
48     * Create an element.
49     *
50     * @param string $style
51     */
52    public function __construct(string $style = '')
53    {
54        $this->text = '';
55        if ($style !== '') {
56            $this->styleName = $style;
57        } else {
58            $this->styleName = 'footnote';
59        }
60    }
61
62    /**
63     * Set the width to wrap text.
64     *
65     * @param float $wrapwidth
66     * @param float $cellwidth
67     *
68     * @return float
69     */
70    public function setWrapWidth(float $wrapwidth, float $cellwidth): float
71    {
72        $this->wrapWidthCell = $cellwidth;
73        if (str_contains($this->numText, "\n")) {
74            $this->wrapWidthRemaining = $cellwidth;
75        } else {
76            $this->wrapWidthRemaining = $wrapwidth;
77        }
78
79        return $this->wrapWidthRemaining;
80    }
81
82    /**
83     * Set the number.
84     *
85     * @param int $n
86     *
87     * @return void
88     */
89    public function setNum(int $n): void
90    {
91        $this->num     = $n;
92        $this->numText = $n . ' ';
93    }
94
95    /**
96     * Add a link.
97     *
98     * @param string $a
99     *
100     * @return void
101     */
102    public function setAddlink(string $a): void
103    {
104        $this->addlink = $a;
105    }
106}
107