View Source

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[{zone-template-instance:ZFDEV:Zend Proposal Zone Template}

{zone-data:component-name}
Zend_Figlet
{zone-data}

{zone-data:proposer-list}
[Ben Scholzen|mailto:mail@dasprids.de]
[Matthew Weier O'Phinney (Zend Liaison)|~matthew]
{zone-data}

{zone-data:revision}
1.1 - 7 April 2008: Initial proposal
1.1 - 9 April 2008: Inserted prototype class skeleton
{zone-data}

{zone-data:overview}
Zend_Text_Figlet is a PHP implementation of the computer program "FIGlet". It can be useful if you want to create captchas for example, which are also usable for text browsers.

The output on text browsers and gfx browser could look like this:
!http://stuff.dasprids.de/figlet-gfx.png!
!http://stuff.dasprids.de/figlet-text.png!
{zone-data}

{zone-data:references}
* [FIGlet Wikipedia Entry|http://en.wikipedia.org/wiki/FIGlet]
* [FIGlet Website|http://www.figlet.org/]
* [FIGFont description|http://www.jave.de/figlet/figfont.txt]
{zone-data}

{zone-data:requirements}
* This component *will* read the FIGlet font file format
* This component *will* support a GZIP compressed font files
* This component *will* support output width for automatic line break
* This component *will* allow to force specific smushing modes
* This component *will* support multiple encodings via iconv
{zone-data}

{zone-data:dependencies}
* Zend_Text_Exception
{zone-data}

{zone-data:operation}
The component will be instantiated with a font filename. If no filename is supplied, a default font will be used. After the instantiation, you can use the component to convert strings into FIGlet strings.
{zone-data}

{zone-data:milestones}
* Milestone 1: [done] Proposal finished
* Milestone 2: [done] Working prototype checked into the zend.svn.dasprids.de
* Milestone 3: [done] Component approval
* Milestone 4: [done] Working prototype checked into the incubator
* Milestone 5: [done] Unit tests exist, work, and are checked into SVN.
* Milestone 6: [done] Documentation exists.
{zone-data}

{zone-data:class-list}
* Zend_Text_Figlet
* Zend_Text_Figlet_Exception
{zone-data}

{zone-data:use-cases}
||UC-01||

$figlet = new Zend_Text_Figlet();
echo $figlet->generate('Zend_Text_Figlet Demo');
{zone-data}

{zone-data:skeletons}
{code}
class Zend_Text_Figlet_Exception extends Zend_Text_Exception {}

<?php
class Zend_Text_Figlet
{
/**
* Smush2 layout modes
*/
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;

/**
* Magic fontfile number
*/
const FONTFILE_MAGIC_NUMBER = 'flf2';


/**
* Array containing all characters of the current font
*
* @var array
*/
protected $_charList = array();

/**
* Output width, defaults to 80.
*
* @var int
*/
protected $_outputWidth = 80;

/**
* Hard blank character
*
* @var string
*/
protected $_hardBlank;

/**
* Height of the characters
*
* @var int
*/
protected $_charHeight;

/**
* Max length of any character
*
* @var int
*/
protected $_maxLength;

/**
* Smush mode
*
* @var int
*/
protected $_smushMode = 0;

/**
* Justification for the text
*
* @var int
*/
protected $_justification = null;

/**
* Pre-defined right to left
*
* @var int
*/
protected $_rightToLeft = null;

/**
* Override font file smush layout
*
* @var int
*/
protected $_smushOverride = false;

/**
* Options of the current font
*
* @var array
*/
protected $_fontOptions = array();

/**
* Previous character width
*
* @var int
*/
protected $_previousCharWidth = 0;

/**
* Current character width
*
* @var int
*/
protected $_currentCharWidth = 0;

/**
* Current outline length
*
* @var int
*/
protected $_outlineLength = 0;


/**
* Maxmimum outline length
*
* @var int
*/
protected $_outlineLengthLimit = 0;

/**
* In character line
*
* @var string
*/
protected $_inCharLine;

/**
* In character line length
*
* @var int
*/
protected $_inCharLineLength = 0;

/**
* Maximum in character line length
*
* @var int
*/
protected $_inCharLineLengthLimit = 0;

/**
* Current char
*
* @var array
*/
protected $_currentChar = null;

/**
* Current output line
*
* @var array
*/
protected $_outputLine;

/**
* Current output
*
* @var string
*/
protected $_output;


/**
* Instantiate the FIGlet with a specific font. If font is null, 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.
*
* @param string $fontFile
* @param array|Zend_Config $options
*/
public function __construct($fontFile = null, $options = null);

/**
* Set options from array
*
* @param array $options
* @return Zend_Figlet
*/
public function setOptions(array $options);

/**
* Set options from config object
*
* @param Zend_Config $config
* @return Zend_Figlet
*/
public function setConfig(Zend_Config $config);

/**
* Set the justification. 0 stands for left aligned, 1 for centered and 2
* for right aligned.
*
* @param int $justification
* @return Zend_Figlet
*/
public function setJustification($justification);

/**
* Set the output width
*
* @param int $outputWidth
* @return Zend_Figlet
*/
public function setOutputWidth($outputWidth);

/**
* Set the layout mode
*
* @param int $layoutMode
* @return Zend_Figlet
*/
public function setLayoutMode($layoutMode);

/**
* Set right to left mode. For writing from left to right, use "0". For
* writing from right to left, use "1".
*
* @param int $rightToLeft
* @return Zend_Figlet
*/
public function setRightToLeft($rightToLeft);

/**
* Wether to allow smush override or not.
*
* @param boolean $smushOverride
*/
protected function _setSmushOverride($smushOverride);

/**
* Generate a FIGlet text
*
* @param string $text
* @return string
*/
public function generate($text);

/**
* 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.
*
* @param string $string
*/
protected function _putString($string);

/**
* Appends the current line to the output
*/
protected function _appendLine();

/**
* 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.
*/
protected function _splitLine();

/**
* Clears the current line
*/
protected function _clearLine();

/**
* Attempts to add the given character onto the end of the current line.
* Returns true if this can be done, false otherwise.
*
* @param string $char
* @return boolean
*/
protected function _addChar($char);

/**
* Gets the requested character and sets current and previous char width.
*
* @param string $char
*/
protected function _getLetter($char);

/**
* Returns the maximum amount that the current character can be smushed into
* the current line.
*
* @return int


*/
protected function _smushAmount();

/**
* 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
*
* @param string $leftChar
* @param string $rightChar
* @return string
*/
protected function _smushem($leftChar, $rightChar);

/**
* Load the specified font
*
* @param string $fontFile
*/
protected function _loadFont($fontFile);

/**
* Reads a four-character magic string from a stream
*
* @param resource $fp
*/
protected function _readMagic($fp);

/**
* Skip a stream to the end of line
*
* @param resource $fp
*/
protected function _skipToEol($fp);

/**
* Load a single character from the font file
*
* @param resource $fp
*/
protected function _loadChar($fp);
}
{code}
{zone-data}

{zone-template-instance}]]></ac:plain-text-body></ac:macro>