Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Zend_Text_Figlet Class Reference

Public Member Functions

 __construct ($options=null)
 
 setOptions (array $options)
 
 setConfig (Zend_Config $config)
 
 setFont ($font)
 
 setHandleParagraphs ($handleParagraphs)
 
 setJustification ($justification)
 
 setOutputWidth ($outputWidth)
 
 setRightToLeft ($rightToLeft)
 
 setSmushMode ($smushMode)
 
 render ($text, $encoding='UTF-8')
 

Data Fields

const SM_EQUAL = 0x01
 
const SM_LOWLINE = 0x02
 
const SM_HIERARCHY = 0x04
 
const SM_PAIR = 0x08
 
const SM_BIGX = 0x10
 
const SM_HARDBLANK = 0x20
 
const SM_KERN = 0x40
 
const SM_SMUSH = 0x80
 
const SMO_NO = 0
 
const SMO_YES = 1
 
const SMO_FORCE = 2
 
const JUSTIFICATION_LEFT = 0
 
const JUSTIFICATION_CENTER = 1
 
const JUSTIFICATION_RIGHT = 2
 
const DIRECTION_LEFT_TO_RIGHT = 0
 
const DIRECTION_RIGHT_TO_LEFT = 1
 
const FONTFILE_MAGIC_NUMBER = 'flf2'
 

Protected Member Functions

 _putString ($string)
 
 _appendLine ()
 
 _splitLine ()
 
 _clearLine ()
 
 _addChar ($char)
 
 _getLetter ($char)
 
 _smushAmount ()
 
 _smushem ($leftChar, $rightChar)
 
 _loadFont ($fontFile)
 
 _setUsedSmush ()
 
 _readMagic ($fp)
 
 _skipToEol ($fp)
 
 _loadChar ($fp)
 
 _uniOrd ($c)
 

Protected Attributes

 $_charList = array()
 
 $_fontLoaded = false
 
 $_germanChars = array(196, 214, 220, 228, 246, 252, 223)
 
 $_outputWidth = 80
 
 $_hardBlank
 
 $_charHeight
 
 $_maxLength
 
 $_smushMode = 0
 
 $_fontSmush = 0
 
 $_userSmush = 0
 
 $_handleParagraphs = false
 
 $_justification = null
 
 $_rightToLeft = null
 
 $_smushOverride = 0
 
 $_fontOptions = array()
 
 $_previousCharWidth = 0
 
 $_currentCharWidth = 0
 
 $_outlineLength = 0
 
 $_outlineLengthLimit = 0
 
 $_inCharLine
 
 $_inCharLineLength = 0
 
 $_inCharLineLengthLimit = 0
 
 $_currentChar = null
 
 $_outputLine
 
 $_output
 
 $_skipOptions
 

Detailed Description

Definition at line 30 of file Figlet.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $options = null)

Instantiate the FIGlet with a specific font. If no font is given, the standard font is used. You can also supply multiple options via the $options variable, which can either be an array or an instance of Zend_Config.

Parameters
array | Zend_Config$optionsOptions for the output

Definition at line 276 of file Figlet.php.

