xref: /webtrees/app/Report/ReportBaseText.php (revision dec352c1d7404cdd35c9b1a1b5d97f29e7c4ebb5)
1a25f0a04SGreg Roach<?php
23976b470SGreg Roach
3a25f0a04SGreg Roach/**
4a25f0a04SGreg Roach * webtrees: online genealogy
5*dec352c1SGreg Roach * Copyright (C) 2020 webtrees development team
6a25f0a04SGreg Roach * This program is free software: you can redistribute it and/or modify
7a25f0a04SGreg Roach * it under the terms of the GNU General Public License as published by
8a25f0a04SGreg Roach * the Free Software Foundation, either version 3 of the License, or
9a25f0a04SGreg Roach * (at your option) any later version.
10a25f0a04SGreg Roach * This program is distributed in the hope that it will be useful,
11a25f0a04SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12a25f0a04SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13a25f0a04SGreg Roach * GNU General Public License for more details.
14a25f0a04SGreg Roach * You should have received a copy of the GNU General Public License
15a25f0a04SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
16a25f0a04SGreg Roach */
17fcfa147eSGreg Roach
18e7f56f2aSGreg Roachdeclare(strict_types=1);
19e7f56f2aSGreg Roach
2076692c8bSGreg Roachnamespace Fisharebest\Webtrees\Report;
21a25f0a04SGreg Roach
22*dec352c1SGreg Roachuse function str_contains;
23b6f35a76SGreg Roach
24a25f0a04SGreg Roach/**
25a25f0a04SGreg Roach * Class ReportBaseText
26a25f0a04SGreg Roach */
27c1010edaSGreg Roachclass ReportBaseText extends ReportBaseElement
28c1010edaSGreg Roach{
29a25f0a04SGreg Roach    /**
30a25f0a04SGreg Roach     * Text color in HTML code
31a25f0a04SGreg Roach     *
32a25f0a04SGreg Roach     * @var string
33a25f0a04SGreg Roach     */
34a25f0a04SGreg Roach    public $color;
35a25f0a04SGreg Roach    /**
36a25f0a04SGreg Roach     * Style name
37a25f0a04SGreg Roach     *
38a25f0a04SGreg Roach     * @var string
39a25f0a04SGreg Roach     */
40a25f0a04SGreg Roach    public $styleName;
41a25f0a04SGreg Roach    /**
42a25f0a04SGreg Roach     * Remaining width of a cel
43a25f0a04SGreg Roach     *
44589feda3SGreg Roach     * @var float User unit (points)
45a25f0a04SGreg Roach     */
46a25f0a04SGreg Roach    public $wrapWidthRemaining;
47a25f0a04SGreg Roach    /**
48a25f0a04SGreg Roach     * Original width of a cell
49a25f0a04SGreg Roach     *
50589feda3SGreg Roach     * @var float User unit (points)
51a25f0a04SGreg Roach     */
52a25f0a04SGreg Roach    public $wrapWidthCell;
53a25f0a04SGreg Roach
54a25f0a04SGreg Roach    /**
55a25f0a04SGreg Roach     * Create a Text class - Base
56a25f0a04SGreg Roach     *
57a25f0a04SGreg Roach     * @param string $style The name of the text style
58a25f0a04SGreg Roach     * @param string $color HTML color code
59a25f0a04SGreg Roach     */
60c1010edaSGreg Roach    public function __construct($style, $color)
61c1010edaSGreg Roach    {
62a25f0a04SGreg Roach        $this->text               = '';
63a25f0a04SGreg Roach        $this->color              = $color;
64a25f0a04SGreg Roach        $this->wrapWidthRemaining = 0;
65a25f0a04SGreg Roach        $this->styleName          = $style;
66a25f0a04SGreg Roach    }
67a25f0a04SGreg Roach
68a25f0a04SGreg Roach    /**
6976692c8bSGreg Roach     * Set the width for word-wrapping.
7076692c8bSGreg Roach     *
71c21bdddcSGreg Roach     * @param float $wrapwidth
72c21bdddcSGreg Roach     * @param float $cellwidth
73a25f0a04SGreg Roach     *
74589feda3SGreg Roach     * @return float
75a25f0a04SGreg Roach     */
76c21bdddcSGreg Roach    public function setWrapWidth(float $wrapwidth, float $cellwidth): float
77c1010edaSGreg Roach    {
78a25f0a04SGreg Roach        $this->wrapWidthCell = $cellwidth;
79*dec352c1SGreg Roach        if (str_contains($this->text, "\n")) {
80a25f0a04SGreg Roach            $this->wrapWidthRemaining = $cellwidth;
81a25f0a04SGreg Roach        } else {
82a25f0a04SGreg Roach            $this->wrapWidthRemaining = $wrapwidth;
83a25f0a04SGreg Roach        }
84a25f0a04SGreg Roach
85a25f0a04SGreg Roach        return $this->wrapWidthRemaining;
86a25f0a04SGreg Roach    }
87a25f0a04SGreg Roach
88a25f0a04SGreg Roach    /**
8976692c8bSGreg Roach     * Get the style name.
9076692c8bSGreg Roach     *
91a25f0a04SGreg Roach     * @return string
92a25f0a04SGreg Roach     */
938f53f488SRico Sonntag    public function getStyleName(): string
94c1010edaSGreg Roach    {
95a25f0a04SGreg Roach        return $this->styleName;
96a25f0a04SGreg Roach    }
97a25f0a04SGreg Roach}
98