7
* This source file is subject to the new BSD license that is bundled
8
* with this package in the file LICENSE.txt.
9
* It is also available through the world-wide-web at this URL:
10
* http://framework.zend.com/license/new-bsd
11
* If you did not receive a copy of the license and are unable to
12
* obtain it through the world-wide-web, please send an email
13
* to license@zend.com so we can send you a copy immediately.
16
* @package Zend_Text_Figlet
17
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
18
* @license http://framework.zend.com/license/new-bsd New BSD License
23
* Zend_Text_Figlet is a PHP implementation of FIGlet
26
* @package Zend_Text_Figlet
27
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
28
* @license http://framework.zend.com/license/new-bsd New BSD License
30
class Zend_Text_Figlet
35
const SM_EQUAL = 0x01;
36
const SM_LOWLINE = 0x02;
37
const SM_HIERARCHY = 0x04;
40
const SM_HARDBLANK = 0x20;
42
const SM_SMUSH = 0x80;
45
* Smush mode override modes
54
const JUSTIFICATION_LEFT = 0;
55
const JUSTIFICATION_CENTER = 1;
56
const JUSTIFICATION_RIGHT = 2;
61
const DIRECTION_LEFT_TO_RIGHT = 0;
62
const DIRECTION_RIGHT_TO_LEFT = 1;
65
* Magic fontfile number
67
const FONTFILE_MAGIC_NUMBER = 'flf2';
70
* Array containing all characters of the current font
74
protected $_charList = array();
77
* Indicates if a font was loaded yet
81
protected $_fontLoaded = false;
84
* Latin-1 codes for German letters, respectively:
86
* LATIN CAPITAL LETTER A WITH DIAERESIS = A-umlaut
87
* LATIN CAPITAL LETTER O WITH DIAERESIS = O-umlaut
88
* LATIN CAPITAL LETTER U WITH DIAERESIS = U-umlaut
89
* LATIN SMALL LETTER A WITH DIAERESIS = a-umlaut
90
* LATIN SMALL LETTER O WITH DIAERESIS = o-umlaut
91
* LATIN SMALL LETTER U WITH DIAERESIS = u-umlaut
92
* LATIN SMALL LETTER SHARP S = ess-zed
96
protected $_germanChars = array(196, 214, 220, 228, 246, 252, 223);
99
* Output width, defaults to 80.
103
protected $_outputWidth = 80;
106
* Hard blank character
110
protected $_hardBlank;
113
* Height of the characters
117
protected $_charHeight;
120
* Max length of any character
124
protected $_maxLength;
131
protected $_smushMode = 0;
134
* Smush defined by the font
138
protected $_fontSmush = 0;
141
* Smush defined by the user
145
protected $_userSmush = 0;
148
* Wether to handle paragraphs || not
152
protected $_handleParagraphs = false;
155
* Justification for the text, according to $_outputWidth
157
* For using font default, this parameter should be null, else one of
158
* the values of Zend_Text_Figlet::JUSTIFICATION_*
162
protected $_justification = null;
165
* Direction of text-writing, namely right to left
167
* For using font default, this parameter should be null, else one of
168
* the values of Zend_Text_Figlet::DIRECTION_*
172
protected $_rightToLeft = null;
175
* Override font file smush layout
179
protected $_smushOverride = 0;
182
* Options of the current font
186
protected $_fontOptions = array();
189
* Previous character width
193
protected $_previousCharWidth = 0;
196
* Current character width
200
protected $_currentCharWidth = 0;
203
* Current outline length
207
protected $_outlineLength = 0;
210
* Maxmimum outline length
214
protected $_outlineLengthLimit = 0;
221
protected $_inCharLine;
224
* In character line length
228
protected $_inCharLineLength = 0;
231
* Maximum in character line length
235
protected $_inCharLineLengthLimit = 0;
242
protected $_currentChar = null;
245
* Current output line
249
protected $_outputLine;
259
* Option keys to skip when calling setOptions()
263
protected $_skipOptions = array(
269
* Instantiate the FIGlet with a specific font. If no font is given, the
270
* standard font is used. You can also supply multiple options via
271
* the $options variable, which can either be an array or an instance of
274
* @param array|Zend_Config $options Options for the output
276
public function __construct($options = null)
279
if (is_array($options)) {
280
$this->setOptions($options);
281
} else if ($options instanceof Zend_Config) {
282
$this->setConfig($options);
285
// If no font was defined, load default font
286
if (!$this->_fontLoaded) {
287
$this->_loadFont(dirname(__FILE__) . '/Figlet/zend-framework.flf');
292
* Set options from array
294
* @param array $options Configuration for Zend_Text_Figlet
295
* @return Zend_Text_Figlet
297
public function setOptions(array $options)
299
foreach ($options as $key => $value) {
300
if (in_array(strtolower($key), $this->_skipOptions)) {
304
$method = 'set' . ucfirst($key);
305
if (method_exists($this, $method)) {
306
$this->$method($value);
313
* Set options from config object
315
* @param Zend_Config $config Configuration for Zend_Text_Figlet
316
* @return Zend_Text_Figlet
318
public function setConfig(Zend_Config $config)
320
return $this->setOptions($config->toArray());
326
* @param string $font Path to the font
327
* @return Zend_Text_Figlet
329
public function setFont($font)
331
$this->_loadFont($font);
336
* Set handling of paragraphs
338
* @param boolean $handleParagraphs Wether to handle paragraphs or not
339
* @return Zend_Text_Figlet
341
public function setHandleParagraphs($handleParagraphs)
343
$this->_handleParagraphs = (bool) $handleParagraphs;
348
* Set the justification. 0 stands for left aligned, 1 for centered and 2
351
* @param integer $justification Justification of the output text
352
* @return Zend_Text_Figlet
354
public function setJustification($justification)
356
$this->_justification = min(3, max(0, (int) $justification));
361
* Set the output width
363
* @param integer $outputWidth Output with which should be used for word
364
* wrapping and justification
365
* @return Zend_Text_Figlet
367
public function setOutputWidth($outputWidth)
369
$this->_outputWidth = max(1, (int) $outputWidth);
374
* Set right to left mode. For writing from left to right, use
375
* Zend_Text_Figlet::DIRECTION_LEFT_TO_RIGHT. For writing from right to left,
376
* use Zend_Text_Figlet::DIRECTION_RIGHT_TO_LEFT.
378
* @param integer $rightToLeft Right-to-left mode
379
* @return Zend_Text_Figlet
381
public function setRightToLeft($rightToLeft)
383
$this->_rightToLeft = min(1, max(0, (int) $rightToLeft));
388
* Set the smush mode.
390
* Use one of the constants of Zend_Text_Figlet::SM_*, you may combine them.
392
* @param integer $smushMode Smush mode to use for generating text
393
* @return Zend_Text_Figlet
395
public function setSmushMode($smushMode)
397
$smushMode = (int) $smushMode;
399
if ($smushMode < -1) {
400
$this->_smushOverride = self::SMO_NO;
402
if ($smushMode === 0) {
403
$this->_userSmush = self::SM_KERN;
404
} else if ($smushMode === -1) {
405
$this->_userSmush = 0;
407
$this->_userSmush = (($smushMode & 63) | self::SM_SMUSH);
410
$this->_smushOverride = self::SMO_YES;
413
$this->_setUsedSmush();
419
* Render a FIGlet text
421
* @param string $text Text to convert to a figlet text
422
* @param string $encoding Encoding of the input string
423
* @throws InvalidArgumentException When $text is not a string
424
* @throws Zend_Text_Figlet_Exception When $text it not properly encoded
427
public function render($text, $encoding = 'UTF-8')
429
if (!is_string($text)) {
430
throw new InvalidArgumentException('$text must be a string');
433
if ($encoding !== 'UTF-8') {
434
$text = iconv($encoding, 'UTF-8', $text);
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';
451
throw new Zend_Text_Figlet_Exception('$text is not encoded with ' . $encoding);
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";
473
// Skip unprintable characters
474
$ordChar = $this->_uniOrd($char);
475
if (($ordChar > 0 && $ordChar < 32 && $char !== "\n") || $ordChar === 127) {
479
// Build the character
480
// Note: The following code is complex and thoroughly tested.
481
// Be careful when modifying!
483
$charNotAdded = false;
485
if ($wordBreakMode === -1) {
488
} else if ($char === "\n") {
496
if ($char === "\n") {
497
$this->_appendLine();
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) {
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));
511
$this->_putString($this->_currentChar[$i]);
516
} else if ($char === ' ') {
517
if ($wordBreakMode === 2) {
520
$this->_appendLine();
525
if ($wordBreakMode >= 2) {
528
$this->_appendLine();
531
$wordBreakMode = ($wordBreakMode === 3) ? 1 : 0;
532
$charNotAdded = true;
534
} while ($charNotAdded);
537
if ($this->_outlineLength !== 0) {
538
$this->_appendLine();
541
return $this->_output;
545
* Puts the given string, substituting blanks for hardblanks. If outputWidth
546
* is 1, puts the entire string; otherwise puts at most outputWidth - 1
547
* characters. Puts a newline at the end of the string. The string is left-
548
* justified, centered or right-justified (taking outputWidth as the screen
549
* width) if justification is 0, 1 or 2 respectively.
551
* @param string $string The string to add to the output
554
protected function _putString($string)
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) {
565
((3 - $this->_justification) * $i + $length + $this->_justification - 2) < $this->_outputWidth;
567
$this->_output .= ' ';
572
$this->_output .= str_replace($this->_hardBlank, ' ', $string) . "\n";
576
* Appends the current line to the output
580
protected function _appendLine()
582
for ($i = 0; $i < $this->_charHeight; $i++) {
583
$this->_putString($this->_outputLine[$i]);
590
* Splits inCharLine at the last word break (bunch of consecutive blanks).
591
* Makes a new line out of the first part and appends it using appendLine().
592
* Makes a new line out of the second part and returns.
596
protected function _splitLine()
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++) {
626
$this->_addChar($firstPart[$i]);
629
$this->_appendLine();
631
for ($i = 0; $i < $lastLength; $i++) {
632
$this->_addChar($lastPart[$i]);
637
* Clears the current line
641
protected function _clearLine()
643
for ($i = 0; $i < $this->_charHeight; $i++) {
644
$this->_outputLine[$i] = '';
647
$this->_outlineLength = 0;
648
$this->_inCharLineLength = 0;
652
* Attempts to add the given character onto the end of the current line.
653
* Returns true if this can be done, false otherwise.
655
* @param string $char Character which to add to the output
658
protected function _addChar($char)
660
$this->_getLetter($char);
662
if ($this->_currentChar === null) {
666
$smushAmount = $this->_smushAmount();
668
if (($this->_outlineLength + $this->_currentCharWidth - $smushAmount) > $this->_outlineLengthLimit
669
|| ($this->_inCharLineLength + 1) > $this->_inCharLineLengthLimit) {
674
for ($row = 0; $row < $this->_charHeight; $row++) {
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;
711
* Gets the requested character and sets current and previous char width.
713
* @param string $char The character from which to get the letter of
716
protected function _getLetter($char)
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]);
723
$this->_currentChar = null;
728
* Returns the maximum amount that the current character can be smushed into
733
protected function _smushAmount()
735
if (($this->_smushMode & (self::SM_SMUSH | self::SM_KERN)) === 0) {
739
$maxSmush = $this->_currentCharWidth;
742
for ($row = 0; $row < $this->_charHeight; $row++) {
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);
824
* Given two characters, attempts to smush them into one, according to the
825
* current smushmode. Returns smushed character or false if no smushing can
828
* Smushmode values are sum of following (all values smush blanks):
830
* 1: Smush equal chars (not hardblanks)
831
* 2: Smush '_' with any char in hierarchy below
832
* 4: hierarchy: "|", "/\", "[]", "{}", "()", "<>"
833
* Each class in hier. can be replaced by later class.
834
* 8: [ + ] -> |, { + } -> |, ( + ) -> |
835
* 16: / + \ -> X, > + < -> X (only in that order)
836
* 32: hardblank + hardblank -> hardblank
838
* @param string $leftChar Left character to smush
839
* @param string $rightChar Right character to smush
842
protected function _smushem($leftChar, $rightChar)
844
if ($leftChar === ' ') {
848
if ($rightChar === ' ') {
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.
858
if (($this->_smushMode & self::SM_SMUSH) === 0) {
863
if (($this->_smushMode & 63) === 0) {
864
// This is smushing by universal overlapping
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) {
876
// Occurs in the absence of above exceptions
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 === '<') {
959
* Load the specified font
961
* @param string $fontFile Font file to load
962
* @throws Zend_Text_Figlet_Exception When font file was not found
963
* @throws Zend_Text_Figlet_Exception When GZIP library is required but not found
964
* @throws Zend_Text_Figlet_Exception When font file is not readable
967
protected function _loadFont($fontFile)
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');
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');
983
$fontFile = 'compress.zlib://' . $fontFile;
989
// Try to open the file
990
$fp = fopen($fontFile, 'rb');
992
require_once 'Zend/Text/Figlet/Exception.php';
993
throw new Zend_Text_Figlet_Exception($fontFile . ': Could not open file');
996
// If the file is not compressed, lock the stream
1002
$magic = $this->_readMagic($fp);
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';
1017
throw new Zend_Text_Figlet_Exception($fontFile . ': Not a FIGlet 2 font file');
1020
// Set default right to left
1021
if ($numsRead < 6) {
1025
// If no smush2, decode smush into smush2
1026
if ($numsRead < 7) {
1028
$this->_fontSmush = self::SM_KERN;
1029
} else if ($smush < 0) {
1030
$this->_fontSmush = 0;
1032
$this->_fontSmush = (($smush & 31) | self::SM_SMUSH);
1036
// Correct char height && maxlength
1037
$this->_charHeight = max(1, $this->_charHeight);
1038
$this->_maxLength = max(1, $this->_maxLength);
1040
// Give ourselves some extra room
1041
$this->_maxLength += 100;
1043
// See if we have to override smush settings
1044
$this->_setUsedSmush();
1046
// Get left to right value
1047
if ($this->_rightToLeft === null) {
1048
$this->_rightToLeft = $rightToLeft;
1051
// Get justification value
1052
if ($this->_justification === null) {
1053
$this->_justification = (2 * $this->_rightToLeft);
1056
// Skip all comment lines
1057
for ($line = 1; $line <= $cmtLines; $line++) {
1058
$this->_skipToEol($fp);
1061
// Fetch all ASCII characters
1062
for ($asciiCode = 32; $asciiCode < 127; $asciiCode++) {
1063
$this->_charList[$asciiCode] = $this->_loadChar($fp);
1066
// Fetch all german characters
1067
foreach ($this->_germanChars as $uniCode) {
1068
$char = $this->_loadChar($fp);
1070
if ($char === false) {
1075
if (trim(implode('', $char)) !== '') {
1076
$this->_charList[$uniCode] = $char;
1080
// At the end fetch all extended characters
1081
while (!feof($fp)) {
1083
list($uniCode) = explode(' ', fgets($fp, 2048));
1085
if (empty($uniCode)) {
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
1094
substr($uniCode, 0, 2) === '-0') {
1095
$uniCode = octdec($uniCode);
1097
$uniCode = (int) $uniCode;
1100
// Now fetch the character
1101
$char = $this->_loadChar($fp);
1103
if ($char === false) {
1108
$this->_charList[$uniCode] = $char;
1113
$this->_fontLoaded = true;
1117
* Set the used smush mode, according to smush override, user smsush and
1122
protected function _setUsedSmush()
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);
1134
* Reads a four-character magic string from a stream
1136
* @param resource $fp File pointer to the font file
1139
protected function _readMagic($fp)
1143
for ($i = 0; $i < 4; $i++) {
1144
$magic .= fgetc($fp);
1151
* Skip a stream to the end of line
1153
* @param resource $fp File pointer to the font file
1156
protected function _skipToEol($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);
1179
* Load a single character from the font file
1181
* @param resource $fp File pointer to the font file
1184
protected function _loadChar($fp)
1188
for ($i = 0; $i < $this->_charHeight; $i++) {
1193
$line = rtrim(fgets($fp, 2048), "\r\n");
1195
if (preg_match('#(.)\\1?$#', $line, $result) === 1) {
1196
$line = str_replace($result[1], '', $line);
1206
* Unicode compatible ord() method
1208
* @param string $c The char to get the value from
1211
protected function _uniOrd($c)
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));