277  {
278  // Set options
279  if (is_array($options)) {
280  $this->setOptions($options);
281  } else if ($options instanceof Zend_Config) {
282  $this->setConfig($options);
283  }
284 
285  // If no font was defined, load default font
286  if (!$this->_fontLoaded) {
287  $this->_loadFont(dirname(__FILE__) . '/Figlet/zend-framework.flf');
288  }
289  }
defined('MTF_BOOT_FILE')||define('MTF_BOOT_FILE' __FILE__
Definition: bootstrap.php:7
setConfig(Zend_Config $config)
Definition: Figlet.php:318
setOptions(array $options)
Definition: Figlet.php:297
_loadFont($fontFile)
Definition: Figlet.php:967

Member Function Documentation

◆ _addChar()

_addChar (   $char)
protected

Attempts to add the given character onto the end of the current line. Returns true if this can be done, false otherwise.

Parameters
string$charCharacter which to add to the output
Returns
boolean

Definition at line 658 of file Figlet.php.

659  {
660  $this->_getLetter($char);
661 
662  if ($this->_currentChar === null) {
663  return true;
664  }
665 
666  $smushAmount = $this->_smushAmount();
667 
668  if (($this->_outlineLength + $this->_currentCharWidth - $smushAmount) > $this->_outlineLengthLimit
669  || ($this->_inCharLineLength + 1) > $this->_inCharLineLengthLimit) {
670  return false;
671  }
672 
673  $tempLine = '';
674  for ($row = 0; $row < $this->_charHeight; $row++) {
675  if ($this->_rightToLeft === 1) {
676  $tempLine = $this->_currentChar[$row];
677 
678  for ($k = 0; $k < $smushAmount; $k++) {
679  $position = ($this->_currentCharWidth - $smushAmount + $k);
680  $tempLine[$position] = $this->_smushem($tempLine[$position], $this->_outputLine[$row][$k]);
681  }
682 
683  $this->_outputLine[$row] = $tempLine . substr($this->_outputLine[$row], $smushAmount);
684  } else {
685  for ($k = 0; $k < $smushAmount; $k++) {
686  if (($this->_outlineLength - $smushAmount + $k) < 0) {
687  continue;
688  }
689 
690  $position = ($this->_outlineLength - $smushAmount + $k);
691  if (isset($this->_outputLine[$row][$position])) {
692  $leftChar = $this->_outputLine[$row][$position];
693  } else {
694  $leftChar = null;
695  }
696 
697  $this->_outputLine[$row][$position] = $this->_smushem($leftChar, $this->_currentChar[$row][$k]);
698  }
699 
700  $this->_outputLine[$row] .= substr($this->_currentChar[$row], $smushAmount);
701  }
702  }
703 
704  $this->_outlineLength = strlen($this->_outputLine[0]);
705  $this->_inCharLine[$this->_inCharLineLength++] = $char;
706 
707  return true;
708  }
_getLetter($char)
Definition: Figlet.php:716
_smushem($leftChar, $rightChar)
Definition: Figlet.php:842

◆ _appendLine()

_appendLine ( )
protected

Appends the current line to the output

Returns
void

Definition at line 580 of file Figlet.php.

581  {
582  for ($i = 0; $i < $this->_charHeight; $i++) {
583  $this->_putString($this->_outputLine[$i]);
584  }
585 
586  $this->_clearLine();
587  }
_putString($string)
Definition: Figlet.php:554
$i
Definition: gallery.phtml:31

◆ _clearLine()

_clearLine ( )
protected

Clears the current line

Returns
void

Definition at line 641 of file Figlet.php.

642  {
643  for ($i = 0; $i < $this->_charHeight; $i++) {
644  $this->_outputLine[$i] = '';
645  }
646 
647  $this->_outlineLength = 0;
648  $this->_inCharLineLength = 0;
649  }
$i
Definition: gallery.phtml:31

◆ _getLetter()

_getLetter (   $char)
protected

Gets the requested character and sets current and previous char width.

Parameters
string$charThe character from which to get the letter of
Returns
void

Definition at line 716 of file Figlet.php.

717  {
718  if (array_key_exists($this->_uniOrd($char), $this->_charList)) {
719  $this->_currentChar = $this->_charList[$this->_uniOrd($char)];
720  $this->_previousCharWidth = $this->_currentCharWidth;
721  $this->_currentCharWidth = strlen($this->_currentChar[0]);
722  } else {
723  $this->_currentChar = null;
724  }
725  }

◆ _loadChar()

_loadChar (   $fp)
protected

Load a single character from the font file

Parameters
resource$fpFile pointer to the font file
Returns
array

Definition at line 1184 of file Figlet.php.

1185  {
1186  $char = array();
1187 
1188  for ($i = 0; $i < $this->_charHeight; $i++) {
1189  if (feof($fp)) {
1190  return false;
1191  }
1192 
1193  $line = rtrim(fgets($fp, 2048), "\r\n");
1194 
1195  if (preg_match('#(.)\\1?$#', $line, $result) === 1) {
1196  $line = str_replace($result[1], '', $line);
1197  }
1198 
1199  $char[] = $line;
1200  }
1201 
1202  return $char;
1203  }
$i
Definition: gallery.phtml:31

◆ _loadFont()

_loadFont (   $fontFile)
protected

Load the specified font

Parameters
string$fontFileFont file to load
Exceptions
Zend_Text_Figlet_ExceptionWhen font file was not found
Zend_Text_Figlet_ExceptionWhen GZIP library is required but not found
Zend_Text_Figlet_ExceptionWhen font file is not readable
Returns
void

Definition at line 967 of file Figlet.php.

968  {
969  // Check if the font file exists
970  if (!file_exists($fontFile)) {
971  #require_once 'Zend/Text/Figlet/Exception.php';
972  throw new Zend_Text_Figlet_Exception($fontFile . ': Font file not found');
973  }
974 
975  // Check if gzip support is required
976  if (substr($fontFile, -3) === '.gz') {
977  if (!function_exists('gzcompress')) {
978  #require_once 'Zend/Text/Figlet/Exception.php';
979  throw new Zend_Text_Figlet_Exception('GZIP library is required for '
980  . 'gzip compressed font files');
981  }
982 
983  $fontFile = 'compress.zlib://' . $fontFile;
984  $compressed = true;
985  } else {
986  $compressed = false;
987  }
988 
989  // Try to open the file
990  $fp = fopen($fontFile, 'rb');
991  if ($fp === false) {
992  #require_once 'Zend/Text/Figlet/Exception.php';
993  throw new Zend_Text_Figlet_Exception($fontFile . ': Could not open file');
994  }
995 
996  // If the file is not compressed, lock the stream
997  if (!$compressed) {
998  flock($fp, LOCK_SH);
999  }
1000 
1001  // Get magic
1002  $magic = $this->_readMagic($fp);
1003 
1004  // Get the header
1005  $numsRead = sscanf(fgets($fp, 1000),
1006  '%*c%c %d %*d %d %d %d %d %d',
1007  $this->_hardBlank,
1008  $this->_charHeight,
1009  $this->_maxLength,
1010  $smush,
1011  $cmtLines,
1012  $rightToLeft,
1013  $this->_fontSmush);
1014 
1015  if ($magic !== self::FONTFILE_MAGIC_NUMBER || $numsRead < 5) {
1016  #require_once 'Zend/Text/Figlet/Exception.php';
1017  throw new Zend_Text_Figlet_Exception($fontFile . ': Not a FIGlet 2 font file');
1018  }
1019 
1020  // Set default right to left
1021  if ($numsRead < 6) {
1022  $rightToLeft = 0;
1023  }
1024 
1025  // If no smush2, decode smush into smush2
1026  if ($numsRead < 7) {
1027  if ($smush === 2) {
1028  $this->_fontSmush = self::SM_KERN;
1029  } else if ($smush < 0) {
1030  $this->_fontSmush = 0;
1031  } else {
1032  $this->_fontSmush = (($smush & 31) | self::SM_SMUSH);
1033  }
1034  }
1035 
1036  // Correct char height && maxlength
1037  $this->_charHeight = max(1, $this->_charHeight);
1038  $this->_maxLength = max(1, $this->_maxLength);
1039 
1040  // Give ourselves some extra room
1041  $this->_maxLength += 100;
1042 
1043  // See if we have to override smush settings
1044  $this->_setUsedSmush();
1045 
1046  // Get left to right value
1047  if ($this->_rightToLeft === null) {
1048  $this->_rightToLeft = $rightToLeft;
1049  }
1050 
1051  // Get justification value
1052  if ($this->_justification === null) {
1053  $this->_justification = (2 * $this->_rightToLeft);
1054  }
1055 
1056  // Skip all comment lines
1057  for ($line = 1; $line <= $cmtLines; $line++) {
1058  $this->_skipToEol($fp);
1059  }
1060 
1061  // Fetch all ASCII characters
1062  for ($asciiCode = 32; $asciiCode < 127; $asciiCode++) {
1063  $this->_charList[$asciiCode] = $this->_loadChar($fp);
1064  }
1065 
1066  // Fetch all german characters
1067  foreach ($this->_germanChars as $uniCode) {
1068  $char = $this->_loadChar($fp);
1069 
1070  if ($char === false) {
1071  fclose($fp);
1072  return;
1073  }
1074 
1075  if (trim(implode('', $char)) !== '') {
1076  $this->_charList[$uniCode] = $char;
1077  }
1078  }
1079 
1080  // At the end fetch all extended characters
1081  while (!feof($fp)) {
1082  // Get the Unicode
1083  list($uniCode) = explode(' ', fgets($fp, 2048));
1084 
1085  if (empty($uniCode)) {
1086  continue;
1087  }
1088 
1089  // Convert it if required
1090  if (substr($uniCode, 0, 2) === '0x') {
1091  $uniCode = hexdec(substr($uniCode, 2));
1092  } else if (substr($uniCode, 0, 1) === '0' and
1093  $uniCode !== '0' or
1094  substr($uniCode, 0, 2) === '-0') {
1095  $uniCode = octdec($uniCode);
1096  } else {
1097  $uniCode = (int) $uniCode;
1098  }
1099 
1100  // Now fetch the character
1101  $char = $this->_loadChar($fp);
1102 
1103  if ($char === false) {
1104  fclose($fp);
1105  return;
1106  }
1107 
1108  $this->_charList[$uniCode] = $char;
1109  }
1110 
1111  fclose($fp);
1112 
1113  $this->_fontLoaded = true;
1114  }
const SM_KERN
Definition: Figlet.php:41

◆ _putString()

_putString (   $string)
protected

Puts the given string, substituting blanks for hardblanks. If outputWidth is 1, puts the entire string; otherwise puts at most outputWidth - 1 characters. Puts a newline at the end of the string. The string is left- justified, centered or right-justified (taking outputWidth as the screen width) if justification is 0, 1 or 2 respectively.

Parameters
string$stringThe string to add to the output
Returns
void

Definition at line 554 of file Figlet.php.

555  {
556  $length = strlen($string);
557 
558  if ($this->_outputWidth > 1) {
559  if ($length > ($this->_outputWidth - 1)) {
560  $length = ($this->_outputWidth - 1);
561  }
562 
563  if ($this->_justification > 0) {
564  for ($i = 1;
565  ((3 - $this->_justification) * $i + $length + $this->_justification - 2) < $this->_outputWidth;
566  $i++) {
567  $this->_output .= ' ';
568  }
569  }
570  }
571 
572  $this->_output .= str_replace($this->_hardBlank, ' ', $string) . "\n";
573  }
$i
Definition: gallery.phtml:31

◆ _readMagic()

_readMagic (   $fp)
protected

Reads a four-character magic string from a stream

Parameters
resource$fpFile pointer to the font file
Returns
string

Definition at line 1139 of file Figlet.php.

1140  {
1141  $magic = '';
1142 
1143  for ($i = 0; $i < 4; $i++) {
1144  $magic .= fgetc($fp);
1145  }
1146 
1147  return $magic;
1148  }
$i
Definition: gallery.phtml:31

◆ _setUsedSmush()

_setUsedSmush ( )
protected

Set the used smush mode, according to smush override, user smsush and font smush.

Returns
void

Definition at line 1122 of file Figlet.php.

1123  {
1124  if ($this->_smushOverride === self::SMO_NO) {
1125  $this->_smushMode = $this->_fontSmush;
1126  } else if ($this->_smushOverride === self::SMO_YES) {
1127  $this->_smushMode = $this->_userSmush;
1128  } else if ($this->_smushOverride === self::SMO_FORCE) {
1129  $this->_smushMode = ($this->_fontSmush | $this->_userSmush);
1130  }
1131  }

◆ _skipToEol()

_skipToEol (   $fp)
protected

Skip a stream to the end of line

Parameters
resource$fpFile pointer to the font file
Returns
void

Definition at line 1156 of file Figlet.php.

1157  {
1158  $dummy = fgetc($fp);
1159  while ($dummy !== false && !feof($fp)) {
1160  if ($dummy === "\n") {
1161  return;
1162  }
1163 
1164  if ($dummy === "\r") {
1165  $dummy = fgetc($fp);
1166 
1167  if (!feof($fp) && $dummy !== "\n") {
1168  fseek($fp, -1, SEEK_SET);
1169  }
1170 
1171  return;
1172  }
1173 
1174  $dummy = fgetc($fp);
1175  }
1176  }

◆ _smushAmount()

_smushAmount ( )
protected

Returns the maximum amount that the current character can be smushed into the current line.

Returns
integer

Definition at line 733 of file Figlet.php.

734  {
735  if (($this->_smushMode & (self::SM_SMUSH | self::SM_KERN)) === 0) {
736  return 0;
737  }
738 
739  $maxSmush = $this->_currentCharWidth;
740  $amount = $maxSmush;
741 
742  for ($row = 0; $row < $this->_charHeight; $row++) {
743  if ($this->_rightToLeft === 1) {
744  $charbd = strlen($this->_currentChar[$row]);
745  while (true) {
746  if (!isset($this->_currentChar[$row][$charbd])) {
747  $leftChar = null;
748  } else {
749  $leftChar = $this->_currentChar[$row][$charbd];
750  }
751 
752  if ($charbd > 0 && ($leftChar === null || $leftChar == ' ')) {
753  $charbd--;
754  } else {
755  break;
756  }
757  }
758 
759  $linebd = 0;
760  while (true) {
761  if (!isset($this->_outputLine[$row][$linebd])) {
762  $rightChar = null;
763  } else {
764  $rightChar = $this->_outputLine[$row][$linebd];
765  }
766 
767  if ($rightChar === ' ') {
768  $linebd++;
769  } else {
770  break;
771  }
772  }
773 
774  $amount = ($linebd + $this->_currentCharWidth - 1 - $charbd);
775  } else {
776  $linebd = strlen($this->_outputLine[$row]);
777  while (true) {
778  if (!isset($this->_outputLine[$row][$linebd])) {
779  $leftChar = null;
780  } else {
781  $leftChar = $this->_outputLine[$row][$linebd];
782  }
783 
784  if ($linebd > 0 && ($leftChar === null || $leftChar == ' ')) {
785  $linebd--;
786  } else {
787  break;
788  }
789  }
790 
791  $charbd = 0;
792  while (true) {
793  if (!isset($this->_currentChar[$row][$charbd])) {
794  $rightChar = null;
795  } else {
796  $rightChar = $this->_currentChar[$row][$charbd];
797  }
798 
799  if ($rightChar === ' ') {
800  $charbd++;
801  } else {
802  break;
803  }
804  }
805 
806  $amount = ($charbd + $this->_outlineLength - 1 - $linebd);
807  }
808 
809  if (empty($leftChar) || $leftChar === ' ') {
810  $amount++;
811  } else if (!empty($rightChar)) {
812  if ($this->_smushem($leftChar, $rightChar) !== null) {
813  $amount++;
814  }
815  }
816 
817  $maxSmush = min($amount, $maxSmush);
818  }
819 
820  return $maxSmush;
821  }
$amount
Definition: order.php:14
_smushem($leftChar, $rightChar)
Definition: Figlet.php:842

◆ _smushem()

_smushem (   $leftChar,
  $rightChar 
)
protected

Given two characters, attempts to smush them into one, according to the current smushmode. Returns smushed character or false if no smushing can be done.

Smushmode values are sum of following (all values smush blanks):

1: Smush equal chars (not hardblanks) 2: Smush '_' with any char in hierarchy below 4: hierarchy: "|", "/\", "[]", "{}", "()", "<>" Each class in hier. can be replaced by later class. 8: [ + ] -> |, { + } -> |, ( + ) -> | 16: / + \ -> X, > + < -> X (only in that order) 32: hardblank + hardblank -> hardblank

Parameters
string$leftCharLeft character to smush
string$rightCharRight character to smush
Returns
string

Definition at line 842 of file Figlet.php.

843  {
844  if ($leftChar === ' ') {
845  return $rightChar;
846  }
847 
848  if ($rightChar === ' ') {
849  return $leftChar;
850  }
851 
852  if ($this->_previousCharWidth < 2 || $this->_currentCharWidth < 2) {
853  // Disallows overlapping if the previous character or the current
854  // character has a width of one or zero.
855  return null;
856  }
857 
858  if (($this->_smushMode & self::SM_SMUSH) === 0) {
859  // Kerning
860  return null;
861  }
862 
863  if (($this->_smushMode & 63) === 0) {
864  // This is smushing by universal overlapping
865  if ($leftChar === ' ') {
866  return $rightChar;
867  } else if ($rightChar === ' ') {
868  return $leftChar;
869  } else if ($leftChar === $this->_hardBlank) {
870  return $rightChar;
871  } else if ($rightChar === $this->_hardBlank) {
872  return $rightChar;
873  } else if ($this->_rightToLeft === 1) {
874  return $leftChar;
875  } else {
876  // Occurs in the absence of above exceptions
877  return $rightChar;
878  }
879  }
880 
881  if (($this->_smushMode & self::SM_HARDBLANK) > 0) {
882  if ($leftChar === $this->_hardBlank && $rightChar === $this->_hardBlank) {
883  return $leftChar;
884  }
885  }
886 
887  if ($leftChar === $this->_hardBlank && $rightChar === $this->_hardBlank) {
888  return null;
889  }
890 
891  if (($this->_smushMode & self::SM_EQUAL) > 0) {
892  if ($leftChar === $rightChar) {
893  return $leftChar;
894  }
895  }
896 
897  if (($this->_smushMode & self::SM_LOWLINE) > 0) {
898  if ($leftChar === '_' && strchr('|/\\[]{}()<>', $rightChar) !== false) {
899  return $rightChar;
900  } else if ($rightChar === '_' && strchr('|/\\[]{}()<>', $leftChar) !== false) {
901  return $leftChar;
902  }
903  }
904 
905  if (($this->_smushMode & self::SM_HIERARCHY) > 0) {
906  if ($leftChar === '|' && strchr('/\\[]{}()<>', $rightChar) !== false) {
907  return $rightChar;
908  } else if ($rightChar === '|' && strchr('/\\[]{}()<>', $leftChar) !== false) {
909  return $leftChar;
910  } else if (strchr('/\\', $leftChar) && strchr('[]{}()<>', $rightChar) !== false) {
911  return $rightChar;
912  } else if (strchr('/\\', $rightChar) && strchr('[]{}()<>', $leftChar) !== false) {
913  return $leftChar;
914  } else if (strchr('[]', $leftChar) && strchr('{}()<>', $rightChar) !== false) {
915  return $rightChar;
916  } else if (strchr('[]', $rightChar) && strchr('{}()<>', $leftChar) !== false) {
917  return $leftChar;
918  } else if (strchr('{}', $leftChar) && strchr('()<>', $rightChar) !== false) {
919  return $rightChar;
920  } else if (strchr('{}', $rightChar) && strchr('()<>', $leftChar) !== false) {
921  return $leftChar;
922  } else if (strchr('()', $leftChar) && strchr('<>', $rightChar) !== false) {
923  return $rightChar;
924  } else if (strchr('()', $rightChar) && strchr('<>', $leftChar) !== false) {
925  return $leftChar;
926  }
927  }
928 
929  if (($this->_smushMode & self::SM_PAIR) > 0) {
930  if ($leftChar === '[' && $rightChar === ']') {
931  return '|';
932  } else if ($rightChar === '[' && $leftChar === ']') {
933  return '|';
934  } else if ($leftChar === '{' && $rightChar === '}') {
935  return '|';
936  } else if ($rightChar === '{' && $leftChar === '}') {
937  return '|';
938  } else if ($leftChar === '(' && $rightChar === ')') {
939  return '|';
940  } else if ($rightChar === '(' && $leftChar === ')') {
941  return '|';
942  }
943  }
944 
945  if (($this->_smushMode & self::SM_BIGX) > 0) {
946  if ($leftChar === '/' && $rightChar === '\\') {
947  return '|';
948  } else if ($rightChar === '/' && $leftChar === '\\') {
949  return 'Y';
950  } else if ($leftChar === '>' && $rightChar === '<') {
951  return 'X';
952  }
953  }
954 
955  return null;
956  }

◆ _splitLine()

_splitLine ( )
protected

Splits inCharLine at the last word break (bunch of consecutive blanks). Makes a new line out of the first part and appends it using appendLine(). Makes a new line out of the second part and returns.

Returns
void

Definition at line 596 of file Figlet.php.

597  {
598  $gotSpace = false;
599  for ($i = ($this->_inCharLineLength - 1); $i >= 0; $i--) {
600  if (!$gotSpace && $this->_inCharLine[$i] === ' ') {
601  $gotSpace = true;
602  $lastSpace = $i;
603  }
604 
605  if ($gotSpace && $this->_inCharLine[$i] !== ' ') {
606  break;
607  }
608  }
609 
610  $firstLength = ($i + 1);
611  $lastLength = ($this->_inCharLineLength - $lastSpace - 1);
612 
613  $firstPart = '';
614  for ($i = 0; $i < $firstLength; $i++) {
615  $firstPart[$i] = $this->_inCharLine[$i];
616  }
617 
618  $lastPart = '';
619  for ($i = 0; $i < $lastLength; $i++) {
620  $lastPart[$i] = $this->_inCharLine[($lastSpace + 1 + $i)];
621  }
622 
623  $this->_clearLine();
624 
625  for ($i = 0; $i < $firstLength; $i++) {
626  $this->_addChar($firstPart[$i]);
627  }
628 
629  $this->_appendLine();
630 
631  for ($i = 0; $i < $lastLength; $i++) {
632  $this->_addChar($lastPart[$i]);
633  }
634  }
$i
Definition: gallery.phtml:31
_addChar($char)
Definition: Figlet.php:658

◆ _uniOrd()

_uniOrd (   $c)
protected

Unicode compatible ord() method

Parameters
string$cThe char to get the value from
Returns
integer

Definition at line 1211 of file Figlet.php.

1212  {
1213  $h = ord($c[0]);
1214 
1215  if ($h <= 0x7F) {
1216  $ord = $h;
1217  } else if ($h < 0xC2) {
1218  $ord = 0;
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));
1226  } else {
1227  $ord = 0;
1228  }
1229 
1230  return $ord;
1231  }

