286 if (!$this->_fontLoaded) {
300 if (in_array(strtolower($key), $this->_skipOptions)) {
304 $method =
'set' . ucfirst($key);
305 if (method_exists($this,
$method)) {
343 $this->_handleParagraphs = (bool) $handleParagraphs;
356 $this->_justification = min(3, max(0, (
int) $justification));
369 $this->_outputWidth = max(1, (
int) $outputWidth);
383 $this->_rightToLeft = min(1, max(0, (
int) $rightToLeft));
397 $smushMode = (int) $smushMode;
399 if ($smushMode < -1) {
402 if ($smushMode === 0) {
404 }
else if ($smushMode === -1) {
405 $this->_userSmush = 0;
407 $this->_userSmush = (($smushMode & 63) | self::SM_SMUSH);
429 if (!is_string(
$text)) {
430 throw new InvalidArgumentException(
'$text must be a string');
433 if ($encoding !==
'UTF-8') {
438 $this->_outputLine = array();
442 $this->_outlineLengthLimit = ($this->_outputWidth - 1);
443 $this->_inCharLineLengthLimit = ($this->_outputWidth * 4 + 100);
446 $lastCharWasEol =
false;
447 $textLength = @iconv_strlen(
$text,
'UTF-8');
449 if ($textLength ===
false) {
450 #require_once 'Zend/Text/Figlet/Exception.php'; 454 for ($charNum = 0; $charNum < $textLength; $charNum++) {
456 $char = iconv_substr(
$text, $charNum, 1,
'UTF-8');
458 if ($char ===
"\n" && $this->_handleParagraphs && !$lastCharWasEol) {
459 $nextChar = iconv_substr(
$text, ($charNum + 1), 1,
'UTF-8');
464 $char = (ctype_space($nextChar)) ?
"\n" :
' ';
467 $lastCharWasEol = (ctype_space($char) && $char !==
"\t" && $char !==
' ');
469 if (ctype_space($char)) {
470 $char = ($char ===
"\t" || $char ===
' ') ?
' ':
"\n";
474 $ordChar = $this->
_uniOrd($char);
475 if (($ordChar > 0 && $ordChar < 32 && $char !==
"\n") || $ordChar === 127) {
483 $charNotAdded =
false;
485 if ($wordBreakMode === -1) {
488 }
else if ($char ===
"\n") {
496 if ($char ===
"\n") {
498 $wordBreakMode =
false;
499 }
else if ($this->
_addChar($char)) {
501 $wordBreakMode = ($wordBreakMode >= 2) ? 3: 1;
503 $wordBreakMode = ($wordBreakMode > 0) ? 2: 0;
505 }
else if ($this->_outlineLength === 0) {
507 if ($this->_rightToLeft === 1 && $this->_outputWidth > 1) {
509 $this->
_putString(substr($this->_currentChar[
$i], $offset));
516 }
else if ($char ===
' ') {
517 if ($wordBreakMode === 2) {
525 if ($wordBreakMode >= 2) {
531 $wordBreakMode = ($wordBreakMode === 3) ? 1 : 0;
532 $charNotAdded =
true;
534 }
while ($charNotAdded);
537 if ($this->_outlineLength !== 0) {
556 $length = strlen($string);
558 if ($this->_outputWidth > 1) {
559 if ($length > ($this->_outputWidth - 1)) {
560 $length = ($this->_outputWidth - 1);
563 if ($this->_justification > 0) {
567 $this->_output .=
' ';
572 $this->_output .= str_replace($this->_hardBlank,
' ', $string) .
"\n";
599 for (
$i = ($this->_inCharLineLength - 1);
$i >= 0;
$i--) {
600 if (!$gotSpace && $this->_inCharLine[
$i] ===
' ') {
605 if ($gotSpace && $this->_inCharLine[
$i] !==
' ') {
610 $firstLength = (
$i + 1);
611 $lastLength = ($this->_inCharLineLength - $lastSpace - 1);
614 for (
$i = 0;
$i < $firstLength;
$i++) {
615 $firstPart[
$i] = $this->_inCharLine[
$i];
619 for (
$i = 0;
$i < $lastLength;
$i++) {
620 $lastPart[
$i] = $this->_inCharLine[($lastSpace + 1 +
$i)];
625 for (
$i = 0;
$i < $firstLength;
$i++) {
631 for (
$i = 0;
$i < $lastLength;
$i++) {
644 $this->_outputLine[
$i] =
'';
647 $this->_outlineLength = 0;
648 $this->_inCharLineLength = 0;
662 if ($this->_currentChar ===
null) {
668 if (($this->_outlineLength + $this->_currentCharWidth - $smushAmount) > $this->_outlineLengthLimit
669 || ($this->_inCharLineLength + 1) > $this->_inCharLineLengthLimit) {
675 if ($this->_rightToLeft === 1) {
676 $tempLine = $this->_currentChar[
$row];
678 for ($k = 0; $k < $smushAmount; $k++) {
679 $position = ($this->_currentCharWidth - $smushAmount + $k);
680 $tempLine[$position] = $this->
_smushem($tempLine[$position], $this->_outputLine[
$row][$k]);
683 $this->_outputLine[
$row] = $tempLine . substr($this->_outputLine[
$row], $smushAmount);
685 for ($k = 0; $k < $smushAmount; $k++) {
686 if (($this->_outlineLength - $smushAmount + $k) < 0) {
690 $position = ($this->_outlineLength - $smushAmount + $k);
691 if (isset($this->_outputLine[
$row][$position])) {
692 $leftChar = $this->_outputLine[
$row][$position];
697 $this->_outputLine[
$row][$position] = $this->
_smushem($leftChar, $this->_currentChar[
$row][$k]);
700 $this->_outputLine[
$row] .= substr($this->_currentChar[
$row], $smushAmount);
704 $this->_outlineLength = strlen($this->_outputLine[0]);
705 $this->_inCharLine[$this->_inCharLineLength++] = $char;
718 if (array_key_exists($this->
_uniOrd($char), $this->_charList)) {
719 $this->_currentChar = $this->_charList[$this->
_uniOrd($char)];
721 $this->_currentCharWidth = strlen($this->_currentChar[0]);
723 $this->_currentChar =
null;
735 if (($this->_smushMode & (self::SM_SMUSH | self::SM_KERN)) === 0) {
743 if ($this->_rightToLeft === 1) {
744 $charbd = strlen($this->_currentChar[
$row]);
746 if (!isset($this->_currentChar[
$row][$charbd])) {
749 $leftChar = $this->_currentChar[
$row][$charbd];
752 if ($charbd > 0 && ($leftChar ===
null || $leftChar ==
' ')) {
761 if (!isset($this->_outputLine[
$row][$linebd])) {
764 $rightChar = $this->_outputLine[
$row][$linebd];
767 if ($rightChar ===
' ') {
774 $amount = ($linebd + $this->_currentCharWidth - 1 - $charbd);
776 $linebd = strlen($this->_outputLine[
$row]);
778 if (!isset($this->_outputLine[
$row][$linebd])) {
781 $leftChar = $this->_outputLine[
$row][$linebd];
784 if ($linebd > 0 && ($leftChar ===
null || $leftChar ==
' ')) {
793 if (!isset($this->_currentChar[
$row][$charbd])) {
796 $rightChar = $this->_currentChar[
$row][$charbd];
799 if ($rightChar ===
' ') {
806 $amount = ($charbd + $this->_outlineLength - 1 - $linebd);
809 if (empty($leftChar) || $leftChar ===
' ') {
811 }
else if (!empty($rightChar)) {
812 if ($this->
_smushem($leftChar, $rightChar) !==
null) {
817 $maxSmush = min(
$amount, $maxSmush);
844 if ($leftChar ===
' ') {
848 if ($rightChar ===
' ') {
852 if ($this->_previousCharWidth < 2 || $this->_currentCharWidth < 2) {
858 if (($this->_smushMode & self::SM_SMUSH) === 0) {
863 if (($this->_smushMode & 63) === 0) {
865 if ($leftChar ===
' ') {
867 }
else if ($rightChar ===
' ') {
869 }
else if ($leftChar === $this->_hardBlank) {
871 }
else if ($rightChar === $this->_hardBlank) {
873 }
else if ($this->_rightToLeft === 1) {
881 if (($this->_smushMode & self::SM_HARDBLANK) > 0) {
882 if ($leftChar === $this->_hardBlank && $rightChar === $this->_hardBlank) {
887 if ($leftChar === $this->_hardBlank && $rightChar === $this->_hardBlank) {
891 if (($this->_smushMode & self::SM_EQUAL) > 0) {
892 if ($leftChar === $rightChar) {
897 if (($this->_smushMode & self::SM_LOWLINE) > 0) {
898 if ($leftChar ===
'_' && strchr(
'|/\\[]{}()<>', $rightChar) !==
false) {
900 }
else if ($rightChar ===
'_' && strchr(
'|/\\[]{}()<>', $leftChar) !==
false) {
905 if (($this->_smushMode & self::SM_HIERARCHY) > 0) {
906 if ($leftChar ===
'|' && strchr(
'/\\[]{}()<>', $rightChar) !==
false) {
908 }
else if ($rightChar ===
'|' && strchr(
'/\\[]{}()<>', $leftChar) !==
false) {
910 }
else if (strchr(
'/\\', $leftChar) && strchr(
'[]{}()<>', $rightChar) !==
false) {
912 }
else if (strchr(
'/\\', $rightChar) && strchr(
'[]{}()<>', $leftChar) !==
false) {
914 }
else if (strchr(
'[]', $leftChar) && strchr(
'{}()<>', $rightChar) !==
false) {
916 }
else if (strchr(
'[]', $rightChar) && strchr(
'{}()<>', $leftChar) !==
false) {
918 }
else if (strchr(
'{}', $leftChar) && strchr(
'()<>', $rightChar) !==
false) {
920 }
else if (strchr(
'{}', $rightChar) && strchr(
'()<>', $leftChar) !==
false) {
922 }
else if (strchr(
'()', $leftChar) && strchr(
'<>', $rightChar) !==
false) {
924 }
else if (strchr(
'()', $rightChar) && strchr(
'<>', $leftChar) !==
false) {
929 if (($this->_smushMode & self::SM_PAIR) > 0) {
930 if ($leftChar ===
'[' && $rightChar ===
']') {
932 }
else if ($rightChar ===
'[' && $leftChar ===
']') {
934 }
else if ($leftChar ===
'{' && $rightChar ===
'}') {
936 }
else if ($rightChar ===
'{' && $leftChar ===
'}') {
938 }
else if ($leftChar ===
'(' && $rightChar ===
')') {
940 }
else if ($rightChar ===
'(' && $leftChar ===
')') {
945 if (($this->_smushMode & self::SM_BIGX) > 0) {
946 if ($leftChar ===
'/' && $rightChar ===
'\\') {
948 }
else if ($rightChar ===
'/' && $leftChar ===
'\\') {
950 }
else if ($leftChar ===
'>' && $rightChar ===
'<') {
970 if (!file_exists($fontFile)) {
971 #require_once 'Zend/Text/Figlet/Exception.php'; 976 if (substr($fontFile, -3) ===
'.gz') {
978 #require_once 'Zend/Text/Figlet/Exception.php'; 980 .
'gzip compressed font files');
983 $fontFile =
'compress.zlib://' . $fontFile;
990 $fp =
fopen($fontFile,
'rb');
992 #require_once 'Zend/Text/Figlet/Exception.php'; 1005 $numsRead = sscanf(fgets($fp, 1000),
1006 '%*c%c %d %*d %d %d %d %d %d',
1015 if ($magic !== self::FONTFILE_MAGIC_NUMBER || $numsRead < 5) {
1016 #require_once 'Zend/Text/Figlet/Exception.php'; 1021 if ($numsRead < 6) {
1026 if ($numsRead < 7) {
1029 }
else if ($smush < 0) {
1030 $this->_fontSmush = 0;
1032 $this->_fontSmush = (($smush & 31) | self::SM_SMUSH);
1037 $this->_charHeight = max(1, $this->_charHeight);
1038 $this->_maxLength = max(1, $this->_maxLength);
1041 $this->_maxLength += 100;
1047 if ($this->_rightToLeft ===
null) {
1048 $this->_rightToLeft = $rightToLeft;
1052 if ($this->_justification ===
null) {
1057 for ($line = 1; $line <= $cmtLines; $line++) {
1062 for ($asciiCode = 32; $asciiCode < 127; $asciiCode++) {
1063 $this->_charList[$asciiCode] = $this->
_loadChar($fp);
1067 foreach ($this->_germanChars as $uniCode) {
1070 if ($char ===
false) {
1075 if (trim(implode(
'', $char)) !==
'') {
1076 $this->_charList[$uniCode] = $char;
1081 while (!
feof($fp)) {
1083 list($uniCode) = explode(
' ', fgets($fp, 2048));
1085 if (empty($uniCode)) {
1090 if (substr($uniCode, 0, 2) ===
'0x') {
1091 $uniCode = hexdec(substr($uniCode, 2));
1092 }
else if (substr($uniCode, 0, 1) ===
'0' and
1094 substr($uniCode, 0, 2) ===
'-0') {
1095 $uniCode = octdec($uniCode);
1097 $uniCode = (int) $uniCode;
1103 if ($char ===
false) {
1108 $this->_charList[$uniCode] = $char;
1113 $this->_fontLoaded =
true;
1124 if ($this->_smushOverride === self::SMO_NO) {
1126 }
else if ($this->_smushOverride === self::SMO_YES) {
1128 }
else if ($this->_smushOverride === self::SMO_FORCE) {
1143 for (
$i = 0;
$i < 4;
$i++) {
1144 $magic .= fgetc($fp);
1158 $dummy = fgetc($fp);
1159 while ($dummy !==
false && !
feof($fp)) {
1160 if ($dummy ===
"\n") {
1164 if ($dummy ===
"\r") {
1165 $dummy = fgetc($fp);
1167 if (!
feof($fp) && $dummy !==
"\n") {
1168 fseek($fp, -1, SEEK_SET);
1174 $dummy = fgetc($fp);
1193 $line = rtrim(fgets($fp, 2048),
"\r\n");
1195 if (preg_match(
'#(.)\\1?$#', $line,
$result) === 1) {
1196 $line = str_replace(
$result[1],
'', $line);
1217 }
else if ($h < 0xC2) {
1219 }
else if ($h <= 0xDF) {
1220 $ord = (($h & 0x1F) << 6 | (ord($c[1]) & 0x3F));
1221 }
else if ($h <= 0xEF) {
1222 $ord = (($h & 0x0F) << 12 | (ord($c[1]) & 0x3F) << 6 | (ord($c[2]) & 0x3F));
1223 }
else if ($h <= 0xF4) {
1224 $ord = (($h & 0x0F) << 18 | (ord($c[1]) & 0x3F) << 12 |
1225 (ord($c[2]) & 0x3F) << 6 | (ord($c[3]) & 0x3F));
const DIRECTION_LEFT_TO_RIGHT
setHandleParagraphs($handleParagraphs)
const JUSTIFICATION_CENTER
setRightToLeft($rightToLeft)
setOutputWidth($outputWidth)
render($text, $encoding='UTF-8')
defined('MTF_BOOT_FILE')||define('MTF_BOOT_FILE' __FILE__
const DIRECTION_RIGHT_TO_LEFT
const FONTFILE_MAGIC_NUMBER
setConfig(Zend_Config $config)
setJustification($justification)
setOptions(array $options)
__construct($options=null)
const JUSTIFICATION_RIGHT
_smushem($leftChar, $rightChar)