Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Static Public Member Functions
Zend_Pdf_Filter_RunLength Class Reference
Inheritance diagram for Zend_Pdf_Filter_RunLength:
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 RunLength.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 95 of file RunLength.php.

96  {
97  $dataLength = strlen($data);
98  $output = '';
99  $offset = 0;
100 
101  while($offset < $dataLength) {
102  $length = ord($data[$offset]);
103 
104  $offset++;
105 
106  if ($length == 128) {
107  // EOD byte
108  break;
109  } else if ($length < 128) {
110  $length++;
111 
112  $output .= substr($data, $offset, $length);
113 
114  $offset += $length;
115  } else if ($length > 128) {
116  $output .= str_repeat($data[$offset], 257 - $length);
117 
118  $offset++;
119  }
120  }
121 
122  return $output;
123  }

◆ 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 RunLength.php.

44  {
45  $output = '';
46 
47  $chainStartOffset = 0;
48  $offset = 0;
49 
50  while ($offset < strlen($data)) {
51  // Do not encode 2 char chains since they produce 2 char run sequence,
52  // but it takes more time to decode such output (because of processing additional run)
53  if (($repeatedCharChainLength = strspn($data, $data[$offset], $offset + 1, 127) + 1) > 2) {
54  if ($chainStartOffset != $offset) {
55  // Drop down previouse (non-repeatable chars) run
56  $output .= chr($offset - $chainStartOffset - 1)
57  . substr($data, $chainStartOffset, $offset - $chainStartOffset);
58  }
59 
60  $output .= chr(257 - $repeatedCharChainLength) . $data[$offset];
61 
62  $offset += $repeatedCharChainLength;
63  $chainStartOffset = $offset;
64  } else {
65  $offset++;
66 
67  if ($offset - $chainStartOffset == 128) {
68  // Maximum run length is reached
69  // Drop down non-repeatable chars run
70  $output .= "\x7F" . substr($data, $chainStartOffset, 128);
71 
72  $chainStartOffset = $offset;
73  }
74  }
75  }
76 
77  if ($chainStartOffset != $offset) {
78  // Drop down non-repeatable chars run
79  $output .= chr($offset - $chainStartOffset - 1) . substr($data, $chainStartOffset, $offset - $chainStartOffset);
80  }
81 
82  $output .= "\x80";
83 
84  return $output;
85  }

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