◆ render()

render (   $text,
  $encoding = 'UTF-8' 
)

Render a FIGlet text

Parameters
string$textText to convert to a figlet text
string$encodingEncoding of the input string
Exceptions
InvalidArgumentExceptionWhen $text is not a string
Zend_Text_Figlet_ExceptionWhen $text it not properly encoded
Returns
string

Definition at line 427 of file Figlet.php.

428  {
429  if (!is_string($text)) {
430  throw new InvalidArgumentException('$text must be a string');
431  }
432 
433  if ($encoding !== 'UTF-8') {
434  $text = iconv($encoding, 'UTF-8', $text);
435  }
436 
437  $this->_output = '';
438  $this->_outputLine = array();
439 
440  $this->_clearLine();
441 
442  $this->_outlineLengthLimit = ($this->_outputWidth - 1);
443  $this->_inCharLineLengthLimit = ($this->_outputWidth * 4 + 100);
444 
445  $wordBreakMode = 0;
446  $lastCharWasEol = false;
447  $textLength = @iconv_strlen($text, 'UTF-8');
448 
449  if ($textLength === false) {
450  #require_once 'Zend/Text/Figlet/Exception.php';
451  throw new Zend_Text_Figlet_Exception('$text is not encoded with ' . $encoding);
452  }
453 
454  for ($charNum = 0; $charNum < $textLength; $charNum++) {
455  // Handle paragraphs
456  $char = iconv_substr($text, $charNum, 1, 'UTF-8');
457 
458  if ($char === "\n" && $this->_handleParagraphs && !$lastCharWasEol) {
459  $nextChar = iconv_substr($text, ($charNum + 1), 1, 'UTF-8');
460  if (!$nextChar) {
461  $nextChar = null;
462  }
463 
464  $char = (ctype_space($nextChar)) ? "\n" : ' ';
465  }
466 
467  $lastCharWasEol = (ctype_space($char) && $char !== "\t" && $char !== ' ');
468 
469  if (ctype_space($char)) {
470  $char = ($char === "\t" || $char === ' ') ? ' ': "\n";
471  }
472 
473  // Skip unprintable characters
474  $ordChar = $this->_uniOrd($char);
475  if (($ordChar > 0 && $ordChar < 32 && $char !== "\n") || $ordChar === 127) {
476  continue;
477  }
478 
479  // Build the character
480  // Note: The following code is complex and thoroughly tested.
481  // Be careful when modifying!
482  do {
483  $charNotAdded = false;
484 
485  if ($wordBreakMode === -1) {
486  if ($char === ' ') {
487  break;
488  } else if ($char === "\n") {
489  $wordBreakMode = 0;
490  break;
491  }
492 
493  $wordBreakMode = 0;
494  }
495 
496  if ($char === "\n") {
497  $this->_appendLine();
498  $wordBreakMode = false;
499  } else if ($this->_addChar($char)) {
500  if ($char !== ' ') {
501  $wordBreakMode = ($wordBreakMode >= 2) ? 3: 1;
502  } else {
503  $wordBreakMode = ($wordBreakMode > 0) ? 2: 0;
504  }
505  } else if ($this->_outlineLength === 0) {
506  for ($i = 0; $i < $this->_charHeight; $i++) {
507  if ($this->_rightToLeft === 1 && $this->_outputWidth > 1) {
508  $offset = (strlen($this->_currentChar[$i]) - $this->_outlineLengthLimit);
509  $this->_putString(substr($this->_currentChar[$i], $offset));
510  } else {
511  $this->_putString($this->_currentChar[$i]);
512  }
513  }
514 
515  $wordBreakMode = -1;
516  } else if ($char === ' ') {
517  if ($wordBreakMode === 2) {
518  $this->_splitLine();
519  } else {
520  $this->_appendLine();
521  }
522 
523  $wordBreakMode = -1;
524  } else {
525  if ($wordBreakMode >= 2) {
526  $this->_splitLine();
527  } else {
528  $this->_appendLine();
529  }
530 
531  $wordBreakMode = ($wordBreakMode === 3) ? 1 : 0;
532  $charNotAdded = true;
533  }
534  } while ($charNotAdded);
535  }
536 
537  if ($this->_outlineLength !== 0) {
538  $this->_appendLine();
539  }
540 
541  return $this->_output;
542  }
endifif( $block->getLastPageNum()>1)( 'Page') ?></strong >< ul class $text
Definition: pager.phtml:43
_putString($string)
Definition: Figlet.php:554
$i
Definition: gallery.phtml:31
_addChar($char)
Definition: Figlet.php:658

