xref: /webtrees/app/Report/ReportBaseCell.php (revision 9320815f1ce8e5a76b792d0fc59d7ba088fe3793)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2021 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 <https://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees\Report;
21
22/**
23 * Class ReportBaseCell
24 */
25class ReportBaseCell extends ReportBaseElement
26{
27    /**
28     * Allows to center or align the text. Possible values are:<ul><li>left or empty string: left align</li><li>center: center align</li><li>right: right align</li><li>justify: justification (default value when $ishtml=false)</li></ul>
29     *
30     * @var string
31     */
32    public $align = '';
33    /**
34     * Whether or not a border should be printed around this box. 0 = no border, 1 = border. Default is 0.
35     * Or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
36     *
37     * @var mixed
38     */
39    public $border;
40    /**
41     * Border color in HTML code
42     *
43     * @var string
44     */
45    public $bocolor;
46    /**
47     * The HTML color code to fill the background of this cell.
48     *
49     * @var string
50     */
51    public $bgcolor;
52    /**
53     * Indicates if the cell background must be painted (1) or transparent (0). Default value: 1.
54     * If no background color is set then it will not be painted
55     *
56     * @var int
57     */
58    public $fill;
59    /**
60     * Cell height DEFAULT 0 (expressed in points)
61     * The starting height of this cell. If the text wraps the height will automatically be adjusted.
62     *
63     * @var float
64     */
65    public $height;
66    /**
67     * Left position in user units (X-position). Default is the current position
68     *
69     * @var mixed
70     */
71    public $left;
72    /**
73     * Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right [DEFAULT]</li><li>1: to the beginning of the next line</li><li>2: below</li></ul>
74     *
75     * @var int
76     */
77    public $newline;
78    /**
79     * The name of the Style that should be used to render the text.
80     *
81     * @var string
82     */
83    public $styleName;
84    /**
85     * Stretch carachter mode: <ul><li>0 = disabled (default)</li><li>1 = horizontal scaling only if necessary</li><li>2 = forced horizontal scaling</li><li>3 = character spacing only if necessary</li><li>4 = forced character spacing</li></ul>
86     *
87     * @var int
88     */
89    public $stretch;
90    /**
91     * Text color in HTML code
92     *
93     * @var string
94     */
95    public $tcolor;
96    /**
97     * Top position in user units (Y-position). Default is the current position
98     *
99     * @var mixed
100     */
101    public $top;
102    /**
103     * URL address
104     *
105     * @var string
106     */
107    public $url;
108    /**
109     * Cell width DEFAULT 0 (expressed in points)
110     * Setting the width to 0 will make it the width from the current location to the right margin.
111     *
112     * @var float
113     */
114    public $width;
115
116    /** @var bool */
117    public $reseth;
118
119    /**
120     * CELL - Element
121     *
122     * @param int    $width   cell width (expressed in points)
123     * @param int    $height  cell height (expressed in points)
124     * @param mixed  $border  Border style
125     * @param string $align   Text alignement
126     * @param string $bgcolor Background color code
127     * @param string $style   The name of the text style
128     * @param int    $ln      Indicates where the current position should go after the call
129     * @param mixed  $top     Y-position
130     * @param mixed  $left    X-position
131     * @param int    $fill    Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
132     * @param int    $stretch Stretch carachter mode
133     * @param string $bocolor Border color
134     * @param string $tcolor  Text color
135     * @param bool   $reseth
136     */
137    public function __construct(
138        int $width,
139        int $height,
140        $border,
141        string $align,
142        string $bgcolor,
143        string $style,
144        int $ln,
145        $top,
146        $left,
147        int $fill,
148        int $stretch,
149        string $bocolor,
150        string $tcolor,
151        bool $reseth
152    ) {
153        $this->align     = $align;
154        $this->border    = $border;
155        $this->bgcolor   = $bgcolor;
156        $this->bocolor   = $bocolor;
157        $this->fill      = $fill;
158        $this->height    = $height;
159        $this->left      = $left;
160        $this->newline   = $ln;
161        $this->styleName = $style;
162        $this->text      = '';
163        $this->tcolor    = $tcolor;
164        $this->top       = $top;
165        $this->url       = '';
166        $this->stretch   = $stretch;
167        $this->width     = $width;
168        $this->reseth    = $reseth;
169    }
170
171    /**
172     * Get the cell height
173     *
174     * @param HtmlRenderer|PdfRenderer $renderer
175     *
176     * @return float
177     */
178    public function getHeight($renderer): float
179    {
180        return $this->height;
181    }
182
183    /**
184     * Sets the current cells URL
185     *
186     * @param string $url The URL address to save
187     *
188     * @return void
189     */
190    public function setUrl($url): void
191    {
192        $this->url = $url;
193    }
194
195    /**
196     * Get the cell width
197     *
198     * @param HtmlRenderer|PdfRenderer $renderer
199     *
200     * @return float|array
201     */
202    public function getWidth($renderer)
203    {
204        return $this->width;
205    }
206}
207