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