type('ICON'); // $myfont->readbitmap(); // $myfont->importfromtxt($conf['BASEPATH'].'ICON/'.'icon_logo.dat.txt'); // $myfont->savename=$conf['BASEPATH'].'ICON/'.'icon_logo.dat'; // $myfont->savebitmap(); // $myfont->saveshow(); // import_all_in_dir($conf['BASEPATH'].'FONT/Main/Special', 'FONT'); convert_all_in_dir($conf['BASEPATH'].'FONT', 'FONT'); // import_all_in_dir($conf['BASEPATH'].'FONT', 'FONT'); // convert_all_in_dir($conf['BASEPATH'].'ICON', 'ICON'); } function errmsg($msg , $prio = 'WARN') { switch($prio){ case 'FATAL': die ($prio . ': ' . $msg ); default: echo (htmlspecialchars($prio . ': ' . $msg) . "\n"); } return true; } function convert_all_in_dir($dir, $type = 'FONT', $extension = '.dat') { global $conf; if ($hdir = @opendir($dir)) { while (false !== ($file = readdir($hdir))) { if ($file=='.' || $file=='..') continue; $completepath="$dir/$file"; if ((!is_dir($completepath)) && (strtoupper(substr($file,-strlen($extension))) == strtoupper($extension))) { $myfont = new bitmap($file, $dir); $myfont->type($type); $myfont->readbitmap(); errmsg('ConvertAllInDir: Converting: '. $completepath.$conf['SAVE_EXT'] , 'INFO'); $myfont->savename=$completepath.$conf['SAVE_EXT']; $myfont->saveshow(); } else if (is_dir($completepath)) { convert_all_in_dir($completepath,$type,$extension); } } closedir($hdir); } else errmsg('ConvertAllInDir: Directory not found: '. $dir , 'FATAL'); return true; } function import_all_in_dir($dir, $type = 'FONT', $extension = '.txt', $type = 'FONT') { global $conf; if ($hdir = @opendir($dir)) { while (false !== ($file = readdir($hdir))) { if ($file=='.' || $file=='..') continue; $completepath="$dir/$file"; if ((!is_dir($completepath)) && (strtoupper(substr($file,-strlen($extension))) == strtoupper($extension))) { $myfont = new bitmap(substr($file,0,-strlen($extension)), $dir); $myfont->type($type); $myfont->readbitmap(); $myfont->importfromtxt($completepath); errmsg('ImportAllInDir: Saving: '. substr($completepath,0,-strlen($extension)) , 'INFO'); // $myfont->displaytxt(); $myfont->savename=substr($completepath,0,-strlen($extension)); $myfont->savebitmap(); } else if (is_dir($completepath)) { import_all_in_dir($completepath,$type,$extension); } } closedir($hdir); } else errmsg('ImportAllInDir: Directory not found: '. $dir , 'FATAL'); return true; } // strin returns the string inbetween (non-inclusive) the two needles. PHP 4.x version (5.0 version is 3 lines :/) function strin( $pajar, $primero, $segundo ) { // Case insenstive... PHP 4.3 doesn't have stripos :( $tempPajar = strtolower( $pajar ); $tempPrimero = strtolower( $primero ); $tempSegundo = strtolower( $segundo ); // Locations of the start of both strings.... if ($tempPrimero == '') $startpos = 0; else $startpos = strpos( $tempPajar, $tempPrimero) + strlen($tempPrimero); if ($tempSegundo == '') $endpos = strlen($pajar); else $endpos = strpos( substr( $tempPajar, $startpos ), $tempSegundo); return substr( $pajar, $startpos, $endpos ); } // True if aguja is on pajar function in_str($pajar,$aguja,$mayusc=false) { if ($aguja) if ($mayusc) $re = strstr($pajar,$aguja); else $re = stristr($pajar,$aguja); else $re = true; return ( (boolean) $re); } // Begin Class Bitmap class bitmap { var $filename; var $basepath; var $savename; var $bitmap; var $rawarray; var $bmarray; var $showarray; var $width; var $height; var $baseaddress; var $asciicode; var $internalname; var $_type; var $_isextended; var $_newline; function bitmap($filename , $path = '') { global $conf; $this->_newline = $conf['NEW_LINE']; $this->basepath = ($path == '' ? $conf['BASEPATH'] : $path); $this->filename = $this->basepath . '/' . $filename; $this->savename = $this->filename . $conf['SAVE_EXT']; $this->rawarray = array(); $this->bmarray = array(); $this->showarray = array(); $this->_type='UNDEFINED'; } function type($type) { switch (strtoupper($type)){ case 'FONT': $this->_type='FONT'; break; case 'ICON': $this->_type='ICON'; break; default: errmsg('Bitmap type undefined', 'FATAL'); } } function checktype() { $type=''; switch (strtoupper($this->_type)){ case 'FONT': $type='FONT'; break; case 'ICON': $type='ICON'; break; default: errmsg('Bitmap type undefined', 'FATAL'); } return $type; } function is_icon() { return ($this->checktype == 'ICON'); } function is_font() { return ($this->checktype == 'FONT'); } function readbitmap() { $this->checktype(); $f = @fopen($this->filename, 'r') or (errmsg('ReadBitmap: Could not open file: ' . $this->filename, 'ERROR')); fclose($f); $this->rawarray = explode( $this->_newline , implode( $this->_newline, file( $this->filename ) )); $this->rawarray = $this->normalize($this->rawarray); $this->_header = $this->rawarray[0]; $this->createbm(); $this->createshow(); $this->width = count($this->bmarray); $this->height = count($this->showarray); $this->asciicode = trim(strin($this->rawarray[0], '', ':')); $this->baseaddress = trim(strin($this->rawarray[0], '.WORD', 'H')); $this->internalname = 'ascii_' . $this->asciicode; } function normalize($array) { global $conf; $temparray = array(); // Normalize array foreach ($array as $key => $value) { // if ((in_str($value, '.WORD', true)) && (substr(trim($value),0,1) != ';')) if ((substr(trim($value),0,5) == '.WORD') && (substr(trim($value),0,1) != ';')) { $temparray[] = trim($value); if (in_str($value, ',')) $this->setextended(); } } return $temparray; } function setextended() { $this->_isextended = true; } function splitwords($line) { $array = array(); $line = str_replace('.WORD','',$line); $line = str_replace('H','',$line); $array = split( ',' , $line ); foreach ($array as $key => $value) $array[$key] = $this->convert2bm(trim($value)); return $array; } function createbm() { // Create bitmap array foreach ($this->rawarray as $key => $value) { if ($key != 0) { if ($this->_isextended) { $this->bmarray[] = $this->splitwords($value); } else $this->bmarray[] = $this->convert2bm(trim(strin($value, '.WORD', 'H'))); } } } function createshow() { global $conf; $x=0; $y=0; // Create visual array foreach ($this->bmarray as $key => $value) { if ($this->_isextended) { foreach ($this->bmarray[$key] as $ikey => $ivalue) { for($i=0; $i < strlen($ivalue); $i++) { $this->showarray[$key] .= ($ivalue[$i] == 1 ? $conf['BIT_SET'] : $conf['BIT_UNSET']); } } } else { for($i=0; $i < strlen($value); $i++) { $this->showarray[$i] .= ($value[$i] == 1 ? $conf['BIT_SET'] : $conf['BIT_UNSET']); } } } if ($this->_isextended) $this->showarray = $this->transpose($this->showarray); } function transpose($array) { $temparray = array(); for ($i=0; $i $value) $str .= $value[$i]; $temparray[$i]=$str; } return $temparray; } function show2raw() { $this->show2bm(); $this->bm2raw(); } function show2bm() { global $conf; $this->bmarray = array(); foreach ($this->showarray as $key => $value) { for($i=0; $i < strlen($value); $i++) { $this->bmarray[$i] = $this->bmarray[$i] . ($value[$i] == $conf['BIT_SET'] ? 1 : 0); } } } function bm2raw() { $this->rawarray = array(); $this->rawarray[0] = $this->_header; foreach ($this->bmarray as $key => $value) { $this->rawarray[] = "\t.WORD\t". $this->convert2hex($value); } } function array2str($array) { $res=''; foreach ($array as $key => $value) { $res .= $value . $this->_newline; } return $res; } function convert2bm($hex) { $res = str_pad( decbin(hexdec($hex)), 16, '0', STR_PAD_LEFT); return $res; } function convert2hex($bm) { if ($this->is_extended) { $tmp = strtoupper(str_pad( dechex(bindec($bm)), 5, '0', STR_PAD_LEFT)); do { $res = strtoupper(str_pad( dechex(bindec($tmp)), 5, '0', STR_PAD_LEFT)).', '; $tmp = $tmp - 0xFFFFF; }while($tmp > 0xFFFFF); } else $res = strtoupper(str_pad( dechex(bindec($bm)), 5, '0', STR_PAD_LEFT)); return $res.'H'; } function displaytxt() { echo $this->array2str($this->showarray); } function savebitmap() { if ($this->is_extended) errmsg('SaveBitmap: Could not save extended bitmap: '. $this->savename , 'ERROR'); else { errmsg('SaveBitmap: Saving: '. $this->savename , 'INFO'); $f = @fopen($this->savename, 'w') or (errmsg('SaveBitMap: Could not write to file: ' . $this->savename, 'ERROR')); fputs($f, $this->array2str($this->rawarray)); fclose($f); } } function saveshow() { errmsg('SaveShow: Saving: '. $this->savename , 'INFO'); $f = @fopen($this->savename, 'w') or (errmsg('SaveShow: Could not write to file: ' . $this->savename, 'ERROR')); fputs($f, $this->array2str($this->showarray)); fclose($f); } function importfromtxt($file) { $f = @fopen($file, 'r') or (errmsg('ImportFromTxt: Could not open file: ' . $file, 'ERROR')); fclose($f); $this->showarray = explode( $this->_newline , implode( $this->_newline, file( $file ) )); $this->show2raw(); } } // End Class Bitmap ?>