Files
core/HwpFile/HwpDoc/Paragraph/CtrlShapeEllipse.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

302 lines
8.4 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 "CtrlShapeEllipse.h"
namespace HWP
{
EArcType GetArcType(int nValue)
{
SWITCH(EArcType, nValue)
{
DEFAULT(EArcType::NORMAL);
CASE(EArcType::PIE);
CASE(EArcType::CHORD);
}
}
EArcType GetArcType(const std::string& sValue, EHanType eType)
{
if (sValue.empty() || GetValueName(EValue::Normal, eType) == sValue)
return EArcType::NORMAL;
if (GetValueName(EValue::Pie, eType) == sValue)
return EArcType::PIE;
if (GetValueName(EValue::Chord, eType) == sValue)
return EArcType::CHORD;
return EArcType::NORMAL;
}
CCtrlShapeEllipse::CCtrlShapeEllipse()
{}
CCtrlShapeEllipse::CCtrlShapeEllipse(const HWP_STRING& sCtrlID)
: CCtrlGeneralShape(sCtrlID)
{}
CCtrlShapeEllipse::CCtrlShapeEllipse(const CCtrlGeneralShape& oShape)
: CCtrlGeneralShape(oShape)
{}
CCtrlShapeEllipse::CCtrlShapeEllipse(const HWP_STRING& sCtrlID, int nSize, CHWPStream& oBuffer, int nOff, int nVersion)
: CCtrlGeneralShape(sCtrlID, nSize, oBuffer, nOff, nVersion)
{}
CCtrlShapeEllipse::CCtrlShapeEllipse(const HWP_STRING& sCtrlID, CXMLReader& oReader, EHanType eType)
: CCtrlGeneralShape(sCtrlID, oReader, eType)
{
switch(eType)
{
case EHanType::HWPX: ReadFromHWPX (oReader); return;
case EHanType::HWPML: ReadFromHWPML(oReader); return;
default: break;
}
}
void CCtrlShapeEllipse::ReadFromHWPX(CXMLReader &oReader)
{
START_READ_ATTRIBUTES(oReader)
{
if ("intervalDirty" == sAttributeName)
m_bIntervalDirty = oReader.GetBool();
else if ("hasArcPr" == sAttributeName)
m_bHasArcProperty = oReader.GetBool();
else if ("arcType" == sAttributeName)
m_eArcType = GetArcType(oReader.GetTextA(), EHanType::HWPX);
}
END_READ_ATTRIBUTES(oReader)
WHILE_READ_NEXT_NODE_WITH_NAME(oReader)
{
if ("hc:center" == sNodeName)
{
START_READ_ATTRIBUTES(oReader)
{
if ("x" == sAttributeName)
m_nCenterX = oReader.GetInt();
else if ("y" == sAttributeName)
m_nCenterY = oReader.GetInt();
}
END_READ_ATTRIBUTES(oReader)
}
else if ("hp:ax1" == sNodeName)
{
START_READ_ATTRIBUTES(oReader)
{
if ("x" == sAttributeName)
m_nAxixX1 = oReader.GetInt();
else if ("y" == sAttributeName)
m_nAxixY1 = oReader.GetInt();
}
END_READ_ATTRIBUTES(oReader)
}
else if ("hp:ax2" == sNodeName)
{
START_READ_ATTRIBUTES(oReader)
{
if ("x" == sAttributeName)
m_nAxixX2 = oReader.GetInt();
else if ("y" == sAttributeName)
m_nAxixY2 = oReader.GetInt();
}
END_READ_ATTRIBUTES(oReader)
}
else if ("hp:start1" == sNodeName)
{
START_READ_ATTRIBUTES(oReader)
{
if ("x" == sAttributeName)
m_nStartX1 = oReader.GetInt();
else if ("y" == sAttributeName)
m_nStartY1 = oReader.GetInt();
}
END_READ_ATTRIBUTES(oReader)
}
else if ("hp:start2" == sNodeName)
{
START_READ_ATTRIBUTES(oReader)
{
if ("x" == sAttributeName)
m_nStartX2 = oReader.GetInt();
else if ("y" == sAttributeName)
m_nStartY2 = oReader.GetInt();
}
END_READ_ATTRIBUTES(oReader)
}
else if ("hp:end1" == sNodeName)
{
START_READ_ATTRIBUTES(oReader)
{
if ("x" == sAttributeName)
m_nEndX1 = oReader.GetInt();
else if ("y" == sAttributeName)
m_nEndY1 = oReader.GetInt();
}
END_READ_ATTRIBUTES(oReader)
}
else if ("hp:end2" == sNodeName)
{
START_READ_ATTRIBUTES(oReader)
{
if ("x" == sAttributeName)
m_nEndX2 = oReader.GetInt();
else if ("y" == sAttributeName)
m_nEndY2 = oReader.GetInt();
}
END_READ_ATTRIBUTES(oReader)
}
else
CCtrlGeneralShape::ParseChildren(oReader, EHanType::HWPX);
}
END_WHILE
}
void CCtrlShapeEllipse::ReadFromHWPML(CXMLReader &oReader)
{
START_READ_ATTRIBUTES(oReader)
{
if ("IntervalDirty" == sAttributeName)
m_bIntervalDirty = oReader.GetBool();
else if ("HasArcProperty" == sAttributeName)
m_bHasArcProperty = oReader.GetBool();
else if ("ArcType" == sAttributeName)
m_eArcType = GetArcType(oReader.GetTextA(), EHanType::HWPML);
else if ("CenterX" == sAttributeName)
m_nCenterX = oReader.GetInt();
else if ("CenterY" == sAttributeName)
m_nCenterY = oReader.GetInt();
else if ("Axis1X" == sAttributeName)
m_nAxixX1 = oReader.GetInt();
else if ("Axis1Y" == sAttributeName)
m_nAxixY1 = oReader.GetInt();
else if ("Axis2X" == sAttributeName)
m_nAxixX2 = oReader.GetInt();
else if ("Axis2Y" == sAttributeName)
m_nAxixY2 = oReader.GetInt();
else if ("Start1X" == sAttributeName)
m_nStartX1 = oReader.GetInt();
else if ("Start1Y" == sAttributeName)
m_nStartY1 = oReader.GetInt();
else if ("End1X" == sAttributeName)
m_nEndX1 = oReader.GetInt();
else if ("End1Y" == sAttributeName)
m_nEndY1 = oReader.GetInt();
else if ("Start2X" == sAttributeName)
m_nStartX2 = oReader.GetInt();
else if ("Start2Y" == sAttributeName)
m_nStartY2 = oReader.GetInt();
else if ("End2X" == sAttributeName)
m_nEndX2 = oReader.GetInt();
else if ("End2Y" == sAttributeName)
m_nEndY2 = oReader.GetInt();
}
END_READ_ATTRIBUTES(oReader)
WHILE_READ_NEXT_NODE(oReader)
CCtrlGeneralShape::ParseChildren(oReader, EHanType::HWPML);
END_WHILE
}
EShapeType CCtrlShapeEllipse::GetShapeType() const
{
return EShapeType::Ellipse;
}
int CCtrlShapeEllipse::ParseElement(CCtrlShapeEllipse& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion)
{
oBuffer.SavePosition();
int nAttr;
oBuffer.ReadInt(nAttr);
oObj.m_bIntervalDirty = CHECK_FLAG(nAttr, 0x01);
oObj.m_bHasArcProperty = CHECK_FLAG(nAttr, 0x02);
oObj.m_eArcType = GetArcType(nAttr << 2 & 0xFF);
oBuffer.Skip(4);
oBuffer.ReadInt(oObj.m_nCenterX);
oBuffer.ReadInt(oObj.m_nCenterY);
oBuffer.ReadInt(oObj.m_nAxixX1);
oBuffer.ReadInt(oObj.m_nAxixY1);
oBuffer.ReadInt(oObj.m_nAxixX2);
oBuffer.ReadInt(oObj.m_nAxixY2);
oBuffer.ReadInt(oObj.m_nStartX1);
oBuffer.ReadInt(oObj.m_nStartY1);
oBuffer.ReadInt(oObj.m_nEndX1);
oBuffer.ReadInt(oObj.m_nEndY1);
oBuffer.ReadInt(oObj.m_nStartX2);
oBuffer.ReadInt(oObj.m_nStartY2);
oBuffer.ReadInt(oObj.m_nEndX2);
oBuffer.ReadInt(oObj.m_nEndY2);
oBuffer.Skip(nSize - oBuffer.GetDistanceToLastPos(true));
return nSize;
}
int CCtrlShapeEllipse::ParseCtrl(CCtrlShapeEllipse& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion)
{
oBuffer.SavePosition();
CCtrlGeneralShape::ParseCtrl(oObj, nSize, oBuffer, nOff, nVersion);
return oBuffer.GetDistanceToLastPos(true);
}
int CCtrlShapeEllipse::ParseListHeaderAppend(CCtrlShapeEllipse& oObj, int nSize, CHWPStream& oBuffer, int nOff, int nVersion)
{
oBuffer.SavePosition();
oBuffer.Skip(2);
oBuffer.ReadShort(oObj.m_shLeftSpace);
oBuffer.ReadShort(oObj.m_shRightSpace);
oBuffer.ReadShort(oObj.m_shTopSpace);
oBuffer.ReadShort(oObj.m_shBottomSpace);
oBuffer.ReadInt(oObj.m_nMaxTxtWidth);
oBuffer.Skip(13);
if (nSize > oBuffer.GetDistanceToLastPos())
{
oBuffer.Skip(10);
HWP_STRING sFieldName;
oBuffer.ReadString(sFieldName, EStringCharacter::UTF16);
oBuffer.Skip(nSize - oBuffer.GetDistanceToLastPos());
}
return oBuffer.GetDistanceToLastPos(true);
}
}