From 83d548417dabe2e3b7ac212e28529f3e57093bfc Mon Sep 17 00:00:00 2001 From: Simon Berger Date: Mon, 7 Aug 2017 21:42:22 +0200 Subject: [PATCH 1/4] #1502 | Added o_toUnicode to encrypt fields in this prev content block --- lib/Cpdf.php | 98 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 67 insertions(+), 31 deletions(-) diff --git a/lib/Cpdf.php b/lib/Cpdf.php index d585c0341..fbd2bcec1 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,59 @@ protected function o_font($id, $action, $options = '') return null; } + protected function o_toUnicode($id, $action, $options = '') + { + 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 * @@ -1119,8 +1144,18 @@ protected function o_fontDescendentCID($id, $action, $options = '') $cidSystemInfoId = ++$this->numObj; $this->o_contents($cidSystemInfoId, 'new', 'raw'); $this->objects[$id]['info']['cidSystemInfo'] = $cidSystemInfoId; - $res = "<encrypted) { + $this->encryptInit($id); + $ordering = $this->ARC4($ordering); + $registry = $this->ARC4($registry); + } + + $res = '<objects[$cidSystemInfoId]['c'] = $res; @@ -4455,6 +4490,7 @@ function closeObject() // close the object, as long as there was one open in the first place, which will be indicated by // an objectId on the stack. if ($this->nStack > 0) { + dd($this->stack[$this->nStack]); $this->currentContents = $this->stack[$this->nStack]['c']; $this->currentPage = $this->stack[$this->nStack]['p']; $this->nStack--; From 05d60b24c06e907f38012a530c708e82b36fe33c Mon Sep 17 00:00:00 2001 From: Simon Berger Date: Mon, 7 Aug 2017 21:49:45 +0200 Subject: [PATCH 2/4] #1502 | Added o_cidSystemInfo to encrypt fields in this prev content block --- lib/Cpdf.php | 53 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/lib/Cpdf.php b/lib/Cpdf.php index fbd2bcec1..3d068ddfe 100644 --- a/lib/Cpdf.php +++ b/lib/Cpdf.php @@ -1142,24 +1142,9 @@ 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; - $ordering = '(UCS)'; - $registry = '(Adobe)'; - - if ($this->encrypted) { - $this->encryptInit($id); - $ordering = $this->ARC4($ordering); - $registry = $this->ARC4($registry); - } - - $res = '<objects[$cidSystemInfoId]['c'] = $res; - // and a CID to GID map $cidToGidMapId = ++$this->numObj; $this->o_fontGIDtoCIDMap($cidToGidMapId, 'new', $options); @@ -1228,6 +1213,42 @@ protected function o_fontDescendentCID($id, $action, $options = '') return null; } + protected function o_cidSystemInfo($id, $action, $options = '') + { + 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 .= '< Date: Mon, 7 Aug 2017 21:53:18 +0200 Subject: [PATCH 3/4] #1502 | Added phpdoc and removed unused option parameter --- lib/Cpdf.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/Cpdf.php b/lib/Cpdf.php index 3d068ddfe..2ec44714a 100644 --- a/lib/Cpdf.php +++ b/lib/Cpdf.php @@ -951,7 +951,14 @@ protected function o_font($id, $action, $options = '') return null; } - protected function o_toUnicode($id, $action, $options = '') + /** + * A toUnicode section, needed for unicode fonts + * + * @param $id + * @param $action + * @return null|string + */ + protected function o_toUnicode($id, $action) { switch ($action) { case 'new': @@ -1213,7 +1220,14 @@ protected function o_fontDescendentCID($id, $action, $options = '') return null; } - protected function o_cidSystemInfo($id, $action, $options = '') + /** + * 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': From 9ee94120a8d3d010826f646b89887a74bfc1f31e Mon Sep 17 00:00:00 2001 From: Simon Berger Date: Tue, 29 Aug 2017 20:27:06 +0200 Subject: [PATCH 4/4] removed debug --- lib/Cpdf.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Cpdf.php b/lib/Cpdf.php index 2ec44714a..64e8d2b78 100644 --- a/lib/Cpdf.php +++ b/lib/Cpdf.php @@ -4525,7 +4525,6 @@ function closeObject() // close the object, as long as there was one open in the first place, which will be indicated by // an objectId on the stack. if ($this->nStack > 0) { - dd($this->stack[$this->nStack]); $this->currentContents = $this->stack[$this->nStack]['c']; $this->currentPage = $this->stack[$this->nStack]['p']; $this->nStack--;