getMetrics() public method

public getMetrics ( $file )
Ejemplo n.º 1
0
 function _putfonts()
 {
     $nf = $this->n;
     foreach ($this->diffs as $diff) {
         //Encodings
         $this->_newobj();
         $this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences [' . $diff . ']>>');
         $this->_out('endobj');
     }
     foreach ($this->FontFiles as $file => $info) {
         if (!isset($info['type']) || $info['type'] != 'TrueTypesubset') {
             //Font file embedding
             $this->_newobj();
             $this->FontFiles[$file]['n'] = $this->n;
             $font = '';
             $f = fopen($this->_getfontpath() . $file, 'rb', 1);
             if (!$f) {
                 $this->Error('Font file not found');
             }
             while (!feof($f)) {
                 $font .= fread($f, 8192);
             }
             fclose($f);
             $compressed = substr($file, -2) == '.z';
             if (!$compressed && isset($info['length2'])) {
                 $header = ord($font[0]) == 128;
                 if ($header) {
                     //Strip first binary header
                     $font = substr($font, 6);
                 }
                 if ($header && ord($font[$info['length1']]) == 128) {
                     //Strip second binary header
                     $font = substr($font, 0, $info['length1']) . substr($font, $info['length1'] + 6);
                 }
             }
             $this->_out('<</Length ' . strlen($font));
             if ($compressed) {
                 $this->_out('/Filter /FlateDecode');
             }
             $this->_out('/Length1 ' . $info['length1']);
             if (isset($info['length2'])) {
                 $this->_out('/Length2 ' . $info['length2'] . ' /Length3 0');
             }
             $this->_out('>>');
             $this->_putstream($font);
             $this->_out('endobj');
         }
     }
     foreach ($this->fonts as $k => $font) {
         //Font objects
         //$this->fonts[$k]['n']=$this->n+1;
         $type = $font['type'];
         $name = $font['name'];
         if ($type == 'core') {
             //Standard font
             $this->fonts[$k]['n'] = $this->n + 1;
             $this->_newobj();
             $this->_out('<</Type /Font');
             $this->_out('/BaseFont /' . $name);
             $this->_out('/Subtype /Type1');
             if ($name != 'Symbol' && $name != 'ZapfDingbats') {
                 $this->_out('/Encoding /WinAnsiEncoding');
             }
             $this->_out('>>');
             $this->_out('endobj');
         } elseif ($type == 'Type1' || $type == 'TrueType') {
             //Additional Type1 or TrueType font
             $this->fonts[$k]['n'] = $this->n + 1;
             $this->_newobj();
             $this->_out('<</Type /Font');
             $this->_out('/BaseFont /' . $name);
             $this->_out('/Subtype /' . $type);
             $this->_out('/FirstChar 32 /LastChar 255');
             $this->_out('/Widths ' . ($this->n + 1) . ' 0 R');
             $this->_out('/FontDescriptor ' . ($this->n + 2) . ' 0 R');
             if ($font['enc']) {
                 if (isset($font['diff'])) {
                     $this->_out('/Encoding ' . ($nf + $font['diff']) . ' 0 R');
                 } else {
                     $this->_out('/Encoding /WinAnsiEncoding');
                 }
             }
             $this->_out('>>');
             $this->_out('endobj');
             //Widths
             $this->_newobj();
             $cw =& $font['cw'];
             $s = '[';
             for ($i = 32; $i <= 255; $i++) {
                 $s .= $cw[chr($i)] . ' ';
             }
             $this->_out($s . ']');
             $this->_out('endobj');
             //Descriptor
             $this->_newobj();
             $s = '<</Type /FontDescriptor /FontName /' . $name;
             foreach ($font['desc'] as $k => $v) {
                 $s .= ' /' . $k . ' ' . $v;
             }
             $file = $font['file'];
             if ($file) {
                 $s .= ' /FontFile' . ($type == 'Type1' ? '' : '2') . ' ' . $this->FontFiles[$file]['n'] . ' 0 R';
             }
             $this->_out($s . '>>');
             $this->_out('endobj');
         } else {
             if ($type == 'TrueTypesubset') {
                 $ssfaid = "A";
                 include_once $this->_getfontpath() . 'unifont/ttfonts.php';
                 $ttf = new TTFontFile();
                 $ttf->getMetrics($font['file'], 1);
                 for ($sfid = 0; $sfid < count($font['subsetfontids']); $sfid++) {
                     $this->fonts[$k]['n'][$sfid] = $this->n + 1;
                     // NB an array for subset
                     $subsetname = 'MPDFA' . $ssfaid . '+' . $font['name'];
                     $ssfaid++;
                     $subset = $font['subsets'][$sfid];
                     unset($subset[0]);
                     $ttfontstream = $ttf->makeSubset($subset);
                     $ttfontsize = strlen($ttfontstream);
                     $fontstream = gzcompress($ttfontstream);
                     $widthstring = '';
                     $toUnistring = '';
                     foreach ($font['subsets'][$sfid] as $cp => $u) {
                         if (isset($font['cw'][$u])) {
                             $widthstring .= $font['cw'][$u] . ' ';
                         } else {
                             $widthstring .= $ttf->defaultWidth . ' ';
                         }
                         $toUnistring .= sprintf("<%02s> <%04s>\n", strtoupper(dechex($cp)), strtoupper(dechex($u)));
                     }
                     //Additional Type1 or TrueType font
                     $this->_newobj();
                     $this->_out('<</Type /Font');
                     $this->_out('/BaseFont /' . $subsetname);
                     $this->_out('/Subtype /TrueType');
                     $this->_out('/FirstChar 0 /LastChar ' . count($font['subsets'][$sfid]));
                     $this->_out('/Widths ' . ($this->n + 1) . ' 0 R');
                     $this->_out('/FontDescriptor ' . ($this->n + 2) . ' 0 R');
                     $this->_out('/ToUnicode ' . ($this->n + 3) . ' 0 R');
                     $this->_out('>>');
                     $this->_out('endobj');
                     //Widths
                     $this->_newobj();
                     $this->_out('[' . $widthstring . ']');
                     $this->_out('endobj');
                     //Descriptor
                     $this->_newobj();
                     $s = '<</Type /FontDescriptor /FontName /' . $subsetname . "\n";
                     foreach ($font['desc'] as $kd => $v) {
                         if ($kd == 'Flags') {
                             $v = $v | 4;
                             $v = $v & ~32;
                         }
                         $s .= ' /' . $kd . ' ' . $v . "\n";
                     }
                     $s .= '/FontFile2 ' . ($this->n + 2) . ' 0 R';
                     $this->_out($s . '>>');
                     $this->_out('endobj');
                     // ToUnicode
                     $toUni = "stream\n";
                     $toUni .= "/CIDInit /ProcSet findresource begin\n";
                     $toUni .= "12 dict begin\n";
                     $toUni .= "begincmap\n";
                     $toUni .= "/CIDSystemInfo\n";
                     $toUni .= "<</Registry (Adobe)\n";
                     $toUni .= "/Ordering (UCS)\n";
                     $toUni .= "/Supplement 0\n";
                     $toUni .= ">> def\n";
                     $toUni .= "/CMapName /Adobe-Identity-UCS def\n";
                     $toUni .= "/CMapType 2 def\n";
                     $toUni .= "1 begincodespacerange\n";
                     $toUni .= "<00> <FF>\n";
                     $toUni .= "endcodespacerange\n";
                     $toUni .= count($font['subsets'][$sfid]) . " beginbfchar\n";
                     $toUni .= $toUnistring;
                     $toUni .= "endbfchar\n";
                     $toUni .= "endcmap\n";
                     $toUni .= "CMapName currentdict /CMap defineresource pop\n";
                     $toUni .= "end\n";
                     $toUni .= "end\n";
                     $toUni .= "endstream\n";
                     $toUni .= "endobj";
                     $this->_newobj();
                     $this->_out('<</Length ' . (strlen($toUni) - 24) . '>>');
                     $this->_out($toUni);
                     //Font file
                     $this->_newobj();
                     $this->_out('<</Length ' . strlen($fontstream));
                     $this->_out('/Filter /FlateDecode');
                     $this->_out('/Length1 ' . $ttfontsize);
                     $this->_out('>>');
                     $this->_putstream($fontstream);
                     $this->_out('endobj');
                 }
                 unset($ttf);
             } else {
                 //Allow for additional types
                 $this->fonts[$k]['n'] = $this->n + 1;
                 $mtd = '_put' . strtolower($type);
                 if (!method_exists($this, $mtd)) {
                     $this->Error('Unsupported font type: ' . $type);
                 }
                 $this->{$mtd}($font);
             }
         }
     }
 }
