/** * Get the list of available fonts * * @return Array of "filename" => "font name" **/ public static function getFontList() { $list = array(); $path = TCPDF_FONTS::_getfontpath(); foreach (glob($path . '/*.php') as $font) { unset($name, $type); include $font; unset($cbbox, $cidinfo, $cw, $dw); $font = basename($font, '.php'); // skip subfonts if ((substr($font, -1) == 'b' || substr($font, -1) == 'i') && isset($list[substr($font, 0, -1)])) { continue; } if (substr($font, -2) == 'bi' && isset($list[substr($font, 0, -2)])) { continue; } if (isset($name)) { if (isset($type) && $type == 'cidfont0') { // cidfont often have the same name (ArialUnicodeMS) $list[$font] = sprintf(__('%1$s (%2$s)'), $name, $font); } else { $list[$font] = $name; } } } return $list; }
/** * Fill the list of available fonts ($this->fontlist). * @protected * @since 4.0.013 (2008-07-28) */ protected function getFontsList() { if (($fontsdir = opendir(TCPDF_FONTS::_getfontpath())) !== false) { while (($file = readdir($fontsdir)) !== false) { if (substr($file, -4) == '.php') { array_push($this->fontlist, strtolower(basename($file, '.php'))); } } closedir($fontsdir); } }
/** * 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 = ''; // search files on various directories if ($fontdir !== false and file_exists($fontdir . $ctgfile)) { $fontfile = $fontdir . $ctgfile; } elseif (file_exists(TCPDF_FONTS::_getfontpath() . $ctgfile)) { $fontfile = TCPDF_FONTS::_getfontpath() . $ctgfile; } elseif (file_exists($ctgfile)) { $fontfile = $ctgfile; } 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); } }