xref: /webtrees/app/Report/PdfRenderer.php (revision 0a709a28d2e059f9bb8e972842558806739da9cb)
1b6f35a76SGreg Roach<?php
2b6f35a76SGreg Roach
3b6f35a76SGreg Roach/**
4b6f35a76SGreg Roach * webtrees: online genealogy
589f7189bSGreg Roach * Copyright (C) 2021 webtrees development team
6b6f35a76SGreg Roach * This program is free software: you can redistribute it and/or modify
7b6f35a76SGreg Roach * it under the terms of the GNU General Public License as published by
8b6f35a76SGreg Roach * the Free Software Foundation, either version 3 of the License, or
9b6f35a76SGreg Roach * (at your option) any later version.
10b6f35a76SGreg Roach * This program is distributed in the hope that it will be useful,
11b6f35a76SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12b6f35a76SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13b6f35a76SGreg Roach * GNU General Public License for more details.
14b6f35a76SGreg 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/>.
16b6f35a76SGreg Roach */
17b6f35a76SGreg Roach
18b6f35a76SGreg Roachdeclare(strict_types=1);
19b6f35a76SGreg Roach
20b6f35a76SGreg Roachnamespace Fisharebest\Webtrees\Report;
21b6f35a76SGreg Roach
22b6f35a76SGreg Roachuse Fisharebest\Webtrees\MediaFile;
23b6f35a76SGreg Roachuse Fisharebest\Webtrees\Webtrees;
24f7cf8a15SGreg Roachuse League\Flysystem\FilesystemOperator;
25b6f35a76SGreg Roach
26b6f35a76SGreg Roachuse function count;
27b6f35a76SGreg Roach
28b6f35a76SGreg Roach/**
29b6f35a76SGreg Roach * Class PdfRenderer
30b6f35a76SGreg Roach */
31b6f35a76SGreg Roachclass PdfRenderer extends AbstractRenderer
32b6f35a76SGreg Roach{
33b6f35a76SGreg Roach    /**
34b6f35a76SGreg Roach     * PDF compression - Zlib extension is required
35b6f35a76SGreg Roach     *
36b6f35a76SGreg Roach     * @var bool const
37b6f35a76SGreg Roach     */
38b6f35a76SGreg Roach    private const COMPRESSION = true;
39b6f35a76SGreg Roach
40b6f35a76SGreg Roach    /**
41b6f35a76SGreg Roach     * If true reduce the RAM memory usage by caching temporary data on filesystem (slower).
42b6f35a76SGreg Roach     *
43b6f35a76SGreg Roach     * @var bool const
44b6f35a76SGreg Roach     */
45b6f35a76SGreg Roach    private const DISK_CACHE = false;
46b6f35a76SGreg Roach
47b6f35a76SGreg Roach    /**
48b6f35a76SGreg Roach     * true means that the input text is unicode (PDF)
49b6f35a76SGreg Roach     *
50b6f35a76SGreg Roach     * @var bool const
51b6f35a76SGreg Roach     */
52b6f35a76SGreg Roach    private const UNICODE = true;
53b6f35a76SGreg Roach
54345fcc8aSGreg Roach    // Font sub-setting in TCPDF is slow.
55b6f35a76SGreg Roach    private const SUBSETTING = false;
56b6f35a76SGreg Roach
57345fcc8aSGreg Roach    public TcpdfWrapper $tcpdf;
58b6f35a76SGreg Roach
59345fcc8aSGreg Roach    /** @var array<ReportPdfFootnote> Array of elements in the footer notes */
60345fcc8aSGreg Roach    public array $printedfootnotes = [];
61b6f35a76SGreg Roach
62*0a709a28SGreg Roach    // The last cell height
63345fcc8aSGreg Roach    public float $lastCellHeight = 0.0;
64b6f35a76SGreg Roach
65*0a709a28SGreg Roach    // The largest font size within a TextBox to calculate the height
66345fcc8aSGreg Roach    public float $largestFontHeight = 0.0;
67b6f35a76SGreg Roach
68*0a709a28SGreg Roach    // The last pictures page number
69345fcc8aSGreg Roach    public int $lastpicpage = 0;
70b6f35a76SGreg Roach
71b6f35a76SGreg Roach    /**
72b6f35a76SGreg Roach     * PDF Header -PDF
73b6f35a76SGreg Roach     *
74b6f35a76SGreg Roach     * @return void
75b6f35a76SGreg Roach     */
76b6f35a76SGreg Roach    public function header(): void
77b6f35a76SGreg Roach    {
78b6f35a76SGreg Roach        foreach ($this->headerElements as $element) {
79b6f35a76SGreg Roach            if ($element instanceof ReportBaseElement) {
80b6f35a76SGreg Roach                $element->render($this);
81b6f35a76SGreg Roach            } elseif ($element === 'footnotetexts') {
82b6f35a76SGreg Roach                $this->footnotes();
83b6f35a76SGreg Roach            } elseif ($element === 'addpage') {
84b6f35a76SGreg Roach                $this->newPage();
85b6f35a76SGreg Roach            }
86b6f35a76SGreg Roach        }
87b6f35a76SGreg Roach    }
88b6f35a76SGreg Roach
89b6f35a76SGreg Roach    /**
90b6f35a76SGreg Roach     * PDF Body -PDF
91b6f35a76SGreg Roach     *
92b6f35a76SGreg Roach     * @return void
93b6f35a76SGreg Roach     */
94b6f35a76SGreg Roach    public function body(): void
95b6f35a76SGreg Roach    {
96b6f35a76SGreg Roach        $this->tcpdf->AddPage();
97b6f35a76SGreg Roach
98b6f35a76SGreg Roach        foreach ($this->bodyElements as $key => $element) {
99b6f35a76SGreg Roach            if ($element instanceof ReportBaseElement) {
100b6f35a76SGreg Roach                $element->render($this);
101b6f35a76SGreg Roach            } elseif ($element === 'footnotetexts') {
102b6f35a76SGreg Roach                $this->footnotes();
103b6f35a76SGreg Roach            } elseif ($element === 'addpage') {
104b6f35a76SGreg Roach                $this->newPage();
105b6f35a76SGreg Roach            }
106b6f35a76SGreg Roach        }
107b6f35a76SGreg Roach    }
108b6f35a76SGreg Roach
109b6f35a76SGreg Roach    /**
110b6f35a76SGreg Roach     * PDF Footnotes -PDF
111b6f35a76SGreg Roach     *
112b6f35a76SGreg Roach     * @return void
113b6f35a76SGreg Roach     */
114b6f35a76SGreg Roach    public function footnotes(): void
115b6f35a76SGreg Roach    {
116b6f35a76SGreg Roach        foreach ($this->printedfootnotes as $element) {
11752135727SGreg Roach            if ($this->tcpdf->GetY() + $element->getFootnoteHeight($this) > $this->tcpdf->getPageHeight()) {
118b6f35a76SGreg Roach                $this->tcpdf->AddPage();
119b6f35a76SGreg Roach            }
120b6f35a76SGreg Roach
121b6f35a76SGreg Roach            $element->renderFootnote($this);
122b6f35a76SGreg Roach
123b6f35a76SGreg Roach            if ($this->tcpdf->GetY() > $this->tcpdf->getPageHeight()) {
124b6f35a76SGreg Roach                $this->tcpdf->AddPage();
125b6f35a76SGreg Roach            }
126b6f35a76SGreg Roach        }
127b6f35a76SGreg Roach    }
128b6f35a76SGreg Roach
129b6f35a76SGreg Roach    /**
130b6f35a76SGreg Roach     * PDF Footer -PDF
131b6f35a76SGreg Roach     *
132b6f35a76SGreg Roach     * @return void
133b6f35a76SGreg Roach     */
134b6f35a76SGreg Roach    public function footer(): void
135b6f35a76SGreg Roach    {
136b6f35a76SGreg Roach        foreach ($this->footerElements as $element) {
137b6f35a76SGreg Roach            if ($element instanceof ReportBaseElement) {
138b6f35a76SGreg Roach                $element->render($this);
139b6f35a76SGreg Roach            } elseif ($element === 'footnotetexts') {
140b6f35a76SGreg Roach                $this->footnotes();
141b6f35a76SGreg Roach            } elseif ($element === 'addpage') {
142b6f35a76SGreg Roach                $this->newPage();
143b6f35a76SGreg Roach            }
144b6f35a76SGreg Roach        }
145b6f35a76SGreg Roach    }
146b6f35a76SGreg Roach
147b6f35a76SGreg Roach    /**
148b6f35a76SGreg Roach     * Remove the header.
149b6f35a76SGreg Roach     *
150b6f35a76SGreg Roach     * @param int $index
151b6f35a76SGreg Roach     *
152b6f35a76SGreg Roach     * @return void
153b6f35a76SGreg Roach     */
154b6f35a76SGreg Roach    public function removeHeader(int $index): void
155b6f35a76SGreg Roach    {
156b6f35a76SGreg Roach        unset($this->headerElements[$index]);
157b6f35a76SGreg Roach    }
158b6f35a76SGreg Roach
159b6f35a76SGreg Roach    /**
160b6f35a76SGreg Roach     * Remove the body.
161b6f35a76SGreg Roach     *
162b6f35a76SGreg Roach     * @param int $index
163b6f35a76SGreg Roach     *
164b6f35a76SGreg Roach     * @return void
165b6f35a76SGreg Roach     */
166b6f35a76SGreg Roach    public function removeBody(int $index): void
167b6f35a76SGreg Roach    {
168b6f35a76SGreg Roach        unset($this->bodyElements[$index]);
169b6f35a76SGreg Roach    }
170b6f35a76SGreg Roach
171b6f35a76SGreg Roach    /**
172b6f35a76SGreg Roach     * Remove the footer.
173b6f35a76SGreg Roach     *
174b6f35a76SGreg Roach     * @param int $index
175b6f35a76SGreg Roach     *
176b6f35a76SGreg Roach     * @return void
177b6f35a76SGreg Roach     */
178b6f35a76SGreg Roach    public function removeFooter(int $index): void
179b6f35a76SGreg Roach    {
180b6f35a76SGreg Roach        unset($this->footerElements[$index]);
181b6f35a76SGreg Roach    }
182b6f35a76SGreg Roach
183b6f35a76SGreg Roach    /**
184b6f35a76SGreg Roach     * Clear the Header -PDF
185b6f35a76SGreg Roach     *
186b6f35a76SGreg Roach     * @return void
187b6f35a76SGreg Roach     */
188b6f35a76SGreg Roach    public function clearHeader(): void
189b6f35a76SGreg Roach    {
190b6f35a76SGreg Roach        unset($this->headerElements);
191b6f35a76SGreg Roach        $this->headerElements = [];
192b6f35a76SGreg Roach    }
193b6f35a76SGreg Roach
194b6f35a76SGreg Roach    /**
195b6f35a76SGreg Roach     * Get the currently used style name -PDF
196b6f35a76SGreg Roach     *
197b6f35a76SGreg Roach     * @return string
198b6f35a76SGreg Roach     */
199b6f35a76SGreg Roach    public function getCurrentStyle(): string
200b6f35a76SGreg Roach    {
201b6f35a76SGreg Roach        return $this->currentStyle;
202b6f35a76SGreg Roach    }
203b6f35a76SGreg Roach
204b6f35a76SGreg Roach    /**
205b6f35a76SGreg Roach     * Setup a style for usage -PDF
206b6f35a76SGreg Roach     *
207b6f35a76SGreg Roach     * @param string $s Style name
208b6f35a76SGreg Roach     *
209b6f35a76SGreg Roach     * @return void
210b6f35a76SGreg Roach     */
211b6f35a76SGreg Roach    public function setCurrentStyle(string $s): void
212b6f35a76SGreg Roach    {
213b6f35a76SGreg Roach        $this->currentStyle = $s;
214ceab9748SGreg Roach        $style              = $this->getStyle($s);
215b6f35a76SGreg Roach        $this->tcpdf->SetFont($style['font'], $style['style'], $style['size']);
216b6f35a76SGreg Roach    }
217b6f35a76SGreg Roach
218b6f35a76SGreg Roach    /**
219b6f35a76SGreg Roach     * Get the style -PDF
220b6f35a76SGreg Roach     *
221b6f35a76SGreg Roach     * @param string $s Style name
222b6f35a76SGreg Roach     *
223b6f35a76SGreg Roach     * @return array
224b6f35a76SGreg Roach     */
225b6f35a76SGreg Roach    public function getStyle(string $s): array
226b6f35a76SGreg Roach    {
227ceab9748SGreg Roach        if (!isset($this->styles[$s])) {
228b6f35a76SGreg Roach            $s                = $this->getCurrentStyle();
229ceab9748SGreg Roach            $this->styles[$s] = $s;
230b6f35a76SGreg Roach        }
231b6f35a76SGreg Roach
232ceab9748SGreg Roach        return $this->styles[$s];
233b6f35a76SGreg Roach    }
234b6f35a76SGreg Roach
235b6f35a76SGreg Roach    /**
236b6f35a76SGreg Roach     * Add margin when static horizontal position is used -PDF
237b6f35a76SGreg Roach     * RTL supported
238b6f35a76SGreg Roach     *
239b6f35a76SGreg Roach     * @param float $x Static position
240b6f35a76SGreg Roach     *
241b6f35a76SGreg Roach     * @return float
242b6f35a76SGreg Roach     */
243b6f35a76SGreg Roach    public function addMarginX(float $x): float
244b6f35a76SGreg Roach    {
245b6f35a76SGreg Roach        $m = $this->tcpdf->getMargins();
246b6f35a76SGreg Roach        if ($this->tcpdf->getRTL()) {
247b6f35a76SGreg Roach            $x += $m['right'];
248b6f35a76SGreg Roach        } else {
249b6f35a76SGreg Roach            $x += $m['left'];
250b6f35a76SGreg Roach        }
251b6f35a76SGreg Roach        $this->tcpdf->SetX($x);
252b6f35a76SGreg Roach
253b6f35a76SGreg Roach        return $x;
254b6f35a76SGreg Roach    }
255b6f35a76SGreg Roach
256b6f35a76SGreg Roach    /**
257b6f35a76SGreg Roach     * Get the maximum line width to draw from the curren position -PDF
258b6f35a76SGreg Roach     * RTL supported
259b6f35a76SGreg Roach     *
260b6f35a76SGreg Roach     * @return float
261b6f35a76SGreg Roach     */
262b6f35a76SGreg Roach    public function getMaxLineWidth(): float
263b6f35a76SGreg Roach    {
264b6f35a76SGreg Roach        $m = $this->tcpdf->getMargins();
265b6f35a76SGreg Roach        if ($this->tcpdf->getRTL()) {
26652135727SGreg Roach            return $this->tcpdf->getRemainingWidth() + $m['right'];
267b6f35a76SGreg Roach        }
268b6f35a76SGreg Roach
26952135727SGreg Roach        return $this->tcpdf->getRemainingWidth() + $m['left'];
270b6f35a76SGreg Roach    }
271b6f35a76SGreg Roach
272b6f35a76SGreg Roach    /**
273b6f35a76SGreg Roach     * Get the height of the footnote.
274b6f35a76SGreg Roach     *
275b6f35a76SGreg Roach     * @return float
276b6f35a76SGreg Roach     */
277b6f35a76SGreg Roach    public function getFootnotesHeight(): float
278b6f35a76SGreg Roach    {
279b6f35a76SGreg Roach        $h = 0;
280b6f35a76SGreg Roach        foreach ($this->printedfootnotes as $element) {
281b6f35a76SGreg Roach            $h += $element->getHeight($this);
282b6f35a76SGreg Roach        }
283b6f35a76SGreg Roach
284b6f35a76SGreg Roach        return $h;
285b6f35a76SGreg Roach    }
286b6f35a76SGreg Roach
287b6f35a76SGreg Roach    /**
288b6f35a76SGreg Roach     * Returns the the current font size height -PDF
289b6f35a76SGreg Roach     *
290b6f35a76SGreg Roach     * @return float
291b6f35a76SGreg Roach     */
292b6f35a76SGreg Roach    public function getCurrentStyleHeight(): float
293b6f35a76SGreg Roach    {
294b6f35a76SGreg Roach        if ($this->currentStyle === '') {
295ceab9748SGreg Roach            return $this->default_font_size;
296b6f35a76SGreg Roach        }
297ceab9748SGreg Roach        $style = $this->getStyle($this->currentStyle);
298b6f35a76SGreg Roach
299b6f35a76SGreg Roach        return (float) $style['size'];
300b6f35a76SGreg Roach    }
301b6f35a76SGreg Roach
302b6f35a76SGreg Roach    /**
303b6f35a76SGreg Roach     * Checks the Footnote and numbers them
304b6f35a76SGreg Roach     *
305b6f35a76SGreg Roach     * @param ReportPdfFootnote $footnote
306b6f35a76SGreg Roach     *
307b6f35a76SGreg Roach     * @return ReportPdfFootnote|bool object if already numbered, false otherwise
308b6f35a76SGreg Roach     */
309b6f35a76SGreg Roach    public function checkFootnote(ReportPdfFootnote $footnote)
310b6f35a76SGreg Roach    {
311b6f35a76SGreg Roach        $ct  = count($this->printedfootnotes);
312b6f35a76SGreg Roach        $val = $footnote->getValue();
313b6f35a76SGreg Roach        $i   = 0;
314b6f35a76SGreg Roach        while ($i < $ct) {
315b6f35a76SGreg Roach            if ($this->printedfootnotes[$i]->getValue() == $val) {
316b6f35a76SGreg Roach                // If this footnote already exist then set up the numbers for this object
317b6f35a76SGreg Roach                $footnote->setNum($i + 1);
318b6f35a76SGreg Roach                $footnote->setAddlink((string) ($i + 1));
319b6f35a76SGreg Roach
320b6f35a76SGreg Roach                return $this->printedfootnotes[$i];
321b6f35a76SGreg Roach            }
322b6f35a76SGreg Roach            $i++;
323b6f35a76SGreg Roach        }
324b6f35a76SGreg Roach        // If this Footnote has not been set up yet
325b6f35a76SGreg Roach        $footnote->setNum($ct + 1);
326b6f35a76SGreg Roach        $footnote->setAddlink((string) $this->tcpdf->AddLink());
327b6f35a76SGreg Roach        $this->printedfootnotes[] = $footnote;
328b6f35a76SGreg Roach
329b6f35a76SGreg Roach        return false;
330b6f35a76SGreg Roach    }
331b6f35a76SGreg Roach
332b6f35a76SGreg Roach    /**
333b6f35a76SGreg Roach     * Used this function instead of AddPage()
334b6f35a76SGreg Roach     * This function will make sure that images will not be overwritten
335b6f35a76SGreg Roach     *
336b6f35a76SGreg Roach     * @return void
337b6f35a76SGreg Roach     */
338b6f35a76SGreg Roach    public function newPage(): void
339b6f35a76SGreg Roach    {
340b6f35a76SGreg Roach        if ($this->lastpicpage > $this->tcpdf->getPage()) {
341b6f35a76SGreg Roach            $this->tcpdf->setPage($this->lastpicpage);
342b6f35a76SGreg Roach        }
343b6f35a76SGreg Roach        $this->tcpdf->AddPage();
344b6f35a76SGreg Roach    }
345b6f35a76SGreg Roach
346b6f35a76SGreg Roach    /**
347b6f35a76SGreg Roach     * Add a page if needed -PDF
348b6f35a76SGreg Roach     *
349b6f35a76SGreg Roach     * @param float $height Cell height
350b6f35a76SGreg Roach     *
351b6f35a76SGreg Roach     * @return bool true in case of page break, false otherwise
352b6f35a76SGreg Roach     */
353b6f35a76SGreg Roach    public function checkPageBreakPDF(float $height): bool
354b6f35a76SGreg Roach    {
355b6f35a76SGreg Roach        return $this->tcpdf->checkPageBreak($height);
356b6f35a76SGreg Roach    }
357b6f35a76SGreg Roach
358b6f35a76SGreg Roach    /**
359b6f35a76SGreg Roach     * Returns the remaining width between the current position and margins -PDF
360b6f35a76SGreg Roach     *
361b6f35a76SGreg Roach     * @return float Remaining width
362b6f35a76SGreg Roach     */
363b6f35a76SGreg Roach    public function getRemainingWidthPDF(): float
364b6f35a76SGreg Roach    {
365b6f35a76SGreg Roach        return $this->tcpdf->getRemainingWidth();
366b6f35a76SGreg Roach    }
367b6f35a76SGreg Roach    /**
368b6f35a76SGreg Roach     * PDF Setup - ReportPdf
369b6f35a76SGreg Roach     *
370b6f35a76SGreg Roach     * @return void
371b6f35a76SGreg Roach     */
372b6f35a76SGreg Roach    public function setup(): void
373b6f35a76SGreg Roach    {
374b6f35a76SGreg Roach        parent::setup();
375b6f35a76SGreg Roach
376345fcc8aSGreg Roach        $this->tcpdf = new TcpdfWrapper(
377345fcc8aSGreg Roach            $this->orientation,
378345fcc8aSGreg Roach            self::UNITS,
379345fcc8aSGreg Roach            [$this->page_width, $this->page_height],
380345fcc8aSGreg Roach            self::UNICODE,
381345fcc8aSGreg Roach            'UTF-8',
382345fcc8aSGreg Roach            self::DISK_CACHE
383345fcc8aSGreg Roach        );
384b6f35a76SGreg Roach
385b6f35a76SGreg Roach        $this->tcpdf->SetMargins($this->left_margin, $this->top_margin, $this->right_margin);
386b6f35a76SGreg Roach        $this->tcpdf->setHeaderMargin($this->header_margin);
387b6f35a76SGreg Roach        $this->tcpdf->setFooterMargin($this->footer_margin);
388b6f35a76SGreg Roach        $this->tcpdf->SetAutoPageBreak(true, $this->bottom_margin);
389b6f35a76SGreg Roach        $this->tcpdf->setFontSubsetting(self::SUBSETTING);
390b6f35a76SGreg Roach        $this->tcpdf->SetCompression(self::COMPRESSION);
391b6f35a76SGreg Roach        $this->tcpdf->setRTL($this->rtl);
392b6f35a76SGreg Roach        $this->tcpdf->SetCreator(Webtrees::NAME . ' ' . Webtrees::VERSION);
393b6f35a76SGreg Roach        $this->tcpdf->SetAuthor($this->rauthor);
394b6f35a76SGreg Roach        $this->tcpdf->SetTitle($this->title);
395b6f35a76SGreg Roach        $this->tcpdf->SetSubject($this->rsubject);
396b6f35a76SGreg Roach        $this->tcpdf->SetKeywords($this->rkeywords);
397db9b720fSGreg Roach        $this->tcpdf->SetHeaderData('', 0, $this->title);
398f6351d1fSGreg Roach        $this->tcpdf->setHeaderFont([$this->default_font, '', $this->default_font_size]);
399b6f35a76SGreg Roach
400b6f35a76SGreg Roach        if ($this->show_generated_by) {
401b6f35a76SGreg Roach            // The default style name for Generated by.... is 'genby'
402b6f35a76SGreg Roach            $element = new ReportPdfCell(0, 10, 0, 'C', '', 'genby', 1, ReportBaseElement::CURRENT_POSITION, ReportBaseElement::CURRENT_POSITION, 0, 0, '', '', true);
403b6f35a76SGreg Roach            $element->addText($this->generated_by);
404b6f35a76SGreg Roach            $element->setUrl(Webtrees::URL);
405345fcc8aSGreg Roach            $this->addElementToFooter($element);
406b6f35a76SGreg Roach        }
407b6f35a76SGreg Roach    }
408b6f35a76SGreg Roach
409b6f35a76SGreg Roach    /**
410b6f35a76SGreg Roach     * Run the report.
411b6f35a76SGreg Roach     *
412b6f35a76SGreg Roach     * @return void
413b6f35a76SGreg Roach     */
414b6f35a76SGreg Roach    public function run(): void
415b6f35a76SGreg Roach    {
416b6f35a76SGreg Roach        $this->body();
417b6f35a76SGreg Roach        echo $this->tcpdf->Output('doc.pdf', 'S');
418b6f35a76SGreg Roach    }
419b6f35a76SGreg Roach
420b6f35a76SGreg Roach    /**
421b6f35a76SGreg Roach     * Create a new Cell object.
422b6f35a76SGreg Roach     *
423b6f35a76SGreg Roach     * @param int    $width   cell width (expressed in points)
424b6f35a76SGreg Roach     * @param int    $height  cell height (expressed in points)
425b6f35a76SGreg Roach     * @param mixed  $border  Border style
426b6f35a76SGreg Roach     * @param string $align   Text alignement
427b6f35a76SGreg Roach     * @param string $bgcolor Background color code
428b6f35a76SGreg Roach     * @param string $style   The name of the text style
429b6f35a76SGreg Roach     * @param int    $ln      Indicates where the current position should go after the call
430b6f35a76SGreg Roach     * @param mixed  $top     Y-position
431b6f35a76SGreg Roach     * @param mixed  $left    X-position
432b6f35a76SGreg Roach     * @param int    $fill    Indicates if the cell background must be painted (1) or transparent (0). Default value: 1
433b6f35a76SGreg Roach     * @param int    $stretch Stretch carachter mode
434b6f35a76SGreg Roach     * @param string $bocolor Border color
435b6f35a76SGreg Roach     * @param string $tcolor  Text color
436b6f35a76SGreg Roach     * @param bool   $reseth
437b6f35a76SGreg Roach     *
438b6f35a76SGreg Roach     * @return ReportBaseCell
439b6f35a76SGreg Roach     */
44024f2a3afSGreg Roach    public function createCell(int $width, int $height, $border, string $align, string $bgcolor, string $style, int $ln, $top, $left, int $fill, int $stretch, string $bocolor, string $tcolor, bool $reseth): ReportBaseCell
441b6f35a76SGreg Roach    {
442b6f35a76SGreg Roach        return new ReportPdfCell($width, $height, $border, $align, $bgcolor, $style, $ln, $top, $left, $fill, $stretch, $bocolor, $tcolor, $reseth);
443b6f35a76SGreg Roach    }
444b6f35a76SGreg Roach
445b6f35a76SGreg Roach    /**
446b6f35a76SGreg Roach     * Create a new TextBox object.
447b6f35a76SGreg Roach     *
448b6f35a76SGreg Roach     * @param float  $width   Text box width
449b6f35a76SGreg Roach     * @param float  $height  Text box height
450b6f35a76SGreg Roach     * @param bool   $border
451b6f35a76SGreg Roach     * @param string $bgcolor Background color code in HTML
452b6f35a76SGreg Roach     * @param bool   $newline
453b6f35a76SGreg Roach     * @param float  $left
454b6f35a76SGreg Roach     * @param float  $top
455b6f35a76SGreg Roach     * @param bool   $pagecheck
456b6f35a76SGreg Roach     * @param string $style
457b6f35a76SGreg Roach     * @param bool   $fill
458b6f35a76SGreg Roach     * @param bool   $padding
459b6f35a76SGreg Roach     * @param bool   $reseth
460b6f35a76SGreg Roach     *
461b6f35a76SGreg Roach     * @return ReportBaseTextbox
462b6f35a76SGreg Roach     */
463b6f35a76SGreg Roach    public function createTextBox(
464b6f35a76SGreg Roach        float $width,
465b6f35a76SGreg Roach        float $height,
466b6f35a76SGreg Roach        bool $border,
467b6f35a76SGreg Roach        string $bgcolor,
468b6f35a76SGreg Roach        bool $newline,
469b6f35a76SGreg Roach        float $left,
470b6f35a76SGreg Roach        float $top,
471b6f35a76SGreg Roach        bool $pagecheck,
472b6f35a76SGreg Roach        string $style,
473b6f35a76SGreg Roach        bool $fill,
474b6f35a76SGreg Roach        bool $padding,
475b6f35a76SGreg Roach        bool $reseth
476b6f35a76SGreg Roach    ): ReportBaseTextbox {
477b6f35a76SGreg Roach        return new ReportPdfTextBox($width, $height, $border, $bgcolor, $newline, $left, $top, $pagecheck, $style, $fill, $padding, $reseth);
478b6f35a76SGreg Roach    }
479b6f35a76SGreg Roach
480b6f35a76SGreg Roach    /**
481b6f35a76SGreg Roach     * Create a text element.
482b6f35a76SGreg Roach     *
483b6f35a76SGreg Roach     * @param string $style
484b6f35a76SGreg Roach     * @param string $color
485b6f35a76SGreg Roach     *
486b6f35a76SGreg Roach     * @return ReportBaseText
487b6f35a76SGreg Roach     */
488b6f35a76SGreg Roach    public function createText(string $style, string $color): ReportBaseText
489b6f35a76SGreg Roach    {
490b6f35a76SGreg Roach        return new ReportPdfText($style, $color);
491b6f35a76SGreg Roach    }
492b6f35a76SGreg Roach
493b6f35a76SGreg Roach    /**
494b6f35a76SGreg Roach     * Create a new Footnote object.
495b6f35a76SGreg Roach     *
496b6f35a76SGreg Roach     * @param string $style Style name
497b6f35a76SGreg Roach     *
498b6f35a76SGreg Roach     * @return ReportBaseFootnote
499b6f35a76SGreg Roach     */
50024f2a3afSGreg Roach    public function createFootnote(string $style): ReportBaseFootnote
501b6f35a76SGreg Roach    {
502b6f35a76SGreg Roach        return new ReportPdfFootnote($style);
503b6f35a76SGreg Roach    }
504b6f35a76SGreg Roach
505b6f35a76SGreg Roach    /**
506b6f35a76SGreg Roach     * Create a new image object.
507b6f35a76SGreg Roach     *
508b6f35a76SGreg Roach     * @param string $file  Filename
509b6f35a76SGreg Roach     * @param float  $x
510b6f35a76SGreg Roach     * @param float  $y
511b6f35a76SGreg Roach     * @param float  $w     Image width
512b6f35a76SGreg Roach     * @param float  $h     Image height
513b6f35a76SGreg Roach     * @param string $align L:left, C:center, R:right or empty to use x/y
514b6f35a76SGreg Roach     * @param string $ln    T:same line, N:next line
515b6f35a76SGreg Roach     *
516b6f35a76SGreg Roach     * @return ReportBaseImage
517b6f35a76SGreg Roach     */
518b6f35a76SGreg Roach    public function createImage(string $file, float $x, float $y, float $w, float $h, string $align, string $ln): ReportBaseImage
519b6f35a76SGreg Roach    {
520b6f35a76SGreg Roach        return new ReportPdfImage($file, $x, $y, $w, $h, $align, $ln);
521b6f35a76SGreg Roach    }
522b6f35a76SGreg Roach
523b6f35a76SGreg Roach    /**
524b6f35a76SGreg Roach     * Create a new image object from Media Object.
525b6f35a76SGreg Roach     *
526b6f35a76SGreg Roach     * @param MediaFile          $media_file
527b6f35a76SGreg Roach     * @param float              $x
528b6f35a76SGreg Roach     * @param float              $y
529b6f35a76SGreg Roach     * @param float              $w     Image width
530b6f35a76SGreg Roach     * @param float              $h     Image height
531b6f35a76SGreg Roach     * @param string             $align L:left, C:center, R:right or empty to use x/y
532b6f35a76SGreg Roach     * @param string             $ln    T:same line, N:next line
533f7cf8a15SGreg Roach     * @param FilesystemOperator $data_filesystem
534b6f35a76SGreg Roach     *
535b6f35a76SGreg Roach     * @return ReportBaseImage
536b6f35a76SGreg Roach     */
537b6f35a76SGreg Roach    public function createImageFromObject(
538b6f35a76SGreg Roach        MediaFile $media_file,
539b6f35a76SGreg Roach        float $x,
540b6f35a76SGreg Roach        float $y,
541b6f35a76SGreg Roach        float $w,
542b6f35a76SGreg Roach        float $h,
543b6f35a76SGreg Roach        string $align,
544b6f35a76SGreg Roach        string $ln,
545f7cf8a15SGreg Roach        FilesystemOperator $data_filesystem
546b6f35a76SGreg Roach    ): ReportBaseImage {
547b6f35a76SGreg Roach        return new ReportPdfImage('@' . $media_file->fileContents($data_filesystem), $x, $y, $w, $h, $align, $ln);
548b6f35a76SGreg Roach    }
549b6f35a76SGreg Roach
550b6f35a76SGreg Roach    /**
551b6f35a76SGreg Roach     * Create a line.
552b6f35a76SGreg Roach     *
553b6f35a76SGreg Roach     * @param float $x1
554b6f35a76SGreg Roach     * @param float $y1
555b6f35a76SGreg Roach     * @param float $x2
556b6f35a76SGreg Roach     * @param float $y2
557b6f35a76SGreg Roach     *
558b6f35a76SGreg Roach     * @return ReportBaseLine
559b6f35a76SGreg Roach     */
560b6f35a76SGreg Roach    public function createLine(float $x1, float $y1, float $x2, float $y2): ReportBaseLine
561b6f35a76SGreg Roach    {
562b6f35a76SGreg Roach        return new ReportPdfLine($x1, $y1, $x2, $y2);
563b6f35a76SGreg Roach    }
564b6f35a76SGreg Roach}
565