xref: /webtrees/app/Report/ReportBaseText.php (revision fcfa147e10aaa6c7ff580c29bd6e5b88666befc1)
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 ReportBaseText
24 */
25class ReportBaseText extends ReportBaseElement
26{
27    /**
28     * Text color in HTML code
29     *
30     * @var string
31     */
32    public $color;
33    /**
34     * Style name
35     *
36     * @var string
37     */
38    public $styleName;
39    /**
40     * Remaining width of a cel
41     *
42     * @var float User unit (points)
43     */
44    public $wrapWidthRemaining;
45    /**
46     * Original width of a cell
47     *
48     * @var float User unit (points)
49     */
50    public $wrapWidthCell;
51
52    /**
53     * Create a Text class - Base
54     *
55     * @param string $style The name of the text style
56     * @param string $color HTML color code
57     */
58    public function __construct($style, $color)
59    {
60        $this->text               = '';
61        $this->color              = $color;
62        $this->wrapWidthRemaining = 0;
63        $this->styleName          = $style;
64    }
65
66    /**
67     * Set the width for word-wrapping.
68     *
69     * @param float $wrapwidth
70     * @param float $cellwidth
71     *
72     * @return float
73     */
74    public function setWrapWidth(float $wrapwidth, float $cellwidth): float
75    {
76        $this->wrapWidthCell = $cellwidth;
77        if (strpos($this->text, "\n") !== false) {
78            $this->wrapWidthRemaining = $cellwidth;
79        } else {
80            $this->wrapWidthRemaining = $wrapwidth;
81        }
82
83        return $this->wrapWidthRemaining;
84    }
85
86    /**
87     * Get the style name.
88     *
89     * @return string
90     */
91    public function getStyleName(): string
92    {
93        return $this->styleName;
94    }
95}
96