Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Static Public Member Functions
Zend_Pdf_Filter_Ascii85 Class Reference
Inheritance diagram for Zend_Pdf_Filter_Ascii85:
Zend_Pdf_Filter_Interface

Static Public Member Functions

static encode ($data, $params=null)
 
static decode ($data, $params=null)
 

Detailed Description

Definition at line 33 of file Ascii85.php.

Member Function Documentation

◆ decode()

static decode (   $data,
  $params = null 
)
static

Decode data

Parameters
string$data
array$params
Returns
string
Exceptions
Zend_Pdf_Exception

Implements Zend_Pdf_Filter_Interface.

Definition at line 114 of file Ascii85.php.

115  {
116  $output = '';
117 
118  //get rid of the whitespaces
119  $whiteSpace = array("\x00", "\x09", "\x0A", "\x0C", "\x0D", "\x20");
120  $data = str_replace($whiteSpace, '', $data);
121 
122  if (substr($data, -2) != '~>') {
123  #require_once 'Zend/Pdf/Exception.php';
124  throw new Zend_Pdf_Exception('Invalid EOF marker');
125  return '';
126  }
127 
128  $data = substr($data, 0, (strlen($data) - 2));
129  $dataLength = strlen($data);
130 
131  for ($i = 0; $i < $dataLength; $i += 5) {
132  $b = 0;
133 
134  if (substr($data, $i, 1) == "z") {
135  $i -= 4;
136  $output .= pack("N", 0);
137  continue;
138  }
139 
140  $c = substr($data, $i, 5);
141 
142  if(strlen($c) < 5) {
143  //partial chunk
144  break;
145  }
146 
147  $c = unpack('C5', $c);
148  $value = 0;
149 
150  for ($j = 1; $j <= 5; $j++) {
151  $value += (($c[$j] - 33) * pow(85, (5 - $j)));
152  }
153 
154  $output .= pack("N", $value);
155  }
156 
157  //decode partial
158  if ($i < $dataLength) {
159  $value = 0;
160  $chunk = substr($data, $i);
161  $partialLength = strlen($chunk);
162 
163  //pad the rest of the chunk with u's
164  //until the lenght of the chunk is 5
165  for ($j = 0; $j < (5 - $partialLength); $j++) {
166  $chunk .= 'u';
167  }
168 
169  $c = unpack('C5', $chunk);
170 
171  for ($j = 1; $j <= 5; $j++) {
172  $value += (($c[$j] - 33) * pow(85, (5 - $j)));
173  }
174 
175  $foo = pack("N", $value);
176  $output .= substr($foo, 0, ($partialLength - 1));
177  }
178 
179  return $output;
180  }
$value
Definition: gender.phtml:16
$i
Definition: gallery.phtml:31

◆ encode()

static encode (   $data,
  $params = null 
)
static

Encode data

Parameters
string$data
array$params
Returns
string
Exceptions
Zend_Pdf_Exception

Implements Zend_Pdf_Filter_Interface.

Definition at line 43 of file Ascii85.php.

44  {
45  $output = '';
46  $dataLength = strlen($data);
47 
48  for ($i = 0; $i < $dataLength; $i += 4) {
49  //convert the 4 characters into a 32-bit number
50  $chunk = substr($data, $i, 4);
51 
52  if (strlen($chunk) < 4) {
53  //partial chunk
54  break;
55  }
56 
57  $b = unpack("N", $chunk);
58  $b = $b[1];
59 
60  //special char for all 4 bytes = 0
61  if ($b == 0) {
62  $output .= 'z';
63  continue;
64  }
65 
66  //encode into 5 bytes
67  for ($j = 4; $j >= 0; $j--) {
68  $foo = (int) (($b / pow(85,$j)) + 33);
69  $b %= pow(85,$j);
70  $output .= chr($foo);
71  }
72  }
73 
74  //encode partial chunk
75  if ($i < $dataLength) {
76  $n = $dataLength - $i;
77  $chunk = substr($data, -$n);
78 
79  //0 pad the rest
80  for ($j = $n;$j < 4;$j++) {
81  $chunk .= "\0";
82  }
83 
84  $b = unpack("N", $chunk);
85  $b = $b[1];
86 
87  //encode just $n + 1
88  for ($j = 4; $j >= (4 - $n); $j--) {
89  $foo = (int) (($b / pow(85,$j)) + 33);
90  $b %= pow(85,$j);
91  $output .= chr($foo);
92  }
93  }
94 
95  //EOD
96  $output .= '~>';
97 
98  //make sure lines are split
99  $output = chunk_split($output, 76, "\n");
100 
101  //get rid of new line at the end
102  $output = substr($output, 0, -1);
103  return $output;
104  }
$i
Definition: gallery.phtml:31

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