◆ setConfig()

setConfig ( Zend_Config  $config)

Set options from config object

Parameters
Zend_Config$configConfiguration for Zend_Text_Figlet
Returns
Zend_Text_Figlet

Definition at line 318 of file Figlet.php.

319  {
320  return $this->setOptions($config->toArray());
321  }
setOptions(array $options)
Definition: Figlet.php:297

◆ setFont()

setFont (   $font)

Set a font to use

Parameters
string$fontPath to the font
Returns
Zend_Text_Figlet

Definition at line 329 of file Figlet.php.

330  {
331  $this->_loadFont($font);
332  return $this;
333  }
_loadFont($fontFile)
Definition: Figlet.php:967

◆ setHandleParagraphs()

setHandleParagraphs (   $handleParagraphs)

Set handling of paragraphs

Parameters
boolean$handleParagraphsWether to handle paragraphs or not
Returns
Zend_Text_Figlet

Definition at line 341 of file Figlet.php.

342  {
343  $this->_handleParagraphs = (bool) $handleParagraphs;
344  return $this;
345  }

◆ setJustification()

setJustification (   $justification)

Set the justification. 0 stands for left aligned, 1 for centered and 2 for right aligned.

Parameters
integer$justificationJustification of the output text
Returns
Zend_Text_Figlet

