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