/** * Get the PDF output string for Indexed palette object * * @param array $data Image raw data * * @return string */ protected function getOutPalette(&$data) { if ($data['colspace'] != 'Indexed') { return ''; } $data['obj_pal'] = ++$this->pon; $stream = $this->enc->encryptString(gzcompress($data['pal']), $this->pon); return $this->pon . ' 0 obj' . "\n" . '<</Filter /FlateDecode' . ' /Length ' . strlen($stream) . '>> stream' . "\n" . $stream . "\n" . 'endstream' . "\n" . 'endobj' . "\n"; }
/** * Get the PDF output string for gradient shaders * * @param int $pon Current PDF Object Number * * @return string PDF command */ public function getOutGradientShaders($pon) { if ($this->pdfa || empty($this->gradients)) { return ''; } $this->pon = (int) $pon; $idt = count($this->gradients); // index for transparency gradients $out = ''; foreach ($this->gradients as $idx => $grad) { $out .= $this->getOutGradientCols($grad, 'color'); $this->gradients[$idx]['id'] = $this->pon - 1; $this->gradients[$idx]['pattern'] = $this->pon; $out .= $this->getOutGradientCols($grad, 'opacity'); $idgs = $idx + $idt; $this->gradients[$idgs]['id'] = $this->pon - 1; $this->gradients[$idgs]['pattern'] = $this->pon; if ($grad['transparency']) { $oid = ++$this->pon; $pwidth = $this->pagew * $this->kunit; $pheight = $this->pageh * $this->kunit; $stream = 'q /a0 gs /Pattern cs /p' . $idgs . ' scn 0 0 ' . $pwidth . ' ' . $pheight . ' re f Q'; $stream = gzcompress($stream); $stream = $this->enc->encryptString($stream, $oid); $rect = sprintf('%F %F', $pwidth, $pheight); $out .= $oid . ' 0 obj' . "\n" . '<<' . ' /Type /XObject' . ' /Subtype /Form' . ' /FormType 1' . ' /Filter /FlateDecode' . ' /Length ' . strlen($stream) . ' /BBox [0 0 ' . $rect . ']' . ' /Group << /Type /Group /S /Transparency /CS /DeviceGray >>' . ' /Resources <<' . ' /ExtGState << /a0 << /ca 1 /CA 1 >> >>' . ' /Pattern << /p' . $idgs . ' ' . $this->gradients[$idgs]['pattern'] . ' 0 R >>' . ' >>' . ' >>' . "\n" . ' stream' . "\n" . $stream . "\n" . 'endstream' . "\n" . 'endobj' . "\n"; // SMask $objsm = ++$this->pon; $out .= $objsm . ' 0 obj' . "\n" . '<<' . ' /Type /Mask' . ' /S /Luminosity' . ' /G ' . $oid . ' 0 R' . ' >>' . "\n" . 'endobj' . "\n"; // ExtGState $objext = ++$this->pon; $out .= ++$objext . ' 0 obj' . "\n" . '<<' . ' /Type /ExtGState' . ' /SMask ' . $objsm . ' 0 R' . ' /AIS false' . ' >>' . "\n" . 'endobj' . "\n"; $this->extgstates[] = array('n' => $objext, 'name' => 'TGS' . $idx); } } return $out; }
/** * Get the PDF output string for a TrueTypeUnicode font. * Based on PDF Reference 1.3 (section 5) * * @param array $font Font to process * * return string */ protected function getTrueTypeUnicode(array $font) { $fontname = ''; if ($font['subset']) { // change name for font subsetting $subtag = sprintf('%06u', $font['i']); $subtag = strtr($subtag, '0123456789', 'ABCDEFGHIJ'); $fontname .= $subtag . '+'; } $fontname .= $font['name']; // Type0 Font // A composite font composed of other fonts, organized hierarchically // obj 1 $out = $font['n'] . ' 0 obj' . "\n" . '<< /Type /Font' . ' /Subtype /Type0' . ' /BaseFont /' . $fontname . ' /Name /F' . $font['i'] . ' /Encoding /' . $font['enc'] . ' /ToUnicode ' . ($this->pon + 1) . ' 0 R' . ' /DescendantFonts [' . ($this->pon + 2) . ' 0 R]' . ' >>' . "\n" . 'endobj' . "\n"; // ToUnicode Object $out .= ++$this->pon . ' 0 obj' . "\n"; $stream = $this->enc->encryptString(gzcompress(Identity::CIDHMAP), $this->pon); // ToUnicode map for Identity-H $out .= '<</Filter /FlateDecode /Length ' . strlen($stream) . '>> stream' . "\n" . $stream . "\n" . 'endstream' . "\n" . 'endobj' . "\n"; // CIDFontType2 // A CIDFont whose glyph descriptions are based on TrueType font technology $out .= ++$this->pon . ' 0 obj' . "\n" . '<< /Type /Font' . ' /Subtype /CIDFontType2' . ' /BaseFont /' . $fontname; // A dictionary containing entries that define the character collection of the CIDFont. $cidinfo = '/Registry ' . $this->enc->escapeDataString($font['cidinfo']['Registry'], $this->pon) . ' /Ordering ' . $this->enc->escapeDataString($font['cidinfo']['Ordering'], $this->pon) . ' /Supplement ' . $font['cidinfo']['Supplement']; $out .= ' /CIDSystemInfo << ' . $cidinfo . ' >>' . ' /FontDescriptor ' . ($this->pon + 1) . ' 0 R' . ' /DW ' . $font['dw'] . "\n" . $this->getCharWidths($font, 0); if (!empty($font['ctg'])) { $out .= "\n" . '/CIDToGIDMap ' . ($this->pon + 2) . ' 0 R'; } $out .= ' >>' . "\n" . 'endobj' . "\n"; // Font descriptor // A font descriptor describing the CIDFont default metrics other than its glyph widths $out .= ++$this->pon . ' 0 obj' . "\n" . '<< /Type /FontDescriptor' . ' /FontName /' . $fontname; foreach ($font['desc'] as $key => $val) { $out .= $this->getKeyValOut($key, $val); } if (!empty($font['file_n'])) { // A stream containing a TrueType font $out .= ' /FontFile2 ' . $font['file_n'] . ' 0 R'; } $out .= ' >>' . "\n" . 'endobj' . "\n"; if (!empty($font['ctg'])) { $out .= ++$this->pon . ' 0 obj' . "\n"; // Embed CIDToGIDMap // A specification of the mapping from CIDs to glyph indices // search and get CTG font file to embedd $ctgfile = strtolower($font['ctg']); // search and get ctg font file to embedd $fontfile = $this->getFontFullPath($font['dir'], $ctgfile); $stream = $this->enc->encryptString(file_get_contents($fontfile), $this->pon); $out .= '<< /Length ' . strlen($stream) . ''; if (substr($fontfile, -2) == '.z') { // check file extension // Decompresses data encoded using the public-domain // zlib/deflate compression method, reproducing the // original text or binary data $out .= ' /Filter /FlateDecode'; } $out .= ' >>' . ' stream' . "\n" . $stream . "\n" . 'endstream' . "\n" . 'endobj' . "\n"; } return $out; }
/** * Returns the PDF command to output the page content. * * @param int $pon Current PDF object number. * @param string $content Page content. * * @return string PDF command */ protected function getPageContentObj(&$pon, $content = '') { $stream = $this->enc->encryptString(gzcompress($content), ++$pon); $out = $pon . ' 0 obj' . "\n" . '<</Filter /FlateDecode /Length ' . strlen($stream) . '>>' . "\n" . 'stream' . "\n" . $stream . "\n" . 'endstream' . "\n" . 'endobj' . "\n"; return $out; }