Definition at line 354 of file Figlet.php.

355  {
356  $this->_justification = min(3, max(0, (int) $justification));
357  return $this;
358  }

◆ setOptions()

setOptions ( array  $options)

Set options from array

Parameters
array$optionsConfiguration for Zend_Text_Figlet
Returns
Zend_Text_Figlet

Definition at line 297 of file Figlet.php.

298  {
299  foreach ($options as $key => $value) {
300  if (in_array(strtolower($key), $this->_skipOptions)) {
301  continue;
302  }
303 
304  $method = 'set' . ucfirst($key);
305  if (method_exists($this, $method)) {
306  $this->$method($value);
307  }
308  }
309  return $this;
310  }
$value
Definition: gender.phtml:16
$method
Definition: info.phtml:13

◆ setOutputWidth()

setOutputWidth (   $outputWidth)

Set the output width

Parameters
integer$outputWidthOutput with which should be used for word wrapping and justification
Returns
Zend_Text_Figlet

Definition at line 367 of file Figlet.php.

368  {
369  $this->_outputWidth = max(1, (int) $outputWidth);
370  return $this;
371  }

◆ setRightToLeft()

setRightToLeft (   $rightToLeft)

Set right to left mode. For writing from left to right, use Zend_Text_Figlet::DIRECTION_LEFT_TO_RIGHT. For writing from right to left, use Zend_Text_Figlet::DIRECTION_RIGHT_TO_LEFT.

