Source for file makefont.php
Documentation is available at makefont.php
/*****************************************************************************
* Utility to generate font definition files *
*******************************************************************************/
die('<B>Error:</B> encoding not found: '.
$enc);
//Read a font metric file
$fix=
array('Edot'=>
'Edotaccent','edot'=>
'edotaccent','Idot'=>
'Idotaccent','Zdot'=>
'Zdotaccent','zdot'=>
'zdotaccent',
'Odblacute'=>
'Ohungarumlaut','odblacute'=>
'ohungarumlaut','Udblacute'=>
'Uhungarumlaut','udblacute'=>
'uhungarumlaut',
'Gcedilla'=>
'Gcommaaccent','gcedilla'=>
'gcommaaccent','Kcedilla'=>
'Kcommaaccent','kcedilla'=>
'kcommaaccent',
'Lcedilla'=>
'Lcommaaccent','lcedilla'=>
'lcommaaccent','Ncedilla'=>
'Ncommaaccent','ncedilla'=>
'ncommaaccent',
'Rcedilla'=>
'Rcommaaccent','rcedilla'=>
'rcommaaccent','Scedilla'=>
'Scommaaccent','scedilla'=>
'scommaaccent',
'Tcedilla'=>
'Tcommaaccent','tcedilla'=>
'tcommaaccent','Dslash'=>
'Dcroat','dslash'=>
'dcroat','Dmacron'=>
'Dcroat','dmacron'=>
'dcroat',
'combininggraveaccent'=>
'gravecomb','combininghookabove'=>
'hookabovecomb','combiningtildeaccent'=>
'tildecomb',
'combiningacuteaccent'=>
'acutecomb','combiningdotbelow'=>
'dotbelowcomb','dongsign'=>
'dong');
//Fix incorrect glyph name
//Symbolic font: use built-in encoding
$fm['CapXHeight']=
$e[13];
elseif($code==
'FontName')
elseif($code==
'ItalicAngle')
$fm['ItalicAngle']=(double)
$param;
elseif($code==
'Ascender')
$fm['Ascender']=(int)
$param;
elseif($code==
'Descender')
$fm['Descender']=(int)
$param;
elseif($code==
'UnderlineThickness')
$fm['UnderlineThickness']=(int)
$param;
elseif($code==
'UnderlinePosition')
$fm['UnderlinePosition']=(int)
$param;
elseif($code==
'IsFixedPitch')
$fm['IsFixedPitch']=
($param==
'true');
elseif($code==
'FontBBox')
$fm['FontBBox']=
array($e[1],$e[2],$e[3],$e[4]);
elseif($code==
'CapHeight')
$fm['CapHeight']=(int)
$param;
$fm['StdVW']=(int)
$param;
if(!isset
($fm['FontName']))
die('FontName not found');
if(!isset
($widths['.notdef']))
if(!isset
($widths['Delta']) and isset
($widths['increment']))
$widths['Delta']=
$widths['increment'];
//Order widths according to map
if(!isset
($widths[$map[$i]]))
echo
'<B>Warning:</B> character '.
$map[$i].
' is missing<BR>';
$widths[$i]=
$widths['.notdef'];
$widths[$i]=
$widths[$map[$i]];
$asc=
(isset
($fm['Ascender']) ?
$fm['Ascender'] :
1000);
$fd=
"array('Ascent'=>".
$asc;
$desc=
(isset
($fm['Descender']) ?
$fm['Descender'] : -
200);
$fd.=
",'Descent'=>".
$desc;
if(isset
($fm['CapHeight']))
elseif(isset
($fm['CapXHeight']))
$fd.=
",'CapHeight'=>".
$ch;
if(isset
($fm['IsFixedPitch']) and $fm['IsFixedPitch'])
if(isset
($fm['ItalicAngle']) and $fm['ItalicAngle']!=
0)
$fd.=
",'Flags'=>".
$flags;
if(isset
($fm['FontBBox']))
$fbb=
array(0,$des-
100,1000,$asc+
100);
$fd.=
",'FontBBox'=>'[".
$fbb[0].
' '.
$fbb[1].
' '.
$fbb[2].
' '.
$fbb[3].
"]'";
$ia=
(isset
($fm['ItalicAngle']) ?
$fm['ItalicAngle'] :
0);
$fd.=
",'ItalicAngle'=>".
$ia;
elseif(isset
($fm['Weight']) and eregi('(bold|black)',$fm['Weight']))
$fd.=
",'StemV'=>".
$stemv;
if(isset
($fm['MissingWidth']))
$fd.=
",'MissingWidth'=>".
$fm['MissingWidth'];
//Make character width array
elseif($i>=
32 and $i<=
126)
$s.=
'=>'.
$fm['Widths'][$i];
//Build differences from reference encoding
$f=
fopen($file,'w'.
$mode);
die('Can\'t write to file '.
$file);
//Check if font license allows embedding
die('<B>Error:</B> Can\'t open '.
$file);
//Extract number of tables
fseek($f,$offset,SEEK_SET);
echo
'<B>Warning:</B> font license does not allow embedding';
/*****************************************************************************
* $fontfile : chemin du fichier TTF (ou chane vide si pas d'incorporation) *
* $afmfile : chemin du fichier AFM *
* $enc : encodage (ou chane vide si la police est symbolique) *
* $patch : patch optionnel pour l'encodage *
* $type : type de la police si $fontfile est vide *
*******************************************************************************/
function MakeFont($fontfile,$afmfile,$enc=
'cp1252',$patch=
array(),$type=
'TrueType')
//Generate a font definition file
ini_set('auto_detect_line_endings','1');
foreach($patch as $cc=>
$gn)
die('<B>Error:</B> AFM file not found: '.
$afmfile);
die('<B>Error:</B> unrecognized font file extension: '.
$ext);
if($type!=
'TrueType' and $type!=
'Type1')
die('<B>Error:</B> incorrect font type: '.
$type);
$s.=
'$type=\''.
$type.
"';\n";
$s.=
'$name=\''.
$fm['FontName'].
"';\n";
if(!isset
($fm['UnderlinePosition']))
$fm['UnderlinePosition']=-
100;
if(!isset
($fm['UnderlineThickness']))
$fm['UnderlineThickness']=
50;
$s.=
'$up='.
$fm['UnderlinePosition'].
";\n";
$s.=
'$ut='.
$fm['UnderlineThickness'].
";\n";
$s.=
'$enc=\''.
$enc.
"';\n";
$s.=
'$diff=\''.
$diff.
"';\n";
die('<B>Error:</B> font file not found: '.
$fontfile);
$f=
fopen($fontfile,'rb');
die('<B>Error:</B> Can\'t open '.
$fontfile);
//Find first two sections and discard third one
$header=
(ord($file{0})==
128);
//Strip first binary header
die('<B>Error:</B> font file does not seem to be valid Type1');
if($header and ord($file{$size1})==
128)
//Strip second binary header
$pos=
strpos($file,'00000000');
die('<B>Error:</B> font file does not seem to be valid Type1');
$file=
substr($file,0,$size1+
$size2);
$s.=
'$file=\''.
$cmp.
"';\n";
echo
'Font file compressed ('.
$cmp.
')<BR>';
$s.=
'$file=\''.
basename($fontfile).
"';\n";
echo
'<B>Notice:</B> font file could not be compressed (zlib extension not available)<BR>';
$s.=
'$size1='.
$size1.
";\n";
$s.=
'$size2='.
$size2.
";\n";
$s.=
'$originalsize='.
filesize($fontfile).
";\n";
echo
'Font definition file generated ('.
$basename.
'.php'.
')<BR>';
Documentation generated on Sat, 24 Mar 2007 10:00:21 +0100 by phpDocumentor 1.3.1