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