Ejemplo n.º 2
0
function AddFont($family,$style='') {
	if(empty($family)) { return; }
	$family = strtolower($family);
	$style=strtoupper($style);
	$style=str_replace('U','',$style);
	if($style=='IB') $style='BI';
	$fontkey = $family.$style;
	// check if the font has been already added
	if(isset($this->fonts[$fontkey])) {
		return;
	}

/*-- CJK-FONTS --*/
	if (in_array($family,$this->available_CJK_fonts)) { 
		if (empty($this->Big5_widths)) { require(_MPDF_PATH . 'includes/CJKdata.php'); }
		$this->AddCJKFont($family);	// don't need to add style
		return; 
	}
/*-- END CJK-FONTS --*/

	if ($this->usingCoreFont) { die("mPDF Error - problem with Font management"); }

	$stylekey = $style;
	if (!$style) { $stylekey = 'R'; }

	if (!isset($this->fontdata[$family][$stylekey]) || !$this->fontdata[$family][$stylekey]) {
		die('mPDF Error - Font is not supported - '.$family.' '.$style);
	}

	$name = '';
	$originalsize = 0;
	$sip = false;
	$smp = false;
	$unAGlyphs = false;	// mPDF 5.4.05
	$haskerninfo = false;
	$BMPselected = false;
	@include(_MPDF_TTFONTDATAPATH.$fontkey.'.mtx.php');

	$ttffile = '';
	if (defined('_MPDF_SYSTEM_TTFONTS')) {
		$ttffile = _MPDF_SYSTEM_TTFONTS.$this->fontdata[$family][$stylekey];
		if (!file_exists($ttffile)) { $ttffile = ''; }
	}
	if (!$ttffile) {
		$ttffile = _MPDF_TTFONTPATH.$this->fontdata[$family][$stylekey];
		if (!file_exists($ttffile)) { die("mPDF Error - cannot find TTF TrueType font file - ".$ttffile); }
	}
	$ttfstat = stat($ttffile);

	if (isset($this->fontdata[$family]['TTCfontID'][$stylekey])) { $TTCfontID = $this->fontdata[$family]['TTCfontID'][$stylekey]; }
	else { $TTCfontID = 0; }


	$BMPonly = false;
	if (in_array($family,$this->BMPonly)) { $BMPonly = true; }
	$regenerate = false;
	if ($BMPonly && !$BMPselected) { $regenerate = true; }
	else if (!$BMPonly && $BMPselected) { $regenerate = true; }
	if ($this->useKerning && !$haskerninfo) { $regenerate = true; }
	// mPDF 5.4.05
	if (isset($this->fontdata[$family]['unAGlyphs']) && $this->fontdata[$family]['unAGlyphs'] && !$unAGlyphs) { 
		$regenerate = true; 
		$unAGlyphs = true;
	}
	else if ((!isset($this->fontdata[$family]['unAGlyphs']) || !$this->fontdata[$family]['unAGlyphs']) && $unAGlyphs) { 
		$regenerate = true; 
		$unAGlyphs = false;
	}
	if (!isset($name) || $originalsize != $ttfstat['size'] || $regenerate) {
		if (!class_exists('TTFontFile', false)) { include(_MPDF_PATH .'classes/ttfontsuni.php'); }
		$ttf = new TTFontFile();
		$ttf->getMetrics($ttffile, $TTCfontID, $this->debugfonts, $BMPonly, $this->useKerning, $unAGlyphs);	// mPDF 5.4.05
		$cw = $ttf->charWidths;
		$kerninfo = $ttf->kerninfo;
		$haskerninfo = true;
		$name = preg_replace('/[ ()]/','',$ttf->fullName);
		$sip = $ttf->sipset;
		$smp = $ttf->smpset;

		$desc= array('Ascent'=>round($ttf->ascent),
		'Descent'=>round($ttf->descent),
		'CapHeight'=>round($ttf->capHeight),
		'Flags'=>$ttf->flags,
		'FontBBox'=>'['.round($ttf->bbox[0])." ".round($ttf->bbox[1])." ".round($ttf->bbox[2])." ".round($ttf->bbox[3]).']',
		'ItalicAngle'=>$ttf->italicAngle,
		'StemV'=>round($ttf->stemV),
		'MissingWidth'=>round($ttf->defaultWidth));
		$panose = '';
		// mPDF 5.5.19
		if (count($ttf->panose)) {
			$panoseArray = array_merge(array($ttf->sFamilyClass, $ttf->sFamilySubClass), $ttf->panose);
			foreach($panoseArray as $value)
				$panose .= ' '.dechex($value);
		}
		$up = round($ttf->underlinePosition);
		$ut = round($ttf->underlineThickness);
		$originalsize = $ttfstat['size']+0;
		$type = 'TTF';
		//Generate metrics .php file
		$s='<?php'."\n";
		$s.='$name=\''.$name."';\n";
		$s.='$type=\''.$type."';\n";
		$s.='$desc='.var_export($desc,true).";\n";
		$s.='$up='.$up.";\n";
		$s.='$ut='.$ut.";\n";
		$s.='$ttffile=\''.$ttffile."';\n";
		$s.='$TTCfontID=\''.$TTCfontID."';\n";
		$s.='$originalsize='.$originalsize.";\n";
		if ($sip) $s.='$sip=true;'."\n";
		else $s.='$sip=false;'."\n";
		if ($smp) $s.='$smp=true;'."\n";
		else $s.='$smp=false;'."\n";
		if ($BMPonly) $s.='$BMPselected=true;'."\n";
		else $s.='$BMPselected=false;'."\n";
		$s.='$fontkey=\''.$fontkey."';\n";
		$s.='$panose=\''.$panose."';\n";
		if ($this->useKerning) { 
			$s.='$kerninfo='.var_export($kerninfo,true).";\n"; 
			$s.='$haskerninfo=true;'."\n";
		}
		else $s.='$haskerninfo=false;'."\n";
		// mPDF 5.4.05
		if ($this->fontdata[$family]['unAGlyphs']) { 
			$s.='$unAGlyphs=true;'."\n";
		}
		else $s.='$unAGlyphs=false;'."\n";
		$s.="?>";
		if (is_writable(dirname(_MPDF_TTFONTDATAPATH.'x'))) {
			$fh = fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.mtx.php',"w");
			fwrite($fh,$s,strlen($s));
			fclose($fh);
			$fh = fopen(_MPDF_TTFONTDATAPATH.$fontkey.'.cw.dat',"wb");
			fwrite($fh,$cw,strlen($cw));
			fclose($fh);
			@unlink(_MPDF_TTFONTDATAPATH.$fontkey.'.cgm');
			@unlink(_MPDF_TTFONTDATAPATH.$fontkey.'.z');
			@unlink(_MPDF_TTFONTDATAPATH.$fontkey.'.cw127.php');
			@unlink(_MPDF_TTFONTDATAPATH.$fontkey.'.cw');
		}
		else if ($this->debugfonts) { $this->Error('Cannot write to the font caching directory - '._MPDF_TTFONTDATAPATH); }
		unset($ttf);
	}
	else {
		$cw = @file_get_contents(_MPDF_TTFONTDATAPATH.$fontkey.'.cw.dat'); 
	}

	if (isset($this->fontdata[$family]['indic']) && $this->fontdata[$family]['indic']) { $indic = true; }
	else { $indic = false; }
	if (isset($this->fontdata[$family]['sip-ext']) && $this->fontdata[$family]['sip-ext']) { $sipext = $this->fontdata[$family]['sip-ext']; }
	else { $sipext = ''; }


	$i = count($this->fonts)+$this->extraFontSubsets+1;
	if ($sip || $smp) {
		$this->fonts[$fontkey] = array('i'=>$i, 'type'=>$type, 'name'=>$name, 'desc'=>$desc, 'panose'=>$panose, 'up'=>$up, 'ut'=>$ut, 'cw'=>$cw, 'ttffile'=>$ttffile, 'fontkey'=>$fontkey, 'subsets'=>array(0=>range(0,127)), 'subsetfontids'=>array($i), 'used'=>false, 'indic'=>$indic, 'sip'=>$sip, 'sipext'=>$sipext, 'smp'=>$smp, 'TTCfontID' => $TTCfontID, 'unAGlyphs' => false);	// mPDF 5.4.05
	}
	else  {
		$ss = array();
		for ($s=32; $s<128; $s++) { $ss[$s] = $s; }
		$this->fonts[$fontkey] = array('i'=>$i, 'type'=>$type, 'name'=>$name, 'desc'=>$desc, 'panose'=>$panose, 'up'=>$up, 'ut'=>$ut, 'cw'=>$cw, 'ttffile'=>$ttffile, 'fontkey'=>$fontkey, 'subset'=>$ss, 'used'=>false, 'indic'=>$indic, 'sip'=>$sip, 'sipext'=>$sipext, 'smp'=>$smp, 'TTCfontID' => $TTCfontID, 'unAGlyphs' => $unAGlyphs);	// mPDF 5.4.05
	}
	if ($this->useKerning && $haskerninfo) { $this->fonts[$fontkey]['kerninfo'] = $kerninfo; }
	$this->FontFiles[$fontkey]=array('length1'=>$originalsize, 'type'=>"TTF", 'ttffile'=>$ttffile, 'sip'=>$sip, 'smp'=>$smp);
	unset($cw);
}
Ejemplo n.º 3
0
 function AddFont($family, $style = '', $file = '', $uni = false)
 {
     // Add a TrueType, OpenType or Type1 font
     $family = strtolower($family);
     $style = strtoupper($style);
     if ($style == 'IB') {
         $style = 'BI';
     }
     if ($file == '') {
         if ($uni) {
             $file = str_replace(' ', '', $family) . strtolower($style) . '.ttf';
         } else {
             $file = str_replace(' ', '', $family) . strtolower($style) . '.php';
         }
     }
     $fontkey = $family . $style;
     if (isset($this->fonts[$fontkey])) {
         return;
     }
     if ($uni) {
         if (defined("_SYSTEM_TTFONTS") && file_exists(_SYSTEM_TTFONTS . $file)) {
             $ttffilename = _SYSTEM_TTFONTS . $file;
         } else {
             $ttffilename = $this->_getfontpath() . 'unifont/' . $file;
         }
         $unifilename = $this->_getfontpath() . 'unifont/' . strtolower(substr($file, 0, strpos($file, '.')));
         $name = '';
         $originalsize = 0;
         $ttfstat = stat($ttffilename);
         if (file_exists($unifilename . '.mtx.php')) {
             include $unifilename . '.mtx.php';
         }
         if (!isset($type) || !isset($name) || $originalsize != $ttfstat['size']) {
             $ttffile = $ttffilename;
             require_once $this->_getfontpath() . 'unifont/ttfonts.php';
             $ttf = new TTFontFile();
             $ttf->getMetrics($ttffile);
             $cw = $ttf->charWidths;
             $name = preg_replace('/[ ()]/', '', $ttf->fullName);
             $desc = array('Ascent' => round($ttf->ascent), 'Descent' => round($ttf->descent), 'CapHeight' => round($ttf->capHeight), 'Flags' => $ttf->flags, 'FontBBox' => '[' . round($ttf->bbox[0]) . " " . round($ttf->bbox[1]) . " " . round($ttf->bbox[2]) . " " . round($ttf->bbox[3]) . ']', 'ItalicAngle' => $ttf->italicAngle, 'StemV' => round($ttf->stemV), 'MissingWidth' => round($ttf->defaultWidth));
             $up = round($ttf->underlinePosition);
             $ut = round($ttf->underlineThickness);
             $originalsize = $ttfstat['size'] + 0;
             $type = 'TTF';
             // Generate metrics .php file
             $s = '<?php' . "\n";
             $s .= '$name=\'' . $name . "';\n";
             $s .= '$type=\'' . $type . "';\n";
             $s .= '$desc=' . var_export($desc, true) . ";\n";
             $s .= '$up=' . $up . ";\n";
             $s .= '$ut=' . $ut . ";\n";
             $s .= '$ttffile=\'' . $ttffile . "';\n";
             $s .= '$originalsize=' . $originalsize . ";\n";
             $s .= '$fontkey=\'' . $fontkey . "';\n";
             $s .= "?>";
             if (is_writable(dirname($this->_getfontpath() . 'unifont/' . 'x'))) {
                 $fh = fopen($unifilename . '.mtx.php', "w");
                 fwrite($fh, $s, strlen($s));
                 fclose($fh);
                 $fh = fopen($unifilename . '.cw.dat', "wb");
                 fwrite($fh, $cw, strlen($cw));
                 fclose($fh);
                 @unlink($unifilename . '.cw127.php');
             }
             unset($ttf);
         } else {
             $cw = @file_get_contents($unifilename . '.cw.dat');
         }
         $i = count($this->fonts) + 1;
         if (!empty($this->AliasNbPages)) {
             $sbarr = range(0, 57);
         } else {
             $sbarr = range(0, 32);
         }
         $this->fonts[$fontkey] = array('i' => $i, 'type' => $type, 'name' => $name, 'desc' => $desc, 'up' => $up, 'ut' => $ut, 'cw' => $cw, 'ttffile' => $ttffile, 'fontkey' => $fontkey, 'subset' => $sbarr, 'unifilename' => $unifilename);
         $this->FontFiles[$fontkey] = array('length1' => $originalsize, 'type' => "TTF", 'ttffile' => $ttffile);
         $this->FontFiles[$file] = array('type' => "TTF");
         unset($cw);
     } else {
         $info = $this->_loadfont($file);
         $info['i'] = count($this->fonts) + 1;
         if (!empty($info['diff'])) {
             // Search existing encodings
             $n = array_search($info['diff'], $this->diffs);
             if (!$n) {
                 $n = count($this->diffs) + 1;
                 $this->diffs[$n] = $info['diff'];
             }
             $info['diffn'] = $n;
         }
         if (!empty($info['file'])) {
             // Embedded font
             if ($info['type'] == 'TrueType') {
                 $this->FontFiles[$info['file']] = array('length1' => $info['originalsize']);
             } else {
                 $this->FontFiles[$info['file']] = array('length1' => $info['size1'], 'length2' => $info['size2']);
             }
         }
         $this->fonts[$fontkey] = $info;
     }
 }
