Changeset View
Changeset View
Standalone View
Standalone View
externals/pear-figlet/Text/Figlet.php
Show First 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | function loadFont($filename, $loadgerman = true) | ||||
if (!($fp = fopen($filename, 'rb'))) { | if (!($fp = fopen($filename, 'rb'))) { | ||||
return self::raiseError('Cannot open figlet font file ' . $filename, 2); | return self::raiseError('Cannot open figlet font file ' . $filename, 2); | ||||
} | } | ||||
if (!$compressed) { | if (!$compressed) { | ||||
/* ZIPed font */ | /* ZIPed font */ | ||||
if (fread($fp, 2) == 'PK') { | if (fread($fp, 2) == 'PK') { | ||||
if (!function_exists('zip_open')) { | |||||
return self::raiseError('Cannot load ZIP compressed fonts since' | |||||
. ' ZIP PHP extension is not available.', | |||||
5); | |||||
} | |||||
fclose($fp); | fclose($fp); | ||||
$zip = new ZipArchive(); | |||||
if (!($fp = zip_open($filename))) { | $open_result = $zip->open($filename, ZipArchive::RDONLY); | ||||
return self::raiseError('Cannot open figlet font file ' . $filename, 2); | if ($open_result !== true) { | ||||
return self::raiseError('Cannot open figlet font file ' . | |||||
$filename . ', got error: ' . $open_result, 2); | |||||
} | } | ||||
$name = zip->getNameIndex(0); | |||||
$name = zip_entry_name(zip_read($fp)); | $zip->close(); | ||||
zip_close($fp); | |||||
if (!($fp = fopen('zip://' . realpath($filename) . '#' . $name, 'rb'))) { | if (!($fp = fopen('zip://' . realpath($filename) . '#' . $name, 'rb'))) { | ||||
return self::raiseError('Cannot open figlet font file ' . $filename, 2); | return self::raiseError('Cannot open figlet font file ' . $filename, 2); | ||||
} | } | ||||
$compressed = true; | $compressed = true; | ||||
} else { | } else { | ||||
flock($fp, LOCK_SH); | flock($fp, LOCK_SH); | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | function loadFont($filename, $loadgerman = true) | ||||
if (preg_match('/^\-0x/i', $i)) { | if (preg_match('/^\-0x/i', $i)) { | ||||
$this->_skip($fp); | $this->_skip($fp); | ||||
} else { | } else { | ||||
// If Unicode | // If Unicode | ||||
if (preg_match('/^0x/i', $i)) { | if (preg_match('/^0x/i', $i)) { | ||||
$i = hexdec(substr($i, 2)); | $i = hexdec(substr($i, 2)); | ||||
} else { | } else { | ||||
// If octal | // If octal | ||||
if ($i{0} === '0' && $i !== '0' || substr($i, 0, 2) == '-0') { | if ($i[0] === '0' && $i !== '0' || substr($i, 0, 2) == '-0') { | ||||
$i = octdec($i); | $i = octdec($i); | ||||
} | } | ||||
} | } | ||||
$letter = $this->_char($fp); | $letter = $this->_char($fp); | ||||
// Invalid character but main font is loaded and I can use it | // Invalid character but main font is loaded and I can use it | ||||
if ($letter === false) { | if ($letter === false) { | ||||
Show All 26 Lines | function lineEcho($str, $inhtml = false) | ||||
$out = array(); | $out = array(); | ||||
for ($i = 0; $i<strlen($str); $i++) { | for ($i = 0; $i<strlen($str); $i++) { | ||||
// Pseudo Unicode support | // Pseudo Unicode support | ||||
if (substr($str, $i, 2) == '%u') { | if (substr($str, $i, 2) == '%u') { | ||||
$lt = hexdec(substr($str, $i+2, 4)); | $lt = hexdec(substr($str, $i+2, 4)); | ||||
$i += 5; | $i += 5; | ||||
} else { | } else { | ||||
$lt = ord($str{$i}); | $lt = ord($str[$i]); | ||||
} | } | ||||
$hb = preg_quote($this->hardblank, '/'); | $hb = preg_quote($this->hardblank, '/'); | ||||
$sp = "$hb\\x00\\s"; | $sp = "$hb\\x00\\s"; | ||||
// If chosen character not found try to use default | // If chosen character not found try to use default | ||||
// If default character is not defined skip it | // If default character is not defined skip it | ||||
▲ Show 20 Lines • Show All 206 Lines • ▼ Show 20 Lines | function _skip(&$fp) | ||||
return true; | return true; | ||||
} | } | ||||
private static function raiseError($message, $code = 1) { | private static function raiseError($message, $code = 1) { | ||||
throw new Exception($message); | throw new Exception($message); | ||||
} | } | ||||
} | } | ||||
No newline at end of file |