1<?php
2
3namespace Mpdf\Writer;
4
5use Mpdf\Strict;
6use Mpdf\Mpdf;
7
8final class FormWriter
9{
10
11	use Strict;
12
13	/**
14	 * @var \Mpdf\Mpdf
15	 */
16	private $mpdf;
17
18	/**
19	 * @var \Mpdf\Writer\BaseWriter
20	 */
21	private $writer;
22
23	public function __construct(Mpdf $mpdf, BaseWriter $writer)
24	{
25		$this->mpdf = $mpdf;
26		$this->writer = $writer;
27	}
28
29	public function writeFormObjects() // _putformobjects
30	{
31		foreach ($this->mpdf->formobjects as $file => $info) {
32
33			$this->writer->object();
34
35			$this->mpdf->formobjects[$file]['n'] = $this->mpdf->n;
36
37			$this->writer->write('<</Type /XObject');
38			$this->writer->write('/Subtype /Form');
39			$this->writer->write('/Group ' . ($this->mpdf->n + 1) . ' 0 R');
40			$this->writer->write('/BBox [' . $info['x'] . ' ' . $info['y'] . ' ' . ($info['w'] + $info['x']) . ' ' . ($info['h'] + $info['y']) . ']');
41
42			if ($this->mpdf->compress) {
43				$this->writer->write('/Filter /FlateDecode');
44			}
45
46			$data = $this->mpdf->compress ? gzcompress($info['data']) : $info['data'];
47			$this->writer->write('/Length ' . strlen($data) . '>>');
48			$this->writer->stream($data);
49
50			unset($this->mpdf->formobjects[$file]['data']);
51
52			$this->writer->write('endobj');
53
54			// Required for SVG transparency (opacity) to work
55			$this->writer->object();
56			$this->writer->write('<</Type /Group');
57			$this->writer->write('/S /Transparency');
58			$this->writer->write('>>');
59			$this->writer->write('endobj');
60		}
61	}
62}
63