/* * (c) Copyright Ascensio System SIA 2010-2018 * * 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 "Table.h" namespace ASCDocFileFormat { void Table::SetDepth( unsigned int _depth ) { this->depth = _depth; } /*========================================================================================================*/ unsigned int Table::GetDepth() const { return this->depth; } /*========================================================================================================*/ Table::Table(): depth(1), tableRowsOffset(0) { } /*========================================================================================================*/ Table::~Table() { } /*========================================================================================================*/ Table::Table( const Table& table ): rows(table.rows), depth(table.depth), tableRowsOffset(table.tableRowsOffset) { } /*========================================================================================================*/ void Table::AddRow( const TableRow& row ) { TableRow newRow( row ); const unsigned char PFInTable = 1; const int PItap = row.GetDepth(); const unsigned char PFInnerTableCell = 1; newRow.AddProperty( (short)DocFileFormat::sprmPFInTable, (void*)(&PFInTable) ); newRow.AddProperty( (short)DocFileFormat::sprmPItap, (void*)(&PItap) ); if ( row.GetDepth() <= 1 ) { const unsigned char PFTtp = 1; newRow.AddProperty( (short)DocFileFormat::sprmPFTtp, (void*)(&PFTtp) ); } else { const unsigned char PFInnerTtp = 1; newRow.AddProperty( (short)DocFileFormat::sprmPFInnerTtp, (void*)(&PFInnerTtp) ); newRow.AddProperty( (short)DocFileFormat::sprmPFInnerTableCell, (void*)(&PFInnerTableCell) ); } this->rows.push_back( TableRowWithOffset( newRow, this->tableRowsOffset ) ); this->tableRowsOffset += ( sizeof(wchar_t) * row.GetAllText().size() ); } /*========================================================================================================*/ wstring Table::GetAllText() const { wstring allText; for ( list::const_iterator iter = this->rows.begin(); iter != this->rows.end(); iter++ ) { allText += iter->tableRow.GetAllText(); } return allText; } /*========================================================================================================*/ Table::operator wstring() const { wstring allText; for ( list::const_iterator iter = this->rows.begin(); iter != this->rows.end(); iter++ ) { allText += iter->tableRow; } return allText; } /*========================================================================================================*/ IVirtualConstructor* Table::New() const { return new Table(); } /*========================================================================================================*/ IVirtualConstructor* Table::Clone() const { return new Table( *this ); } /*========================================================================================================*/ vector Table::GetAllParagraphsCopy() const { vector allParagraphs; for ( list::const_iterator iter = this->rows.begin(); iter != this->rows.end(); iter++ ) { vector tableRowParagraphs = iter->tableRow.GetAllParagraphsCopy(); for ( vector::const_iterator tableRowParagraphsIter = tableRowParagraphs.begin(); tableRowParagraphsIter != tableRowParagraphs.end(); tableRowParagraphsIter++ ) { allParagraphs.push_back( TextItemPtr( static_cast( (*tableRowParagraphsIter)->Clone() ) ) ); } } return allParagraphs; } /*========================================================================================================*/ vector Table::GetAllParagraphs() { vector allParagraphs; for ( list::iterator iter = this->rows.begin(); iter != this->rows.end(); iter++ ) { vector tableRowParagraphs = iter->tableRow.GetAllParagraphs(); for ( vector::iterator tableRowParagraphsIter = tableRowParagraphs.begin(); tableRowParagraphsIter != tableRowParagraphs.end(); tableRowParagraphsIter++ ) { allParagraphs.push_back( *tableRowParagraphsIter ); } } return allParagraphs; } /*========================================================================================================*/ vector Table::GetAllRunsCopy( vector* allRunsOffsets ) const { vector allRuns; if ( allRunsOffsets != NULL ) { unsigned int runOffset = 0; for ( list::const_iterator iter = this->rows.begin(); iter != this->rows.end(); iter++ ) { vector allRowRunsOffsets; vector allRowRuns = iter->tableRow.GetAllRunsCopy( &allRowRunsOffsets ); for ( unsigned int i = 0; i < allRowRuns.size(); i++ ) { allRuns.push_back( IParagraphItemPtr( static_cast(allRowRuns[i]->Clone()) ) ); allRunsOffsets->push_back( runOffset + allRowRunsOffsets[i] ); } runOffset += ( sizeof(wchar_t) * iter->tableRow.GetAllText().size() ); } } return allRuns; } /*========================================================================================================*/ vector Table::GetAllParagraphItemsCopy( vector* allParagraphItemsOffsets ) const { vector allParagraphItems; if ( allParagraphItemsOffsets != NULL ) { unsigned int paragraphItemOffset = 0; for ( list::const_iterator iter = this->rows.begin(); iter != this->rows.end(); iter++ ) { vector allRowParagraphItemsOffsets; vector allRowParagraphItems = iter->tableRow.GetAllParagraphItemsCopy( &allRowParagraphItemsOffsets ); for ( unsigned int i = 0; i < allRowParagraphItems.size(); i++ ) { allParagraphItems.push_back( IParagraphItemPtr( static_cast(allRowParagraphItems[i]->Clone()) ) ); allParagraphItemsOffsets->push_back( paragraphItemOffset + allRowParagraphItemsOffsets[i] ); } paragraphItemOffset += ( sizeof(wchar_t) * iter->tableRow.GetAllText().size() ); } } return allParagraphItems; } /*========================================================================================================*/ vector Table::GetAllParagraphsProperties( vector* allParagraphsOffsets ) const { vector allParagraphsProperties; unsigned int paragraphOffset = 0; if ( allParagraphsOffsets != NULL ) { for ( list::const_iterator iter = this->rows.begin(); iter != this->rows.end(); iter++ ) { vector tableRowParagraphsOffsets; vector tableRowParagraphsProperties = iter->tableRow.GetAllParagraphsProperties( &tableRowParagraphsOffsets ); for ( unsigned int i = 0; i < tableRowParagraphsProperties.size(); i++ ) { allParagraphsProperties.push_back( tableRowParagraphsProperties[i] ); allParagraphsOffsets->push_back( paragraphOffset + tableRowParagraphsOffsets[i] ); } paragraphOffset += ( sizeof(wchar_t) * iter->tableRow.GetAllText().size() ); } } return allParagraphsProperties; } /*========================================================================================================*/ vector Table::GetAllRunProperties( vector* allRunsOffsets ) const { vector allRunsProperties; unsigned int runOffset = 0; if ( allRunsOffsets != NULL ) { for ( list::const_iterator iter = this->rows.begin(); iter != this->rows.end(); iter++ ) { vector tableRowRunsOffsets; vector tableRowRunsProperties = iter->tableRow.GetAllRunProperties( &tableRowRunsOffsets ); for ( unsigned int i = 0; i < tableRowRunsProperties.size(); i++ ) { allRunsProperties.push_back( tableRowRunsProperties[i] ); allRunsOffsets->push_back( runOffset + tableRowRunsOffsets[i] ); } runOffset += ( sizeof(wchar_t) * iter->tableRow.GetAllText().size() ); } } return allRunsProperties; } }