Parameters
integer$rightToLeftRight-to-left mode
Returns
Zend_Text_Figlet

Definition at line 381 of file Figlet.php.

382  {
383  $this->_rightToLeft = min(1, max(0, (int) $rightToLeft));
384  return $this;
385  }

◆ setSmushMode()

setSmushMode (   $smushMode)

Set the smush mode.

Use one of the constants of Zend_Text_Figlet::SM_*, you may combine them.

Parameters
integer$smushModeSmush mode to use for generating text
Returns
Zend_Text_Figlet

Definition at line 395 of file Figlet.php.

396  {
397  $smushMode = (int) $smushMode;
398 
399  if ($smushMode < -1) {
400  $this->_smushOverride = self::SMO_NO;
401  } else {
402  if ($smushMode === 0) {
403  $this->_userSmush = self::SM_KERN;
404  } else if ($smushMode === -1) {
405  $this->_userSmush = 0;
406  } else {
407  $this->_userSmush = (($smushMode & 63) | self::SM_SMUSH);
408  }
409 
410  $this->_smushOverride = self::SMO_YES;
411  }
412 
413  $this->_setUsedSmush();
414 
415  return $this;
416  }
const SMO_YES
Definition: Figlet.php:48
const SMO_NO
Definition: Figlet.php:47
const SM_KERN
Definition: Figlet.php:41

