/* * (c) Copyright Ascensio System SIA 2010-2017 * * This program is a free software product. You can redistribute it and/or * modify it under the terms of the GNU Affero General Public License (AGPL) * version 3 as published by the Free Software Foundation. In accordance with * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect * that Ascensio System SIA expressly excludes the warranty of non-infringement * of any third-party rights. * * This program is distributed WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html * * You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, * EU, LV-1021. * * The interactive user interfaces in modified source and object code versions * of the Program must display Appropriate Legal Notices, as required under * Section 5 of the GNU AGPL version 3. * * Pursuant to Section 7(b) of the License you must retain the original Product * logo when distributing the program. Pursuant to Section 7(e) we decline to * grant you any rights under trademark law for use of our trademarks. * * All the Product's GUI elements, including illustrations and icon sets, as * well as technical writing content are licensed under the terms of the * Creative Commons Attribution-ShareAlike 4.0 International. See the License * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode * */ #include "Footer.h" namespace ASCDocFileFormat { Footer::Footer() : footerItemsOffset(0) { Paragraph paragraph; paragraph.AddParagraphItem( Run() ); this->textItems.push_back( FooterItemWithOffset( TextItemPtr( static_cast(paragraph.Clone()) ), this->footerItemsOffset ) ); this->footerItemsOffset += ( sizeof(wchar_t) * paragraph.GetAllText().size() ); } Footer::Footer( const Footer& _footer ) : footerItemsOffset(_footer.footerItemsOffset) { for ( list::const_iterator iter = _footer.textItems.begin(); iter != _footer.textItems.end(); iter++ ) { this->textItems.push_back( FooterItemWithOffset( TextItemPtr( static_cast( iter->footerItem->Clone() ) ), iter->footerItemOffset ) ); } } void Footer::AddTextItem( const ITextItem& _textItem ) { ITextItem* textItem = static_cast( _textItem.Clone() ); if ( !this->textItems.empty() ) { list::iterator iter = this->textItems.begin(); for ( unsigned int i = 0; i < ( this->textItems.size() - 1 ); i++, iter++ ); this->textItems.erase( iter ); this->footerItemsOffset -= sizeof(wchar_t); } if ( textItem != NULL ) { this->textItems.push_back( FooterItemWithOffset( TextItemPtr( textItem ), this->footerItemsOffset ) ); this->footerItemsOffset += ( sizeof(wchar_t) * textItem->GetAllText().size() ); Paragraph paragraph; paragraph.AddParagraphItem( Run() ); this->textItems.push_back( FooterItemWithOffset( TextItemPtr( static_cast(paragraph.Clone()) ), this->footerItemsOffset ) ); this->footerItemsOffset += ( sizeof(wchar_t) * paragraph.GetAllText().size() ); } } Footer::~Footer() { } wstring Footer::GetAllText() const { wstring allText; for ( list::const_iterator iter = this->textItems.begin(); iter != this->textItems.end(); iter++ ) { allText += iter->footerItem->GetAllText(); } return allText; } Footer::operator wstring() const { wstring allText; for ( list::const_iterator iter = this->textItems.begin(); iter != this->textItems.end(); iter++ ) { allText += *(iter->footerItem); } return allText; } vector Footer::GetAllParagraphsCopy() const { vector allParagraphs; for ( list::const_iterator iter = this->textItems.begin(); iter != this->textItems.end(); iter++ ) { vector textItemParagraphs = iter->footerItem->GetAllParagraphsCopy(); for ( vector::const_iterator textItemParagraphsIter = textItemParagraphs.begin(); textItemParagraphsIter != textItemParagraphs.end(); textItemParagraphsIter++ ) { allParagraphs.push_back( TextItemPtr( static_cast( (*textItemParagraphsIter)->Clone() ) ) ); } } return allParagraphs; } vector Footer::GetAllParagraphs() { vector allParagraphs; for ( list::const_iterator iter = this->textItems.begin(); iter != this->textItems.end(); iter++ ) { ITextItem* item = (ITextItem*)iter->footerItem.operator->(); vector textItemParagraphs = item->GetAllParagraphs(); for ( vector::iterator textItemParagraphsIter = textItemParagraphs.begin(); textItemParagraphsIter != textItemParagraphs.end(); textItemParagraphsIter++ ) { allParagraphs.push_back( *textItemParagraphsIter ); } } return allParagraphs; } vector Footer::GetAllParagraphsProperties( vector* allParagraphsOffsets ) const { vector allParagraphsProperties; unsigned int paragraphOffset = 0; if ( allParagraphsOffsets != NULL ) { for ( list::const_iterator iter = this->textItems.begin(); iter != this->textItems.end(); iter++ ) { vector footerItemParagraphsOffsets; vector footerItemParagraphsProperties = iter->footerItem->GetAllParagraphsProperties( &footerItemParagraphsOffsets ); for ( unsigned int i = 0; i < footerItemParagraphsProperties.size(); i++ ) { allParagraphsProperties.push_back( footerItemParagraphsProperties[i] ); allParagraphsOffsets->push_back( paragraphOffset + footerItemParagraphsOffsets[i] ); } paragraphOffset += ( sizeof(wchar_t) * iter->footerItem->GetAllText().size() ); } } return allParagraphsProperties; } vector Footer::GetAllRunProperties( vector* allRunsOffsets ) const { vector allRunsProperties; unsigned int runOffset = 0; if ( allRunsOffsets != NULL ) { for ( list::const_iterator iter = this->textItems.begin(); iter != this->textItems.end(); iter++ ) { vector footerItemRunsOffsets; vector footerItemRunsProperties = iter->footerItem->GetAllRunProperties( &footerItemRunsOffsets ); for ( unsigned int i = 0; i < footerItemRunsProperties.size(); i++ ) { allRunsProperties.push_back( footerItemRunsProperties[i] ); allRunsOffsets->push_back( runOffset + footerItemRunsOffsets[i] ); } runOffset += ( sizeof(wchar_t) * iter->footerItem->GetAllText().size() ); } } return allRunsProperties; } vector Footer::GetAllRunsCopy( vector* allRunsOffsets ) const { vector allRuns; if ( allRunsOffsets != NULL ) { unsigned int runOffset = 0; for ( list::const_iterator iter = this->textItems.begin(); iter != this->textItems.end(); iter++ ) { vector allTextItemRunsOffsets; vector allTextItemRuns = iter->footerItem->GetAllRunsCopy( &allTextItemRunsOffsets ); for ( unsigned int i = 0; i < allTextItemRuns.size(); i++ ) { allRuns.push_back( IParagraphItemPtr( static_cast(allTextItemRuns[i]->Clone()) ) ); allRunsOffsets->push_back( runOffset + allTextItemRunsOffsets[i] ); } runOffset += ( sizeof(wchar_t) * iter->footerItem->GetAllText().size() ); } } return allRuns; } vector Footer::GetAllParagraphItemsCopy( vector* allParagraphItemsOffsets ) const { vector allParagraphItems; if ( allParagraphItemsOffsets != NULL ) { unsigned int textItemOffset = 0; for ( list::const_iterator iter = this->textItems.begin(); iter != this->textItems.end(); iter++ ) { vector allTextItemParagraphItemsOffsets; vector allTextItemParagraphItems = iter->footerItem->GetAllParagraphItemsCopy( &allTextItemParagraphItemsOffsets ); for ( unsigned int i = 0; i < allTextItemParagraphItems.size(); i++ ) { allParagraphItems.push_back( IParagraphItemPtr( static_cast(allTextItemParagraphItems[i]->Clone()) ) ); allParagraphItemsOffsets->push_back( textItemOffset + allTextItemParagraphItemsOffsets[i] ); } textItemOffset += ( sizeof(wchar_t) * iter->footerItem->GetAllText().size() ); } } return allParagraphItems; } IVirtualConstructor* Footer::New() const { return new Footer(); } IVirtualConstructor* Footer::Clone() const { return new Footer( *this ); } }