Just to share with the PHP community:
Thanx! I got it to work at last
<?
if (!function_exists('get_ttf_info')) {
/**
* Obtain TTF font information from file {@link http://winbinder.org/highlight.php?code=code/ttfreader.phpw click here for more information}
*
* @access public
* @param string $fontFile Name of font file including path
* @return string Font type name (will also include subfamily into name if not the "regular" font type)
* @see actual_path
* @see unicode2ansi
* @staticvar array $stringNameArray To be used to map font type name array to allow for extraction of $array['FACENAME']
*/
function &get_ttf_info($fontFile) {
if (@!is_file(actual_path($fontFile))) return null;
static $stringNameArray = array(
"COPYRIGHT",
"FACENAME",
"SUBFAMILY",
"UNIQUEFONTID",
"FAMILY",
"VERSION",
"PSNAME",
"TRADEMARK",
"UC_COPYRIGHT",
"UC_FAMILY",
"UC_SUBFAMILY",
"UC_UNIQUEFONTID",
"UC_FACENAME",
"UC_VERSION",
"UC_PSNAME",
"UC_TRADEMARK"
);
$fh = fopen($fontFile, 'rb');
@fseek($fh, 0);
$data = @fread($fh, 12);
@fseek($fh, 0);
$data = @fread($fh, 1024);
$namepos = strpos($data, 'name');
@fseek($fh, $namepos);
$data = @fread($fh, 16);
$ttfNameArray = @unpack('a4/N/Noffset', $data);
@fseek($fh, $ttfNameArray['offset']);
$data = @fread($fh, 6);
$ttfNameArray = @unpack('n/ncount/nstringoffset', $data);
$strstart = @ftell($fh) - 6 + $ttfNameArray['stringoffset'];
$names = min($ttfNameArray['count'], 16);
for ($i = 0; $i < $names; $i++) {
$data = @fread($fh, 12);
$fpos = @ftell($fh);
$ttfNameArray = @unpack('n4/nLengthID/nOffsetID', $data);
$len = $ttfNameArray['LengthID'];
if ($len) {
@fseek($fh, $strstart + $ttfNameArray['OffsetID']);
$data = @fread($fh, $len);
@fseek($fh, $fpos);
$nameArray = @unpack('a' . $len . 'Data', $data);
$ttfStringArray[$stringNameArray[$i]] = unicode2ansi($nameArray['Data']);
} else {
$ttfStringArray[$stringNameArray[$i]] = '';
}
}
@fclose($fh);
if (strcmp(strtolower($ttfStringArray['SUBFAMILY']), 'regular') == 0) {
return $ttfStringArray['FACENAME']; // REGULAR FONT NAME
} else { // SUBFAMILY FONT NAME
return $ttfStringArray['FACENAME'] . ' ' . $ttfStringArray['SUBFAMILY'];
}
}
}
if (!function_exists('unicode2ansi')) {
/**
* Convert Unicode string to ANSI {@link http://winbinder.org/highlight.php?code=code/ttfreader.phpw click here for more information}
*
* @access public
* @param string $string
* @return string ANSI
*/
function unicode2ansi($string) {
$string = (string)$string;
if(!is_string($string)) return $string;
// Is it an empty string?
if(strlen($string) == 0) return $string;
// Is it Unicode?
if(ord($string[0]) != 0) return $string;
// Do the conversion
$len = strlen($string);
$out = '';
for($i = 0; $i < $len; $i += 2)
if(ord($string[$i]) == 0 && ord($string[$i + 1]) != 0) $out .= $string[$i + 1];
return $out;
}
}
?>
Phil