Files
core/HwpFile/HwpDoc/Paragraph/CtrlTable.cpp
Alexander Trofimov 76ee07f61c [copyright] Update copyright header
Co-authored-by: Alexander Trofimov <alexander.trofimov@onlyoffice.com>
Co-committed-by: Alexander Trofimov <alexander.trofimov@onlyoffice.com>
2026-05-14 08:23:56 +00:00

283 lines
7.5 KiB
C++

/*
* Copyright (C) Ascensio System SIA, 2009-2026
*
* 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, together with the
* additional terms provided in the LICENSE file.
*
* 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: https://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA by email at info@onlyoffice.com
* or by postal mail at 20A-6 Ernesta Birznieka-Upisha Street, Riga,
* LV-1050, Latvia, European Union.
*
* The interactive user interfaces in modified versions of the Program
* are required to display Appropriate Legal Notices in accordance with
* Section 5 of the GNU AGPL version 3.
*
* No trademark rights are granted under this License.
*
* All non-code elements of the Product, including illustrations,
* icon sets, and technical writing content, are licensed under the
* Creative Commons Attribution-ShareAlike 4.0 International License:
* https://creativecommons.org/licenses/by-sa/4.0/legalcode
*
* This license applies only to such non-code elements and does not
* modify or replace the licensing terms applicable to the Program's
* source code, which remains licensed under the GNU Affero General
* Public License v3.
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
#include "CtrlTable.h"
#include "../Common/NodeNames.h"
namespace HWP
{
CCtrlTable::CCtrlTable(const HWP_STRING& sCtrlID)
: CCtrlCommon(sCtrlID)
{}
CCtrlTable::CCtrlTable(const HWP_STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion)
: CCtrlCommon(sCtrlID, nSize, oBuffer, nOff, nVersion)
{}
CCtrlTable::CCtrlTable(const HWP_STRING& sCtrlID, CXMLReader& oReader, EHanType eType)
: CCtrlCommon(sCtrlID, oReader, eType)
{
START_READ_ATTRIBUTES(oReader)
{
if (GetAttributeName(EAttribute::RowCount, eType) == sAttributeName)
m_shNRows = oReader.GetInt();
else if (GetAttributeName(EAttribute::ColCount, eType) == sAttributeName)
m_shNCols = oReader.GetInt();
else if (GetAttributeName(EAttribute::CellSpacing, eType) == sAttributeName)
m_shCellSpacing = oReader.GetInt();
else if (GetAttributeName(EAttribute::BorderFill, eType) == sAttributeName)
m_shBorderFillID = oReader.GetInt();
}
END_READ_ATTRIBUTES(oReader)
WHILE_READ_NEXT_NODE_WITH_NAME(oReader)
{
if (GetNodeName(ENode::InSideMargin, eType) == sNodeName)
{
START_READ_ATTRIBUTES(oReader)
{
if (GetAttributeName(EAttribute::Left, eType) == sAttributeName)
m_shInLSpace = oReader.GetInt();
else if (GetAttributeName(EAttribute::Right, eType) == sAttributeName)
m_shInRSpace = oReader.GetInt();
else if (GetAttributeName(EAttribute::Top, eType) == sAttributeName)
m_shInTSpace = oReader.GetInt();
else if (GetAttributeName(EAttribute::Bottom, eType) == sAttributeName)
m_shInBSpace = oReader.GetInt();
}
END_READ_ATTRIBUTES(oReader)
}
else if (GetNodeName(ENode::CellZoneList, eType) == sNodeName)
{
WHILE_READ_NEXT_NODE_WITH_DEPTH_ONE_NAME(oReader, Child, GetNodeName(ENode::CellZone, eType))
{
TCellZone* pCellZone = new TCellZone();
START_READ_ATTRIBUTES(oReader)
{
if (GetAttributeName(EAttribute::StartRowAddr, eType) == sAttributeName)
pCellZone->m_shStartRowAddr = oReader.GetInt();
else if (GetAttributeName(EAttribute::StartColAddr, eType) == sAttributeName)
pCellZone->m_shStartColAddr = oReader.GetInt();
else if (GetAttributeName(EAttribute::EndRowAddr, eType) == sAttributeName)
pCellZone->m_shEndRowAddr = oReader.GetInt();
else if (GetAttributeName(EAttribute::EndColAddr, eType) == sAttributeName)
pCellZone->m_shEndColAddr = oReader.GetInt();
else if (GetAttributeName(EAttribute::BorderFill, eType) == sAttributeName)
pCellZone->m_shBorderFillIDRef = oReader.GetInt();
}
END_READ_ATTRIBUTES(oReader)
m_arCellzoneList.push_back(pCellZone);
}
END_WHILE
}
else if (GetNodeName(ENode::Row, eType) == sNodeName)
{
WHILE_READ_NEXT_NODE_WITH_DEPTH_ONE_NAME(oReader, Child, GetNodeName(ENode::Cell, eType))
m_arCells.push_back(new CTblCell(oReader, eType));
END_WHILE
}
else
CCtrlCommon::ParseChildren(oReader, eType);
}
END_WHILE
}
CCtrlTable::~CCtrlTable()
{
for (TCellZone* pCellzone : m_arCellzoneList)
{
if (nullptr != pCellzone)
delete pCellzone;
}
for (CTblCell* pTblCell : m_arCells)
{
if (nullptr != pTblCell)
delete pTblCell;
}
}
ECtrlObjectType CCtrlTable::GetCtrlType() const
{
return ECtrlObjectType::Table;
}
bool CCtrlTable::Empty() const
{
return m_arCells.empty();
}
short CCtrlTable::GetRows() const
{
return m_shNRows;
}
short CCtrlTable::GetCols() const
{
return m_shNCols;
}
short CCtrlTable::GetColsInRow(short shRowIndex) const
{
if (shRowIndex >= m_arRowSize.size())
return 1;
return m_arRowSize[shRowIndex];
}
short CCtrlTable::GetCountCells() const
{
return m_arCells.size();
}
short CCtrlTable::GetBorderFillID() const
{
return m_shBorderFillID;
}
short CCtrlTable::GetInLSpace() const
{
return m_shInLSpace;
}
short CCtrlTable::GetInTSpace() const
{
return m_shInTSpace;
}
short CCtrlTable::GetInRSpace() const
{
return m_shInRSpace;
}
short CCtrlTable::GetInBSpace() const
{
return m_shInBSpace;
}
void CCtrlTable::AddCell(CTblCell* pCell)
{
m_arCells.push_back(pCell);
}
bool CCtrlTable::HaveCells()
{
return !m_arCells.empty();
}
const CTblCell* CCtrlTable::GetCell(unsigned int unIndex) const
{
if (unIndex >= m_arCells.size())
return nullptr;
return m_arCells[unIndex];
}
CTblCell* CCtrlTable::GetLastCell()
{
return (!m_arCells.empty()) ? m_arCells.back() : nullptr;
}
int CCtrlTable::ParseCtrl(CCtrlTable& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion)
{
oBuffer.SavePosition();
oBuffer.ReadInt(oObj.m_nAttr);
oBuffer.ReadShort(oObj.m_shNRows);
oBuffer.ReadShort(oObj.m_shNCols);
oBuffer.ReadShort(oObj.m_shCellSpacing);
oBuffer.ReadShort(oObj.m_shInLSpace);
oBuffer.ReadShort(oObj.m_shInRSpace);
oBuffer.ReadShort(oObj.m_shInTSpace);
oBuffer.ReadShort(oObj.m_shInBSpace);
oObj.m_arRowSize.resize(oObj.m_shNRows);
for (unsigned int unIndex = 0; unIndex < oObj.m_shNRows; ++unIndex)
oBuffer.ReadShort(oObj.m_arRowSize[unIndex]);
oBuffer.ReadShort(oObj.m_shBorderFillID);
if (nVersion >= 5010 && (oBuffer.GetDistanceToLastPos() < nSize))
{
oBuffer.ReadShort(oObj.m_shValidZoneSize);
if (0 < oObj.m_shValidZoneSize && (oBuffer.GetDistanceToLastPos() < nSize))
{
for (unsigned int unIndex = 0; unIndex < oObj.m_shValidZoneSize; ++unIndex)
{
TCellZone *pCellZone = new TCellZone();
if (nullptr == pCellZone)
continue;
oBuffer.ReadShort(pCellZone->m_shStartRowAddr);
oBuffer.ReadShort(pCellZone->m_shStartColAddr);
oBuffer.ReadShort(pCellZone->m_shEndRowAddr);
oBuffer.ReadShort(pCellZone->m_shEndColAddr);
oBuffer.ReadShort(pCellZone->m_shBorderFillIDRef);
oObj.m_arCellzoneList.push_back(pCellZone);
}
}
}
oObj.m_bFullFilled = true;
oBuffer.Skip(nSize - oBuffer.GetDistanceToLastPos(true));
return nSize;
}
int CCtrlTable::ParseListHeaderAppend(CCtrlTable& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion)
{
if (24 != nSize)
{
oBuffer.Skip(nSize);
return nSize;
}
oBuffer.Skip(2);
oBuffer.ReadInt(oObj.m_nCaptionAttr);
oBuffer.ReadInt(oObj.m_nCaptionWidth);
oObj.m_nCaptionSpacing = oBuffer.ReadShort();
oBuffer.ReadInt(oObj.m_nCaptionMaxW);
oBuffer.Skip(8);
return nSize;
}
}