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