Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
dompdf#1502 | Added o_toUnicode to encrypt fields in this prev conten…
Browse files Browse the repository at this point in the history
…t block
  • Loading branch information
simonberger authored and bsweeney committed Sep 14, 2017
1 parent 39cf890 commit 83d5484
Showing 1 changed file with 67 additions and 31 deletions.
98 changes: 67 additions & 31 deletions lib/Cpdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <<<EOT
/CIDInit /ProcSet findresource begin
12 dict begin
begincmap
/CIDSystemInfo
<</Registry (Adobe)
/Ordering (UCS)
/Supplement 0
>> def
/CMapName /Adobe-Identity-UCS def
/CMapType 2 def
1 begincodespacerange
<0000> <FFFF>
endcodespacerange
1 beginbfrange
<0000> <FFFF> <0000>
endbfrange
endcmap
CMapName currentdict /CMap defineresource pop
end
end
EOT;

$res = "<</Length " . mb_strlen($stream, '8bit') . " >>\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;
Expand Down Expand Up @@ -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 = <<<EOT
/CIDInit /ProcSet findresource begin
12 dict begin
begincmap
/CIDSystemInfo
<</Registry $registry
/Ordering $ordering
/Supplement 0
>> def
/CMapName /Adobe-Identity-UCS def
/CMapType 2 def
1 begincodespacerange
<0000> <FFFF>
endcodespacerange
1 beginbfrange
<0000> <FFFF> <0000>
endbfrange
endcmap
CMapName currentdict /CMap defineresource pop
end
end
EOT;

$res = "\n$id 0 obj\n";
$res .= "<</Length " . mb_strlen($stream, '8bit') . " >>\n";
$res .= "stream\n" . $stream . "\nendstream" . "\nendobj";;

return $res;
}

return null;
}

/**
* a font descriptor, needed for including additional fonts
*
Expand Down Expand Up @@ -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 = "<</Registry (Adobe)\n"; // A string identifying an issuer of character collections
$res .= "/Ordering (UCS)\n"; // A string that uniquely names a character collection issued by a specific registry

$ordering = '(UCS)';
$registry = '(Adobe)';

if ($this->encrypted) {
$this->encryptInit($id);
$ordering = $this->ARC4($ordering);
$registry = $this->ARC4($registry);
}

$res = '<</Registry ' . $registry . "\n"; // A string identifying an issuer of character collections
$res .= '/Ordering ' . $ordering . "\n"; // A string that uniquely names a character collection issued by a specific registry
$res .= "/Supplement 0\n"; // The supplement number of the character collection.
$res .= ">>";
$this->objects[$cidSystemInfoId]['c'] = $res;
Expand Down Expand Up @@ -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--;
Expand Down

0 comments on commit 83d5484

Please sign in to comment.