Example #1
0
 public function testRepeatBytesLongerThan128BytesDecode()
 {
     $testString = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' . 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' . 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' . 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' . 'AAAAAAAAAAAAAAAAAAAAAABBBCDEFFFF';
     $encodedContents = "�A�A�BCDE�F�";
     $this->assertEquals(StreamFilter\RunLength::decode($encodedContents), $testString);
     $encodedContents = "�A�A�BCDE�F�";
     $this->assertEquals(StreamFilter\RunLength::decode($encodedContents), $testString);
 }
Example #2
0
 /**
  * Encode stream
  *
  * @throws \Zend\Pdf\Exception
  */
 private function _encodeStream()
 {
     /**
      * All applied stream filters must be processed to encode stream.
      * If we don't recognize any of applied filetrs an exception should be thrown here
      */
     if (isset($this->_initialDictionaryData['F'])) {
         /** @todo Check, how external files can be processed. */
         throw new Exception\NotImplementedException('External filters are not supported now.');
     }
     $filters = array_reverse($this->_initialDictionaryData['Filter'], true);
     foreach ($filters as $id => $filterName) {
         $valueRef =& $this->_value->value->getRef();
         $this->_value->value->touch();
         switch ($filterName) {
             case 'ASCIIHexDecode':
                 $valueRef = StreamFilter\AsciiHex::encode($valueRef);
                 break;
             case 'ASCII85Decode':
                 $valueRef = StreamFilter\Ascii85::encode($valueRef);
                 break;
             case 'FlateDecode':
                 $valueRef = CompressionFilter\Flate::encode($valueRef, $this->_initialDictionaryData['DecodeParms'][$id]);
                 break;
             case 'LZWDecode':
                 $valueRef = CompressionFilter\Lzw::encode($valueRef, $this->_initialDictionaryData['DecodeParms'][$id]);
                 break;
             case 'RunLengthDecode':
                 $valueRef = StreamFilter\RunLength::encode($valueRef);
                 break;
             default:
                 throw new Exception\CorruptedPdfException('Unknown stream filter: \'' . $filterName . '\'.');
         }
     }
     $this->_streamDecoded = false;
 }
Example #3
0
    public function testRepeatBytesLongerThan128BytesDecode()
    {
        $testString  = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
                     . 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
                     . 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
                     . 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
                     . 'AAAAAAAAAAAAAAAAAAAAAABBBCDEFFFF';

        $encodedContents = "\x81A\xEBA\xFEB\x00C\x00D\x00E\xFDF\x80";
        $this->assertEquals(StreamFilter\RunLength::decode($encodedContents), $testString);

        $encodedContents = "\x81A\xEBA\xFEB\x02CDE\xFDF\x80";
        $this->assertEquals(StreamFilter\RunLength::decode($encodedContents), $testString);
    }