Changeset 693 for trunk/phpbms/fpdf/font/makefont/makefont.php
- Timestamp:
- 12/31/09 13:36:45 (2 years ago)
- Files:
-
- 1 modified
-
trunk/phpbms/fpdf/font/makefont/makefont.php (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/phpbms/fpdf/font/makefont/makefont.php
r667 r693 2 2 /******************************************************************************* 3 3 * Utility to generate font definition files * 4 * Version: 1.13 * 5 * Date: 2004-12-31 * 4 * * 5 * Version: 1.14 * 6 * Date: 2008-08-03 * 7 * Author: Olivier PLATHEY * 6 8 *******************************************************************************/ 7 9 … … 12 14 $a=file($file); 13 15 if(empty($a)) 14 die('< B>Error:</B> encoding not found: '.$enc);16 die('<b>Error:</b> encoding not found: '.$enc); 15 17 $cc2gn=array(); 16 18 foreach($a as $l) 17 19 { 18 if($l {0}=='!')20 if($l[0]=='!') 19 21 { 20 22 $e=preg_split('/[ \\t]+/',rtrim($l)); … … 32 34 } 33 35 34 function ReadAFM($file, &$map)36 function ReadAFM($file, &$map) 35 37 { 36 38 //Read a font metric file … … 115 117 if(!isset($widths['.notdef'])) 116 118 $widths['.notdef']=600; 117 if(!isset($widths['Delta']) andisset($widths['increment']))119 if(!isset($widths['Delta']) && isset($widths['increment'])) 118 120 $widths['Delta']=$widths['increment']; 119 121 //Order widths according to map … … 122 124 if(!isset($widths[$map[$i]])) 123 125 { 124 echo '< B>Warning:</B> character '.$map[$i].' is missing<br />';126 echo '<b>Warning:</b> character '.$map[$i].' is missing<br>'; 125 127 $widths[$i]=$widths['.notdef']; 126 128 } … … 133 135 } 134 136 135 function MakeFontDescriptor($fm, $symbolic)137 function MakeFontDescriptor($fm, $symbolic) 136 138 { 137 139 //Ascent … … 151 153 //Flags 152 154 $flags=0; 153 if(isset($fm['IsFixedPitch']) and$fm['IsFixedPitch'])155 if(isset($fm['IsFixedPitch']) && $fm['IsFixedPitch']) 154 156 $flags+=1<<0; 155 157 if($symbolic) … … 157 159 if(!$symbolic) 158 160 $flags+=1<<5; 159 if(isset($fm['ItalicAngle']) and$fm['ItalicAngle']!=0)161 if(isset($fm['ItalicAngle']) && $fm['ItalicAngle']!=0) 160 162 $flags+=1<<6; 161 163 $fd.=",'Flags'=>".$flags; … … 164 166 $fbb=$fm['FontBBox']; 165 167 else 166 $fbb=array(0,$des -100,1000,$asc+100);168 $fbb=array(0,$desc-100,1000,$asc+100); 167 169 $fd.=",'FontBBox'=>'[".$fbb[0].' '.$fbb[1].' '.$fbb[2].' '.$fbb[3]."]'"; 168 170 //ItalicAngle … … 172 174 if(isset($fm['StdVW'])) 173 175 $stemv=$fm['StdVW']; 174 elseif(isset($fm['Weight']) && preg_match('/ (bold|black)/i',$fm['Weight']))176 elseif(isset($fm['Weight']) && preg_match('/bold|black/i',$fm['Weight'])) 175 177 $stemv=120; 176 178 else … … 195 197 elseif(chr($i)=="\\") 196 198 $s.="'\\\\'"; 197 elseif($i>=32 and$i<=126)199 elseif($i>=32 && $i<=126) 198 200 $s.="'".chr($i)."'"; 199 201 else … … 228 230 } 229 231 230 function SaveToFile($file, $s,$mode='t')232 function SaveToFile($file, $s, $mode) 231 233 { 232 234 $f=fopen($file,'w'.$mode); … … 254 256 $f=fopen($file,'rb'); 255 257 if(!$f) 256 die('< B>Error:</B> Can\'t open '.$file);258 die('<b>Error:</b> Can\'t open '.$file); 257 259 //Extract number of tables 258 260 fseek($f,4,SEEK_CUR); … … 285 287 $e=($fsType & 0x08)!=0; 286 288 fclose($f); 287 if($rl and !$pp and!$e)288 echo '< B>Warning:</B> font license does not allow embedding';289 if($rl && !$pp && !$e) 290 echo '<b>Warning:</b> font license does not allow embedding'; 289 291 } 290 292 291 293 /******************************************************************************* 292 * $fontfile : chemin du fichier TTF (ou chaîne vide si pas d'incorporation)*293 * $afmfile : chemin du fichier AFM*294 * $enc : encodage (ou chaîne vide si la police est symbolique)*295 * $patch : patch optionnel pour l'encodage*296 * $type : type de la police si $fontfile est vide*294 * fontfile: path to TTF file (or empty string if not to be embedded) * 295 * afmfile: path to AFM file * 296 * enc: font encoding (or empty string for symbolic fonts) * 297 * patch: optional patch for encoding * 298 * type: font type if fontfile is empty * 297 299 *******************************************************************************/ 298 function MakeFont($fontfile, $afmfile,$enc='cp1252',$patch=array(),$type='TrueType')300 function MakeFont($fontfile, $afmfile, $enc='cp1252', $patch=array(), $type='TrueType') 299 301 { 300 302 //Generate a font definition file 301 set_magic_quotes_runtime(0); 303 if(get_magic_quotes_runtime()) 304 @set_magic_quotes_runtime(0); 302 305 ini_set('auto_detect_line_endings','1'); 303 306 if($enc) … … 310 313 $map=array(); 311 314 if(!file_exists($afmfile)) 312 die('< B>Error:</B> AFM file not found: '.$afmfile);315 die('<b>Error:</b> AFM file not found: '.$afmfile); 313 316 $fm=ReadAFM($afmfile,$map); 314 317 if($enc) … … 326 329 $type='Type1'; 327 330 else 328 die('< B>Error:</B> unrecognized font file extension: '.$ext);329 } 330 else 331 { 332 if($type!='TrueType' and$type!='Type1')333 die('< B>Error:</B> incorrect font type: '.$type);331 die('<b>Error:</b> unrecognized font file extension: '.$ext); 332 } 333 else 334 { 335 if($type!='TrueType' && $type!='Type1') 336 die('<b>Error:</b> incorrect font type: '.$type); 334 337 } 335 338 //Start generation … … 353 356 //Embedded font 354 357 if(!file_exists($fontfile)) 355 die('< B>Error:</B> font file not found: '.$fontfile);358 die('<b>Error:</b> font file not found: '.$fontfile); 356 359 if($type=='TrueType') 357 360 CheckTTF($fontfile); 358 361 $f=fopen($fontfile,'rb'); 359 362 if(!$f) 360 die('< B>Error:</B> Can\'t open '.$fontfile);363 die('<b>Error:</b> Can\'t open '.$fontfile); 361 364 $file=fread($f,filesize($fontfile)); 362 365 fclose($f); … … 364 367 { 365 368 //Find first two sections and discard third one 366 $header=(ord($file {0})==128);369 $header=(ord($file[0])==128); 367 370 if($header) 368 371 { … … 372 375 $pos=strpos($file,'eexec'); 373 376 if(!$pos) 374 die('< B>Error:</B> font file does not seem to be valid Type1');377 die('<b>Error:</b> font file does not seem to be valid Type1'); 375 378 $size1=$pos+6; 376 if($header and ord($file{$size1})==128)379 if($header && ord($file[$size1])==128) 377 380 { 378 381 //Strip second binary header … … 381 384 $pos=strpos($file,'00000000'); 382 385 if(!$pos) 383 die('< B>Error:</B> font file does not seem to be valid Type1');386 die('<b>Error:</b> font file does not seem to be valid Type1'); 384 387 $size2=$pos-$size1; 385 388 $file=substr($file,0,$size1+$size2); … … 390 393 SaveToFile($cmp,gzcompress($file),'b'); 391 394 $s.='$file=\''.$cmp."';\n"; 392 echo 'Font file compressed ('.$cmp.')<br />';395 echo 'Font file compressed ('.$cmp.')<br>'; 393 396 } 394 397 else 395 398 { 396 399 $s.='$file=\''.basename($fontfile)."';\n"; 397 echo '< B>Notice:</B> font file could not be compressed (zlib extension not available)<br />';400 echo '<b>Notice:</b> font file could not be compressed (zlib extension not available)<br>'; 398 401 } 399 402 if($type=='Type1') … … 411 414 } 412 415 $s.="?>\n"; 413 SaveToFile($basename.'.php',$s );414 echo 'Font definition file generated ('.$basename.'.php'.')<br />';416 SaveToFile($basename.'.php',$s,'t'); 417 echo 'Font definition file generated ('.$basename.'.php'.')<br>'; 415 418 } 416 419 ?>