Ejemplo n.º 4
0
 function AddFont($family, $style = '', $file = '', $deprec = false)
 {
     // Add a TrueType, OpenType or Type1 font
     $family = strtolower($family);
     $style = strtolower($style);
     if (strpos($style, 'u') !== false) {
         $style = str_replace('u', '', $style);
     }
     if ($style == 'ib') {
         $style = 'bi';
     }
     $fontkey = str_replace(' ', '', $family) . $style;
     if (isset($this->fonts[$fontkey])) {
         return;
     }
     if ($file) {
         $file = trim($file);
     }
     if ($file == '') {
         $ttf = $this->FindTtfFile($fontkey, $style);
         if ($ttf) {
             $file = $fontkey . '.ttf';
         } else {
             $file = $this->unifontpath . DIRECTORY_SEPARATOR . $fontkey . '.php';
             if (!file_exists($file)) {
                 $file = $this->fontpath . DIRECTORY_SEPARATOR . $fontkey . '.php';
                 if (!file_exists($file)) {
                     $this->Warn("{$family} font file not found");
                     $file = $this->unifontpath . DIRECTORY_SEPARATOR . 'helvetica.php';
                 }
             }
         }
     } else {
         $ttf = $this->FindTtfFile($file);
         if (!$ttf) {
             $file = $this->unifontpath . DIRECTORY_SEPARATOR . $file . '.php';
             if (!file_exists($file)) {
                 $file = $this->fontpath . DIRECTORY_SEPARATOR . $file . '.php';
                 if (!file_exists($file)) {
                     $this->Warn("{$file} font file not found");
                     $file = $this->unifontpath . DIRECTORY_SEPARATOR . 'helvetica.php';
                 }
             }
         }
     }
     if ($ttf) {
         if (!$this->canTtf) {
             $this->Error("PHP's mbstring extension needed for TTF fonts");
         }
         $unifilename = $this->unifontpath . DIRECTORY_SEPARATOR . strtolower(substr($file, 0, strpos($file, '.')));
         $name = '';
         $originalsize = 0;
         $ttfstat = stat($ttf);
         if (file_exists($unifilename . '.mtx.php')) {
             include $unifilename . '.mtx.php';
         }
         if (!isset($type) || !isset($name) || $originalsize != $ttfstat['size']) {
             $ttffile = $ttf;
             require_once $this->unifontpath . DIRECTORY_SEPARATOR . 'ttfonts.php';
             $ttf = new TTFontFile();
             $ttf->getMetrics($ttffile);
             $cw = $ttf->charWidths;
             $name = preg_replace('/[ ()]/', '', $ttf->fullName);
             $desc = array('Ascent' => round($ttf->ascent), 'Descent' => round($ttf->descent), 'CapHeight' => round($ttf->capHeight), 'Flags' => $ttf->flags, 'FontBBox' => '[' . round($ttf->bbox[0]) . ' ' . round($ttf->bbox[1]) . ' ' . round($ttf->bbox[2]) . ' ' . round($ttf->bbox[3]) . ']', 'ItalicAngle' => $ttf->italicAngle, 'StemV' => round($ttf->stemV), 'MissingWidth' => round($ttf->defaultWidth));
             $up = round($ttf->underlinePosition);
             $ut = round($ttf->underlineThickness);
             $originalsize = $ttfstat['size'] + 0;
             $type = 'TTF';
             if (is_writable($this->unifontpath)) {
                 // Generate metrics .php file
                 $lines = array('<?php', '$name=\'' . $name . '\';', '$type=\'' . $type . '\';', '$desc=' . var_export($desc, true) . ';', '$up=' . $up . ';', '$ut=' . $ut . ';', '$ttffile=\'' . $ttffile . '\';', '$originalsize=' . $originalsize . ';', '$fontkey=\'' . $fontkey . '\';', '?>');
                 $s = implode("\n", $lines);
                 $fh = fopen($unifilename . '.mtx.php', 'w');
                 fwrite($fh, $s, strlen($s));
                 fclose($fh);
                 $fh = fopen($unifilename . '.cw.dat', 'wb');
                 fwrite($fh, $cw, strlen($cw));
                 fclose($fh);
                 @unlink($unifilename . '.cw127.php');
             }
             unset($ttf);
         } else {
             $cw = @file_get_contents($unifilename . '.cw.dat');
         }
         $i = count($this->fonts) + 1;
         if (!empty($this->AliasNbPages)) {
             $sbarr = range(0, 57);
         } else {
             $sbarr = range(0, 32);
         }
         $this->fonts[$fontkey] = array('i' => $i, 'type' => $type, 'name' => $name, 'desc' => $desc, 'up' => $up, 'ut' => $ut, 'cw' => $cw, 'ttffile' => $ttffile, 'fontkey' => $fontkey, 'subset' => $sbarr, 'unifilename' => $unifilename);
         $this->FontFiles[$fontkey] = array('length1' => $originalsize, 'type' => 'TTF', 'ttffile' => $ttffile);
         $this->FontFiles[$file] = array('type' => 'TTF');
         unset($cw);
     } else {
         $info = $this->_loadfont($file);
         $info['i'] = count($this->fonts) + 1;
         if (!empty($info['diff'])) {
             // Search existing encodings
             $n = array_search($info['diff'], $this->diffs);
             if (!$n) {
                 $n = count($this->diffs) + 1;
                 $this->diffs[$n] = $info['diff'];
             }
             $info['diffn'] = $n;
         }
         if (!empty($info['file'])) {
             // Embedded font
             if ($info['type'] == 'TrueType') {
                 $this->FontFiles[$info['file']] = array('length1' => $info['originalsize']);
             } else {
                 $this->FontFiles[$info['file']] = array('length1' => $info['size1'], 'length2' => $info['size2']);
             }
         }
         $this->fonts[$fontkey] = $info;
     }
 }