xref: /webtrees/app/Report/ReportBaseText.php (revision d11be7027e34e3121be11cc025421873364403f9)
1a25f0a04SGreg Roach<?php
23976b470SGreg Roach
3a25f0a04SGreg Roach/**
4a25f0a04SGreg Roach * webtrees: online genealogy
5*d11be702SGreg Roach * Copyright (C) 2023 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
1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
16a25f0a04SGreg Roach */
17fcfa147eSGreg Roach
18e7f56f2aSGreg Roachdeclare(strict_types=1);
19e7f56f2aSGreg Roach
2076692c8bSGreg Roachnamespace Fisharebest\Webtrees\Report;
21a25f0a04SGreg Roach
22dec352c1SGreg Roachuse function str_contains;
23b6f35a76SGreg Roach
24a25f0a04SGreg Roach/**
25a25f0a04SGreg Roach * Class ReportBaseText
26a25f0a04SGreg Roach */
27c1010edaSGreg Roachclass ReportBaseText extends ReportBaseElement
28c1010edaSGreg Roach{
2977bab461SGreg Roach    // Text color in HTML code
3077bab461SGreg Roach    public string $color;
3177bab461SGreg Roach
3277bab461SGreg Roach    // Style name
3377bab461SGreg Roach    public string $styleName;
3477bab461SGreg Roach
3577bab461SGreg Roach    // Remaining width of a cell (points)
3677bab461SGreg Roach    public float $wrapWidthRemaining;
3777bab461SGreg Roach
3877bab461SGreg Roach    // Original width of a cell  (points)
3977bab461SGreg Roach    public float $wrapWidthCell;
40a25f0a04SGreg Roach
41a25f0a04SGreg Roach    /**
42a25f0a04SGreg Roach     * Create a Text class - Base
43a25f0a04SGreg Roach     *
44a25f0a04SGreg Roach     * @param string $style The name of the text style
45a25f0a04SGreg Roach     * @param string $color HTML color code
46a25f0a04SGreg Roach     */
4724f2a3afSGreg Roach    public function __construct(string $style, string $color)
48c1010edaSGreg Roach    {
49a25f0a04SGreg Roach        $this->text               = '';
50a25f0a04SGreg Roach        $this->color              = $color;
5177bab461SGreg Roach        $this->wrapWidthRemaining = 0.0;
52a25f0a04SGreg Roach        $this->styleName          = $style;
53a25f0a04SGreg Roach    }
54a25f0a04SGreg Roach
55a25f0a04SGreg Roach    /**
5676692c8bSGreg Roach     * Set the width for word-wrapping.
5776692c8bSGreg Roach     *
58c21bdddcSGreg Roach     * @param float $wrapwidth
59c21bdddcSGreg Roach     * @param float $cellwidth
60a25f0a04SGreg Roach     *
61589feda3SGreg Roach     * @return float
62a25f0a04SGreg Roach     */
63c21bdddcSGreg Roach    public function setWrapWidth(float $wrapwidth, float $cellwidth): float
64c1010edaSGreg Roach    {
65a25f0a04SGreg Roach        $this->wrapWidthCell = $cellwidth;
66dec352c1SGreg Roach        if (str_contains($this->text, "\n")) {
67a25f0a04SGreg Roach            $this->wrapWidthRemaining = $cellwidth;
68a25f0a04SGreg Roach        } else {
69a25f0a04SGreg Roach            $this->wrapWidthRemaining = $wrapwidth;
70a25f0a04SGreg Roach        }
71a25f0a04SGreg Roach
72a25f0a04SGreg Roach        return $this->wrapWidthRemaining;
73a25f0a04SGreg Roach    }
74a25f0a04SGreg Roach
75a25f0a04SGreg Roach    /**
7676692c8bSGreg Roach     * Get the style name.
7776692c8bSGreg Roach     *
78a25f0a04SGreg Roach     * @return string
79a25f0a04SGreg Roach     */
808f53f488SRico Sonntag    public function getStyleName(): string
81c1010edaSGreg Roach    {
82a25f0a04SGreg Roach        return $this->styleName;
83a25f0a04SGreg Roach    }
84a25f0a04SGreg Roach}
85