Skip to content

Commit

Permalink
Merge branch 'develop' in preparation for 0.8.1
Browse files Browse the repository at this point in the history
(missed a pull request)
  • Loading branch information
bsweeney committed Sep 14, 2017
2 parents 93737b5 + 9ee9412 commit 9ea852c
Showing 1 changed file with 105 additions and 35 deletions.
140 changes: 105 additions & 35 deletions lib/Cpdf.php
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,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 = <<<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 @@ -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 = "<</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
$res .= "/Supplement 0\n"; // The supplement number of the character collection.
$res .= ">>";
$this->objects[$cidSystemInfoId]['c'] = $res;

// and a CID to GID map
$cidToGidMapId = ++$this->numObj;
Expand Down Expand Up @@ -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 .= '<</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 .= ">>";

$res .= "\nendobj";;

return $res;
}

return null;
}

/**
* a font glyph to character map, needed for unicode fonts
*
Expand Down

0 comments on commit 9ea852c

Please sign in to comment.