1<?php
2
3namespace Mpdf\Conversion;
4
5use Mpdf\Mpdf;
6use Mpdf\Utils\UtfString;
7
8class DecToOther
9{
10
11	/**
12	 * @var \Mpdf\Mpdf
13	 */
14	private $mpdf;
15
16	public function __construct(Mpdf $mpdf)
17	{
18		$this->mpdf = $mpdf;
19	}
20
21	public function convert($num, $cp, $check = true)
22	{
23		// From printlistbuffer: font is set, so check if character is available
24		// From docPageNum: font is not set, so no check
25		$nstr = (string) $num;
26		$rnum = '';
27		$len = strlen($nstr);
28
29		for ($i = 0; $i < $len; $i++) {
30			if (!$check || $this->mpdf->_charDefined($this->mpdf->CurrentFont['cw'], $cp + ((int) $nstr[$i]))) {
31				$rnum .= UtfString::code2utf($cp + (int) $nstr[$i]);
32			} else {
33				$rnum .= $nstr[$i];
34			}
35		}
36
37		return $rnum;
38	}
39
40	/**
41	 * @param string $script
42	 * @return int
43	 */
44	public function getCodePage($script)
45	{
46		$codePages = [
47			'arabic-indic' => 0x0660,
48			'persian' => 0x06F0,
49			'urdu' => 0x06F0,
50			'bengali' => 0x09E6,
51			'devanagari' => 0x0966,
52			'gujarati' => 0x0AE6,
53			'gurmukhi' => 0x0A66,
54			'kannada' => 0x0CE6,
55			'malayalam' => 0x0D66,
56			'oriya' => 0x0B66,
57			'telugu' => 0x0C66,
58			'tamil' => 0x0BE6,
59			'thai' => 0x0E50,
60			'khmer' => 0x17E0,
61			'cambodian' => 0x17E0,
62			'lao' => 0x0ED0,
63			'myanmar' => 0x1040
64		];
65
66		return isset($codePages[$script]) ? $codePages[$script] : 0;
67	}
68
69}
70