Login   Register  
PHP Classes
elePHPant
Icontem

fix 2 - remove spaces

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      TTF Info  >  All threads  >  fix 2 - remove spaces  >  (Un) Subscribe thread alerts  
Subject:fix 2 - remove spaces
Summary:removes the null character ascii 0
Messages:1
Author:paul
Date:2006-09-09 13:21:33
 

  1. fix 2 - remove spaces   Reply  
Picture of paul
paul
2006-09-09 13:21:33
<?
class ttf {
private function dec2hex($dec){
$hex=dechex($dec);
return( str_repeat("0",2-strlen($hex)) . strtoupper($hex) );
}
public function info($ttf_filename) {
return str_replace(chr(0),"", $this->infomation($ttf_filename));
}
private function infomation($ttf_filename) {
$fd = fopen ($ttf_filename, "r");
$text = fread ($fd, filesize ($ttf_filename));
fclose ($fd);
$number_of_tabs = $this->dec2hex(ord($text[4])) . $this->dec2hex(ord($text[5]));
for ($i=0;$i<hexdec($number_of_tabs);$i++){
$tag = $text[12+$i*16].$text[12+$i*16+1].$text[12+$i*16+2].$text[12+$i*16+3];
if ($tag == "name") {
$offset_name_table_hex = $this->dec2hex(ord($text[12+$i*16+8])) . $this->dec2hex(ord($text[12+$i*16+8+1])) . $this->dec2hex(ord($text[12+$i*16+8+2])) . $this->dec2hex(ord($text[12+$i*16+8+3]));
$offset_name_table_dec = hexdec($offset_name_table_hex);
$offset_storage_hex = $this->dec2hex(ord($text[$offset_name_table_dec+4])) . $this->dec2hex(ord($text[$offset_name_table_dec+5]));
$offset_storage_dec = hexdec($offset_storage_hex);
$number_name_records_hex = $this->dec2hex(ord($text[$offset_name_table_dec+2])) . $this->dec2hex(ord($text[$offset_name_table_dec+3]));
$number_name_records_dec = hexdec($number_name_records_hex);
break;
}
}
$storage_dec = $offset_storage_dec + $offset_name_table_dec;
$storage_hex = strtoupper(dechex($storage_dec));
for ($j=0;$j<$number_name_records_dec;$j++){
$platform_id_hex = $this->dec2hex(ord($text[$offset_name_table_dec+6+$j*12+0])) . $this->dec2hex(ord($text[$offset_name_table_dec+6+$j*12+1]));
$platform_id_dec = hexdec($platform_id_hex);
$name_id_hex = $this->dec2hex(ord($text[$offset_name_table_dec+6+$j*12+6])) . $this->dec2hex(ord($text[$offset_name_table_dec+6+$j*12+7]));
$name_id_dec = hexdec($name_id_hex);
$string_length_hex = $this->dec2hex(ord($text[$offset_name_table_dec+6+$j*12+8])) . $this->dec2hex(ord($text[$offset_name_table_dec+6+$j*12+9]));
$string_length_dec = hexdec($string_length_hex);
$string_offset_hex = $this->dec2hex(ord($text[$offset_name_table_dec+6+$j*12+10])) . $this->dec2hex(ord($text[$offset_name_table_dec+6+$j*12+11]));
$string_offset_dec = hexdec($string_offset_hex);
if ($name_id_dec==0 and !isset($copyright)) {
$copyright='';
for($l=0;$l<$string_length_dec;$l++){
$copyright.=$text[$storage_dec+$string_offset_dec+$l];
}
}
if ($name_id_dec==1 and !isset($fontfamily)) {
$fontfamily='';
for($l=0;$l<$string_length_dec;$l++){
$fontfamily.=$text[$storage_dec+$string_offset_dec+$l];
}
}
if ($name_id_dec==2 and !isset($fontsubfamily)) {
$fontsubfamily='';
for($l=0;$l<$string_length_dec;$l++){
$fontsubfamily.=$text[$storage_dec+$string_offset_dec+$l];
}
}
if ($name_id_dec==4 and !isset($fullfontname)) {
$fullfontname ='';
for($l=0;$l<$string_length_dec;$l++){
$fullfontname.=$text[$storage_dec+$string_offset_dec+$l];
}
}
if (!isset($fontfamily) and !isset($fontsubfamily) and !isset($fullfontname) and !isset($copyright)) {
break;
}
}
return (array('fontfamily'=>$fontfamily,'fontsubfamily'=>$fontsubfamily,'fullfontname'=>$fullfontname,'copyright'=>$copyright));
}

}

?>