Skip to content

Commit 83d5484

Browse files
simonbergerbsweeney
authored andcommitted
dompdf#1502 | Added o_toUnicode to encrypt fields in this prev content block
1 parent 39cf890 commit 83d5484

File tree

1 file changed

+67
-31
lines changed

1 file changed

+67
-31
lines changed

lib/Cpdf.php

Lines changed: 67 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -855,37 +855,9 @@ protected function o_font($id, $action, $options = '')
855855
// transform FPDF to TCPDF (http://tcpdf.sourceforge.net/)
856856

857857
$toUnicodeId = ++$this->numObj;
858-
$this->o_contents($toUnicodeId, 'new', 'raw');
858+
$this->o_toUnicode($toUnicodeId, 'new');
859859
$this->objects[$id]['info']['toUnicode'] = $toUnicodeId;
860860

861-
$stream = <<<EOT
862-
/CIDInit /ProcSet findresource begin
863-
12 dict begin
864-
begincmap
865-
/CIDSystemInfo
866-
<</Registry (Adobe)
867-
/Ordering (UCS)
868-
/Supplement 0
869-
>> def
870-
/CMapName /Adobe-Identity-UCS def
871-
/CMapType 2 def
872-
1 begincodespacerange
873-
<0000> <FFFF>
874-
endcodespacerange
875-
1 beginbfrange
876-
<0000> <FFFF> <0000>
877-
endbfrange
878-
endcmap
879-
CMapName currentdict /CMap defineresource pop
880-
end
881-
end
882-
EOT;
883-
884-
$res = "<</Length " . mb_strlen($stream, '8bit') . " >>\n";
885-
$res .= "stream\n" . $stream . "\nendstream";
886-
887-
$this->objects[$toUnicodeId]['c'] = $res;
888-
889861
$cidFontId = ++$this->numObj;
890862
$this->o_fontDescendentCID($cidFontId, 'new', $options);
891863
$this->objects[$id]['info']['cidFont'] = $cidFontId;
@@ -979,6 +951,59 @@ protected function o_font($id, $action, $options = '')
979951
return null;
980952
}
981953

954+
protected function o_toUnicode($id, $action, $options = '')
955+
{
956+
switch ($action) {
957+
case 'new':
958+
$this->objects[$id] = array(
959+
't' => 'toUnicode'
960+
);
961+
break;
962+
case 'add':
963+
break;
964+
case 'out':
965+
$ordering = '(UCS)';
966+
$registry = '(Adobe)';
967+
968+
if ($this->encrypted) {
969+
$this->encryptInit($id);
970+
$ordering = $this->ARC4($ordering);
971+
$registry = $this->ARC4($registry);
972+
}
973+
974+
$stream = <<<EOT
975+
/CIDInit /ProcSet findresource begin
976+
12 dict begin
977+
begincmap
978+
/CIDSystemInfo
979+
<</Registry $registry
980+
/Ordering $ordering
981+
/Supplement 0
982+
>> def
983+
/CMapName /Adobe-Identity-UCS def
984+
/CMapType 2 def
985+
1 begincodespacerange
986+
<0000> <FFFF>
987+
endcodespacerange
988+
1 beginbfrange
989+
<0000> <FFFF> <0000>
990+
endbfrange
991+
endcmap
992+
CMapName currentdict /CMap defineresource pop
993+
end
994+
end
995+
EOT;
996+
997+
$res = "\n$id 0 obj\n";
998+
$res .= "<</Length " . mb_strlen($stream, '8bit') . " >>\n";
999+
$res .= "stream\n" . $stream . "\nendstream" . "\nendobj";;
1000+
1001+
return $res;
1002+
}
1003+
1004+
return null;
1005+
}
1006+
9821007
/**
9831008
* a font descriptor, needed for including additional fonts
9841009
*
@@ -1119,8 +1144,18 @@ protected function o_fontDescendentCID($id, $action, $options = '')
11191144
$cidSystemInfoId = ++$this->numObj;
11201145
$this->o_contents($cidSystemInfoId, 'new', 'raw');
11211146
$this->objects[$id]['info']['cidSystemInfo'] = $cidSystemInfoId;
1122-
$res = "<</Registry (Adobe)\n"; // A string identifying an issuer of character collections
1123-
$res .= "/Ordering (UCS)\n"; // A string that uniquely names a character collection issued by a specific registry
1147+
1148+
$ordering = '(UCS)';
1149+
$registry = '(Adobe)';
1150+
1151+
if ($this->encrypted) {
1152+
$this->encryptInit($id);
1153+
$ordering = $this->ARC4($ordering);
1154+
$registry = $this->ARC4($registry);
1155+
}
1156+
1157+
$res = '<</Registry ' . $registry . "\n"; // A string identifying an issuer of character collections
1158+
$res .= '/Ordering ' . $ordering . "\n"; // A string that uniquely names a character collection issued by a specific registry
11241159
$res .= "/Supplement 0\n"; // The supplement number of the character collection.
11251160
$res .= ">>";
11261161
$this->objects[$cidSystemInfoId]['c'] = $res;
@@ -4455,6 +4490,7 @@ function closeObject()
44554490
// close the object, as long as there was one open in the first place, which will be indicated by
44564491
// an objectId on the stack.
44574492
if ($this->nStack > 0) {
4493+
dd($this->stack[$this->nStack]);
44584494
$this->currentContents = $this->stack[$this->nStack]['c'];
44594495
$this->currentPage = $this->stack[$this->nStack]['p'];
44604496
$this->nStack--;

0 commit comments

Comments
 (0)