/*
* Copyright (C) 2012 Webdoc SA
*
* This file is part of Open-Sankoré.
*
* Open-Sankoré is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation, version 2,
* with a specific linking exception for the OpenSSL project's
* "OpenSSL" library (or with modified versions of it that use the
* same license as the "OpenSSL" library).
*
* Open-Sankoré is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with Open-Sankoré; if not, see
* .
*/
#include "ContentHandler.h"
#include "Filter.h"
#include "FlateDecode.h"
#include
#include
#include
#include "core/memcheck.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