Field Documentation

◆ $_charHeight

$_charHeight
protected

Definition at line 117 of file Figlet.php.

◆ $_charList

$_charList = array()
protected

Definition at line 74 of file Figlet.php.

◆ $_currentChar

$_currentChar = null
protected

Definition at line 242 of file Figlet.php.

◆ $_currentCharWidth

$_currentCharWidth = 0
protected

Definition at line 200 of file Figlet.php.

◆ $_fontLoaded

$_fontLoaded = false
protected

Definition at line 81 of file Figlet.php.

◆ $_fontOptions

$_fontOptions = array()
protected

Definition at line 186 of file Figlet.php.

◆ $_fontSmush

$_fontSmush = 0
protected

Definition at line 138 of file Figlet.php.

◆ $_germanChars

$_germanChars = array(196, 214, 220, 228, 246, 252, 223)
protected

Definition at line 96 of file Figlet.php.

◆ $_handleParagraphs

$_handleParagraphs = false
protected

Definition at line 152 of file Figlet.php.

◆ $_hardBlank

$_hardBlank
protected

Definition at line 110 of file Figlet.php.

◆ $_inCharLine

$_inCharLine
protected

Definition at line 221 of file Figlet.php.

◆ $_inCharLineLength

$_inCharLineLength = 0
protected

