diff --git a/lib/Cpdf.php b/lib/Cpdf.php index d585c0341..64e8d2b78 100644 --- a/lib/Cpdf.php +++ b/lib/Cpdf.php @@ -855,37 +855,9 @@ protected function o_font($id, $action, $options = '') // transform FPDF to TCPDF (http://tcpdf.sourceforge.net/) $toUnicodeId = ++$this->numObj; - $this->o_contents($toUnicodeId, 'new', 'raw'); + $this->o_toUnicode($toUnicodeId, 'new'); $this->objects[$id]['info']['toUnicode'] = $toUnicodeId; - $stream = <<> def -/CMapName /Adobe-Identity-UCS def -/CMapType 2 def -1 begincodespacerange -<0000> -endcodespacerange -1 beginbfrange -<0000> <0000> -endbfrange -endcmap -CMapName currentdict /CMap defineresource pop -end -end -EOT; - - $res = "<>\n"; - $res .= "stream\n" . $stream . "\nendstream"; - - $this->objects[$toUnicodeId]['c'] = $res; - $cidFontId = ++$this->numObj; $this->o_fontDescendentCID($cidFontId, 'new', $options); $this->objects[$id]['info']['cidFont'] = $cidFontId; @@ -979,6 +951,66 @@ protected function o_font($id, $action, $options = '') return null; } + /** + * A toUnicode section, needed for unicode fonts + * + * @param $id + * @param $action + * @return null|string + */ + protected function o_toUnicode($id, $action) + { + switch ($action) { + case 'new': + $this->objects[$id] = array( + 't' => 'toUnicode' + ); + break; + case 'add': + break; + case 'out': + $ordering = '(UCS)'; + $registry = '(Adobe)'; + + if ($this->encrypted) { + $this->encryptInit($id); + $ordering = $this->ARC4($ordering); + $registry = $this->ARC4($registry); + } + + $stream = <<> def +/CMapName /Adobe-Identity-UCS def +/CMapType 2 def +1 begincodespacerange +<0000> +endcodespacerange +1 beginbfrange +<0000> <0000> +endbfrange +endcmap +CMapName currentdict /CMap defineresource pop +end +end +EOT; + + $res = "\n$id 0 obj\n"; + $res .= "<>\n"; + $res .= "stream\n" . $stream . "\nendstream" . "\nendobj";; + + return $res; + } + + return null; + } + /** * a font descriptor, needed for including additional fonts * @@ -1117,13 +1149,8 @@ protected function o_fontDescendentCID($id, $action, $options = '') // we need a CID system info section $cidSystemInfoId = ++$this->numObj; - $this->o_contents($cidSystemInfoId, 'new', 'raw'); + $this->o_cidSystemInfo($cidSystemInfoId, 'new'); $this->objects[$id]['info']['cidSystemInfo'] = $cidSystemInfoId; - $res = "<objects[$cidSystemInfoId]['c'] = $res; // and a CID to GID map $cidToGidMapId = ++$this->numObj; @@ -1193,6 +1220,49 @@ protected function o_fontDescendentCID($id, $action, $options = '') return null; } + /** + * CID system info section, needed for unicode fonts + * + * @param $id + * @param $action + * @return null|string + */ + protected function o_cidSystemInfo($id, $action) + { + switch ($action) { + case 'new': + $this->objects[$id] = array( + 't' => 'cidSystemInfo' + ); + break; + case 'add': + break; + case 'out': + $ordering = '(UCS)'; + $registry = '(Adobe)'; + + if ($this->encrypted) { + $this->encryptInit($id); + $ordering = $this->ARC4($ordering); + $registry = $this->ARC4($registry); + } + + + $res = "\n$id 0 obj\n"; + + $res .= '<