FilterASCII85

Class FilterASCII85.

Defined (1)

The class is defined in the following location(s).

/vendor/setasign/fpdi/filters/FilterASCII85.php  
  1. class FilterASCII85 
  2. /** 
  3. * Decode ASCII85 encoded string 
  4. * @param string $in 
  5. * @return string 
  6. * @throws Exception 
  7. */ 
  8. public function decode($in) 
  9. $ord = array( 
  10. '~' => ord('~'),  
  11. 'z' => ord('z'),  
  12. 'u' => ord('u'),  
  13. '!' => ord('!') 
  14. ); 
  15.  
  16. $out = ''; 
  17. $state = 0; 
  18. $chn = null; 
  19.  
  20. $l = strlen($in); 
  21.  
  22. for ($k = 0; $k < $l; ++$k) { 
  23. $ch = ord($in[$k]) & 0xff; 
  24.  
  25. if ($ch == $ord['~']) { 
  26. break; 
  27. if (preg_match('/^\s$/', chr($ch))) { 
  28. continue; 
  29. if ($ch == $ord['z'] && $state == 0) { 
  30. $out .= chr(0) . chr(0) . chr(0) . chr(0); 
  31. continue; 
  32. if ($ch < $ord['!'] || $ch > $ord['u']) { 
  33. throw new Exception('Illegal character in ASCII85Decode.'); 
  34.  
  35. $chn[$state++] = $ch - $ord['!']; 
  36.  
  37. if ($state == 5) { 
  38. $state = 0; 
  39. $r = 0; 
  40. for ($j = 0; $j < 5; ++$j) { 
  41. $r = (int)($r * 85 + $chn[$j]); 
  42.  
  43. $out .= chr($r >> 24); 
  44. $out .= chr($r >> 16); 
  45. $out .= chr($r >> 8); 
  46. $out .= chr($r); 
  47. $r = 0; 
  48.  
  49. if ($state == 1) { 
  50. throw new Exception('Illegal length in ASCII85Decode.'); 
  51.  
  52. if ($state == 2) { 
  53. $r = $chn[0] * 85 * 85 * 85 * 85 + ($chn[1]+1) * 85 * 85 * 85; 
  54. $out .= chr($r >> 24); 
  55.  
  56. } else if ($state == 3) { 
  57. $r = $chn[0] * 85 * 85 * 85 * 85 + $chn[1] * 85 * 85 * 85 + ($chn[2]+1) * 85 * 85; 
  58. $out .= chr($r >> 24); 
  59. $out .= chr($r >> 16); 
  60.  
  61. } else if ($state == 4) { 
  62. $r = $chn[0] * 85 * 85 * 85 * 85 + $chn[1] * 85 * 85 * 85 + $chn[2] * 85 * 85 + ($chn[3]+1) * 85 ; 
  63. $out .= chr($r >> 24); 
  64. $out .= chr($r >> 16); 
  65. $out .= chr($r >> 8); 
  66.  
  67. return $out; 
  68.  
  69. /** 
  70. * NOT IMPLEMENTED 
  71. * @param string $in 
  72. * @return string 
  73. * @throws LogicException 
  74. */ 
  75. public function encode($in) 
  76. throw new LogicException("ASCII85 encoding not implemented.");