Definition at line 228 of file Figlet.php.

◆ $_inCharLineLengthLimit

$_inCharLineLengthLimit = 0
protected

Definition at line 235 of file Figlet.php.

◆ $_justification

$_justification = null
protected

Definition at line 162 of file Figlet.php.

◆ $_maxLength

$_maxLength
protected

Definition at line 124 of file Figlet.php.

◆ $_outlineLength

$_outlineLength = 0
protected

Definition at line 207 of file Figlet.php.

◆ $_outlineLengthLimit

$_outlineLengthLimit = 0
protected

Definition at line 214 of file Figlet.php.

◆ $_output

$_output
protected

Definition at line 256 of file Figlet.php.

◆ $_outputLine

$_outputLine
protected

Definition at line 249 of file Figlet.php.

◆ $_outputWidth

$_outputWidth = 80
protected

Definition at line 103 of file Figlet.php.

◆ $_previousCharWidth

$_previousCharWidth = 0
protected

Definition at line 193 of file Figlet.php.

◆ $_rightToLeft

$_rightToLeft = null
protected

Definition at line 172 of file Figlet.php.

◆ $_skipOptions

$_skipOptions
protected
Initial value:
= array(
'options',
'config',
)

Definition at line 263 of file Figlet.php.

◆ $_smushMode

$_smushMode = 0
protected

Definition at line 131 of file Figlet.php.

◆ $_smushOverride

$_smushOverride = 0
protected

Definition at line 179 of file Figlet.php.

◆ $_userSmush

$_userSmush = 0
protected

Definition at line 145 of file Figlet.php.

◆ DIRECTION_LEFT_TO_RIGHT

const DIRECTION_LEFT_TO_RIGHT = 0

Write directions

Definition at line 61 of file Figlet.php.

◆ DIRECTION_RIGHT_TO_LEFT

const DIRECTION_RIGHT_TO_LEFT = 1

Definition at line 62 of file Figlet.php.

◆ FONTFILE_MAGIC_NUMBER

const FONTFILE_MAGIC_NUMBER = 'flf2'

Magic fontfile number

Definition at line 67 of file Figlet.php.

◆ JUSTIFICATION_CENTER

const JUSTIFICATION_CENTER = 1

Definition at line 55 of file Figlet.php.

◆ JUSTIFICATION_LEFT

const JUSTIFICATION_LEFT = 0

Justifications

Definition at line 54 of file Figlet.php.

◆ JUSTIFICATION_RIGHT

const JUSTIFICATION_RIGHT = 2

Definition at line 56 of file Figlet.php.

◆ SM_BIGX

const SM_BIGX = 0x10

Definition at line 39 of file Figlet.php.

◆ SM_EQUAL

const SM_EQUAL = 0x01

Smush2 layout modes

Definition at line 35 of file Figlet.php.

◆ SM_HARDBLANK

const SM_HARDBLANK = 0x20

Definition at line 40 of file Figlet.php.

◆ SM_HIERARCHY

const SM_HIERARCHY = 0x04

Definition at line 37 of file Figlet.php.

◆ SM_KERN

const SM_KERN = 0x40

Definition at line 41 of file Figlet.php.

◆ SM_LOWLINE

const SM_LOWLINE = 0x02

Definition at line 36 of file Figlet.php.

◆ SM_PAIR

const SM_PAIR = 0x08

Definition at line 38 of file Figlet.php.

◆ SM_SMUSH

const SM_SMUSH = 0x80

Definition at line 42 of file Figlet.php.

◆ SMO_FORCE

const SMO_FORCE = 2

Definition at line 49 of file Figlet.php.

◆ SMO_NO

const SMO_NO = 0

Smush mode override modes

Definition at line 47 of file Figlet.php.

◆ SMO_YES

const SMO_YES = 1

Definition at line 48 of file Figlet.php.


The documentation for this class was generated from the following file: