Пример #1
0
 /**
  * Adds unicode fonts.<br>
  * Based on PDF Reference 1.3 (section 5)
  * @param $font (array) font data
  * @protected
  * @author Nicola Asuni
  * @since 1.52.0.TC005 (2005-01-05)
  */
 protected function _puttruetypeunicode($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
     $out = $this->_getobj($this->font_obj_ids[$font['fontkey']]) . "\n";
     $out .= '<< /Type /Font';
     $out .= ' /Subtype /Type0';
     $out .= ' /BaseFont /' . $fontname;
     $out .= ' /Name /F' . $font['i'];
     $out .= ' /Encoding /' . $font['enc'];
     $out .= ' /ToUnicode ' . ($this->n + 1) . ' 0 R';
     $out .= ' /DescendantFonts [' . ($this->n + 2) . ' 0 R]';
     $out .= ' >>';
     $out .= "\n" . 'endobj';
     $this->_out($out);
     // ToUnicode map for Identity-H
     $stream = TCPDF_FONT_DATA::$uni_identity_h;
     // ToUnicode Object
     $this->_newobj();
     $stream = $this->compress ? gzcompress($stream) : $stream;
     $filter = $this->compress ? '/Filter /FlateDecode ' : '';
     $stream = $this->_getrawstream($stream);
     $this->_out('<<' . $filter . '/Length ' . strlen($stream) . '>> stream' . "\n" . $stream . "\n" . 'endstream' . "\n" . 'endobj');
     // CIDFontType2
     // A CIDFont whose glyph descriptions are based on TrueType font technology
     $oid = $this->_newobj();
     $out = '<< /Type /Font';
     $out .= ' /Subtype /CIDFontType2';
     $out .= ' /BaseFont /' . $fontname;
     // A dictionary containing entries that define the character collection of the CIDFont.
     $cidinfo = '/Registry ' . $this->_datastring($font['cidinfo']['Registry'], $oid);
     $cidinfo .= ' /Ordering ' . $this->_datastring($font['cidinfo']['Ordering'], $oid);
     $cidinfo .= ' /Supplement ' . $font['cidinfo']['Supplement'];
     $out .= ' /CIDSystemInfo << ' . $cidinfo . ' >>';
     $out .= ' /FontDescriptor ' . ($this->n + 1) . ' 0 R';
     $out .= ' /DW ' . $font['dw'];
     // default width
     $out .= "\n" . TCPDF_FONTS::_putfontwidths($font, 0);
     if (isset($font['ctg']) and !TCPDF_STATIC::empty_string($font['ctg'])) {
         $out .= "\n" . '/CIDToGIDMap ' . ($this->n + 2) . ' 0 R';
     }
     $out .= ' >>';
     $out .= "\n" . 'endobj';
     $this->_out($out);
     // Font descriptor
     // A font descriptor describing the CIDFont default metrics other than its glyph widths
     $this->_newobj();
     $out = '<< /Type /FontDescriptor';
     $out .= ' /FontName /' . $fontname;
     foreach ($font['desc'] as $key => $value) {
         if (is_float($value)) {
             $value = sprintf('%F', $value);
         }
         $out .= ' /' . $key . ' ' . $value;
     }
     $fontdir = false;
     if (!TCPDF_STATIC::empty_string($font['file'])) {
         // A stream containing a TrueType font
         $out .= ' /FontFile2 ' . $this->FontFiles[$font['file']]['n'] . ' 0 R';
         $fontdir = $this->FontFiles[$font['file']]['fontdir'];
     }
     $out .= ' >>';
     $out .= "\n" . 'endobj';
     $this->_out($out);
     if (isset($font['ctg']) and !TCPDF_STATIC::empty_string($font['ctg'])) {
         $this->_newobj();
         // 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 = TCPDF_FONTS::getFontFullPath($ctgfile, $fontdir);
         if (TCPDF_STATIC::empty_string($fontfile)) {
             $this->Error('Font file not found: ' . $ctgfile);
         }
         $stream = $this->_getrawstream(file_get_contents($fontfile));
         $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 .= ' >>';
         $out .= ' stream' . "\n" . $stream . "\n" . 'endstream';
         $out .= "\n" . 'endobj';
         $this->_out($out);
     }
 }