Index: tests/Zend/Pdf/Filter/AllTests.php =================================================================== --- tests/Zend/Pdf/Filter/AllTests.php (revision 0) +++ tests/Zend/Pdf/Filter/AllTests.php (revision 0) @@ -0,0 +1,58 @@ +addTestSuite('Zend_Pdf_Filter_RunLengthTest'); + + return $suite; + } +} + +if (PHPUnit_MAIN_METHOD == 'Zend_Pdf_Filter_AllTests::main') { + Zend_Pdf_Filter_AllTests::main(); +} Index: tests/Zend/Pdf/Filter/RunLengthTest.php =================================================================== --- tests/Zend/Pdf/Filter/RunLengthTest.php (revision 0) +++ tests/Zend/Pdf/Filter/RunLengthTest.php (revision 0) @@ -0,0 +1,86 @@ +assertEquals($encodedContents, $testString); + } + + public function testSimpleStringDecode() + { + $encodedContents = "\xF5\x57\x00\x42\xF5\x57\xFE\x42"; + $encodedContents .= "\xE9\x57\x00\x42\xF3\x57\x80"; + $decodedContents = Zend_Pdf_Filter_RunLength::decode($encodedContents); + $testString = 'WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWW'; + $testString .= 'WWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW'; + $this->assertEquals($decodedContents, $testString); + } + + public function testRepeatBytesLongerThan128BytesEncode() + { + $decodedContents = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'; + $decodedContents .= 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'; + $decodedContents .= 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'; + $decodedContents .= 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'; + $decodedContents .= 'AAAAAAAAAAAAAAAAAAAAAABBBCDEFFFF'; + $encodedContents = Zend_Pdf_Filter_RunLength::encode($decodedContents); + $testString = "\x81\x41\xEB\x41\xFE\x42\x00\x43"; + $testString .= "\x00\x44\x00\x45\xFD\x46\x80"; + $this->assertEquals($encodedContents, $testString); + } + + public function testRepeatBytesLongerThan128BytesDecode() + { + $encodedContents = "\x81\x41\xEB\x41\xFE\x42\x00\x43\x00\x44\x00\x45\xFD\x46\x80"; + $decodedContents = Zend_Pdf_Filter_RunLength::decode($encodedContents); + $testString = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'; + $testString .= 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'; + $testString .= 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'; + $testString .= 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'; + $testString .= 'AAAAAAAAAAAAAAAAAAAAAABBBCDEFFFF'; + $this->assertEquals($decodedContents, $testString); + } +} Index: library/Zend/Pdf/Filter/RunLength.php =================================================================== --- library/Zend/Pdf/Filter/RunLength.php (revision 0) +++ library/Zend/Pdf/Filter/RunLength.php (revision 0) @@ -0,0 +1,130 @@ + 128) { + $numOfTimesToCopy = 257 - $byteValue; + $copyValue = $data[$i + 1]; + + for($j = 0; $j < $numOfTimesToCopy; $j++) { + $output .= $copyValue; + } + + $i += 2; + } + + } + + return $output; + } +} Index: library/Zend/Pdf/Element/Object/Stream.php =================================================================== --- library/Zend/Pdf/Element/Object/Stream.php (revision 19316) +++ library/Zend/Pdf/Element/Object/Stream.php (working copy) @@ -211,6 +211,11 @@ $this->_originalDictionary['DecodeParms'][$id]); break; + case 'RunLengthDecode': + require_once 'Zend/Pdf/Filter/RunLength.php'; + $valueRef = Zend_Pdf_Filter_RunLength::decode($valueRef); + break; + default: require_once 'Zend/Pdf/Exception.php'; throw new Zend_Pdf_Exception('Unknown stream filter: \'' . $filterName . '\'.');