#include "TextBox.h" namespace ASCDocFileFormat { TextBox::TextBox (short _aFtnIdx) : textBoxItemsOffset(0), aFtnIdx(_aFtnIdx) { } TextBox::TextBox (const TextBox& oTextBox) : textBoxItemsOffset(oTextBox.textBoxItemsOffset), aFtnIdx(oTextBox.aFtnIdx) { for (std::list::const_iterator iter = oTextBox.textItems.begin(); iter != oTextBox.textItems.end(); ++iter) { textItems.push_back( TextBoxItemWithOffset( TextItemPtr( static_cast(iter->textBoxItem->Clone() ) ), iter->textBoxItemOffset ) ); } } } namespace ASCDocFileFormat { void TextBox::AddTextItem(const ITextItem& oTextItem) { ITextItem* pTextItem = static_cast(oTextItem.Clone()); if (pTextItem) { textItems.push_back(TextBoxItemWithOffset(TextItemPtr(pTextItem), textBoxItemsOffset)); textBoxItemsOffset += (sizeof(wchar_t) * pTextItem->GetAllText().size()); } } short TextBox::GetIndex() const { return aFtnIdx; } TextBox::~TextBox() { } std::wstring TextBox::GetAllText() const { std::wstring allText; for (std::list::const_iterator iter = textItems.begin(); iter != textItems.end(); ++iter) { allText += iter->textBoxItem->GetAllText(); } return allText; } TextBox::operator wstring() const { std::wstring allText; for (std::list::const_iterator iter = textItems.begin(); iter != textItems.end(); ++iter) { allText += *(iter->textBoxItem); } return allText; } std::vector TextBox::GetAllParagraphsCopy() const { std::vector allParagraphs; for (std::list::const_iterator iter = this->textItems.begin(); iter != this->textItems.end(); iter++ ) { std::vector textItemParagraphs = iter->textBoxItem->GetAllParagraphsCopy(); for (std::vector::const_iterator textItemParagraphsIter = textItemParagraphs.begin(); textItemParagraphsIter != textItemParagraphs.end(); ++textItemParagraphsIter) { allParagraphs.push_back( TextItemPtr( static_cast( (*textItemParagraphsIter)->Clone() ) ) ); } } return allParagraphs; } vector TextBox::GetAllParagraphs() { vector allParagraphs; for ( list::const_iterator iter = this->textItems.begin(); iter != this->textItems.end(); iter++ ) { ITextItem* item = (ITextItem*)iter->textBoxItem.operator->(); vector textItemParagraphs = item->GetAllParagraphs(); for ( vector::iterator textItemParagraphsIter = textItemParagraphs.begin(); textItemParagraphsIter != textItemParagraphs.end(); textItemParagraphsIter++ ) { allParagraphs.push_back( *textItemParagraphsIter ); } } return allParagraphs; } std::vector TextBox::GetAllParagraphsProperties( vector* allParagraphsOffsets ) const { std::vector allParagraphsProperties; unsigned int paragraphOffset = 0; if (allParagraphsOffsets) { for ( list::const_iterator iter = textItems.begin(); iter != textItems.end(); ++iter) { std::vector footnoteItemParagraphsOffsets; std::vector itemParagraphsProperties = iter->textBoxItem->GetAllParagraphsProperties( &footnoteItemParagraphsOffsets ); for (unsigned int i = 0; i < itemParagraphsProperties.size(); ++i) { allParagraphsProperties.push_back(itemParagraphsProperties[i]); allParagraphsOffsets->push_back(paragraphOffset + footnoteItemParagraphsOffsets[i]); } paragraphOffset += ( sizeof(wchar_t) * iter->textBoxItem->GetAllText().size() ); } } return allParagraphsProperties; } std::vector TextBox::GetAllRunProperties(vector* allRunsOffsets) const { std::vector allRunsProperties; unsigned int runOffset = 0; if (allRunsOffsets) { for (std::list::const_iterator iter = textItems.begin(); iter != textItems.end(); ++iter) { std::vector footnoteItemRunsOffsets; std::vector footnoteItemRunsProperties = iter->textBoxItem->GetAllRunProperties(&footnoteItemRunsOffsets); for (unsigned int i = 0; i < footnoteItemRunsProperties.size(); ++i) { allRunsProperties.push_back( footnoteItemRunsProperties[i] ); allRunsOffsets->push_back( runOffset + footnoteItemRunsOffsets[i] ); } runOffset += ( sizeof(wchar_t) * iter->textBoxItem->GetAllText().size() ); } } return allRunsProperties; } std::vector TextBox::GetAllRunsCopy(vector* allRunsOffsets) const { std::vector allRuns; if ( allRunsOffsets != NULL ) { unsigned int runOffset = 0; for ( list::const_iterator iter = this->textItems.begin(); iter != this->textItems.end(); iter++ ) { std::vector allTextItemRunsOffsets; std::vector allTextItemRuns = iter->textBoxItem->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->textBoxItem->GetAllText().size() ); } } return allRuns; } vector TextBox::GetAllParagraphItemsCopy( vector* allParagraphItemsOffsets ) const { std::vector allParagraphItems; if (allParagraphItemsOffsets) { unsigned int textItemOffset = 0; for (std::list::const_iterator iter = textItems.begin(); iter != textItems.end(); ++iter) { std::vector allTextItemParagraphItemsOffsets; std::vector allTextItemParagraphItems = iter->textBoxItem->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->textBoxItem->GetAllText().size() ); } } return allParagraphItems; } IVirtualConstructor* TextBox::New() const { return new TextBox(); } IVirtualConstructor* TextBox::Clone() const { return new TextBox( *this ); } }