xref: /webtrees/app/Report/ReportBaseText.php (revision da83637ca6236094f5a00d6e54530cd25ac7aa0e)
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        return 0;
62    }
63
64    /**
65     * Set the width for word-wrapping.
66     *
67     * @param $wrapwidth
68     * @param $cellwidth
69     *
70     * @return mixed
71     */
72    public function setWrapWidth($wrapwidth, $cellwidth)
73    {
74        $this->wrapWidthCell = $cellwidth;
75        if (strpos($this->text, "\n") !== false) {
76            $this->wrapWidthRemaining = $cellwidth;
77        } else {
78            $this->wrapWidthRemaining = $wrapwidth;
79        }
80
81        return $this->wrapWidthRemaining;
82    }
83
84    /**
85     * Get the style name.
86     *
87     * @return string
88     */
89    public function getStyleName()
90    {
91        return $this->styleName;
92    }
93}
94