2) { if ($chainStartOffset != $offset) { // Drop down previouse (non-repeatable chars) run $output .= chr($offset - $chainStartOffset - 1) . substr($data, $chainStartOffset, $offset - $chainStartOffset); } $output .= chr(257 - $repeatedCharChainLength) . $data[$offset]; $offset += $repeatedCharChainLength; $chainStartOffset = $offset; } else { $offset++; if ($offset - $chainStartOffset == 128) { // Maximum run length is reached // Drop down non-repeatable chars run $output .= "\x7F" . substr($data, $chainStartOffset, 128); $chainStartOffset = $offset; } } } if ($chainStartOffset != $offset) { // Drop down non-repeatable chars run $output .= chr($offset - $chainStartOffset - 1) . substr($data, $chainStartOffset, $offset - $chainStartOffset); } $output .= "\x80"; return $output; } /** * Decode data * * @param string $data * @param array $params * @return string * @throws Zend_Pdf_Exception */ public static function decode($data, $params = null) { $dataLength = strlen($data); $output = ''; $offset = 0; while($offset < $dataLength) { $length = ord($data[$offset]); $offset++; if ($length == 128) { // EOD byte break; } else if ($length < 128) { $length++; $output .= substr($data, $offset, $length); $offset += $length; } else if ($length > 128) { $output .= str_repeat($data[$offset], 257 - $length); $offset++; } } return $output; } }