You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.6 KiB
74 lines
2.6 KiB
14 years ago
|
#include "ContentHandler.h"
|
||
|
#include "Filter.h"
|
||
|
#include "FlateDecode.h"
|
||
|
|
||
|
#include <iostream>
|
||
|
|
||
|
#include <string>
|
||
|
#include <string.h>
|
||
|
|
||
|
using namespace merge_lib;
|
||
|
using namespace std;
|
||
|
//concatenate stream of all objects which contain Content of Page
|
||
|
void ContentHandler::_processObjectContent(unsigned int startOfPageElement)
|
||
|
{
|
||
|
|
||
|
unsigned int endOfPage = _findEndOfElementContent(startOfPageElement);
|
||
|
_concatenatedStream = _retrieveStreamContent(_page, startOfPageElement, endOfPage);
|
||
|
|
||
|
FlateDecode flate;
|
||
|
flate.encode(_concatenatedStream);
|
||
|
}
|
||
|
|
||
|
//write concatenated stream to Page object
|
||
|
void ContentHandler::_changeObjectContent(unsigned int startOfPageElement)
|
||
|
{
|
||
|
|
||
|
unsigned int endOfPage = _findEndOfElementContent(startOfPageElement);
|
||
|
_page->forgetAboutChildren(startOfPageElement, endOfPage);
|
||
|
_page->eraseContent(startOfPageElement, endOfPage - startOfPageElement);
|
||
|
unsigned int endOfObjectDescription = _pageContent.rfind(">>");
|
||
|
const char * length = "/Filter /FlateDecode\n/Length ";
|
||
|
unsigned int sizeOfLength = strlen(length);
|
||
|
_page->insertToContent(endOfObjectDescription, length, sizeOfLength);
|
||
|
_page->insertToContent(endOfObjectDescription + sizeOfLength, Utils::uIntToStr(_concatenatedStream.size()).c_str());
|
||
|
_page->appendContent("\nstream\n");
|
||
|
_page->appendContent(_concatenatedStream);
|
||
|
_page->appendContent("endstream\n");
|
||
|
_page->forgetStreamInFile();
|
||
|
}
|
||
|
|
||
|
//get content of stream
|
||
|
// object - object with stream
|
||
|
//leftBound - left bound of object's content
|
||
|
//rightBound - right bound of object's content
|
||
|
string ContentHandler::_retrieveStreamContent(merge_lib::Object * object, unsigned int leftBound, unsigned int rightBound)
|
||
|
{
|
||
|
return (object->hasStream()) ?
|
||
|
_getStreamFromContent(object) :
|
||
|
_getStreamFromReferencies(object, leftBound, rightBound);
|
||
|
|
||
|
}
|
||
|
//get stream from Array elements
|
||
|
string ContentHandler::_getStreamFromReferencies(merge_lib::Object * objectWithArray, unsigned int leftBound, unsigned int rightBound)
|
||
|
{
|
||
|
std::string result;
|
||
|
std::vector<Object *> referencies = objectWithArray->getSortedByPositionChildren(leftBound, rightBound);
|
||
|
for(size_t i = 0; i < referencies.size(); ++i)
|
||
|
{
|
||
|
result.append(_retrieveStreamContent(referencies[i], 0, referencies[i]->getObjectContent().size()));
|
||
|
}
|
||
|
objectWithArray->forgetAboutChildren(leftBound,rightBound);
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
//get stream from Object
|
||
|
string ContentHandler::_getStreamFromContent(merge_lib::Object * objectWithStream)
|
||
|
{
|
||
|
Filter filter(objectWithStream);
|
||
|
string decodedStream;
|
||
|
filter.getDecodedStream(decodedStream);
|
||
|
|
||
|
return decodedStream;
|
||
|
}
|