1<?php
2
3namespace Mpdf\Tag;
4
5class Columns extends Tag
6{
7	/**
8	 * @param string $tag
9	 * @return \Mpdf\Tag\Tag
10	 */
11	private function getTagInstance($tag)
12	{
13		$className = \Mpdf\Tag::getTagClassName($tag);
14		if (class_exists($className)) {
15			return new $className(
16				$this->mpdf,
17				$this->cache,
18				$this->cssManager,
19				$this->form,
20				$this->otl,
21				$this->tableOfContents,
22				$this->sizeConverter,
23				$this->colorConverter,
24				$this->imageProcessor,
25				$this->languageToFont
26			);
27		}
28
29		return null;
30	}
31
32	public function open($attr, &$ahtml, &$ihtml)
33	{
34		if (isset($attr['COLUMN-COUNT']) && ($attr['COLUMN-COUNT'] || $attr['COLUMN-COUNT'] === '0')) {
35			// Close any open block tags
36			for ($b = $this->mpdf->blklvl; $b > 0; $b--) {
37				if ($t = $this->getTagInstance($this->mpdf->blk[$b]['tag'])) {
38					$t->close($ahtml, $ihtml);
39				}
40			}
41			if (!empty($this->mpdf->textbuffer)) { //Output previously buffered content
42				$this->mpdf->printbuffer($this->mpdf->textbuffer);
43				$this->mpdf->textbuffer = [];
44			}
45
46			if (!empty($attr['VALIGN'])) {
47				if ($attr['VALIGN'] === 'J') {
48					$valign = 'J';
49				} else {
50					$valign = $this->getAlign($attr['VALIGN']);
51				}
52			} else {
53				$valign = '';
54			}
55			if (!empty($attr['COLUMN-GAP'])) {
56				$this->mpdf->SetColumns($attr['COLUMN-COUNT'], $valign, $attr['COLUMN-GAP']);
57			} else {
58				$this->mpdf->SetColumns($attr['COLUMN-COUNT'], $valign);
59			}
60		}
61		$this->mpdf->ignorefollowingspaces = true;
62	}
63
64	public function close(&$ahtml, &$ihtml)
65	{
66	}
67}
68