diff --git a/MsBinaryFile/Common/ODraw/BaseShape.cpp b/MsBinaryFile/Common/ODraw/BaseShape.cpp new file mode 100644 index 0000000000..ba80bec181 --- /dev/null +++ b/MsBinaryFile/Common/ODraw/BaseShape.cpp @@ -0,0 +1,111 @@ +/* + * (c) Copyright Ascensio System SIA 2010-2019 + * + * 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 20A-12 Ernesta Birznieka-Upisha + * street, Riga, Latvia, EU, LV-1050. + * + * 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 + * + */ +#pragma once + +#include "BaseShape.h" +#include "CustomShape.h" + +namespace NSCustomShapesConvert +{ + CHandle_::CHandle_() + { + position = _T(""); + xrange = _T(""); + yrange = _T(""); + switchHandle = _T(""); + polar = _T(""); + radiusrange = _T(""); + } + CHandle_& CHandle_::operator =(const CHandle_& oSrc) + { + position = oSrc.position; + xrange = oSrc.xrange; + yrange = oSrc.yrange; + switchHandle = oSrc.switchHandle; + polar = oSrc.polar; + radiusrange = oSrc.radiusrange; + return (*this); + } + + CBaseShape::CBaseShape() + { + } + CBaseShape* CBaseShape::CreateByType( int ShapeType) + { + return CCustomShape::CreateByType((oox::MSOSPT)ShapeType); + } + bool CBaseShape::SetType( int ShapeType) + { + return ((CCustomShape*)this)->SetShapeType((oox::MSOSPT)ShapeType); + } + bool CBaseShape::SetProperties(CBaseShape* Shape) + { + if( Shape == NULL) + return false; + + m_oPath = Shape->m_oPath; + m_strPath = Shape->m_strPath; + m_strRect = Shape->m_strRect; + + m_arAdjustments.clear(); + for(size_t i = 0; i < Shape->m_arAdjustments.size(); i++) + m_arAdjustments.push_back(Shape->m_arAdjustments[i]); + + m_arGuides.clear(); + for(size_t i = 0; i < Shape->m_arGuides.size(); i++) + m_arGuides.push_back(Shape->m_arGuides[i]); + + m_eJoin = Shape->m_eJoin; + m_bConcentricFill = Shape->m_bConcentricFill; + + m_arConnectors.clear(); + for(size_t i = 0; i < Shape->m_arConnectors.size(); i++) + m_arConnectors.push_back(Shape->m_arConnectors[i]); + + m_arConnectorAngles.clear(); + for(size_t i = 0; i < Shape->m_arConnectorAngles.size(); i++) + m_arConnectorAngles.push_back(Shape->m_arConnectorAngles[i]); + + m_arTextRects.clear(); + for(size_t i = 0; i < Shape->m_arTextRects.size(); i++) + m_arTextRects.push_back(Shape->m_arTextRects[i]); + + m_arHandles.clear(); + for(size_t i = 0; i < Shape->m_arHandles.size(); i++) + m_arHandles.push_back(Shape->m_arHandles[i]); + + + m_strRect = Shape->m_strRect; + m_strTransformXml = Shape->m_strTransformXml; + return true; + } +} diff --git a/MsBinaryFile/Common/ODraw/BaseShape.h b/MsBinaryFile/Common/ODraw/BaseShape.h index 80ab75eaa9..8313364e1e 100644 --- a/MsBinaryFile/Common/ODraw/BaseShape.h +++ b/MsBinaryFile/Common/ODraw/BaseShape.h @@ -47,25 +47,9 @@ public: std::wstring radiusrange; public: - CHandle_() - { - position = _T(""); - xrange = _T(""); - yrange = _T(""); - switchHandle = _T(""); - polar = _T(""); - radiusrange = _T(""); - } - CHandle_& operator =(const CHandle_& oSrc) - { - position = oSrc.position; - xrange = oSrc.xrange; - yrange = oSrc.yrange; - switchHandle = oSrc.switchHandle; - polar = oSrc.polar; - radiusrange = oSrc.radiusrange; - return (*this); - } + CHandle_(); + + CHandle_& operator =(const CHandle_& oSrc); }; class CBaseShape @@ -93,10 +77,9 @@ public: LONG m_lLimoY; CPath m_oPath; + public: - CBaseShape() - { - } + CBaseShape(); virtual bool LoadTextRect(const std::wstring& xml) = 0; virtual bool LoadPathList(const std::wstring& xml) = 0; @@ -105,47 +88,7 @@ public: bool SetType(int ShapeType); - virtual bool SetProperties(CBaseShape* Shape) - { - if( Shape == NULL) - return false; - - m_oPath = Shape->m_oPath; - m_strPath = Shape->m_strPath; - m_strRect = Shape->m_strRect; - - m_arAdjustments.clear(); - for(size_t i = 0; i < Shape->m_arAdjustments.size(); i++) - m_arAdjustments.push_back(Shape->m_arAdjustments[i]); - - m_arGuides.clear(); - for(size_t i = 0; i < Shape->m_arGuides.size(); i++) - m_arGuides.push_back(Shape->m_arGuides[i]); - - m_eJoin = Shape->m_eJoin; - m_bConcentricFill = Shape->m_bConcentricFill; - - m_arConnectors.clear(); - for(size_t i = 0; i < Shape->m_arConnectors.size(); i++) - m_arConnectors.push_back(Shape->m_arConnectors[i]); - - m_arConnectorAngles.clear(); - for(size_t i = 0; i < Shape->m_arConnectorAngles.size(); i++) - m_arConnectorAngles.push_back(Shape->m_arConnectorAngles[i]); - - m_arTextRects.clear(); - for(size_t i = 0; i < Shape->m_arTextRects.size(); i++) - m_arTextRects.push_back(Shape->m_arTextRects[i]); - - m_arHandles.clear(); - for(size_t i = 0; i < Shape->m_arHandles.size(); i++) - m_arHandles.push_back(Shape->m_arHandles[i]); - - - m_strRect = Shape->m_strRect; - m_strTransformXml = Shape->m_strTransformXml; - return true; - } + virtual bool SetProperties(CBaseShape* Shape); //virtual bool SetToDublicate(CBaseShape* Shape) //{ diff --git a/MsBinaryFile/Common/ODraw/CustomGeomShape.cpp b/MsBinaryFile/Common/ODraw/CustomGeomShape.cpp new file mode 100644 index 0000000000..7da3febd54 --- /dev/null +++ b/MsBinaryFile/Common/ODraw/CustomGeomShape.cpp @@ -0,0 +1,365 @@ +/* + * (c) Copyright Ascensio System SIA 2010-2019 + * + * 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 20A-12 Ernesta Birznieka-Upisha + * street, Riga, Latvia, EU, LV-1050. + * + * 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 "CustomGeomShape.h" + +namespace NSCustomShapesConvert +{ + CSegment::CSegment(RulesType eType, WORD nCount) + { + m_eRuler = eType; + m_nCount = nCount; + } + CSegment::CSegment(const CSegment& oSrc) + { + m_eRuler = oSrc.m_eRuler; + m_nCount = oSrc.m_nCount; + } + CSegment& CSegment::operator=(const CSegment& oSrc) + { + m_eRuler = oSrc.m_eRuler; + m_nCount = oSrc.m_nCount; + + return (*this); + } + CSegment::~CSegment() + { + } + + CGuide::CGuide() + { + m_eType = ftVal; + + m_param_type1 = 0; + m_param_type2 = 0; + m_param_type3 = 0; + + m_param_value1 = 0; + m_param_value2 = 0; + m_param_value3 = 0; + + } + CGuide::CGuide(const CGuide& oSrc) + { + *this = oSrc; + } + CGuide& CGuide::operator=(const CGuide& oSrc) + { + m_eType = oSrc.m_eType; + + m_param_type1 = oSrc.m_param_type1; + m_param_type2 = oSrc.m_param_type2; + m_param_type3 = oSrc.m_param_type3; + + m_param_value1 = oSrc.m_param_value1; + m_param_value2 = oSrc.m_param_value2; + m_param_value3 = oSrc.m_param_value3; + + return *this; + } + void CGuide::SetToFormula(NSCustomShapesConvert::CFormula& oFormula) + { + oFormula.m_eFormulaType = m_eType; + + SetParam(m_param_type1, m_param_value1, oFormula.m_eType1, oFormula.m_lParam1); + SetParam(m_param_type2, m_param_value2, oFormula.m_eType2, oFormula.m_lParam2); + SetParam(m_param_type3, m_param_value3, oFormula.m_eType3, oFormula.m_lParam3); + } + void CGuide::SetParam(BYTE type, WORD param, ParamType& param_type, LONG& param_value) + { + if (0 == type) + { + param_type = ptValue; + param_value = (LONG)param; + } + + if (0x0140 == param) + { + param_type = ptValue; + param_value = ShapeSizeVML / 2; + return; + } + if (0x0141 == param) + { + param_type = ptValue; + param_value = ShapeSizeVML / 2; + return; + } + if (0x0142 == param) + { + param_type = ptValue; + param_value = ShapeSizeVML; + return; + } + if (0x0143 == param) + { + param_type = ptValue; + param_value = ShapeSizeVML; + return; + } + + if ((0x0147 <= param) && (param <= 0x014E)) + { + param_type = ptAdjust; + param_value = (LONG)(param - 0x0147); + return; + } + + if ((0x0400 <= param) && (param <= 0x047F)) + { + param_type = ptFormula; + param_value = (LONG)(param - 0x0400); + return; + } + + param_type = ptValue; + param_value = ShapeSizeVML; + } + + CCustomVML::CCustomVML() : m_arVertices(), m_arSegments(), m_arGuides(), m_pAdjustValues(NULL) + { + m_ePath = rtCurveTo/*rtLineTo*/; + + m_bIsPathPresent = false; + } + CCustomVML::CCustomVML(const CCustomVML& oSrc) + { + *this = oSrc; + } + CCustomVML& CCustomVML::operator=(const CCustomVML& oSrc) + { + m_ePath = oSrc.m_ePath; + + m_arVertices.clear(); + m_arVertices.insert(m_arVertices.end(), oSrc.m_arVertices.begin(), oSrc.m_arVertices.end()); + + m_arSegments.clear(); + m_arSegments.insert(m_arSegments.end(), oSrc.m_arSegments.begin(), oSrc.m_arSegments.end()); + + m_arGuides.clear(); + m_arGuides.insert(m_arGuides.end(), oSrc.m_arGuides.begin(), oSrc.m_arGuides.end()); + + m_pAdjustValues = oSrc.m_pAdjustValues; + + m_bIsPathPresent = oSrc.m_bIsPathPresent; + + return *this; + } + CCustomVML::~CCustomVML() + { + } + bool CCustomVML::IsCustom() + { + return (!m_arVertices.empty() && (m_bIsPathPresent || !m_arSegments.empty())); + } + void CCustomVML::SetPath(RulesType ePath) + { + m_ePath = ePath; + m_bIsPathPresent = true; + } + void CCustomVML::LoadAHs(unsigned char* buffer, int buffer_size) + { + } + void CCustomVML::addSegment(RulesType eRuler, _UINT16 nCount) + { + CSegment oInfo(eRuler, nCount); + m_arSegments.push_back(oInfo); + } + void CCustomVML::addGuide(CGuide & oInfo) + { + m_arGuides.push_back(oInfo); + } + void CCustomVML::addAdjust(int lIndex, int lValue) + { + if (NULL == m_pAdjustValues) + return; + + int lCount = m_pAdjustValues->size(); + + while (lCount <= lIndex) + { + m_pAdjustValues->push_back(0); + lCount = m_pAdjustValues->size(); + } + + (*m_pAdjustValues)[lIndex] = lValue; + } + void CCustomVML::SetAdjusts(std::vector* pList) + { + m_pAdjustValues = pList; + } + void CCustomVML::ToCustomShape(CBaseShape* pShape, NSCustomShapesConvert::CFormulasManager& oManager) + { + if ((NULL == pShape) || (!IsCustom())) + return; + + oManager.Clear(); + // сначала заполним формулы + for (size_t nIndex = 0; nIndex < m_arGuides.size(); ++nIndex) + { + NSCustomShapesConvert::CFormula oF; + m_arGuides[nIndex].SetToFormula(oF); + oManager.AddFormula(oF); + } + + oManager.Clear(m_pAdjustValues); + + std::wstring strPath = _T(""); + + bool bBreak = false; + + long lMinF = (_INT32)0x80000000; + long lMaxF = (_INT32)0x8000007F; + + int nGuideIndex_x , nGuideIndex_y; + + if (0 == m_arSegments.size()) + { + strPath = GetRulerVML(m_ePath); + + for (size_t nIndex = 0; nIndex < m_arVertices.size(); ++nIndex) + { + nGuideIndex_x = nGuideIndex_y = -1; + + if (lMaxF > m_arVertices[nIndex].x ) nGuideIndex_x = (DWORD)m_arVertices[nIndex].x - (DWORD)lMinF; + if (lMaxF > m_arVertices[nIndex].y ) nGuideIndex_y = (DWORD)m_arVertices[nIndex].y - (DWORD)lMinF; + + if (nGuideIndex_x >= 0 && nGuideIndex_x < (int)m_arGuides.size()) + { + strPath += std::to_wstring(m_arGuides[nGuideIndex_x].m_param_value1) + L","; + } + else + { + strPath += std::to_wstring(m_arVertices[nIndex].x) + L","; + } + if (nGuideIndex_y >= 0 && nGuideIndex_y < (int)m_arGuides.size()) + { + strPath += std::to_wstring(m_arGuides[nGuideIndex_y].m_param_value1) + L","; + } + else + { + strPath += std::to_wstring(m_arVertices[nIndex].y) + L","; + } + } + strPath.erase(strPath.length() - 1); + } + else + { + size_t nStart = 0; + size_t nEnd = 0; + for (size_t nS = 0; nS < m_arSegments.size(); ++nS) + { + if (bBreak) + { + if ((rtEnd != m_arSegments[nS].m_eRuler) && + (rtNoFill != m_arSegments[nS].m_eRuler) && + (rtNoStroke != m_arSegments[nS].m_eRuler) && + (rtClose != m_arSegments[nS].m_eRuler)) + { + strPath += _T("e"); + break; + } + } + + if ((rtFillColor == m_arSegments[nS].m_eRuler) || (rtLineColor == m_arSegments[nS].m_eRuler)) + { + if (nStart < m_arVertices.size()) + { + if (rtFillColor == m_arSegments[nS].m_eRuler) + { + //m_oBrush.Color1 = (DWORD)m_arVertices[nStart].x; todooooo + //m_oBrush.Color2 = (DWORD)m_arVertices[nStart].y; + } + else + { + //m_oPen.Color = (DWORD)m_arVertices[nStart].x; todooooo + } + } + nEnd = nStart + m_arSegments[nS].m_nCount; + if (nEnd > m_arVertices.size()) + nEnd = m_arVertices.size(); + nStart = nEnd; + + if (nEnd == m_arVertices.size()) + { + bBreak = true; + } + continue; + } + + strPath += GetRulerVML(m_arSegments[nS].m_eRuler); + + nEnd = nStart + m_arSegments[nS].m_nCount; + if (nEnd > m_arVertices.size()) + nEnd = m_arVertices.size(); + + for (size_t nV = nStart; nV < nEnd; ++nV) + { + nGuideIndex_x = nGuideIndex_y = -1; + + if (lMaxF > m_arVertices[nV].x ) nGuideIndex_x = (DWORD)m_arVertices[nV].x - (DWORD)lMinF; + if (lMaxF > m_arVertices[nV].y ) nGuideIndex_y = (DWORD)m_arVertices[nV].y - (DWORD)lMinF; + + if (nGuideIndex_x >= 0 && nGuideIndex_x < (int)m_arGuides.size() ) + { + strPath += std::to_wstring(m_arGuides[nGuideIndex_x].m_param_value1) + L","; + } + else + { + strPath += std::to_wstring(m_arVertices[nV].x) + L","; + } + if (nGuideIndex_y >= 0 && nGuideIndex_y < (int)m_arGuides.size()) + { + strPath += std::to_wstring(m_arGuides[nGuideIndex_y].m_param_value1) + L","; + } + else + { + strPath += std::to_wstring(m_arVertices[nV].y) + L","; + } + } + + if (nEnd != nStart) + { + strPath.erase(strPath.length() - 1); + } + nStart = nEnd; + + if (nEnd == m_arVertices.size()) + { + bBreak = true; + } + } + } + oManager.CalculateResults(); + pShape->LoadPathList(strPath); + } +} diff --git a/MsBinaryFile/Common/ODraw/CustomGeomShape.h b/MsBinaryFile/Common/ODraw/CustomGeomShape.h index ea9218ab60..171cb95ea5 100644 --- a/MsBinaryFile/Common/ODraw/CustomGeomShape.h +++ b/MsBinaryFile/Common/ODraw/CustomGeomShape.h @@ -31,9 +31,7 @@ */ #pragma once - #include "BaseShape.h" - #include "FormulaShape.h" #include "../../../OOXML/SystemUtility/File.h" @@ -46,29 +44,10 @@ namespace NSCustomShapesConvert RulesType m_eRuler; WORD m_nCount; - CSegment(RulesType eType = rtMoveTo, WORD nCount = 2) - { - m_eRuler = eType; - m_nCount = nCount; - } - - CSegment(const CSegment& oSrc) - { - m_eRuler = oSrc.m_eRuler; - m_nCount = oSrc.m_nCount; - } - - CSegment& operator=(const CSegment& oSrc) - { - m_eRuler = oSrc.m_eRuler; - m_nCount = oSrc.m_nCount; - - return (*this); - } - - ~CSegment() - { - } + CSegment(RulesType eType = rtMoveTo, WORD nCount = 2); + CSegment(const CSegment& oSrc); + CSegment& operator=(const CSegment& oSrc); + ~CSegment(); }; class CGuide @@ -84,100 +63,14 @@ namespace NSCustomShapesConvert WORD m_param_value2; WORD m_param_value3; - CGuide() - { - m_eType = ftVal; + CGuide(); + CGuide(const CGuide& oSrc); - m_param_type1 = 0; - m_param_type2 = 0; - m_param_type3 = 0; - - m_param_value1 = 0; - m_param_value2 = 0; - m_param_value3 = 0; - - } - - CGuide(const CGuide& oSrc) - { - *this = oSrc; - } - - CGuide& operator=(const CGuide& oSrc) - { - m_eType = oSrc.m_eType; - - m_param_type1 = oSrc.m_param_type1; - m_param_type2 = oSrc.m_param_type2; - m_param_type3 = oSrc.m_param_type3; - - m_param_value1 = oSrc.m_param_value1; - m_param_value2 = oSrc.m_param_value2; - m_param_value3 = oSrc.m_param_value3; - - return *this; - } - - void SetToFormula(NSCustomShapesConvert::CFormula& oFormula) - { - oFormula.m_eFormulaType = m_eType; - - SetParam(m_param_type1, m_param_value1, oFormula.m_eType1, oFormula.m_lParam1); - SetParam(m_param_type2, m_param_value2, oFormula.m_eType2, oFormula.m_lParam2); - SetParam(m_param_type3, m_param_value3, oFormula.m_eType3, oFormula.m_lParam3); - } + CGuide& operator=(const CGuide& oSrc); + void SetToFormula(NSCustomShapesConvert::CFormula& oFormula); private: - void SetParam(BYTE type, WORD param, ParamType& param_type, LONG& param_value) - { - if (0 == type) - { - param_type = ptValue; - param_value = (LONG)param; - } - - if (0x0140 == param) - { - param_type = ptValue; - param_value = ShapeSizeVML / 2; - return; - } - if (0x0141 == param) - { - param_type = ptValue; - param_value = ShapeSizeVML / 2; - return; - } - if (0x0142 == param) - { - param_type = ptValue; - param_value = ShapeSizeVML; - return; - } - if (0x0143 == param) - { - param_type = ptValue; - param_value = ShapeSizeVML; - return; - } - - if ((0x0147 <= param) && (param <= 0x014E)) - { - param_type = ptAdjust; - param_value = (LONG)(param - 0x0147); - return; - } - - if ((0x0400 <= param) && (param <= 0x047F)) - { - param_type = ptFormula; - param_value = (LONG)(param - 0x0400); - return; - } - - param_type = ptValue; - param_value = ShapeSizeVML; - } + void SetParam(BYTE type, WORD param, ParamType& param_type, LONG& param_value); }; class CCustomVML @@ -192,229 +85,21 @@ namespace NSCustomShapesConvert bool m_bIsPathPresent; - CCustomVML() : m_arVertices(), m_arSegments(), m_arGuides(), m_pAdjustValues(NULL) - { - m_ePath = rtCurveTo/*rtLineTo*/; - - m_bIsPathPresent = false; - } - - CCustomVML(const CCustomVML& oSrc) - { - *this = oSrc; - } + CCustomVML(); + CCustomVML(const CCustomVML& oSrc); + CCustomVML& operator=(const CCustomVML& oSrc); + ~CCustomVML(); - CCustomVML& operator=(const CCustomVML& oSrc) - { - m_ePath = oSrc.m_ePath; + bool IsCustom(); - m_arVertices.clear(); - m_arVertices.insert(m_arVertices.end(), oSrc.m_arVertices.begin(), oSrc.m_arVertices.end()); + void SetPath(RulesType ePath); + void LoadAHs(unsigned char* buffer, int buffer_size); - m_arSegments.clear(); - m_arSegments.insert(m_arSegments.end(), oSrc.m_arSegments.begin(), oSrc.m_arSegments.end()); + void addSegment(RulesType eRuler, _UINT16 nCount); + void addGuide(CGuide & oInfo); + void addAdjust(int lIndex, int lValue); - m_arGuides.clear(); - m_arGuides.insert(m_arGuides.end(), oSrc.m_arGuides.begin(), oSrc.m_arGuides.end()); - - m_pAdjustValues = oSrc.m_pAdjustValues; - - m_bIsPathPresent = oSrc.m_bIsPathPresent; - - return *this; - } - - ~CCustomVML() - { - } - - bool IsCustom() - { - return (!m_arVertices.empty() && (m_bIsPathPresent || !m_arSegments.empty())); - } - - void SetPath(RulesType ePath) - { - m_ePath = ePath; - m_bIsPathPresent = true; - } - void LoadAHs(unsigned char* buffer, int buffer_size) - { - } - void addSegment(RulesType eRuler, _UINT16 nCount) - { - CSegment oInfo(eRuler, nCount); - m_arSegments.push_back(oInfo); - } - void addGuide(CGuide & oInfo) - { - m_arGuides.push_back(oInfo); - } - void addAdjust(int lIndex, int lValue) - { - if (NULL == m_pAdjustValues) - return; - - int lCount = m_pAdjustValues->size(); - - while (lCount <= lIndex) - { - m_pAdjustValues->push_back(0); - lCount = m_pAdjustValues->size(); - } - - (*m_pAdjustValues)[lIndex] = lValue; - } - - void SetAdjusts(std::vector* pList) - { - m_pAdjustValues = pList; - } - - void ToCustomShape(CBaseShape* pShape, NSCustomShapesConvert::CFormulasManager& oManager) - { - if ((NULL == pShape) || (!IsCustom())) - return; - - oManager.Clear(); - // сначала заполним формулы - for (size_t nIndex = 0; nIndex < m_arGuides.size(); ++nIndex) - { - NSCustomShapesConvert::CFormula oF; - m_arGuides[nIndex].SetToFormula(oF); - oManager.AddFormula(oF); - } - - oManager.Clear(m_pAdjustValues); - - std::wstring strPath = _T(""); - - bool bBreak = false; - - long lMinF = (_INT32)0x80000000; - long lMaxF = (_INT32)0x8000007F; - - int nGuideIndex_x , nGuideIndex_y; - - if (0 == m_arSegments.size()) - { - strPath = GetRulerVML(m_ePath); - - for (size_t nIndex = 0; nIndex < m_arVertices.size(); ++nIndex) - { - nGuideIndex_x = nGuideIndex_y = -1; - - if (lMaxF > m_arVertices[nIndex].x ) nGuideIndex_x = (DWORD)m_arVertices[nIndex].x - (DWORD)lMinF; - if (lMaxF > m_arVertices[nIndex].y ) nGuideIndex_y = (DWORD)m_arVertices[nIndex].y - (DWORD)lMinF; - - if (nGuideIndex_x >= 0 && nGuideIndex_x < (int)m_arGuides.size()) - { - strPath += std::to_wstring(m_arGuides[nGuideIndex_x].m_param_value1) + L","; - } - else - { - strPath += std::to_wstring(m_arVertices[nIndex].x) + L","; - } - if (nGuideIndex_y >= 0 && nGuideIndex_y < (int)m_arGuides.size()) - { - strPath += std::to_wstring(m_arGuides[nGuideIndex_y].m_param_value1) + L","; - } - else - { - strPath += std::to_wstring(m_arVertices[nIndex].y) + L","; - } - } - strPath.erase(strPath.length() - 1); - } - else - { - size_t nStart = 0; - size_t nEnd = 0; - for (size_t nS = 0; nS < m_arSegments.size(); ++nS) - { - if (bBreak) - { - if ((rtEnd != m_arSegments[nS].m_eRuler) && - (rtNoFill != m_arSegments[nS].m_eRuler) && - (rtNoStroke != m_arSegments[nS].m_eRuler) && - (rtClose != m_arSegments[nS].m_eRuler)) - { - strPath += _T("e"); - break; - } - } - - if ((rtFillColor == m_arSegments[nS].m_eRuler) || (rtLineColor == m_arSegments[nS].m_eRuler)) - { - if (nStart < m_arVertices.size()) - { - if (rtFillColor == m_arSegments[nS].m_eRuler) - { - //m_oBrush.Color1 = (DWORD)m_arVertices[nStart].x; todooooo - //m_oBrush.Color2 = (DWORD)m_arVertices[nStart].y; - } - else - { - //m_oPen.Color = (DWORD)m_arVertices[nStart].x; todooooo - } - } - nEnd = nStart + m_arSegments[nS].m_nCount; - if (nEnd > m_arVertices.size()) - nEnd = m_arVertices.size(); - nStart = nEnd; - - if (nEnd == m_arVertices.size()) - { - bBreak = true; - } - continue; - } - - strPath += GetRulerVML(m_arSegments[nS].m_eRuler); - - nEnd = nStart + m_arSegments[nS].m_nCount; - if (nEnd > m_arVertices.size()) - nEnd = m_arVertices.size(); - - for (size_t nV = nStart; nV < nEnd; ++nV) - { - nGuideIndex_x = nGuideIndex_y = -1; - - if (lMaxF > m_arVertices[nV].x ) nGuideIndex_x = (DWORD)m_arVertices[nV].x - (DWORD)lMinF; - if (lMaxF > m_arVertices[nV].y ) nGuideIndex_y = (DWORD)m_arVertices[nV].y - (DWORD)lMinF; - - if (nGuideIndex_x >= 0 && nGuideIndex_x < (int)m_arGuides.size() ) - { - strPath += std::to_wstring(m_arGuides[nGuideIndex_x].m_param_value1) + L","; - } - else - { - strPath += std::to_wstring(m_arVertices[nV].x) + L","; - } - if (nGuideIndex_y >= 0 && nGuideIndex_y < (int)m_arGuides.size()) - { - strPath += std::to_wstring(m_arGuides[nGuideIndex_y].m_param_value1) + L","; - } - else - { - strPath += std::to_wstring(m_arVertices[nV].y) + L","; - } - } - - if (nEnd != nStart) - { - strPath.erase(strPath.length() - 1); - } - nStart = nEnd; - - if (nEnd == m_arVertices.size()) - { - bBreak = true; - } - } - } - oManager.CalculateResults(); - pShape->LoadPathList(strPath); - } + void SetAdjusts(std::vector* pList); + void ToCustomShape(CBaseShape* pShape, NSCustomShapesConvert::CFormulasManager& oManager); }; } diff --git a/MsBinaryFile/Common/ODraw/CustomShape.cpp b/MsBinaryFile/Common/ODraw/CustomShape.cpp index 7ff56debfa..dd61164a49 100644 --- a/MsBinaryFile/Common/ODraw/CustomShape.cpp +++ b/MsBinaryFile/Common/ODraw/CustomShape.cpp @@ -47,252 +47,345 @@ using namespace ODRAW; namespace NSCustomShapesConvert { -CCustomShape* CCustomShape::CreateByType(oox::MSOSPT type) -{ - CCustomShape* pShape = NULL; - switch (type) + CCustomShape::CCustomShape() : CBaseShape() { -// msosptNotchedCircularArrow 0x00000064 A value that SHOULD NOT be used. -// msosptHostControl 0x000000C9 A value that SHOULD NOT be used. + m_eType = oox::msosptNotPrimitive; + } + CCustomShape::~CCustomShape() + { + } + void CCustomShape::AddGuide(const std::wstring& strGuide) + { + m_oManager.AddFormula(strGuide); + } + bool CCustomShape::LoadAdjustHandlesList(const std::wstring& xml) + { + return true; + } + bool CCustomShape::LoadConnectorsList(const std::wstring& xml) + { + return true; + } + bool CCustomShape::LoadTextRect(const std::wstring& xml) + { + std::vector oArray; + NSStringUtils::ParseString(_T(";"), xml, oArray); - case sptNotchedCircularArrow: - case sptHostControl: - case 0: { pShape = new CRectangleType(); break; } - //CREATE_BY_SPT(sptMin, CLineType) + LONG lCount = (LONG)oArray.size(); - CREATE_BY_SPT(sptAccentBorderCallout90, CAccentBorderCallout90Type) - CREATE_BY_SPT(sptAccentBorderCallout1, CAccentBorderCallout1Type) - CREATE_BY_SPT(sptAccentBorderCallout2, CAccentBorderCallout2Type) - CREATE_BY_SPT(sptAccentBorderCallout3, CAccentBorderCallout3Type) + if (lCount <= 0) + return true; - CREATE_BY_SPT(sptAccentCallout90, CAccentCallout90Type) - CREATE_BY_SPT(sptAccentCallout1, CAccentCallout1Type) - CREATE_BY_SPT(sptAccentCallout2, CAccentCallout2Type) - CREATE_BY_SPT(sptAccentCallout3, CAccentCallout3Type) - - CREATE_BY_SPT(sptBorderCallout90, CBorderCallout90Type) - CREATE_BY_SPT(sptBorderCallout1, CBorderCallout1Type) - CREATE_BY_SPT(sptBorderCallout2, CBorderCallout2Type) - CREATE_BY_SPT(sptBorderCallout3, CBorderCallout3Type) - - CREATE_BY_SPT(sptCallout90, CCallout90Type) - CREATE_BY_SPT(sptCallout1, CCallout1Type) - CREATE_BY_SPT(sptCallout2, CCallout2Type) - CREATE_BY_SPT(sptCallout3, CCallout3Type) - - CREATE_BY_SPT(sptActionButtonBlank, CActionButtonBlankType) - CREATE_BY_SPT(sptActionButtonHome, CActionButtonHomeType) - CREATE_BY_SPT(sptActionButtonHelp, CActionButtonHelpType) - CREATE_BY_SPT(sptActionButtonInformation, CActionButtonInfoType) - CREATE_BY_SPT(sptActionButtonBackPrevious, CActionButtonBackType) - CREATE_BY_SPT(sptActionButtonForwardNext, CActionButtonNextType) - CREATE_BY_SPT(sptActionButtonBeginning, CActionButtonBeginType) - CREATE_BY_SPT(sptActionButtonEnd, CActionButtonEndType) - CREATE_BY_SPT(sptActionButtonReturn, CActionButtonReturnType) - CREATE_BY_SPT(sptActionButtonDocument, CActionButtonDocType) - CREATE_BY_SPT(sptActionButtonSound, CActionButtonSoundType) - CREATE_BY_SPT(sptActionButtonMovie, CActionButtonMovieType) - - CREATE_BY_SPT(sptArc, CArcType) - CREATE_BY_SPT(sptLine, CLineType) - - CREATE_BY_SPT(sptBentArrow, CBentArrowType) - CREATE_BY_SPT(sptBentUpArrow, CBentUpArrowType) - CREATE_BY_SPT(sptBevel, CBevelType) - CREATE_BY_SPT(sptBlockArc, CBlockArcType) - CREATE_BY_SPT(sptBracePair, CBracePairType) - CREATE_BY_SPT(sptBracketPair, CBracketPairType) - - CREATE_BY_SPT(sptCan, CCanType) - CREATE_BY_SPT(sptChevron, CChevronType) - CREATE_BY_SPT(sptCircularArrow, CCircularArrowType) - CREATE_BY_SPT(sptCloudCallout, CCloudCalloutType) - CREATE_BY_SPT(sptCube, CCubeType) - CREATE_BY_SPT(sptCurvedDownArrow, CCurvedDownArrowType) - CREATE_BY_SPT(sptCurvedLeftArrow, CCurvedLeftArrowType) - CREATE_BY_SPT(sptCurvedRightArrow, CCurvedRightArrowType) - CREATE_BY_SPT(sptCurvedUpArrow, CCurvedUpArrowType) - - CREATE_BY_SPT(sptDiamond, CDiamondType) - CREATE_BY_SPT(sptDonut, CDonutType) - CREATE_BY_SPT(sptDownArrowCallout, CDownArrowCalloutType) - CREATE_BY_SPT(sptDownArrow, CDownArrowType) - - CREATE_BY_SPT(sptEllipse, CEllipseType) - CREATE_BY_SPT(sptEllipseRibbon, CEllipceRibbonType) - CREATE_BY_SPT(sptEllipseRibbon2, CEllipceRibbon2Type) - - CREATE_BY_SPT(sptFlowChartAlternateProcess, CFlowChartAlternateProcessType) - CREATE_BY_SPT(sptFlowChartCollate, CFlowChartCollateType) - CREATE_BY_SPT(sptFlowChartConnector, CFlowChartConnectorType) - CREATE_BY_SPT(sptFlowChartDecision, CFlowChartDecisionType) - CREATE_BY_SPT(sptFlowChartDisplay, CFlowChartDisplayType) - CREATE_BY_SPT(sptFlowChartDelay, CFlowChartDelayType) - CREATE_BY_SPT(sptFlowChartDocument, CFlowChartDocumentType) - CREATE_BY_SPT(sptFlowChartExtract, CFlowChartExtractType) - CREATE_BY_SPT(sptFlowChartInputOutput, CFlowChartInputOutputType) - CREATE_BY_SPT(sptFlowChartInternalStorage, CFlowChartInternalStorageType) - CREATE_BY_SPT(sptFlowChartMagneticDisk, CFlowChartMagneticDiskType) - CREATE_BY_SPT(sptFlowChartMagneticDrum, CFlowChartMagneticDrumType) - CREATE_BY_SPT(sptFlowChartMagneticTape, CFlowChartMagneticTapeType) - CREATE_BY_SPT(sptFlowChartManualInput, CFlowChartManualInputType) - CREATE_BY_SPT(sptFlowChartManualOperation, CFlowChartManualOperationType) - CREATE_BY_SPT(sptFlowChartMerge, CFlowChartMergeType) - CREATE_BY_SPT(sptFlowChartMultidocument, CFlowChartMultidocumentType) - CREATE_BY_SPT(sptFlowChartOffpageConnector, CFlowChartOffpageConnectorType) - CREATE_BY_SPT(sptFlowChartOnlineStorage, CFlowChartOnlineStorageType) - CREATE_BY_SPT(sptFlowChartOr, CFlowChartOrType) - CREATE_BY_SPT(sptFlowChartPredefinedProcess, CFlowChartPredefinedProcessType) - CREATE_BY_SPT(sptFlowChartPreparation, CFlowChartPreparationType) - CREATE_BY_SPT(sptFlowChartProcess, CFlowChartProcessType) - CREATE_BY_SPT(sptFlowChartPunchedCard, CFlowChartPunchedCardType) - CREATE_BY_SPT(sptFlowChartPunchedTape, CFlowChartPunchedTapeType) - CREATE_BY_SPT(sptFlowChartSort, CFlowChartSortType) - CREATE_BY_SPT(sptFlowChartSummingJunction, CFlowChartSummingJunctionType) - CREATE_BY_SPT(sptFlowChartTerminator, CFlowChartTerminatorType) - CREATE_BY_SPT(sptFoldedCorner, CFoldedCornerType) - - CREATE_BY_SPT(sptHeart, CHeartType) - CREATE_BY_SPT(sptHexagon, CHexagonType) - CREATE_BY_SPT(sptHomePlate, CHomePlateType) - - CREATE_BY_SPT(sptIrregularSeal1, CIrregularSealOneType) - CREATE_BY_SPT(sptIrregularSeal2, CIrregularSealTwo) - CREATE_BY_SPT(sptIsocelesTriangle, CIsoscelesTriangleType) - - CREATE_BY_SPT(sptLeftArrowCallout, CLeftArrowCalloutType) - CREATE_BY_SPT(sptLeftArrow, CLeftArrowType) - CREATE_BY_SPT(sptLeftBrace, CLeftBraceType) - CREATE_BY_SPT(sptLeftBracket, CLeftBracketType) - CREATE_BY_SPT(sptLeftRightArrowCallout, CLeftRightArrowCalloutType) - CREATE_BY_SPT(sptLeftRightArrow, CLeftRightArrowType) - CREATE_BY_SPT(sptLeftRightUpArrow, CLeftRightUpArrow) - CREATE_BY_SPT(sptLeftUpArrow, CLeftUpArrowType) - CREATE_BY_SPT(sptLightningBolt, CLightningBoltType) - - CREATE_BY_SPT(sptMoon, CMoonType) - - CREATE_BY_SPT(sptNoSmoking, CNoSmokingType) - CREATE_BY_SPT(sptNotchedRightArrow, CNotchedRightArrowType) - - CREATE_BY_SPT(sptOctagon, COctagonType) - - CREATE_BY_SPT(sptParallelogram, CParallelogramType) - CREATE_BY_SPT(sptPentagon, CPentagonType) - CREATE_BY_SPT(sptPlaque, CPlaqueType) - CREATE_BY_SPT(sptPlus, CPlusType) - - CREATE_BY_SPT(sptQuadArrowCallout, CQuadArrowCalloutType) - CREATE_BY_SPT(sptQuadArrow, CQuadArrowType) - - CREATE_BY_SPT(sptRectangle, CRectangleType) - CREATE_BY_SPT(sptRibbon, CRibbonDownType) - CREATE_BY_SPT(sptRibbon2, CRibbonUpType) - CREATE_BY_SPT(sptRightArrowCallout, CRightArrowCalloutType) - CREATE_BY_SPT(sptArrow, CRightArrowType) - CREATE_BY_SPT(sptRightBrace, CRightBracetype) - CREATE_BY_SPT(sptRightBracket, CRightBracketType) - CREATE_BY_SPT(sptRightTriangle, CRightTriangleType) - CREATE_BY_SPT(sptRoundRectangle, CRoundedRectangleType) - - CREATE_BY_SPT(sptSeal16, CSeal16Type) - CREATE_BY_SPT(sptSeal24, CSeal24Type) - CREATE_BY_SPT(sptSeal32, CSeal32Type) - CREATE_BY_SPT(sptSeal4, CSeal4Type) - CREATE_BY_SPT(sptSeal8, CSeal8Type) - CREATE_BY_SPT(sptSmileyFace, CSmileyFaceType) - CREATE_BY_SPT(sptStar, CStarType) - CREATE_BY_SPT(sptStraightConnector1, CStraightConnectorType) - CREATE_BY_SPT(sptStripedRightArrow, CStripedRightArrowType) - CREATE_BY_SPT(sptSun, CSunType) - - CREATE_BY_SPT(sptTextBox, CTextboxType) - CREATE_BY_SPT(sptTrapezoid, CTrapezoidType) - - CREATE_BY_SPT(sptUpArrowCallout, CUpArrowCalloutType) - CREATE_BY_SPT(sptUpArrow, CUpArrowType) - CREATE_BY_SPT(sptUpDownArrowCallout, CUpDownArrowCalloutType) - CREATE_BY_SPT(sptUpDownArrow, CUpDownArrowType) - CREATE_BY_SPT(sptUturnArrow, CUturnArrowType) - - CREATE_BY_SPT(sptVerticalScroll, CVerticalScrollType) - CREATE_BY_SPT(sptHorizontalScroll, CHorizontalScrollType) - - CREATE_BY_SPT(sptWedgeEllipseCallout, CWedgeEllipseCalloutType) - CREATE_BY_SPT(sptWedgeRectCallout, CWedgeRectCalloutType) - CREATE_BY_SPT(sptWedgeRRectCallout, CWedgeRoundedRectCalloutType) - - CREATE_BY_SPT(sptWave, CWaveType) - CREATE_BY_SPT(sptDoubleWave, CWaveDoubleType) - - case sptBentConnector2: - case sptBentConnector3: - case sptBentConnector4: - case sptBentConnector5: - { - pShape = new CBentConnectorType(); - break; - } - case sptCurvedConnector2: - case sptCurvedConnector3: - case sptCurvedConnector4: - case sptCurvedConnector5: - { - pShape = new CCurvedConnectorType(); - break; - } - - case sptTextPlainText: - case sptTextStop: - case sptTextTriangle: - case sptTextTriangleInverted: - case sptTextChevron: - case sptTextChevronInverted: - case sptTextRingInside: - case sptTextRingOutside: - case sptTextArchUpCurve: - case sptTextArchDownCurve: - case sptTextCircleCurve: - case sptTextButtonCurve: - case sptTextArchUpPour: - case sptTextArchDownPour: - case sptTextCirclePour: - case sptTextButtonPour: - case sptTextCurveUp: - case sptTextCurveDown: - case sptTextCascadeUp: - case sptTextCascadeDown: - case sptTextWave1: - case sptTextWave2: - case sptTextWave3: - case sptTextWave4: - case sptTextInflate: - case sptTextDeflate: - case sptTextInflateBottom: - case sptTextDeflateBottom: - case sptTextInflateTop: - case sptTextDeflateTop: - case sptTextDeflateInflate: - case sptTextDeflateInflateDeflate: - case sptTextFadeRight: - case sptTextFadeLeft: - case sptTextFadeUp: - case sptTextFadeDown: - case sptTextSlantUp: - case sptTextSlantDown: - case sptTextCanUp: - case sptTextCanDown: + m_arStringTextRects.clear(); + for (LONG i = 0; i < lCount; ++i) { - pShape = new CTextboxType(); + m_arStringTextRects.push_back(oArray[i]); } - default: break; - }; + return true; + } + bool CCustomShape::LoadPathList(const std::wstring& xml) + { + m_strPath = xml; - if (NULL != pShape) - pShape->m_eType = type; - - return pShape; -} + m_oPath.FromXML(xml, m_oManager); + return true; + } + bool CCustomShape::SetAdjustment(long index, long value) + { + if (index < (long)m_arAdjustments.size() && index >= 0) + { + m_arAdjustments[index] = value; + return TRUE; + } + return FALSE; + } + void CCustomShape::ReCalculate() + { + m_oManager.Clear(&m_arAdjustments); + m_oManager.CalculateResults(); + + if (_T("") == m_strPath) + return; + + LoadPathList(m_strPath); + } + bool CCustomShape::SetProperties(CBaseShape* Shape) + { + if(Shape == NULL) + return false; + + m_oManager = ((CCustomShape*)Shape)->m_oManager; + + //m_strPathLimoX = ((CCustomShape*)Shape)->m_strPathLimoX; + //m_strPathLimoY = ((CCustomShape*)Shape)->m_strPathLimoY; + + //m_arStringTextRects.clear(); + //m_arStringTextRects.insert(m_arStringTextRects.end(), ((CCustomShape*)Shape)->m_arStringTextRects.begin(), ((CCustomShape*)Shape)->m_arStringTextRects.end()); + + return CBaseShape::SetProperties(Shape); + } + bool CCustomShape::SetShapeType(oox::MSOSPT type) + { + CCustomShape* l_pShape = CreateByType(type); + if(l_pShape != NULL) + { + m_eType = type; + + SetProperties(l_pShape); + delete l_pShape; + return true; + } + + m_eType = oox::msosptNotPrimitive; + return false; + } + CCustomShape* CCustomShape::CreateByType(oox::MSOSPT type) + { + CCustomShape* pShape = NULL; + switch (type) + { + // msosptNotchedCircularArrow 0x00000064 A value that SHOULD NOT be used. + // msosptHostControl 0x000000C9 A value that SHOULD NOT be used. + + case sptNotchedCircularArrow: + case sptHostControl: + case 0: { pShape = new CRectangleType(); break; } + //CREATE_BY_SPT(sptMin, CLineType) + + CREATE_BY_SPT(sptAccentBorderCallout90, CAccentBorderCallout90Type) + CREATE_BY_SPT(sptAccentBorderCallout1, CAccentBorderCallout1Type) + CREATE_BY_SPT(sptAccentBorderCallout2, CAccentBorderCallout2Type) + CREATE_BY_SPT(sptAccentBorderCallout3, CAccentBorderCallout3Type) + + CREATE_BY_SPT(sptAccentCallout90, CAccentCallout90Type) + CREATE_BY_SPT(sptAccentCallout1, CAccentCallout1Type) + CREATE_BY_SPT(sptAccentCallout2, CAccentCallout2Type) + CREATE_BY_SPT(sptAccentCallout3, CAccentCallout3Type) + + CREATE_BY_SPT(sptBorderCallout90, CBorderCallout90Type) + CREATE_BY_SPT(sptBorderCallout1, CBorderCallout1Type) + CREATE_BY_SPT(sptBorderCallout2, CBorderCallout2Type) + CREATE_BY_SPT(sptBorderCallout3, CBorderCallout3Type) + + CREATE_BY_SPT(sptCallout90, CCallout90Type) + CREATE_BY_SPT(sptCallout1, CCallout1Type) + CREATE_BY_SPT(sptCallout2, CCallout2Type) + CREATE_BY_SPT(sptCallout3, CCallout3Type) + + CREATE_BY_SPT(sptActionButtonBlank, CActionButtonBlankType) + CREATE_BY_SPT(sptActionButtonHome, CActionButtonHomeType) + CREATE_BY_SPT(sptActionButtonHelp, CActionButtonHelpType) + CREATE_BY_SPT(sptActionButtonInformation, CActionButtonInfoType) + CREATE_BY_SPT(sptActionButtonBackPrevious, CActionButtonBackType) + CREATE_BY_SPT(sptActionButtonForwardNext, CActionButtonNextType) + CREATE_BY_SPT(sptActionButtonBeginning, CActionButtonBeginType) + CREATE_BY_SPT(sptActionButtonEnd, CActionButtonEndType) + CREATE_BY_SPT(sptActionButtonReturn, CActionButtonReturnType) + CREATE_BY_SPT(sptActionButtonDocument, CActionButtonDocType) + CREATE_BY_SPT(sptActionButtonSound, CActionButtonSoundType) + CREATE_BY_SPT(sptActionButtonMovie, CActionButtonMovieType) + + CREATE_BY_SPT(sptArc, CArcType) + CREATE_BY_SPT(sptLine, CLineType) + + CREATE_BY_SPT(sptBentArrow, CBentArrowType) + CREATE_BY_SPT(sptBentUpArrow, CBentUpArrowType) + CREATE_BY_SPT(sptBevel, CBevelType) + CREATE_BY_SPT(sptBlockArc, CBlockArcType) + CREATE_BY_SPT(sptBracePair, CBracePairType) + CREATE_BY_SPT(sptBracketPair, CBracketPairType) + + CREATE_BY_SPT(sptCan, CCanType) + CREATE_BY_SPT(sptChevron, CChevronType) + CREATE_BY_SPT(sptCircularArrow, CCircularArrowType) + CREATE_BY_SPT(sptCloudCallout, CCloudCalloutType) + CREATE_BY_SPT(sptCube, CCubeType) + CREATE_BY_SPT(sptCurvedDownArrow, CCurvedDownArrowType) + CREATE_BY_SPT(sptCurvedLeftArrow, CCurvedLeftArrowType) + CREATE_BY_SPT(sptCurvedRightArrow, CCurvedRightArrowType) + CREATE_BY_SPT(sptCurvedUpArrow, CCurvedUpArrowType) + + CREATE_BY_SPT(sptDiamond, CDiamondType) + CREATE_BY_SPT(sptDonut, CDonutType) + CREATE_BY_SPT(sptDownArrowCallout, CDownArrowCalloutType) + CREATE_BY_SPT(sptDownArrow, CDownArrowType) + + CREATE_BY_SPT(sptEllipse, CEllipseType) + CREATE_BY_SPT(sptEllipseRibbon, CEllipceRibbonType) + CREATE_BY_SPT(sptEllipseRibbon2, CEllipceRibbon2Type) + + CREATE_BY_SPT(sptFlowChartAlternateProcess, CFlowChartAlternateProcessType) + CREATE_BY_SPT(sptFlowChartCollate, CFlowChartCollateType) + CREATE_BY_SPT(sptFlowChartConnector, CFlowChartConnectorType) + CREATE_BY_SPT(sptFlowChartDecision, CFlowChartDecisionType) + CREATE_BY_SPT(sptFlowChartDisplay, CFlowChartDisplayType) + CREATE_BY_SPT(sptFlowChartDelay, CFlowChartDelayType) + CREATE_BY_SPT(sptFlowChartDocument, CFlowChartDocumentType) + CREATE_BY_SPT(sptFlowChartExtract, CFlowChartExtractType) + CREATE_BY_SPT(sptFlowChartInputOutput, CFlowChartInputOutputType) + CREATE_BY_SPT(sptFlowChartInternalStorage, CFlowChartInternalStorageType) + CREATE_BY_SPT(sptFlowChartMagneticDisk, CFlowChartMagneticDiskType) + CREATE_BY_SPT(sptFlowChartMagneticDrum, CFlowChartMagneticDrumType) + CREATE_BY_SPT(sptFlowChartMagneticTape, CFlowChartMagneticTapeType) + CREATE_BY_SPT(sptFlowChartManualInput, CFlowChartManualInputType) + CREATE_BY_SPT(sptFlowChartManualOperation, CFlowChartManualOperationType) + CREATE_BY_SPT(sptFlowChartMerge, CFlowChartMergeType) + CREATE_BY_SPT(sptFlowChartMultidocument, CFlowChartMultidocumentType) + CREATE_BY_SPT(sptFlowChartOffpageConnector, CFlowChartOffpageConnectorType) + CREATE_BY_SPT(sptFlowChartOnlineStorage, CFlowChartOnlineStorageType) + CREATE_BY_SPT(sptFlowChartOr, CFlowChartOrType) + CREATE_BY_SPT(sptFlowChartPredefinedProcess, CFlowChartPredefinedProcessType) + CREATE_BY_SPT(sptFlowChartPreparation, CFlowChartPreparationType) + CREATE_BY_SPT(sptFlowChartProcess, CFlowChartProcessType) + CREATE_BY_SPT(sptFlowChartPunchedCard, CFlowChartPunchedCardType) + CREATE_BY_SPT(sptFlowChartPunchedTape, CFlowChartPunchedTapeType) + CREATE_BY_SPT(sptFlowChartSort, CFlowChartSortType) + CREATE_BY_SPT(sptFlowChartSummingJunction, CFlowChartSummingJunctionType) + CREATE_BY_SPT(sptFlowChartTerminator, CFlowChartTerminatorType) + CREATE_BY_SPT(sptFoldedCorner, CFoldedCornerType) + + CREATE_BY_SPT(sptHeart, CHeartType) + CREATE_BY_SPT(sptHexagon, CHexagonType) + CREATE_BY_SPT(sptHomePlate, CHomePlateType) + + CREATE_BY_SPT(sptIrregularSeal1, CIrregularSealOneType) + CREATE_BY_SPT(sptIrregularSeal2, CIrregularSealTwo) + CREATE_BY_SPT(sptIsocelesTriangle, CIsoscelesTriangleType) + + CREATE_BY_SPT(sptLeftArrowCallout, CLeftArrowCalloutType) + CREATE_BY_SPT(sptLeftArrow, CLeftArrowType) + CREATE_BY_SPT(sptLeftBrace, CLeftBraceType) + CREATE_BY_SPT(sptLeftBracket, CLeftBracketType) + CREATE_BY_SPT(sptLeftRightArrowCallout, CLeftRightArrowCalloutType) + CREATE_BY_SPT(sptLeftRightArrow, CLeftRightArrowType) + CREATE_BY_SPT(sptLeftRightUpArrow, CLeftRightUpArrow) + CREATE_BY_SPT(sptLeftUpArrow, CLeftUpArrowType) + CREATE_BY_SPT(sptLightningBolt, CLightningBoltType) + + CREATE_BY_SPT(sptMoon, CMoonType) + + CREATE_BY_SPT(sptNoSmoking, CNoSmokingType) + CREATE_BY_SPT(sptNotchedRightArrow, CNotchedRightArrowType) + + CREATE_BY_SPT(sptOctagon, COctagonType) + + CREATE_BY_SPT(sptParallelogram, CParallelogramType) + CREATE_BY_SPT(sptPentagon, CPentagonType) + CREATE_BY_SPT(sptPlaque, CPlaqueType) + CREATE_BY_SPT(sptPlus, CPlusType) + + CREATE_BY_SPT(sptQuadArrowCallout, CQuadArrowCalloutType) + CREATE_BY_SPT(sptQuadArrow, CQuadArrowType) + + CREATE_BY_SPT(sptRectangle, CRectangleType) + CREATE_BY_SPT(sptRibbon, CRibbonDownType) + CREATE_BY_SPT(sptRibbon2, CRibbonUpType) + CREATE_BY_SPT(sptRightArrowCallout, CRightArrowCalloutType) + CREATE_BY_SPT(sptArrow, CRightArrowType) + CREATE_BY_SPT(sptRightBrace, CRightBracetype) + CREATE_BY_SPT(sptRightBracket, CRightBracketType) + CREATE_BY_SPT(sptRightTriangle, CRightTriangleType) + CREATE_BY_SPT(sptRoundRectangle, CRoundedRectangleType) + + CREATE_BY_SPT(sptSeal16, CSeal16Type) + CREATE_BY_SPT(sptSeal24, CSeal24Type) + CREATE_BY_SPT(sptSeal32, CSeal32Type) + CREATE_BY_SPT(sptSeal4, CSeal4Type) + CREATE_BY_SPT(sptSeal8, CSeal8Type) + CREATE_BY_SPT(sptSmileyFace, CSmileyFaceType) + CREATE_BY_SPT(sptStar, CStarType) + CREATE_BY_SPT(sptStraightConnector1, CStraightConnectorType) + CREATE_BY_SPT(sptStripedRightArrow, CStripedRightArrowType) + CREATE_BY_SPT(sptSun, CSunType) + + CREATE_BY_SPT(sptTextBox, CTextboxType) + CREATE_BY_SPT(sptTrapezoid, CTrapezoidType) + + CREATE_BY_SPT(sptUpArrowCallout, CUpArrowCalloutType) + CREATE_BY_SPT(sptUpArrow, CUpArrowType) + CREATE_BY_SPT(sptUpDownArrowCallout, CUpDownArrowCalloutType) + CREATE_BY_SPT(sptUpDownArrow, CUpDownArrowType) + CREATE_BY_SPT(sptUturnArrow, CUturnArrowType) + + CREATE_BY_SPT(sptVerticalScroll, CVerticalScrollType) + CREATE_BY_SPT(sptHorizontalScroll, CHorizontalScrollType) + + CREATE_BY_SPT(sptWedgeEllipseCallout, CWedgeEllipseCalloutType) + CREATE_BY_SPT(sptWedgeRectCallout, CWedgeRectCalloutType) + CREATE_BY_SPT(sptWedgeRRectCallout, CWedgeRoundedRectCalloutType) + + CREATE_BY_SPT(sptWave, CWaveType) + CREATE_BY_SPT(sptDoubleWave, CWaveDoubleType) + + case sptBentConnector2: + case sptBentConnector3: + case sptBentConnector4: + case sptBentConnector5: + { + pShape = new CBentConnectorType(); + break; + } + case sptCurvedConnector2: + case sptCurvedConnector3: + case sptCurvedConnector4: + case sptCurvedConnector5: + { + pShape = new CCurvedConnectorType(); + break; + } + + case sptTextPlainText: + case sptTextStop: + case sptTextTriangle: + case sptTextTriangleInverted: + case sptTextChevron: + case sptTextChevronInverted: + case sptTextRingInside: + case sptTextRingOutside: + case sptTextArchUpCurve: + case sptTextArchDownCurve: + case sptTextCircleCurve: + case sptTextButtonCurve: + case sptTextArchUpPour: + case sptTextArchDownPour: + case sptTextCirclePour: + case sptTextButtonPour: + case sptTextCurveUp: + case sptTextCurveDown: + case sptTextCascadeUp: + case sptTextCascadeDown: + case sptTextWave1: + case sptTextWave2: + case sptTextWave3: + case sptTextWave4: + case sptTextInflate: + case sptTextDeflate: + case sptTextInflateBottom: + case sptTextDeflateBottom: + case sptTextInflateTop: + case sptTextDeflateTop: + case sptTextDeflateInflate: + case sptTextDeflateInflateDeflate: + case sptTextFadeRight: + case sptTextFadeLeft: + case sptTextFadeUp: + case sptTextFadeDown: + case sptTextSlantUp: + case sptTextSlantDown: + case sptTextCanUp: + case sptTextCanDown: + { + pShape = new CTextboxType(); + } + + default: break; + }; + + if (NULL != pShape) + pShape->m_eType = type; + + return pShape; + } } diff --git a/MsBinaryFile/Common/ODraw/CustomShape.h b/MsBinaryFile/Common/ODraw/CustomShape.h index 3ed8abb8ab..54a777c12f 100644 --- a/MsBinaryFile/Common/ODraw/CustomShape.h +++ b/MsBinaryFile/Common/ODraw/CustomShape.h @@ -52,111 +52,22 @@ public: std::vector m_arStringTextRects; - CCustomShape() : CBaseShape() - { - m_eType = oox::msosptNotPrimitive; - } + CCustomShape(); + ~CCustomShape(); - ~CCustomShape() - { - } + virtual void AddGuide(const std::wstring& strGuide); - virtual void AddGuide(const std::wstring& strGuide) - { - m_oManager.AddFormula(strGuide); - } + virtual bool LoadAdjustHandlesList(const std::wstring& xml); + virtual bool LoadConnectorsList(const std::wstring& xml); + virtual bool LoadTextRect(const std::wstring& xml); + virtual bool LoadPathList(const std::wstring& xml); - virtual bool LoadAdjustHandlesList(const std::wstring& xml) - { - return true; - } - - virtual bool LoadConnectorsList(const std::wstring& xml) - { - return true; - } - - virtual bool LoadTextRect(const std::wstring& xml) - { - std::vector oArray; - NSStringUtils::ParseString(_T(";"), xml, oArray); - - LONG lCount = (LONG)oArray.size(); - - if (lCount <= 0) - return true; - - m_arStringTextRects.clear(); - for (LONG i = 0; i < lCount; ++i) - { - m_arStringTextRects.push_back(oArray[i]); - } - - return true; - } - - virtual bool LoadPathList(const std::wstring& xml) - { - m_strPath = xml; - - m_oPath.FromXML(xml, m_oManager); - return true; - } - - virtual bool SetAdjustment(long index, long value) - { - if (index < (long)m_arAdjustments.size() && index >= 0) - { - m_arAdjustments[index] = value; - return TRUE; - } - return FALSE; - } - - virtual void ReCalculate() - { - m_oManager.Clear(&m_arAdjustments); - - m_oManager.CalculateResults(); - - if (_T("") == m_strPath) - return; - - LoadPathList(m_strPath); - } + virtual bool SetAdjustment(long index, long value); + virtual void ReCalculate(); static CCustomShape* CreateByType(oox::MSOSPT type); - virtual bool SetProperties(CBaseShape* Shape) - { - if(Shape == NULL) - return false; - - m_oManager = ((CCustomShape*)Shape)->m_oManager; - - //m_strPathLimoX = ((CCustomShape*)Shape)->m_strPathLimoX; - //m_strPathLimoY = ((CCustomShape*)Shape)->m_strPathLimoY; - - //m_arStringTextRects.clear(); - //m_arStringTextRects.insert(m_arStringTextRects.end(), ((CCustomShape*)Shape)->m_arStringTextRects.begin(), ((CCustomShape*)Shape)->m_arStringTextRects.end()); - - return CBaseShape::SetProperties(Shape); - } - - bool SetShapeType(oox::MSOSPT type) - { - CCustomShape* l_pShape = CreateByType(type); - if(l_pShape != NULL) - { - m_eType = type; - - SetProperties(l_pShape); - delete l_pShape; - return true; - } - - m_eType = oox::msosptNotPrimitive; - return false; - } + virtual bool SetProperties(CBaseShape* Shape); + bool SetShapeType(oox::MSOSPT type); }; } diff --git a/MsBinaryFile/Common/ODraw/CustomShapeConvert.cpp b/MsBinaryFile/Common/ODraw/CustomShapeConvert.cpp new file mode 100644 index 0000000000..a57ef6fe7b --- /dev/null +++ b/MsBinaryFile/Common/ODraw/CustomShapeConvert.cpp @@ -0,0 +1,1955 @@ +/* + * (c) Copyright Ascensio System SIA 2010-2019 + * + * 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 20A-12 Ernesta Birznieka-Upisha + * street, Riga, Latvia, EU, LV-1050. + * + * 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 "CustomShapeConvert.h" + +namespace NSCustomShapesConvert +{ + CSlicePath::CSlicePath(RulesType eType) + { + m_eRuler = eType; + m_nCountElementsPoint = 0; + } + void CSlicePath::AddParam(LONG lParam, ParamType eParType) + { + long lPoint = m_nCountElementsPoint % 2; + if (0 == lPoint) + { + Aggplus::POINT point; + SPointType pointType; + + point.x = lParam; + point.y = 0; + pointType.x = eParType; + pointType.y = ptValue; + m_arPoints.push_back(point); + m_arPointsType.push_back(pointType); + } + else + { + m_arPoints.back().y = lParam; + m_arPointsType.back().y = eParType; + } + ++m_nCountElementsPoint; + } + + CFormulaConverter::CFormulaConverter() + { + m_lIndexDst = 0; + m_lIndexSrc = -1; + m_lWidth = ShapeSizeVML; + m_lHeight = ShapeSizeVML; + + m_lMaxAdjUse = -1; + } + void CFormulaConverter::ConvertCoef(NSCustomShapesConvert::CFormParam pCoef) + { + if (pCoef.m_eType == ptValue) + ConvertVal(pCoef.m_lParam, pCoef.m_eType, false, m_oCoef); + else if (pCoef.m_eType == ptFormula) + { + ConvertProd(22, ptValue, 1, ptValue, 7, ptValue, false, false, false, m_oCoef); + ConvertProd(m_lIndexDst-1, ptFormula, 1, ptValue, 180, ptValue, true, false, false, m_oCoef); + } + m_oParam.m_lParam = m_lIndexDst-1; + m_oParam.m_eType = ptFormula; + m_oParam.m_lCoef = pCoef.m_lCoef; + } + void CFormulaConverter::ConvertCoef2(NSCustomShapesConvert::CFormParam pCoef) + { + if (pCoef.m_eType == ptValue) + ConvertVal(pCoef.m_lParam, pCoef.m_eType, false, m_oGuidsRes); + else if (pCoef.m_eType == ptFormula) + { + ConvertProd(22, ptValue, 1, ptValue, 7, ptValue, false, false, false, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, 1, ptValue, 180, ptValue, true, false, false, m_oGuidsRes); + } + m_oParam.m_lParam = m_lIndexDst-1; + m_oParam.m_eType = ptFormula; + m_oParam.m_lCoef = pCoef.m_lCoef; + } + void CFormulaConverter::ConvertAdj(const std::vector& arAdj) + { + int nAdjCount = arAdj.size(); + for (int i = 0; i < nAdjCount; ++i) + { + m_oAdjRes.WriteString(_T("")); + } + for (int i = nAdjCount; i <= m_lMaxAdjUse; ++i) + { + m_oAdjRes.WriteString(_T("")); + } + } + void CFormulaConverter::ConvertFormula(const std::vector& arFormulas) + { + int nGuidCount = arFormulas.size(); + for (int i = 0; i < nGuidCount; ++i) + { + const CFormula& pFormula = arFormulas[i]; + m_lIndexSrc++; + + switch (pFormula.m_eFormulaType) + { + case ftVal: + { + ConvertVal(pFormula.m_lParam1, pFormula.m_eType1, false, m_oGuidsRes); + break; + } + case ftSum: + { + ConvertSum(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, pFormula.m_lParam3, pFormula.m_eType3, false, false, false, m_oGuidsRes); + break; + } + case ftProduct: + { + ConvertProd(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, pFormula.m_lParam3, pFormula.m_eType3, false, false, false, m_oGuidsRes); + break; + } + case ftMid: + { + // TODO: +/ ??? + ConvertSum(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, 0, ptValue, false, false, false, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, 1, ptValue, 2, ptValue, true, false, false, m_oGuidsRes); + break; + } + case ftAbsolute: + { + ConvertAbs (pFormula.m_lParam1, pFormula.m_eType1, false, m_oGuidsRes); + break; + } + case ftMin: + { + ConvertMin(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, false, false, m_oGuidsRes); + break; + } + case ftMax: + { + ConvertMax(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, false, false, m_oGuidsRes); + break; + } + case ftIf: + { + ConvertIf(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, pFormula.m_lParam3, pFormula.m_eType3, false, false, false, m_oGuidsRes); + break; + } + case ftMod: + { + ConvertMod(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, pFormula.m_lParam3, pFormula.m_eType3, false, false, false, m_oGuidsRes); + break; + } + case ftAtan2: + { + ConvertAt2(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, false, false, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_oParam.m_lParam, m_oParam.m_eType, pow3_16, ptValue, true, true, false, m_oGuidsRes); + break; + } + case ftSin: + { + ConvertProd(pFormula.m_lParam2, pFormula.m_eType2, pow3_16, ptValue, m_oParam.m_lParam, m_oParam.m_eType, false, false, true, m_oGuidsRes); + ConvertSin(pFormula.m_lParam1, pFormula.m_eType1, m_lIndexDst-1, ptFormula, false, true, m_oGuidsRes); + break; + } + case ftCos: + { + ConvertProd(pFormula.m_lParam2, pFormula.m_eType2, pow3_16, ptValue, m_oParam.m_lParam, m_oParam.m_eType, false, false, true, m_oGuidsRes); + ConvertCos(pFormula.m_lParam1, pFormula.m_eType1, m_lIndexDst-1, ptFormula, false, true, m_oGuidsRes); + break; + } + case ftCosatan2: + { + ConvertCat2(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, pFormula.m_lParam3, pFormula.m_eType3, false, false, false, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_oParam.m_lParam, m_oParam.m_eType, pow3_16, ptValue, true, true, false, m_oGuidsRes); + break; + } + case ftSinatan2: + { + ConvertSat2(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, pFormula.m_lParam3, pFormula.m_eType3, false, false, false, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_oParam.m_lParam, m_oParam.m_eType, pow3_16, ptValue, true, true, false, m_oGuidsRes); + break; + } + case ftSqrt: + { + ConvertSqrt(pFormula.m_lParam1, pFormula.m_eType1, false, m_oGuidsRes); + break; + } + case ftTan: + { + ConvertTag(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, false, false, m_oGuidsRes); + break; + } + case ftSumangle: + { + ConvertProd(pFormula.m_lParam1, pFormula.m_eType1, pow3_16, ptValue, m_oParam.m_lParam, m_oParam.m_eType, false, false, true, m_oGuidsRes); + ConvertProd(pow3_16, ptValue, pFormula.m_lParam2, pFormula.m_eType2, 1, ptValue, false, false, false, m_oGuidsRes); + ConvertProd(pow3_16, ptValue, pFormula.m_lParam3, pFormula.m_eType3, 1, ptValue, false, false, false, m_oGuidsRes); + ConvertSum(m_lIndexDst-3, ptFormula, m_lIndexDst-2, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_oParam.m_lParam, m_oParam.m_eType, pow3_16, ptValue, true, true, false, m_oGuidsRes); + break; + } + case ftEllipse: + { + ConvertProd(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam1, pFormula.m_eType1, 1, ptValue , false, false, false, m_oGuidsRes); + ConvertProd(pFormula.m_lParam2, pFormula.m_eType2, pFormula.m_lParam2, pFormula.m_eType2, 1, ptValue , false, false, false, m_oGuidsRes); + ConvertProd(1, ptValue, m_lIndexDst-2, ptFormula, m_lIndexDst-1, ptFormula, false, true, true, m_oGuidsRes); + ConvertSum(0, ptValue, 1, ptValue, m_lIndexDst-1, ptFormula, false, false, true, m_oGuidsRes); + ConvertSqrt(m_lIndexDst-1, ptFormula, true, m_oGuidsRes); + ConvertProd(pFormula.m_lParam3, pFormula.m_eType3, m_lIndexDst-1, ptFormula, 1, ptValue, false, true, false, m_oGuidsRes); + break; + } + default: + break; + } + + m_arIndexDst.push_back(m_lIndexDst-1); + } + } + void CFormulaConverter::ConvertPath(std::wstring strPath, const CPath& oPath) + { + m_arParts.clear(); + std::vector oArray; + NSStringUtils::ParseString(L"e", strPath, oArray); + + int nSizeArr = oArray.size(); + for (int nIndex = 0; nIndex < nSizeArr; ++nIndex) + { + if (oArray[nIndex].empty()) continue; + + if (nIndex < (int)oPath.m_arParts.size() ) + { + const CPartPath& oPart = oPath.m_arParts[nIndex]; + m_lWidth = oPart.width; + m_lHeight = oPart.height; + } + + bool bFill = false; + bool bStroke = false; + + std::wstring strValue; + FromXML(oArray[nIndex], bFill, bStroke); + LONG nCountSlices = m_arSlicesPath.size(); + + m_oPathRes.StartNode(L"a:path"); + m_oPathRes.StartAttributes(); + m_oPathRes.WriteAttribute(L"w", m_lWidth); + m_oPathRes.WriteAttribute(L"h", m_lHeight); + + m_oPathRes.WriteAttribute(L"fill" , std::wstring(bFill ? L"norm" : L"none")); + m_oPathRes.WriteAttribute(L"stroke" , bStroke ? 1 : 0); + m_oPathRes.WriteAttribute(L"extrusionOk", 0); + + m_oPathRes.EndAttributes(); + + for (int i = 0; i < nCountSlices; ++i) + { + CSlicePath& oSlice = m_arSlicesPath[i]; + + //m_lIndexDst-1 - номер последней записанной формулы + //m_lIndexSrc - номер последнего блока формул + //m_arIndexDst[n] - возвращает номер последней формулы в блоке n + //m_arIndexDst[m_lIndexSrc] = m_lIndexDst + + switch (oSlice.m_eRuler) + { + case rtMoveTo: + { + ConvertSlice_MoveTo(oSlice); + break; + } + case rtRMoveTo: + { + ConvertSlice_RMoveTo(oSlice); + break; + } + case rtClose: + { + m_oPathRes.WriteString(_T("")); + break; + } + case rtLineTo: + { + ConvertSlice_LineTo(oSlice); + break; + } + case rtRLineTo: + { + ConvertSlice_RLineTo(oSlice); + break; + } + case rtArcTo: + case rtArc: + { + ConvertSlice_ArcTo(oSlice); + break; + } + case rtClockwiseArcTo: + case rtClockwiseArc: + { + ConvertSlice_ClockwiseTo(oSlice); + break; + } + case rtQuadrBesier: + { + ConvertSlice_QuadrBesier(oSlice); + break; + } + case rtCurveTo: + { + ConvertSlice_CurveTo(oSlice); + break; + } + case rtRCurveTo: + { + ConvertSlice_RCurveTo(oSlice); + break; + } + case rtAngleEllipse: + case rtAngleEllipseTo: + { + ConvertSlice_AngleEllipse(oSlice); + break; + } + case rtEllipticalQuadrX: + { + ConvertSlice_EllipticalQuadrX(oSlice); + break; + } + case rtEllipticalQuadrY: + { + ConvertSlice_EllipticalQuadrY(oSlice); + break; + } + default: + break; + } + } + + m_oPathRes.WriteString(_T("")); + } + } + void CFormulaConverter::ConvertHandle(const std::vector& arHandles, std::vector& arAdj, oox::MSOSPT oSType) + { + LONG nHandlesCount = arHandles.size(); + if (oSType == 19) // в пптх не реализована функция изменения размера шейпа при изменении handle + nHandlesCount = 0; + for (int i = 0; i < nHandlesCount; ++i) + { + const CHandle_& pHnPoint = arHandles[i]; + std::vector arPos; + + std::wstring sPos0 = _T(""); + std::wstring sPos1 = _T(""); + + SHandle oHandle; + ParamType ptType; + + if (pHnPoint.position != _T("")) + { + NSStringUtils::ParseString(_T(","), pHnPoint.position, arPos); + sPos0 = arPos[0]; + sPos1 = arPos[1]; + + oHandle.gdRef.x = GetHandleValue(sPos0, m_lWidth, ptType); + oHandle.gdRefType.x = ptType; + if (oHandle.gdRefType.x == ptAdjust) + oHandle.bRefExist.x = true; + + oHandle.gdRef.y = GetHandleValue(sPos1, m_lWidth, ptType); + oHandle.gdRefType.y = ptType; + if (oHandle.gdRefType.y == ptAdjust) + oHandle.bRefExist.y = true; + + if (pHnPoint.polar != _T("")) + { + //пришел полярный угол + oHandle.bRefExist.y = false; + + oHandle.bRefPolarExist.y = true; + oHandle.bMinPolarExist.y = true; + + NSStringUtils::ParseString(_T(","), pHnPoint.polar, arPos); + + oHandle.PolarCentre.x = GetHandleValue(arPos[0], m_lWidth, ptType); + oHandle.PolarCentreType.x = ptType; + + oHandle.PolarCentre.y = GetHandleValue(arPos[1], m_lWidth, ptType); + oHandle.PolarCentreType.y = ptType; + + if (oHandle.gdRefType.y == ptAdjust) + { + //угол должен храниться в pptx формате, поэтому придётся его везде заменить + std::wstring strNewFmla = GetValue2(m_lIndexDst, ptFormula, true); + std::wstring strOldFmla = GetValue2(oHandle.gdRef.y, oHandle.gdRefType.y, false); + LONG nIndex = m_lIndexDst; + + // TODO: !!! тут медленный код. + m_oGuidsRes.ReplaceString(strOldFmla, strNewFmla); + + m_lIndexSrc++; + + // TODO: !!! тут медленный код. + CXmlWriter memGuidsRes; + ConvertProd(oHandle.gdRef.y, oHandle.gdRefType.y, m_oParam.m_lCoef, ptValue, pow3_16, ptValue, false, true, false, memGuidsRes); + m_oGuidsRes.m_oWriter.WriteBefore(memGuidsRes.m_oWriter); + m_arIndexDst.push_back(m_lIndexDst-1); + + if (oHandle.gdRefType.y == ptAdjust) + { + double dScale = (double)pow3_16 / m_oParam.m_lCoef; + + LONG nCountAdj = arAdj.size(); + if (oHandle.gdRef.y >= nCountAdj) + { + // дурацкий код. надо память перевыделить, а старую скопировать + // пока сделаю так, чтобы наверняка + int nNewSize = (int)oHandle.gdRef.y + 1; + while ((int)arAdj.size() < nNewSize) + arAdj.push_back(0); + } + + LONG lVal = (LONG)(dScale * arAdj[oHandle.gdRef.y]); + arAdj[oHandle.gdRef.y] = lVal; + } + + //рассчитаем координаты точки handle + + m_lIndexSrc++; + ConvertCos(oHandle.gdRef.x, oHandle.gdRefType.x, oHandle.gdRef.y, oHandle.gdRefType.y, false, false, m_oGuidsRes); + ConvertSin(oHandle.gdRef.x, oHandle.gdRefType.x, oHandle.gdRef.y, oHandle.gdRefType.y, false, false, m_oGuidsRes); + ConvertSum(oHandle.PolarCentre.x, oHandle.PolarCentreType.x, m_lIndexDst-2, ptFormula, 0, ptValue, false, true, false, m_oGuidsRes); + ConvertSum(oHandle.PolarCentre.y, oHandle.PolarCentreType.y, m_lIndexDst-2, ptFormula, 0, ptValue, false, true, false, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + + std::wstring strMem = std::to_wstring(m_lIndexDst - 2); + + oHandle.Pos.x = GetHandlePos(strMem, _T("w"), m_lWidth); + oHandle.PosType.x = ptFormula; + + strMem = std::to_wstring(m_lIndexDst - 2); + oHandle.Pos.y = GetHandlePos(strMem, _T("h"), m_lHeight); + oHandle.PosType.y = ptFormula; + } + + } + else//если пришли обычные координаты + { + if ((pHnPoint.xrange != _T("") && oHandle.gdRefType.x != ptAdjust && oHandle.gdRefType.y == ptAdjust) || + (pHnPoint.yrange != _T("") && oHandle.gdRefType.x == ptAdjust && oHandle.gdRefType.y != ptAdjust)) + { + oHandle.Pos.x = GetHandlePos(sPos1, _T("w"), m_lWidth); + oHandle.PosType.x = ptFormula; + + oHandle.Pos.y = GetHandlePos(sPos0, _T("h"), m_lHeight); + oHandle.PosType.y = ptFormula; + } + else + { + oHandle.Pos.x = GetHandlePos(sPos0, _T("w"), m_lWidth); + oHandle.PosType.x = ptFormula; + + oHandle.Pos.y = GetHandlePos(sPos1, _T("h"), m_lHeight); + oHandle.PosType.y = ptFormula; + } + } + } + + if (pHnPoint.xrange != _T("")) + { + if ( oHandle.gdRefType.x != ptAdjust && oHandle.gdRefType.y == ptAdjust) + { + oHandle.gdRef.x = GetHandleValue(sPos1, m_lWidth, ptType); + oHandle.gdRefType.x = ptType; + oHandle.bRefExist.x = true; + + oHandle.gdRef.y = GetHandleValue(sPos0, m_lHeight, ptType); + oHandle.gdRefType.y = ptType; + oHandle.bRefExist.y = false; + } + + NSStringUtils::ParseString(_T(","), pHnPoint.xrange, arPos); + oHandle.Min.x = GetHandleValue(arPos[0], m_lWidth, ptType); + oHandle.MinType.x = ptType; + if ( oHandle.bRefExist.x) + oHandle.bMinExist.x = true; + + oHandle.Max.x = GetHandleValue(arPos[1], m_lWidth, ptType); + oHandle.MaxType.x = ptType; + if ( oHandle.bRefExist.x) + oHandle.bMaxExist.x = true; + } + + if (pHnPoint.yrange != _T("")) + { + if (oHandle.gdRefType.x == ptAdjust && oHandle.gdRefType.y != ptAdjust) + { + oHandle.gdRef.x = GetHandleValue(sPos1, m_lWidth, ptType); + oHandle.gdRefType.x = ptType; + oHandle.bRefExist.x = false; + + oHandle.gdRef.y = GetHandleValue(sPos0, m_lHeight, ptType); + oHandle.gdRefType.y = ptType; + oHandle.bRefExist.y = true; + } + + NSStringUtils::ParseString(_T(","), pHnPoint.yrange, arPos); + oHandle.Min.y = GetHandleValue(arPos[0], m_lHeight, ptType); + oHandle.MinType.y = ptType; + if ( oHandle.bRefExist.y ) + oHandle.bMinExist.y = true; + + oHandle.Max.y = GetHandleValue(arPos[1], m_lHeight, ptType); + oHandle.MaxType.y = ptType; + if ( oHandle.bRefExist.y ) + oHandle.bMaxExist.y = true; + } + + if (pHnPoint.radiusrange != _T("")) + { + NSStringUtils::ParseString(_T(","), pHnPoint.radiusrange, arPos); + oHandle.Min.x = GetHandleValue(arPos[0], m_lHeight, ptType); + oHandle.MinType.x = ptType; + oHandle.bMinPolarExist.x = true; + + oHandle.Max.x = GetHandleValue(arPos[1], m_lHeight, ptType); + oHandle.MaxType.x = ptType; + oHandle.bMinPolarExist.y = true; + + if (oHandle.gdRefType.x == ptAdjust) + { + oHandle.bRefPolarExist.x = true; + oHandle.bRefExist.x = false; + } + } + + CreateHandle(oHandle); + + } + ConvertAdj(arAdj); + } + void CFormulaConverter::ConvertTextRect ( std::wstring strRect) + { + if (strRect.empty()) return; + + std::vector arBorder; + NSStringUtils::ParseString(_T(","), strRect, arBorder); + + m_lIndexSrc++; + ConvertProd(_T("w"), arBorder[0], m_lWidth, m_oGuidsRes); + ConvertProd(_T("h"), arBorder[1], m_lHeight, m_oGuidsRes); + ConvertProd(_T("w"), arBorder[2], m_lWidth, m_oGuidsRes); + ConvertProd(_T("h"), arBorder[3], m_lHeight, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst); + + m_oTextRect.WriteString(_T("")); + } + void CFormulaConverter::GetValue(const LONG& lParam, const ParamType& eParamType, const bool& bExtShape, CXmlWriter& oWriter) + { + oWriter.m_oWriter.AddSize(15); + switch (eParamType) + { + case ptFormula: + { + oWriter.m_oWriter.AddCharNoCheck((WCHAR)'g'); + oWriter.m_oWriter.AddCharNoCheck((WCHAR)'d'); + + if (bExtShape) + oWriter.m_oWriter.AddIntNoCheck(lParam); + else + oWriter.m_oWriter.AddIntNoCheck(m_arIndexDst[lParam]); + break; + } + case ptAdjust: + { + oWriter.m_oWriter.AddCharNoCheck((WCHAR)'a'); + oWriter.m_oWriter.AddCharNoCheck((WCHAR)'d'); + oWriter.m_oWriter.AddCharNoCheck((WCHAR)'j'); + oWriter.m_oWriter.AddIntNoCheck(lParam); + + if (lParam > m_lMaxAdjUse) + m_lMaxAdjUse = lParam; + + break; + } + case ptValue: + { + oWriter.m_oWriter.AddIntNoCheck(lParam); + break; + } + default: + break; + } + } + std::wstring CFormulaConverter::GetValue2(const LONG& lParam, const ParamType& eParamType, const bool& bExtShape) + { + std::wstring strValue; + switch (eParamType) + { + case ptFormula: + { + if (bExtShape) + strValue = std::to_wstring(lParam); + else + strValue = std::to_wstring(m_arIndexDst[lParam]); + strValue = _T("gd") + strValue; + break; + } + case ptAdjust: + { + strValue = _T("adj") + std::to_wstring(lParam); + break; + } + case ptValue: + { + strValue = std::to_wstring(lParam); + break; + } + default: + break; + } + return strValue; + } + + void CFormulaConverter::ConvertVal(const LONG& lParam1, const ParamType& eType1, const bool& bExtShape1, CXmlWriter& oWriter) + { + GUIDE_PARAM_1(val) + } + + void CFormulaConverter::ConvertSum(const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, + const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, CXmlWriter& oWriter) + { + GUIDE_PARAM_3(sum) + } + + void CFormulaConverter::ConvertProd(const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, + const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, CXmlWriter& oWriter) + { + GUIDE_PARAM_3(prod) + } + + void CFormulaConverter::ConvertAbs(const LONG& lParam1, const ParamType& eType1, const bool& bExtShape1, CXmlWriter& oWriter) + { + GUIDE_PARAM_1(abs) + } + + void CFormulaConverter::ConvertMin(const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, + const bool& bExtShape1, const bool& bExtShape2, CXmlWriter& oWriter) + { + GUIDE_PARAM_2(min) + } + + void CFormulaConverter::ConvertMax (const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, + const bool& bExtShape1, const bool& bExtShape2, CXmlWriter& oWriter) + { + GUIDE_PARAM_2(max) + } + + void CFormulaConverter::ConvertIf(const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, + const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, CXmlWriter& oWriter) + { + GUIDE_PARAM_3(_if) + } + + void CFormulaConverter::ConvertSqrt(const LONG& lParam1, const ParamType& eType1, const bool& bExtShape1, CXmlWriter& oWriter) + { + GUIDE_PARAM_1(sqrt) + } + + void CFormulaConverter::ConvertAt2 (const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, + const bool& bExtShape1, const bool& bExtShape2, CXmlWriter& oWriter) + { + GUIDE_PARAM_2(at2) + } + + void CFormulaConverter::ConvertSin (const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, + const bool& bExtShape1, const bool& bExtShape2, CXmlWriter& oWriter) + { + GUIDE_PARAM_2(sin) + } + + void CFormulaConverter::ConvertCos (const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, + const bool& bExtShape1, const bool& bExtShape2, CXmlWriter& oWriter) + { + GUIDE_PARAM_2(cos) + } + + void CFormulaConverter::ConvertCat2(const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, + const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, CXmlWriter& oWriter) + { + GUIDE_PARAM_3(cat2) + } + + void CFormulaConverter::ConvertSat2(const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, + const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, CXmlWriter& oWriter) + { + GUIDE_PARAM_3(sat2) + } + + void CFormulaConverter::ConvertMod(const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, + const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, CXmlWriter& oWriter) + { + GUIDE_PARAM_3(mod) + } + + void CFormulaConverter::ConvertTag (const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, + const bool& bExtShape1, const bool& bExtShape2, CXmlWriter& oWriter) + { + GUIDE_PARAM_2(tag) + } + + void CFormulaConverter::ConvertProd(const std::wstring& strParam1, const std::wstring& strParam2, const LONG& lParam3, CXmlWriter& oWriter) + { + oWriter.m_oWriter.AddSize(g_guide_max_len); + oWriter.m_oWriter.WriteStringNoSafe(g_guide_string1, g_guide_string1_len); + oWriter.m_oWriter.AddIntNoCheck(m_lIndexDst); + oWriter.m_oWriter.WriteStringNoSafe(g_guide_string_prod, g_guide_string_prod_len); + oWriter.WriteString(strParam1); + oWriter.m_oWriter.AddSpaceNoCheck(); + + if ('#' == strParam2[0]) + { + LONG lRes = (LONG)XmlUtils::GetInteger(strParam2.substr(1)); + GetValue(lRes, ptAdjust, false, oWriter); + } + else if ('@' == strParam2[0]) + { + LONG lRes = (LONG)XmlUtils::GetInteger(strParam2.substr(1)); + GetValue(lRes, ptFormula, false, oWriter); + } + else + oWriter.WriteString(strParam2); + + oWriter.m_oWriter.AddSpaceNoCheck(); + GetValue(lParam3, ptValue, false, oWriter); + + ++m_lIndexDst; + oWriter.m_oWriter.WriteStringNoSafe(g_guide_string2, g_guide_string2_len); + } + + void CFormulaConverter::FromXML(std::wstring strPath, bool &m_bFill, bool &m_bStroke) + { + m_arSlicesPath.clear(); + NSStringUtils::CheckPathOn_Fill_Stroke(strPath, m_bFill, m_bStroke); + std::vector oArray; + + NSStringUtils::ParsePath2(strPath, &oArray); + + ParamType eParamType = ptValue; + RulesType eRuler = rtEnd; + LONG lValue; + bool bRes = true; + + for (size_t nIndex = 0; nIndex < oArray.size(); ++nIndex) + { + std::wstring str = oArray[nIndex]; + lValue = NSCustomShapesConvert::GetValue(oArray[nIndex], eParamType, bRes); + if (bRes) + { + if (0 != m_arSlicesPath.size()) + { + m_arSlicesPath[m_arSlicesPath.size() - 1].AddParam(lValue, eParamType); + } + } + else + { + eRuler = GetRuler(oArray[nIndex], bRes); + if (bRes) + { + if (rtNoFill == eRuler) + { + m_bFill = false; + } + else if (rtNoStroke == eRuler) + { + m_bStroke = false; + } + else + { + CSlicePath oSlice(eRuler); + m_arSlicesPath.push_back(oSlice); + } + } + } + } + } + void CFormulaConverter::CreateHandle ( SHandle oHnd ) + { + std::wstring strRes = _T(""); + if (oHnd.bRefPolarExist.x || oHnd.bRefPolarExist.y) + m_oHandleRes.WriteString(_T("")); + else if (oHnd.bRefExist.x || oHnd.bRefExist.y) + m_oHandleRes.WriteString(_T("\"/>")); + } + LONG CFormulaConverter::GetHandlePos(const std::wstring& strParam, const std::wstring& strBase, LONG lSize) + { + LONG lRes; + std::wstring strSize; + std::wstring strIndex; + + strSize = std::to_wstring( lSize); + + if ('#' == strParam[0]) + { + lRes = (LONG)XmlUtils::GetInteger(strParam.substr(1)); + strFrmla = GetValue2(lRes, ptAdjust, false) + L" " + strSize; + } + else if ('&' == strParam[0]) + { + lRes = (LONG)XmlUtils::GetInteger(strParam.substr(1)); + strFrmla = GetValue2(lRes, ptFormula, true) + L" " + strSize; + } + else if ('@' == strParam[0]) + { + lRes = (LONG)XmlUtils::GetInteger(strParam.substr(1)); + strFrmla = GetValue2(lRes, ptFormula, false) + L" " + strSize; + } + else if (!NSStringUtils::IsNumber(strParam)) + { + if (_T("center") == strParam) + strFrmla = _T("1 2"); + else if (_T("topLeft") == strParam) + strFrmla = _T("0 1"); + else if ( _T("bottomRight") == strParam) + strFrmla = _T("1 1"); + } + else + { + lRes = (LONG)XmlUtils::GetInteger(strParam.c_str()); + strFrmla = GetValue2(lRes, ptValue, false) + strSize; + } + + m_lIndexSrc++; + m_arIndexDst.push_back(m_lIndexDst); + strIndex = std::to_wstring(m_lIndexDst); + + m_oGuidsRes.WriteString(_T("")); + + m_lIndexDst++; + + return m_lIndexDst-1; + } + LONG CFormulaConverter::GetHandleValue(const std::wstring& strParam, const LONG& lVal, ParamType& ptType) + { + ptType = ptValue; + if ('#' == strParam[0]) + { + ptType = ptAdjust; + return (LONG)XmlUtils::GetInteger(strParam.substr(1).c_str()); + } + else if ('@' == strParam[0]) + { + ptType = ptFormula; + return (LONG)XmlUtils::GetInteger(strParam.substr(1).c_str()); + } + else if (!NSStringUtils::IsNumber(strParam)) + { + if (_T("center") == strParam) + return lVal/2; + else if (_T("bottomRight") == strParam)//Demo-Hayden-Management-v2.docx + return lVal; + else + return 0; //??? + //todooo прописать все варианты правильно + } + else + { + ptType = ptValue; + return (LONG)XmlUtils::GetInteger(strParam.c_str()); + } + } + void CFormulaConverter::ConvertQuadrX(Aggplus::POINT pPoint, SPointType pPointType) + { + LONG nIndex = m_arIndexDst[m_lIndexSrc]; + + m_lIndexSrc++; + + ConvertSum(pPoint.x, pPointType.x, 0, ptValue, nIndex-1, ptFormula, false, true, true, m_oGuidsRes); + ConvertSum(pPoint.y, pPointType.y, 0, ptValue, nIndex, ptFormula, false, true, true, m_oGuidsRes); + ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-2, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(m_lIndexDst-4, ptFormula, 16200000, ptValue, 5400000, ptValue, true, true, true, m_oGuidsRes); //stAng + ConvertIf(m_lIndexDst-2, ptFormula, 5400000, ptValue, -5400000, ptValue, true, true, true, m_oGuidsRes); //swAng + ConvertProd(m_lIndexDst-7, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-7, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(m_lIndexDst-9, ptFormula, m_lIndexDst-9, ptFormula, m_lIndexDst-2, ptFormula, true, true, true, m_oGuidsRes);//wR + ConvertIf(m_lIndexDst-9, ptFormula, m_lIndexDst-9, ptFormula, m_lIndexDst-2, ptFormula, true, true, true, m_oGuidsRes);//hR + + m_arIndexDst.push_back(m_lIndexDst-1); + + nIndex = m_arIndexDst[m_lIndexSrc]; + + m_oPathRes.WriteString(_T("")); + + m_lIndexSrc++; + ConvertVal(pPoint.x, pPointType.x, false, m_oGuidsRes); + ConvertVal(pPoint.y, pPointType.y, false, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + return; + } + void CFormulaConverter::ConvertQuadrY(Aggplus::POINT pPoint, SPointType pPointType) + { + LONG nIndex = m_arIndexDst[m_lIndexSrc]; + + m_lIndexSrc++; + + ConvertSum(pPoint.x, pPointType.x, 0, ptValue, nIndex-1, ptFormula, false, true, true, m_oGuidsRes); + ConvertSum(pPoint.y, pPointType.y, 0, ptValue, nIndex, ptFormula, false, true, true, m_oGuidsRes); + ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-2, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(m_lIndexDst-5, ptFormula, 10800000, ptValue, 0, ptValue, true, true, true, m_oGuidsRes); //stAng + ConvertIf(m_lIndexDst-2, ptFormula, -5400000, ptValue, 5400000, ptValue, true, true, true, m_oGuidsRes); //swAng + ConvertProd(m_lIndexDst-7, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-7, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(m_lIndexDst-9, ptFormula, m_lIndexDst-9, ptFormula, m_lIndexDst-2, ptFormula, true, true, true, m_oGuidsRes);//wR + ConvertIf(m_lIndexDst-9, ptFormula, m_lIndexDst-9, ptFormula, m_lIndexDst-2, ptFormula, true, true, true, m_oGuidsRes);//hR + m_arIndexDst.push_back(m_lIndexDst-1); + + nIndex = m_arIndexDst[m_lIndexSrc]; + + m_oPathRes.WriteString(_T("")); + + m_lIndexSrc++; + ConvertVal(pPoint.x, pPointType.x, false, m_oGuidsRes); + ConvertVal(pPoint.y, pPointType.y, false, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + return; + } + void CFormulaConverter::ConvertSlice_MoveTo(const CSlicePath& oSlice) + { + int nCountPoints = oSlice.m_arPoints.size(); + for (int j = 0; j < nCountPoints; ++j) + { + pCurPoint = oSlice.m_arPoints[j]; + pCurPointType = oSlice.m_arPointsType[j]; + + m_lIndexSrc++; + ConvertVal(pCurPoint.x, pCurPointType.x, false, m_oGuidsRes); + ConvertVal(pCurPoint.y, pCurPointType.y, false, m_oGuidsRes); + + m_arIndexDst.push_back(m_lIndexDst-1); + + m_oPathRes.WriteString(_T("")); + } + } + void CFormulaConverter::ConvertSlice_RMoveTo(const CSlicePath& oSlice) + { + int nCountPoints = oSlice.m_arPoints.size(); + for (int j = 0; j < nCountPoints; j++) + { + pCurPoint = oSlice.m_arPoints[j]; + pCurPointType = oSlice.m_arPointsType[j]; + + m_lIndexSrc ++; + ConvertSum(m_lIndexDst-2, ptFormula, pCurPoint.x, pCurPointType.x, 0, ptValue, true, false, true, m_oGuidsRes); + ConvertSum(m_lIndexDst-2, ptFormula, pCurPoint.y, pCurPointType.y, 0, ptValue, true, false, true, m_oGuidsRes); + + m_arIndexDst.push_back(m_lIndexDst-1); + + m_oPathRes.WriteString(_T("")); + } + } + void CFormulaConverter::ConvertSlice_LineTo(const CSlicePath& oSlice) + { + int nCountPoints = oSlice.m_arPoints.size(); + for (int j = 0; j < nCountPoints; j++) + { + pCurPoint = oSlice.m_arPoints[j]; + pCurPointType = oSlice.m_arPointsType[j]; + + m_lIndexSrc++; + ConvertVal(pCurPoint.x, pCurPointType.x, false, m_oGuidsRes); + ConvertVal(pCurPoint.y, pCurPointType.y, false, m_oGuidsRes); + + m_arIndexDst.push_back(m_lIndexDst-1); + + m_oPathRes.WriteString(_T("")); + } + } + void CFormulaConverter::ConvertSlice_RLineTo(const CSlicePath& oSlice) + { + int nCountPoints = oSlice.m_arPoints.size(); + for (int j = 0; j < nCountPoints; j++) + { + pCurPoint = oSlice.m_arPoints[j]; + pCurPointType = oSlice.m_arPointsType[j]; + + m_lIndexSrc++; + ConvertSum(m_lIndexDst-2, ptFormula, pCurPoint.x, pCurPointType.x, 0, ptValue, true, false, true, m_oGuidsRes); + ConvertSum(m_lIndexDst-2, ptFormula, pCurPoint.y, pCurPointType.y, 0, ptValue, true, false, true, m_oGuidsRes); + + m_arIndexDst.push_back(m_lIndexDst-1); + + m_oPathRes.WriteString(_T("")); + } + } + void CFormulaConverter::ConvertSlice_ArcTo(const CSlicePath& oSlice) + { + int nCountPoints = oSlice.m_arPoints.size(); + LONG nIndex = 0; + LONG nIndex1 = 0; + LONG nIndex2 = 0; + for (int j = 0; j < nCountPoints; j+=4) + { + pCurPoint = oSlice.m_arPoints[j]; + pCurPointType = oSlice.m_arPointsType[j]; + pCurPoint1 = oSlice.m_arPoints[j+1]; + pCurPointType1 = oSlice.m_arPointsType[j+1]; + + //длина сторон + m_lIndexSrc++; + ConvertSum(pCurPoint1.x, pCurPointType1.x, 0, ptValue, pCurPoint.x, pCurPointType.x, false, true, false, m_oGuidsRes); + ConvertSum(pCurPoint1.y, pCurPointType1.y, 0, ptValue, pCurPoint.y, pCurPointType.y, false, true, false, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //координаты центра + nIndex = m_arIndexDst[m_lIndexSrc]; + + m_lIndexSrc++; + ConvertProd(nIndex-1, ptFormula, 1, ptValue, 2, ptValue, true, true, true, m_oGuidsRes); //a=wR + ConvertProd(nIndex, ptFormula, 1, ptValue, 2, ptValue, true, true, true, m_oGuidsRes); //b=hR + + ConvertSum(pCurPoint.x, pCurPointType.x, m_lIndexDst-2, ptFormula, 0, ptValue, false, true, true, m_oGuidsRes); + ConvertSum(pCurPoint.y, pCurPointType.y, m_lIndexDst-2, ptFormula, 0, ptValue, false, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //рассчет для stAng--------------------------- + //расположение текущей точки по четвертям 3 4 + // 2 1 + + pCurPoint = oSlice.m_arPoints[j+2]; + pCurPointType = oSlice.m_arPointsType[j+2]; + nIndex = m_arIndexDst[m_lIndexSrc]; + + m_lIndexSrc++; + ConvertSum(pCurPoint.x, pCurPointType.x, 0, ptValue, nIndex-1, ptFormula, false, true, true, m_oGuidsRes); + ConvertSum(pCurPoint.y, pCurPointType.y, 0, ptValue, nIndex, ptFormula, false, true, true, m_oGuidsRes); + ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //угол между Ох и радиус-вектором к точке + nIndex = m_arIndexDst[m_lIndexSrc]; + + m_lIndexSrc++; + ConvertProd(nIndex-2, ptFormula, 1, ptValue, nIndex-3, ptFormula, true, true, true, m_oGuidsRes); + ConvertAt2(1, ptValue, m_lIndexDst-1, ptFormula, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //радиус к точке + nIndex = m_arIndexDst[m_lIndexSrc]; + nIndex1 = m_arIndexDst[m_lIndexSrc-2]; + + m_lIndexSrc++; + ConvertCos(1, ptValue, nIndex, ptFormula, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(nIndex1-2, ptFormula, nIndex1-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//(b*cos(u))^2 + + ConvertSin(1, ptValue, nIndex, ptFormula, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(nIndex1-3, ptFormula, nIndex1-3, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//(a*sin(u))^2 + + ConvertSum(m_lIndexDst-1, ptFormula, m_lIndexDst-5, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); + ConvertSqrt(m_lIndexDst-1, ptFormula, true, m_oGuidsRes); + ConvertProd(nIndex1-3, ptFormula, nIndex1-2, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//r + m_arIndexDst.push_back(m_lIndexDst-1); + //если точка во 2 и 3 четвертях, прибавляем по 180grad + nIndex = m_arIndexDst[m_lIndexSrc-2]; + + m_lIndexSrc++; + ConvertIf(nIndex-3, ptFormula, 0, ptValue, 10800000, ptValue, true, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //угол до 1 точки (stAngle) + nIndex = m_arIndexDst[m_lIndexSrc-2];//угол между ох и радиусом + nIndex1 = m_arIndexDst[m_lIndexSrc-3];//расположение точки по четвертям + nIndex2 = m_arIndexDst[m_lIndexSrc];//прибавка 180 или 0 + + m_lIndexSrc ++; + ConvertProd(nIndex1-1, ptFormula, nIndex1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//знак у угла + ConvertProd(nIndex, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(nIndex, ptFormula, nIndex, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//угол всегда положительный + + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-3, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//u с нужным знаком + + ConvertSum(m_lIndexDst-1, ptFormula, nIndex2, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //координаты стартовой точки + nIndex = m_arIndexDst[m_lIndexSrc-2]; + nIndex1 = m_arIndexDst[m_lIndexSrc-4]; + nIndex2 = m_arIndexDst[m_lIndexSrc-5]; + + m_lIndexSrc++; + ConvertProd(nIndex, ptFormula, nIndex-10, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//r*cos(a) + ConvertProd(nIndex1-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertSum(nIndex2-1, ptFormula, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); //x + + ConvertProd(nIndex-6, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(nIndex-6, ptFormula, nIndex-6, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//sin теперь всегда>0 + + ConvertProd(nIndex, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//r*sin + ConvertProd(nIndex1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertSum(nIndex2, ptFormula, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes);//y + m_arIndexDst.push_back(m_lIndexDst-1); + //рассчет для swAng--------------------------- + //расположение текущей точки по четвертям 3 4 + // 2 1 + + pCurPoint = oSlice.m_arPoints[j+3]; + pCurPointType = oSlice.m_arPointsType[j+3]; + + nIndex = m_arIndexDst[m_lIndexSrc-6]; + + m_lIndexSrc++; + ConvertSum(pCurPoint.x, pCurPointType.x, 0, ptValue, nIndex-1, ptFormula, false, true, true, m_oGuidsRes); + ConvertSum(pCurPoint.y, pCurPointType.y, 0, ptValue, nIndex, ptFormula, false, true, true, m_oGuidsRes); + ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //угол между Ох и радиус-вектором к точке + nIndex = m_arIndexDst[m_lIndexSrc]; + + m_lIndexSrc++; + ConvertProd(nIndex-2, ptFormula, 1, ptValue, nIndex-3, ptFormula, true, true, true, m_oGuidsRes); + ConvertAt2(1, ptValue, m_lIndexDst-1, ptFormula, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //радиус к точке + nIndex = m_arIndexDst[m_lIndexSrc]; + nIndex1 = m_arIndexDst[m_lIndexSrc-8]; + + m_lIndexSrc++; + ConvertCos(1, ptValue, nIndex, ptFormula, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(nIndex1-2, ptFormula, nIndex1-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + + ConvertSin(1, ptValue, nIndex, ptFormula, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(nIndex1-3, ptFormula, nIndex1-3, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + + ConvertSum(m_lIndexDst-1, ptFormula, m_lIndexDst-5, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); + ConvertSqrt(m_lIndexDst-1, ptFormula, true, m_oGuidsRes); + ConvertProd(nIndex1-3, ptFormula, nIndex1-2, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //если точка во 2 и 3 четвертях, прибавляем по 180grad + nIndex = m_arIndexDst[m_lIndexSrc-2]; + + m_lIndexSrc++; + ConvertIf(nIndex-3, ptFormula, 0, ptValue, 10800000, ptValue, true, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //угол до 2 точки + nIndex = m_arIndexDst[m_lIndexSrc-2];//угол между ох и радиусом + nIndex1 = m_arIndexDst[m_lIndexSrc-3];//расположение точки по четвертям + nIndex2 = m_arIndexDst[m_lIndexSrc];//прибавка 180 или 0 + + m_lIndexSrc++; + ConvertProd(nIndex1-1, ptFormula, nIndex1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//знак у угла + ConvertProd(nIndex, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(nIndex, ptFormula, nIndex, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//угол всегда положительный + + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-3, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//u с нужным знаком + + ConvertSum(m_lIndexDst-1, ptFormula, nIndex2, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //координаты конечной точки + nIndex = m_arIndexDst[m_lIndexSrc-2]; + nIndex1 = m_arIndexDst[m_lIndexSrc-4]; + nIndex2 = m_arIndexDst[m_lIndexSrc-11]; + + m_lIndexSrc++; + ConvertProd(nIndex, ptFormula, nIndex-10, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//r*cos(a) + ConvertProd(nIndex1-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertSum(nIndex2-1, ptFormula, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes);//x + + ConvertProd(nIndex-6, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(nIndex-6, ptFormula, nIndex-6, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//sin теперь всегда>0 + + ConvertProd(nIndex, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//r*sin(a) + ConvertProd(nIndex1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertSum(nIndex2, ptFormula, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes);//y + m_arIndexDst.push_back(m_lIndexDst-1); + //swAngle + nIndex = m_arIndexDst[m_lIndexSrc-1]; //2 угол + nIndex1 = m_arIndexDst[m_lIndexSrc-7]; //1 угол + + m_lIndexSrc++; + ConvertSum(nIndex1, ptFormula, 0, ptValue, nIndex, ptFormula, true, true, true, m_oGuidsRes); // (1)-(2), если отрицательный то берем его, иначе пересчитываем + ConvertProd(m_lIndexDst-1, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); + + ConvertSum(nIndex1, ptFormula, 21600000, ptValue, nIndex, ptFormula, true, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); // -1*((1)+360-(2)) + + ConvertIf(m_lIndexDst-4, ptFormula, m_lIndexDst-3, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes); + + m_arIndexDst.push_back(m_lIndexDst-1); + //wR,hR + nIndex = m_arIndexDst[m_lIndexSrc-14]; + m_lIndexSrc++; + ConvertProd(nIndex-1, ptFormula, 1, ptValue, 2, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(nIndex, ptFormula, 1, ptValue, 2, ptValue, true, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + + //--------------------------------------------------------- + nIndex = m_arIndexDst[m_lIndexSrc-8];//координаты стартовой точки + nIndex1 = m_arIndexDst[m_lIndexSrc-9];//stAng + nIndex2 = m_arIndexDst[m_lIndexSrc-1];//swAng + + if (oSlice.m_eRuler == rtArc && j == 0) + strFrmla = _T("moveTo"); + else + strFrmla = _T("lnTo"); + + if (oSlice.m_eRuler == rtArc && j == 0) + { + m_oPathRes.WriteString(_T("")); + } + else + { + m_oPathRes.WriteString(_T("")); + } + + //старт + /* + LONG nIndex3 = m_arIndexDst[m_lIndexSrc-14]; + strPathRes += _T(""); + */ + + //текущая точка + nIndex = m_arIndexDst[m_lIndexSrc-2]; + ConvertVal(nIndex-5, ptFormula, true, m_oGuidsRes); + ConvertVal(nIndex, ptFormula, true, m_oGuidsRes); + } + } + void CFormulaConverter::ConvertSlice_ClockwiseTo(const CSlicePath& oSlice) + { + int nCountPoints = oSlice.m_arPoints.size(); + LONG nIndex = 0; + LONG nIndex1 = 0; + LONG nIndex2 = 0; + for (int j = 0; j < nCountPoints; j += 4) + { + pCurPoint = oSlice.m_arPoints[j]; + pCurPointType = oSlice.m_arPointsType[j]; + pCurPoint1 = oSlice.m_arPoints[j+1]; + pCurPointType1 = oSlice.m_arPointsType[j+1]; + + //длина сторон + m_lIndexSrc++; + ConvertSum(pCurPoint1.x, pCurPointType1.x, 0, ptValue, pCurPoint.x, pCurPointType.x, false, true, false, m_oGuidsRes); + ConvertSum(pCurPoint1.y, pCurPointType1.y, 0, ptValue, pCurPoint.y, pCurPointType.y, false, true, false, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //координаты центра + nIndex = m_arIndexDst[m_lIndexSrc]; + + m_lIndexSrc++; + ConvertProd(nIndex-1, ptFormula, 1, ptValue, 2, ptValue, true, true, true, m_oGuidsRes); //a=wR + ConvertProd(nIndex, ptFormula, 1, ptValue, 2, ptValue, true, true, true, m_oGuidsRes); //b=hR + + ConvertSum(pCurPoint.x, pCurPointType.x, m_lIndexDst-2, ptFormula, 0, ptValue, false, true, true, m_oGuidsRes); + ConvertSum(pCurPoint.y, pCurPointType.y, m_lIndexDst-2, ptFormula, 0, ptValue, false, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //рассчет для stAng--------------------------- + //расположение текущей точки по четвертям 3 4 + // 2 1 + + pCurPoint = oSlice.m_arPoints[j+2]; + pCurPointType = oSlice.m_arPointsType[j+2]; + nIndex = m_arIndexDst[m_lIndexSrc]; + + m_lIndexSrc++; + ConvertSum(pCurPoint.x, pCurPointType.x, 0, ptValue, nIndex-1, ptFormula, false, true, true, m_oGuidsRes); + ConvertSum(pCurPoint.y, pCurPointType.y, 0, ptValue, nIndex, ptFormula, false, true, true, m_oGuidsRes); + ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //угол между Ох и радиус-вектором к точке + nIndex = m_arIndexDst[m_lIndexSrc]; + + m_lIndexSrc++; + ConvertProd(nIndex-2, ptFormula, 1, ptValue, nIndex-3, ptFormula, true, true, true, m_oGuidsRes); + ConvertAt2(1, ptValue, m_lIndexDst-1, ptFormula, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //радиус к точке + nIndex = m_arIndexDst[m_lIndexSrc]; + nIndex1 = m_arIndexDst[m_lIndexSrc-2]; + + m_lIndexSrc++; + ConvertCos(1, ptValue, nIndex, ptFormula, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(nIndex1-2, ptFormula, nIndex1-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//(b*cos(u))^2 + + ConvertSin(1, ptValue, nIndex, ptFormula, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(nIndex1-3, ptFormula, nIndex1-3, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//(a*sin(u))^2 + + ConvertSum(m_lIndexDst-1, ptFormula, m_lIndexDst-5, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); + ConvertSqrt(m_lIndexDst-1, ptFormula, true, m_oGuidsRes); + ConvertProd(nIndex1-3, ptFormula, nIndex1-2, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//r + m_arIndexDst.push_back(m_lIndexDst-1); + //если точка во 2 и 3 четвертях, прибавляем по 180grad + nIndex = m_arIndexDst[m_lIndexSrc-2]; + + m_lIndexSrc++; + ConvertIf(nIndex-3, ptFormula, 0, ptValue, 10800000, ptValue, true, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //угол до 1 точки (stAngle) + nIndex = m_arIndexDst[m_lIndexSrc-2];//угол между ох и радиусом + nIndex1 = m_arIndexDst[m_lIndexSrc-3];//расположение точки по четвертям + nIndex2 = m_arIndexDst[m_lIndexSrc];//прибавка 180 или 0 + + m_lIndexSrc++; + ConvertProd(nIndex1-1, ptFormula, nIndex1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//знак у угла + ConvertProd(nIndex, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(nIndex, ptFormula, nIndex, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//угол всегда положительный + + ConvertProd ( m_lIndexDst-1, ptFormula, m_lIndexDst-3, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//u с нужным знаком + + ConvertSum ( m_lIndexDst-1, ptFormula, nIndex2, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //координаты стартовой точки + nIndex = m_arIndexDst[m_lIndexSrc-2]; + nIndex1 = m_arIndexDst[m_lIndexSrc-4]; + nIndex2 = m_arIndexDst[m_lIndexSrc-5]; + + m_lIndexSrc++; + ConvertProd(nIndex, ptFormula, nIndex-10, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//r*cos(a) + ConvertProd(nIndex1-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertSum(nIndex2-1, ptFormula, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); //x + + ConvertProd(nIndex-6, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(nIndex-6, ptFormula, nIndex-6, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//sin теперь всегда>0 + + ConvertProd(nIndex, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//r*sin + ConvertProd(nIndex1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertSum(nIndex2, ptFormula, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes);//y + m_arIndexDst.push_back(m_lIndexDst-1); + //рассчет для swAng--------------------------- + //расположение текущей точки по четвертям 3 4 + // 2 1 + + pCurPoint = oSlice.m_arPoints[j+3]; + pCurPointType = oSlice.m_arPointsType[j+3]; + + nIndex = m_arIndexDst[m_lIndexSrc-6]; + + m_lIndexSrc++; + ConvertSum(pCurPoint.x, pCurPointType.x, 0, ptValue, nIndex-1, ptFormula, false, true, true, m_oGuidsRes); + ConvertSum(pCurPoint.y, pCurPointType.y, 0, ptValue, nIndex, ptFormula, false, true, true, m_oGuidsRes); + ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //угол между Ох и радиус-вектором к точке + nIndex = m_arIndexDst[m_lIndexSrc]; + + m_lIndexSrc++; + ConvertProd(nIndex-2, ptFormula, 1, ptValue, nIndex-3, ptFormula, true, true, true, m_oGuidsRes); + ConvertAt2(1, ptValue, m_lIndexDst-1, ptFormula, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //радиус к точке + nIndex = m_arIndexDst[m_lIndexSrc]; + nIndex1 = m_arIndexDst[m_lIndexSrc-8]; + + m_lIndexSrc++; + ConvertCos(1, ptValue, nIndex, ptFormula, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(nIndex1-2, ptFormula, nIndex1-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + + ConvertSin(1, ptValue, nIndex, ptFormula, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(nIndex1-3, ptFormula, nIndex1-3, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + + ConvertSum(m_lIndexDst-1, ptFormula, m_lIndexDst-5, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); + ConvertSqrt(m_lIndexDst-1, ptFormula, true, m_oGuidsRes); + ConvertProd(nIndex1-3, ptFormula, nIndex1-2, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //если точка во 2 и 3 четвертях, прибавляем по 180grad + nIndex = m_arIndexDst[m_lIndexSrc-2]; + + m_lIndexSrc++; + ConvertIf(nIndex-3, ptFormula, 0, ptValue, 10800000, ptValue, true, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //угол до 2 точки + nIndex = m_arIndexDst[m_lIndexSrc-2];//угол между ох и радиусом + nIndex1 = m_arIndexDst[m_lIndexSrc-3];//расположение точки по четвертям + nIndex2 = m_arIndexDst[m_lIndexSrc];//прибавка 180 или 0 + + m_lIndexSrc ++; + ConvertProd(nIndex1-1, ptFormula, nIndex1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//знак у угла + ConvertProd(nIndex, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(nIndex, ptFormula, nIndex, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//угол всегда положительный + + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-3, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//u с нужным знаком + + ConvertSum(m_lIndexDst-1, ptFormula, nIndex2, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //координаты конечной точки + nIndex = m_arIndexDst[m_lIndexSrc-2]; + nIndex1 = m_arIndexDst[m_lIndexSrc-4]; + nIndex2 = m_arIndexDst[m_lIndexSrc-11]; + + m_lIndexSrc++; + ConvertProd(nIndex, ptFormula, nIndex-10, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//r*cos(a) + ConvertProd(nIndex1-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertSum(nIndex2-1, ptFormula, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes);//x + + ConvertProd(nIndex-6, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(nIndex-6, ptFormula, nIndex-6, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//sin теперь всегда>0 + + ConvertProd(nIndex, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//r*sin(a) + ConvertProd(nIndex1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertSum(nIndex2, ptFormula, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes);//y + m_arIndexDst.push_back(m_lIndexDst-1); + //swAngle + nIndex = m_arIndexDst[m_lIndexSrc-1]; + nIndex1 = m_arIndexDst[m_lIndexSrc-7]; + + m_lIndexSrc++; + ConvertSum(nIndex, ptFormula, 0, ptValue, nIndex1, ptFormula, true, true, true, m_oGuidsRes); + ConvertSum(21600000, ptValue, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(m_lIndexDst-2, ptFormula, m_lIndexDst-2, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//swAng + + m_arIndexDst.push_back(m_lIndexDst-1); + //wR,hR + nIndex = m_arIndexDst[m_lIndexSrc-14]; + m_lIndexSrc++; + ConvertProd(nIndex-1, ptFormula, 1, ptValue, 2, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(nIndex, ptFormula, 1, ptValue, 2, ptValue, true, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + + //--------------------------------------------------------- + nIndex = m_arIndexDst[m_lIndexSrc-8];//координаты стартовой точки + nIndex1 = m_arIndexDst[m_lIndexSrc-9];//stAng + nIndex2 = m_arIndexDst[m_lIndexSrc-1];//swAng + + if (oSlice.m_eRuler == rtClockwiseArc && j == 0) + { + m_oPathRes.WriteString(_T("")); + } + else + { + m_oPathRes.WriteString(_T("")); + } + + //текущая точка + nIndex = m_arIndexDst[m_lIndexSrc-2]; + ConvertVal(nIndex-5, ptFormula, true, m_oGuidsRes); + ConvertVal(nIndex, ptFormula, true, m_oGuidsRes); + } + } + void CFormulaConverter::ConvertSlice_QuadrBesier(const CSlicePath& oSlice) + { + int nCountPoints = oSlice.m_arPoints.size(); + for (int j = 0; j < nCountPoints; j += 2) + { + int l = nCountPoints - j - 3; + if (l >= 0) + { + m_oPathRes.WriteString(_T("")); + for (int k = 0; k < 2; ++k) + { + pCurPoint = oSlice.m_arPoints[j+k]; + pCurPointType = oSlice.m_arPointsType[j+k]; + + m_oPathRes.WriteString(_T("")); + } + m_oPathRes.WriteString(_T("")); + } + else + { + for (int k = 0; k < nCountPoints - j; ++k) + { + pCurPoint = oSlice.m_arPoints[j+k]; + pCurPointType = oSlice.m_arPointsType[j+k]; + + m_oPathRes.WriteString(_T("")); + } + } + + m_lIndexSrc++; + ConvertVal(pCurPoint.x, pCurPointType.x, false, m_oGuidsRes); + ConvertVal(pCurPoint.y, pCurPointType.y, false, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + } + } + void CFormulaConverter::ConvertSlice_CurveTo(const CSlicePath& oSlice) + { + int nCountPoints = oSlice.m_arPoints.size(); + LONG nIndex = 0; + for (int j = 0; j < nCountPoints; j += 3) + { + int l = nCountPoints - j - 3; + if ( l>=0 ) + { + m_oPathRes.WriteString(_T("")); + for (int k = 0; k < 3; ++k) + { + pCurPoint = oSlice.m_arPoints[j+k]; + pCurPointType = oSlice.m_arPointsType[j+k]; + + m_oPathRes.WriteString(_T("")); + } + m_oPathRes.WriteString(_T("")); + } + else + { + for (int k=0; k")); + } + } + + m_lIndexSrc++; + ConvertVal(pCurPoint.x, pCurPointType.x, false, m_oGuidsRes); + ConvertVal(pCurPoint.y, pCurPointType.y, false, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + } + } + void CFormulaConverter::ConvertSlice_RCurveTo(const CSlicePath& oSlice) + { + int nCountPoints = oSlice.m_arPoints.size(); + LONG nIndex = 0; + for (int j = 0; j < nCountPoints; j += 3) + { + nIndex = m_arIndexDst[m_lIndexSrc]; + + int l = nCountPoints - j - 3; + if (l >= 0) + { + m_oPathRes.WriteString(_T("")); + for (int k = 0; k < 3; ++k) + { + pCurPoint = oSlice.m_arPoints[j+k]; + pCurPointType = oSlice.m_arPointsType[j+k]; + + m_lIndexSrc++; + ConvertSum(nIndex-1, ptFormula, pCurPoint.x, pCurPointType.x, 0, ptValue, true, false, true, m_oGuidsRes); + ConvertSum(nIndex, ptFormula, pCurPoint.y, pCurPointType.y, 0, ptValue, true, false, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + + m_oPathRes.WriteString(_T("")); + } + m_oPathRes.WriteString(_T("")); + } + else + { + for (int k=0; k")); + } + } + + nIndex = m_arIndexDst[m_lIndexSrc]; + + m_lIndexSrc++; + ConvertVal(nIndex-1, ptFormula, true, m_oGuidsRes); + ConvertVal(nIndex, ptFormula, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + } + } + void CFormulaConverter::ConvertSlice_AngleEllipse(const CSlicePath& oSlice) + { + int nCountPoints = oSlice.m_arPoints.size(); + LONG nIndex = 0; + LONG nIndex1 = 0; + LONG nIndex2 = 0; + for (int j = 0; j < nCountPoints; j += 3) + { + pCurPoint = oSlice.m_arPoints[j+1]; + pCurPointType = oSlice.m_arPointsType[j+1]; + pCurPoint1 = oSlice.m_arPoints[j+2]; + pCurPointType1 = oSlice.m_arPointsType[j+2]; + + //конвертация углов в pptx формат + m_lIndexSrc++; + ConvertProd(pCurPoint1.x, pCurPointType1.x, pow3_16, ptValue, m_oParam.m_lParam, m_oParam.m_eType, false, true, true, m_oGuidsRes); //1 угол + ConvertProd(pCurPoint1.y, pCurPointType1.y, pow3_16, ptValue, m_oParam.m_lParam, m_oParam.m_eType, false, true, true, m_oGuidsRes); //2 угол + m_arIndexDst.push_back(m_lIndexDst-1); + + //wR и hR + nIndex = m_arIndexDst[m_lIndexSrc]; + + m_lIndexSrc++; + ConvertVal(pCurPoint.x, pCurPointType.x, false, m_oGuidsRes);//wr=a + ConvertVal(pCurPoint.y, pCurPointType.y, false, m_oGuidsRes);//hr=b + + m_arIndexDst.push_back(m_lIndexDst-1); + + //stAng и swAng + nIndex = m_arIndexDst[m_lIndexSrc-1]; + + m_lIndexSrc++; + ConvertProd(nIndex-1, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); //stAng + ConvertSum(nIndex-1, ptFormula, nIndex, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(nIndex, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes);//swAng + m_arIndexDst.push_back(m_lIndexDst-1); + + //радиус до стартовой точки + + nIndex = m_arIndexDst[m_lIndexSrc]; //stang + nIndex1 = m_arIndexDst[m_lIndexSrc-1]; //wr hr + + m_lIndexSrc++; + ConvertCos(1, ptValue, nIndex-2, ptFormula, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(nIndex1, ptFormula, nIndex1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//(b*cos(u))^2 + + ConvertSin(1, ptValue, nIndex-2, ptFormula, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(nIndex1-1, ptFormula, nIndex1-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//(a*sin(u))^2 + + ConvertSum(m_lIndexDst-1, ptFormula, m_lIndexDst-5, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); + ConvertSqrt(m_lIndexDst-1, ptFormula, true, m_oGuidsRes); + ConvertProd(nIndex1, ptFormula, nIndex1-1, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//r + m_arIndexDst.push_back(m_lIndexDst-1); + + //координаты конечной точки (она же начальная для эллипса) + + pCurPoint1 = oSlice.m_arPoints[j];//коорд центра + pCurPointType1 = oSlice.m_arPointsType[j]; + + nIndex = m_arIndexDst[m_lIndexSrc-1]; //stang + nIndex1 = m_arIndexDst[m_lIndexSrc]; //r + + m_lIndexSrc++; + + ConvertProd(nIndex1, ptFormula, nIndex1-10, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); //r*cos + ConvertSum(pCurPoint1.x, pCurPointType1.x, m_lIndexDst-1, ptFormula, 0, ptValue, false, true, true, m_oGuidsRes);//x + + ConvertProd(nIndex1, ptFormula, nIndex1-6, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);// r*sin + ConvertSum(pCurPoint1.y, pCurPointType1.y, m_lIndexDst-1, ptFormula, 0, ptValue, false, true, true, m_oGuidsRes);//y + m_arIndexDst.push_back(m_lIndexDst-1); + //--------------------- + + nIndex = m_arIndexDst[m_lIndexSrc];//текущая точка + nIndex1 = m_arIndexDst[m_lIndexSrc-2];//stAng и swAng + nIndex2 = m_arIndexDst[m_lIndexSrc-3];//wR и hR + + if (j == 0) + strFrmla = _T("moveTo"); + else + strFrmla = _T("lnTo"); + + if (j == 0) + { + m_oPathRes.WriteString(_T("")); + } + else + { + m_oPathRes.WriteString(_T("")); + } + + //текущая точка + + nIndex = m_arIndexDst[m_lIndexSrc]; + + m_lIndexSrc++; + ConvertVal(nIndex-2, ptFormula, true, m_oGuidsRes); + ConvertVal(nIndex, ptFormula, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + } + } + void CFormulaConverter::ConvertSlice_EllipticalQuadrX(const CSlicePath& oSlice) + { + int nCountPoints = oSlice.m_arPoints.size(); + for (int j = 0; j < nCountPoints; j += 2) + { + pCurPoint = oSlice.m_arPoints[j]; + pCurPointType = oSlice.m_arPointsType[j]; + ConvertQuadrX(pCurPoint, pCurPointType); + + if (j+1 < nCountPoints) + { + pCurPoint1 = oSlice.m_arPoints[j+1]; + pCurPointType1 = oSlice.m_arPointsType[j+1]; + ConvertQuadrY(pCurPoint1, pCurPointType1); + } + } + } + void CFormulaConverter::ConvertSlice_EllipticalQuadrY(const CSlicePath& oSlice) + { + int nCountPoints = oSlice.m_arPoints.size(); + for (int j = 0; j < nCountPoints; j += 2) + { + pCurPoint = oSlice.m_arPoints[j]; + pCurPointType = oSlice.m_arPointsType[j]; + ConvertQuadrY(pCurPoint, pCurPointType); + + if (j+1 < nCountPoints) + { + pCurPoint1 = oSlice.m_arPoints[j+1]; + pCurPointType1 = oSlice.m_arPointsType[j+1]; + ConvertQuadrX(pCurPoint1, pCurPointType1); + } + } + } +} diff --git a/MsBinaryFile/Common/ODraw/CustomShapeConvert.h b/MsBinaryFile/Common/ODraw/CustomShapeConvert.h index d047817e98..42e7d7df48 100644 --- a/MsBinaryFile/Common/ODraw/CustomShapeConvert.h +++ b/MsBinaryFile/Common/ODraw/CustomShapeConvert.h @@ -33,12 +33,14 @@ #include "FormulaShape.h" #include "PathShape.h" +#include "BaseShape.h" +#include "../../XlsFile/Converter/ShapeType.h" #include "XmlWriter.h" namespace NSCustomShapesConvert { - static int __wstrlen(const wchar_t* str) + static int __wstrlen(const wchar_t* str) { const wchar_t* s = str; for (; *s != 0; ++s); @@ -143,6 +145,7 @@ namespace NSCustomShapesConvert ParamType m_eType; LONG m_lCoef; }; + class CSlicePath { public: @@ -154,34 +157,9 @@ namespace NSCustomShapesConvert int m_nCountElementsPoint; public: - CSlicePath(RulesType eType = rtMoveTo) - { - m_eRuler = eType; - m_nCountElementsPoint = 0; - } + CSlicePath(RulesType eType = rtMoveTo); - void AddParam(LONG lParam, ParamType eParType) - { - long lPoint = m_nCountElementsPoint % 2; - if (0 == lPoint) - { - Aggplus::POINT point; - SPointType pointType; - - point.x = lParam; - point.y = 0; - pointType.x = eParType; - pointType.y = ptValue; - m_arPoints.push_back(point); - m_arPointsType.push_back(pointType); - } - else - { - m_arPoints.back().y = lParam; - m_arPointsType.back().y = eParType; - } - ++m_nCountElementsPoint; - } + void AddParam(LONG lParam, ParamType eParType); }; class CFormulaConverter @@ -211,7 +189,6 @@ namespace NSCustomShapesConvert int m_lMaxAdjUse; public: - LONG m_lWidth; LONG m_lHeight; @@ -223,1921 +200,88 @@ namespace NSCustomShapesConvert CXmlWriter m_oCoef; public: - CFormulaConverter() - { - m_lIndexDst = 0; - m_lIndexSrc = -1; - m_lWidth = ShapeSizeVML; - m_lHeight = ShapeSizeVML; + CFormulaConverter(); - m_lMaxAdjUse = -1; - } - void ConvertCoef(NSCustomShapesConvert::CFormParam pCoef) - { - if (pCoef.m_eType == ptValue) - ConvertVal(pCoef.m_lParam, pCoef.m_eType, false, m_oCoef); - else if (pCoef.m_eType == ptFormula) - { - ConvertProd(22, ptValue, 1, ptValue, 7, ptValue, false, false, false, m_oCoef); - ConvertProd(m_lIndexDst-1, ptFormula, 1, ptValue, 180, ptValue, true, false, false, m_oCoef); - } - m_oParam.m_lParam = m_lIndexDst-1; - m_oParam.m_eType = ptFormula; - m_oParam.m_lCoef = pCoef.m_lCoef; - } - void ConvertCoef2(NSCustomShapesConvert::CFormParam pCoef) - { - if (pCoef.m_eType == ptValue) - ConvertVal(pCoef.m_lParam, pCoef.m_eType, false, m_oGuidsRes); - else if (pCoef.m_eType == ptFormula) - { - ConvertProd(22, ptValue, 1, ptValue, 7, ptValue, false, false, false, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, 1, ptValue, 180, ptValue, true, false, false, m_oGuidsRes); - } - m_oParam.m_lParam = m_lIndexDst-1; - m_oParam.m_eType = ptFormula; - m_oParam.m_lCoef = pCoef.m_lCoef; - } - void ConvertAdj(const std::vector& arAdj) - { - int nAdjCount = arAdj.size(); - for (int i = 0; i < nAdjCount; ++i) - { - m_oAdjRes.WriteString(_T("")); - } - for (int i = nAdjCount; i <= m_lMaxAdjUse; ++i) - { - m_oAdjRes.WriteString(_T("")); - } - } - void ConvertFormula(const std::vector& arFormulas) - { - int nGuidCount = arFormulas.size(); - for (int i = 0; i < nGuidCount; ++i) - { - const CFormula& pFormula = arFormulas[i]; - m_lIndexSrc++; + void ConvertCoef(NSCustomShapesConvert::CFormParam pCoef); + void ConvertCoef2(NSCustomShapesConvert::CFormParam pCoef); + void ConvertAdj(const std::vector& arAdj); + void ConvertFormula(const std::vector& arFormulas); + void ConvertPath(std::wstring strPath, const CPath& oPath); + void ConvertHandle(const std::vector& arHandles, std::vector& arAdj, oox::MSOSPT oSType); + void ConvertTextRect ( std::wstring strRect); - switch (pFormula.m_eFormulaType) - { - case ftVal: - { - ConvertVal(pFormula.m_lParam1, pFormula.m_eType1, false, m_oGuidsRes); - break; - } - case ftSum: - { - ConvertSum(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, pFormula.m_lParam3, pFormula.m_eType3, false, false, false, m_oGuidsRes); - break; - } - case ftProduct: - { - ConvertProd(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, pFormula.m_lParam3, pFormula.m_eType3, false, false, false, m_oGuidsRes); - break; - } - case ftMid: - { - // TODO: +/ ??? - ConvertSum(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, 0, ptValue, false, false, false, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, 1, ptValue, 2, ptValue, true, false, false, m_oGuidsRes); - break; - } - case ftAbsolute: - { - ConvertAbs (pFormula.m_lParam1, pFormula.m_eType1, false, m_oGuidsRes); - break; - } - case ftMin: - { - ConvertMin(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, false, false, m_oGuidsRes); - break; - } - case ftMax: - { - ConvertMax(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, false, false, m_oGuidsRes); - break; - } - case ftIf: - { - ConvertIf(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, pFormula.m_lParam3, pFormula.m_eType3, false, false, false, m_oGuidsRes); - break; - } - case ftMod: - { - ConvertMod(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, pFormula.m_lParam3, pFormula.m_eType3, false, false, false, m_oGuidsRes); - break; - } - case ftAtan2: - { - ConvertAt2(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, false, false, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_oParam.m_lParam, m_oParam.m_eType, pow3_16, ptValue, true, true, false, m_oGuidsRes); - break; - } - case ftSin: - { - ConvertProd(pFormula.m_lParam2, pFormula.m_eType2, pow3_16, ptValue, m_oParam.m_lParam, m_oParam.m_eType, false, false, true, m_oGuidsRes); - ConvertSin(pFormula.m_lParam1, pFormula.m_eType1, m_lIndexDst-1, ptFormula, false, true, m_oGuidsRes); - break; - } - case ftCos: - { - ConvertProd(pFormula.m_lParam2, pFormula.m_eType2, pow3_16, ptValue, m_oParam.m_lParam, m_oParam.m_eType, false, false, true, m_oGuidsRes); - ConvertCos(pFormula.m_lParam1, pFormula.m_eType1, m_lIndexDst-1, ptFormula, false, true, m_oGuidsRes); - break; - } - case ftCosatan2: - { - ConvertCat2(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, pFormula.m_lParam3, pFormula.m_eType3, false, false, false, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_oParam.m_lParam, m_oParam.m_eType, pow3_16, ptValue, true, true, false, m_oGuidsRes); - break; - } - case ftSinatan2: - { - ConvertSat2(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, pFormula.m_lParam3, pFormula.m_eType3, false, false, false, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_oParam.m_lParam, m_oParam.m_eType, pow3_16, ptValue, true, true, false, m_oGuidsRes); - break; - } - case ftSqrt: - { - ConvertSqrt(pFormula.m_lParam1, pFormula.m_eType1, false, m_oGuidsRes); - break; - } - case ftTan: - { - ConvertTag(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, false, false, m_oGuidsRes); - break; - } - case ftSumangle: - { - ConvertProd(pFormula.m_lParam1, pFormula.m_eType1, pow3_16, ptValue, m_oParam.m_lParam, m_oParam.m_eType, false, false, true, m_oGuidsRes); - ConvertProd(pow3_16, ptValue, pFormula.m_lParam2, pFormula.m_eType2, 1, ptValue, false, false, false, m_oGuidsRes); - ConvertProd(pow3_16, ptValue, pFormula.m_lParam3, pFormula.m_eType3, 1, ptValue, false, false, false, m_oGuidsRes); - ConvertSum(m_lIndexDst-3, ptFormula, m_lIndexDst-2, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_oParam.m_lParam, m_oParam.m_eType, pow3_16, ptValue, true, true, false, m_oGuidsRes); - break; - } - case ftEllipse: - { - ConvertProd(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam1, pFormula.m_eType1, 1, ptValue , false, false, false, m_oGuidsRes); - ConvertProd(pFormula.m_lParam2, pFormula.m_eType2, pFormula.m_lParam2, pFormula.m_eType2, 1, ptValue , false, false, false, m_oGuidsRes); - ConvertProd(1, ptValue, m_lIndexDst-2, ptFormula, m_lIndexDst-1, ptFormula, false, true, true, m_oGuidsRes); - ConvertSum(0, ptValue, 1, ptValue, m_lIndexDst-1, ptFormula, false, false, true, m_oGuidsRes); - ConvertSqrt(m_lIndexDst-1, ptFormula, true, m_oGuidsRes); - ConvertProd(pFormula.m_lParam3, pFormula.m_eType3, m_lIndexDst-1, ptFormula, 1, ptValue, false, true, false, m_oGuidsRes); - break; - } - default: - break; - } - - m_arIndexDst.push_back(m_lIndexDst-1); - } - } - - - - void ConvertPath(std::wstring strPath, const CPath& oPath) - { - m_arParts.clear(); - std::vector oArray; - NSStringUtils::ParseString(L"e", strPath, oArray); - - int nSizeArr = oArray.size(); - for (int nIndex = 0; nIndex < nSizeArr; ++nIndex) - { - if (oArray[nIndex].empty()) continue; - - if (nIndex < (int)oPath.m_arParts.size() ) - { - const CPartPath& oPart = oPath.m_arParts[nIndex]; - m_lWidth = oPart.width; - m_lHeight = oPart.height; - } - - bool bFill = false; - bool bStroke = false; - - std::wstring strValue; - FromXML(oArray[nIndex], bFill, bStroke); - LONG nCountSlices = m_arSlicesPath.size(); - - m_oPathRes.StartNode(L"a:path"); - m_oPathRes.StartAttributes(); - m_oPathRes.WriteAttribute(L"w", m_lWidth); - m_oPathRes.WriteAttribute(L"h", m_lHeight); - - m_oPathRes.WriteAttribute(L"fill" , std::wstring(bFill ? L"norm" : L"none")); - m_oPathRes.WriteAttribute(L"stroke" , bStroke ? 1 : 0); - m_oPathRes.WriteAttribute(L"extrusionOk", 0); - - m_oPathRes.EndAttributes(); - - for (int i = 0; i < nCountSlices; ++i) - { - CSlicePath& oSlice = m_arSlicesPath[i]; - - //m_lIndexDst-1 - номер последней записанной формулы - //m_lIndexSrc - номер последнего блока формул - //m_arIndexDst[n] - возвращает номер последней формулы в блоке n - //m_arIndexDst[m_lIndexSrc] = m_lIndexDst - - switch (oSlice.m_eRuler) - { - case rtMoveTo: - { - ConvertSlice_MoveTo(oSlice); - break; - } - case rtRMoveTo: - { - ConvertSlice_RMoveTo(oSlice); - break; - } - case rtClose: - { - m_oPathRes.WriteString(_T("")); - break; - } - case rtLineTo: - { - ConvertSlice_LineTo(oSlice); - break; - } - case rtRLineTo: - { - ConvertSlice_RLineTo(oSlice); - break; - } - case rtArcTo: - case rtArc: - { - ConvertSlice_ArcTo(oSlice); - break; - } - case rtClockwiseArcTo: - case rtClockwiseArc: - { - ConvertSlice_ClockwiseTo(oSlice); - break; - } - case rtQuadrBesier: - { - ConvertSlice_QuadrBesier(oSlice); - break; - } - case rtCurveTo: - { - ConvertSlice_CurveTo(oSlice); - break; - } - case rtRCurveTo: - { - ConvertSlice_RCurveTo(oSlice); - break; - } - case rtAngleEllipse: - case rtAngleEllipseTo: - { - ConvertSlice_AngleEllipse(oSlice); - break; - } - case rtEllipticalQuadrX: - { - ConvertSlice_EllipticalQuadrX(oSlice); - break; - } - case rtEllipticalQuadrY: - { - ConvertSlice_EllipticalQuadrY(oSlice); - break; - } - default: - break; - } - } - - m_oPathRes.WriteString(_T("")); - } - } - - void ConvertHandle(const std::vector& arHandles, std::vector& arAdj, oox::MSOSPT oSType) - { - LONG nHandlesCount = arHandles.size(); - if (oSType == 19) // в пптх не реализована функция изменения размера шейпа при изменении handle - nHandlesCount = 0; - for (int i = 0; i < nHandlesCount; ++i) - { - const CHandle_& pHnPoint = arHandles[i]; - std::vector arPos; - - std::wstring sPos0 = _T(""); - std::wstring sPos1 = _T(""); - - SHandle oHandle; - ParamType ptType; - - if (pHnPoint.position != _T("")) - { - NSStringUtils::ParseString(_T(","), pHnPoint.position, arPos); - sPos0 = arPos[0]; - sPos1 = arPos[1]; - - oHandle.gdRef.x = GetHandleValue(sPos0, m_lWidth, ptType); - oHandle.gdRefType.x = ptType; - if (oHandle.gdRefType.x == ptAdjust) - oHandle.bRefExist.x = true; - - oHandle.gdRef.y = GetHandleValue(sPos1, m_lWidth, ptType); - oHandle.gdRefType.y = ptType; - if (oHandle.gdRefType.y == ptAdjust) - oHandle.bRefExist.y = true; - - if (pHnPoint.polar != _T("")) - { - //пришел полярный угол - oHandle.bRefExist.y = false; - - oHandle.bRefPolarExist.y = true; - oHandle.bMinPolarExist.y = true; - - NSStringUtils::ParseString(_T(","), pHnPoint.polar, arPos); - - oHandle.PolarCentre.x = GetHandleValue(arPos[0], m_lWidth, ptType); - oHandle.PolarCentreType.x = ptType; - - oHandle.PolarCentre.y = GetHandleValue(arPos[1], m_lWidth, ptType); - oHandle.PolarCentreType.y = ptType; - - if (oHandle.gdRefType.y == ptAdjust) - { - //угол должен храниться в pptx формате, поэтому придётся его везде заменить - std::wstring strNewFmla = GetValue2(m_lIndexDst, ptFormula, true); - std::wstring strOldFmla = GetValue2(oHandle.gdRef.y, oHandle.gdRefType.y, false); - LONG nIndex = m_lIndexDst; - - // TODO: !!! тут медленный код. - m_oGuidsRes.ReplaceString(strOldFmla, strNewFmla); - - m_lIndexSrc++; - - // TODO: !!! тут медленный код. - CXmlWriter memGuidsRes; - ConvertProd(oHandle.gdRef.y, oHandle.gdRefType.y, m_oParam.m_lCoef, ptValue, pow3_16, ptValue, false, true, false, memGuidsRes); - m_oGuidsRes.m_oWriter.WriteBefore(memGuidsRes.m_oWriter); - m_arIndexDst.push_back(m_lIndexDst-1); - - if (oHandle.gdRefType.y == ptAdjust) - { - double dScale = (double)pow3_16 / m_oParam.m_lCoef; - - LONG nCountAdj = arAdj.size(); - if (oHandle.gdRef.y >= nCountAdj) - { - // дурацкий код. надо память перевыделить, а старую скопировать - // пока сделаю так, чтобы наверняка - int nNewSize = (int)oHandle.gdRef.y + 1; - while ((int)arAdj.size() < nNewSize) - arAdj.push_back(0); - } - - LONG lVal = (LONG)(dScale * arAdj[oHandle.gdRef.y]); - arAdj[oHandle.gdRef.y] = lVal; - } - - //рассчитаем координаты точки handle - - m_lIndexSrc++; - ConvertCos(oHandle.gdRef.x, oHandle.gdRefType.x, oHandle.gdRef.y, oHandle.gdRefType.y, false, false, m_oGuidsRes); - ConvertSin(oHandle.gdRef.x, oHandle.gdRefType.x, oHandle.gdRef.y, oHandle.gdRefType.y, false, false, m_oGuidsRes); - ConvertSum(oHandle.PolarCentre.x, oHandle.PolarCentreType.x, m_lIndexDst-2, ptFormula, 0, ptValue, false, true, false, m_oGuidsRes); - ConvertSum(oHandle.PolarCentre.y, oHandle.PolarCentreType.y, m_lIndexDst-2, ptFormula, 0, ptValue, false, true, false, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - - std::wstring strMem = std::to_wstring(m_lIndexDst - 2); - - oHandle.Pos.x = GetHandlePos(strMem, _T("w"), m_lWidth); - oHandle.PosType.x = ptFormula; - - strMem = std::to_wstring(m_lIndexDst - 2); - oHandle.Pos.y = GetHandlePos(strMem, _T("h"), m_lHeight); - oHandle.PosType.y = ptFormula; - } - - } - else//если пришли обычные координаты - { - if ((pHnPoint.xrange != _T("") && oHandle.gdRefType.x != ptAdjust && oHandle.gdRefType.y == ptAdjust) || - (pHnPoint.yrange != _T("") && oHandle.gdRefType.x == ptAdjust && oHandle.gdRefType.y != ptAdjust)) - { - oHandle.Pos.x = GetHandlePos(sPos1, _T("w"), m_lWidth); - oHandle.PosType.x = ptFormula; - - oHandle.Pos.y = GetHandlePos(sPos0, _T("h"), m_lHeight); - oHandle.PosType.y = ptFormula; - } - else - { - oHandle.Pos.x = GetHandlePos(sPos0, _T("w"), m_lWidth); - oHandle.PosType.x = ptFormula; - - oHandle.Pos.y = GetHandlePos(sPos1, _T("h"), m_lHeight); - oHandle.PosType.y = ptFormula; - } - } - } - - if (pHnPoint.xrange != _T("")) - { - if ( oHandle.gdRefType.x != ptAdjust && oHandle.gdRefType.y == ptAdjust) - { - oHandle.gdRef.x = GetHandleValue(sPos1, m_lWidth, ptType); - oHandle.gdRefType.x = ptType; - oHandle.bRefExist.x = true; - - oHandle.gdRef.y = GetHandleValue(sPos0, m_lHeight, ptType); - oHandle.gdRefType.y = ptType; - oHandle.bRefExist.y = false; - } - - NSStringUtils::ParseString(_T(","), pHnPoint.xrange, arPos); - oHandle.Min.x = GetHandleValue(arPos[0], m_lWidth, ptType); - oHandle.MinType.x = ptType; - if ( oHandle.bRefExist.x) - oHandle.bMinExist.x = true; - - oHandle.Max.x = GetHandleValue(arPos[1], m_lWidth, ptType); - oHandle.MaxType.x = ptType; - if ( oHandle.bRefExist.x) - oHandle.bMaxExist.x = true; - } - - if (pHnPoint.yrange != _T("")) - { - if (oHandle.gdRefType.x == ptAdjust && oHandle.gdRefType.y != ptAdjust) - { - oHandle.gdRef.x = GetHandleValue(sPos1, m_lWidth, ptType); - oHandle.gdRefType.x = ptType; - oHandle.bRefExist.x = false; - - oHandle.gdRef.y = GetHandleValue(sPos0, m_lHeight, ptType); - oHandle.gdRefType.y = ptType; - oHandle.bRefExist.y = true; - } - - NSStringUtils::ParseString(_T(","), pHnPoint.yrange, arPos); - oHandle.Min.y = GetHandleValue(arPos[0], m_lHeight, ptType); - oHandle.MinType.y = ptType; - if ( oHandle.bRefExist.y ) - oHandle.bMinExist.y = true; - - oHandle.Max.y = GetHandleValue(arPos[1], m_lHeight, ptType); - oHandle.MaxType.y = ptType; - if ( oHandle.bRefExist.y ) - oHandle.bMaxExist.y = true; - } - - if (pHnPoint.radiusrange != _T("")) - { - NSStringUtils::ParseString(_T(","), pHnPoint.radiusrange, arPos); - oHandle.Min.x = GetHandleValue(arPos[0], m_lHeight, ptType); - oHandle.MinType.x = ptType; - oHandle.bMinPolarExist.x = true; - - oHandle.Max.x = GetHandleValue(arPos[1], m_lHeight, ptType); - oHandle.MaxType.x = ptType; - oHandle.bMinPolarExist.y = true; - - if (oHandle.gdRefType.x == ptAdjust) - { - oHandle.bRefPolarExist.x = true; - oHandle.bRefExist.x = false; - } - } - - CreateHandle(oHandle); - - } - ConvertAdj(arAdj); - } - - void ConvertTextRect ( std::wstring strRect) - { - if (strRect.empty()) return; - - std::vector arBorder; - NSStringUtils::ParseString(_T(","), strRect, arBorder); - - m_lIndexSrc++; - ConvertProd(_T("w"), arBorder[0], m_lWidth, m_oGuidsRes); - ConvertProd(_T("h"), arBorder[1], m_lHeight, m_oGuidsRes); - ConvertProd(_T("w"), arBorder[2], m_lWidth, m_oGuidsRes); - ConvertProd(_T("h"), arBorder[3], m_lHeight, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst); - - m_oTextRect.WriteString(_T("")); - } private: + void GetValue(const LONG& lParam, const ParamType& eParamType, const bool& bExtShape, CXmlWriter& oWriter); + std::wstring GetValue2(const LONG& lParam, const ParamType& eParamType, const bool& bExtShape); - void GetValue(const LONG& lParam, const ParamType& eParamType, const bool& bExtShape, CXmlWriter& oWriter) - { - oWriter.m_oWriter.AddSize(15); - switch (eParamType) - { - case ptFormula: - { - oWriter.m_oWriter.AddCharNoCheck((WCHAR)'g'); - oWriter.m_oWriter.AddCharNoCheck((WCHAR)'d'); - - if (bExtShape) - oWriter.m_oWriter.AddIntNoCheck(lParam); - else - oWriter.m_oWriter.AddIntNoCheck(m_arIndexDst[lParam]); - break; - } - case ptAdjust: - { - oWriter.m_oWriter.AddCharNoCheck((WCHAR)'a'); - oWriter.m_oWriter.AddCharNoCheck((WCHAR)'d'); - oWriter.m_oWriter.AddCharNoCheck((WCHAR)'j'); - oWriter.m_oWriter.AddIntNoCheck(lParam); - - if (lParam > m_lMaxAdjUse) - m_lMaxAdjUse = lParam; - - break; - } - case ptValue: - { - oWriter.m_oWriter.AddIntNoCheck(lParam); - break; - } - default: - break; - } - } - std::wstring GetValue2(const LONG& lParam, const ParamType& eParamType, const bool& bExtShape) - { - std::wstring strValue; - switch (eParamType) - { - case ptFormula: - { - if (bExtShape) - strValue = std::to_wstring(lParam); - else - strValue = std::to_wstring(m_arIndexDst[lParam]); - strValue = _T("gd") + strValue; - break; - } - case ptAdjust: - { - strValue = _T("adj") + std::to_wstring(lParam); - break; - } - case ptValue: - { - strValue = std::to_wstring(lParam); - break; - } - default: - break; - } - return strValue; - } //--------------------------------------- - void ConvertVal(const LONG& lParam1, const ParamType& eType1, const bool& bExtShape1, CXmlWriter& oWriter) - { - GUIDE_PARAM_1(val) - } + void ConvertVal(const LONG& lParam1, const ParamType& eType1, const bool& bExtShape1, CXmlWriter& oWriter); void ConvertSum(const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, - const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, CXmlWriter& oWriter) - { - GUIDE_PARAM_3(sum) - } + const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, CXmlWriter& oWriter); void ConvertProd(const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, - const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, CXmlWriter& oWriter) - { - GUIDE_PARAM_3(prod) - } + const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, CXmlWriter& oWriter); - void ConvertAbs(const LONG& lParam1, const ParamType& eType1, const bool& bExtShape1, CXmlWriter& oWriter) - { - GUIDE_PARAM_1(abs) - } + void ConvertAbs(const LONG& lParam1, const ParamType& eType1, const bool& bExtShape1, CXmlWriter& oWriter); void ConvertMin(const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, - const bool& bExtShape1, const bool& bExtShape2, CXmlWriter& oWriter) - { - GUIDE_PARAM_2(min) - } + const bool& bExtShape1, const bool& bExtShape2, CXmlWriter& oWriter); void ConvertMax (const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, - const bool& bExtShape1, const bool& bExtShape2, CXmlWriter& oWriter) - { - GUIDE_PARAM_2(max) - } + const bool& bExtShape1, const bool& bExtShape2, CXmlWriter& oWriter); void ConvertIf(const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, - const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, CXmlWriter& oWriter) - { - GUIDE_PARAM_3(_if) - } + const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, CXmlWriter& oWriter); - void ConvertSqrt(const LONG& lParam1, const ParamType& eType1, const bool& bExtShape1, CXmlWriter& oWriter) - { - GUIDE_PARAM_1(sqrt) - } + void ConvertSqrt(const LONG& lParam1, const ParamType& eType1, const bool& bExtShape1, CXmlWriter& oWriter); void ConvertAt2 (const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, - const bool& bExtShape1, const bool& bExtShape2, CXmlWriter& oWriter) - { - GUIDE_PARAM_2(at2) - } + const bool& bExtShape1, const bool& bExtShape2, CXmlWriter& oWriter); void ConvertSin (const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, - const bool& bExtShape1, const bool& bExtShape2, CXmlWriter& oWriter) - { - GUIDE_PARAM_2(sin) - } + const bool& bExtShape1, const bool& bExtShape2, CXmlWriter& oWriter); void ConvertCos (const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, - const bool& bExtShape1, const bool& bExtShape2, CXmlWriter& oWriter) - { - GUIDE_PARAM_2(cos) - } + const bool& bExtShape1, const bool& bExtShape2, CXmlWriter& oWriter); void ConvertCat2(const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, - const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, CXmlWriter& oWriter) - { - GUIDE_PARAM_3(cat2) - } + const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, CXmlWriter& oWriter); void ConvertSat2(const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, - const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, CXmlWriter& oWriter) - { - GUIDE_PARAM_3(sat2) - } + const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, CXmlWriter& oWriter); void ConvertMod(const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, - const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, CXmlWriter& oWriter) - { - GUIDE_PARAM_3(mod) - } + const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, CXmlWriter& oWriter); void ConvertTag (const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, - const bool& bExtShape1, const bool& bExtShape2, CXmlWriter& oWriter) - { - GUIDE_PARAM_2(tag) - } + const bool& bExtShape1, const bool& bExtShape2, CXmlWriter& oWriter); - void ConvertProd(const std::wstring& strParam1, const std::wstring& strParam2, const LONG& lParam3, CXmlWriter& oWriter) - { - oWriter.m_oWriter.AddSize(g_guide_max_len); - oWriter.m_oWriter.WriteStringNoSafe(g_guide_string1, g_guide_string1_len); - oWriter.m_oWriter.AddIntNoCheck(m_lIndexDst); - oWriter.m_oWriter.WriteStringNoSafe(g_guide_string_prod, g_guide_string_prod_len); - oWriter.WriteString(strParam1); - oWriter.m_oWriter.AddSpaceNoCheck(); - - if ('#' == strParam2[0]) - { - LONG lRes = (LONG)XmlUtils::GetInteger(strParam2.substr(1)); - GetValue(lRes, ptAdjust, false, oWriter); - } - else if ('@' == strParam2[0]) - { - LONG lRes = (LONG)XmlUtils::GetInteger(strParam2.substr(1)); - GetValue(lRes, ptFormula, false, oWriter); - } - else - oWriter.WriteString(strParam2); - - oWriter.m_oWriter.AddSpaceNoCheck(); - GetValue(lParam3, ptValue, false, oWriter); - - ++m_lIndexDst; - oWriter.m_oWriter.WriteStringNoSafe(g_guide_string2, g_guide_string2_len); - } + void ConvertProd(const std::wstring& strParam1, const std::wstring& strParam2, const LONG& lParam3, CXmlWriter& oWriter); //------------------------------------- - void FromXML(std::wstring strPath, bool &m_bFill, bool &m_bStroke) - { - m_arSlicesPath.clear(); - NSStringUtils::CheckPathOn_Fill_Stroke(strPath, m_bFill, m_bStroke); - std::vector oArray; - NSStringUtils::ParsePath2(strPath, &oArray); + void FromXML(std::wstring strPath, bool &m_bFill, bool &m_bStroke); + void CreateHandle ( SHandle oHnd ); - ParamType eParamType = ptValue; - RulesType eRuler = rtEnd; - LONG lValue; - bool bRes = true; - - for (size_t nIndex = 0; nIndex < oArray.size(); ++nIndex) - { - std::wstring str = oArray[nIndex]; - lValue = NSCustomShapesConvert::GetValue(oArray[nIndex], eParamType, bRes); - if (bRes) - { - if (0 != m_arSlicesPath.size()) - { - m_arSlicesPath[m_arSlicesPath.size() - 1].AddParam(lValue, eParamType); - } - } - else - { - eRuler = GetRuler(oArray[nIndex], bRes); - if (bRes) - { - if (rtNoFill == eRuler) - { - m_bFill = false; - } - else if (rtNoStroke == eRuler) - { - m_bStroke = false; - } - else - { - CSlicePath oSlice(eRuler); - m_arSlicesPath.push_back(oSlice); - } - } - } - } - } - void CreateHandle ( SHandle oHnd ) - { - std::wstring strRes = _T(""); - if (oHnd.bRefPolarExist.x || oHnd.bRefPolarExist.y) - m_oHandleRes.WriteString(_T("")); - else if (oHnd.bRefExist.x || oHnd.bRefExist.y) - m_oHandleRes.WriteString(_T("\"/>")); - } - - LONG GetHandlePos(const std::wstring& strParam, const std::wstring& strBase, LONG lSize) - { - LONG lRes; - std::wstring strSize; - std::wstring strIndex; - - strSize = std::to_wstring( lSize); - - if ('#' == strParam[0]) - { - lRes = (LONG)XmlUtils::GetInteger(strParam.substr(1)); - strFrmla = GetValue2(lRes, ptAdjust, false) + L" " + strSize; - } - else if ('&' == strParam[0]) - { - lRes = (LONG)XmlUtils::GetInteger(strParam.substr(1)); - strFrmla = GetValue2(lRes, ptFormula, true) + L" " + strSize; - } - else if ('@' == strParam[0]) - { - lRes = (LONG)XmlUtils::GetInteger(strParam.substr(1)); - strFrmla = GetValue2(lRes, ptFormula, false) + L" " + strSize; - } - else if (!NSStringUtils::IsNumber(strParam)) - { - if (_T("center") == strParam) - strFrmla = _T("1 2"); - else if (_T("topLeft") == strParam) - strFrmla = _T("0 1"); - else if ( _T("bottomRight") == strParam) - strFrmla = _T("1 1"); - } - else - { - lRes = (LONG)XmlUtils::GetInteger(strParam.c_str()); - strFrmla = GetValue2(lRes, ptValue, false) + strSize; - } - - m_lIndexSrc++; - m_arIndexDst.push_back(m_lIndexDst); - strIndex = std::to_wstring(m_lIndexDst); - - m_oGuidsRes.WriteString(_T("")); - - m_lIndexDst++; - - return m_lIndexDst-1; - } - - - LONG GetHandleValue(const std::wstring& strParam, const LONG& lVal, ParamType& ptType) - { - ptType = ptValue; - if ('#' == strParam[0]) - { - ptType = ptAdjust; - return (LONG)XmlUtils::GetInteger(strParam.substr(1).c_str()); - } - else if ('@' == strParam[0]) - { - ptType = ptFormula; - return (LONG)XmlUtils::GetInteger(strParam.substr(1).c_str()); - } - else if (!NSStringUtils::IsNumber(strParam)) - { - if (_T("center") == strParam) - return lVal/2; - else if (_T("bottomRight") == strParam)//Demo-Hayden-Management-v2.docx - return lVal; - else - return 0; //??? - //todooo прописать все варианты правильно - } - else - { - ptType = ptValue; - return (LONG)XmlUtils::GetInteger(strParam.c_str()); - } - } - void ConvertQuadrX(Aggplus::POINT pPoint, SPointType pPointType) - { - LONG nIndex = m_arIndexDst[m_lIndexSrc]; - - m_lIndexSrc++; - - ConvertSum(pPoint.x, pPointType.x, 0, ptValue, nIndex-1, ptFormula, false, true, true, m_oGuidsRes); - ConvertSum(pPoint.y, pPointType.y, 0, ptValue, nIndex, ptFormula, false, true, true, m_oGuidsRes); - ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-2, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(m_lIndexDst-4, ptFormula, 16200000, ptValue, 5400000, ptValue, true, true, true, m_oGuidsRes); //stAng - ConvertIf(m_lIndexDst-2, ptFormula, 5400000, ptValue, -5400000, ptValue, true, true, true, m_oGuidsRes); //swAng - ConvertProd(m_lIndexDst-7, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-7, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(m_lIndexDst-9, ptFormula, m_lIndexDst-9, ptFormula, m_lIndexDst-2, ptFormula, true, true, true, m_oGuidsRes);//wR - ConvertIf(m_lIndexDst-9, ptFormula, m_lIndexDst-9, ptFormula, m_lIndexDst-2, ptFormula, true, true, true, m_oGuidsRes);//hR - - m_arIndexDst.push_back(m_lIndexDst-1); - - nIndex = m_arIndexDst[m_lIndexSrc]; - - m_oPathRes.WriteString(_T("")); - - m_lIndexSrc++; - ConvertVal(pPoint.x, pPointType.x, false, m_oGuidsRes); - ConvertVal(pPoint.y, pPointType.y, false, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - return; - } - - void ConvertQuadrY(Aggplus::POINT pPoint, SPointType pPointType) - { - LONG nIndex = m_arIndexDst[m_lIndexSrc]; - - m_lIndexSrc++; - - ConvertSum(pPoint.x, pPointType.x, 0, ptValue, nIndex-1, ptFormula, false, true, true, m_oGuidsRes); - ConvertSum(pPoint.y, pPointType.y, 0, ptValue, nIndex, ptFormula, false, true, true, m_oGuidsRes); - ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-2, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(m_lIndexDst-5, ptFormula, 10800000, ptValue, 0, ptValue, true, true, true, m_oGuidsRes); //stAng - ConvertIf(m_lIndexDst-2, ptFormula, -5400000, ptValue, 5400000, ptValue, true, true, true, m_oGuidsRes); //swAng - ConvertProd(m_lIndexDst-7, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-7, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(m_lIndexDst-9, ptFormula, m_lIndexDst-9, ptFormula, m_lIndexDst-2, ptFormula, true, true, true, m_oGuidsRes);//wR - ConvertIf(m_lIndexDst-9, ptFormula, m_lIndexDst-9, ptFormula, m_lIndexDst-2, ptFormula, true, true, true, m_oGuidsRes);//hR - m_arIndexDst.push_back(m_lIndexDst-1); - - nIndex = m_arIndexDst[m_lIndexSrc]; - - m_oPathRes.WriteString(_T("")); - - m_lIndexSrc++; - ConvertVal(pPoint.x, pPointType.x, false, m_oGuidsRes); - ConvertVal(pPoint.y, pPointType.y, false, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - return; - } + LONG GetHandlePos(const std::wstring& strParam, const std::wstring& strBase, LONG lSize); + LONG GetHandleValue(const std::wstring& strParam, const LONG& lVal, ParamType& ptType); + void ConvertQuadrX(Aggplus::POINT pPoint, SPointType pPointType); + void ConvertQuadrY(Aggplus::POINT pPoint, SPointType pPointType); //------------------------------------- - void ConvertSlice_MoveTo(const CSlicePath& oSlice) - { - int nCountPoints = oSlice.m_arPoints.size(); - for (int j = 0; j < nCountPoints; ++j) - { - pCurPoint = oSlice.m_arPoints[j]; - pCurPointType = oSlice.m_arPointsType[j]; - - m_lIndexSrc++; - ConvertVal(pCurPoint.x, pCurPointType.x, false, m_oGuidsRes); - ConvertVal(pCurPoint.y, pCurPointType.y, false, m_oGuidsRes); - - m_arIndexDst.push_back(m_lIndexDst-1); - - m_oPathRes.WriteString(_T("")); - } - } - - void ConvertSlice_RMoveTo(const CSlicePath& oSlice) - { - int nCountPoints = oSlice.m_arPoints.size(); - for (int j = 0; j < nCountPoints; j++) - { - pCurPoint = oSlice.m_arPoints[j]; - pCurPointType = oSlice.m_arPointsType[j]; - - m_lIndexSrc ++; - ConvertSum(m_lIndexDst-2, ptFormula, pCurPoint.x, pCurPointType.x, 0, ptValue, true, false, true, m_oGuidsRes); - ConvertSum(m_lIndexDst-2, ptFormula, pCurPoint.y, pCurPointType.y, 0, ptValue, true, false, true, m_oGuidsRes); - - m_arIndexDst.push_back(m_lIndexDst-1); - - m_oPathRes.WriteString(_T("")); - } - } - - void ConvertSlice_LineTo(const CSlicePath& oSlice) - { - int nCountPoints = oSlice.m_arPoints.size(); - for (int j = 0; j < nCountPoints; j++) - { - pCurPoint = oSlice.m_arPoints[j]; - pCurPointType = oSlice.m_arPointsType[j]; - - m_lIndexSrc++; - ConvertVal(pCurPoint.x, pCurPointType.x, false, m_oGuidsRes); - ConvertVal(pCurPoint.y, pCurPointType.y, false, m_oGuidsRes); - - m_arIndexDst.push_back(m_lIndexDst-1); - - m_oPathRes.WriteString(_T("")); - } - } - - void ConvertSlice_RLineTo(const CSlicePath& oSlice) - { - int nCountPoints = oSlice.m_arPoints.size(); - for (int j = 0; j < nCountPoints; j++) - { - pCurPoint = oSlice.m_arPoints[j]; - pCurPointType = oSlice.m_arPointsType[j]; - - m_lIndexSrc++; - ConvertSum(m_lIndexDst-2, ptFormula, pCurPoint.x, pCurPointType.x, 0, ptValue, true, false, true, m_oGuidsRes); - ConvertSum(m_lIndexDst-2, ptFormula, pCurPoint.y, pCurPointType.y, 0, ptValue, true, false, true, m_oGuidsRes); - - m_arIndexDst.push_back(m_lIndexDst-1); - - m_oPathRes.WriteString(_T("")); - } - } - - void ConvertSlice_ArcTo(const CSlicePath& oSlice) - { - int nCountPoints = oSlice.m_arPoints.size(); - LONG nIndex = 0; - LONG nIndex1 = 0; - LONG nIndex2 = 0; - for (int j = 0; j < nCountPoints; j+=4) - { - pCurPoint = oSlice.m_arPoints[j]; - pCurPointType = oSlice.m_arPointsType[j]; - pCurPoint1 = oSlice.m_arPoints[j+1]; - pCurPointType1 = oSlice.m_arPointsType[j+1]; - - //длина сторон - m_lIndexSrc++; - ConvertSum(pCurPoint1.x, pCurPointType1.x, 0, ptValue, pCurPoint.x, pCurPointType.x, false, true, false, m_oGuidsRes); - ConvertSum(pCurPoint1.y, pCurPointType1.y, 0, ptValue, pCurPoint.y, pCurPointType.y, false, true, false, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //координаты центра - nIndex = m_arIndexDst[m_lIndexSrc]; - - m_lIndexSrc++; - ConvertProd(nIndex-1, ptFormula, 1, ptValue, 2, ptValue, true, true, true, m_oGuidsRes); //a=wR - ConvertProd(nIndex, ptFormula, 1, ptValue, 2, ptValue, true, true, true, m_oGuidsRes); //b=hR - - ConvertSum(pCurPoint.x, pCurPointType.x, m_lIndexDst-2, ptFormula, 0, ptValue, false, true, true, m_oGuidsRes); - ConvertSum(pCurPoint.y, pCurPointType.y, m_lIndexDst-2, ptFormula, 0, ptValue, false, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //рассчет для stAng--------------------------- - //расположение текущей точки по четвертям 3 4 - // 2 1 - - pCurPoint = oSlice.m_arPoints[j+2]; - pCurPointType = oSlice.m_arPointsType[j+2]; - nIndex = m_arIndexDst[m_lIndexSrc]; - - m_lIndexSrc++; - ConvertSum(pCurPoint.x, pCurPointType.x, 0, ptValue, nIndex-1, ptFormula, false, true, true, m_oGuidsRes); - ConvertSum(pCurPoint.y, pCurPointType.y, 0, ptValue, nIndex, ptFormula, false, true, true, m_oGuidsRes); - ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //угол между Ох и радиус-вектором к точке - nIndex = m_arIndexDst[m_lIndexSrc]; - - m_lIndexSrc++; - ConvertProd(nIndex-2, ptFormula, 1, ptValue, nIndex-3, ptFormula, true, true, true, m_oGuidsRes); - ConvertAt2(1, ptValue, m_lIndexDst-1, ptFormula, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //радиус к точке - nIndex = m_arIndexDst[m_lIndexSrc]; - nIndex1 = m_arIndexDst[m_lIndexSrc-2]; - - m_lIndexSrc++; - ConvertCos(1, ptValue, nIndex, ptFormula, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(nIndex1-2, ptFormula, nIndex1-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//(b*cos(u))^2 - - ConvertSin(1, ptValue, nIndex, ptFormula, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(nIndex1-3, ptFormula, nIndex1-3, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//(a*sin(u))^2 - - ConvertSum(m_lIndexDst-1, ptFormula, m_lIndexDst-5, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); - ConvertSqrt(m_lIndexDst-1, ptFormula, true, m_oGuidsRes); - ConvertProd(nIndex1-3, ptFormula, nIndex1-2, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//r - m_arIndexDst.push_back(m_lIndexDst-1); - //если точка во 2 и 3 четвертях, прибавляем по 180grad - nIndex = m_arIndexDst[m_lIndexSrc-2]; - - m_lIndexSrc++; - ConvertIf(nIndex-3, ptFormula, 0, ptValue, 10800000, ptValue, true, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //угол до 1 точки (stAngle) - nIndex = m_arIndexDst[m_lIndexSrc-2];//угол между ох и радиусом - nIndex1 = m_arIndexDst[m_lIndexSrc-3];//расположение точки по четвертям - nIndex2 = m_arIndexDst[m_lIndexSrc];//прибавка 180 или 0 - - m_lIndexSrc ++; - ConvertProd(nIndex1-1, ptFormula, nIndex1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//знак у угла - ConvertProd(nIndex, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(nIndex, ptFormula, nIndex, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//угол всегда положительный - - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-3, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//u с нужным знаком - - ConvertSum(m_lIndexDst-1, ptFormula, nIndex2, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //координаты стартовой точки - nIndex = m_arIndexDst[m_lIndexSrc-2]; - nIndex1 = m_arIndexDst[m_lIndexSrc-4]; - nIndex2 = m_arIndexDst[m_lIndexSrc-5]; - - m_lIndexSrc++; - ConvertProd(nIndex, ptFormula, nIndex-10, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//r*cos(a) - ConvertProd(nIndex1-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertSum(nIndex2-1, ptFormula, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); //x - - ConvertProd(nIndex-6, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(nIndex-6, ptFormula, nIndex-6, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//sin теперь всегда>0 - - ConvertProd(nIndex, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//r*sin - ConvertProd(nIndex1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertSum(nIndex2, ptFormula, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes);//y - m_arIndexDst.push_back(m_lIndexDst-1); - //рассчет для swAng--------------------------- - //расположение текущей точки по четвертям 3 4 - // 2 1 - - pCurPoint = oSlice.m_arPoints[j+3]; - pCurPointType = oSlice.m_arPointsType[j+3]; - - nIndex = m_arIndexDst[m_lIndexSrc-6]; - - m_lIndexSrc++; - ConvertSum(pCurPoint.x, pCurPointType.x, 0, ptValue, nIndex-1, ptFormula, false, true, true, m_oGuidsRes); - ConvertSum(pCurPoint.y, pCurPointType.y, 0, ptValue, nIndex, ptFormula, false, true, true, m_oGuidsRes); - ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //угол между Ох и радиус-вектором к точке - nIndex = m_arIndexDst[m_lIndexSrc]; - - m_lIndexSrc++; - ConvertProd(nIndex-2, ptFormula, 1, ptValue, nIndex-3, ptFormula, true, true, true, m_oGuidsRes); - ConvertAt2(1, ptValue, m_lIndexDst-1, ptFormula, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //радиус к точке - nIndex = m_arIndexDst[m_lIndexSrc]; - nIndex1 = m_arIndexDst[m_lIndexSrc-8]; - - m_lIndexSrc++; - ConvertCos(1, ptValue, nIndex, ptFormula, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(nIndex1-2, ptFormula, nIndex1-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - - ConvertSin(1, ptValue, nIndex, ptFormula, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(nIndex1-3, ptFormula, nIndex1-3, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - - ConvertSum(m_lIndexDst-1, ptFormula, m_lIndexDst-5, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); - ConvertSqrt(m_lIndexDst-1, ptFormula, true, m_oGuidsRes); - ConvertProd(nIndex1-3, ptFormula, nIndex1-2, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //если точка во 2 и 3 четвертях, прибавляем по 180grad - nIndex = m_arIndexDst[m_lIndexSrc-2]; - - m_lIndexSrc++; - ConvertIf(nIndex-3, ptFormula, 0, ptValue, 10800000, ptValue, true, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //угол до 2 точки - nIndex = m_arIndexDst[m_lIndexSrc-2];//угол между ох и радиусом - nIndex1 = m_arIndexDst[m_lIndexSrc-3];//расположение точки по четвертям - nIndex2 = m_arIndexDst[m_lIndexSrc];//прибавка 180 или 0 - - m_lIndexSrc++; - ConvertProd(nIndex1-1, ptFormula, nIndex1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//знак у угла - ConvertProd(nIndex, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(nIndex, ptFormula, nIndex, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//угол всегда положительный - - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-3, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//u с нужным знаком - - ConvertSum(m_lIndexDst-1, ptFormula, nIndex2, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //координаты конечной точки - nIndex = m_arIndexDst[m_lIndexSrc-2]; - nIndex1 = m_arIndexDst[m_lIndexSrc-4]; - nIndex2 = m_arIndexDst[m_lIndexSrc-11]; - - m_lIndexSrc++; - ConvertProd(nIndex, ptFormula, nIndex-10, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//r*cos(a) - ConvertProd(nIndex1-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertSum(nIndex2-1, ptFormula, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes);//x - - ConvertProd(nIndex-6, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(nIndex-6, ptFormula, nIndex-6, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//sin теперь всегда>0 - - ConvertProd(nIndex, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//r*sin(a) - ConvertProd(nIndex1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertSum(nIndex2, ptFormula, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes);//y - m_arIndexDst.push_back(m_lIndexDst-1); - //swAngle - nIndex = m_arIndexDst[m_lIndexSrc-1]; //2 угол - nIndex1 = m_arIndexDst[m_lIndexSrc-7]; //1 угол - - m_lIndexSrc++; - ConvertSum(nIndex1, ptFormula, 0, ptValue, nIndex, ptFormula, true, true, true, m_oGuidsRes); // (1)-(2), если отрицательный то берем его, иначе пересчитываем - ConvertProd(m_lIndexDst-1, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); - - ConvertSum(nIndex1, ptFormula, 21600000, ptValue, nIndex, ptFormula, true, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); // -1*((1)+360-(2)) - - ConvertIf(m_lIndexDst-4, ptFormula, m_lIndexDst-3, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes); - - m_arIndexDst.push_back(m_lIndexDst-1); - //wR,hR - nIndex = m_arIndexDst[m_lIndexSrc-14]; - m_lIndexSrc++; - ConvertProd(nIndex-1, ptFormula, 1, ptValue, 2, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(nIndex, ptFormula, 1, ptValue, 2, ptValue, true, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - - //--------------------------------------------------------- - nIndex = m_arIndexDst[m_lIndexSrc-8];//координаты стартовой точки - nIndex1 = m_arIndexDst[m_lIndexSrc-9];//stAng - nIndex2 = m_arIndexDst[m_lIndexSrc-1];//swAng - - if (oSlice.m_eRuler == rtArc && j == 0) - strFrmla = _T("moveTo"); - else - strFrmla = _T("lnTo"); - - if (oSlice.m_eRuler == rtArc && j == 0) - { - m_oPathRes.WriteString(_T("")); - } - else - { - m_oPathRes.WriteString(_T("")); - } - - //старт - /* - LONG nIndex3 = m_arIndexDst[m_lIndexSrc-14]; - strPathRes += _T(""); - */ - - //текущая точка - nIndex = m_arIndexDst[m_lIndexSrc-2]; - ConvertVal(nIndex-5, ptFormula, true, m_oGuidsRes); - ConvertVal(nIndex, ptFormula, true, m_oGuidsRes); - } - } - - void ConvertSlice_ClockwiseTo(const CSlicePath& oSlice) - { - int nCountPoints = oSlice.m_arPoints.size(); - LONG nIndex = 0; - LONG nIndex1 = 0; - LONG nIndex2 = 0; - for (int j = 0; j < nCountPoints; j += 4) - { - pCurPoint = oSlice.m_arPoints[j]; - pCurPointType = oSlice.m_arPointsType[j]; - pCurPoint1 = oSlice.m_arPoints[j+1]; - pCurPointType1 = oSlice.m_arPointsType[j+1]; - - //длина сторон - m_lIndexSrc++; - ConvertSum(pCurPoint1.x, pCurPointType1.x, 0, ptValue, pCurPoint.x, pCurPointType.x, false, true, false, m_oGuidsRes); - ConvertSum(pCurPoint1.y, pCurPointType1.y, 0, ptValue, pCurPoint.y, pCurPointType.y, false, true, false, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //координаты центра - nIndex = m_arIndexDst[m_lIndexSrc]; - - m_lIndexSrc++; - ConvertProd(nIndex-1, ptFormula, 1, ptValue, 2, ptValue, true, true, true, m_oGuidsRes); //a=wR - ConvertProd(nIndex, ptFormula, 1, ptValue, 2, ptValue, true, true, true, m_oGuidsRes); //b=hR - - ConvertSum(pCurPoint.x, pCurPointType.x, m_lIndexDst-2, ptFormula, 0, ptValue, false, true, true, m_oGuidsRes); - ConvertSum(pCurPoint.y, pCurPointType.y, m_lIndexDst-2, ptFormula, 0, ptValue, false, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //рассчет для stAng--------------------------- - //расположение текущей точки по четвертям 3 4 - // 2 1 - - pCurPoint = oSlice.m_arPoints[j+2]; - pCurPointType = oSlice.m_arPointsType[j+2]; - nIndex = m_arIndexDst[m_lIndexSrc]; - - m_lIndexSrc++; - ConvertSum(pCurPoint.x, pCurPointType.x, 0, ptValue, nIndex-1, ptFormula, false, true, true, m_oGuidsRes); - ConvertSum(pCurPoint.y, pCurPointType.y, 0, ptValue, nIndex, ptFormula, false, true, true, m_oGuidsRes); - ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //угол между Ох и радиус-вектором к точке - nIndex = m_arIndexDst[m_lIndexSrc]; - - m_lIndexSrc++; - ConvertProd(nIndex-2, ptFormula, 1, ptValue, nIndex-3, ptFormula, true, true, true, m_oGuidsRes); - ConvertAt2(1, ptValue, m_lIndexDst-1, ptFormula, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //радиус к точке - nIndex = m_arIndexDst[m_lIndexSrc]; - nIndex1 = m_arIndexDst[m_lIndexSrc-2]; - - m_lIndexSrc++; - ConvertCos(1, ptValue, nIndex, ptFormula, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(nIndex1-2, ptFormula, nIndex1-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//(b*cos(u))^2 - - ConvertSin(1, ptValue, nIndex, ptFormula, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(nIndex1-3, ptFormula, nIndex1-3, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//(a*sin(u))^2 - - ConvertSum(m_lIndexDst-1, ptFormula, m_lIndexDst-5, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); - ConvertSqrt(m_lIndexDst-1, ptFormula, true, m_oGuidsRes); - ConvertProd(nIndex1-3, ptFormula, nIndex1-2, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//r - m_arIndexDst.push_back(m_lIndexDst-1); - //если точка во 2 и 3 четвертях, прибавляем по 180grad - nIndex = m_arIndexDst[m_lIndexSrc-2]; - - m_lIndexSrc++; - ConvertIf(nIndex-3, ptFormula, 0, ptValue, 10800000, ptValue, true, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //угол до 1 точки (stAngle) - nIndex = m_arIndexDst[m_lIndexSrc-2];//угол между ох и радиусом - nIndex1 = m_arIndexDst[m_lIndexSrc-3];//расположение точки по четвертям - nIndex2 = m_arIndexDst[m_lIndexSrc];//прибавка 180 или 0 - - m_lIndexSrc++; - ConvertProd(nIndex1-1, ptFormula, nIndex1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//знак у угла - ConvertProd(nIndex, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(nIndex, ptFormula, nIndex, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//угол всегда положительный - - ConvertProd ( m_lIndexDst-1, ptFormula, m_lIndexDst-3, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//u с нужным знаком - - ConvertSum ( m_lIndexDst-1, ptFormula, nIndex2, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //координаты стартовой точки - nIndex = m_arIndexDst[m_lIndexSrc-2]; - nIndex1 = m_arIndexDst[m_lIndexSrc-4]; - nIndex2 = m_arIndexDst[m_lIndexSrc-5]; - - m_lIndexSrc++; - ConvertProd(nIndex, ptFormula, nIndex-10, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//r*cos(a) - ConvertProd(nIndex1-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertSum(nIndex2-1, ptFormula, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); //x - - ConvertProd(nIndex-6, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(nIndex-6, ptFormula, nIndex-6, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//sin теперь всегда>0 - - ConvertProd(nIndex, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//r*sin - ConvertProd(nIndex1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertSum(nIndex2, ptFormula, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes);//y - m_arIndexDst.push_back(m_lIndexDst-1); - //рассчет для swAng--------------------------- - //расположение текущей точки по четвертям 3 4 - // 2 1 - - pCurPoint = oSlice.m_arPoints[j+3]; - pCurPointType = oSlice.m_arPointsType[j+3]; - - nIndex = m_arIndexDst[m_lIndexSrc-6]; - - m_lIndexSrc++; - ConvertSum(pCurPoint.x, pCurPointType.x, 0, ptValue, nIndex-1, ptFormula, false, true, true, m_oGuidsRes); - ConvertSum(pCurPoint.y, pCurPointType.y, 0, ptValue, nIndex, ptFormula, false, true, true, m_oGuidsRes); - ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //угол между Ох и радиус-вектором к точке - nIndex = m_arIndexDst[m_lIndexSrc]; - - m_lIndexSrc++; - ConvertProd(nIndex-2, ptFormula, 1, ptValue, nIndex-3, ptFormula, true, true, true, m_oGuidsRes); - ConvertAt2(1, ptValue, m_lIndexDst-1, ptFormula, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //радиус к точке - nIndex = m_arIndexDst[m_lIndexSrc]; - nIndex1 = m_arIndexDst[m_lIndexSrc-8]; - - m_lIndexSrc++; - ConvertCos(1, ptValue, nIndex, ptFormula, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(nIndex1-2, ptFormula, nIndex1-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - - ConvertSin(1, ptValue, nIndex, ptFormula, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(nIndex1-3, ptFormula, nIndex1-3, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - - ConvertSum(m_lIndexDst-1, ptFormula, m_lIndexDst-5, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); - ConvertSqrt(m_lIndexDst-1, ptFormula, true, m_oGuidsRes); - ConvertProd(nIndex1-3, ptFormula, nIndex1-2, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //если точка во 2 и 3 четвертях, прибавляем по 180grad - nIndex = m_arIndexDst[m_lIndexSrc-2]; - - m_lIndexSrc++; - ConvertIf(nIndex-3, ptFormula, 0, ptValue, 10800000, ptValue, true, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //угол до 2 точки - nIndex = m_arIndexDst[m_lIndexSrc-2];//угол между ох и радиусом - nIndex1 = m_arIndexDst[m_lIndexSrc-3];//расположение точки по четвертям - nIndex2 = m_arIndexDst[m_lIndexSrc];//прибавка 180 или 0 - - m_lIndexSrc ++; - ConvertProd(nIndex1-1, ptFormula, nIndex1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//знак у угла - ConvertProd(nIndex, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(nIndex, ptFormula, nIndex, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//угол всегда положительный - - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-3, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//u с нужным знаком - - ConvertSum(m_lIndexDst-1, ptFormula, nIndex2, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //координаты конечной точки - nIndex = m_arIndexDst[m_lIndexSrc-2]; - nIndex1 = m_arIndexDst[m_lIndexSrc-4]; - nIndex2 = m_arIndexDst[m_lIndexSrc-11]; - - m_lIndexSrc++; - ConvertProd(nIndex, ptFormula, nIndex-10, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//r*cos(a) - ConvertProd(nIndex1-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertSum(nIndex2-1, ptFormula, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes);//x - - ConvertProd(nIndex-6, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(nIndex-6, ptFormula, nIndex-6, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//sin теперь всегда>0 - - ConvertProd(nIndex, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//r*sin(a) - ConvertProd(nIndex1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertSum(nIndex2, ptFormula, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes);//y - m_arIndexDst.push_back(m_lIndexDst-1); - //swAngle - nIndex = m_arIndexDst[m_lIndexSrc-1]; - nIndex1 = m_arIndexDst[m_lIndexSrc-7]; - - m_lIndexSrc++; - ConvertSum(nIndex, ptFormula, 0, ptValue, nIndex1, ptFormula, true, true, true, m_oGuidsRes); - ConvertSum(21600000, ptValue, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(m_lIndexDst-2, ptFormula, m_lIndexDst-2, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//swAng - - m_arIndexDst.push_back(m_lIndexDst-1); - //wR,hR - nIndex = m_arIndexDst[m_lIndexSrc-14]; - m_lIndexSrc++; - ConvertProd(nIndex-1, ptFormula, 1, ptValue, 2, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(nIndex, ptFormula, 1, ptValue, 2, ptValue, true, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - - //--------------------------------------------------------- - nIndex = m_arIndexDst[m_lIndexSrc-8];//координаты стартовой точки - nIndex1 = m_arIndexDst[m_lIndexSrc-9];//stAng - nIndex2 = m_arIndexDst[m_lIndexSrc-1];//swAng - - if (oSlice.m_eRuler == rtClockwiseArc && j == 0) - { - m_oPathRes.WriteString(_T("")); - } - else - { - m_oPathRes.WriteString(_T("")); - } - - //текущая точка - nIndex = m_arIndexDst[m_lIndexSrc-2]; - ConvertVal(nIndex-5, ptFormula, true, m_oGuidsRes); - ConvertVal(nIndex, ptFormula, true, m_oGuidsRes); - } - } - - void ConvertSlice_QuadrBesier(const CSlicePath& oSlice) - { - int nCountPoints = oSlice.m_arPoints.size(); - for (int j = 0; j < nCountPoints; j += 2) - { - int l = nCountPoints - j - 3; - if (l >= 0) - { - m_oPathRes.WriteString(_T("")); - for (int k = 0; k < 2; ++k) - { - pCurPoint = oSlice.m_arPoints[j+k]; - pCurPointType = oSlice.m_arPointsType[j+k]; - - m_oPathRes.WriteString(_T("")); - } - m_oPathRes.WriteString(_T("")); - } - else - { - for (int k = 0; k < nCountPoints - j; ++k) - { - pCurPoint = oSlice.m_arPoints[j+k]; - pCurPointType = oSlice.m_arPointsType[j+k]; - - m_oPathRes.WriteString(_T("")); - } - } - - m_lIndexSrc++; - ConvertVal(pCurPoint.x, pCurPointType.x, false, m_oGuidsRes); - ConvertVal(pCurPoint.y, pCurPointType.y, false, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - } - } - - void ConvertSlice_CurveTo(const CSlicePath& oSlice) - { - int nCountPoints = oSlice.m_arPoints.size(); - LONG nIndex = 0; - for (int j = 0; j < nCountPoints; j += 3) - { - int l = nCountPoints - j - 3; - if ( l>=0 ) - { - m_oPathRes.WriteString(_T("")); - for (int k = 0; k < 3; ++k) - { - pCurPoint = oSlice.m_arPoints[j+k]; - pCurPointType = oSlice.m_arPointsType[j+k]; - - m_oPathRes.WriteString(_T("")); - } - m_oPathRes.WriteString(_T("")); - } - else - { - for (int k=0; k")); - } - } - - m_lIndexSrc++; - ConvertVal(pCurPoint.x, pCurPointType.x, false, m_oGuidsRes); - ConvertVal(pCurPoint.y, pCurPointType.y, false, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - } - } - - void ConvertSlice_RCurveTo(const CSlicePath& oSlice) - { - int nCountPoints = oSlice.m_arPoints.size(); - LONG nIndex = 0; - for (int j = 0; j < nCountPoints; j += 3) - { - nIndex = m_arIndexDst[m_lIndexSrc]; - - int l = nCountPoints - j - 3; - if (l >= 0) - { - m_oPathRes.WriteString(_T("")); - for (int k = 0; k < 3; ++k) - { - pCurPoint = oSlice.m_arPoints[j+k]; - pCurPointType = oSlice.m_arPointsType[j+k]; - - m_lIndexSrc++; - ConvertSum(nIndex-1, ptFormula, pCurPoint.x, pCurPointType.x, 0, ptValue, true, false, true, m_oGuidsRes); - ConvertSum(nIndex, ptFormula, pCurPoint.y, pCurPointType.y, 0, ptValue, true, false, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - - m_oPathRes.WriteString(_T("")); - } - m_oPathRes.WriteString(_T("")); - } - else - { - for (int k=0; k")); - } - } - - nIndex = m_arIndexDst[m_lIndexSrc]; - - m_lIndexSrc++; - ConvertVal(nIndex-1, ptFormula, true, m_oGuidsRes); - ConvertVal(nIndex, ptFormula, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - } - } - - void ConvertSlice_AngleEllipse(const CSlicePath& oSlice) - { - int nCountPoints = oSlice.m_arPoints.size(); - LONG nIndex = 0; - LONG nIndex1 = 0; - LONG nIndex2 = 0; - for (int j = 0; j < nCountPoints; j += 3) - { - pCurPoint = oSlice.m_arPoints[j+1]; - pCurPointType = oSlice.m_arPointsType[j+1]; - pCurPoint1 = oSlice.m_arPoints[j+2]; - pCurPointType1 = oSlice.m_arPointsType[j+2]; - - //конвертация углов в pptx формат - m_lIndexSrc++; - ConvertProd(pCurPoint1.x, pCurPointType1.x, pow3_16, ptValue, m_oParam.m_lParam, m_oParam.m_eType, false, true, true, m_oGuidsRes); //1 угол - ConvertProd(pCurPoint1.y, pCurPointType1.y, pow3_16, ptValue, m_oParam.m_lParam, m_oParam.m_eType, false, true, true, m_oGuidsRes); //2 угол - m_arIndexDst.push_back(m_lIndexDst-1); - - //wR и hR - nIndex = m_arIndexDst[m_lIndexSrc]; - - m_lIndexSrc++; - ConvertVal(pCurPoint.x, pCurPointType.x, false, m_oGuidsRes);//wr=a - ConvertVal(pCurPoint.y, pCurPointType.y, false, m_oGuidsRes);//hr=b - - m_arIndexDst.push_back(m_lIndexDst-1); - - //stAng и swAng - nIndex = m_arIndexDst[m_lIndexSrc-1]; - - m_lIndexSrc++; - ConvertProd(nIndex-1, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); //stAng - ConvertSum(nIndex-1, ptFormula, nIndex, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(nIndex, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes);//swAng - m_arIndexDst.push_back(m_lIndexDst-1); - - //радиус до стартовой точки - - nIndex = m_arIndexDst[m_lIndexSrc]; //stang - nIndex1 = m_arIndexDst[m_lIndexSrc-1]; //wr hr - - m_lIndexSrc++; - ConvertCos(1, ptValue, nIndex-2, ptFormula, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(nIndex1, ptFormula, nIndex1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//(b*cos(u))^2 - - ConvertSin(1, ptValue, nIndex-2, ptFormula, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(nIndex1-1, ptFormula, nIndex1-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//(a*sin(u))^2 - - ConvertSum(m_lIndexDst-1, ptFormula, m_lIndexDst-5, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); - ConvertSqrt(m_lIndexDst-1, ptFormula, true, m_oGuidsRes); - ConvertProd(nIndex1, ptFormula, nIndex1-1, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//r - m_arIndexDst.push_back(m_lIndexDst-1); - - //координаты конечной точки (она же начальная для эллипса) - - pCurPoint1 = oSlice.m_arPoints[j];//коорд центра - pCurPointType1 = oSlice.m_arPointsType[j]; - - nIndex = m_arIndexDst[m_lIndexSrc-1]; //stang - nIndex1 = m_arIndexDst[m_lIndexSrc]; //r - - m_lIndexSrc++; - - ConvertProd(nIndex1, ptFormula, nIndex1-10, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); //r*cos - ConvertSum(pCurPoint1.x, pCurPointType1.x, m_lIndexDst-1, ptFormula, 0, ptValue, false, true, true, m_oGuidsRes);//x - - ConvertProd(nIndex1, ptFormula, nIndex1-6, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);// r*sin - ConvertSum(pCurPoint1.y, pCurPointType1.y, m_lIndexDst-1, ptFormula, 0, ptValue, false, true, true, m_oGuidsRes);//y - m_arIndexDst.push_back(m_lIndexDst-1); - //--------------------- - - nIndex = m_arIndexDst[m_lIndexSrc];//текущая точка - nIndex1 = m_arIndexDst[m_lIndexSrc-2];//stAng и swAng - nIndex2 = m_arIndexDst[m_lIndexSrc-3];//wR и hR - - if (j == 0) - strFrmla = _T("moveTo"); - else - strFrmla = _T("lnTo"); - - if (j == 0) - { - m_oPathRes.WriteString(_T("")); - } - else - { - m_oPathRes.WriteString(_T("")); - } - - //текущая точка - - nIndex = m_arIndexDst[m_lIndexSrc]; - - m_lIndexSrc++; - ConvertVal(nIndex-2, ptFormula, true, m_oGuidsRes); - ConvertVal(nIndex, ptFormula, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - } - } - - void ConvertSlice_EllipticalQuadrX(const CSlicePath& oSlice) - { - int nCountPoints = oSlice.m_arPoints.size(); - for (int j = 0; j < nCountPoints; j += 2) - { - pCurPoint = oSlice.m_arPoints[j]; - pCurPointType = oSlice.m_arPointsType[j]; - ConvertQuadrX(pCurPoint, pCurPointType); - - if (j+1 < nCountPoints) - { - pCurPoint1 = oSlice.m_arPoints[j+1]; - pCurPointType1 = oSlice.m_arPointsType[j+1]; - ConvertQuadrY(pCurPoint1, pCurPointType1); - } - } - } - - void ConvertSlice_EllipticalQuadrY(const CSlicePath& oSlice) - { - int nCountPoints = oSlice.m_arPoints.size(); - for (int j = 0; j < nCountPoints; j += 2) - { - pCurPoint = oSlice.m_arPoints[j]; - pCurPointType = oSlice.m_arPointsType[j]; - ConvertQuadrY(pCurPoint, pCurPointType); - - if (j+1 < nCountPoints) - { - pCurPoint1 = oSlice.m_arPoints[j+1]; - pCurPointType1 = oSlice.m_arPointsType[j+1]; - ConvertQuadrX(pCurPoint1, pCurPointType1); - } - } - } + void ConvertSlice_MoveTo(const CSlicePath& oSlice); + void ConvertSlice_RMoveTo(const CSlicePath& oSlice); + void ConvertSlice_LineTo(const CSlicePath& oSlice); + void ConvertSlice_RLineTo(const CSlicePath& oSlice); + void ConvertSlice_ArcTo(const CSlicePath& oSlice); + void ConvertSlice_ClockwiseTo(const CSlicePath& oSlice); + void ConvertSlice_QuadrBesier(const CSlicePath& oSlice); + void ConvertSlice_CurveTo(const CSlicePath& oSlice); + void ConvertSlice_RCurveTo(const CSlicePath& oSlice); + void ConvertSlice_AngleEllipse(const CSlicePath& oSlice); + void ConvertSlice_EllipticalQuadrX(const CSlicePath& oSlice); + void ConvertSlice_EllipticalQuadrY(const CSlicePath& oSlice); }; } diff --git a/MsBinaryFile/Common/ODraw/FormulaShape.cpp b/MsBinaryFile/Common/ODraw/FormulaShape.cpp index c65d85af79..4cd698ba71 100644 --- a/MsBinaryFile/Common/ODraw/FormulaShape.cpp +++ b/MsBinaryFile/Common/ODraw/FormulaShape.cpp @@ -33,134 +33,267 @@ #include "FormulaShape.h" -LONG NSCustomShapesConvert::CFormula::CalculateFormula(NSCustomShapesConvert::CFormulasManager* pManager) +namespace NSCustomShapesConvert { - if ((0 > m_lIndex) || (m_lIndex >= pManager->m_arResults.size())) - return 0; - if (0xFFFFFFFF != pManager->m_arResults[m_lIndex]) + CFormula::CFormula() { - return pManager->m_arResults[m_lIndex]; - } - - LONG lResult = 0; + m_eFormulaType = ftSum; + m_lIndex = 0; + m_lParam1 = 0; m_eType1 = ptValue; + m_lParam2 = 0; m_eType2 = ptValue; + m_lParam3 = 0; m_eType3 = ptValue; - LONG lGuidesCount = pManager->m_arFormulas.size(); - LONG lAdjCount = pManager->m_pAdjustments->size(); - - LONG a1 = m_lParam1; - if (ptFormula == m_eType1) - { - a1 = (m_lParam1 >= lGuidesCount) ? 0 : pManager->m_arFormulas[m_lParam1].CalculateFormula(pManager); + m_lCountRecurs = 0; } - else if (ptAdjust == m_eType1) + CFormula::CFormula(int nIndex) { - a1 = (m_lParam1 >= lAdjCount) ? 0 : (*(pManager->m_pAdjustments))[m_lParam1]; - } + m_eFormulaType = ftSum; + m_lIndex = nIndex; + m_lParam1 = 0; m_eType1 = ptValue; + m_lParam2 = 0; m_eType2 = ptValue; + m_lParam3 = 0; m_eType3 = ptValue; - LONG b1 = m_lParam2; - if (ptFormula == m_eType2) - { - b1 = (m_lParam2 >= lGuidesCount) ? 0 : pManager->m_arFormulas[m_lParam2].CalculateFormula(pManager); + m_lCountRecurs = 0; } - else if (ptAdjust == m_eType2) + CFormula& CFormula::operator =(const CFormula& oSrc) { - b1 = (m_lParam2 >= lAdjCount) ? 0 : (*(pManager->m_pAdjustments))[m_lParam2]; + m_eFormulaType = oSrc.m_eFormulaType; + m_lIndex = oSrc.m_lIndex; + + m_lParam1 = oSrc.m_lParam1; + m_eType1 = oSrc.m_eType1; + + m_lParam2 = oSrc.m_lParam2; + m_eType2 = oSrc.m_eType2; + + m_lParam3 = oSrc.m_lParam3; + m_eType3 = oSrc.m_eType3; + + m_lCountRecurs = 0; + return (*this); } - - LONG c1 = m_lParam3; - if (ptFormula == m_eType3) + void CFormula::FromString(std::wstring strFormula, long lShapeWidth, long lShapeHeight) { - c1 = (m_lParam3 >= lGuidesCount) ? 0 : pManager->m_arFormulas[m_lParam3].CalculateFormula(pManager); - } - else if (ptAdjust == m_eType3) - { - c1 = (m_lParam3 >= lAdjCount) ? 0 : (*(pManager->m_pAdjustments))[m_lParam3]; - } + std::vector oArrayParams; + NSStringUtils::ParseString(_T(" "), strFormula, oArrayParams); + size_t nCount = oArrayParams.size(); + if (nCount == 0) + return; - double a = (double)a1; - double b = (double)b1; - double c = (double)c1; + bool bRes = true; + m_eFormulaType = GetFormula(oArrayParams[0], bRes); - double dRes = 0.0; - - try - { - // теперь нужно просто посчитать - switch (m_eFormulaType) + ParamType ptType = ptValue; + if (1 < nCount) { - case ftSum: { dRes = a + b - c; break; } - case ftProduct: { - if (0 == c) - c = 1; - - dRes = a * b / c; - break; - } - case ftMid: { dRes = (a + b) / 2.0; break; } - case ftAbsolute: { dRes = abs(a); break; } - - case ftMin: { dRes = (std::min)(a, b); break; } - case ftMax: { dRes = (std::max)(a, b); break; } - case ftIf: { dRes = (a > 0) ? b : c; break; } - case ftSqrt: { dRes = sqrt(a); break; } - case ftMod: { dRes = sqrt(a*a + b*b + c*c); break; } - - case ftSin: { - //dRes = a * sin(b); - //dRes = a * sin(b / pow2_16); - dRes = a * sin(M_PI * b / (pow2_16 * 180)); - break; - } - case ftCos: { - //dRes = a * cos(b); - //dRes = a * cos(b / pow2_16); - dRes = a * cos(M_PI * b / (pow2_16 * 180)); - break; - } - case ftTan: { - //dRes = a * tan(b); - dRes = a * tan(M_PI * b / (pow2_16 * 180)); - break; - } - case ftAtan2: { - dRes = 180 * pow2_16 * atan2(b,a) / M_PI; - break; - } - - case ftSinatan2: { dRes = a * sin(atan2(c,b)); break; } - case ftCosatan2: { dRes = a * cos(atan2(c,b)); break; } - - case ftSumangle: { - //dRes = a + b - c; - dRes = a + b * pow2_16 - c * pow2_16; - - /*while (23592960 < dRes) - { - dRes -= 23592960; - } - while (-23592960 > dRes) - { - dRes += 23592960; - }*/ - - break; - } - case ftEllipse: { - if (0 == b) - b = 1; - dRes = c * sqrt(1-(a*a/(b*b))); - break; - } - case ftVal: { dRes = a; break; } - default: break; - }; + m_lParam1 = GetValue(oArrayParams[1], ptType, bRes, lShapeWidth, lShapeHeight); + m_eType1 = ptType; + } + if (2 < nCount) + { + m_lParam2 = GetValue(oArrayParams[2], ptType, bRes, lShapeWidth, lShapeHeight); + m_eType2 = ptType; + } + if (3 < nCount) + { + m_lParam3 = GetValue(oArrayParams[3], ptType, bRes, lShapeWidth, lShapeHeight); + m_eType3 = ptType; + } } - catch (...) + LONG CFormula::CalculateFormula(NSCustomShapesConvert::CFormulasManager* pManager) { - dRes = 0; + if ((0 > m_lIndex) || (m_lIndex >= pManager->m_arResults.size())) + return 0; + if (0xFFFFFFFF != pManager->m_arResults[m_lIndex]) + { + return pManager->m_arResults[m_lIndex]; + } + + LONG lResult = 0; + + LONG lGuidesCount = pManager->m_arFormulas.size(); + LONG lAdjCount = pManager->m_pAdjustments->size(); + + LONG a1 = m_lParam1; + if (ptFormula == m_eType1) + { + a1 = (m_lParam1 >= lGuidesCount) ? 0 : pManager->m_arFormulas[m_lParam1].CalculateFormula(pManager); + } + else if (ptAdjust == m_eType1) + { + a1 = (m_lParam1 >= lAdjCount) ? 0 : (*(pManager->m_pAdjustments))[m_lParam1]; + } + + LONG b1 = m_lParam2; + if (ptFormula == m_eType2) + { + b1 = (m_lParam2 >= lGuidesCount) ? 0 : pManager->m_arFormulas[m_lParam2].CalculateFormula(pManager); + } + else if (ptAdjust == m_eType2) + { + b1 = (m_lParam2 >= lAdjCount) ? 0 : (*(pManager->m_pAdjustments))[m_lParam2]; + } + + LONG c1 = m_lParam3; + if (ptFormula == m_eType3) + { + c1 = (m_lParam3 >= lGuidesCount) ? 0 : pManager->m_arFormulas[m_lParam3].CalculateFormula(pManager); + } + else if (ptAdjust == m_eType3) + { + c1 = (m_lParam3 >= lAdjCount) ? 0 : (*(pManager->m_pAdjustments))[m_lParam3]; + } + + double a = (double)a1; + double b = (double)b1; + double c = (double)c1; + + double dRes = 0.0; + + try + { + // теперь нужно просто посчитать + switch (m_eFormulaType) + { + case ftSum: { dRes = a + b - c; break; } + case ftProduct: { + if (0 == c) + c = 1; + + dRes = a * b / c; + break; + } + case ftMid: { dRes = (a + b) / 2.0; break; } + case ftAbsolute: { dRes = abs(a); break; } + + case ftMin: { dRes = (std::min)(a, b); break; } + case ftMax: { dRes = (std::max)(a, b); break; } + case ftIf: { dRes = (a > 0) ? b : c; break; } + case ftSqrt: { dRes = sqrt(a); break; } + case ftMod: { dRes = sqrt(a*a + b*b + c*c); break; } + + case ftSin: { + //dRes = a * sin(b); + //dRes = a * sin(b / pow2_16); + dRes = a * sin(M_PI * b / (pow2_16 * 180)); + break; + } + case ftCos: { + //dRes = a * cos(b); + //dRes = a * cos(b / pow2_16); + dRes = a * cos(M_PI * b / (pow2_16 * 180)); + break; + } + case ftTan: { + //dRes = a * tan(b); + dRes = a * tan(M_PI * b / (pow2_16 * 180)); + break; + } + case ftAtan2: { + dRes = 180 * pow2_16 * atan2(b,a) / M_PI; + break; + } + + case ftSinatan2: { dRes = a * sin(atan2(c,b)); break; } + case ftCosatan2: { dRes = a * cos(atan2(c,b)); break; } + + case ftSumangle: { + //dRes = a + b - c; + dRes = a + b * pow2_16 - c * pow2_16; + + /*while (23592960 < dRes) + { + dRes -= 23592960; + } + while (-23592960 > dRes) + { + dRes += 23592960; + }*/ + + break; + } + case ftEllipse: { + if (0 == b) + b = 1; + dRes = c * sqrt(1-(a*a/(b*b))); + break; + } + case ftVal: { dRes = a; break; } + default: break; + }; + } + catch (...) + { + dRes = 0; + } + + lResult = (LONG)dRes; + pManager->m_arResults[m_lIndex] = lResult; + return lResult; } - lResult = (LONG)dRes; - pManager->m_arResults[m_lIndex] = lResult; - return lResult; + CFormulasManager::CFormulasManager() : m_arFormulas(), m_arResults() + { + m_pAdjustments = NULL; + m_lShapeWidth = ShapeSizeVML; + m_lShapeHeight = ShapeSizeVML; + } + CFormulasManager& CFormulasManager::operator =(const CFormulasManager& oSrc) + { + m_pAdjustments = oSrc.m_pAdjustments; + m_lShapeWidth = oSrc.m_lShapeWidth; + m_lShapeHeight = oSrc.m_lShapeHeight; + + m_arResults.clear(); + for (size_t nIndex = 0; nIndex < oSrc.m_arResults.size(); ++nIndex) + { + m_arResults.push_back(oSrc.m_arResults[nIndex]); + } + m_arFormulas.clear(); + for (size_t nIndex = 0; nIndex < oSrc.m_arFormulas.size(); ++nIndex) + { + m_arFormulas.push_back(oSrc.m_arFormulas[nIndex]); + } + + return (*this); + } + void CFormulasManager::Clear() + { + m_pAdjustments = NULL; + + + m_arFormulas.clear(); + m_arResults.clear(); + } + void CFormulasManager::Clear(std::vector* pAdjusts) + { + m_pAdjustments = pAdjusts; + + //m_arFormulas.clear(); + //m_arResults.clear(); + for (size_t nIndex = 0; nIndex < m_arResults.size(); ++nIndex) + { + m_arResults[nIndex] = 0xFFFFFFFF; + } + } + void CFormulasManager::AddFormula(std::wstring strFormula) + { + CFormula oFormula((int)m_arFormulas.size()); + oFormula.FromString(strFormula, m_lShapeWidth, m_lShapeHeight); + m_arFormulas.push_back(oFormula); + m_arResults.push_back(0xFFFFFFFF); + } + void CFormulasManager::AddFormula(CFormula oFormula) + { + oFormula.m_lIndex = (int)m_arFormulas.size(); + m_arFormulas.push_back(oFormula); + m_arResults.push_back(0xFFFFFFFF); + } + void CFormulasManager::CalculateResults() + { + for (size_t index = 0; index < m_arFormulas.size(); ++index) + { + LONG lResult = m_arFormulas[index].CalculateFormula(this); + } + } } diff --git a/MsBinaryFile/Common/ODraw/FormulaShape.h b/MsBinaryFile/Common/ODraw/FormulaShape.h index c72954dac7..ccc6c3d4ca 100644 --- a/MsBinaryFile/Common/ODraw/FormulaShape.h +++ b/MsBinaryFile/Common/ODraw/FormulaShape.h @@ -214,27 +214,26 @@ namespace NSCustomShapesConvert struct SHandle { - Aggplus::POINT gdRef; - SPointType gdRefType; - SPointExist bRefExist; - SPointExist bRefPolarExist; + Aggplus::POINT gdRef; + SPointType gdRefType; + SPointExist bRefExist; + SPointExist bRefPolarExist; - Aggplus::POINT Max; - SPointType MaxType; - SPointExist bMaxExist; - SPointExist bMaxPolarExist; + Aggplus::POINT Max; + SPointType MaxType; + SPointExist bMaxExist; + SPointExist bMaxPolarExist; - Aggplus::POINT Min; - SPointType MinType; - SPointExist bMinExist; - SPointExist bMinPolarExist; + Aggplus::POINT Min; + SPointType MinType; + SPointExist bMinExist; + SPointExist bMinPolarExist; - Aggplus::POINT Pos; - SPointType PosType; - - Aggplus::POINT PolarCentre; - SPointType PolarCentreType; + Aggplus::POINT Pos; + SPointType PosType; + Aggplus::POINT PolarCentre; + SPointType PolarCentreType; }; class CFormulasManager; class CFormula @@ -256,74 +255,12 @@ private: long m_lCountRecurs; public: - CFormula() - { - m_eFormulaType = ftSum; - m_lIndex = 0; - m_lParam1 = 0; m_eType1 = ptValue; - m_lParam2 = 0; m_eType2 = ptValue; - m_lParam3 = 0; m_eType3 = ptValue; + CFormula(); + CFormula(int nIndex); - m_lCountRecurs = 0; - } + CFormula& operator =(const CFormula& oSrc); - CFormula(int nIndex) - { - m_eFormulaType = ftSum; - m_lIndex = nIndex; - m_lParam1 = 0; m_eType1 = ptValue; - m_lParam2 = 0; m_eType2 = ptValue; - m_lParam3 = 0; m_eType3 = ptValue; - - m_lCountRecurs = 0; - } - - CFormula& operator =(const CFormula& oSrc) - { - m_eFormulaType = oSrc.m_eFormulaType; - m_lIndex = oSrc.m_lIndex; - - m_lParam1 = oSrc.m_lParam1; - m_eType1 = oSrc.m_eType1; - - m_lParam2 = oSrc.m_lParam2; - m_eType2 = oSrc.m_eType2; - - m_lParam3 = oSrc.m_lParam3; - m_eType3 = oSrc.m_eType3; - - m_lCountRecurs = 0; - return (*this); - } - - void FromString(std::wstring strFormula, long lShapeWidth = ShapeSizeVML, long lShapeHeight = ShapeSizeVML) - { - std::vector oArrayParams; - NSStringUtils::ParseString(_T(" "), strFormula, oArrayParams); - size_t nCount = oArrayParams.size(); - if (nCount == 0) - return; - - bool bRes = true; - m_eFormulaType = GetFormula(oArrayParams[0], bRes); - - ParamType ptType = ptValue; - if (1 < nCount) - { - m_lParam1 = GetValue(oArrayParams[1], ptType, bRes, lShapeWidth, lShapeHeight); - m_eType1 = ptType; - } - if (2 < nCount) - { - m_lParam2 = GetValue(oArrayParams[2], ptType, bRes, lShapeWidth, lShapeHeight); - m_eType2 = ptType; - } - if (3 < nCount) - { - m_lParam3 = GetValue(oArrayParams[3], ptType, bRes, lShapeWidth, lShapeHeight); - m_eType3 = ptType; - } - } + void FromString(std::wstring strFormula, long lShapeWidth = ShapeSizeVML, long lShapeHeight = ShapeSizeVML); LONG CalculateFormula(CFormulasManager* pManager); }; @@ -339,71 +276,15 @@ private: long m_lShapeHeight; public: - CFormulasManager() : m_arFormulas(), m_arResults() - { - m_pAdjustments = NULL; - m_lShapeWidth = ShapeSizeVML; - m_lShapeHeight = ShapeSizeVML; - } - CFormulasManager& operator =(const CFormulasManager& oSrc) - { - m_pAdjustments = oSrc.m_pAdjustments; - m_lShapeWidth = oSrc.m_lShapeWidth; - m_lShapeHeight = oSrc.m_lShapeHeight; + CFormulasManager(); + CFormulasManager& operator =(const CFormulasManager& oSrc); - m_arResults.clear(); - for (size_t nIndex = 0; nIndex < oSrc.m_arResults.size(); ++nIndex) - { - m_arResults.push_back(oSrc.m_arResults[nIndex]); - } - m_arFormulas.clear(); - for (size_t nIndex = 0; nIndex < oSrc.m_arFormulas.size(); ++nIndex) - { - m_arFormulas.push_back(oSrc.m_arFormulas[nIndex]); - } - - return (*this); - } + void Clear(); + void Clear(std::vector* pAdjusts); - void Clear() - { - m_pAdjustments = NULL; + void AddFormula(std::wstring strFormula); + void AddFormula(CFormula oFormula); - - m_arFormulas.clear(); - m_arResults.clear(); - } - - void Clear(std::vector* pAdjusts) - { - m_pAdjustments = pAdjusts; - - //m_arFormulas.clear(); - //m_arResults.clear(); - for (size_t nIndex = 0; nIndex < m_arResults.size(); ++nIndex) - { - m_arResults[nIndex] = 0xFFFFFFFF; - } - } - void AddFormula(std::wstring strFormula) - { - CFormula oFormula((int)m_arFormulas.size()); - oFormula.FromString(strFormula, m_lShapeWidth, m_lShapeHeight); - m_arFormulas.push_back(oFormula); - m_arResults.push_back(0xFFFFFFFF); - } - void AddFormula(CFormula oFormula) - { - oFormula.m_lIndex = (int)m_arFormulas.size(); - m_arFormulas.push_back(oFormula); - m_arResults.push_back(0xFFFFFFFF); - } - void CalculateResults() - { - for (size_t index = 0; index < m_arFormulas.size(); ++index) - { - LONG lResult = m_arFormulas[index].CalculateFormula(this); - } - } + void CalculateResults(); }; } diff --git a/MsBinaryFile/Common/ODraw/GraphicsPath.cpp b/MsBinaryFile/Common/ODraw/GraphicsPath.cpp new file mode 100644 index 0000000000..bf65690f7d --- /dev/null +++ b/MsBinaryFile/Common/ODraw/GraphicsPath.cpp @@ -0,0 +1,702 @@ +/* + * (c) Copyright Ascensio System SIA 2010-2019 + * + * 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 20A-12 Ernesta Birznieka-Upisha + * street, Riga, Latvia, EU, LV-1050. + * + * 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 "GraphicsPath.h" + +namespace NSCustomShapesConvert +{ + CDoubleRect::CDoubleRect() + { + left = 0; + top = 0; + right = 0; + bottom = 0; + } + CDoubleRect& CDoubleRect::operator=(const CDoubleRect& oSrc) + { + left = oSrc.left; + top = oSrc.top; + right = oSrc.right; + bottom = oSrc.bottom; + + return *this; + } + CDoubleRect::CDoubleRect(const CDoubleRect& oSrc) + { + *this = oSrc; + } + + CGeomShapeInfo::CPointD::CPointD() + { + dX = 0; + dY = 0; + } + CGeomShapeInfo::CPointD& CGeomShapeInfo::CPointD::operator= (const CPointD& oSrc) + { + dX = oSrc.dX; + dY = oSrc.dY; + + return *this; + } + CGeomShapeInfo::CPointD::CPointD(const CPointD& oSrc) + { + *this = oSrc; + } + + CGeomShapeInfo::CGeomShapeInfo() + { + m_dLeft = 0; + m_dTop = 0; + m_dWidth = 720; + m_dHeight = 576; + + m_dLimoX = 0; + m_dLimoY = 0; + + m_oCurPoint.dX = 0; + m_oCurPoint.dY = 0; + + m_dRotate = 0.0; + m_bFlipH = false; + m_bFlipV = false; + + m_lOriginalWidth = 0; + m_lOriginalHeight = 0; + } + CGeomShapeInfo::~CGeomShapeInfo() + { + } + CGeomShapeInfo& CGeomShapeInfo::operator =(const CGeomShapeInfo& oSrc) + { + m_dLeft = oSrc.m_dLeft; + m_dTop = oSrc.m_dTop; + m_dWidth = oSrc.m_dWidth; + m_dHeight = oSrc.m_dHeight; + + m_dLimoX = oSrc.m_dLimoX; + m_dLimoY = oSrc.m_dLimoY; + + m_oCurPoint = oSrc.m_oCurPoint; + + m_dRotate = oSrc.m_dRotate; + m_bFlipH = oSrc.m_bFlipH; + m_bFlipV = oSrc.m_bFlipV; + + m_lOriginalWidth = oSrc.m_lOriginalWidth; + m_lOriginalHeight = oSrc.m_lOriginalHeight; + + return (*this); + } + + CDoublePoint::CDoublePoint() + { + dX = 0; + dY = 0; + } + CDoublePoint& CDoublePoint::operator= (const CDoublePoint& oSrc) + { + dX = oSrc.dX; + dY = oSrc.dY; + + return *this; + } + CDoublePoint::CDoublePoint(const CDoublePoint& oSrc) + { + *this = oSrc; + } + + void CGraphicPath::InternalClear() + { + m_lFlags = 0; + } + CGraphicPath::CGraphicPath() + { + InternalClear(); + } + + CGraphicPath::CPart::CPart() : m_eType(rtMoveTo), m_arPoints() + { + } + CGraphicPath::CPart& CGraphicPath::CPart::operator=(const CPart& oSrc) + { + m_eType = oSrc.m_eType; + this->m_arPoints.clear(); + for (size_t nIndex = 0; nIndex < oSrc.m_arPoints.size(); ++nIndex) + { + this->m_arPoints.push_back(oSrc.m_arPoints[nIndex]); + } + return (*this); + } + CGraphicPath::CPart::~CPart() + { + this->m_arPoints.clear(); + } + + void CGraphicPath::CPart::ParseString(std::wstring strDelimeters, std::wstring strSource, + std::vector& pArrayResults, bool bIsCleared) + { + if (bIsCleared) + pArrayResults.clear(); + + std::wstring resToken; + int curPos= 0; + + boost::algorithm::split(pArrayResults, strSource, boost::algorithm::is_any_of(strDelimeters), boost::algorithm::token_compress_on); + + } + + void CGraphicPath::CPart::CheckLastPoint(IRenderer* pRenderer, CDoublePoint& pointCur) + { + if (NULL == pRenderer) + return; + + pRenderer->PathCommandGetCurrentPoint(&pointCur.dX, &pointCur.dY); + } + double CGraphicPath::CPart::GetAngle(double fCentreX, double fCentreY, double fX, double fY) + { + // - + (.. ) + double dX = fX - fCentreX; + double dY = fY - fCentreY; + + double modDX = abs(dX); + double modDY = abs(dY); + + if ((modDX < 0.01) && (modDY < 0.01)) + { + return 0; + } + if ((modDX < 0.01) && (dY < 0)) + { + return -90; + } + else if (modDX < 0.01) + { + return 90; + } + if ((modDY < 0.01) && (dX < 0)) + { + return 180; + } + else if (modDY < 0.01) + { + return 0; + } + + double fAngle = atan(dY / dX); + fAngle *= double(180 / M_PI); + if (dX > 0 && dY > 0) + { + return fAngle; + } + else if (dX > 0 && dY < 0) + { + return fAngle; + } + else if (dX < 0 && dY > 0) + { + //return fAngle + 180; + return 180 + fAngle; + } + else + { + //return fAngle + 180; + return fAngle - 180; + } + } + + void CGraphicPath::CPart::ApplyElliptical(bool& bIsX, double& angleStart, double& angleSweet, + double& Left, double& Top, double& Width, double& Height, const CDoublePoint& pointCur) + { + // (x - y - x...) + if (bIsX) + { + angleStart = -90; + angleSweet = 90; + + if ((Width < 0) && (Height < 0)) + { + angleStart = 90; + Width *= -1; + Height *= -1; + Left = pointCur.dX - Width / 2; + Top = pointCur.dY - Height; + } + else if ((Width < 0) && (Height > 0)) + { + angleStart = -90; + angleSweet = -90; + Width *= -1; + Left = pointCur.dX - Width / 2; + Top = pointCur.dY; + } + else if ((Width > 0) && (Height < 0)) + { + angleStart = 90; + angleSweet = -90; + Height *= -1; + Left = pointCur.dX - Width / 2; + Top = pointCur.dY - Height; + } + else + { + Left = pointCur.dX - Width / 2; + Top = pointCur.dY; + } + } + else + { + angleStart = 180; + angleSweet = -90; + + if ((Width < 0) && (Height < 0)) + { + angleStart = 0; + Width *= -1; + Height *= -1; + Left = pointCur.dX - Width; + Top = pointCur.dY - Height / 2; + } + else if ((Width < 0) && (Height > 0)) + { + angleStart = 0; + angleSweet = 90; + Width *= -1; + Left = pointCur.dX - Width; + Top = pointCur.dY - Height / 2; + } + else if ((Width > 0) && (Height < 0)) + { + angleStart = 180; + angleSweet = 90; + Height *= -1; + Left = pointCur.dX; + Top = pointCur.dY - Height / 2; + } + else + { + Left = pointCur.dX; + Top = pointCur.dY - Height / 2; + } + } + bIsX = !bIsX; + } + + void CGraphicPath::CPart::GetSafearrayPoints(IRenderer* pRenderer, double** ppArray, size_t& nCountOut, CDoublePoint& pointCur, bool bR) + { + if (NULL == ppArray) + return; + + size_t nCount = this->m_arPoints.size(); + + nCountOut = 2 * (nCount + 1); + + double* pArray = new double [nCountOut]; + double* pBuffer = pArray; + + memset (pBuffer, 0, nCountOut * sizeof(double)); + + *pBuffer = pointCur.dX; ++pBuffer; + *pBuffer = pointCur.dY; ++pBuffer; + + if (bR) + { + for (size_t nIndex = 0; nIndex < nCount; ++nIndex) + { + *pBuffer = (this->m_arPoints[nIndex].dX + pointCur.dX); ++pBuffer; + *pBuffer = (this->m_arPoints[nIndex].dY + pointCur.dY); ++pBuffer; + + if (nIndex == (nCount - 1)) + { + pointCur.dX += this->m_arPoints[nIndex].dX; + pointCur.dY += this->m_arPoints[nIndex].dY; + } + } + } + else + { + for (size_t nIndex = 0; nIndex < nCount; ++nIndex) + { + *pBuffer = this->m_arPoints[nIndex].dX; ++pBuffer; + *pBuffer = this->m_arPoints[nIndex].dY; ++pBuffer; + + if (nIndex == (nCount - 1)) + { + pointCur.dX = this->m_arPoints[nIndex].dX; + pointCur.dY = this->m_arPoints[nIndex].dY; + } + } + } + *ppArray = pArray; + + } + + void CGraphicPath::CPart::Draw(IRenderer* pRenderer, CDoublePoint& pointCur) + { + switch (m_eType) + { + case rtMoveTo: + { + if (0 < this->m_arPoints.size()) + { + pointCur.dX = this->m_arPoints[0].dX; + pointCur.dY = this->m_arPoints[0].dY; + pRenderer->PathCommandMoveTo(this->m_arPoints[0].dX, this->m_arPoints[0].dY); + } + break; + } + case rtLineTo: + { + double* pArray = NULL; + size_t nCount = 0; + GetSafearrayPoints(pRenderer, &pArray, nCount, pointCur); + + if (NULL != pArray) + { + pRenderer->PathCommandLinesTo(pArray, (int)nCount /*this->m_arPoints.size()*/); + } + + break; + } + case rtCurveTo: + { + double* pArray = NULL; + size_t nCount = 0; + GetSafearrayPoints(pRenderer, &pArray, nCount, pointCur); + + if (NULL != pArray) + { + pRenderer->PathCommandCurvesTo (pArray, (int)nCount/*this->m_arPoints.size()*/); + } + + break; + } + case rtClose: + { + pRenderer->PathCommandClose(); + break; + } + case rtRMoveTo: + { + if (0 < this->m_arPoints.size()) + { + pointCur.dX = this->m_arPoints[0].dX + pointCur.dX; + pointCur.dY = this->m_arPoints[0].dY + pointCur.dY; + pRenderer->PathCommandMoveTo(pointCur.dX, pointCur.dY); + } + break; + } + case rtRLineTo: + { + double* pArray = NULL; + size_t nCount = 0; + GetSafearrayPoints(pRenderer, &pArray, nCount, pointCur, TRUE); + + if (NULL != pArray) + { + pRenderer->PathCommandLinesTo(pArray, (int)nCount/*this->m_arPoints.size()*/); + } + + break; + } + case rtRCurveTo: + { + double* pArray = NULL; + size_t nCount = 0; + GetSafearrayPoints(pRenderer, &pArray, nCount, pointCur, TRUE); + + if (NULL != pArray) + { + pRenderer->PathCommandCurvesTo(pArray, (int)nCount/*this->m_arPoints.size()*/); + } + break; + } + case rtAngleEllipseTo: + { + int nFigure = 0; + while ((nFigure + 3) <= (int)this->m_arPoints.size()) + { + double nLeft = this->m_arPoints[nFigure].dX - this->m_arPoints[nFigure + 1].dX / 2; + double nTop = this->m_arPoints[nFigure].dY - this->m_arPoints[nFigure + 1].dY / 2; + + pRenderer->PathCommandArcTo(nLeft, nTop, + this->m_arPoints[nFigure + 1].dX, this->m_arPoints[nFigure + 1].dY, + this->m_arPoints[nFigure + 2].dX, this->m_arPoints[nFigure + 2].dY); + + nFigure += 3; + } + + CheckLastPoint(pRenderer, pointCur); + break; + } + case rtAngleEllipse: + { + pRenderer->PathCommandStart(); + int nFigure = 0; + while ((nFigure + 3) <= (int)this->m_arPoints.size()) + { + double nLeft = this->m_arPoints[nFigure].dX - this->m_arPoints[nFigure + 1].dX / 2; + double nTop = this->m_arPoints[nFigure].dY - this->m_arPoints[nFigure + 1].dY / 2; + + pRenderer->PathCommandArcTo(nLeft, nTop, + this->m_arPoints[nFigure + 1].dX, this->m_arPoints[nFigure + 1].dY, + this->m_arPoints[nFigure + 2].dX, this->m_arPoints[nFigure + 2].dY); + + nFigure += 3; + } + + CheckLastPoint(pRenderer, pointCur); + break; + } + case rtArc: + { + pRenderer->PathCommandStart(); + int nFigure = 0; + while ((nFigure + 4) <= (int)this->m_arPoints.size()) + { + double nCentreX = (this->m_arPoints[nFigure].dX + this->m_arPoints[nFigure + 1].dX) / 2; + double nCentreY = (this->m_arPoints[nFigure].dY + this->m_arPoints[nFigure + 1].dY) / 2; + + double angleStart = GetAngle(nCentreX, nCentreY, + this->m_arPoints[nFigure + 2].dX, this->m_arPoints[nFigure + 2].dY); + + double angleEnd = GetAngle(nCentreX, nCentreY, + this->m_arPoints[nFigure + 3].dX, this->m_arPoints[nFigure + 3].dY); + + pRenderer->PathCommandArcTo(this->m_arPoints[nFigure].dX, this->m_arPoints[nFigure].dY, + this->m_arPoints[nFigure + 1].dX - this->m_arPoints[nFigure].dX, + this->m_arPoints[nFigure + 1].dY - this->m_arPoints[nFigure].dY, + angleStart, GetSweepAngle(angleStart, angleEnd)); + + nFigure += 4; + } + + CheckLastPoint(pRenderer, pointCur); + break; + } + case rtArcTo: + { + int nFigure = 0; + while ((nFigure + 4) <= (int)this->m_arPoints.size()) + { + double nCentreX = (this->m_arPoints[nFigure].dX + this->m_arPoints[nFigure + 1].dX) / 2; + double nCentreY = (this->m_arPoints[nFigure].dY + this->m_arPoints[nFigure + 1].dY) / 2; + + double angleStart = GetAngle(nCentreX, nCentreY, + this->m_arPoints[nFigure + 2].dX, this->m_arPoints[nFigure + 2].dY); + + double angleEnd = GetAngle(nCentreX, nCentreY, + this->m_arPoints[nFigure + 3].dX, this->m_arPoints[nFigure + 3].dY); + + pRenderer->PathCommandArcTo(this->m_arPoints[nFigure].dX, this->m_arPoints[nFigure].dY, + this->m_arPoints[nFigure + 1].dX - this->m_arPoints[nFigure].dX, + this->m_arPoints[nFigure + 1].dY - this->m_arPoints[nFigure].dY, + angleStart, GetSweepAngle(angleStart, angleEnd)); + + nFigure += 4; + } + + CheckLastPoint(pRenderer, pointCur); + break; + } + case rtClockwiseArcTo: + { + int nFigure = 0; + while ((nFigure + 4) <= (int)this->m_arPoints.size()) + { + double nCentreX = (this->m_arPoints[nFigure].dX + this->m_arPoints[nFigure + 1].dX) / 2; + double nCentreY = (this->m_arPoints[nFigure].dY + this->m_arPoints[nFigure + 1].dY) / 2; + + double angleStart = GetAngle(nCentreX, nCentreY, + this->m_arPoints[nFigure + 2].dX, this->m_arPoints[nFigure + 2].dY); + + double angleEnd = GetAngle(nCentreX, nCentreY, + this->m_arPoints[nFigure + 3].dX, this->m_arPoints[nFigure + 3].dY); + + pRenderer->PathCommandArcTo(this->m_arPoints[nFigure].dX, this->m_arPoints[nFigure].dY, + this->m_arPoints[nFigure + 1].dX - this->m_arPoints[nFigure].dX, + this->m_arPoints[nFigure + 1].dY - this->m_arPoints[nFigure].dY, + angleStart, 360 + GetSweepAngle(angleStart, angleEnd)); + + nFigure += 4; + } + + CheckLastPoint(pRenderer, pointCur); + break; + } + case rtClockwiseArc: + { + pRenderer->PathCommandStart(); + int nFigure = 0; + while ((nFigure + 4) <= (int)this->m_arPoints.size()) + { + double nCentreX = (this->m_arPoints[nFigure].dX + this->m_arPoints[nFigure + 1].dX) / 2; + double nCentreY = (this->m_arPoints[nFigure].dY + this->m_arPoints[nFigure + 1].dY) / 2; + + double angleStart = GetAngle(nCentreX, nCentreY, + this->m_arPoints[nFigure + 2].dX, this->m_arPoints[nFigure + 2].dY); + + double angleEnd = GetAngle(nCentreX, nCentreY, + this->m_arPoints[nFigure + 3].dX, this->m_arPoints[nFigure + 3].dY); + + pRenderer->PathCommandArcTo(this->m_arPoints[nFigure].dX, this->m_arPoints[nFigure].dY, + this->m_arPoints[nFigure + 1].dX - this->m_arPoints[nFigure].dX, + this->m_arPoints[nFigure + 1].dY - this->m_arPoints[nFigure].dY, + angleStart, 360 + GetSweepAngle(angleStart, angleEnd)); + + nFigure += 4; + } + + CheckLastPoint(pRenderer, pointCur); + break; + } + case rtEllipticalQuadrX: + { + bool bIsX = true; + CheckLastPoint(pRenderer, pointCur); + + size_t nCount = this->m_arPoints.size(); + for (size_t nIndex = 0; nIndex < nCount; ++nIndex) + { + double x1 = pointCur.dX; + double y1 = pointCur.dY; + + double x2 = this->m_arPoints[nIndex].dX; + double y2 = this->m_arPoints[nIndex].dY; + + double dRadX = fabs(x1 - x2); + double dRadY = fabs(y1 - y2); + + AddEllipticalQuadr(pRenderer, bIsX, x1, y1, x2, y2, dRadX, dRadY); + + pointCur.dX = x2; + pointCur.dY = y2; + } + + break; + } + case rtEllipticalQuadrY: + { + bool bIsX = false; + CheckLastPoint(pRenderer, pointCur); + + size_t nCount = this->m_arPoints.size(); + for (size_t nIndex = 0; nIndex < nCount; ++nIndex) + { + double x1 = pointCur.dX; + double y1 = pointCur.dY; + + double x2 = this->m_arPoints[nIndex].dX; + double y2 = this->m_arPoints[nIndex].dY; + + double dRadX = fabs(x1 - x2); + double dRadY = fabs(y1 - y2); + + AddEllipticalQuadr(pRenderer, bIsX, x1, y1, x2, y2, dRadX, dRadY); + + pointCur.dX = x2; + pointCur.dY = y2; + } + + break; + } + case rtQuadrBesier: + { + double* pArray = NULL; + size_t nCount = 0; + GetSafearrayPoints(pRenderer, &pArray, nCount, pointCur, TRUE); + + if (NULL != pArray) + { + pRenderer->PathCommandLinesTo(pArray, (int)nCount/*this->m_arPoints.size()*/); + } + + CheckLastPoint(pRenderer, pointCur); + break; + } + default: break; + }; + } + + void CGraphicPath::CPart::AddEllipticalQuadr(IRenderer*& pRenderer, bool& bIsX, double& x1, double& y1, double& x2, double& y2, double& dRadX, double& dRadY) + { + if (bIsX) + { + if ((x2 >= x1) && (y2 >= y1)) + pRenderer->PathCommandArcTo(x1 - dRadX, y1, 2 * dRadX, 2 * dRadY, -90, 90); + else if ((x2 >= x1) && (y2 <= y1)) + pRenderer->PathCommandArcTo(x1 - dRadX, y1 - 2 * dRadY, 2 * dRadX, 2 * dRadY, 90, -90); + else if ((x2 <= x1) && (y2 >= y1)) + pRenderer->PathCommandArcTo(x1 - dRadX, y1, 2 * dRadX, 2 * dRadY, -90, -90); + else if ((x2 <= x1) && (y2 <= y1)) + pRenderer->PathCommandArcTo(x1 - dRadX, y1 - 2 * dRadY, 2 * dRadX, 2 * dRadY, 90, 90); + } + else + { + if ((x2 >= x1) && (y2 >= y1)) + pRenderer->PathCommandArcTo(x1, y1 - dRadY, 2 * dRadX, 2 * dRadY, 180, -90); + else if ((x2 >= x1) && (y2 <= y1)) + pRenderer->PathCommandArcTo(x1, y1 - dRadY, 2 * dRadX, 2 * dRadY, 180, 90); + else if ((x2 <= x1) && (y2 >= y1)) + pRenderer->PathCommandArcTo(x1 - 2 * dRadX, y1 - dRadY, 2 * dRadX, 2 * dRadY, 0, 90); + else if ((x2 <= x1) && (y2 <= y1)) + pRenderer->PathCommandArcTo(x1 - 2 * dRadX, y1 - dRadY, 2 * dRadX, 2 * dRadY, 0, -90); + } + bIsX = !bIsX; + } + + + void CGraphicPath::AddRuler(const RulesType& eType) + { + size_t lCount = m_arParts.size(); + + CPart oPart; + oPart.m_eType = eType; + + m_arParts.push_back(oPart); + } + void CGraphicPath::AddPoint(const double& x, const double& y) + { + size_t lCount = m_arParts.size(); + if (0 != lCount) + { + CDoublePoint point; + point.dX = x; + point.dY = y; + m_arParts[lCount - 1].m_arPoints.push_back(point); + } + } + + void CGraphicPath::Clear() + { + m_arParts.clear(); + } +} diff --git a/MsBinaryFile/Common/ODraw/GraphicsPath.h b/MsBinaryFile/Common/ODraw/GraphicsPath.h index 20440be1b1..f2842071c3 100644 --- a/MsBinaryFile/Common/ODraw/GraphicsPath.h +++ b/MsBinaryFile/Common/ODraw/GraphicsPath.h @@ -55,32 +55,15 @@ namespace NSCustomShapesConvert double bottom; public: - CDoubleRect() - { - left = 0; - top = 0; - right = 0; - bottom = 0; - } - CDoubleRect& operator=(const CDoubleRect& oSrc) - { - left = oSrc.left; - top = oSrc.top; - right = oSrc.right; - bottom = oSrc.bottom; + CDoubleRect(); + CDoubleRect& operator=(const CDoubleRect& oSrc); + CDoubleRect(const CDoubleRect& oSrc); - return *this; - } - CDoubleRect(const CDoubleRect& oSrc) - { - *this = oSrc; - } inline bool IsEqual(const CDoubleRect& oSrc, double dEps = 0.01) { return ((fabs(left - oSrc.left) < dEps) && (fabs(top - oSrc.top) < dEps) && (fabs(right - oSrc.right) < dEps) && (fabs(bottom - oSrc.bottom) < dEps)); } - inline double GetWidth() const { return right - left; @@ -106,25 +89,11 @@ namespace NSCustomShapesConvert public: double dX; double dY; + public: - CPointD() - { - dX = 0; - dY = 0; - } - - CPointD& operator= (const CPointD& oSrc) - { - dX = oSrc.dX; - dY = oSrc.dY; - - return *this; - } - - CPointD(const CPointD& oSrc) - { - *this = oSrc; - } + CPointD(); + CPointD& operator= (const CPointD& oSrc); + CPointD(const CPointD& oSrc); }; public: @@ -147,51 +116,9 @@ namespace NSCustomShapesConvert LONG m_lOriginalHeight; public: - CGeomShapeInfo() - { - m_dLeft = 0; - m_dTop = 0; - m_dWidth = 720; - m_dHeight = 576; - - m_dLimoX = 0; - m_dLimoY = 0; - - m_oCurPoint.dX = 0; - m_oCurPoint.dY = 0; - - m_dRotate = 0.0; - m_bFlipH = false; - m_bFlipV = false; - - m_lOriginalWidth = 0; - m_lOriginalHeight = 0; - } - ~CGeomShapeInfo() - { - } - - CGeomShapeInfo& operator =(const CGeomShapeInfo& oSrc) - { - m_dLeft = oSrc.m_dLeft; - m_dTop = oSrc.m_dTop; - m_dWidth = oSrc.m_dWidth; - m_dHeight = oSrc.m_dHeight; - - m_dLimoX = oSrc.m_dLimoX; - m_dLimoY = oSrc.m_dLimoY; - - m_oCurPoint = oSrc.m_oCurPoint; - - m_dRotate = oSrc.m_dRotate; - m_bFlipH = oSrc.m_bFlipH; - m_bFlipV = oSrc.m_bFlipV; - - m_lOriginalWidth = oSrc.m_lOriginalWidth; - m_lOriginalHeight = oSrc.m_lOriginalHeight; - - return (*this); - } + CGeomShapeInfo(); + ~CGeomShapeInfo(); + CGeomShapeInfo& operator =(const CGeomShapeInfo& oSrc); inline void SetBounds(const CDoubleRect& oRect) { @@ -217,25 +144,11 @@ namespace NSCustomShapesConvert public: double dX; double dY; + public: - CDoublePoint() - { - dX = 0; - dY = 0; - } - - CDoublePoint& operator= (const CDoublePoint& oSrc) - { - dX = oSrc.dX; - dY = oSrc.dY; - - return *this; - } - - CDoublePoint(const CDoublePoint& oSrc) - { - *this = oSrc; - } + CDoublePoint(); + CDoublePoint& operator= (const CDoublePoint& oSrc); + CDoublePoint(const CDoublePoint& oSrc); }; enum RulesType @@ -286,14 +199,10 @@ namespace NSCustomShapesConvert class CGraphicPath { public: - virtual void InternalClear() - { - m_lFlags = 0; - } - CGraphicPath() - { - InternalClear(); - } + virtual void InternalClear(); + + CGraphicPath(); + class CPart { public: @@ -301,23 +210,10 @@ namespace NSCustomShapesConvert std::vector m_arPoints; public: - CPart() : m_eType(rtMoveTo), m_arPoints() - { - } - CPart& operator=(const CPart& oSrc) - { - m_eType = oSrc.m_eType; - this->m_arPoints.clear(); - for (size_t nIndex = 0; nIndex < oSrc.m_arPoints.size(); ++nIndex) - { - this->m_arPoints.push_back(oSrc.m_arPoints[nIndex]); - } - return (*this); - } - ~CPart() - { - this->m_arPoints.clear(); - } + CPart(); + CPart& operator=(const CPart& oSrc); + ~CPart(); + //void FromXmlNode(XmlUtils::CXmlNode& oNode) //{ // std::wstring strName = oNode.GetAttribute(_T("name")); @@ -364,76 +260,10 @@ namespace NSCustomShapesConvert // } //} void ParseString(std::wstring strDelimeters, std::wstring strSource, - std::vector& pArrayResults, bool bIsCleared = true) - { - if (bIsCleared) - pArrayResults.clear(); + std::vector& pArrayResults, bool bIsCleared = true); - std::wstring resToken; - int curPos= 0; - - boost::algorithm::split(pArrayResults, strSource, boost::algorithm::is_any_of(strDelimeters), boost::algorithm::token_compress_on); - - } - - void CheckLastPoint(IRenderer* pRenderer, CDoublePoint& pointCur) - { - if (NULL == pRenderer) - return; - - pRenderer->PathCommandGetCurrentPoint(&pointCur.dX, &pointCur.dY); - } - double GetAngle(double fCentreX, double fCentreY, double fX, double fY) - { - // - + (.. ) - double dX = fX - fCentreX; - double dY = fY - fCentreY; - - double modDX = abs(dX); - double modDY = abs(dY); - - if ((modDX < 0.01) && (modDY < 0.01)) - { - return 0; - } - if ((modDX < 0.01) && (dY < 0)) - { - return -90; - } - else if (modDX < 0.01) - { - return 90; - } - if ((modDY < 0.01) && (dX < 0)) - { - return 180; - } - else if (modDY < 0.01) - { - return 0; - } - - double fAngle = atan(dY / dX); - fAngle *= double(180 / M_PI); - if (dX > 0 && dY > 0) - { - return fAngle; - } - else if (dX > 0 && dY < 0) - { - return fAngle; - } - else if (dX < 0 && dY > 0) - { - //return fAngle + 180; - return 180 + fAngle; - } - else - { - //return fAngle + 180; - return fAngle - 180; - } - } + void CheckLastPoint(IRenderer* pRenderer, CDoublePoint& pointCur); + double GetAngle(double fCentreX, double fCentreY, double fX, double fY); inline double GetSweepAngle(const double& angleStart, const double& angleEnd) { @@ -444,475 +274,21 @@ namespace NSCustomShapesConvert } void ApplyElliptical(bool& bIsX, double& angleStart, double& angleSweet, - double& Left, double& Top, double& Width, double& Height, const CDoublePoint& pointCur) - { - // (x - y - x...) - if (bIsX) - { - angleStart = -90; - angleSweet = 90; + double& Left, double& Top, double& Width, double& Height, const CDoublePoint& pointCur); - if ((Width < 0) && (Height < 0)) - { - angleStart = 90; - Width *= -1; - Height *= -1; - Left = pointCur.dX - Width / 2; - Top = pointCur.dY - Height; - } - else if ((Width < 0) && (Height > 0)) - { - angleStart = -90; - angleSweet = -90; - Width *= -1; - Left = pointCur.dX - Width / 2; - Top = pointCur.dY; - } - else if ((Width > 0) && (Height < 0)) - { - angleStart = 90; - angleSweet = -90; - Height *= -1; - Left = pointCur.dX - Width / 2; - Top = pointCur.dY - Height; - } - else - { - Left = pointCur.dX - Width / 2; - Top = pointCur.dY; - } - } - else - { - angleStart = 180; - angleSweet = -90; + void GetSafearrayPoints(IRenderer* pRenderer, double** ppArray, size_t& nCountOut, CDoublePoint& pointCur, bool bR = false); - if ((Width < 0) && (Height < 0)) - { - angleStart = 0; - Width *= -1; - Height *= -1; - Left = pointCur.dX - Width; - Top = pointCur.dY - Height / 2; - } - else if ((Width < 0) && (Height > 0)) - { - angleStart = 0; - angleSweet = 90; - Width *= -1; - Left = pointCur.dX - Width; - Top = pointCur.dY - Height / 2; - } - else if ((Width > 0) && (Height < 0)) - { - angleStart = 180; - angleSweet = 90; - Height *= -1; - Left = pointCur.dX; - Top = pointCur.dY - Height / 2; - } - else - { - Left = pointCur.dX; - Top = pointCur.dY - Height / 2; - } - } - bIsX = !bIsX; - } + void Draw(IRenderer* pRenderer, CDoublePoint& pointCur); - - void GetSafearrayPoints(IRenderer* pRenderer, double** ppArray, size_t& nCountOut, CDoublePoint& pointCur, bool bR = false) - { - if (NULL == ppArray) - return; - - size_t nCount = this->m_arPoints.size(); - - nCountOut = 2 * (nCount + 1); - - double* pArray = new double [nCountOut]; - double* pBuffer = pArray; - - memset (pBuffer, 0, nCountOut * sizeof(double)); - - *pBuffer = pointCur.dX; ++pBuffer; - *pBuffer = pointCur.dY; ++pBuffer; - - if (bR) - { - for (size_t nIndex = 0; nIndex < nCount; ++nIndex) - { - *pBuffer = (this->m_arPoints[nIndex].dX + pointCur.dX); ++pBuffer; - *pBuffer = (this->m_arPoints[nIndex].dY + pointCur.dY); ++pBuffer; - - if (nIndex == (nCount - 1)) - { - pointCur.dX += this->m_arPoints[nIndex].dX; - pointCur.dY += this->m_arPoints[nIndex].dY; - } - } - } - else - { - for (size_t nIndex = 0; nIndex < nCount; ++nIndex) - { - *pBuffer = this->m_arPoints[nIndex].dX; ++pBuffer; - *pBuffer = this->m_arPoints[nIndex].dY; ++pBuffer; - - if (nIndex == (nCount - 1)) - { - pointCur.dX = this->m_arPoints[nIndex].dX; - pointCur.dY = this->m_arPoints[nIndex].dY; - } - } - } - *ppArray = pArray; - - } - - void Draw(IRenderer* pRenderer, CDoublePoint& pointCur) - { - switch (m_eType) - { - case rtMoveTo: - { - if (0 < this->m_arPoints.size()) - { - pointCur.dX = this->m_arPoints[0].dX; - pointCur.dY = this->m_arPoints[0].dY; - pRenderer->PathCommandMoveTo(this->m_arPoints[0].dX, this->m_arPoints[0].dY); - } - break; - } - case rtLineTo: - { - double* pArray = NULL; - size_t nCount = 0; - GetSafearrayPoints(pRenderer, &pArray, nCount, pointCur); - - if (NULL != pArray) - { - pRenderer->PathCommandLinesTo(pArray, (int)nCount /*this->m_arPoints.size()*/); - } - - break; - } - case rtCurveTo: - { - double* pArray = NULL; - size_t nCount = 0; - GetSafearrayPoints(pRenderer, &pArray, nCount, pointCur); - - if (NULL != pArray) - { - pRenderer->PathCommandCurvesTo (pArray, (int)nCount/*this->m_arPoints.size()*/); - } - - break; - } - case rtClose: - { - pRenderer->PathCommandClose(); - break; - } - case rtRMoveTo: - { - if (0 < this->m_arPoints.size()) - { - pointCur.dX = this->m_arPoints[0].dX + pointCur.dX; - pointCur.dY = this->m_arPoints[0].dY + pointCur.dY; - pRenderer->PathCommandMoveTo(pointCur.dX, pointCur.dY); - } - break; - } - case rtRLineTo: - { - double* pArray = NULL; - size_t nCount = 0; - GetSafearrayPoints(pRenderer, &pArray, nCount, pointCur, TRUE); - - if (NULL != pArray) - { - pRenderer->PathCommandLinesTo(pArray, (int)nCount/*this->m_arPoints.size()*/); - } - - break; - } - case rtRCurveTo: - { - double* pArray = NULL; - size_t nCount = 0; - GetSafearrayPoints(pRenderer, &pArray, nCount, pointCur, TRUE); - - if (NULL != pArray) - { - pRenderer->PathCommandCurvesTo(pArray, (int)nCount/*this->m_arPoints.size()*/); - } - break; - } - case rtAngleEllipseTo: - { - int nFigure = 0; - while ((nFigure + 3) <= (int)this->m_arPoints.size()) - { - double nLeft = this->m_arPoints[nFigure].dX - this->m_arPoints[nFigure + 1].dX / 2; - double nTop = this->m_arPoints[nFigure].dY - this->m_arPoints[nFigure + 1].dY / 2; - - pRenderer->PathCommandArcTo(nLeft, nTop, - this->m_arPoints[nFigure + 1].dX, this->m_arPoints[nFigure + 1].dY, - this->m_arPoints[nFigure + 2].dX, this->m_arPoints[nFigure + 2].dY); - - nFigure += 3; - } - - CheckLastPoint(pRenderer, pointCur); - break; - } - case rtAngleEllipse: - { - pRenderer->PathCommandStart(); - int nFigure = 0; - while ((nFigure + 3) <= (int)this->m_arPoints.size()) - { - double nLeft = this->m_arPoints[nFigure].dX - this->m_arPoints[nFigure + 1].dX / 2; - double nTop = this->m_arPoints[nFigure].dY - this->m_arPoints[nFigure + 1].dY / 2; - - pRenderer->PathCommandArcTo(nLeft, nTop, - this->m_arPoints[nFigure + 1].dX, this->m_arPoints[nFigure + 1].dY, - this->m_arPoints[nFigure + 2].dX, this->m_arPoints[nFigure + 2].dY); - - nFigure += 3; - } - - CheckLastPoint(pRenderer, pointCur); - break; - } - case rtArc: - { - pRenderer->PathCommandStart(); - int nFigure = 0; - while ((nFigure + 4) <= (int)this->m_arPoints.size()) - { - double nCentreX = (this->m_arPoints[nFigure].dX + this->m_arPoints[nFigure + 1].dX) / 2; - double nCentreY = (this->m_arPoints[nFigure].dY + this->m_arPoints[nFigure + 1].dY) / 2; - - double angleStart = GetAngle(nCentreX, nCentreY, - this->m_arPoints[nFigure + 2].dX, this->m_arPoints[nFigure + 2].dY); - - double angleEnd = GetAngle(nCentreX, nCentreY, - this->m_arPoints[nFigure + 3].dX, this->m_arPoints[nFigure + 3].dY); - - pRenderer->PathCommandArcTo(this->m_arPoints[nFigure].dX, this->m_arPoints[nFigure].dY, - this->m_arPoints[nFigure + 1].dX - this->m_arPoints[nFigure].dX, - this->m_arPoints[nFigure + 1].dY - this->m_arPoints[nFigure].dY, - angleStart, GetSweepAngle(angleStart, angleEnd)); - - nFigure += 4; - } - - CheckLastPoint(pRenderer, pointCur); - break; - } - case rtArcTo: - { - int nFigure = 0; - while ((nFigure + 4) <= (int)this->m_arPoints.size()) - { - double nCentreX = (this->m_arPoints[nFigure].dX + this->m_arPoints[nFigure + 1].dX) / 2; - double nCentreY = (this->m_arPoints[nFigure].dY + this->m_arPoints[nFigure + 1].dY) / 2; - - double angleStart = GetAngle(nCentreX, nCentreY, - this->m_arPoints[nFigure + 2].dX, this->m_arPoints[nFigure + 2].dY); - - double angleEnd = GetAngle(nCentreX, nCentreY, - this->m_arPoints[nFigure + 3].dX, this->m_arPoints[nFigure + 3].dY); - - pRenderer->PathCommandArcTo(this->m_arPoints[nFigure].dX, this->m_arPoints[nFigure].dY, - this->m_arPoints[nFigure + 1].dX - this->m_arPoints[nFigure].dX, - this->m_arPoints[nFigure + 1].dY - this->m_arPoints[nFigure].dY, - angleStart, GetSweepAngle(angleStart, angleEnd)); - - nFigure += 4; - } - - CheckLastPoint(pRenderer, pointCur); - break; - } - case rtClockwiseArcTo: - { - int nFigure = 0; - while ((nFigure + 4) <= (int)this->m_arPoints.size()) - { - double nCentreX = (this->m_arPoints[nFigure].dX + this->m_arPoints[nFigure + 1].dX) / 2; - double nCentreY = (this->m_arPoints[nFigure].dY + this->m_arPoints[nFigure + 1].dY) / 2; - - double angleStart = GetAngle(nCentreX, nCentreY, - this->m_arPoints[nFigure + 2].dX, this->m_arPoints[nFigure + 2].dY); - - double angleEnd = GetAngle(nCentreX, nCentreY, - this->m_arPoints[nFigure + 3].dX, this->m_arPoints[nFigure + 3].dY); - - pRenderer->PathCommandArcTo(this->m_arPoints[nFigure].dX, this->m_arPoints[nFigure].dY, - this->m_arPoints[nFigure + 1].dX - this->m_arPoints[nFigure].dX, - this->m_arPoints[nFigure + 1].dY - this->m_arPoints[nFigure].dY, - angleStart, 360 + GetSweepAngle(angleStart, angleEnd)); - - nFigure += 4; - } - - CheckLastPoint(pRenderer, pointCur); - break; - } - case rtClockwiseArc: - { - pRenderer->PathCommandStart(); - int nFigure = 0; - while ((nFigure + 4) <= (int)this->m_arPoints.size()) - { - double nCentreX = (this->m_arPoints[nFigure].dX + this->m_arPoints[nFigure + 1].dX) / 2; - double nCentreY = (this->m_arPoints[nFigure].dY + this->m_arPoints[nFigure + 1].dY) / 2; - - double angleStart = GetAngle(nCentreX, nCentreY, - this->m_arPoints[nFigure + 2].dX, this->m_arPoints[nFigure + 2].dY); - - double angleEnd = GetAngle(nCentreX, nCentreY, - this->m_arPoints[nFigure + 3].dX, this->m_arPoints[nFigure + 3].dY); - - pRenderer->PathCommandArcTo(this->m_arPoints[nFigure].dX, this->m_arPoints[nFigure].dY, - this->m_arPoints[nFigure + 1].dX - this->m_arPoints[nFigure].dX, - this->m_arPoints[nFigure + 1].dY - this->m_arPoints[nFigure].dY, - angleStart, 360 + GetSweepAngle(angleStart, angleEnd)); - - nFigure += 4; - } - - CheckLastPoint(pRenderer, pointCur); - break; - } - case rtEllipticalQuadrX: - { - bool bIsX = true; - CheckLastPoint(pRenderer, pointCur); - - size_t nCount = this->m_arPoints.size(); - for (size_t nIndex = 0; nIndex < nCount; ++nIndex) - { - double x1 = pointCur.dX; - double y1 = pointCur.dY; - - double x2 = this->m_arPoints[nIndex].dX; - double y2 = this->m_arPoints[nIndex].dY; - - double dRadX = fabs(x1 - x2); - double dRadY = fabs(y1 - y2); - - AddEllipticalQuadr(pRenderer, bIsX, x1, y1, x2, y2, dRadX, dRadY); - - pointCur.dX = x2; - pointCur.dY = y2; - } - - break; - } - case rtEllipticalQuadrY: - { - bool bIsX = false; - CheckLastPoint(pRenderer, pointCur); - - size_t nCount = this->m_arPoints.size(); - for (size_t nIndex = 0; nIndex < nCount; ++nIndex) - { - double x1 = pointCur.dX; - double y1 = pointCur.dY; - - double x2 = this->m_arPoints[nIndex].dX; - double y2 = this->m_arPoints[nIndex].dY; - - double dRadX = fabs(x1 - x2); - double dRadY = fabs(y1 - y2); - - AddEllipticalQuadr(pRenderer, bIsX, x1, y1, x2, y2, dRadX, dRadY); - - pointCur.dX = x2; - pointCur.dY = y2; - } - - break; - } - case rtQuadrBesier: - { - double* pArray = NULL; - size_t nCount = 0; - GetSafearrayPoints(pRenderer, &pArray, nCount, pointCur, TRUE); - - if (NULL != pArray) - { - pRenderer->PathCommandLinesTo(pArray, (int)nCount/*this->m_arPoints.size()*/); - } - - CheckLastPoint(pRenderer, pointCur); - break; - } - default: break; - }; - } - - inline void AddEllipticalQuadr(IRenderer*& pRenderer, bool& bIsX, double& x1, double& y1, double& x2, double& y2, double& dRadX, double& dRadY) - { - if (bIsX) - { - if ((x2 >= x1) && (y2 >= y1)) - pRenderer->PathCommandArcTo(x1 - dRadX, y1, 2 * dRadX, 2 * dRadY, -90, 90); - else if ((x2 >= x1) && (y2 <= y1)) - pRenderer->PathCommandArcTo(x1 - dRadX, y1 - 2 * dRadY, 2 * dRadX, 2 * dRadY, 90, -90); - else if ((x2 <= x1) && (y2 >= y1)) - pRenderer->PathCommandArcTo(x1 - dRadX, y1, 2 * dRadX, 2 * dRadY, -90, -90); - else if ((x2 <= x1) && (y2 <= y1)) - pRenderer->PathCommandArcTo(x1 - dRadX, y1 - 2 * dRadY, 2 * dRadX, 2 * dRadY, 90, 90); - } - else - { - if ((x2 >= x1) && (y2 >= y1)) - pRenderer->PathCommandArcTo(x1, y1 - dRadY, 2 * dRadX, 2 * dRadY, 180, -90); - else if ((x2 >= x1) && (y2 <= y1)) - pRenderer->PathCommandArcTo(x1, y1 - dRadY, 2 * dRadX, 2 * dRadY, 180, 90); - else if ((x2 <= x1) && (y2 >= y1)) - pRenderer->PathCommandArcTo(x1 - 2 * dRadX, y1 - dRadY, 2 * dRadX, 2 * dRadY, 0, 90); - else if ((x2 <= x1) && (y2 <= y1)) - pRenderer->PathCommandArcTo(x1 - 2 * dRadX, y1 - dRadY, 2 * dRadX, 2 * dRadY, 0, -90); - } - bIsX = !bIsX; - } + void AddEllipticalQuadr(IRenderer*& pRenderer, bool& bIsX, double& x1, double& y1, double& x2, double& y2, double& dRadX, double& dRadY); }; - void AddRuler(const RulesType& eType) - { - size_t lCount = m_arParts.size(); - - CPart oPart; - oPart.m_eType = eType; - - m_arParts.push_back(oPart); - } - void AddPoint(const double& x, const double& y) - { - size_t lCount = m_arParts.size(); - if (0 != lCount) - { - CDoublePoint point; - point.dX = x; - point.dY = y; - m_arParts[lCount - 1].m_arPoints.push_back(point); - } - } + void AddRuler(const RulesType& eType); + void AddPoint(const double& x, const double& y); + + void Clear(); - void Clear() - { - m_arParts.clear(); - } std::vector m_arParts; - int m_lFlags; - }; } diff --git a/MsBinaryFile/Common/ODraw/PathShape.cpp b/MsBinaryFile/Common/ODraw/PathShape.cpp new file mode 100644 index 0000000000..7de99a0bb9 --- /dev/null +++ b/MsBinaryFile/Common/ODraw/PathShape.cpp @@ -0,0 +1,420 @@ +/* + * (c) Copyright Ascensio System SIA 2010-2019 + * + * 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 20A-12 Ernesta Birznieka-Upisha + * street, Riga, Latvia, EU, LV-1050. + * + * 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 "PathShape.h" + +namespace NSCustomShapesConvert +{ + CSlice::CSlice(RulesType eType /*, LONG x = 0, LONG y = 0*/) + { + m_eRuler = eType; + m_nCountElementsPoint = 0; + //m_lX = x; + //m_lY = y; + } + void CSlice::AddParam(LONG lParam) + { + long lPoint = m_nCountElementsPoint % 2; + if (0 == lPoint) + { + Aggplus::POINT point; + point.x = lParam/* - m_lX*/; + point.y = 0; + m_arPoints.push_back(point); + } + else + { + m_arPoints[m_arPoints.size() - 1].y = lParam/* - m_lY*/; + } + ++m_nCountElementsPoint; + } + CSlice& CSlice::operator =(const CSlice& oSrc) + { + m_eRuler = oSrc.m_eRuler; + m_arPoints.clear(); + + for (size_t nIndex = 0; nIndex < oSrc.m_arPoints.size(); ++nIndex) + { + m_arPoints.push_back(oSrc.m_arPoints[nIndex]); + } + return (*this); + } + double CSlice::GetAngle(double fCentreX, double fCentreY, double fX, double fY) + { + // - + (.. ) + double dX = fX - fCentreX; + double dY = fY - fCentreY; + + double modDX = abs(dX); + double modDY = abs(dY); + + if ((modDX < 0.01) && (modDY < 0.01)) + { + return 0; + } + if ((modDX < 0.01) && (dY < 0)) + { + return -90; + } + else if (modDX < 0.01) + { + return 90; + } + if ((modDY < 0.01) && (dX < 0)) + { + return 180; + } + else if (modDY < 0.01) + { + return 0; + } + + double fAngle = atan(dY / dX); + fAngle *= (180 / M_PI); + if (dX > 0 && dY > 0) + { + return fAngle; + } + else if (dX > 0 && dY < 0) + { + return fAngle; + } + else if (dX < 0 && dY > 0) + { + //return fAngle + 180; + return 180 + fAngle; + } + else + { + //return fAngle + 180; + return fAngle - 180; + } + } + double CSlice::GetSweepAngle(const double& angleStart, const double& angleEnd) + { + if (angleStart >= angleEnd) + return angleEnd - angleStart; + else + return angleEnd - angleStart - 360; + } + void CSlice::ApplyElliptical(bool& bIsX, double& angleStart, double& angleSweet, + double& Left, double& Top, double& Width, double& Height, const CGeomShapeInfo::CPointD& pointCur) + { + // (x - y - x...) + if (bIsX) + { + angleStart = -90; + angleSweet = 90; + + if ((Width < 0) && (Height < 0)) + { + angleStart = 90; + Width *= -1; + Height *= -1; + Left = pointCur.dX - Width / 2; + Top = pointCur.dY - Height; + } + else if ((Width < 0) && (Height > 0)) + { + angleStart = -90; + angleSweet = -90; + Width *= -1; + Left = pointCur.dX - Width / 2; + Top = pointCur.dY; + } + else if ((Width > 0) && (Height < 0)) + { + angleStart = 90; + angleSweet = -90; + Height *= -1; + Left = pointCur.dX - Width / 2; + Top = pointCur.dY - Height; + } + else + { + Left = pointCur.dX - Width / 2; + Top = pointCur.dY; + } + } + else + { + angleStart = 180; + angleSweet = -90; + + if ((Width < 0) && (Height < 0)) + { + angleStart = 0; + Width *= -1; + Height *= -1; + Left = pointCur.dX - Width; + Top = pointCur.dY - Height / 2; + } + else if ((Width < 0) && (Height > 0)) + { + angleStart = 0; + angleSweet = 90; + Width *= -1; + Left = pointCur.dX - Width; + Top = pointCur.dY - Height / 2; + } + else if ((Width > 0) && (Height < 0)) + { + angleStart = 180; + angleSweet = 90; + Height *= -1; + Left = pointCur.dX; + Top = pointCur.dY - Height / 2; + } + else + { + Left = pointCur.dX; + Top = pointCur.dY - Height / 2; + } + } + bIsX = !bIsX; + } + void CSlice::ApplyLimo(CGeomShapeInfo& pGeomInfo, double& lX, double& lY) + { + if ((0 == pGeomInfo.m_dLimoX) || (0 == pGeomInfo.m_dLimoY)) + return; + + double dAspect = (double)pGeomInfo.m_dLimoX / pGeomInfo.m_dLimoY; + double lWidth = (dAspect * pGeomInfo.m_dHeight); + + if (lWidth < pGeomInfo.m_dWidth) + { + // LimoX + double lXc = pGeomInfo.m_dLeft + pGeomInfo.m_dWidth / 2; + if ((lX > lXc) || ((lX == lXc) && (pGeomInfo.m_oCurPoint.dX >= lXc))) + { + double lXNew = pGeomInfo.m_dLeft + ((lWidth / pGeomInfo.m_dWidth) * (lX - pGeomInfo.m_dLeft)); + lXNew += (pGeomInfo.m_dWidth - lWidth); + lX = lXNew; + } + //if (lX >= lXc) + //{ + // LONG lXNew = pGeomInfo->m_lLeft + (LONG)(((double)lWidth / pGeomInfo->m_lWidth) * (lX - pGeomInfo->m_lLeft)); + // if (pGeomInfo->m_oCurPoint.x >= lXc) + // { + // lXNew += (pGeomInfo->m_lWidth - lWidth); + // } + // lX = lXNew; + //} + } + else if (lWidth != pGeomInfo.m_dWidth) + { + // LimoY + double lHeight = (pGeomInfo.m_dWidth / dAspect); + double lYc = pGeomInfo.m_dTop + pGeomInfo.m_dHeight / 2; + if ((lY > lYc) || ((lY == lYc) && (pGeomInfo.m_oCurPoint.dY >= lYc))) + { + double lYNew = pGeomInfo.m_dTop + ((lHeight / pGeomInfo.m_dHeight) * (lY - pGeomInfo.m_dTop)); + lYNew += (pGeomInfo.m_dHeight - lHeight); + lY = lYNew; + } + } + } + void CSlice::Bez2_3(std::vector& oArray, RulesType& eType) + { + if (rtQuadrBesier == eType) + { + eType = rtCurveTo; + } + else if (rtOOXMLQuadBezTo == eType) + { + eType = rtOOXMLCubicBezTo; + } + else + { + return; + } + + std::vector arOld; + arOld.insert(arOld.end(),oArray.begin(), oArray.end()); + + oArray.clear(); + + size_t nStart = 0; + size_t nEnd = 2; + + size_t nCount = arOld.size(); + while (nStart < (nCount - 1)) + { + if (2 >= (nCount - nStart)) + { + // по идее такого быть не может + for (size_t i = nStart; i < nCount; ++i) + { + oArray.push_back(arOld[i]); + } + + nStart = nCount; + break; + } + + if (4 == (nCount - nStart)) + { + // ничего не поделаешь... делаем кривую третьего порядка + oArray.push_back(arOld[nStart]); + oArray.push_back(arOld[nStart + 1]); + oArray.push_back(arOld[nStart + 2]); + oArray.push_back(arOld[nStart + 3]); + + nStart += 4; + break; + } + + // значит есть еще + CGeomShapeInfo::CPointD mem1; + mem1.dX = (arOld[nStart].dX + 2 * arOld[nStart + 1].dX) / 3.0; + mem1.dY = (arOld[nStart].dY + 2 * arOld[nStart + 1].dY) / 3.0; + + CGeomShapeInfo::CPointD mem2; + mem2.dX = (2 * arOld[nStart + 1].dX + arOld[nStart + 2].dX) / 3.0; + mem2.dY = (2 * arOld[nStart + 1].dY + arOld[nStart + 2].dY) / 3.0; + + oArray.push_back(mem1); + oArray.push_back(mem2); + oArray.push_back(arOld[nStart + 2]); + + nStart += 2; + } + } + + CPartPath::CPartPath() : m_arSlices() + { + m_bFill = true; + m_bStroke = true; + + width = ShapeSizeVML; + height = ShapeSizeVML; //43200? + } + void CPartPath::FromXML(std::wstring strPath, NSCustomShapesConvert::CFormulasManager& pManager) + { + NSStringUtils::CheckPathOn_Fill_Stroke(strPath, m_bFill, m_bStroke); + std::vector oArray; + + NSStringUtils::ParsePath2(strPath, &oArray); + + ParamType eParamType = ptValue; + RulesType eRuler = rtEnd; + LONG lValue; + bool bRes = true; + + for (size_t nIndex = 0; nIndex < oArray.size(); ++nIndex) + { + lValue = GetValue(oArray[nIndex], eParamType, bRes); + if (bRes) + { + switch (eParamType) + { + case ptFormula: { lValue = pManager.m_arResults[lValue]; break; } + case ptAdjust: { lValue = (*(pManager.m_pAdjustments))[lValue]; break; } + default: break; + }; + if (0 != m_arSlices.size()) + { + m_arSlices[m_arSlices.size() - 1].AddParam(lValue); + } + } + else + { + eRuler = GetRuler(oArray[nIndex], bRes); + if (bRes) + { + if (rtNoFill == eRuler) + { + m_bFill = false; + } + else if (rtNoStroke == eRuler) + { + m_bStroke = false; + } + else + { + CSlice oSlice(eRuler); + m_arSlices.push_back(oSlice); + } + } + } + } + } + CPartPath& CPartPath::operator =(const CPartPath& oSrc) + { + m_bFill = oSrc.m_bFill; + m_bStroke = oSrc.m_bStroke; + + width = oSrc.width; + height = oSrc.height; + + m_arSlices.clear(); + + for (size_t nIndex = 0; nIndex < oSrc.m_arSlices.size(); ++nIndex) + { + m_arSlices.push_back(oSrc.m_arSlices[nIndex]); + } + return (*this); + } + + void CPath::FromXML(std::wstring strPath, NSCustomShapesConvert::CFormulasManager& pManager) + { + m_arParts.clear(); + std::vector oArray; + + NSStringUtils::ParseString(_T("e"), strPath, oArray); + + for (size_t nIndex = 0; nIndex < oArray.size(); ++nIndex) + { + CPartPath oPath; + m_arParts.push_back(oPath); + m_arParts.back().FromXML(oArray[nIndex], pManager); + } + } + CPath& CPath::operator =(const CPath& oSrc) + { + m_arParts.clear(); + + for (size_t nIndex = 0; nIndex < oSrc.m_arParts.size(); ++nIndex) + { + m_arParts.push_back(oSrc.m_arParts[nIndex]); + } + return (*this); + } + void CPath::SetCoordsize(LONG lWidth, LONG lHeight) + { + for (size_t nIndex = 0; nIndex < m_arParts.size(); ++nIndex) + { + m_arParts[nIndex].width = lWidth; + m_arParts[nIndex].height = lHeight; + } + } +} diff --git a/MsBinaryFile/Common/ODraw/PathShape.h b/MsBinaryFile/Common/ODraw/PathShape.h index 7316a0df7c..fed9cb5332 100644 --- a/MsBinaryFile/Common/ODraw/PathShape.h +++ b/MsBinaryFile/Common/ODraw/PathShape.h @@ -237,287 +237,22 @@ namespace NSCustomShapesConvert //LONG m_lX; //LONG m_lY; - CSlice(RulesType eType = rtMoveTo/*, LONG x = 0, LONG y = 0*/) - { - m_eRuler = eType; - m_nCountElementsPoint = 0; - //m_lX = x; - //m_lY = y; - } + CSlice(RulesType eType = rtMoveTo/*, LONG x = 0, LONG y = 0*/); + + void AddParam(LONG lParam); + CSlice& operator =(const CSlice& oSrc); - void AddParam(LONG lParam) - { - long lPoint = m_nCountElementsPoint % 2; - if (0 == lPoint) - { - Aggplus::POINT point; - point.x = lParam/* - m_lX*/; - point.y = 0; - m_arPoints.push_back(point); - } - else - { - m_arPoints[m_arPoints.size() - 1].y = lParam/* - m_lY*/; - } - ++m_nCountElementsPoint; - } - CSlice& operator =(const CSlice& oSrc) - { - m_eRuler = oSrc.m_eRuler; - m_arPoints.clear(); - - for (size_t nIndex = 0; nIndex < oSrc.m_arPoints.size(); ++nIndex) - { - m_arPoints.push_back(oSrc.m_arPoints[nIndex]); - } - return (*this); - } protected: - double GetAngle(double fCentreX, double fCentreY, double fX, double fY) - { - // - + (.. ) - double dX = fX - fCentreX; - double dY = fY - fCentreY; + double GetAngle(double fCentreX, double fCentreY, double fX, double fY); - double modDX = abs(dX); - double modDY = abs(dY); - - if ((modDX < 0.01) && (modDY < 0.01)) - { - return 0; - } - if ((modDX < 0.01) && (dY < 0)) - { - return -90; - } - else if (modDX < 0.01) - { - return 90; - } - if ((modDY < 0.01) && (dX < 0)) - { - return 180; - } - else if (modDY < 0.01) - { - return 0; - } - - double fAngle = atan(dY / dX); - fAngle *= (180 / M_PI); - if (dX > 0 && dY > 0) - { - return fAngle; - } - else if (dX > 0 && dY < 0) - { - return fAngle; - } - else if (dX < 0 && dY > 0) - { - //return fAngle + 180; - return 180 + fAngle; - } - else - { - //return fAngle + 180; - return fAngle - 180; - } - } - - inline double GetSweepAngle(const double& angleStart, const double& angleEnd) - { - if (angleStart >= angleEnd) - return angleEnd - angleStart; - else - return angleEnd - angleStart - 360; - } + double GetSweepAngle(const double& angleStart, const double& angleEnd); void ApplyElliptical(bool& bIsX, double& angleStart, double& angleSweet, - double& Left, double& Top, double& Width, double& Height, const CGeomShapeInfo::CPointD& pointCur) - { - // (x - y - x...) - if (bIsX) - { - angleStart = -90; - angleSweet = 90; + double& Left, double& Top, double& Width, double& Height, const CGeomShapeInfo::CPointD& pointCur); - if ((Width < 0) && (Height < 0)) - { - angleStart = 90; - Width *= -1; - Height *= -1; - Left = pointCur.dX - Width / 2; - Top = pointCur.dY - Height; - } - else if ((Width < 0) && (Height > 0)) - { - angleStart = -90; - angleSweet = -90; - Width *= -1; - Left = pointCur.dX - Width / 2; - Top = pointCur.dY; - } - else if ((Width > 0) && (Height < 0)) - { - angleStart = 90; - angleSweet = -90; - Height *= -1; - Left = pointCur.dX - Width / 2; - Top = pointCur.dY - Height; - } - else - { - Left = pointCur.dX - Width / 2; - Top = pointCur.dY; - } - } - else - { - angleStart = 180; - angleSweet = -90; + void ApplyLimo(CGeomShapeInfo& pGeomInfo, double& lX, double& lY); - if ((Width < 0) && (Height < 0)) - { - angleStart = 0; - Width *= -1; - Height *= -1; - Left = pointCur.dX - Width; - Top = pointCur.dY - Height / 2; - } - else if ((Width < 0) && (Height > 0)) - { - angleStart = 0; - angleSweet = 90; - Width *= -1; - Left = pointCur.dX - Width; - Top = pointCur.dY - Height / 2; - } - else if ((Width > 0) && (Height < 0)) - { - angleStart = 180; - angleSweet = 90; - Height *= -1; - Left = pointCur.dX; - Top = pointCur.dY - Height / 2; - } - else - { - Left = pointCur.dX; - Top = pointCur.dY - Height / 2; - } - } - bIsX = !bIsX; - } - - void ApplyLimo(CGeomShapeInfo& pGeomInfo, double& lX, double& lY) - { - if ((0 == pGeomInfo.m_dLimoX) || (0 == pGeomInfo.m_dLimoY)) - return; - - double dAspect = (double)pGeomInfo.m_dLimoX / pGeomInfo.m_dLimoY; - double lWidth = (dAspect * pGeomInfo.m_dHeight); - - if (lWidth < pGeomInfo.m_dWidth) - { - // LimoX - double lXc = pGeomInfo.m_dLeft + pGeomInfo.m_dWidth / 2; - if ((lX > lXc) || ((lX == lXc) && (pGeomInfo.m_oCurPoint.dX >= lXc))) - { - double lXNew = pGeomInfo.m_dLeft + ((lWidth / pGeomInfo.m_dWidth) * (lX - pGeomInfo.m_dLeft)); - lXNew += (pGeomInfo.m_dWidth - lWidth); - lX = lXNew; - } - //if (lX >= lXc) - //{ - // LONG lXNew = pGeomInfo->m_lLeft + (LONG)(((double)lWidth / pGeomInfo->m_lWidth) * (lX - pGeomInfo->m_lLeft)); - // if (pGeomInfo->m_oCurPoint.x >= lXc) - // { - // lXNew += (pGeomInfo->m_lWidth - lWidth); - // } - // lX = lXNew; - //} - } - else if (lWidth != pGeomInfo.m_dWidth) - { - // LimoY - double lHeight = (pGeomInfo.m_dWidth / dAspect); - double lYc = pGeomInfo.m_dTop + pGeomInfo.m_dHeight / 2; - if ((lY > lYc) || ((lY == lYc) && (pGeomInfo.m_oCurPoint.dY >= lYc))) - { - double lYNew = pGeomInfo.m_dTop + ((lHeight / pGeomInfo.m_dHeight) * (lY - pGeomInfo.m_dTop)); - lYNew += (pGeomInfo.m_dHeight - lHeight); - lY = lYNew; - } - } - } - - void Bez2_3(std::vector& oArray, RulesType& eType) - { - if (rtQuadrBesier == eType) - { - eType = rtCurveTo; - } - else if (rtOOXMLQuadBezTo == eType) - { - eType = rtOOXMLCubicBezTo; - } - else - { - return; - } - - std::vector arOld; - arOld.insert(arOld.end(),oArray.begin(), oArray.end()); - - oArray.clear(); - - size_t nStart = 0; - size_t nEnd = 2; - - size_t nCount = arOld.size(); - while (nStart < (nCount - 1)) - { - if (2 >= (nCount - nStart)) - { - // по идее такого быть не может - for (size_t i = nStart; i < nCount; ++i) - { - oArray.push_back(arOld[i]); - } - - nStart = nCount; - break; - } - - if (4 == (nCount - nStart)) - { - // ничего не поделаешь... делаем кривую третьего порядка - oArray.push_back(arOld[nStart]); - oArray.push_back(arOld[nStart + 1]); - oArray.push_back(arOld[nStart + 2]); - oArray.push_back(arOld[nStart + 3]); - - nStart += 4; - break; - } - - // значит есть еще - CGeomShapeInfo::CPointD mem1; - mem1.dX = (arOld[nStart].dX + 2 * arOld[nStart + 1].dX) / 3.0; - mem1.dY = (arOld[nStart].dY + 2 * arOld[nStart + 1].dY) / 3.0; - - CGeomShapeInfo::CPointD mem2; - mem2.dX = (2 * arOld[nStart + 1].dX + arOld[nStart + 2].dX) / 3.0; - mem2.dY = (2 * arOld[nStart + 1].dY + arOld[nStart + 2].dY) / 3.0; - - oArray.push_back(mem1); - oArray.push_back(mem2); - oArray.push_back(arOld[nStart + 2]); - - nStart += 2; - } - } + void Bez2_3(std::vector& oArray, RulesType& eType); }; class CPartPath @@ -530,81 +265,10 @@ namespace NSCustomShapesConvert std::vector m_arSlices; public: - CPartPath() : m_arSlices() - { - m_bFill = true; - m_bStroke = true; - - width = ShapeSizeVML; - height = ShapeSizeVML; //43200? - } - void FromXML(std::wstring strPath, NSCustomShapesConvert::CFormulasManager& pManager) - { - NSStringUtils::CheckPathOn_Fill_Stroke(strPath, m_bFill, m_bStroke); - std::vector oArray; + CPartPath(); - NSStringUtils::ParsePath2(strPath, &oArray); - - ParamType eParamType = ptValue; - RulesType eRuler = rtEnd; - LONG lValue; - bool bRes = true; - - for (size_t nIndex = 0; nIndex < oArray.size(); ++nIndex) - { - lValue = GetValue(oArray[nIndex], eParamType, bRes); - if (bRes) - { - switch (eParamType) - { - case ptFormula: { lValue = pManager.m_arResults[lValue]; break; } - case ptAdjust: { lValue = (*(pManager.m_pAdjustments))[lValue]; break; } - default: break; - }; - if (0 != m_arSlices.size()) - { - m_arSlices[m_arSlices.size() - 1].AddParam(lValue); - } - } - else - { - eRuler = GetRuler(oArray[nIndex], bRes); - if (bRes) - { - if (rtNoFill == eRuler) - { - m_bFill = false; - } - else if (rtNoStroke == eRuler) - { - m_bStroke = false; - } - else - { - CSlice oSlice(eRuler); - m_arSlices.push_back(oSlice); - } - } - } - } - } - - CPartPath& operator =(const CPartPath& oSrc) - { - m_bFill = oSrc.m_bFill; - m_bStroke = oSrc.m_bStroke; - - width = oSrc.width; - height = oSrc.height; - - m_arSlices.clear(); - - for (size_t nIndex = 0; nIndex < oSrc.m_arSlices.size(); ++nIndex) - { - m_arSlices.push_back(oSrc.m_arSlices[nIndex]); - } - return (*this); - } + void FromXML(std::wstring strPath, NSCustomShapesConvert::CFormulasManager& pManager); + CPartPath& operator =(const CPartPath& oSrc); }; class CPath @@ -612,39 +276,9 @@ namespace NSCustomShapesConvert public: std::vector m_arParts; - void FromXML(std::wstring strPath, NSCustomShapesConvert::CFormulasManager& pManager) - { - m_arParts.clear(); - std::vector oArray; + void FromXML(std::wstring strPath, NSCustomShapesConvert::CFormulasManager& pManager); - NSStringUtils::ParseString(_T("e"), strPath, oArray); - - for (size_t nIndex = 0; nIndex < oArray.size(); ++nIndex) - { - CPartPath oPath; - m_arParts.push_back(oPath); - m_arParts.back().FromXML(oArray[nIndex], pManager); - } - } - - CPath& operator =(const CPath& oSrc) - { - m_arParts.clear(); - - for (size_t nIndex = 0; nIndex < oSrc.m_arParts.size(); ++nIndex) - { - m_arParts.push_back(oSrc.m_arParts[nIndex]); - } - return (*this); - } - - void SetCoordsize(LONG lWidth, LONG lHeight) - { - for (size_t nIndex = 0; nIndex < m_arParts.size(); ++nIndex) - { - m_arParts[nIndex].width = lWidth; - m_arParts[nIndex].height = lHeight; - } - } + CPath& operator =(const CPath& oSrc); + void SetCoordsize(LONG lWidth, LONG lHeight); }; } diff --git a/MsBinaryFile/Common/ODraw/XmlWriter.cpp b/MsBinaryFile/Common/ODraw/XmlWriter.cpp new file mode 100644 index 0000000000..0b0fcb6b48 --- /dev/null +++ b/MsBinaryFile/Common/ODraw/XmlWriter.cpp @@ -0,0 +1,274 @@ +/* + * (c) Copyright Ascensio System SIA 2010-2019 + * + * 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 20A-12 Ernesta Birznieka-Upisha + * street, Riga, Latvia, EU, LV-1050. + * + * 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 "XmlWriter.h" + +namespace NSCustomShapesConvert +{ + CXmlWriter::CXmlWriter() : m_oWriter() + { + } + CXmlWriter::~CXmlWriter() + { + } + + std::wstring CXmlWriter::GetXmlString() + { + return m_oWriter.GetData(); + } + void CXmlWriter::ClearNoAttack() + { + m_oWriter.ClearNoAttack(); + } + int CXmlWriter::GetSize() + { + return (int)m_oWriter.GetCurSize(); + } + + // write value + void CXmlWriter::WriteString(const std::wstring& strValue) + { + m_oWriter.WriteString(strValue); + } + void CXmlWriter::WriteStringXML(std::wstring strValue) + { + m_oWriter.WriteEncodeXmlString(strValue); + } + void CXmlWriter::WriteDouble(const double& val) + { + m_oWriter.WriteString(XmlUtils::ToString(val)); + } + void CXmlWriter::WriteLONG(const long& val) + { + m_oWriter.WriteString(XmlUtils::ToString(val)); + + } + void CXmlWriter::WriteINT(const int& val) + { + m_oWriter.WriteString(XmlUtils::ToString(val)); + + } + void CXmlWriter::WriteDWORD(const DWORD& val) + { + m_oWriter.WriteString(XmlUtils::ToString(val)); + + } + void CXmlWriter::WriteDWORD_hex(const DWORD& val) + { + m_oWriter.WriteString(XmlUtils::ToString(val)); + + } + void CXmlWriter::WriteBool(const bool& val) + { + m_oWriter.WriteString(XmlUtils::ToString(val)); + } + void CXmlWriter::WriteAttribute(const std::wstring& strAttributeName, const std::wstring& val) + { + m_oWriter.WriteString(g_bstr_node_space); + m_oWriter.WriteString(strAttributeName); + m_oWriter.WriteString(g_bstr_node_equal); + m_oWriter.WriteString(g_bstr_node_quote); + m_oWriter.WriteString(val); + m_oWriter.WriteString(g_bstr_node_quote); + } + void CXmlWriter::WriteAttribute2(const std::wstring& strAttributeName, const std::wstring& val) + { + m_oWriter.WriteString(g_bstr_node_space); + m_oWriter.WriteString(strAttributeName); + m_oWriter.WriteString(g_bstr_node_equal); + m_oWriter.WriteString(g_bstr_node_quote); + m_oWriter.WriteEncodeXmlString(val); + m_oWriter.WriteString(g_bstr_node_quote); + } + void CXmlWriter::WriteAttribute(const std::wstring& strAttributeName, const double& val) + { + m_oWriter.WriteString(g_bstr_node_space); + m_oWriter.WriteString(strAttributeName); + m_oWriter.WriteString(g_bstr_node_equal); + m_oWriter.WriteString(g_bstr_node_quote); + WriteDouble(val); + m_oWriter.WriteString(g_bstr_node_quote); + } + void CXmlWriter::WriteAttribute(const std::wstring& strAttributeName, const int& val) + { + m_oWriter.WriteString(g_bstr_node_space); + m_oWriter.WriteString(strAttributeName); + m_oWriter.WriteString(g_bstr_node_equal); + m_oWriter.WriteString(g_bstr_node_quote); + WriteINT(val); + m_oWriter.WriteString(g_bstr_node_quote); + } + void CXmlWriter::WriteAttribute(const std::wstring& strAttributeName, const bool& val) + { + m_oWriter.WriteString(g_bstr_node_space); + m_oWriter.WriteString(strAttributeName); + m_oWriter.WriteString(g_bstr_node_equal); + m_oWriter.WriteString(g_bstr_node_quote); + WriteBool(val); + m_oWriter.WriteString(g_bstr_node_quote); + } + void CXmlWriter::WriteAttribute(const std::wstring& strAttributeName, const LONG& val) + { + m_oWriter.WriteString(g_bstr_node_space); + m_oWriter.WriteString(strAttributeName); + m_oWriter.WriteString(g_bstr_node_equal); + m_oWriter.WriteString(g_bstr_node_quote); + WriteLONG(val); + m_oWriter.WriteString(g_bstr_node_quote); + } + void CXmlWriter::WriteAttribute(const std::wstring& strAttributeName, const DWORD& val) + { + m_oWriter.WriteString(g_bstr_node_space); + m_oWriter.WriteString(strAttributeName); + m_oWriter.WriteString(g_bstr_node_equal); + m_oWriter.WriteString(g_bstr_node_quote); + WriteDWORD(val); + m_oWriter.WriteString(g_bstr_node_quote); + } + void CXmlWriter::WriteAttributeDWORD_hex(const std::wstring& strAttributeName, const DWORD& val) + { + m_oWriter.WriteString(g_bstr_node_space); + m_oWriter.WriteString(strAttributeName); + m_oWriter.WriteString(g_bstr_node_equal); + m_oWriter.WriteString(g_bstr_node_quote); + WriteDWORD_hex(val); + m_oWriter.WriteString(g_bstr_node_quote); + } + // document methods + void CXmlWriter::WriteNodeBegin(std::wstring strNodeName, bool bAttributed) + { + m_oWriter.WriteString(g_bstr_nodeopen); + m_oWriter.WriteString(strNodeName); + + if (!bAttributed) + m_oWriter.WriteString(g_bstr_nodeclose); + } + void CXmlWriter::WriteNodeEnd(std::wstring strNodeName, bool bEmptyNode, bool bEndNode) + { + if (bEmptyNode) + { + if (bEndNode) + m_oWriter.WriteString(g_bstr_nodeclose_slash); + else + m_oWriter.WriteString(g_bstr_nodeclose); + } + else + { + m_oWriter.WriteString(g_bstr_nodeopen_slash); + m_oWriter.WriteString(strNodeName); + m_oWriter.WriteString(g_bstr_nodeclose); + } + } + // write node values + void CXmlWriter::WriteNodeValue(const std::wstring& strNodeName, const std::wstring& val) + { + WriteNodeBegin(strNodeName); + WriteString(val); + WriteNodeEnd(strNodeName); + } + void CXmlWriter::WriteNodeValue(const std::wstring& strNodeName, const bool& val) + { + WriteNodeBegin(strNodeName); + + if (val) + WriteString(_T("1")); + else + WriteString(_T("0")); + + WriteNodeEnd(strNodeName); + } + void CXmlWriter::WriteNodeValue(const std::wstring& strNodeName, const double& val) + { + WriteNodeBegin(strNodeName); + WriteDouble(val); + WriteNodeEnd(strNodeName); + } + void CXmlWriter::WriteNodeValue(const std::wstring& strNodeName, const LONG& val) + { + WriteNodeBegin(strNodeName); + WriteLONG(val); + WriteNodeEnd(strNodeName); + } + void CXmlWriter::WriteNodeValue(const std::wstring& strNodeName, const int& val) + { + WriteNodeBegin(strNodeName); + WriteINT(val); + WriteNodeEnd(strNodeName); + } + void CXmlWriter::WriteNodeValue(const std::wstring& strNodeName, const DWORD& val) + { + WriteNodeBegin(strNodeName); + WriteDWORD(val); + WriteNodeEnd(strNodeName); + } + void CXmlWriter::WriteNodeValueDWORD_hex(const std::wstring& strNodeName, const DWORD& val) + { + WriteNodeBegin(strNodeName); + WriteDWORD_hex(val); + WriteNodeEnd(strNodeName); + } + + void CXmlWriter::StartNode(const std::wstring& name) + { + m_oWriter.WriteString(g_bstr_nodeopen); + m_oWriter.WriteString(name); + } + void CXmlWriter::StartAttributes() + { + // none + } + void CXmlWriter::EndAttributes() + { + m_oWriter.WriteString(g_bstr_nodeclose); + } + void CXmlWriter::EndNode(const std::wstring& name) + { + m_oWriter.WriteString(g_bstr_nodeopen_slash); + m_oWriter.WriteString(name); + m_oWriter.WriteString(g_bstr_nodeclose); + } + void CXmlWriter::ReplaceString(std::wstring from, std::wstring to) + { + // ужасная функция. вызывать ее не надо. не для этого класс писался. + std::wstring sCur = m_oWriter.GetData(); + + size_t start_pos = 0; + while((start_pos = sCur .find(from, start_pos)) != std::wstring::npos) + { + sCur .replace(start_pos, from.length(), to); + start_pos += to.length(); + } + + ClearNoAttack(); + WriteString(sCur); + } +} diff --git a/MsBinaryFile/Common/ODraw/XmlWriter.h b/MsBinaryFile/Common/ODraw/XmlWriter.h index 73254502e7..13bb9b6a21 100644 --- a/MsBinaryFile/Common/ODraw/XmlWriter.h +++ b/MsBinaryFile/Common/ODraw/XmlWriter.h @@ -60,230 +60,47 @@ namespace NSCustomShapesConvert public: NSStringUtils::CStringBuilder m_oWriter; - CXmlWriter() : m_oWriter() - { - } - ~CXmlWriter() - { - } + CXmlWriter(); + ~CXmlWriter(); - std::wstring GetXmlString() - { - return m_oWriter.GetData(); - } - void ClearNoAttack() - { - m_oWriter.ClearNoAttack(); - } - int GetSize() - { - return (int)m_oWriter.GetCurSize(); - } + std::wstring GetXmlString(); + void ClearNoAttack(); + int GetSize(); // write value - void WriteString(const std::wstring& strValue) - { - m_oWriter.WriteString(strValue); - } - void WriteStringXML(std::wstring strValue) - { - m_oWriter.WriteEncodeXmlString(strValue); - } - void WriteDouble(const double& val) - { - m_oWriter.WriteString(XmlUtils::ToString(val)); - } - void WriteLONG(const long& val) - { - m_oWriter.WriteString(XmlUtils::ToString(val)); - - } - void WriteINT(const int& val) - { - m_oWriter.WriteString(XmlUtils::ToString(val)); - - } - void WriteDWORD(const DWORD& val) - { - m_oWriter.WriteString(XmlUtils::ToString(val)); - - } - void WriteDWORD_hex(const DWORD& val) - { - m_oWriter.WriteString(XmlUtils::ToString(val)); - - } - void WriteBool(const bool& val) - { - m_oWriter.WriteString(XmlUtils::ToString(val)); - } - void WriteAttribute(const std::wstring& strAttributeName, const std::wstring& val) - { - m_oWriter.WriteString(g_bstr_node_space); - m_oWriter.WriteString(strAttributeName); - m_oWriter.WriteString(g_bstr_node_equal); - m_oWriter.WriteString(g_bstr_node_quote); - m_oWriter.WriteString(val); - m_oWriter.WriteString(g_bstr_node_quote); - } - void WriteAttribute2(const std::wstring& strAttributeName, const std::wstring& val) - { - m_oWriter.WriteString(g_bstr_node_space); - m_oWriter.WriteString(strAttributeName); - m_oWriter.WriteString(g_bstr_node_equal); - m_oWriter.WriteString(g_bstr_node_quote); - m_oWriter.WriteEncodeXmlString(val); - m_oWriter.WriteString(g_bstr_node_quote); - } - void WriteAttribute(const std::wstring& strAttributeName, const double& val) - { - m_oWriter.WriteString(g_bstr_node_space); - m_oWriter.WriteString(strAttributeName); - m_oWriter.WriteString(g_bstr_node_equal); - m_oWriter.WriteString(g_bstr_node_quote); - WriteDouble(val); - m_oWriter.WriteString(g_bstr_node_quote); - } - void WriteAttribute(const std::wstring& strAttributeName, const int& val) - { - m_oWriter.WriteString(g_bstr_node_space); - m_oWriter.WriteString(strAttributeName); - m_oWriter.WriteString(g_bstr_node_equal); - m_oWriter.WriteString(g_bstr_node_quote); - WriteINT(val); - m_oWriter.WriteString(g_bstr_node_quote); - } - void WriteAttribute(const std::wstring& strAttributeName, const bool& val) - { - m_oWriter.WriteString(g_bstr_node_space); - m_oWriter.WriteString(strAttributeName); - m_oWriter.WriteString(g_bstr_node_equal); - m_oWriter.WriteString(g_bstr_node_quote); - WriteBool(val); - m_oWriter.WriteString(g_bstr_node_quote); - } - void WriteAttribute(const std::wstring& strAttributeName, const LONG& val) - { - m_oWriter.WriteString(g_bstr_node_space); - m_oWriter.WriteString(strAttributeName); - m_oWriter.WriteString(g_bstr_node_equal); - m_oWriter.WriteString(g_bstr_node_quote); - WriteLONG(val); - m_oWriter.WriteString(g_bstr_node_quote); - } - void WriteAttribute(const std::wstring& strAttributeName, const DWORD& val) - { - m_oWriter.WriteString(g_bstr_node_space); - m_oWriter.WriteString(strAttributeName); - m_oWriter.WriteString(g_bstr_node_equal); - m_oWriter.WriteString(g_bstr_node_quote); - WriteDWORD(val); - m_oWriter.WriteString(g_bstr_node_quote); - } - void WriteAttributeDWORD_hex(const std::wstring& strAttributeName, const DWORD& val) - { - m_oWriter.WriteString(g_bstr_node_space); - m_oWriter.WriteString(strAttributeName); - m_oWriter.WriteString(g_bstr_node_equal); - m_oWriter.WriteString(g_bstr_node_quote); - WriteDWORD_hex(val); - m_oWriter.WriteString(g_bstr_node_quote); - } + void WriteString(const std::wstring& strValue); + void WriteStringXML(std::wstring strValue); + void WriteDouble(const double& val); + void WriteLONG(const long& val); + void WriteINT(const int& val); + void WriteDWORD(const DWORD& val); + void WriteDWORD_hex(const DWORD& val); + void WriteBool(const bool& val); + void WriteAttribute(const std::wstring& strAttributeName, const std::wstring& val); + void WriteAttribute2(const std::wstring& strAttributeName, const std::wstring& val); + void WriteAttribute(const std::wstring& strAttributeName, const double& val); + void WriteAttribute(const std::wstring& strAttributeName, const int& val); + void WriteAttribute(const std::wstring& strAttributeName, const bool& val); + void WriteAttribute(const std::wstring& strAttributeName, const LONG& val); + void WriteAttribute(const std::wstring& strAttributeName, const DWORD& val); + void WriteAttributeDWORD_hex(const std::wstring& strAttributeName, const DWORD& val); // document methods - void WriteNodeBegin(std::wstring strNodeName, bool bAttributed = false) - { - m_oWriter.WriteString(g_bstr_nodeopen); - m_oWriter.WriteString(strNodeName); - - if (!bAttributed) - m_oWriter.WriteString(g_bstr_nodeclose); - } - void WriteNodeEnd(std::wstring strNodeName, bool bEmptyNode = false, bool bEndNode = true) - { - if (bEmptyNode) - { - if (bEndNode) - m_oWriter.WriteString(g_bstr_nodeclose_slash); - else - m_oWriter.WriteString(g_bstr_nodeclose); - } - else - { - m_oWriter.WriteString(g_bstr_nodeopen_slash); - m_oWriter.WriteString(strNodeName); - m_oWriter.WriteString(g_bstr_nodeclose); - } - } + void WriteNodeBegin(std::wstring strNodeName, bool bAttributed = false); + void WriteNodeEnd(std::wstring strNodeName, bool bEmptyNode = false, bool bEndNode = true); // write node values - void WriteNodeValue(const std::wstring& strNodeName, const std::wstring& val) - { - WriteNodeBegin(strNodeName); - WriteString(val); - WriteNodeEnd(strNodeName); - } - void WriteNodeValue(const std::wstring& strNodeName, const bool& val) - { - WriteNodeBegin(strNodeName); - - if (val) - WriteString(_T("1")); - else - WriteString(_T("0")); - - WriteNodeEnd(strNodeName); - } - void WriteNodeValue(const std::wstring& strNodeName, const double& val) - { - WriteNodeBegin(strNodeName); - WriteDouble(val); - WriteNodeEnd(strNodeName); - } - void WriteNodeValue(const std::wstring& strNodeName, const LONG& val) - { - WriteNodeBegin(strNodeName); - WriteLONG(val); - WriteNodeEnd(strNodeName); - } - void WriteNodeValue(const std::wstring& strNodeName, const int& val) - { - WriteNodeBegin(strNodeName); - WriteINT(val); - WriteNodeEnd(strNodeName); - } - void WriteNodeValue(const std::wstring& strNodeName, const DWORD& val) - { - WriteNodeBegin(strNodeName); - WriteDWORD(val); - WriteNodeEnd(strNodeName); - } - void WriteNodeValueDWORD_hex(const std::wstring& strNodeName, const DWORD& val) - { - WriteNodeBegin(strNodeName); - WriteDWORD_hex(val); - WriteNodeEnd(strNodeName); - } + void WriteNodeValue(const std::wstring& strNodeName, const std::wstring& val); + void WriteNodeValue(const std::wstring& strNodeName, const bool& val); + void WriteNodeValue(const std::wstring& strNodeName, const double& val); + void WriteNodeValue(const std::wstring& strNodeName, const LONG& val); + void WriteNodeValue(const std::wstring& strNodeName, const int& val); + void WriteNodeValue(const std::wstring& strNodeName, const DWORD& val); + void WriteNodeValueDWORD_hex(const std::wstring& strNodeName, const DWORD& val); public: - - void StartNode(const std::wstring& name) - { - m_oWriter.WriteString(g_bstr_nodeopen); - m_oWriter.WriteString(name); - } - void StartAttributes() - { - // none - } - void EndAttributes() - { - m_oWriter.WriteString(g_bstr_nodeclose); - } - void EndNode(const std::wstring& name) - { - m_oWriter.WriteString(g_bstr_nodeopen_slash); - m_oWriter.WriteString(name); - m_oWriter.WriteString(g_bstr_nodeclose); - } + void StartNode(const std::wstring& name); + void StartAttributes(); + void EndAttributes(); + void EndNode(const std::wstring& name); template void WriteArray(const std::wstring& strName, const std::vector& arr) @@ -313,20 +130,6 @@ namespace NSCustomShapesConvert // ------------------------------------------------------------------------------------- - void ReplaceString(std::wstring from, std::wstring to) - { - // ужасная функция. вызывать ее не надо. не для этого класс писался. - std::wstring sCur = m_oWriter.GetData(); - - size_t start_pos = 0; - while((start_pos = sCur .find(from, start_pos)) != std::wstring::npos) - { - sCur .replace(start_pos, from.length(), to); - start_pos += to.length(); - } - - ClearNoAttack(); - WriteString(sCur); - } + void ReplaceString(std::wstring from, std::wstring to); }; } diff --git a/MsBinaryFile/Common/Vml/BaseShape.h b/MsBinaryFile/Common/Vml/BaseShape.h index b0472bbd78..e6720e76ba 100644 --- a/MsBinaryFile/Common/Vml/BaseShape.h +++ b/MsBinaryFile/Common/Vml/BaseShape.h @@ -36,7 +36,7 @@ #include -#define DEFINE_SHAPE_CLASS(Class, BaseClass) \ +#define DEFINE_SHAPE_CLASS(Class, BaseClass) \ class Class : public BaseClass \ { \ public: \ diff --git a/MsBinaryFile/Common/ODraw/BaseShape_1.cpp b/MsBinaryFile/Common/Vml/PPTShape/BinaryReader.cpp similarity index 54% rename from MsBinaryFile/Common/ODraw/BaseShape_1.cpp rename to MsBinaryFile/Common/Vml/PPTShape/BinaryReader.cpp index 08e0162177..ec01273bc1 100644 --- a/MsBinaryFile/Common/ODraw/BaseShape_1.cpp +++ b/MsBinaryFile/Common/Vml/PPTShape/BinaryReader.cpp @@ -1,4 +1,4 @@ -/* +/* * (c) Copyright Ascensio System SIA 2010-2019 * * This program is a free software product. You can redistribute it and/or @@ -29,22 +29,67 @@ * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode * */ -#pragma once -#include "BaseShape.h" +#include "BinaryReader.h" +#include "../../../../OOXML/Base/Base.h" -#include "CustomShape.h" - -namespace NSCustomShapesConvert +namespace ODRAW { -CBaseShape* CBaseShape::CreateByType( int ShapeType) -{ - return CCustomShape::CreateByType((oox::MSOSPT)ShapeType); -} + CBinaryReader::CBinaryReader(BYTE* pBuffer, DWORD lCount) + { + m_pBuffer = pBuffer; + m_lCount = lCount; -bool CBaseShape::SetType( int ShapeType) -{ + m_lOrigin = 0; + } + CBinaryReader::~CBinaryReader() + { + m_pBuffer = NULL; + m_lCount = 0; + } + LONG CBinaryReader::ReadLONG() // int32 подразумевается + { + DWORD lOldOrigin = m_lOrigin; + m_lOrigin += 4; - return ((CCustomShape*)this)->SetShapeType((oox::MSOSPT)ShapeType); -} + BINARY_READER_CHECK_OUT_RANGE(m_lOrigin, m_lCount) + + return *(_INT32*)(m_pBuffer + lOldOrigin); + } + DWORD CBinaryReader::ReadDWORD() + { + DWORD lOldOrigin = m_lOrigin; + m_lOrigin += 4; + + BINARY_READER_CHECK_OUT_RANGE(m_lOrigin, m_lCount) + + return *(DWORD*)(m_pBuffer + lOldOrigin); + } + WORD CBinaryReader::ReadWORD() + { + DWORD lOldOrigin = m_lOrigin; + m_lOrigin += 2; + + BINARY_READER_CHECK_OUT_RANGE(m_lOrigin, m_lCount) + + return *(WORD*)(m_pBuffer + lOldOrigin); + } + SHORT CBinaryReader::ReadSHORT() + { + DWORD lOldOrigin = m_lOrigin; + m_lOrigin += 2; + + BINARY_READER_CHECK_OUT_RANGE(m_lOrigin, m_lCount) + + return *(short*)(m_pBuffer + lOldOrigin); + } + double CBinaryReader::ReadDOUBLE() + { + DWORD lOldOrigin = m_lOrigin; + m_lOrigin += sizeof(double); + + BINARY_READER_CHECK_OUT_RANGE(m_lOrigin, m_lCount) + + return *(SHORT*)(m_pBuffer + lOldOrigin); + } } diff --git a/MsBinaryFile/Common/Vml/PPTShape/BinaryReader.h b/MsBinaryFile/Common/Vml/PPTShape/BinaryReader.h index e30e4dbf49..f822ae604c 100644 --- a/MsBinaryFile/Common/Vml/PPTShape/BinaryReader.h +++ b/MsBinaryFile/Common/Vml/PPTShape/BinaryReader.h @@ -30,7 +30,8 @@ * */ #pragma once -#include "../../../../../../DesktopEditor/common/Types.h" + +#include "../../../../DesktopEditor/common/Types.h" namespace ODRAW { @@ -50,63 +51,13 @@ namespace ODRAW DWORD m_lOrigin; public: - CBinaryReader(BYTE* pBuffer, DWORD lCount) - { - m_pBuffer = pBuffer; - m_lCount = lCount; + CBinaryReader(BYTE* pBuffer, DWORD lCount); + ~CBinaryReader(); - m_lOrigin = 0; - } - ~CBinaryReader() - { - m_pBuffer = NULL; - m_lCount = 0; - } - - LONG ReadLONG() // int32 подразумевается - { - DWORD lOldOrigin = m_lOrigin; - m_lOrigin += 4; - - BINARY_READER_CHECK_OUT_RANGE(m_lOrigin, m_lCount) - - return *(_INT32*)(m_pBuffer + lOldOrigin); - } - DWORD ReadDWORD() - { - DWORD lOldOrigin = m_lOrigin; - m_lOrigin += 4; - - BINARY_READER_CHECK_OUT_RANGE(m_lOrigin, m_lCount) - - return *(DWORD*)(m_pBuffer + lOldOrigin); - } - WORD ReadWORD() - { - DWORD lOldOrigin = m_lOrigin; - m_lOrigin += 2; - - BINARY_READER_CHECK_OUT_RANGE(m_lOrigin, m_lCount) - - return *(WORD*)(m_pBuffer + lOldOrigin); - } - SHORT ReadSHORT() - { - DWORD lOldOrigin = m_lOrigin; - m_lOrigin += 2; - - BINARY_READER_CHECK_OUT_RANGE(m_lOrigin, m_lCount) - - return *(short*)(m_pBuffer + lOldOrigin); - } - double ReadDOUBLE() - { - DWORD lOldOrigin = m_lOrigin; - m_lOrigin += sizeof(double); - - BINARY_READER_CHECK_OUT_RANGE(m_lOrigin, m_lCount) - - return *(SHORT*)(m_pBuffer + lOldOrigin); - } + LONG ReadLONG(); // int32 подразумевается + DWORD ReadDWORD(); + WORD ReadWORD(); + SHORT ReadSHORT(); + double ReadDOUBLE(); }; } diff --git a/MsBinaryFile/Common/Vml/PPTShape/CustomGeomShape.cpp b/MsBinaryFile/Common/Vml/PPTShape/CustomGeomShape.cpp new file mode 100644 index 0000000000..60059f7e41 --- /dev/null +++ b/MsBinaryFile/Common/Vml/PPTShape/CustomGeomShape.cpp @@ -0,0 +1,907 @@ +/* + * (c) Copyright Ascensio System SIA 2010-2019 + * + * 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 20A-12 Ernesta Birznieka-Upisha + * street, Riga, Latvia, EU, LV-1050. + * + * 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 "CustomGeomShape.h" + +namespace NSCustomVML +{ + CSegment::CSegment(ODRAW::RulesType eType, WORD nCount) + { + m_eRuler = eType; + m_nCount = nCount; + } + CSegment::CSegment(const CSegment& oSrc) + { + m_eRuler = oSrc.m_eRuler; + m_nCount = oSrc.m_nCount; + } + CSegment& CSegment::operator=(const CSegment& oSrc) + { + m_eRuler = oSrc.m_eRuler; + m_nCount = oSrc.m_nCount; + + return (*this); + } + CSegment::~CSegment() + { + } + int CSegment::Read(WORD value)//from rtf segments + { + int repeate = 0; + if (value >= 0x2000 && value < 0x20FF) + { + repeate = value & 0x0FFF; + value &= 0xFF00; + } + + m_nCount = 0; + switch (value) + { + case 0x0001: // lineto + m_eRuler = ODRAW::rtLineTo; + m_nCount = 1; + break; + case 0x4000: // moveto + m_eRuler = ODRAW::rtMoveTo; + m_nCount = 1; + break; + case 0x2000: // curveto + m_eRuler = ODRAW::rtCurveTo; + m_nCount = 3; + break; + case 0xb300: // arcto + m_eRuler = ODRAW::rtArc; + m_nCount = 2; + break; + case 0xac00: + case 0xaa00: // nofill + case 0xad00: + m_eRuler = ODRAW::rtNoFill; + break; + case 0xab00: // nostroke + m_eRuler = ODRAW::rtNoStroke; + break; + case 0x6001: // close + m_eRuler = ODRAW::rtClose; + break; + case 0x8000: // end + m_eRuler = ODRAW::rtEnd; + break; + default: // given number of lineto elements + m_eRuler = ODRAW::rtLineTo; + m_nCount = value; + break; + } + return (std::max)(1, repeate); + } + void CSegment::Read(POLE::Stream* pStream)//from binary ms segments + { + WORD mem = StreamUtils::ReadWORD(pStream); + BYTE type = mem & 0x07; + + if (type <= 4) + { + m_eRuler = (ODRAW::RulesType)type; + m_nCount = (mem >> 3) & 0x1FFF; + return; + } + + mem = (mem >> 3) & 0x1FFF; + type = mem & 0x1F; + + switch (type) + { + case 0x00: + { + m_eRuler = ODRAW::rtLineTo; + break; + } + case 0x01: + { + m_eRuler = ODRAW::rtAngleEllipseTo; + break; + } + case 0x02: + { + m_eRuler = ODRAW::rtAngleEllipse; + break; + } + case 0x03: + { + m_eRuler = ODRAW::rtArcTo; + break; + } + case 0x04: + { + m_eRuler = ODRAW::rtArc; + break; + } + case 0x05: + { + m_eRuler = ODRAW::rtClockwiseArcTo; + break; + } + case 0x06: + { + m_eRuler = ODRAW::rtClockwiseArc; + break; + } + case 0x07: + { + m_eRuler = ODRAW::rtEllipticalQuadrX; + break; + } + case 0x08: + { + m_eRuler = ODRAW::rtEllipticalQuadrY; + break; + } + case 0x09: + { + m_eRuler = ODRAW::rtQuadrBesier; + break; + } + case 0x0A: + { + m_eRuler = ODRAW::rtNoFill; + break; + } + case 0x0B: + { + m_eRuler = ODRAW::rtNoStroke; + break; + } + case 0x15: + { + m_eRuler = ODRAW::rtFillColor; + break; + } + case 0x16: + { + m_eRuler = ODRAW::rtLineColor; + break; + } + default: + { + m_eRuler = ODRAW::rtCurveTo; + } + }; + + m_nCount = (mem >> 5) & 0x00FF; + } + void CSegment::Read(ODRAW::CBinaryReader& oReader)//from binary ms segments + { + WORD mem = oReader.ReadWORD(); + + BYTE type = (mem >> 13 & 0x07); + if (type <= 4) + { + m_eRuler = (ODRAW::RulesType)type; + m_nCount = (mem & 0x1FFF); + m_nCount = (WORD)GetCountPoints2(m_eRuler, m_nCount); + return; + } + + type = (mem >> 8) & 0x1F; + mem = mem & 0xFF; + + switch (type) + { + case 0x00: + { + m_eRuler = ODRAW::rtLineTo; + break; + } + case 0x01: + { + m_eRuler = ODRAW::rtAngleEllipseTo; + break; + } + case 0x02: + { + m_eRuler = ODRAW::rtAngleEllipse; + break; + } + case 0x03: + { + m_eRuler = ODRAW::rtArcTo; + break; + } + case 0x04: + { + m_eRuler = ODRAW::rtArc; + break; + } + case 0x05: + { + m_eRuler = ODRAW::rtClockwiseArcTo; + break; + } + case 0x06: + { + m_eRuler = ODRAW::rtClockwiseArc; + break; + } + case 0x07: + { + m_eRuler = ODRAW::rtEllipticalQuadrX; + break; + } + case 0x08: + { + m_eRuler = ODRAW::rtEllipticalQuadrY; + break; + } + case 0x09: + { + m_eRuler = ODRAW::rtQuadrBesier; + break; + } + case 0x0A: + { + m_eRuler = ODRAW::rtNoFill; + break; + } + case 0x0B: + { + m_eRuler = ODRAW::rtNoStroke; + break; + } + case 0x0C: + case 0x10: + { + m_eRuler = ODRAW::rtLineTo; + break; + } + case 0x0D: + case 0x0E: + case 0x0F: + case 0x11: + case 0x12: + case 0x13: + case 0x14: + { + m_eRuler = ODRAW::rtCurveTo; + break; + } + case 0x15: + { + m_eRuler = ODRAW::rtFillColor; + break; + } + case 0x16: + { + m_eRuler = ODRAW::rtLineColor; + break; + } + default: + { + m_eRuler = ODRAW::rtCurveTo; + } + }; + + m_nCount = (WORD)mem; + m_nCount = (WORD)GetCountPoints2(m_eRuler, m_nCount); + //m_nCount = (WORD)GetCountPoints2(m_eRuler); + } + + CGuide::CGuide() + { + m_eType = NSGuidesVML::ftVal; + + m_param_type1 = 0; + m_param_type2 = 0; + m_param_type3 = 0; + + m_param_value1 = 0; + m_param_value2 = 0; + m_param_value3 = 0; + + m_lShapeWidth = ShapeSizeVML; + m_lShapeHeight = ShapeSizeVML; + } + CGuide::CGuide(const CGuide& oSrc) + { + *this = oSrc; + } + CGuide& CGuide::operator=(const CGuide& oSrc) + { + m_eType = oSrc.m_eType; + + m_param_type1 = oSrc.m_param_type1; + m_param_type2 = oSrc.m_param_type2; + m_param_type3 = oSrc.m_param_type3; + + m_param_value1 = oSrc.m_param_value1; + m_param_value2 = oSrc.m_param_value2; + m_param_value3 = oSrc.m_param_value3; + + m_lShapeWidth = oSrc.m_lShapeWidth; + m_lShapeHeight = oSrc.m_lShapeHeight; + + return *this; + } + void CGuide::SetToFormula(NSGuidesVML::CFormula& oFormula) + { + oFormula.m_eFormulaType = m_eType; + + SetParam(m_param_type1, m_param_value1, oFormula.m_eType1, oFormula.m_lParam1); + SetParam(m_param_type2, m_param_value2, oFormula.m_eType2, oFormula.m_lParam2); + SetParam(m_param_type3, m_param_value3, oFormula.m_eType3, oFormula.m_lParam3); + } + void CGuide::Read(POLE::Stream* pStream) + { + WORD ftType = StreamUtils::ReadWORD(pStream); + + m_eType = NSGuidesVML::FormulaType(ftType & 0x1FFF); + + m_param_type1 = (BYTE)(ftType & 0x04); + m_param_type2 = (BYTE)(ftType & 0x02); + m_param_type3 = (BYTE)(ftType & 0x01); + + m_param_value1 = StreamUtils::ReadWORD(pStream); + m_param_value2 = StreamUtils::ReadWORD(pStream); + m_param_value3 = StreamUtils::ReadWORD(pStream); + } + void CGuide::Read(ODRAW::CBinaryReader& oReader) + { + WORD ftType = oReader.ReadWORD(); + + m_eType = NSGuidesVML::FormulaType(ftType & 0x1FFF); + + m_param_type1 = (BYTE)(ftType & 0x04); + m_param_type2 = (BYTE)(ftType & 0x02); + m_param_type3 = (BYTE)(ftType & 0x01); + + m_param_value1 = oReader.ReadWORD(); + m_param_value2 = oReader.ReadWORD(); + m_param_value3 = oReader.ReadWORD(); + } + void CGuide::SetParam(BYTE type, WORD param, ParamType& param_type, LONG& param_value) + { + if (0 == type) + { + param_type = ptValue; + param_value = (LONG)param; + } + + if (0x0140 == param) + { + param_type = ptValue; + param_value = ShapeSizeVML / 2; + return; + } + if (0x0141 == param) + { + param_type = ptValue; + param_value = ShapeSizeVML / 2; + return; + } + if (0x0142 == param) + { + param_type = ptValue; + param_value = ShapeSizeVML; + return; + } + if (0x0143 == param) + { + param_type = ptValue; + param_value = ShapeSizeVML; + return; + } + + if ((0x0147 <= param) && (param <= 0x014E)) + { + param_type = ptAdjust; + param_value = (LONG)(param - 0x0147); + return; + } + + if ((0x0400 <= param) && (param <= 0x047F)) + { + param_type = ptFormula; + param_value = (LONG)(param - 0x0400); + return; + } + + param_type = ptValue; + param_value = ShapeSizeVML; + } + + CCustomVML::CCustomVML() : m_pAdjustValues(NULL) + { + m_ePath = ODRAW::rtCurveTo/*rtLineTo*/; + + m_bIsVerticesPresent = false; + m_bIsPathPresent = false; + } + CCustomVML::CCustomVML(const CCustomVML& oSrc) + { + *this = oSrc; + } + CCustomVML& CCustomVML::operator=(const CCustomVML& oSrc) + { + m_ePath = oSrc.m_ePath; + + m_arVertices.clear(); + m_arVertices.insert(m_arVertices.end(), oSrc.m_arVertices.begin(), oSrc.m_arVertices.end()); + + m_arSegments.clear(); + m_arSegments.insert(m_arSegments.end(), oSrc.m_arSegments.begin(), oSrc.m_arSegments.end()); + + m_arGuides.clear(); + m_arGuides.insert(m_arGuides.end(), oSrc.m_arGuides.begin(), oSrc.m_arGuides.end()); + + m_pAdjustValues = oSrc.m_pAdjustValues; + + m_bIsPathPresent = oSrc.m_bIsPathPresent; + m_bIsVerticesPresent = oSrc.m_bIsVerticesPresent; + + m_oBrush = oSrc.m_oBrush; + m_oPen = oSrc.m_oPen; + + return *this; + } + CCustomVML::~CCustomVML() + { + } + bool CCustomVML::IsCustom() + { + return (m_bIsVerticesPresent && m_bIsPathPresent); + } + void CCustomVML::SetPath(ODRAW::RulesType ePath) + { + m_ePath = ePath; + m_bIsPathPresent = true; + } + void CCustomVML::LoadVertices(std::vector> values) + { + if (!values.empty()) + m_bIsVerticesPresent = true; + + m_arVertices.clear(); + + for (size_t ind = 0; ind < values.size(); ++ind) + { + Aggplus::POINT oPoint; + + oPoint.x = values[ind].first; + oPoint.y = values[ind].second; + + LONG lMinF = (LONG)0x80000000; + LONG lMaxF = (LONG)0x8000007F; + if (lMinF <= oPoint.x) + { + int nGuideIndex = (_UINT32)oPoint.x - 0x80000000; + + bool b = false; + } + if (lMinF <= oPoint.y) + { + int nGuideIndex = (_UINT32)oPoint.y - 0x80000000; + + bool b = false; + } + + m_arVertices.push_back(oPoint); + } + } + void CCustomVML::LoadConnectionSitesDir(CProperty* pProperty) + { + ODRAW::CBinaryReader oReader(pProperty->m_pOptions, pProperty->m_lValue); + m_arConnectionSitesDir.clear(); + + WORD lCount = (WORD)(pProperty->m_lValue / 4); + + for (WORD lIndex = 0; lIndex < lCount; ++lIndex) + { + _UINT32 v = oReader.ReadLONG(); + double val = (double)((WORD)(v >> 16) + ((WORD)(v) / 65536.0)); + m_arConnectionSitesDir.push_back(val); + } + } + void CCustomVML::LoadConnectionSites(CProperty* pProperty) + { + ODRAW::CBinaryReader oReader(pProperty->m_pOptions, pProperty->m_lValue); + m_arConnectionSites.clear(); + + WORD lCount = (WORD)(pProperty->m_lValue / 8); + if (pProperty->m_bIsTruncated) + { + lCount = (WORD)(pProperty->m_lValue / 4); + } + + for (WORD lIndex = 0; lIndex < lCount; ++lIndex) + { + Aggplus::POINT oPoint; + if (pProperty->m_bIsTruncated) + { + oPoint.x = (short)oReader.ReadWORD(); + oPoint.y = (short)oReader.ReadWORD(); + } + else + { + oPoint.x = oReader.ReadLONG(); + oPoint.y = oReader.ReadLONG(); + } + + LONG lMinF = (LONG)0x80000000; + LONG lMaxF = (LONG)0x8000007F; + if (lMinF <= oPoint.x) + { + int nGuideIndex = (_UINT32)oPoint.x - 0x80000000; + + bool b = false; + } + if (lMinF <= oPoint.y) + { + int nGuideIndex = (_UINT32)oPoint.y - 0x80000000; + + bool b = false; + } + + m_arConnectionSites.push_back(oPoint); + } + } + void CCustomVML::LoadVertices(CProperty* pProperty) + { + ODRAW::CBinaryReader oReader(pProperty->m_pOptions, pProperty->m_lValue); + + m_arVertices.clear(); + + WORD lCount = (WORD)(pProperty->m_lValue / 8); + if (pProperty->m_bIsTruncated) + { + lCount = (WORD)(pProperty->m_lValue / 4); + } + + if (lCount > 0) + { + m_bIsVerticesPresent = true; + } + + for (WORD lIndex = 0; lIndex < lCount; ++lIndex) + { + Aggplus::POINT oPoint; + if (pProperty->m_bIsTruncated) + { + oPoint.x = (short)oReader.ReadWORD(); + oPoint.y = (short)oReader.ReadWORD(); + } + else + { + oPoint.x = oReader.ReadLONG(); + oPoint.y = oReader.ReadLONG(); + } + + LONG lMinF = (LONG)0x80000000; + LONG lMaxF = (LONG)0x8000007F; + if (lMinF <= oPoint.x) + { + int nGuideIndex = (_UINT32)oPoint.x - 0x80000000; + + bool b = false; + } + if (lMinF <= oPoint.y) + { + int nGuideIndex = (_UINT32)oPoint.y - 0x80000000; + + bool b = false; + } + + m_arVertices.push_back(oPoint); + } + } + void CCustomVML::LoadAHs(CProperty* pProperty) + { + } + void CCustomVML::LoadSegments(std::vector values) + { + m_arSegments.clear(); + + if (!values.empty()) + m_bIsPathPresent = true; + + for (size_t ind = 0; ind < values.size(); ++ind) + { + CSegment oInfo; + int count = oInfo.Read(values[ind]); + + if (0 == oInfo.m_nCount) + { + if ((ODRAW::rtEnd != oInfo.m_eRuler) && + (ODRAW::rtNoFill != oInfo.m_eRuler) && + (ODRAW::rtNoStroke != oInfo.m_eRuler) && + (ODRAW::rtClose != oInfo.m_eRuler)) + { + continue; + } + } + for (int i = 0 ; i < count; i++) + m_arSegments.push_back(oInfo); + } + } + void CCustomVML::LoadSegments(CProperty* pProperty) + { + ODRAW::CBinaryReader oReader(pProperty->m_pOptions, pProperty->m_lValue); + m_arSegments.clear(); + + WORD lCount = (WORD)(pProperty->m_lValue / 2); + + if (lCount > 0) m_bIsPathPresent = true; + + for (WORD lIndex = 0; lIndex < lCount; ++lIndex) + { + CSegment oInfo; + oInfo.Read(oReader); + + if (0 == oInfo.m_nCount) + { + if ((ODRAW::rtEnd != oInfo.m_eRuler) && + (ODRAW::rtNoFill != oInfo.m_eRuler) && + (ODRAW::rtNoStroke != oInfo.m_eRuler) && + (ODRAW::rtClose != oInfo.m_eRuler)) + { + continue; + } + } + + //if (rtClose == oInfo.m_eRuler) + //{ + // // проводим линию + // CSegment oInfo2(rtLineTo, 1); + // m_arSegments.push_back(oInfo2); + //} + + m_arSegments.push_back(oInfo); + } + } + void CCustomVML::LoadGuides(CProperty* pProperty) + { + ODRAW::CBinaryReader oReader(pProperty->m_pOptions, pProperty->m_lValue); + WORD lCount = (WORD)(pProperty->m_lValue / 4); + + for (WORD lIndex = 0; lIndex < lCount; ++lIndex) + { + CGuide oInfo; + oInfo.Read(oReader); + m_arGuides.push_back(oInfo); + } + } + void CCustomVML::LoadInscribe(CProperty* pProperty) + { + ODRAW::CBinaryReader oReader(pProperty->m_pOptions, pProperty->m_lValue); + m_arInscribe.clear(); + + WORD lCount = (WORD)(pProperty->m_lValue / 16); + if (pProperty->m_bIsTruncated) + { + lCount = (WORD)(pProperty->m_lValue / 8); + } + + for (WORD lIndex = 0; lIndex < lCount; ++lIndex) + { + Aggplus::RECT oRect; + if (pProperty->m_bIsTruncated) + { + oRect.left = (short)oReader.ReadWORD(); + oRect.right = (short)oReader.ReadWORD(); + oRect.top = (short)oReader.ReadWORD(); + oRect.bottom = (short)oReader.ReadWORD(); + } + else + { + oRect.left = (short)oReader.ReadLONG(); + oRect.right = (short)oReader.ReadLONG(); + oRect.top = (short)oReader.ReadLONG(); + oRect.bottom = (short)oReader.ReadLONG(); + } + m_arInscribe.push_back(oRect); + } + } + void CCustomVML::LoadAdjusts(LONG lIndex, LONG lValue) + { + if (NULL == m_pAdjustValues) + return; + + LONG lCount = (LONG)m_pAdjustValues->size(); + + while (lCount <= lIndex) + { + m_pAdjustValues->push_back(0); + lCount = (LONG)m_pAdjustValues->size(); + } + + (*m_pAdjustValues)[lIndex] = lValue; + } + void CCustomVML::SetAdjusts(std::vector* pList) + { + m_pAdjustValues = pList; + } + void CCustomVML::ToCustomShape(ODRAW::CBaseShape* pShape, NSGuidesVML::CFormulasManager& oManager) + { + if ((NULL == pShape) || (!IsCustom())) + return; + + oManager.Clear(); + // сначала заполним формулы + for (size_t nIndex = 0; nIndex < m_arGuides.size(); ++nIndex) + { + NSGuidesVML::CFormula oF; + m_arGuides[nIndex].SetToFormula(oF); + oManager.AddFormula(oF); + } + + oManager.Clear(m_pAdjustValues); + + std::wstring strPath = _T(""); + + bool bBreak = false; + + long lMinF = (_INT32)0x80000000; + long lMaxF = (_INT32)0x8000007F; + + int nGuideIndex_x , nGuideIndex_y; + + if (0 == m_arSegments.size()) + { + strPath = GetRulerVML(m_ePath); + + for (size_t nIndex = 0; nIndex < m_arVertices.size(); ++nIndex) + { + nGuideIndex_x = nGuideIndex_y = -1; + + if (lMaxF > m_arVertices[nIndex].x ) nGuideIndex_x = (_UINT32)m_arVertices[nIndex].x - (_UINT32)lMinF; + if (lMaxF > m_arVertices[nIndex].y ) nGuideIndex_y = (_UINT32)m_arVertices[nIndex].y - (_UINT32)lMinF; + + if (nGuideIndex_x >= 0 ) + { + strPath += std::to_wstring(m_arGuides[nGuideIndex_x].m_param_value1) + L","; + } + else + { + strPath += std::to_wstring(m_arVertices[nIndex].x) + L","; + } + if (nGuideIndex_y >= 0) + { + strPath += std::to_wstring(m_arGuides[nGuideIndex_y].m_param_value1) + L","; + } + else + { + strPath += std::to_wstring(m_arVertices[nIndex].y) + L","; + } + + } + strPath.erase(strPath.length() - 1); + } + else + { + size_t nStart = 0; + size_t nEnd = 0; + for (size_t nS = 0; nS < m_arSegments.size(); ++nS) + { + if (bBreak) + { + if ((ODRAW::rtEnd != m_arSegments[nS].m_eRuler) && + (ODRAW::rtNoFill != m_arSegments[nS].m_eRuler) && + (ODRAW::rtNoStroke != m_arSegments[nS].m_eRuler) && + (ODRAW::rtClose != m_arSegments[nS].m_eRuler)) + { + strPath += _T("e"); + break; + } + } + + if ((ODRAW::rtFillColor == m_arSegments[nS].m_eRuler) || (ODRAW::rtLineColor == m_arSegments[nS].m_eRuler)) + { + if (nStart < m_arVertices.size()) + { + if (ODRAW::rtFillColor == m_arSegments[nS].m_eRuler) + { + m_oBrush.Color1 = (_UINT32)m_arVertices[nStart].x; + m_oBrush.Color2 = (_UINT32)m_arVertices[nStart].y; + } + else + { + m_oPen.Color = (_UINT32)m_arVertices[nStart].x; + } + } + nEnd = nStart + m_arSegments[nS].m_nCount; + if (nEnd > m_arVertices.size()) + nEnd = m_arVertices.size(); + nStart = nEnd; + + if (nEnd == m_arVertices.size()) + { + bBreak = true; + } + continue; + } + + strPath += GetRulerVML(m_arSegments[nS].m_eRuler); + + nEnd = nStart + m_arSegments[nS].m_nCount; + if (nEnd > m_arVertices.size()) + nEnd = m_arVertices.size(); + + for (size_t nV = nStart; nV < nEnd; ++nV) + { + nGuideIndex_x = nGuideIndex_y = -1; + + if (lMaxF > m_arVertices[nV].x ) nGuideIndex_x = (_UINT32)m_arVertices[nV].x - (_UINT32)lMinF; + if (lMaxF > m_arVertices[nV].y ) nGuideIndex_y = (_UINT32)m_arVertices[nV].y - (_UINT32)lMinF; + + std::wstring str = _T(""); + if (nGuideIndex_x >= 0 && nGuideIndex_x < (int)m_arGuides.size()) + { + strPath += std::to_wstring(m_arGuides[nGuideIndex_x].m_param_value1) + L","; + } + else + { + strPath += std::to_wstring(m_arVertices[nV].x) + L","; + } + if (nGuideIndex_y >= 0 && nGuideIndex_y < (int)m_arGuides.size()) + { + strPath += std::to_wstring(m_arGuides[nGuideIndex_y].m_param_value1) + L","; + } + else + { + strPath += std::to_wstring(m_arVertices[nV].y) + L","; + } + } + + if (nEnd != nStart) + { + strPath.erase(strPath.length() - 1); + } + nStart = nEnd; + + if (nEnd == m_arVertices.size()) + { + bBreak = true; + } + } + } + + oManager.CalculateResults(); + + pShape->LoadPathList(strPath); + + /*std::wstring str = _T("\ + \ + \ + \ + ");*/ + + //pShape->LoadFromXML(str); + } +} diff --git a/MsBinaryFile/Common/Vml/PPTShape/CustomGeomShape.h b/MsBinaryFile/Common/Vml/PPTShape/CustomGeomShape.h index 87980aec8a..e198fb2ea5 100644 --- a/MsBinaryFile/Common/Vml/PPTShape/CustomGeomShape.h +++ b/MsBinaryFile/Common/Vml/PPTShape/CustomGeomShape.h @@ -33,7 +33,7 @@ #include "BinaryReader.h" #include "ElementSettings.h" #include "../BaseShape.h" -#include "../../../PptFile/Drawing/Attributes.h" +//#include "../../../PptFile/Drawing/Attributes.h" #include "PptFormula.h" #include "../GraphicsPath.h" @@ -46,288 +46,14 @@ namespace NSCustomVML WORD m_nCount; public: - CSegment(ODRAW::RulesType eType = ODRAW::rtMoveTo, WORD nCount = 2) - { - m_eRuler = eType; - m_nCount = nCount; - } + CSegment(ODRAW::RulesType eType = ODRAW::rtMoveTo, WORD nCount = 2); + CSegment(const CSegment& oSrc); + CSegment& operator=(const CSegment& oSrc); + ~CSegment(); - CSegment(const CSegment& oSrc) - { - m_eRuler = oSrc.m_eRuler; - m_nCount = oSrc.m_nCount; - } - - CSegment& operator=(const CSegment& oSrc) - { - m_eRuler = oSrc.m_eRuler; - m_nCount = oSrc.m_nCount; - - return (*this); - } - - ~CSegment() - { - } - int Read(WORD value)//from rtf segments - { - int repeate = 0; - if (value >= 0x2000 && value < 0x20FF) - { - repeate = value & 0x0FFF; - value &= 0xFF00; - } - - m_nCount = 0; - switch (value) - { - case 0x0001: // lineto - m_eRuler = ODRAW::rtLineTo; - m_nCount = 1; - break; - case 0x4000: // moveto - m_eRuler = ODRAW::rtMoveTo; - m_nCount = 1; - break; - case 0x2000: // curveto - m_eRuler = ODRAW::rtCurveTo; - m_nCount = 3; - break; - case 0xb300: // arcto - m_eRuler = ODRAW::rtArc; - m_nCount = 2; - break; - case 0xac00: - case 0xaa00: // nofill - case 0xad00: - m_eRuler = ODRAW::rtNoFill; - break; - case 0xab00: // nostroke - m_eRuler = ODRAW::rtNoStroke; - break; - case 0x6001: // close - m_eRuler = ODRAW::rtClose; - break; - case 0x8000: // end - m_eRuler = ODRAW::rtEnd; - break; - default: // given number of lineto elements - m_eRuler = ODRAW::rtLineTo; - m_nCount = value; - break; - } - return (std::max)(1, repeate); - } - void Read(POLE::Stream* pStream)//from binary ms segments - { - WORD mem = StreamUtils::ReadWORD(pStream); - BYTE type = mem & 0x07; - - if (type <= 4) - { - m_eRuler = (ODRAW::RulesType)type; - m_nCount = (mem >> 3) & 0x1FFF; - return; - } - - mem = (mem >> 3) & 0x1FFF; - type = mem & 0x1F; - - switch (type) - { - case 0x00: - { - m_eRuler = ODRAW::rtLineTo; - break; - } - case 0x01: - { - m_eRuler = ODRAW::rtAngleEllipseTo; - break; - } - case 0x02: - { - m_eRuler = ODRAW::rtAngleEllipse; - break; - } - case 0x03: - { - m_eRuler = ODRAW::rtArcTo; - break; - } - case 0x04: - { - m_eRuler = ODRAW::rtArc; - break; - } - case 0x05: - { - m_eRuler = ODRAW::rtClockwiseArcTo; - break; - } - case 0x06: - { - m_eRuler = ODRAW::rtClockwiseArc; - break; - } - case 0x07: - { - m_eRuler = ODRAW::rtEllipticalQuadrX; - break; - } - case 0x08: - { - m_eRuler = ODRAW::rtEllipticalQuadrY; - break; - } - case 0x09: - { - m_eRuler = ODRAW::rtQuadrBesier; - break; - } - case 0x0A: - { - m_eRuler = ODRAW::rtNoFill; - break; - } - case 0x0B: - { - m_eRuler = ODRAW::rtNoStroke; - break; - } - case 0x15: - { - m_eRuler = ODRAW::rtFillColor; - break; - } - case 0x16: - { - m_eRuler = ODRAW::rtLineColor; - break; - } - default: - { - m_eRuler = ODRAW::rtCurveTo; - } - }; - - m_nCount = (mem >> 5) & 0x00FF; - } - void Read(ODRAW::CBinaryReader& oReader)//from binary ms segments - { - WORD mem = oReader.ReadWORD(); - - BYTE type = (mem >> 13 & 0x07); - if (type <= 4) - { - m_eRuler = (ODRAW::RulesType)type; - m_nCount = (mem & 0x1FFF); - m_nCount = (WORD)GetCountPoints2(m_eRuler, m_nCount); - return; - } - - type = (mem >> 8) & 0x1F; - mem = mem & 0xFF; - - switch (type) - { - case 0x00: - { - m_eRuler = ODRAW::rtLineTo; - break; - } - case 0x01: - { - m_eRuler = ODRAW::rtAngleEllipseTo; - break; - } - case 0x02: - { - m_eRuler = ODRAW::rtAngleEllipse; - break; - } - case 0x03: - { - m_eRuler = ODRAW::rtArcTo; - break; - } - case 0x04: - { - m_eRuler = ODRAW::rtArc; - break; - } - case 0x05: - { - m_eRuler = ODRAW::rtClockwiseArcTo; - break; - } - case 0x06: - { - m_eRuler = ODRAW::rtClockwiseArc; - break; - } - case 0x07: - { - m_eRuler = ODRAW::rtEllipticalQuadrX; - break; - } - case 0x08: - { - m_eRuler = ODRAW::rtEllipticalQuadrY; - break; - } - case 0x09: - { - m_eRuler = ODRAW::rtQuadrBesier; - break; - } - case 0x0A: - { - m_eRuler = ODRAW::rtNoFill; - break; - } - case 0x0B: - { - m_eRuler = ODRAW::rtNoStroke; - break; - } - case 0x0C: - case 0x10: - { - m_eRuler = ODRAW::rtLineTo; - break; - } - case 0x0D: - case 0x0E: - case 0x0F: - case 0x11: - case 0x12: - case 0x13: - case 0x14: - { - m_eRuler = ODRAW::rtCurveTo; - break; - } - case 0x15: - { - m_eRuler = ODRAW::rtFillColor; - break; - } - case 0x16: - { - m_eRuler = ODRAW::rtLineColor; - break; - } - default: - { - m_eRuler = ODRAW::rtCurveTo; - } - }; - - m_nCount = (WORD)mem; - m_nCount = (WORD)GetCountPoints2(m_eRuler, m_nCount); - //m_nCount = (WORD)GetCountPoints2(m_eRuler); - } + int Read(WORD value); //from rtf segments + void Read(POLE::Stream* pStream); //from binary ms segments + void Read(ODRAW::CBinaryReader& oReader); //from binary ms segments }; class CGuide @@ -346,135 +72,17 @@ namespace NSCustomVML LONG m_lShapeWidth; LONG m_lShapeHeight; + CGuide(); + CGuide(const CGuide& oSrc); + CGuide& operator=(const CGuide& oSrc); - CGuide() - { - m_eType = NSGuidesVML::ftVal; + void SetToFormula(NSGuidesVML::CFormula& oFormula); - m_param_type1 = 0; - m_param_type2 = 0; - m_param_type3 = 0; - - m_param_value1 = 0; - m_param_value2 = 0; - m_param_value3 = 0; - - m_lShapeWidth = ShapeSizeVML; - m_lShapeHeight = ShapeSizeVML; - } - - CGuide(const CGuide& oSrc) - { - *this = oSrc; - } - - CGuide& operator=(const CGuide& oSrc) - { - m_eType = oSrc.m_eType; - - m_param_type1 = oSrc.m_param_type1; - m_param_type2 = oSrc.m_param_type2; - m_param_type3 = oSrc.m_param_type3; - - m_param_value1 = oSrc.m_param_value1; - m_param_value2 = oSrc.m_param_value2; - m_param_value3 = oSrc.m_param_value3; - - m_lShapeWidth = oSrc.m_lShapeWidth; - m_lShapeHeight = oSrc.m_lShapeHeight; - - return *this; - } - - void SetToFormula(NSGuidesVML::CFormula& oFormula) - { - oFormula.m_eFormulaType = m_eType; - - SetParam(m_param_type1, m_param_value1, oFormula.m_eType1, oFormula.m_lParam1); - SetParam(m_param_type2, m_param_value2, oFormula.m_eType2, oFormula.m_lParam2); - SetParam(m_param_type3, m_param_value3, oFormula.m_eType3, oFormula.m_lParam3); - } - - void Read(POLE::Stream* pStream) - { - WORD ftType = StreamUtils::ReadWORD(pStream); - - m_eType = NSGuidesVML::FormulaType(ftType & 0x1FFF); - - m_param_type1 = (BYTE)(ftType & 0x04); - m_param_type2 = (BYTE)(ftType & 0x02); - m_param_type3 = (BYTE)(ftType & 0x01); - - m_param_value1 = StreamUtils::ReadWORD(pStream); - m_param_value2 = StreamUtils::ReadWORD(pStream); - m_param_value3 = StreamUtils::ReadWORD(pStream); - } - void Read(ODRAW::CBinaryReader& oReader) - { - WORD ftType = oReader.ReadWORD(); - - m_eType = NSGuidesVML::FormulaType(ftType & 0x1FFF); - - m_param_type1 = (BYTE)(ftType & 0x04); - m_param_type2 = (BYTE)(ftType & 0x02); - m_param_type3 = (BYTE)(ftType & 0x01); - - m_param_value1 = oReader.ReadWORD(); - m_param_value2 = oReader.ReadWORD(); - m_param_value3 = oReader.ReadWORD(); - } + void Read(POLE::Stream* pStream); + void Read(ODRAW::CBinaryReader& oReader); private: - void SetParam(BYTE type, WORD param, ParamType& param_type, LONG& param_value) - { - if (0 == type) - { - param_type = ptValue; - param_value = (LONG)param; - } - - if (0x0140 == param) - { - param_type = ptValue; - param_value = ShapeSizeVML / 2; - return; - } - if (0x0141 == param) - { - param_type = ptValue; - param_value = ShapeSizeVML / 2; - return; - } - if (0x0142 == param) - { - param_type = ptValue; - param_value = ShapeSizeVML; - return; - } - if (0x0143 == param) - { - param_type = ptValue; - param_value = ShapeSizeVML; - return; - } - - if ((0x0147 <= param) && (param <= 0x014E)) - { - param_type = ptAdjust; - param_value = (LONG)(param - 0x0147); - return; - } - - if ((0x0400 <= param) && (param <= 0x047F)) - { - param_type = ptFormula; - param_value = (LONG)(param - 0x0400); - return; - } - - param_type = ptValue; - param_value = ShapeSizeVML; - } + void SetParam(BYTE type, WORD param, ParamType& param_type, LONG& param_value); }; class CCustomVML @@ -497,480 +105,26 @@ namespace NSCustomVML ODRAW::CPen m_oPen; public: - CCustomVML() : m_pAdjustValues(NULL) - { - m_ePath = ODRAW::rtCurveTo/*rtLineTo*/; - - m_bIsVerticesPresent = false; - m_bIsPathPresent = false; - } - - CCustomVML(const CCustomVML& oSrc) - { - *this = oSrc; - } - - CCustomVML& operator=(const CCustomVML& oSrc) - { - m_ePath = oSrc.m_ePath; - - m_arVertices.clear(); - m_arVertices.insert(m_arVertices.end(), oSrc.m_arVertices.begin(), oSrc.m_arVertices.end()); - - m_arSegments.clear(); - m_arSegments.insert(m_arSegments.end(), oSrc.m_arSegments.begin(), oSrc.m_arSegments.end()); - - m_arGuides.clear(); - m_arGuides.insert(m_arGuides.end(), oSrc.m_arGuides.begin(), oSrc.m_arGuides.end()); - - m_pAdjustValues = oSrc.m_pAdjustValues; - - m_bIsPathPresent = oSrc.m_bIsPathPresent; - m_bIsVerticesPresent = oSrc.m_bIsVerticesPresent; - - m_oBrush = oSrc.m_oBrush; - m_oPen = oSrc.m_oPen; - - return *this; - } - - ~CCustomVML() - { - } - - bool IsCustom() - { - return (m_bIsVerticesPresent && m_bIsPathPresent); - } - - void SetPath(ODRAW::RulesType ePath) - { - m_ePath = ePath; - m_bIsPathPresent = true; - } - void LoadVertices(std::vector> values) - { - if (!values.empty()) - m_bIsVerticesPresent = true; - - m_arVertices.clear(); - - for (size_t ind = 0; ind < values.size(); ++ind) - { - Aggplus::POINT oPoint; - - oPoint.x = values[ind].first; - oPoint.y = values[ind].second; - - LONG lMinF = (LONG)0x80000000; - LONG lMaxF = (LONG)0x8000007F; - if (lMinF <= oPoint.x) - { - int nGuideIndex = (_UINT32)oPoint.x - 0x80000000; - - bool b = false; - } - if (lMinF <= oPoint.y) - { - int nGuideIndex = (_UINT32)oPoint.y - 0x80000000; - - bool b = false; - } - - m_arVertices.push_back(oPoint); - } - } - void LoadConnectionSitesDir(CProperty* pProperty) - { - ODRAW::CBinaryReader oReader(pProperty->m_pOptions, pProperty->m_lValue); - m_arConnectionSitesDir.clear(); - - WORD lCount = (WORD)(pProperty->m_lValue / 4); - - for (WORD lIndex = 0; lIndex < lCount; ++lIndex) - { - _UINT32 v = oReader.ReadLONG(); - double val = (double)((WORD)(v >> 16) + ((WORD)(v) / 65536.0)); - m_arConnectionSitesDir.push_back(val); - } - } - void LoadConnectionSites(CProperty* pProperty) - { - ODRAW::CBinaryReader oReader(pProperty->m_pOptions, pProperty->m_lValue); - m_arConnectionSites.clear(); - - WORD lCount = (WORD)(pProperty->m_lValue / 8); - if (pProperty->m_bIsTruncated) - { - lCount = (WORD)(pProperty->m_lValue / 4); - } - - for (WORD lIndex = 0; lIndex < lCount; ++lIndex) - { - Aggplus::POINT oPoint; - if (pProperty->m_bIsTruncated) - { - oPoint.x = (short)oReader.ReadWORD(); - oPoint.y = (short)oReader.ReadWORD(); - } - else - { - oPoint.x = oReader.ReadLONG(); - oPoint.y = oReader.ReadLONG(); - } - - LONG lMinF = (LONG)0x80000000; - LONG lMaxF = (LONG)0x8000007F; - if (lMinF <= oPoint.x) - { - int nGuideIndex = (_UINT32)oPoint.x - 0x80000000; - - bool b = false; - } - if (lMinF <= oPoint.y) - { - int nGuideIndex = (_UINT32)oPoint.y - 0x80000000; - - bool b = false; - } - - m_arConnectionSites.push_back(oPoint); - } - } - void LoadVertices(CProperty* pProperty) - { - ODRAW::CBinaryReader oReader(pProperty->m_pOptions, pProperty->m_lValue); - - m_arVertices.clear(); - - WORD lCount = (WORD)(pProperty->m_lValue / 8); - if (pProperty->m_bIsTruncated) - { - lCount = (WORD)(pProperty->m_lValue / 4); - } - - if (lCount > 0) - { - m_bIsVerticesPresent = true; - } - - for (WORD lIndex = 0; lIndex < lCount; ++lIndex) - { - Aggplus::POINT oPoint; - if (pProperty->m_bIsTruncated) - { - oPoint.x = (short)oReader.ReadWORD(); - oPoint.y = (short)oReader.ReadWORD(); - } - else - { - oPoint.x = oReader.ReadLONG(); - oPoint.y = oReader.ReadLONG(); - } - - LONG lMinF = (LONG)0x80000000; - LONG lMaxF = (LONG)0x8000007F; - if (lMinF <= oPoint.x) - { - int nGuideIndex = (_UINT32)oPoint.x - 0x80000000; - - bool b = false; - } - if (lMinF <= oPoint.y) - { - int nGuideIndex = (_UINT32)oPoint.y - 0x80000000; - - bool b = false; - } - - m_arVertices.push_back(oPoint); - } - } - - void LoadAHs(CProperty* pProperty) - { - } - void LoadSegments(std::vector values) - { - m_arSegments.clear(); - - if (!values.empty()) - m_bIsPathPresent = true; - - for (size_t ind = 0; ind < values.size(); ++ind) - { - CSegment oInfo; - int count = oInfo.Read(values[ind]); - - if (0 == oInfo.m_nCount) - { - if ((ODRAW::rtEnd != oInfo.m_eRuler) && - (ODRAW::rtNoFill != oInfo.m_eRuler) && - (ODRAW::rtNoStroke != oInfo.m_eRuler) && - (ODRAW::rtClose != oInfo.m_eRuler)) - { - continue; - } - } - for (int i = 0 ; i < count; i++) - m_arSegments.push_back(oInfo); - } - } - void LoadSegments(CProperty* pProperty) - { - ODRAW::CBinaryReader oReader(pProperty->m_pOptions, pProperty->m_lValue); - m_arSegments.clear(); - - WORD lCount = (WORD)(pProperty->m_lValue / 2); - - if (lCount > 0) m_bIsPathPresent = true; - - for (WORD lIndex = 0; lIndex < lCount; ++lIndex) - { - CSegment oInfo; - oInfo.Read(oReader); - - if (0 == oInfo.m_nCount) - { - if ((ODRAW::rtEnd != oInfo.m_eRuler) && - (ODRAW::rtNoFill != oInfo.m_eRuler) && - (ODRAW::rtNoStroke != oInfo.m_eRuler) && - (ODRAW::rtClose != oInfo.m_eRuler)) - { - continue; - } - } - - //if (rtClose == oInfo.m_eRuler) - //{ - // // проводим линию - // CSegment oInfo2(rtLineTo, 1); - // m_arSegments.push_back(oInfo2); - //} - - m_arSegments.push_back(oInfo); - } - } - void LoadGuides(CProperty* pProperty) - { - ODRAW::CBinaryReader oReader(pProperty->m_pOptions, pProperty->m_lValue); - WORD lCount = (WORD)(pProperty->m_lValue / 4); - - for (WORD lIndex = 0; lIndex < lCount; ++lIndex) - { - CGuide oInfo; - oInfo.Read(oReader); - m_arGuides.push_back(oInfo); - } - } - void LoadInscribe(CProperty* pProperty) - { - ODRAW::CBinaryReader oReader(pProperty->m_pOptions, pProperty->m_lValue); - m_arInscribe.clear(); - - WORD lCount = (WORD)(pProperty->m_lValue / 16); - if (pProperty->m_bIsTruncated) - { - lCount = (WORD)(pProperty->m_lValue / 8); - } - - for (WORD lIndex = 0; lIndex < lCount; ++lIndex) - { - Aggplus::RECT oRect; - if (pProperty->m_bIsTruncated) - { - oRect.left = (short)oReader.ReadWORD(); - oRect.right = (short)oReader.ReadWORD(); - oRect.top = (short)oReader.ReadWORD(); - oRect.bottom = (short)oReader.ReadWORD(); - } - else - { - oRect.left = (short)oReader.ReadLONG(); - oRect.right = (short)oReader.ReadLONG(); - oRect.top = (short)oReader.ReadLONG(); - oRect.bottom = (short)oReader.ReadLONG(); - } - m_arInscribe.push_back(oRect); - } - } - void LoadAdjusts(LONG lIndex, LONG lValue) - { - if (NULL == m_pAdjustValues) - return; - - LONG lCount = (LONG)m_pAdjustValues->size(); - - while (lCount <= lIndex) - { - m_pAdjustValues->push_back(0); - lCount = (LONG)m_pAdjustValues->size(); - } - - (*m_pAdjustValues)[lIndex] = lValue; - } - - void SetAdjusts(std::vector* pList) - { - m_pAdjustValues = pList; - } - - void ToCustomShape(ODRAW::CBaseShape* pShape, NSGuidesVML::CFormulasManager& oManager) - { - if ((NULL == pShape) || (!IsCustom())) - return; - - oManager.Clear(); - // сначала заполним формулы - for (size_t nIndex = 0; nIndex < m_arGuides.size(); ++nIndex) - { - NSGuidesVML::CFormula oF; - m_arGuides[nIndex].SetToFormula(oF); - oManager.AddFormula(oF); - } - - oManager.Clear(m_pAdjustValues); - - std::wstring strPath = _T(""); - - bool bBreak = false; - - long lMinF = (_INT32)0x80000000; - long lMaxF = (_INT32)0x8000007F; - - int nGuideIndex_x , nGuideIndex_y; - - if (0 == m_arSegments.size()) - { - strPath = GetRulerVML(m_ePath); - - for (size_t nIndex = 0; nIndex < m_arVertices.size(); ++nIndex) - { - nGuideIndex_x = nGuideIndex_y = -1; - - if (lMaxF > m_arVertices[nIndex].x ) nGuideIndex_x = (_UINT32)m_arVertices[nIndex].x - (_UINT32)lMinF; - if (lMaxF > m_arVertices[nIndex].y ) nGuideIndex_y = (_UINT32)m_arVertices[nIndex].y - (_UINT32)lMinF; - - if (nGuideIndex_x >= 0 ) - { - strPath += std::to_wstring(m_arGuides[nGuideIndex_x].m_param_value1) + L","; - } - else - { - strPath += std::to_wstring(m_arVertices[nIndex].x) + L","; - } - if (nGuideIndex_y >= 0) - { - strPath += std::to_wstring(m_arGuides[nGuideIndex_y].m_param_value1) + L","; - } - else - { - strPath += std::to_wstring(m_arVertices[nIndex].y) + L","; - } - - } - strPath.erase(strPath.length() - 1); - } - else - { - size_t nStart = 0; - size_t nEnd = 0; - for (size_t nS = 0; nS < m_arSegments.size(); ++nS) - { - if (bBreak) - { - if ((ODRAW::rtEnd != m_arSegments[nS].m_eRuler) && - (ODRAW::rtNoFill != m_arSegments[nS].m_eRuler) && - (ODRAW::rtNoStroke != m_arSegments[nS].m_eRuler) && - (ODRAW::rtClose != m_arSegments[nS].m_eRuler)) - { - strPath += _T("e"); - break; - } - } - - if ((ODRAW::rtFillColor == m_arSegments[nS].m_eRuler) || (ODRAW::rtLineColor == m_arSegments[nS].m_eRuler)) - { - if (nStart < m_arVertices.size()) - { - if (ODRAW::rtFillColor == m_arSegments[nS].m_eRuler) - { - m_oBrush.Color1 = (_UINT32)m_arVertices[nStart].x; - m_oBrush.Color2 = (_UINT32)m_arVertices[nStart].y; - } - else - { - m_oPen.Color = (_UINT32)m_arVertices[nStart].x; - } - } - nEnd = nStart + m_arSegments[nS].m_nCount; - if (nEnd > m_arVertices.size()) - nEnd = m_arVertices.size(); - nStart = nEnd; - - if (nEnd == m_arVertices.size()) - { - bBreak = true; - } - continue; - } - - strPath += GetRulerVML(m_arSegments[nS].m_eRuler); - - nEnd = nStart + m_arSegments[nS].m_nCount; - if (nEnd > m_arVertices.size()) - nEnd = m_arVertices.size(); - - for (size_t nV = nStart; nV < nEnd; ++nV) - { - nGuideIndex_x = nGuideIndex_y = -1; - - if (lMaxF > m_arVertices[nV].x ) nGuideIndex_x = (_UINT32)m_arVertices[nV].x - (_UINT32)lMinF; - if (lMaxF > m_arVertices[nV].y ) nGuideIndex_y = (_UINT32)m_arVertices[nV].y - (_UINT32)lMinF; - - std::wstring str = _T(""); - if (nGuideIndex_x >= 0 && nGuideIndex_x < (int)m_arGuides.size()) - { - strPath += std::to_wstring(m_arGuides[nGuideIndex_x].m_param_value1) + L","; - } - else - { - strPath += std::to_wstring(m_arVertices[nV].x) + L","; - } - if (nGuideIndex_y >= 0 && nGuideIndex_y < (int)m_arGuides.size()) - { - strPath += std::to_wstring(m_arGuides[nGuideIndex_y].m_param_value1) + L","; - } - else - { - strPath += std::to_wstring(m_arVertices[nV].y) + L","; - } - } - - if (nEnd != nStart) - { - strPath.erase(strPath.length() - 1); - } - nStart = nEnd; - - if (nEnd == m_arVertices.size()) - { - bBreak = true; - } - } - } - - oManager.CalculateResults(); - - pShape->LoadPathList(strPath); - - /*std::wstring str = _T("\ - \ - \ - \ - ");*/ - - //pShape->LoadFromXML(str); - } - }; + CCustomVML(); + CCustomVML(const CCustomVML& oSrc); + CCustomVML& operator=(const CCustomVML& oSrc); + ~CCustomVML(); + + bool IsCustom(); + void SetPath(ODRAW::RulesType ePath); + + void LoadVertices(std::vector> values); + void LoadConnectionSitesDir(CProperty* pProperty); + void LoadConnectionSites(CProperty* pProperty); + void LoadVertices(CProperty* pProperty); + void LoadAHs(CProperty* pProperty); + void LoadSegments(std::vector values); + void LoadSegments(CProperty* pProperty); + void LoadGuides(CProperty* pProperty); + void LoadInscribe(CProperty* pProperty); + void LoadAdjusts(LONG lIndex, LONG lValue); + + void SetAdjusts(std::vector* pList); + void ToCustomShape(ODRAW::CBaseShape* pShape, NSGuidesVML::CFormulasManager& oManager); + }; } diff --git a/MsBinaryFile/Common/Vml/PPTShape/ElementSettings.cpp b/MsBinaryFile/Common/Vml/PPTShape/ElementSettings.cpp index a0af50254d..9fc2cb67a9 100644 --- a/MsBinaryFile/Common/Vml/PPTShape/ElementSettings.cpp +++ b/MsBinaryFile/Common/Vml/PPTShape/ElementSettings.cpp @@ -37,9 +37,26 @@ #include "../../../PptFile/Reader/Records.h" #include "../../../PptFile/Reader/PPTFileDefines.h" +#include "../../../PptFile/Records/Drawing/ArtBlip.h" + // это класс, использующийся для передачи свойств объектов, // например - указатель на картинку... (по PID'у) +CProperty::CProperty() +{ + m_ePID = ODRAW::ePropertyId_left; + m_bIsBlip = false; + m_bComplex = false; + m_lValue = 0; + m_pOptions = NULL; + + m_bIsTruncated = false; +} +CProperty::~CProperty() +{ + if (m_pOptions) delete []m_pOptions; + m_pOptions = NULL; +} void CProperty::FromStream(POLE::Stream* pStream) { // читаем из стрима... @@ -53,7 +70,6 @@ void CProperty::FromStream(POLE::Stream* pStream) m_lValue = StreamUtils::ReadDWORD(pStream); } - void CProperty::ComplexFromStream(POLE::Stream* pStream) { if (m_bComplex && m_lValue > 0) @@ -141,7 +157,14 @@ void CProperty::ComplexFromStream(POLE::Stream* pStream) } } - +CProperties::CProperties() : m_arProperties() +{ +} +CProperties::~CProperties() +{ + m_lCount = 0; + m_arProperties.clear(); +} void CProperties::FromStream(POLE::Stream* pStream, long lCount) { m_lCount = lCount; @@ -158,8 +181,6 @@ void CProperties::FromStream(POLE::Stream* pStream, long lCount) m_arProperties[lIndex].ComplexFromStream(pStream); } } - - size_t CProperties::GetLen() { size_t dwLen = 6 * m_lCount; diff --git a/MsBinaryFile/Common/Vml/PPTShape/ElementSettings.h b/MsBinaryFile/Common/Vml/PPTShape/ElementSettings.h index 9d0b175977..bdad573475 100644 --- a/MsBinaryFile/Common/Vml/PPTShape/ElementSettings.h +++ b/MsBinaryFile/Common/Vml/PPTShape/ElementSettings.h @@ -31,7 +31,6 @@ */ #pragma once -#include "../../../PptFile/Records/Drawing/ArtBlip.h" #include "../../../../OOXML/Base/Types_32.h" #include "../../../../Common/3dParty/pole/pole.h" #include "Enums.h" @@ -52,21 +51,9 @@ public: // чтобы не плодить классы - это value, когда m_bComplex == true bool m_bIsTruncated; - CProperty() - { - m_ePID = ODRAW::ePropertyId_left; - m_bIsBlip = false; - m_bComplex = false; - m_lValue = 0; - m_pOptions = NULL; + CProperty(); + ~CProperty(); - m_bIsTruncated = false; - } - ~CProperty() - { - if (m_pOptions) delete []m_pOptions; - m_pOptions = NULL; - } void FromStream(POLE::Stream* pStream); void ComplexFromStream(POLE::Stream* pStream); }; @@ -80,14 +67,8 @@ public: // тем более это класс - не связанный с RecordHeader size_t m_lCount; - CProperties() : m_arProperties() - { - } - ~CProperties() - { - m_lCount = 0; - m_arProperties.clear(); - } + CProperties(); + ~CProperties(); void FromStream(POLE::Stream* pStream, long lCount); size_t GetLen(); diff --git a/MsBinaryFile/Common/Vml/PPTShape/Ppt2PptxShapeConverter.cpp b/MsBinaryFile/Common/Vml/PPTShape/Ppt2PptxShapeConverter.cpp new file mode 100644 index 0000000000..09b8904c91 --- /dev/null +++ b/MsBinaryFile/Common/Vml/PPTShape/Ppt2PptxShapeConverter.cpp @@ -0,0 +1,2015 @@ +/* + * (c) Copyright Ascensio System SIA 2010-2019 + * + * 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 20A-12 Ernesta Birznieka-Upisha + * street, Riga, Latvia, EU, LV-1050. + * + * 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 "Ppt2PptxShapeConverter.h" + +namespace NSGuidesVML +{ + int __wstrlen(const wchar_t* str) + { + const wchar_t* s = str; + for (; *s != 0; ++s); + return (LONG)(s - str); + } + + CSlicePath::CSlicePath(RulesType rule, LONG x, LONG y) : m_lX(x), m_lY(y), m_eRuler(rule) + { + m_nCountElementsPoint = 0; + } + void CSlicePath::AddParam(LONG lParam, ParamType eParType) + { + long lPoint = m_nCountElementsPoint % 2; + if (0 == lPoint) + { + Aggplus::POINT point; + SPointType pointType; + + point.x = lParam; + if (m_eRuler != rtRMoveTo && m_eRuler != rtRLineTo && m_eRuler != rtRCurveTo) + { + point.x -= m_lX; + } + point.y = 0; + pointType.x = eParType; + pointType.y = ptValue; + m_arPoints.push_back(point); + m_arPointsType.push_back(pointType); + } + else + { + m_arPoints.back().y = lParam; + if (m_eRuler != rtRMoveTo && m_eRuler != rtRLineTo && m_eRuler != rtRCurveTo) + { + m_arPoints.back().y -= m_lY; + } + + m_arPointsType.back().y = eParType; + } + ++m_nCountElementsPoint; + } + + CFormulaConverter::CFormulaConverter() + { + m_lIndexDst = 0; + m_lIndexSrc = -1; + + m_lWidth = 0; + m_lHeight = 0; + + m_lX = 0; + m_lY = 0; + + m_lMaxAdjUse = -1; + } + void CFormulaConverter::ConvertCoef(NSGuidesVML::CFormParam pCoef) + { + if (pCoef.m_eType == ptValue) + ConvertVal(pCoef.m_lParam, pCoef.m_eType, false, m_oCoef); + else if (pCoef.m_eType == ptFormula) + { + ConvertProd(22, ptValue, 1, ptValue, 7, ptValue, false, false, false, m_oCoef); + ConvertProd(m_lIndexDst-1, ptFormula, 1, ptValue, 180, ptValue, true, false, false, m_oCoef); + } + m_oParam.m_lParam = m_lIndexDst-1; + m_oParam.m_eType = ptFormula; + m_oParam.m_lCoef = pCoef.m_lCoef; + } + void CFormulaConverter::ConvertCoef2(NSGuidesVML::CFormParam pCoef) + { + if (pCoef.m_eType == ptValue) + ConvertVal(pCoef.m_lParam, pCoef.m_eType, false, m_oGuidsRes); + else if (pCoef.m_eType == ptFormula) + { + ConvertProd(22, ptValue, 1, ptValue, 7, ptValue, false, false, false, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, 1, ptValue, 180, ptValue, true, false, false, m_oGuidsRes); + } + m_oParam.m_lParam = m_lIndexDst-1; + m_oParam.m_eType = ptFormula; + m_oParam.m_lCoef = pCoef.m_lCoef; + } + void CFormulaConverter::ConvertAdj(const std::vector& arAdj) + { + for (int i = 0; i < (int)arAdj.size(); ++i) + { + m_oAdjRes.WriteString(L""); + } + for (int i = (int)arAdj.size(); i <= m_lMaxAdjUse; ++i) + { + m_oAdjRes.WriteString(L""); + } + } + void CFormulaConverter::ConvertFormula(const std::vector& arFormulas) + { + for (size_t i = 0; i < arFormulas.size(); ++i) + { + const CFormula& pFormula = arFormulas[i]; + m_lIndexSrc++; + + switch (pFormula.m_eFormulaType) + { + case ftVal: + { + ConvertVal(pFormula.m_lParam1, pFormula.m_eType1, false, m_oGuidsRes); + break; + } + case ftSum: + { + ConvertSum(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, pFormula.m_lParam3, pFormula.m_eType3, false, false, false, m_oGuidsRes); + break; + } + case ftProduct: + { + ConvertProd(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, pFormula.m_lParam3, pFormula.m_eType3, false, false, false, m_oGuidsRes); + break; + } + case ftMid: + { + // TODO: +/ ??? + ConvertSum(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, 0, ptValue, false, false, false, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, 1, ptValue, 2, ptValue, true, false, false, m_oGuidsRes); + break; + } + case ftAbsolute: + { + ConvertAbs (pFormula.m_lParam1, pFormula.m_eType1, false, m_oGuidsRes); + break; + } + case ftMin: + { + ConvertMin(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, false, false, m_oGuidsRes); + break; + } + case ftMax: + { + ConvertMax(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, false, false, m_oGuidsRes); + break; + } + case ftIf: + { + ConvertIf(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, pFormula.m_lParam3, pFormula.m_eType3, false, false, false, m_oGuidsRes); + break; + } + case ftMod: + { + ConvertMod(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, pFormula.m_lParam3, pFormula.m_eType3, false, false, false, m_oGuidsRes); + break; + } + case ftAtan2: + { + ConvertAt2(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, false, false, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_oParam.m_lParam, m_oParam.m_eType, pow3_16, ptValue, true, true, false, m_oGuidsRes); + break; + } + case ftSin: + { + ConvertProd(pFormula.m_lParam2, pFormula.m_eType2, pow3_16, ptValue, m_oParam.m_lParam, m_oParam.m_eType, false, false, true, m_oGuidsRes); + ConvertSin(pFormula.m_lParam1, pFormula.m_eType1, m_lIndexDst-1, ptFormula, false, true, m_oGuidsRes); + break; + } + case ftCos: + { + ConvertProd(pFormula.m_lParam2, pFormula.m_eType2, pow3_16, ptValue, m_oParam.m_lParam, m_oParam.m_eType, false, false, true, m_oGuidsRes); + ConvertCos(pFormula.m_lParam1, pFormula.m_eType1, m_lIndexDst-1, ptFormula, false, true, m_oGuidsRes); + break; + } + case ftCosatan2: + { + ConvertCat2(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, pFormula.m_lParam3, pFormula.m_eType3, false, false, false, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_oParam.m_lParam, m_oParam.m_eType, pow3_16, ptValue, true, true, false, m_oGuidsRes); + break; + } + case ftSinatan2: + { + ConvertSat2(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, pFormula.m_lParam3, pFormula.m_eType3, false, false, false, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_oParam.m_lParam, m_oParam.m_eType, pow3_16, ptValue, true, true, false, m_oGuidsRes); + break; + } + case ftSqrt: + { + ConvertSqrt(pFormula.m_lParam1, pFormula.m_eType1, false, m_oGuidsRes); + break; + } + case ftTan: + { + ConvertTag(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, false, false, m_oGuidsRes); + break; + } + case ftSumangle: + { + ConvertProd(pFormula.m_lParam1, pFormula.m_eType1, pow3_16, ptValue, m_oParam.m_lParam, m_oParam.m_eType, false, false, true, m_oGuidsRes); + ConvertProd(pow3_16, ptValue, pFormula.m_lParam2, pFormula.m_eType2, 1, ptValue, false, false, false, m_oGuidsRes); + ConvertProd(pow3_16, ptValue, pFormula.m_lParam3, pFormula.m_eType3, 1, ptValue, false, false, false, m_oGuidsRes); + ConvertSum(m_lIndexDst-3, ptFormula, m_lIndexDst-2, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_oParam.m_lParam, m_oParam.m_eType, pow3_16, ptValue, true, true, false, m_oGuidsRes); + break; + } + case ftEllipse: + { + ConvertProd(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam1, pFormula.m_eType1, 1, ptValue , false, false, false, m_oGuidsRes); + ConvertProd(pFormula.m_lParam2, pFormula.m_eType2, pFormula.m_lParam2, pFormula.m_eType2, 1, ptValue , false, false, false, m_oGuidsRes); + ConvertProd(1, ptValue, m_lIndexDst-2, ptFormula, m_lIndexDst-1, ptFormula, false, true, true, m_oGuidsRes); + ConvertSum(0, ptValue, 1, ptValue, m_lIndexDst-1, ptFormula, false, false, true, m_oGuidsRes); + ConvertSqrt(m_lIndexDst-1, ptFormula, true, m_oGuidsRes); + ConvertProd(pFormula.m_lParam3, pFormula.m_eType3, m_lIndexDst-1, ptFormula, 1, ptValue, false, true, false, m_oGuidsRes); + break; + } + default: + break; + } + + m_arIndexDst.push_back(m_lIndexDst-1); + } + } + void CFormulaConverter::ConvertPath(std::wstring strPath, const ODRAW::CPath& oPath) + { + m_arParts.clear(); + std::vector oArray; + boost::algorithm::split(oArray, strPath, boost::algorithm::is_any_of(L"e"), boost::algorithm::token_compress_on); + + for (size_t nIndex = 0; nIndex < oArray.size(); ++nIndex) + { + if (oPath.m_arParts.size() <= nIndex) + break; + const CPartPath& oPart = oPath.m_arParts[nIndex]; + + m_lWidth = oPart.width; + m_lHeight = oPart.height; + + m_lX = oPart.x; + m_lY = oPart.y; + + bool bFill = false; + bool bStroke = false; + std::wstring strValue; + FromXML(oArray[nIndex], bFill, bStroke); + + m_oPathRes.StartNode(L"a:path"); + m_oPathRes.StartAttributes(); + m_oPathRes.WriteAttribute(L"w", m_lWidth); + m_oPathRes.WriteAttribute(L"h", m_lHeight); + + if (!bStroke) + m_oPathRes.WriteAttribute(L"stroke", (std::wstring)L"false"); + if (!bFill) + m_oPathRes.WriteAttribute(L"fill", (std::wstring)L"none"); + m_oPathRes.EndAttributes(); + + for (size_t i = 0; i < m_arSlicesPath.size(); ++i) + { + CSlicePath& oSlice = m_arSlicesPath[i]; + + //m_lIndexDst-1 - номер последней записанной формулы + //m_lIndexSrc - номер последнего блока формул + //m_arIndexDst[n] - возвращает номер последней формулы в блоке n + //m_arIndexDst[m_lIndexSrc] = m_lIndexDst + + switch (oSlice.m_eRuler) + { + case rtMoveTo: + { + ConvertSlice_MoveTo(oSlice); + break; + } + case rtRMoveTo: + { + ConvertSlice_RMoveTo(oSlice); + break; + } + case rtClose: + { + m_oPathRes.WriteString(L""); + break; + } + case rtLineTo: + { + ConvertSlice_LineTo(oSlice); + break; + } + case rtRLineTo: + { + ConvertSlice_RLineTo(oSlice); + break; + } + case rtArcTo: + case rtArc: + { + ConvertSlice_ArcTo(oSlice); + break; + } + case rtClockwiseArcTo: + case rtClockwiseArc: + { + ConvertSlice_ClockwiseTo(oSlice); + break; + } + case rtQuadrBesier: + { + ConvertSlice_QuadrBesier(oSlice); + break; + } + case rtCurveTo: + { + ConvertSlice_CurveTo(oSlice); + break; + } + case rtRCurveTo: + { + ConvertSlice_RCurveTo(oSlice); + break; + } + case rtAngleEllipse: + case rtAngleEllipseTo: + { + ConvertSlice_AngleEllipse(oSlice); + break; + } + case rtEllipticalQuadrX: + { + ConvertSlice_EllipticalQuadrX(oSlice); + break; + } + case rtEllipticalQuadrY: + { + ConvertSlice_EllipticalQuadrY(oSlice); + break; + } + default: + break; + } + } + + m_oPathRes.WriteString(L""); + } + } + void CFormulaConverter::ConvertHandle(const std::vector& arHandles, std::vector& arAdj, PPTShapes::ShapeType oSType) + { + size_t nHandlesCount = arHandles.size(); + if (oSType == 19) // в пптх не реализована функция изменения размера шейпа при изменении handle + nHandlesCount = 0; + for (size_t i = 0; i < nHandlesCount; ++i) + { + const CHandle_& pHnPoint = arHandles[i]; + std::vector arPos; + + std::wstring sPos0 = L""; + std::wstring sPos1 = L""; + + SHandle oHandle; + ParamType ptType; + + if (pHnPoint.position != L"") + { + boost::algorithm::split(arPos, pHnPoint.position, boost::algorithm::is_any_of(L","), boost::algorithm::token_compress_on); + sPos0 = arPos[0]; + sPos1 = arPos[1]; + + oHandle.gdRef.x = GetHandleValue(sPos0, m_lWidth, ptType); + oHandle.gdRefType.x = ptType; + if (oHandle.gdRefType.x == ptAdjust) + oHandle.bRefExist.x = true; + + oHandle.gdRef.y = GetHandleValue(sPos1, m_lWidth, ptType); + oHandle.gdRefType.y = ptType; + if (oHandle.gdRefType.y == ptAdjust) + oHandle.bRefExist.y = true; + + if (pHnPoint.polar != L"") + { + //пришел полярный угол + oHandle.bRefExist.y = false; + + oHandle.bRefPolarExist.y = true; + oHandle.bMinPolarExist.y = true; + + boost::algorithm::split(arPos, pHnPoint.polar, boost::algorithm::is_any_of(L","), boost::algorithm::token_compress_on); + + oHandle.PolarCentre.x = GetHandleValue(arPos[0], m_lWidth, ptType); + oHandle.PolarCentreType.x = ptType; + + oHandle.PolarCentre.y = GetHandleValue(arPos[1], m_lWidth, ptType); + oHandle.PolarCentreType.y = ptType; + + if (oHandle.gdRefType.y == ptAdjust) + { + //угол должен храниться в pptx формате, поэтому придётся его везде заменить + std::wstring strNewFmla = GetValue2(m_lIndexDst, ptFormula, true); + std::wstring strOldFmla = GetValue2(oHandle.gdRef.y, oHandle.gdRefType.y, false); + LONG nIndex = m_lIndexDst; + + // TODO: !!! тут медленный код. + m_oGuidsRes.ReplaceString(strOldFmla, strNewFmla); + + m_lIndexSrc++; + + // TODO: !!! тут медленный код. + NSBinPptxRW::CXmlWriter memGuidsRes; + ConvertProd(oHandle.gdRef.y, oHandle.gdRefType.y, m_oParam.m_lCoef, ptValue, pow3_16, ptValue, false, true, false, memGuidsRes); + m_oGuidsRes.m_oWriter.WriteBefore(memGuidsRes.m_oWriter); + m_arIndexDst.push_back(m_lIndexDst-1); + + if (oHandle.gdRefType.y == ptAdjust) + { + double dScale = (double)pow3_16 / m_oParam.m_lCoef; + + if (oHandle.gdRef.y >= (int)arAdj.size()) + { + // дурацкий код. надо память перевыделить, а старую скопировать + // пока сделаю так, чтобы наверняка + int nNewSize = (int)oHandle.gdRef.y + 1; + while ((int)arAdj.size() < nNewSize) + arAdj.push_back(0); + } + + LONG lVal = (LONG)(dScale * arAdj[oHandle.gdRef.y]); + arAdj[oHandle.gdRef.y] = lVal; + } + + //рассчитаем координаты точки handle + + m_lIndexSrc++; + ConvertCos(oHandle.gdRef.x, oHandle.gdRefType.x, oHandle.gdRef.y, oHandle.gdRefType.y, false, false, m_oGuidsRes); + ConvertSin(oHandle.gdRef.x, oHandle.gdRefType.x, oHandle.gdRef.y, oHandle.gdRefType.y, false, false, m_oGuidsRes); + ConvertSum(oHandle.PolarCentre.x, oHandle.PolarCentreType.x, m_lIndexDst-2, ptFormula, 0, ptValue, false, true, false, m_oGuidsRes); + ConvertSum(oHandle.PolarCentre.y, oHandle.PolarCentreType.y, m_lIndexDst-2, ptFormula, 0, ptValue, false, true, false, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + + std::wstring strMem = L"&" + std::to_wstring(m_lIndexDst-2); + oHandle.Pos.x = GetHandlePos(strMem, L"w", m_lWidth); + oHandle.PosType.x = ptFormula; + + strMem = L"&" + std::to_wstring(m_lIndexDst-2); //????? + oHandle.Pos.y = GetHandlePos(strMem, L"h", m_lHeight); + oHandle.PosType.y = ptFormula; + } + + } + else//если пришли обычные координаты + { + if ((pHnPoint.xrange != L"" && oHandle.gdRefType.x != ptAdjust && oHandle.gdRefType.y == ptAdjust) || + (pHnPoint.yrange != L"" && oHandle.gdRefType.x == ptAdjust && oHandle.gdRefType.y != ptAdjust)) + { + oHandle.Pos.x = GetHandlePos(sPos1, L"w", m_lWidth); + oHandle.PosType.x = ptFormula; + + oHandle.Pos.y = GetHandlePos(sPos0, L"h", m_lHeight); + oHandle.PosType.y = ptFormula; + } + else + { + oHandle.Pos.x = GetHandlePos(sPos0, L"w", m_lWidth); + oHandle.PosType.x = ptFormula; + + oHandle.Pos.y = GetHandlePos(sPos1, L"h", m_lHeight); + oHandle.PosType.y = ptFormula; + } + } + } + + if (pHnPoint.xrange != L"") + { + if ( oHandle.gdRefType.x != ptAdjust && oHandle.gdRefType.y == ptAdjust) + { + oHandle.gdRef.x = GetHandleValue(sPos1, m_lWidth, ptType); + oHandle.gdRefType.x = ptType; + oHandle.bRefExist.x = true; + + oHandle.gdRef.y = GetHandleValue(sPos0, m_lHeight, ptType); + oHandle.gdRefType.y = ptType; + oHandle.bRefExist.y = false; + } + + boost::algorithm::split(arPos, pHnPoint.xrange, boost::algorithm::is_any_of(L","), boost::algorithm::token_compress_on); + + oHandle.Min.x = GetHandleValue(arPos[0], m_lWidth, ptType); + oHandle.MinType.x = ptType; + if ( oHandle.bRefExist.x) + oHandle.bMinExist.x = true; + + oHandle.Max.x = GetHandleValue(arPos[1], m_lWidth, ptType); + oHandle.MaxType.x = ptType; + if ( oHandle.bRefExist.x) + oHandle.bMaxExist.x = true; + } + + if (pHnPoint.yrange != L"") + { + if (oHandle.gdRefType.x == ptAdjust && oHandle.gdRefType.y != ptAdjust) + { + oHandle.gdRef.x = GetHandleValue(sPos1, m_lWidth, ptType); + oHandle.gdRefType.x = ptType; + oHandle.bRefExist.x = false; + + oHandle.gdRef.y = GetHandleValue(sPos0, m_lHeight, ptType); + oHandle.gdRefType.y = ptType; + oHandle.bRefExist.y = true; + } + boost::algorithm::split(arPos, pHnPoint.yrange, boost::algorithm::is_any_of(L","), boost::algorithm::token_compress_on); + + oHandle.Min.y = GetHandleValue(arPos[0], m_lHeight, ptType); + oHandle.MinType.y = ptType; + if ( oHandle.bRefExist.y ) + oHandle.bMinExist.y = true; + + oHandle.Max.y = GetHandleValue(arPos[1], m_lHeight, ptType); + oHandle.MaxType.y = ptType; + if ( oHandle.bRefExist.y ) + oHandle.bMaxExist.y = true; + } + + if (pHnPoint.radiusrange != L"") + { + boost::algorithm::split(arPos, pHnPoint.radiusrange, boost::algorithm::is_any_of(L","), boost::algorithm::token_compress_on); + + oHandle.Min.x = GetHandleValue(arPos[0], m_lHeight, ptType); + oHandle.MinType.x = ptType; + oHandle.bMinPolarExist.x = true; + + oHandle.Max.x = GetHandleValue(arPos[1], m_lHeight, ptType); + oHandle.MaxType.x = ptType; + oHandle.bMinPolarExist.y = true; + + if (oHandle.gdRefType.x == ptAdjust) + { + oHandle.bRefPolarExist.x = true; + oHandle.bRefExist.x = false; + } + } + + CreateHandle(oHandle); + + } + ConvertAdj(arAdj); + } + void CFormulaConverter::SetTextRectDefault() + { + m_lIndexSrc++; + + ConvertProd(L"w", L"0", m_lWidth, m_oGuidsRes); + ConvertProd(L"h", L"0", m_lHeight, m_oGuidsRes); + ConvertProd(L"w", std::to_wstring(m_lWidth), m_lWidth, m_oGuidsRes); + ConvertProd(L"h", std::to_wstring(m_lHeight), m_lHeight, m_oGuidsRes); + + m_arIndexDst.push_back(m_lIndexDst); + + m_oTextRect.WriteString(L""); + } + void CFormulaConverter::ConvertTextRect ( std::wstring strRect) + { + if (strRect.empty()) + return; + + std::vector arBorder; + boost::algorithm::split(arBorder, strRect, boost::algorithm::is_any_of(L","), boost::algorithm::token_compress_on); + + m_lIndexSrc++; + if (arBorder.size() > 0 && !arBorder[0].empty()) + ConvertProd(L"w", arBorder[0], m_lWidth, m_oGuidsRes); + else + ConvertProd(L"w", L"0", m_lWidth, m_oGuidsRes); + + if (arBorder.size() > 1 && !arBorder[1].empty()) + ConvertProd(L"h", arBorder[1], m_lHeight, m_oGuidsRes); + else + ConvertProd(L"h", L"0", m_lHeight, m_oGuidsRes); + + if (arBorder.size() > 2 && !arBorder[2].empty()) + ConvertProd(L"w", arBorder[2], m_lWidth, m_oGuidsRes); + else + ConvertProd(L"w", std::to_wstring(m_lWidth), m_lWidth, m_oGuidsRes); + + if (arBorder.size() > 3 && !arBorder[3].empty()) + ConvertProd(L"h", arBorder[3], m_lHeight, m_oGuidsRes); + else + ConvertProd(L"h", std::to_wstring(m_lHeight), m_lHeight, m_oGuidsRes); + + m_arIndexDst.push_back(m_lIndexDst); + + // if (true) + // { + m_oTextRect.WriteString(L""); + // } else + // { + // m_oTextRect.WriteString(L""); + // } + + } + void CFormulaConverter::GetValue(const LONG& lParam, const ParamType& eParamType, const bool& bExtShape, NSBinPptxRW::CXmlWriter& oWriter) + { + oWriter.m_oWriter.AddSize(15); + switch (eParamType) + { + case ptFormula: + if (bExtShape || lParam < (int)m_arIndexDst.size()) + { + oWriter.m_oWriter.AddCharNoCheck((WCHAR)'g'); + oWriter.m_oWriter.AddCharNoCheck((WCHAR)'d'); + + if (bExtShape) + oWriter.m_oWriter.AddIntNoCheck(lParam); + else + oWriter.m_oWriter.AddIntNoCheck(m_arIndexDst[lParam]); + } + break; + case ptAdjust: + { + oWriter.m_oWriter.AddCharNoCheck((WCHAR)'a'); + oWriter.m_oWriter.AddCharNoCheck((WCHAR)'d'); + oWriter.m_oWriter.AddCharNoCheck((WCHAR)'j'); + oWriter.m_oWriter.AddIntNoCheck(lParam); + + if (lParam > m_lMaxAdjUse) + m_lMaxAdjUse = lParam; + + break; + } + case ptValue: + { + oWriter.m_oWriter.AddIntNoCheck(lParam); + break; + } + default: + break; + } + } + std::wstring CFormulaConverter::GetValue2(const LONG& lParam, const ParamType& eParamType, const bool& bExtShape) + { + std::wstring strValue; + switch (eParamType) + { + case ptFormula: + { + if (bExtShape) + strValue = std::to_wstring(lParam); + else + strValue = std::to_wstring(m_arIndexDst[lParam]); + strValue = L"gd" + strValue; + break; + } + case ptAdjust: + { + strValue = std::to_wstring(lParam); + strValue = L"adj" + strValue; + break; + } + case ptValue: + { + strValue = std::to_wstring(lParam); + strValue = strValue; + break; + } + default: + break; + } + return strValue; + } + + void CFormulaConverter::ConvertVal(const LONG& lParam1, const ParamType& eType1, const bool& bExtShape1, NSBinPptxRW::CXmlWriter& oWriter) + { + GUIDE_PARAM_1(val) + } + + void CFormulaConverter::ConvertSum(const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, + const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, NSBinPptxRW::CXmlWriter& oWriter) + { + GUIDE_PARAM_3(sum) + } + + void CFormulaConverter::ConvertProd(const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, + const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, NSBinPptxRW::CXmlWriter& oWriter) + { + GUIDE_PARAM_3(prod) + } + + void CFormulaConverter::ConvertAbs(const LONG& lParam1, const ParamType& eType1, const bool& bExtShape1, NSBinPptxRW::CXmlWriter& oWriter) + { + GUIDE_PARAM_1(abs) + } + + void CFormulaConverter::ConvertMin(const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, + const bool& bExtShape1, const bool& bExtShape2, NSBinPptxRW::CXmlWriter& oWriter) + { + GUIDE_PARAM_2(min) + } + + void CFormulaConverter::ConvertMax (const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, + const bool& bExtShape1, const bool& bExtShape2, NSBinPptxRW::CXmlWriter& oWriter) + { + GUIDE_PARAM_2(max) + } + void CFormulaConverter::ConvertIf(const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, + const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, NSBinPptxRW::CXmlWriter& oWriter) + { + GUIDE_PARAM_3(_if) + } + + void CFormulaConverter::ConvertSqrt(const LONG& lParam1, const ParamType& eType1, const bool& bExtShape1, NSBinPptxRW::CXmlWriter& oWriter) + { + GUIDE_PARAM_1(sqrt) + } + + void CFormulaConverter::ConvertAt2 (const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, + const bool& bExtShape1, const bool& bExtShape2, NSBinPptxRW::CXmlWriter& oWriter) + { + GUIDE_PARAM_2(at2) + } + + void CFormulaConverter::ConvertSin (const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, + const bool& bExtShape1, const bool& bExtShape2, NSBinPptxRW::CXmlWriter& oWriter) + { + GUIDE_PARAM_2(sin) + } + + void CFormulaConverter::ConvertCos (const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, + const bool& bExtShape1, const bool& bExtShape2, NSBinPptxRW::CXmlWriter& oWriter) + { + GUIDE_PARAM_2(cos) + } + + void CFormulaConverter::ConvertCat2(const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, + const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, NSBinPptxRW::CXmlWriter& oWriter) + { + GUIDE_PARAM_3(cat2) + } + + void CFormulaConverter::ConvertSat2(const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, + const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, NSBinPptxRW::CXmlWriter& oWriter) + { + GUIDE_PARAM_3(sat2) + } + + void CFormulaConverter::ConvertMod(const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, + const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, NSBinPptxRW::CXmlWriter& oWriter) + { + GUIDE_PARAM_3(mod) + } + + void CFormulaConverter::ConvertTag (const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, + const bool& bExtShape1, const bool& bExtShape2, NSBinPptxRW::CXmlWriter& oWriter) + { + GUIDE_PARAM_2(tag) + } + + void CFormulaConverter::ConvertProd(const std::wstring& strParam1, const std::wstring& strParam2, const LONG& lParam3, NSBinPptxRW::CXmlWriter& oWriter) + { + oWriter.m_oWriter.AddSize(g_guide_max_len); + oWriter.m_oWriter.WriteStringNoSafe(g_guide_string1, g_guide_string1_len); + oWriter.m_oWriter.AddIntNoCheck(m_lIndexDst); + oWriter.m_oWriter.WriteStringNoSafe(g_guide_string_prod, g_guide_string_prod_len); + oWriter.WriteString(strParam1); + oWriter.m_oWriter.AddSpaceNoCheck(); + + if ('#' == strParam2[0]) + { + LONG lRes = (LONG)XmlUtils::GetInteger(strParam2.substr(1)); + GetValue(lRes, ptAdjust, false, oWriter); + } + else if ('@' == strParam2[0]) + { + LONG lRes = (LONG)XmlUtils::GetInteger(strParam2.substr(1)); + GetValue(lRes, ptFormula, false, oWriter); + } + else + oWriter.WriteString(strParam2); + + oWriter.m_oWriter.AddSpaceNoCheck(); + GetValue(lParam3, ptValue, false, oWriter); + + ++m_lIndexDst; + oWriter.m_oWriter.WriteStringNoSafe(g_guide_string2, g_guide_string2_len); + } + + void CFormulaConverter::FromXML(std::wstring strPath, bool &m_bFill, bool &m_bStroke) + { + m_arSlicesPath.clear(); + NSStringUtils::CheckPathOn_Fill_Stroke(strPath, m_bFill, m_bStroke); + std::vector oArray; + + NSStringUtils::ParsePath2(strPath, &oArray); + + ParamType eParamType = ptValue; + RulesType eRuler = rtEnd; + LONG lValue; + bool bRes = true; + + for (size_t nIndex = 0; nIndex < oArray.size(); ++nIndex) + { + std::wstring str = oArray[nIndex]; + lValue = NSGuidesVML::GetValue(oArray[nIndex], eParamType, bRes); + if (bRes) + { + if (0 != m_arSlicesPath.size()) + { + if ( lValue >= 0x7fffff00 || lValue <= -0x7fffff00) + { + lValue = 0; //process(2).ppt - todooo разобраться что за хрень это ваще приплыла + } + + m_arSlicesPath[m_arSlicesPath.size() - 1].AddParam(lValue, eParamType); + } + } + else + { + eRuler = GetRuler(oArray[nIndex], bRes); + if (bRes) + { + if (rtNoFill == eRuler) + { + m_bFill = false; + } + else if (rtNoStroke == eRuler) + { + m_bStroke = false; + } + else + { + CSlicePath oSlice(eRuler, m_lX, m_lY); + + m_arSlicesPath.push_back(oSlice); + } + } + } + } + } + void CFormulaConverter::CreateHandle ( SHandle oHnd ) + { + std::wstring strRes = L""; + if (oHnd.bRefPolarExist.x || oHnd.bRefPolarExist.y) + m_oHandleRes.WriteString(L""); + else if (oHnd.bRefExist.x || oHnd.bRefExist.y) + m_oHandleRes.WriteString(L"\"/>"); + } + + LONG CFormulaConverter::GetHandlePos(const std::wstring& strParam, const std::wstring& strBase, LONG lSize) + { + LONG lRes; + std::wstring strSize = L" " + std::to_wstring(lSize); + std::wstring strIndex; + + if ('#' == strParam[0]) + { + lRes = (LONG)XmlUtils::GetInteger(strParam.substr(1)); + strFrmla = GetValue2(lRes, ptAdjust, false) + strSize; + } + else if ('&' == strParam[0]) + { + lRes = (LONG)XmlUtils::GetInteger(strParam.substr(1)); + strFrmla = GetValue2(lRes, ptFormula, true) + strSize; + } + else if ('@' == strParam[0]) + { + lRes = (LONG)XmlUtils::GetInteger(strParam.substr(1)); + strFrmla = GetValue2(lRes, ptFormula, false) + strSize; + } + else if (!NSStringUtils::IsNumber(strParam)) + { + if (L"center" == strParam) + strFrmla = L"1 2"; + else if (L"topLeft" == strParam) + strFrmla = L"0 1"; + else if ( L"bottomRight" == strParam) + strFrmla = L"1 1"; + } + else + { + lRes = (LONG)XmlUtils::GetInteger(strParam); + strFrmla = GetValue2(lRes, ptValue, false) + strSize; + } + + m_lIndexSrc++; + m_arIndexDst.push_back(m_lIndexDst); + strIndex = std::to_wstring(m_lIndexDst); + + m_oGuidsRes.WriteString(L""); + + m_lIndexDst++; + + return m_lIndexDst-1; + } + LONG CFormulaConverter::GetHandleValue(const std::wstring& strParam, const LONG& lVal, ParamType& ptType) + { + ptType = ptValue; + if ('#' == strParam[0]) + { + ptType = ptAdjust; + return (LONG)XmlUtils::GetInteger(strParam.substr(1)); + } + else if ('@' == strParam[0]) + { + ptType = ptFormula; + return (LONG)XmlUtils::GetInteger(strParam.substr(1)); + } + else if (!NSStringUtils::IsNumber(strParam)) + { + if (L"center" == strParam) + return lVal/2; + else if (L"bottomRight" == strParam)//Demo-Hayden-Management-v2.docx + return lVal; + else + return 0; //??? + //todooo прописать все варианты правильно + } + else + { + ptType = ptValue; + return (LONG)XmlUtils::GetInteger(strParam); + } + } + void CFormulaConverter::ConvertQuadrX(Aggplus::POINT pPoint, SPointType pPointType) + { + LONG nIndex = m_arIndexDst[m_lIndexSrc]; + + m_lIndexSrc++; + + ConvertSum(pPoint.x, pPointType.x, 0, ptValue, nIndex-1, ptFormula, false, true, true, m_oGuidsRes); + ConvertSum(pPoint.y, pPointType.y, 0, ptValue, nIndex, ptFormula, false, true, true, m_oGuidsRes); + ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-2, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(m_lIndexDst-4, ptFormula, 16200000, ptValue, 5400000, ptValue, true, true, true, m_oGuidsRes); //stAng + ConvertIf(m_lIndexDst-2, ptFormula, 5400000, ptValue, -5400000, ptValue, true, true, true, m_oGuidsRes); //swAng + ConvertProd(m_lIndexDst-7, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-7, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(m_lIndexDst-9, ptFormula, m_lIndexDst-9, ptFormula, m_lIndexDst-2, ptFormula, true, true, true, m_oGuidsRes);//wR + ConvertIf(m_lIndexDst-9, ptFormula, m_lIndexDst-9, ptFormula, m_lIndexDst-2, ptFormula, true, true, true, m_oGuidsRes);//hR + + m_arIndexDst.push_back(m_lIndexDst-1); + + nIndex = m_arIndexDst[m_lIndexSrc]; + + m_oPathRes.WriteString(L""); + + m_lIndexSrc++; + ConvertVal(pPoint.x, pPointType.x, false, m_oGuidsRes); + ConvertVal(pPoint.y, pPointType.y, false, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + return; + } + + void CFormulaConverter::ConvertQuadrY(Aggplus::POINT pPoint, SPointType pPointType) + { + LONG nIndex = m_arIndexDst[m_lIndexSrc]; + + m_lIndexSrc++; + + ConvertSum(pPoint.x, pPointType.x, 0, ptValue, nIndex-1, ptFormula, false, true, true, m_oGuidsRes); + ConvertSum(pPoint.y, pPointType.y, 0, ptValue, nIndex, ptFormula, false, true, true, m_oGuidsRes); + ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-2, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(m_lIndexDst-5, ptFormula, 10800000, ptValue, 0, ptValue, true, true, true, m_oGuidsRes); //stAng + ConvertIf(m_lIndexDst-2, ptFormula, -5400000, ptValue, 5400000, ptValue, true, true, true, m_oGuidsRes); //swAng + ConvertProd(m_lIndexDst-7, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-7, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(m_lIndexDst-9, ptFormula, m_lIndexDst-9, ptFormula, m_lIndexDst-2, ptFormula, true, true, true, m_oGuidsRes);//wR + ConvertIf(m_lIndexDst-9, ptFormula, m_lIndexDst-9, ptFormula, m_lIndexDst-2, ptFormula, true, true, true, m_oGuidsRes);//hR + m_arIndexDst.push_back(m_lIndexDst-1); + + nIndex = m_arIndexDst[m_lIndexSrc]; + + m_oPathRes.WriteString(L""); + + m_lIndexSrc++; + ConvertVal(pPoint.x, pPointType.x, false, m_oGuidsRes); + ConvertVal(pPoint.y, pPointType.y, false, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + return; + } + void CFormulaConverter::ConvertSlice_MoveTo(const CSlicePath& oSlice) + { + for (size_t j = 0; j < oSlice.m_arPoints.size(); ++j) + { + pCurPoint = oSlice.m_arPoints[j]; + pCurPointType = oSlice.m_arPointsType[j]; + + m_lIndexSrc++; + ConvertVal(pCurPoint.x, pCurPointType.x, false, m_oGuidsRes); + ConvertVal(pCurPoint.y, pCurPointType.y, false, m_oGuidsRes); + + m_arIndexDst.push_back(m_lIndexDst-1); + + m_oPathRes.WriteString(L""); + } + } + void CFormulaConverter::ConvertSlice_RMoveTo(const CSlicePath& oSlice) + { + for (size_t j = 0; j < oSlice.m_arPoints.size(); j++) + { + pCurPoint = oSlice.m_arPoints[j]; + pCurPointType = oSlice.m_arPointsType[j]; + + m_lIndexSrc ++; + ConvertSum(m_lIndexDst-2, ptFormula, pCurPoint.x, pCurPointType.x, 0, ptValue, true, false, true, m_oGuidsRes); + ConvertSum(m_lIndexDst-2, ptFormula, pCurPoint.y, pCurPointType.y, 0, ptValue, true, false, true, m_oGuidsRes); + + m_arIndexDst.push_back(m_lIndexDst-1); + + m_oPathRes.WriteString(L""); + } + } + void CFormulaConverter::ConvertSlice_LineTo(const CSlicePath& oSlice) + { + for (size_t j = 0; j < oSlice.m_arPoints.size(); j++) + { + pCurPoint = oSlice.m_arPoints[j]; + pCurPointType = oSlice.m_arPointsType[j]; + + m_lIndexSrc++; + ConvertVal(pCurPoint.x, pCurPointType.x, false, m_oGuidsRes); + ConvertVal(pCurPoint.y, pCurPointType.y, false, m_oGuidsRes); + + m_arIndexDst.push_back(m_lIndexDst-1); + + m_oPathRes.WriteString(L""); + } + } + void CFormulaConverter::ConvertSlice_RLineTo(const CSlicePath& oSlice) + { + for (size_t j = 0; j < oSlice.m_arPoints.size(); j++) + { + pCurPoint = oSlice.m_arPoints[j]; + pCurPointType = oSlice.m_arPointsType[j]; + + m_lIndexSrc++; + ConvertSum(m_lIndexDst-2, ptFormula, pCurPoint.x, pCurPointType.x, 0, ptValue, true, false, true, m_oGuidsRes); + ConvertSum(m_lIndexDst-2, ptFormula, pCurPoint.y, pCurPointType.y, 0, ptValue, true, false, true, m_oGuidsRes); + + m_arIndexDst.push_back(m_lIndexDst-1); + + m_oPathRes.WriteString(L""); + } + } + void CFormulaConverter::ConvertSlice_ArcTo(const CSlicePath& oSlice) + { + LONG nIndex = 0; + LONG nIndex1 = 0; + LONG nIndex2 = 0; + + for (size_t j = 0; j < oSlice.m_arPoints.size(); j+=4) + { + pCurPoint = oSlice.m_arPoints[j]; + pCurPointType = oSlice.m_arPointsType[j]; + pCurPoint1 = oSlice.m_arPoints[j+1]; + pCurPointType1 = oSlice.m_arPointsType[j+1]; + + //длина сторон + m_lIndexSrc++; + ConvertSum(pCurPoint1.x, pCurPointType1.x, 0, ptValue, pCurPoint.x, pCurPointType.x, false, true, false, m_oGuidsRes); + ConvertSum(pCurPoint1.y, pCurPointType1.y, 0, ptValue, pCurPoint.y, pCurPointType.y, false, true, false, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //координаты центра + nIndex = m_arIndexDst[m_lIndexSrc]; + + m_lIndexSrc++; + ConvertProd(nIndex-1, ptFormula, 1, ptValue, 2, ptValue, true, true, true, m_oGuidsRes); //a=wR + ConvertProd(nIndex, ptFormula, 1, ptValue, 2, ptValue, true, true, true, m_oGuidsRes); //b=hR + + ConvertSum(pCurPoint.x, pCurPointType.x, m_lIndexDst-2, ptFormula, 0, ptValue, false, true, true, m_oGuidsRes); + ConvertSum(pCurPoint.y, pCurPointType.y, m_lIndexDst-2, ptFormula, 0, ptValue, false, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //рассчет для stAng--------------------------- + //расположение текущей точки по четвертям 3 4 + // 2 1 + + pCurPoint = oSlice.m_arPoints[j+2]; + pCurPointType = oSlice.m_arPointsType[j+2]; + nIndex = m_arIndexDst[m_lIndexSrc]; + + m_lIndexSrc++; + ConvertSum(pCurPoint.x, pCurPointType.x, 0, ptValue, nIndex-1, ptFormula, false, true, true, m_oGuidsRes); + ConvertSum(pCurPoint.y, pCurPointType.y, 0, ptValue, nIndex, ptFormula, false, true, true, m_oGuidsRes); + ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //угол между Ох и радиус-вектором к точке + nIndex = m_arIndexDst[m_lIndexSrc]; + + m_lIndexSrc++; + ConvertProd(nIndex-2, ptFormula, 1, ptValue, nIndex-3, ptFormula, true, true, true, m_oGuidsRes); + ConvertAt2(1, ptValue, m_lIndexDst-1, ptFormula, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //радиус к точке + nIndex = m_arIndexDst[m_lIndexSrc]; + nIndex1 = m_arIndexDst[m_lIndexSrc-2]; + + m_lIndexSrc++; + ConvertCos(1, ptValue, nIndex, ptFormula, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(nIndex1-2, ptFormula, nIndex1-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//(b*cos(u))^2 + + ConvertSin(1, ptValue, nIndex, ptFormula, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(nIndex1-3, ptFormula, nIndex1-3, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//(a*sin(u))^2 + + ConvertSum(m_lIndexDst-1, ptFormula, m_lIndexDst-5, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); + ConvertSqrt(m_lIndexDst-1, ptFormula, true, m_oGuidsRes); + ConvertProd(nIndex1-3, ptFormula, nIndex1-2, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//r + m_arIndexDst.push_back(m_lIndexDst-1); + //если точка во 2 и 3 четвертях, прибавляем по 180grad + nIndex = m_arIndexDst[m_lIndexSrc-2]; + + m_lIndexSrc++; + ConvertIf(nIndex-3, ptFormula, 0, ptValue, 10800000, ptValue, true, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //угол до 1 точки (stAngle) + nIndex = m_arIndexDst[m_lIndexSrc-2];//угол между ох и радиусом + nIndex1 = m_arIndexDst[m_lIndexSrc-3];//расположение точки по четвертям + nIndex2 = m_arIndexDst[m_lIndexSrc];//прибавка 180 или 0 + + m_lIndexSrc ++; + ConvertProd(nIndex1-1, ptFormula, nIndex1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//знак у угла + ConvertProd(nIndex, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(nIndex, ptFormula, nIndex, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//угол всегда положительный + + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-3, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//u с нужным знаком + + ConvertSum(m_lIndexDst-1, ptFormula, nIndex2, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //координаты стартовой точки + nIndex = m_arIndexDst[m_lIndexSrc-2]; + nIndex1 = m_arIndexDst[m_lIndexSrc-4]; + nIndex2 = m_arIndexDst[m_lIndexSrc-5]; + + m_lIndexSrc++; + ConvertProd(nIndex, ptFormula, nIndex-10, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//r*cos(a) + ConvertProd(nIndex1-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertSum(nIndex2-1, ptFormula, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); //x + + ConvertProd(nIndex-6, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(nIndex-6, ptFormula, nIndex-6, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//sin теперь всегда>0 + + ConvertProd(nIndex, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//r*sin + ConvertProd(nIndex1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertSum(nIndex2, ptFormula, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes);//y + m_arIndexDst.push_back(m_lIndexDst-1); + //рассчет для swAng--------------------------- + //расположение текущей точки по четвертям 3 4 + // 2 1 + + pCurPoint = oSlice.m_arPoints[j+3]; + pCurPointType = oSlice.m_arPointsType[j+3]; + + nIndex = m_arIndexDst[m_lIndexSrc-6]; + + m_lIndexSrc++; + ConvertSum(pCurPoint.x, pCurPointType.x, 0, ptValue, nIndex-1, ptFormula, false, true, true, m_oGuidsRes); + ConvertSum(pCurPoint.y, pCurPointType.y, 0, ptValue, nIndex, ptFormula, false, true, true, m_oGuidsRes); + ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //угол между Ох и радиус-вектором к точке + nIndex = m_arIndexDst[m_lIndexSrc]; + + m_lIndexSrc++; + ConvertProd(nIndex-2, ptFormula, 1, ptValue, nIndex-3, ptFormula, true, true, true, m_oGuidsRes); + ConvertAt2(1, ptValue, m_lIndexDst-1, ptFormula, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //радиус к точке + nIndex = m_arIndexDst[m_lIndexSrc]; + nIndex1 = m_arIndexDst[m_lIndexSrc-8]; + + m_lIndexSrc++; + ConvertCos(1, ptValue, nIndex, ptFormula, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(nIndex1-2, ptFormula, nIndex1-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + + ConvertSin(1, ptValue, nIndex, ptFormula, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(nIndex1-3, ptFormula, nIndex1-3, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + + ConvertSum(m_lIndexDst-1, ptFormula, m_lIndexDst-5, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); + ConvertSqrt(m_lIndexDst-1, ptFormula, true, m_oGuidsRes); + ConvertProd(nIndex1-3, ptFormula, nIndex1-2, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //если точка во 2 и 3 четвертях, прибавляем по 180grad + nIndex = m_arIndexDst[m_lIndexSrc-2]; + + m_lIndexSrc++; + ConvertIf(nIndex-3, ptFormula, 0, ptValue, 10800000, ptValue, true, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //угол до 2 точки + nIndex = m_arIndexDst[m_lIndexSrc-2];//угол между ох и радиусом + nIndex1 = m_arIndexDst[m_lIndexSrc-3];//расположение точки по четвертям + nIndex2 = m_arIndexDst[m_lIndexSrc];//прибавка 180 или 0 + + m_lIndexSrc++; + ConvertProd(nIndex1-1, ptFormula, nIndex1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//знак у угла + ConvertProd(nIndex, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(nIndex, ptFormula, nIndex, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//угол всегда положительный + + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-3, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//u с нужным знаком + + ConvertSum(m_lIndexDst-1, ptFormula, nIndex2, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //координаты конечной точки + nIndex = m_arIndexDst[m_lIndexSrc-2]; + nIndex1 = m_arIndexDst[m_lIndexSrc-4]; + nIndex2 = m_arIndexDst[m_lIndexSrc-11]; + + m_lIndexSrc++; + ConvertProd(nIndex, ptFormula, nIndex-10, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//r*cos(a) + ConvertProd(nIndex1-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertSum(nIndex2-1, ptFormula, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes);//x + + ConvertProd(nIndex-6, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(nIndex-6, ptFormula, nIndex-6, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//sin теперь всегда>0 + + ConvertProd(nIndex, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//r*sin(a) + ConvertProd(nIndex1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertSum(nIndex2, ptFormula, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes);//y + m_arIndexDst.push_back(m_lIndexDst-1); + //swAngle + nIndex = m_arIndexDst[m_lIndexSrc-1]; //2 угол + nIndex1 = m_arIndexDst[m_lIndexSrc-7]; //1 угол + + m_lIndexSrc++; + ConvertSum(nIndex1, ptFormula, 0, ptValue, nIndex, ptFormula, true, true, true, m_oGuidsRes); // (1)-(2), если отрицательный то берем его, иначе пересчитываем + ConvertProd(m_lIndexDst-1, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); + + ConvertSum(nIndex1, ptFormula, 21600000, ptValue, nIndex, ptFormula, true, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); // -1*((1)+360-(2)) + + ConvertIf(m_lIndexDst-4, ptFormula, m_lIndexDst-3, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes); + + m_arIndexDst.push_back(m_lIndexDst-1); + //wR,hR + nIndex = m_arIndexDst[m_lIndexSrc-14]; + m_lIndexSrc++; + ConvertProd(nIndex-1, ptFormula, 1, ptValue, 2, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(nIndex, ptFormula, 1, ptValue, 2, ptValue, true, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + + //--------------------------------------------------------- + nIndex = m_arIndexDst[m_lIndexSrc-8];//координаты стартовой точки + nIndex1 = m_arIndexDst[m_lIndexSrc-9];//stAng + nIndex2 = m_arIndexDst[m_lIndexSrc-1];//swAng + + if (oSlice.m_eRuler == rtArc && j == 0) + strFrmla = L"moveTo"; + else + strFrmla = L"lnTo"; + + if (oSlice.m_eRuler == rtArc && j == 0) + { + m_oPathRes.WriteString(L""); + } + else + { + m_oPathRes.WriteString(L""); + } + + //старт + /* + LONG nIndex3 = m_arIndexDst[m_lIndexSrc-14]; + strPathRes += L""); + */ + + //текущая точка + nIndex = m_arIndexDst[m_lIndexSrc-2]; + ConvertVal(nIndex-5, ptFormula, true, m_oGuidsRes); + ConvertVal(nIndex, ptFormula, true, m_oGuidsRes); + } + } + void CFormulaConverter::ConvertSlice_ClockwiseTo(const CSlicePath& oSlice) + { + LONG nIndex = 0; + LONG nIndex1 = 0; + LONG nIndex2 = 0; + + for (size_t j = 0; j < oSlice.m_arPoints.size(); j += 4) + { + pCurPoint = oSlice.m_arPoints[j]; + pCurPointType = oSlice.m_arPointsType[j]; + pCurPoint1 = oSlice.m_arPoints[j+1]; + pCurPointType1 = oSlice.m_arPointsType[j+1]; + + //длина сторон + m_lIndexSrc++; + ConvertSum(pCurPoint1.x, pCurPointType1.x, 0, ptValue, pCurPoint.x, pCurPointType.x, false, true, false, m_oGuidsRes); + ConvertSum(pCurPoint1.y, pCurPointType1.y, 0, ptValue, pCurPoint.y, pCurPointType.y, false, true, false, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //координаты центра + nIndex = m_arIndexDst[m_lIndexSrc]; + + m_lIndexSrc++; + ConvertProd(nIndex-1, ptFormula, 1, ptValue, 2, ptValue, true, true, true, m_oGuidsRes); //a=wR + ConvertProd(nIndex, ptFormula, 1, ptValue, 2, ptValue, true, true, true, m_oGuidsRes); //b=hR + + ConvertSum(pCurPoint.x, pCurPointType.x, m_lIndexDst-2, ptFormula, 0, ptValue, false, true, true, m_oGuidsRes); + ConvertSum(pCurPoint.y, pCurPointType.y, m_lIndexDst-2, ptFormula, 0, ptValue, false, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //рассчет для stAng--------------------------- + //расположение текущей точки по четвертям 3 4 + // 2 1 + + pCurPoint = oSlice.m_arPoints[j+2]; + pCurPointType = oSlice.m_arPointsType[j+2]; + nIndex = m_arIndexDst[m_lIndexSrc]; + + m_lIndexSrc++; + ConvertSum(pCurPoint.x, pCurPointType.x, 0, ptValue, nIndex-1, ptFormula, false, true, true, m_oGuidsRes); + ConvertSum(pCurPoint.y, pCurPointType.y, 0, ptValue, nIndex, ptFormula, false, true, true, m_oGuidsRes); + ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //угол между Ох и радиус-вектором к точке + nIndex = m_arIndexDst[m_lIndexSrc]; + + m_lIndexSrc++; + ConvertProd(nIndex-2, ptFormula, 1, ptValue, nIndex-3, ptFormula, true, true, true, m_oGuidsRes); + ConvertAt2(1, ptValue, m_lIndexDst-1, ptFormula, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //радиус к точке + nIndex = m_arIndexDst[m_lIndexSrc]; + nIndex1 = m_arIndexDst[m_lIndexSrc-2]; + + m_lIndexSrc++; + ConvertCos(1, ptValue, nIndex, ptFormula, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(nIndex1-2, ptFormula, nIndex1-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//(b*cos(u))^2 + + ConvertSin(1, ptValue, nIndex, ptFormula, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(nIndex1-3, ptFormula, nIndex1-3, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//(a*sin(u))^2 + + ConvertSum(m_lIndexDst-1, ptFormula, m_lIndexDst-5, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); + ConvertSqrt(m_lIndexDst-1, ptFormula, true, m_oGuidsRes); + ConvertProd(nIndex1-3, ptFormula, nIndex1-2, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//r + m_arIndexDst.push_back(m_lIndexDst-1); + //если точка во 2 и 3 четвертях, прибавляем по 180grad + nIndex = m_arIndexDst[m_lIndexSrc-2]; + + m_lIndexSrc++; + ConvertIf(nIndex-3, ptFormula, 0, ptValue, 10800000, ptValue, true, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //угол до 1 точки (stAngle) + nIndex = m_arIndexDst[m_lIndexSrc-2];//угол между ох и радиусом + nIndex1 = m_arIndexDst[m_lIndexSrc-3];//расположение точки по четвертям + nIndex2 = m_arIndexDst[m_lIndexSrc];//прибавка 180 или 0 + + m_lIndexSrc++; + ConvertProd(nIndex1-1, ptFormula, nIndex1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//знак у угла + ConvertProd(nIndex, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(nIndex, ptFormula, nIndex, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//угол всегда положительный + + ConvertProd ( m_lIndexDst-1, ptFormula, m_lIndexDst-3, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//u с нужным знаком + + ConvertSum ( m_lIndexDst-1, ptFormula, nIndex2, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //координаты стартовой точки + nIndex = m_arIndexDst[m_lIndexSrc-2]; + nIndex1 = m_arIndexDst[m_lIndexSrc-4]; + nIndex2 = m_arIndexDst[m_lIndexSrc-5]; + + m_lIndexSrc++; + ConvertProd(nIndex, ptFormula, nIndex-10, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//r*cos(a) + ConvertProd(nIndex1-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertSum(nIndex2-1, ptFormula, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); //x + + ConvertProd(nIndex-6, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(nIndex-6, ptFormula, nIndex-6, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//sin теперь всегда>0 + + ConvertProd(nIndex, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//r*sin + ConvertProd(nIndex1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertSum(nIndex2, ptFormula, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes);//y + m_arIndexDst.push_back(m_lIndexDst-1); + //рассчет для swAng--------------------------- + //расположение текущей точки по четвертям 3 4 + // 2 1 + + pCurPoint = oSlice.m_arPoints[j+3]; + pCurPointType = oSlice.m_arPointsType[j+3]; + + nIndex = m_arIndexDst[m_lIndexSrc-6]; + + m_lIndexSrc++; + ConvertSum(pCurPoint.x, pCurPointType.x, 0, ptValue, nIndex-1, ptFormula, false, true, true, m_oGuidsRes); + ConvertSum(pCurPoint.y, pCurPointType.y, 0, ptValue, nIndex, ptFormula, false, true, true, m_oGuidsRes); + ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //угол между Ох и радиус-вектором к точке + nIndex = m_arIndexDst[m_lIndexSrc]; + + m_lIndexSrc++; + ConvertProd(nIndex-2, ptFormula, 1, ptValue, nIndex-3, ptFormula, true, true, true, m_oGuidsRes); + ConvertAt2(1, ptValue, m_lIndexDst-1, ptFormula, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //радиус к точке + nIndex = m_arIndexDst[m_lIndexSrc]; + nIndex1 = m_arIndexDst[m_lIndexSrc-8]; + + m_lIndexSrc++; + ConvertCos(1, ptValue, nIndex, ptFormula, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(nIndex1-2, ptFormula, nIndex1-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + + ConvertSin(1, ptValue, nIndex, ptFormula, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(nIndex1-3, ptFormula, nIndex1-3, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + + ConvertSum(m_lIndexDst-1, ptFormula, m_lIndexDst-5, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); + ConvertSqrt(m_lIndexDst-1, ptFormula, true, m_oGuidsRes); + ConvertProd(nIndex1-3, ptFormula, nIndex1-2, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //если точка во 2 и 3 четвертях, прибавляем по 180grad + nIndex = m_arIndexDst[m_lIndexSrc-2]; + + m_lIndexSrc++; + ConvertIf(nIndex-3, ptFormula, 0, ptValue, 10800000, ptValue, true, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //угол до 2 точки + nIndex = m_arIndexDst[m_lIndexSrc-2];//угол между ох и радиусом + nIndex1 = m_arIndexDst[m_lIndexSrc-3];//расположение точки по четвертям + nIndex2 = m_arIndexDst[m_lIndexSrc];//прибавка 180 или 0 + + m_lIndexSrc ++; + ConvertProd(nIndex1-1, ptFormula, nIndex1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//знак у угла + ConvertProd(nIndex, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(nIndex, ptFormula, nIndex, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//угол всегда положительный + + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-3, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//u с нужным знаком + + ConvertSum(m_lIndexDst-1, ptFormula, nIndex2, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + //координаты конечной точки + nIndex = m_arIndexDst[m_lIndexSrc-2]; + nIndex1 = m_arIndexDst[m_lIndexSrc-4]; + nIndex2 = m_arIndexDst[m_lIndexSrc-11]; + + m_lIndexSrc++; + ConvertProd(nIndex, ptFormula, nIndex-10, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//r*cos(a) + ConvertProd(nIndex1-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertSum(nIndex2-1, ptFormula, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes);//x + + ConvertProd(nIndex-6, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(nIndex-6, ptFormula, nIndex-6, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//sin теперь всегда>0 + + ConvertProd(nIndex, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//r*sin(a) + ConvertProd(nIndex1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertSum(nIndex2, ptFormula, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes);//y + m_arIndexDst.push_back(m_lIndexDst-1); + //swAngle + nIndex = m_arIndexDst[m_lIndexSrc-1]; + nIndex1 = m_arIndexDst[m_lIndexSrc-7]; + + m_lIndexSrc++; + ConvertSum(nIndex, ptFormula, 0, ptValue, nIndex1, ptFormula, true, true, true, m_oGuidsRes); + ConvertSum(21600000, ptValue, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); + ConvertIf(m_lIndexDst-2, ptFormula, m_lIndexDst-2, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//swAng + + m_arIndexDst.push_back(m_lIndexDst-1); + //wR,hR + nIndex = m_arIndexDst[m_lIndexSrc-14]; + m_lIndexSrc++; + ConvertProd(nIndex-1, ptFormula, 1, ptValue, 2, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(nIndex, ptFormula, 1, ptValue, 2, ptValue, true, true, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + + //--------------------------------------------------------- + nIndex = m_arIndexDst[m_lIndexSrc-8];//координаты стартовой точки + nIndex1 = m_arIndexDst[m_lIndexSrc-9];//stAng + nIndex2 = m_arIndexDst[m_lIndexSrc-1];//swAng + + if (oSlice.m_eRuler == rtClockwiseArc && j == 0) + { + m_oPathRes.WriteString(L""); + } + else + { + m_oPathRes.WriteString(L""); + } + + //текущая точка + nIndex = m_arIndexDst[m_lIndexSrc-2]; + ConvertVal(nIndex-5, ptFormula, true, m_oGuidsRes); + ConvertVal(nIndex, ptFormula, true, m_oGuidsRes); + } + } + void CFormulaConverter::ConvertSlice_QuadrBesier(const CSlicePath& oSlice) + { + for (size_t j = 0; j < oSlice.m_arPoints.size(); j += 2) + { + int l = (int)(oSlice.m_arPoints.size() - j - 3); + if (l >= 0) + { + m_oPathRes.WriteString(L""); + for (int k = 0; k < 2; ++k) + { + pCurPoint = oSlice.m_arPoints[j+k]; + pCurPointType = oSlice.m_arPointsType[j+k]; + + m_oPathRes.WriteString(L""); + } + m_oPathRes.WriteString(L""); + } + else + { + for (size_t k = 0; k < oSlice.m_arPoints.size() - j; ++k) + { + pCurPoint = oSlice.m_arPoints[j+k]; + pCurPointType = oSlice.m_arPointsType[j+k]; + + m_oPathRes.WriteString(L""); + } + } + + m_lIndexSrc++; + ConvertVal(pCurPoint.x, pCurPointType.x, false, m_oGuidsRes); + ConvertVal(pCurPoint.y, pCurPointType.y, false, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + } + } + void CFormulaConverter::ConvertSlice_CurveTo(const CSlicePath& oSlice) + { + LONG nIndex = 0; + for (size_t j = 0; j < oSlice.m_arPoints.size(); j += 3) + { + int l = (int)(oSlice.m_arPoints.size() - j - 3); + if ( l >= 0 ) + { + m_oPathRes.WriteString(L""); + for (int k = 0; k < 3; ++k) + { + pCurPoint = oSlice.m_arPoints[j+k]; + pCurPointType = oSlice.m_arPointsType[j+k]; + + m_oPathRes.WriteString(L""); + } + m_oPathRes.WriteString(L""); + } + else + { + for (size_t k = 0; k < oSlice.m_arPoints.size() - j; ++k) + { + m_oPathRes.WriteString(L""); + } + } + + m_lIndexSrc++; + ConvertVal(pCurPoint.x, pCurPointType.x, false, m_oGuidsRes); + ConvertVal(pCurPoint.y, pCurPointType.y, false, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + } + } + void CFormulaConverter::ConvertSlice_RCurveTo(const CSlicePath& oSlice) + { + LONG nIndex = 0; + for (size_t j = 0; j < oSlice.m_arPoints.size(); j += 3) + { + nIndex = m_arIndexDst[m_lIndexSrc]; + + int l = (int)(oSlice.m_arPoints.size() - j - 3); + if (l >= 0) + { + m_oPathRes.WriteString(L""); + for (int k = 0; k < 3; ++k) + { + pCurPoint = oSlice.m_arPoints[j+k]; + pCurPointType = oSlice.m_arPointsType[j+k]; + + m_lIndexSrc++; + ConvertSum(nIndex-1, ptFormula, pCurPoint.x, pCurPointType.x, 0, ptValue, true, false, true, m_oGuidsRes); + ConvertSum(nIndex, ptFormula, pCurPoint.y, pCurPointType.y, 0, ptValue, true, false, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + + m_oPathRes.WriteString(L""); + } + m_oPathRes.WriteString(L""); + } + else + { + for (size_t k=0; k < oSlice.m_arPoints.size() - j; ++k) + { + pCurPoint = oSlice.m_arPoints[j+k]; + pCurPointType = oSlice.m_arPointsType[j+k]; + + m_lIndexSrc++; + ConvertSum(nIndex-1, ptFormula, pCurPoint.x, pCurPointType.x, 0, ptValue, true, false, true, m_oGuidsRes); + ConvertSum(nIndex, ptFormula, pCurPoint.y, pCurPointType.y, 0, ptValue, true, false, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + + m_oPathRes.WriteString(L""); + } + } + + nIndex = m_arIndexDst[m_lIndexSrc]; + + m_lIndexSrc++; + ConvertVal(nIndex-1, ptFormula, true, m_oGuidsRes); + ConvertVal(nIndex, ptFormula, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + } + } + void CFormulaConverter::ConvertSlice_AngleEllipse(const CSlicePath& oSlice) + { + LONG nIndex = 0; + LONG nIndex1 = 0; + LONG nIndex2 = 0; + + for (size_t j = 0; j < oSlice.m_arPoints.size(); j += 3) + { + pCurPoint = oSlice.m_arPoints[j+1]; + pCurPointType = oSlice.m_arPointsType[j+1]; + pCurPoint1 = oSlice.m_arPoints[j+2]; + pCurPointType1 = oSlice.m_arPointsType[j+2]; + + //конвертация углов в pptx формат + m_lIndexSrc++; + ConvertProd(pCurPoint1.x, pCurPointType1.x, pow3_16, ptValue, m_oParam.m_lParam, m_oParam.m_eType, false, true, true, m_oGuidsRes); //1 угол + ConvertProd(pCurPoint1.y, pCurPointType1.y, pow3_16, ptValue, m_oParam.m_lParam, m_oParam.m_eType, false, true, true, m_oGuidsRes); //2 угол + m_arIndexDst.push_back(m_lIndexDst-1); + + //wR и hR + nIndex = m_arIndexDst[m_lIndexSrc]; + + m_lIndexSrc++; + ConvertVal(pCurPoint.x, pCurPointType.x, false, m_oGuidsRes);//wr=a + ConvertVal(pCurPoint.y, pCurPointType.y, false, m_oGuidsRes);//hr=b + + m_arIndexDst.push_back(m_lIndexDst-1); + + //stAng и swAng + nIndex = m_arIndexDst[m_lIndexSrc-1]; + + m_lIndexSrc++; + ConvertProd(nIndex-1, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); //stAng + ConvertSum(nIndex-1, ptFormula, nIndex, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(nIndex, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes);//swAng + m_arIndexDst.push_back(m_lIndexDst-1); + + //радиус до стартовой точки + + nIndex = m_arIndexDst[m_lIndexSrc]; //stang + nIndex1 = m_arIndexDst[m_lIndexSrc-1]; //wr hr + + m_lIndexSrc++; + ConvertCos(1, ptValue, nIndex-2, ptFormula, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(nIndex1, ptFormula, nIndex1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//(b*cos(u))^2 + + ConvertSin(1, ptValue, nIndex-2, ptFormula, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(nIndex1-1, ptFormula, nIndex1-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); + ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//(a*sin(u))^2 + + ConvertSum(m_lIndexDst-1, ptFormula, m_lIndexDst-5, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); + ConvertSqrt(m_lIndexDst-1, ptFormula, true, m_oGuidsRes); + ConvertProd(nIndex1, ptFormula, nIndex1-1, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//r + m_arIndexDst.push_back(m_lIndexDst-1); + + //координаты конечной точки (она же начальная для эллипса) + + pCurPoint1 = oSlice.m_arPoints[j];//коорд центра + pCurPointType1 = oSlice.m_arPointsType[j]; + + nIndex = m_arIndexDst[m_lIndexSrc-1]; //stang + nIndex1 = m_arIndexDst[m_lIndexSrc]; //r + + m_lIndexSrc++; + + ConvertProd(nIndex1, ptFormula, nIndex1-10, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); //r*cos + ConvertSum(pCurPoint1.x, pCurPointType1.x, m_lIndexDst-1, ptFormula, 0, ptValue, false, true, true, m_oGuidsRes);//x + + ConvertProd(nIndex1, ptFormula, nIndex1-6, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);// r*sin + ConvertSum(pCurPoint1.y, pCurPointType1.y, m_lIndexDst-1, ptFormula, 0, ptValue, false, true, true, m_oGuidsRes);//y + m_arIndexDst.push_back(m_lIndexDst-1); + //--------------------- + + nIndex = m_arIndexDst[m_lIndexSrc];//текущая точка + nIndex1 = m_arIndexDst[m_lIndexSrc-2];//stAng и swAng + nIndex2 = m_arIndexDst[m_lIndexSrc-3];//wR и hR + + if (j == 0) + strFrmla = L"moveTo"; + else + strFrmla = L"lnTo"; + + if (j == 0) + { + m_oPathRes.WriteString(L""); + } + else + { + m_oPathRes.WriteString(L""); + } + + //текущая точка + + nIndex = m_arIndexDst[m_lIndexSrc]; + + m_lIndexSrc++; + ConvertVal(nIndex-2, ptFormula, true, m_oGuidsRes); + ConvertVal(nIndex, ptFormula, true, m_oGuidsRes); + m_arIndexDst.push_back(m_lIndexDst-1); + } + } + void CFormulaConverter::ConvertSlice_EllipticalQuadrX(const CSlicePath& oSlice) + { + for (size_t j = 0; j < oSlice.m_arPoints.size(); j += 2) + { + pCurPoint = oSlice.m_arPoints[j]; + pCurPointType = oSlice.m_arPointsType[j]; + + ConvertQuadrX(pCurPoint, pCurPointType); + + if (j + 1 < oSlice.m_arPoints.size()) + { + pCurPoint1 = oSlice.m_arPoints[j+1]; + pCurPointType1 = oSlice.m_arPointsType[j+1]; + ConvertQuadrY(pCurPoint1, pCurPointType1); + } + } + } + void CFormulaConverter::ConvertSlice_EllipticalQuadrY(const CSlicePath& oSlice) + { + for (size_t j = 0; j < oSlice.m_arPoints.size(); j += 2) + { + pCurPoint = oSlice.m_arPoints[j]; + pCurPointType = oSlice.m_arPointsType[j]; + ConvertQuadrY(pCurPoint, pCurPointType); + + if (j + 1 < oSlice.m_arPoints.size()) + { + pCurPoint1 = oSlice.m_arPoints[j+1]; + pCurPointType1 = oSlice.m_arPointsType[j+1]; + ConvertQuadrX(pCurPoint1, pCurPointType1); + } + } + } +} diff --git a/MsBinaryFile/Common/Vml/PPTShape/Ppt2PptxShapeConverter.h b/MsBinaryFile/Common/Vml/PPTShape/Ppt2PptxShapeConverter.h index 41fcd27f00..a364703b97 100644 --- a/MsBinaryFile/Common/Vml/PPTShape/Ppt2PptxShapeConverter.h +++ b/MsBinaryFile/Common/Vml/PPTShape/Ppt2PptxShapeConverter.h @@ -32,6 +32,7 @@ #pragma once #include "PptFormula.h" #include "../Path.h" +#include "../PPTShape/PptShape.h" #include "../PPTXShape/PptxShape.h" #include "../../../../OOXML/Binary/Presentation/XmlWriter.h" @@ -43,12 +44,7 @@ namespace PPTX2EditorAdvanced namespace NSGuidesVML { -AVSINLINE int __wstrlen(const wchar_t* str) -{ - const wchar_t* s = str; - for (; *s != 0; ++s); - return (LONG)(s - str); -} +int __wstrlen(const wchar_t* str); static int g_guide_max_len = 80; @@ -148,6 +144,7 @@ struct CFormParam ParamType m_eType; LONG m_lCoef; }; + class CSlicePath { private: @@ -160,42 +157,9 @@ public: std::vector m_arPoints; std::vector m_arPointsType; - CSlicePath(RulesType rule = rtMoveTo, LONG x = 0, LONG y = 0) : m_lX(x), m_lY(y), m_eRuler(rule) - { - m_nCountElementsPoint = 0; - } + CSlicePath(RulesType rule = rtMoveTo, LONG x = 0, LONG y = 0); - void AddParam(LONG lParam, ParamType eParType) - { - long lPoint = m_nCountElementsPoint % 2; - if (0 == lPoint) - { - Aggplus::POINT point; - SPointType pointType; - - point.x = lParam; - if (m_eRuler != rtRMoveTo && m_eRuler != rtRLineTo && m_eRuler != rtRCurveTo) - { - point.x -= m_lX; - } - point.y = 0; - pointType.x = eParType; - pointType.y = ptValue; - m_arPoints.push_back(point); - m_arPointsType.push_back(pointType); - } - else - { - m_arPoints.back().y = lParam; - if (m_eRuler != rtRMoveTo && m_eRuler != rtRLineTo && m_eRuler != rtRCurveTo) - { - m_arPoints.back().y -= m_lY; - } - - m_arPointsType.back().y = eParType; - } - ++m_nCountElementsPoint; - } + void AddParam(LONG lParam, ParamType eParType); }; class CFormulaConverter @@ -226,6 +190,7 @@ private: CFormParam m_oParam; int m_lMaxAdjUse; + public: // все в одно не получится, формулы появляются и при конвертации path/adj и т.д. NSBinPptxRW::CXmlWriter m_oGuidsRes; @@ -235,1961 +200,90 @@ public: NSBinPptxRW::CXmlWriter m_oTextRect; NSBinPptxRW::CXmlWriter m_oCoef; - CFormulaConverter() - { - m_lIndexDst = 0; - m_lIndexSrc = -1; + CFormulaConverter(); - m_lWidth = 0; - m_lHeight = 0; + void ConvertCoef(NSGuidesVML::CFormParam pCoef); + void ConvertCoef2(NSGuidesVML::CFormParam pCoef); + void ConvertAdj(const std::vector& arAdj); + void ConvertFormula(const std::vector& arFormulas); + void ConvertPath(std::wstring strPath, const ODRAW::CPath& oPath); + void ConvertHandle(const std::vector& arHandles, std::vector& arAdj, PPTShapes::ShapeType oSType); - m_lX = 0; - m_lY = 0; + void SetTextRectDefault(); + void ConvertTextRect ( std::wstring strRect); - m_lMaxAdjUse = -1; - } - void ConvertCoef(NSGuidesVML::CFormParam pCoef) - { - if (pCoef.m_eType == ptValue) - ConvertVal(pCoef.m_lParam, pCoef.m_eType, false, m_oCoef); - else if (pCoef.m_eType == ptFormula) - { - ConvertProd(22, ptValue, 1, ptValue, 7, ptValue, false, false, false, m_oCoef); - ConvertProd(m_lIndexDst-1, ptFormula, 1, ptValue, 180, ptValue, true, false, false, m_oCoef); - } - m_oParam.m_lParam = m_lIndexDst-1; - m_oParam.m_eType = ptFormula; - m_oParam.m_lCoef = pCoef.m_lCoef; - } - void ConvertCoef2(NSGuidesVML::CFormParam pCoef) - { - if (pCoef.m_eType == ptValue) - ConvertVal(pCoef.m_lParam, pCoef.m_eType, false, m_oGuidsRes); - else if (pCoef.m_eType == ptFormula) - { - ConvertProd(22, ptValue, 1, ptValue, 7, ptValue, false, false, false, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, 1, ptValue, 180, ptValue, true, false, false, m_oGuidsRes); - } - m_oParam.m_lParam = m_lIndexDst-1; - m_oParam.m_eType = ptFormula; - m_oParam.m_lCoef = pCoef.m_lCoef; - } - void ConvertAdj(const std::vector& arAdj) - { - for (int i = 0; i < (int)arAdj.size(); ++i) - { - m_oAdjRes.WriteString(L""); - } - for (int i = (int)arAdj.size(); i <= m_lMaxAdjUse; ++i) - { - m_oAdjRes.WriteString(L""); - } - } - void ConvertFormula(const std::vector& arFormulas) - { - for (size_t i = 0; i < arFormulas.size(); ++i) - { - const CFormula& pFormula = arFormulas[i]; - m_lIndexSrc++; - - switch (pFormula.m_eFormulaType) - { - case ftVal: - { - ConvertVal(pFormula.m_lParam1, pFormula.m_eType1, false, m_oGuidsRes); - break; - } - case ftSum: - { - ConvertSum(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, pFormula.m_lParam3, pFormula.m_eType3, false, false, false, m_oGuidsRes); - break; - } - case ftProduct: - { - ConvertProd(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, pFormula.m_lParam3, pFormula.m_eType3, false, false, false, m_oGuidsRes); - break; - } - case ftMid: - { - // TODO: +/ ??? - ConvertSum(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, 0, ptValue, false, false, false, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, 1, ptValue, 2, ptValue, true, false, false, m_oGuidsRes); - break; - } - case ftAbsolute: - { - ConvertAbs (pFormula.m_lParam1, pFormula.m_eType1, false, m_oGuidsRes); - break; - } - case ftMin: - { - ConvertMin(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, false, false, m_oGuidsRes); - break; - } - case ftMax: - { - ConvertMax(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, false, false, m_oGuidsRes); - break; - } - case ftIf: - { - ConvertIf(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, pFormula.m_lParam3, pFormula.m_eType3, false, false, false, m_oGuidsRes); - break; - } - case ftMod: - { - ConvertMod(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, pFormula.m_lParam3, pFormula.m_eType3, false, false, false, m_oGuidsRes); - break; - } - case ftAtan2: - { - ConvertAt2(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, false, false, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_oParam.m_lParam, m_oParam.m_eType, pow3_16, ptValue, true, true, false, m_oGuidsRes); - break; - } - case ftSin: - { - ConvertProd(pFormula.m_lParam2, pFormula.m_eType2, pow3_16, ptValue, m_oParam.m_lParam, m_oParam.m_eType, false, false, true, m_oGuidsRes); - ConvertSin(pFormula.m_lParam1, pFormula.m_eType1, m_lIndexDst-1, ptFormula, false, true, m_oGuidsRes); - break; - } - case ftCos: - { - ConvertProd(pFormula.m_lParam2, pFormula.m_eType2, pow3_16, ptValue, m_oParam.m_lParam, m_oParam.m_eType, false, false, true, m_oGuidsRes); - ConvertCos(pFormula.m_lParam1, pFormula.m_eType1, m_lIndexDst-1, ptFormula, false, true, m_oGuidsRes); - break; - } - case ftCosatan2: - { - ConvertCat2(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, pFormula.m_lParam3, pFormula.m_eType3, false, false, false, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_oParam.m_lParam, m_oParam.m_eType, pow3_16, ptValue, true, true, false, m_oGuidsRes); - break; - } - case ftSinatan2: - { - ConvertSat2(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, pFormula.m_lParam3, pFormula.m_eType3, false, false, false, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_oParam.m_lParam, m_oParam.m_eType, pow3_16, ptValue, true, true, false, m_oGuidsRes); - break; - } - case ftSqrt: - { - ConvertSqrt(pFormula.m_lParam1, pFormula.m_eType1, false, m_oGuidsRes); - break; - } - case ftTan: - { - ConvertTag(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam2, pFormula.m_eType2, false, false, m_oGuidsRes); - break; - } - case ftSumangle: - { - ConvertProd(pFormula.m_lParam1, pFormula.m_eType1, pow3_16, ptValue, m_oParam.m_lParam, m_oParam.m_eType, false, false, true, m_oGuidsRes); - ConvertProd(pow3_16, ptValue, pFormula.m_lParam2, pFormula.m_eType2, 1, ptValue, false, false, false, m_oGuidsRes); - ConvertProd(pow3_16, ptValue, pFormula.m_lParam3, pFormula.m_eType3, 1, ptValue, false, false, false, m_oGuidsRes); - ConvertSum(m_lIndexDst-3, ptFormula, m_lIndexDst-2, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_oParam.m_lParam, m_oParam.m_eType, pow3_16, ptValue, true, true, false, m_oGuidsRes); - break; - } - case ftEllipse: - { - ConvertProd(pFormula.m_lParam1, pFormula.m_eType1, pFormula.m_lParam1, pFormula.m_eType1, 1, ptValue , false, false, false, m_oGuidsRes); - ConvertProd(pFormula.m_lParam2, pFormula.m_eType2, pFormula.m_lParam2, pFormula.m_eType2, 1, ptValue , false, false, false, m_oGuidsRes); - ConvertProd(1, ptValue, m_lIndexDst-2, ptFormula, m_lIndexDst-1, ptFormula, false, true, true, m_oGuidsRes); - ConvertSum(0, ptValue, 1, ptValue, m_lIndexDst-1, ptFormula, false, false, true, m_oGuidsRes); - ConvertSqrt(m_lIndexDst-1, ptFormula, true, m_oGuidsRes); - ConvertProd(pFormula.m_lParam3, pFormula.m_eType3, m_lIndexDst-1, ptFormula, 1, ptValue, false, true, false, m_oGuidsRes); - break; - } - default: - break; - } - - m_arIndexDst.push_back(m_lIndexDst-1); - } - } - void ConvertPath(std::wstring strPath, const ODRAW::CPath& oPath) - { - m_arParts.clear(); - std::vector oArray; - boost::algorithm::split(oArray, strPath, boost::algorithm::is_any_of(L"e"), boost::algorithm::token_compress_on); - - for (size_t nIndex = 0; nIndex < oArray.size(); ++nIndex) - { - if (oPath.m_arParts.size() <= nIndex) - break; - const CPartPath& oPart = oPath.m_arParts[nIndex]; - - m_lWidth = oPart.width; - m_lHeight = oPart.height; - - m_lX = oPart.x; - m_lY = oPart.y; - - bool bFill = false; - bool bStroke = false; - std::wstring strValue; - FromXML(oArray[nIndex], bFill, bStroke); - - m_oPathRes.StartNode(L"a:path"); - m_oPathRes.StartAttributes(); - m_oPathRes.WriteAttribute(L"w", m_lWidth); - m_oPathRes.WriteAttribute(L"h", m_lHeight); - - if (!bStroke) - m_oPathRes.WriteAttribute(L"stroke", (std::wstring)L"false"); - if (!bFill) - m_oPathRes.WriteAttribute(L"fill", (std::wstring)L"none"); - m_oPathRes.EndAttributes(); - - for (size_t i = 0; i < m_arSlicesPath.size(); ++i) - { - CSlicePath& oSlice = m_arSlicesPath[i]; - - //m_lIndexDst-1 - номер последней записанной формулы - //m_lIndexSrc - номер последнего блока формул - //m_arIndexDst[n] - возвращает номер последней формулы в блоке n - //m_arIndexDst[m_lIndexSrc] = m_lIndexDst - - switch (oSlice.m_eRuler) - { - case rtMoveTo: - { - ConvertSlice_MoveTo(oSlice); - break; - } - case rtRMoveTo: - { - ConvertSlice_RMoveTo(oSlice); - break; - } - case rtClose: - { - m_oPathRes.WriteString(L""); - break; - } - case rtLineTo: - { - ConvertSlice_LineTo(oSlice); - break; - } - case rtRLineTo: - { - ConvertSlice_RLineTo(oSlice); - break; - } - case rtArcTo: - case rtArc: - { - ConvertSlice_ArcTo(oSlice); - break; - } - case rtClockwiseArcTo: - case rtClockwiseArc: - { - ConvertSlice_ClockwiseTo(oSlice); - break; - } - case rtQuadrBesier: - { - ConvertSlice_QuadrBesier(oSlice); - break; - } - case rtCurveTo: - { - ConvertSlice_CurveTo(oSlice); - break; - } - case rtRCurveTo: - { - ConvertSlice_RCurveTo(oSlice); - break; - } - case rtAngleEllipse: - case rtAngleEllipseTo: - { - ConvertSlice_AngleEllipse(oSlice); - break; - } - case rtEllipticalQuadrX: - { - ConvertSlice_EllipticalQuadrX(oSlice); - break; - } - case rtEllipticalQuadrY: - { - ConvertSlice_EllipticalQuadrY(oSlice); - break; - } - default: - break; - } - } - - m_oPathRes.WriteString(L""); - } - } - - void ConvertHandle(const std::vector& arHandles, std::vector& arAdj, PPTShapes::ShapeType oSType) - { - size_t nHandlesCount = arHandles.size(); - if (oSType == 19) // в пптх не реализована функция изменения размера шейпа при изменении handle - nHandlesCount = 0; - for (size_t i = 0; i < nHandlesCount; ++i) - { - const CHandle_& pHnPoint = arHandles[i]; - std::vector arPos; - - std::wstring sPos0 = L""; - std::wstring sPos1 = L""; - - SHandle oHandle; - ParamType ptType; - - if (pHnPoint.position != L"") - { - boost::algorithm::split(arPos, pHnPoint.position, boost::algorithm::is_any_of(L","), boost::algorithm::token_compress_on); - sPos0 = arPos[0]; - sPos1 = arPos[1]; - - oHandle.gdRef.x = GetHandleValue(sPos0, m_lWidth, ptType); - oHandle.gdRefType.x = ptType; - if (oHandle.gdRefType.x == ptAdjust) - oHandle.bRefExist.x = true; - - oHandle.gdRef.y = GetHandleValue(sPos1, m_lWidth, ptType); - oHandle.gdRefType.y = ptType; - if (oHandle.gdRefType.y == ptAdjust) - oHandle.bRefExist.y = true; - - if (pHnPoint.polar != L"") - { - //пришел полярный угол - oHandle.bRefExist.y = false; - - oHandle.bRefPolarExist.y = true; - oHandle.bMinPolarExist.y = true; - - boost::algorithm::split(arPos, pHnPoint.polar, boost::algorithm::is_any_of(L","), boost::algorithm::token_compress_on); - - oHandle.PolarCentre.x = GetHandleValue(arPos[0], m_lWidth, ptType); - oHandle.PolarCentreType.x = ptType; - - oHandle.PolarCentre.y = GetHandleValue(arPos[1], m_lWidth, ptType); - oHandle.PolarCentreType.y = ptType; - - if (oHandle.gdRefType.y == ptAdjust) - { - //угол должен храниться в pptx формате, поэтому придётся его везде заменить - std::wstring strNewFmla = GetValue2(m_lIndexDst, ptFormula, true); - std::wstring strOldFmla = GetValue2(oHandle.gdRef.y, oHandle.gdRefType.y, false); - LONG nIndex = m_lIndexDst; - - // TODO: !!! тут медленный код. - m_oGuidsRes.ReplaceString(strOldFmla, strNewFmla); - - m_lIndexSrc++; - - // TODO: !!! тут медленный код. - NSBinPptxRW::CXmlWriter memGuidsRes; - ConvertProd(oHandle.gdRef.y, oHandle.gdRefType.y, m_oParam.m_lCoef, ptValue, pow3_16, ptValue, false, true, false, memGuidsRes); - m_oGuidsRes.m_oWriter.WriteBefore(memGuidsRes.m_oWriter); - m_arIndexDst.push_back(m_lIndexDst-1); - - if (oHandle.gdRefType.y == ptAdjust) - { - double dScale = (double)pow3_16 / m_oParam.m_lCoef; - - if (oHandle.gdRef.y >= (int)arAdj.size()) - { - // дурацкий код. надо память перевыделить, а старую скопировать - // пока сделаю так, чтобы наверняка - int nNewSize = (int)oHandle.gdRef.y + 1; - while ((int)arAdj.size() < nNewSize) - arAdj.push_back(0); - } - - LONG lVal = (LONG)(dScale * arAdj[oHandle.gdRef.y]); - arAdj[oHandle.gdRef.y] = lVal; - } - - //рассчитаем координаты точки handle - - m_lIndexSrc++; - ConvertCos(oHandle.gdRef.x, oHandle.gdRefType.x, oHandle.gdRef.y, oHandle.gdRefType.y, false, false, m_oGuidsRes); - ConvertSin(oHandle.gdRef.x, oHandle.gdRefType.x, oHandle.gdRef.y, oHandle.gdRefType.y, false, false, m_oGuidsRes); - ConvertSum(oHandle.PolarCentre.x, oHandle.PolarCentreType.x, m_lIndexDst-2, ptFormula, 0, ptValue, false, true, false, m_oGuidsRes); - ConvertSum(oHandle.PolarCentre.y, oHandle.PolarCentreType.y, m_lIndexDst-2, ptFormula, 0, ptValue, false, true, false, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - - std::wstring strMem = L"&" + std::to_wstring(m_lIndexDst-2); - oHandle.Pos.x = GetHandlePos(strMem, L"w", m_lWidth); - oHandle.PosType.x = ptFormula; - - strMem = L"&" + std::to_wstring(m_lIndexDst-2); //????? - oHandle.Pos.y = GetHandlePos(strMem, L"h", m_lHeight); - oHandle.PosType.y = ptFormula; - } - - } - else//если пришли обычные координаты - { - if ((pHnPoint.xrange != L"" && oHandle.gdRefType.x != ptAdjust && oHandle.gdRefType.y == ptAdjust) || - (pHnPoint.yrange != L"" && oHandle.gdRefType.x == ptAdjust && oHandle.gdRefType.y != ptAdjust)) - { - oHandle.Pos.x = GetHandlePos(sPos1, L"w", m_lWidth); - oHandle.PosType.x = ptFormula; - - oHandle.Pos.y = GetHandlePos(sPos0, L"h", m_lHeight); - oHandle.PosType.y = ptFormula; - } - else - { - oHandle.Pos.x = GetHandlePos(sPos0, L"w", m_lWidth); - oHandle.PosType.x = ptFormula; - - oHandle.Pos.y = GetHandlePos(sPos1, L"h", m_lHeight); - oHandle.PosType.y = ptFormula; - } - } - } - - if (pHnPoint.xrange != L"") - { - if ( oHandle.gdRefType.x != ptAdjust && oHandle.gdRefType.y == ptAdjust) - { - oHandle.gdRef.x = GetHandleValue(sPos1, m_lWidth, ptType); - oHandle.gdRefType.x = ptType; - oHandle.bRefExist.x = true; - - oHandle.gdRef.y = GetHandleValue(sPos0, m_lHeight, ptType); - oHandle.gdRefType.y = ptType; - oHandle.bRefExist.y = false; - } - - boost::algorithm::split(arPos, pHnPoint.xrange, boost::algorithm::is_any_of(L","), boost::algorithm::token_compress_on); - - oHandle.Min.x = GetHandleValue(arPos[0], m_lWidth, ptType); - oHandle.MinType.x = ptType; - if ( oHandle.bRefExist.x) - oHandle.bMinExist.x = true; - - oHandle.Max.x = GetHandleValue(arPos[1], m_lWidth, ptType); - oHandle.MaxType.x = ptType; - if ( oHandle.bRefExist.x) - oHandle.bMaxExist.x = true; - } - - if (pHnPoint.yrange != L"") - { - if (oHandle.gdRefType.x == ptAdjust && oHandle.gdRefType.y != ptAdjust) - { - oHandle.gdRef.x = GetHandleValue(sPos1, m_lWidth, ptType); - oHandle.gdRefType.x = ptType; - oHandle.bRefExist.x = false; - - oHandle.gdRef.y = GetHandleValue(sPos0, m_lHeight, ptType); - oHandle.gdRefType.y = ptType; - oHandle.bRefExist.y = true; - } - boost::algorithm::split(arPos, pHnPoint.yrange, boost::algorithm::is_any_of(L","), boost::algorithm::token_compress_on); - - oHandle.Min.y = GetHandleValue(arPos[0], m_lHeight, ptType); - oHandle.MinType.y = ptType; - if ( oHandle.bRefExist.y ) - oHandle.bMinExist.y = true; - - oHandle.Max.y = GetHandleValue(arPos[1], m_lHeight, ptType); - oHandle.MaxType.y = ptType; - if ( oHandle.bRefExist.y ) - oHandle.bMaxExist.y = true; - } - - if (pHnPoint.radiusrange != L"") - { - boost::algorithm::split(arPos, pHnPoint.radiusrange, boost::algorithm::is_any_of(L","), boost::algorithm::token_compress_on); - - oHandle.Min.x = GetHandleValue(arPos[0], m_lHeight, ptType); - oHandle.MinType.x = ptType; - oHandle.bMinPolarExist.x = true; - - oHandle.Max.x = GetHandleValue(arPos[1], m_lHeight, ptType); - oHandle.MaxType.x = ptType; - oHandle.bMinPolarExist.y = true; - - if (oHandle.gdRefType.x == ptAdjust) - { - oHandle.bRefPolarExist.x = true; - oHandle.bRefExist.x = false; - } - } - - CreateHandle(oHandle); - - } - ConvertAdj(arAdj); - } - void SetTextRectDefault() - { - m_lIndexSrc++; - - ConvertProd(L"w", L"0", m_lWidth, m_oGuidsRes); - ConvertProd(L"h", L"0", m_lHeight, m_oGuidsRes); - ConvertProd(L"w", std::to_wstring(m_lWidth), m_lWidth, m_oGuidsRes); - ConvertProd(L"h", std::to_wstring(m_lHeight), m_lHeight, m_oGuidsRes); - - m_arIndexDst.push_back(m_lIndexDst); - - m_oTextRect.WriteString(L""); - } - void ConvertTextRect ( std::wstring strRect) - { - if (strRect.empty()) - return; - - std::vector arBorder; - boost::algorithm::split(arBorder, strRect, boost::algorithm::is_any_of(L","), boost::algorithm::token_compress_on); - - m_lIndexSrc++; - if (arBorder.size() > 0 && !arBorder[0].empty()) - ConvertProd(L"w", arBorder[0], m_lWidth, m_oGuidsRes); - else - ConvertProd(L"w", L"0", m_lWidth, m_oGuidsRes); - - if (arBorder.size() > 1 && !arBorder[1].empty()) - ConvertProd(L"h", arBorder[1], m_lHeight, m_oGuidsRes); - else - ConvertProd(L"h", L"0", m_lHeight, m_oGuidsRes); - - if (arBorder.size() > 2 && !arBorder[2].empty()) - ConvertProd(L"w", arBorder[2], m_lWidth, m_oGuidsRes); - else - ConvertProd(L"w", std::to_wstring(m_lWidth), m_lWidth, m_oGuidsRes); - - if (arBorder.size() > 3 && !arBorder[3].empty()) - ConvertProd(L"h", arBorder[3], m_lHeight, m_oGuidsRes); - else - ConvertProd(L"h", std::to_wstring(m_lHeight), m_lHeight, m_oGuidsRes); - - m_arIndexDst.push_back(m_lIndexDst); - - // if (true) - // { - m_oTextRect.WriteString(L""); - // } else - // { - // m_oTextRect.WriteString(L""); - // } - - } private: + void GetValue(const LONG& lParam, const ParamType& eParamType, const bool& bExtShape, NSBinPptxRW::CXmlWriter& oWriter); + std::wstring GetValue2(const LONG& lParam, const ParamType& eParamType, const bool& bExtShape); - AVSINLINE void GetValue(const LONG& lParam, const ParamType& eParamType, const bool& bExtShape, NSBinPptxRW::CXmlWriter& oWriter) - { - oWriter.m_oWriter.AddSize(15); - switch (eParamType) - { - case ptFormula: - if (bExtShape || lParam < (int)m_arIndexDst.size()) - { - oWriter.m_oWriter.AddCharNoCheck((WCHAR)'g'); - oWriter.m_oWriter.AddCharNoCheck((WCHAR)'d'); + //--------------------------------------- - if (bExtShape) - oWriter.m_oWriter.AddIntNoCheck(lParam); - else - oWriter.m_oWriter.AddIntNoCheck(m_arIndexDst[lParam]); - } - break; - case ptAdjust: - { - oWriter.m_oWriter.AddCharNoCheck((WCHAR)'a'); - oWriter.m_oWriter.AddCharNoCheck((WCHAR)'d'); - oWriter.m_oWriter.AddCharNoCheck((WCHAR)'j'); - oWriter.m_oWriter.AddIntNoCheck(lParam); - - if (lParam > m_lMaxAdjUse) - m_lMaxAdjUse = lParam; - - break; - } - case ptValue: - { - oWriter.m_oWriter.AddIntNoCheck(lParam); - break; - } - default: - break; - } - } - std::wstring GetValue2(const LONG& lParam, const ParamType& eParamType, const bool& bExtShape) - { - std::wstring strValue; - switch (eParamType) - { - case ptFormula: - { - if (bExtShape) - strValue = std::to_wstring(lParam); - else - strValue = std::to_wstring(m_arIndexDst[lParam]); - strValue = L"gd" + strValue; - break; - } - case ptAdjust: - { - strValue = std::to_wstring(lParam); - strValue = L"adj" + strValue; - break; - } - case ptValue: - { - strValue = std::to_wstring(lParam); - strValue = strValue; - break; - } - default: - break; - } - return strValue; - } - //--------------------------------------- - - void ConvertVal(const LONG& lParam1, const ParamType& eType1, const bool& bExtShape1, NSBinPptxRW::CXmlWriter& oWriter) - { - GUIDE_PARAM_1(val) - } + void ConvertVal(const LONG& lParam1, const ParamType& eType1, const bool& bExtShape1, NSBinPptxRW::CXmlWriter& oWriter); void ConvertSum(const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, - const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, NSBinPptxRW::CXmlWriter& oWriter) - { - GUIDE_PARAM_3(sum) - } + const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, NSBinPptxRW::CXmlWriter& oWriter); void ConvertProd(const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, - const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, NSBinPptxRW::CXmlWriter& oWriter) - { - GUIDE_PARAM_3(prod) - } + const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, NSBinPptxRW::CXmlWriter& oWriter); - void ConvertAbs(const LONG& lParam1, const ParamType& eType1, const bool& bExtShape1, NSBinPptxRW::CXmlWriter& oWriter) - { - GUIDE_PARAM_1(abs) - } + void ConvertAbs(const LONG& lParam1, const ParamType& eType1, const bool& bExtShape1, NSBinPptxRW::CXmlWriter& oWriter); void ConvertMin(const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, - const bool& bExtShape1, const bool& bExtShape2, NSBinPptxRW::CXmlWriter& oWriter) - { - GUIDE_PARAM_2(min) - } + const bool& bExtShape1, const bool& bExtShape2, NSBinPptxRW::CXmlWriter& oWriter); void ConvertMax (const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, - const bool& bExtShape1, const bool& bExtShape2, NSBinPptxRW::CXmlWriter& oWriter) - { - GUIDE_PARAM_2(max) - } + const bool& bExtShape1, const bool& bExtShape2, NSBinPptxRW::CXmlWriter& oWriter); void ConvertIf(const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, - const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, NSBinPptxRW::CXmlWriter& oWriter) - { - GUIDE_PARAM_3(_if) - } + const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, NSBinPptxRW::CXmlWriter& oWriter); - void ConvertSqrt(const LONG& lParam1, const ParamType& eType1, const bool& bExtShape1, NSBinPptxRW::CXmlWriter& oWriter) - { - GUIDE_PARAM_1(sqrt) - } + void ConvertSqrt(const LONG& lParam1, const ParamType& eType1, const bool& bExtShape1, NSBinPptxRW::CXmlWriter& oWriter); void ConvertAt2 (const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, - const bool& bExtShape1, const bool& bExtShape2, NSBinPptxRW::CXmlWriter& oWriter) - { - GUIDE_PARAM_2(at2) - } + const bool& bExtShape1, const bool& bExtShape2, NSBinPptxRW::CXmlWriter& oWriter); void ConvertSin (const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, - const bool& bExtShape1, const bool& bExtShape2, NSBinPptxRW::CXmlWriter& oWriter) - { - GUIDE_PARAM_2(sin) - } + const bool& bExtShape1, const bool& bExtShape2, NSBinPptxRW::CXmlWriter& oWriter); void ConvertCos (const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, - const bool& bExtShape1, const bool& bExtShape2, NSBinPptxRW::CXmlWriter& oWriter) - { - GUIDE_PARAM_2(cos) - } + const bool& bExtShape1, const bool& bExtShape2, NSBinPptxRW::CXmlWriter& oWriter); void ConvertCat2(const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, - const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, NSBinPptxRW::CXmlWriter& oWriter) - { - GUIDE_PARAM_3(cat2) - } + const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, NSBinPptxRW::CXmlWriter& oWriter); void ConvertSat2(const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, - const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, NSBinPptxRW::CXmlWriter& oWriter) - { - GUIDE_PARAM_3(sat2) - } + const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, NSBinPptxRW::CXmlWriter& oWriter); void ConvertMod(const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, - const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, NSBinPptxRW::CXmlWriter& oWriter) - { - GUIDE_PARAM_3(mod) - } + const LONG& lParam3, const ParamType& eType3, const bool& bExtShape1, const bool& bExtShape2, const bool& bExtShape3, NSBinPptxRW::CXmlWriter& oWriter); void ConvertTag (const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2, - const bool& bExtShape1, const bool& bExtShape2, NSBinPptxRW::CXmlWriter& oWriter) - { - GUIDE_PARAM_2(tag) - } + const bool& bExtShape1, const bool& bExtShape2, NSBinPptxRW::CXmlWriter& oWriter); - void ConvertProd(const std::wstring& strParam1, const std::wstring& strParam2, const LONG& lParam3, NSBinPptxRW::CXmlWriter& oWriter) - { - oWriter.m_oWriter.AddSize(g_guide_max_len); - oWriter.m_oWriter.WriteStringNoSafe(g_guide_string1, g_guide_string1_len); - oWriter.m_oWriter.AddIntNoCheck(m_lIndexDst); - oWriter.m_oWriter.WriteStringNoSafe(g_guide_string_prod, g_guide_string_prod_len); - oWriter.WriteString(strParam1); - oWriter.m_oWriter.AddSpaceNoCheck(); - - if ('#' == strParam2[0]) - { - LONG lRes = (LONG)XmlUtils::GetInteger(strParam2.substr(1)); - GetValue(lRes, ptAdjust, false, oWriter); - } - else if ('@' == strParam2[0]) - { - LONG lRes = (LONG)XmlUtils::GetInteger(strParam2.substr(1)); - GetValue(lRes, ptFormula, false, oWriter); - } - else - oWriter.WriteString(strParam2); - - oWriter.m_oWriter.AddSpaceNoCheck(); - GetValue(lParam3, ptValue, false, oWriter); - - ++m_lIndexDst; - oWriter.m_oWriter.WriteStringNoSafe(g_guide_string2, g_guide_string2_len); - } + void ConvertProd(const std::wstring& strParam1, const std::wstring& strParam2, const LONG& lParam3, NSBinPptxRW::CXmlWriter& oWriter); //------------------------------------- - void FromXML(std::wstring strPath, bool &m_bFill, bool &m_bStroke) - { - m_arSlicesPath.clear(); - NSStringUtils::CheckPathOn_Fill_Stroke(strPath, m_bFill, m_bStroke); - std::vector oArray; + void FromXML(std::wstring strPath, bool &m_bFill, bool &m_bStroke); + void CreateHandle ( SHandle oHnd ); - NSStringUtils::ParsePath2(strPath, &oArray); + LONG GetHandlePos(const std::wstring& strParam, const std::wstring& strBase, LONG lSize); + LONG GetHandleValue(const std::wstring& strParam, const LONG& lVal, ParamType& ptType); - ParamType eParamType = ptValue; - RulesType eRuler = rtEnd; - LONG lValue; - bool bRes = true; - - for (size_t nIndex = 0; nIndex < oArray.size(); ++nIndex) - { - std::wstring str = oArray[nIndex]; - lValue = NSGuidesVML::GetValue(oArray[nIndex], eParamType, bRes); - if (bRes) - { - if (0 != m_arSlicesPath.size()) - { - if ( lValue >= 0x7fffff00 || lValue <= -0x7fffff00) - { - lValue = 0; //process(2).ppt - todooo разобраться что за хрень это ваще приплыла - } - - m_arSlicesPath[m_arSlicesPath.size() - 1].AddParam(lValue, eParamType); - } - } - else - { - eRuler = GetRuler(oArray[nIndex], bRes); - if (bRes) - { - if (rtNoFill == eRuler) - { - m_bFill = false; - } - else if (rtNoStroke == eRuler) - { - m_bStroke = false; - } - else - { - CSlicePath oSlice(eRuler, m_lX, m_lY); - - m_arSlicesPath.push_back(oSlice); - } - } - } - } - } - void CreateHandle ( SHandle oHnd ) - { - std::wstring strRes = L""; - if (oHnd.bRefPolarExist.x || oHnd.bRefPolarExist.y) - m_oHandleRes.WriteString(L""); - else if (oHnd.bRefExist.x || oHnd.bRefExist.y) - m_oHandleRes.WriteString(L"\"/>"); - } - - LONG GetHandlePos(const std::wstring& strParam, const std::wstring& strBase, LONG lSize) - { - LONG lRes; - std::wstring strSize = L" " + std::to_wstring(lSize); - std::wstring strIndex; - - if ('#' == strParam[0]) - { - lRes = (LONG)XmlUtils::GetInteger(strParam.substr(1)); - strFrmla = GetValue2(lRes, ptAdjust, false) + strSize; - } - else if ('&' == strParam[0]) - { - lRes = (LONG)XmlUtils::GetInteger(strParam.substr(1)); - strFrmla = GetValue2(lRes, ptFormula, true) + strSize; - } - else if ('@' == strParam[0]) - { - lRes = (LONG)XmlUtils::GetInteger(strParam.substr(1)); - strFrmla = GetValue2(lRes, ptFormula, false) + strSize; - } - else if (!NSStringUtils::IsNumber(strParam)) - { - if (L"center" == strParam) - strFrmla = L"1 2"; - else if (L"topLeft" == strParam) - strFrmla = L"0 1"; - else if ( L"bottomRight" == strParam) - strFrmla = L"1 1"; - } - else - { - lRes = (LONG)XmlUtils::GetInteger(strParam); - strFrmla = GetValue2(lRes, ptValue, false) + strSize; - } - - m_lIndexSrc++; - m_arIndexDst.push_back(m_lIndexDst); - strIndex = std::to_wstring(m_lIndexDst); - - m_oGuidsRes.WriteString(L""); - - m_lIndexDst++; - - return m_lIndexDst-1; - } - - - LONG GetHandleValue(const std::wstring& strParam, const LONG& lVal, ParamType& ptType) - { - ptType = ptValue; - if ('#' == strParam[0]) - { - ptType = ptAdjust; - return (LONG)XmlUtils::GetInteger(strParam.substr(1)); - } - else if ('@' == strParam[0]) - { - ptType = ptFormula; - return (LONG)XmlUtils::GetInteger(strParam.substr(1)); - } - else if (!NSStringUtils::IsNumber(strParam)) - { - if (L"center" == strParam) - return lVal/2; - else if (L"bottomRight" == strParam)//Demo-Hayden-Management-v2.docx - return lVal; - else - return 0; //??? - //todooo прописать все варианты правильно - } - else - { - ptType = ptValue; - return (LONG)XmlUtils::GetInteger(strParam); - } - } - void ConvertQuadrX(Aggplus::POINT pPoint, SPointType pPointType) - { - LONG nIndex = m_arIndexDst[m_lIndexSrc]; - - m_lIndexSrc++; - - ConvertSum(pPoint.x, pPointType.x, 0, ptValue, nIndex-1, ptFormula, false, true, true, m_oGuidsRes); - ConvertSum(pPoint.y, pPointType.y, 0, ptValue, nIndex, ptFormula, false, true, true, m_oGuidsRes); - ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-2, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(m_lIndexDst-4, ptFormula, 16200000, ptValue, 5400000, ptValue, true, true, true, m_oGuidsRes); //stAng - ConvertIf(m_lIndexDst-2, ptFormula, 5400000, ptValue, -5400000, ptValue, true, true, true, m_oGuidsRes); //swAng - ConvertProd(m_lIndexDst-7, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-7, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(m_lIndexDst-9, ptFormula, m_lIndexDst-9, ptFormula, m_lIndexDst-2, ptFormula, true, true, true, m_oGuidsRes);//wR - ConvertIf(m_lIndexDst-9, ptFormula, m_lIndexDst-9, ptFormula, m_lIndexDst-2, ptFormula, true, true, true, m_oGuidsRes);//hR - - m_arIndexDst.push_back(m_lIndexDst-1); - - nIndex = m_arIndexDst[m_lIndexSrc]; - - m_oPathRes.WriteString(L""); - - m_lIndexSrc++; - ConvertVal(pPoint.x, pPointType.x, false, m_oGuidsRes); - ConvertVal(pPoint.y, pPointType.y, false, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - return; - } - - void ConvertQuadrY(Aggplus::POINT pPoint, SPointType pPointType) - { - LONG nIndex = m_arIndexDst[m_lIndexSrc]; - - m_lIndexSrc++; - - ConvertSum(pPoint.x, pPointType.x, 0, ptValue, nIndex-1, ptFormula, false, true, true, m_oGuidsRes); - ConvertSum(pPoint.y, pPointType.y, 0, ptValue, nIndex, ptFormula, false, true, true, m_oGuidsRes); - ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-2, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(m_lIndexDst-5, ptFormula, 10800000, ptValue, 0, ptValue, true, true, true, m_oGuidsRes); //stAng - ConvertIf(m_lIndexDst-2, ptFormula, -5400000, ptValue, 5400000, ptValue, true, true, true, m_oGuidsRes); //swAng - ConvertProd(m_lIndexDst-7, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-7, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(m_lIndexDst-9, ptFormula, m_lIndexDst-9, ptFormula, m_lIndexDst-2, ptFormula, true, true, true, m_oGuidsRes);//wR - ConvertIf(m_lIndexDst-9, ptFormula, m_lIndexDst-9, ptFormula, m_lIndexDst-2, ptFormula, true, true, true, m_oGuidsRes);//hR - m_arIndexDst.push_back(m_lIndexDst-1); - - nIndex = m_arIndexDst[m_lIndexSrc]; - - m_oPathRes.WriteString(L""); - - m_lIndexSrc++; - ConvertVal(pPoint.x, pPointType.x, false, m_oGuidsRes); - ConvertVal(pPoint.y, pPointType.y, false, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - return; - } + void ConvertQuadrX(Aggplus::POINT pPoint, SPointType pPointType); + void ConvertQuadrY(Aggplus::POINT pPoint, SPointType pPointType); //------------------------------------- - void ConvertSlice_MoveTo(const CSlicePath& oSlice) - { - for (size_t j = 0; j < oSlice.m_arPoints.size(); ++j) - { - pCurPoint = oSlice.m_arPoints[j]; - pCurPointType = oSlice.m_arPointsType[j]; - - m_lIndexSrc++; - ConvertVal(pCurPoint.x, pCurPointType.x, false, m_oGuidsRes); - ConvertVal(pCurPoint.y, pCurPointType.y, false, m_oGuidsRes); - - m_arIndexDst.push_back(m_lIndexDst-1); - - m_oPathRes.WriteString(L""); - } - } - - void ConvertSlice_RMoveTo(const CSlicePath& oSlice) - { - for (size_t j = 0; j < oSlice.m_arPoints.size(); j++) - { - pCurPoint = oSlice.m_arPoints[j]; - pCurPointType = oSlice.m_arPointsType[j]; - - m_lIndexSrc ++; - ConvertSum(m_lIndexDst-2, ptFormula, pCurPoint.x, pCurPointType.x, 0, ptValue, true, false, true, m_oGuidsRes); - ConvertSum(m_lIndexDst-2, ptFormula, pCurPoint.y, pCurPointType.y, 0, ptValue, true, false, true, m_oGuidsRes); - - m_arIndexDst.push_back(m_lIndexDst-1); - - m_oPathRes.WriteString(L""); - } - } - - void ConvertSlice_LineTo(const CSlicePath& oSlice) - { - for (size_t j = 0; j < oSlice.m_arPoints.size(); j++) - { - pCurPoint = oSlice.m_arPoints[j]; - pCurPointType = oSlice.m_arPointsType[j]; - - m_lIndexSrc++; - ConvertVal(pCurPoint.x, pCurPointType.x, false, m_oGuidsRes); - ConvertVal(pCurPoint.y, pCurPointType.y, false, m_oGuidsRes); - - m_arIndexDst.push_back(m_lIndexDst-1); - - m_oPathRes.WriteString(L""); - } - } - - void ConvertSlice_RLineTo(const CSlicePath& oSlice) - { - for (size_t j = 0; j < oSlice.m_arPoints.size(); j++) - { - pCurPoint = oSlice.m_arPoints[j]; - pCurPointType = oSlice.m_arPointsType[j]; - - m_lIndexSrc++; - ConvertSum(m_lIndexDst-2, ptFormula, pCurPoint.x, pCurPointType.x, 0, ptValue, true, false, true, m_oGuidsRes); - ConvertSum(m_lIndexDst-2, ptFormula, pCurPoint.y, pCurPointType.y, 0, ptValue, true, false, true, m_oGuidsRes); - - m_arIndexDst.push_back(m_lIndexDst-1); - - m_oPathRes.WriteString(L""); - } - } - - void ConvertSlice_ArcTo(const CSlicePath& oSlice) - { - LONG nIndex = 0; - LONG nIndex1 = 0; - LONG nIndex2 = 0; - - for (size_t j = 0; j < oSlice.m_arPoints.size(); j+=4) - { - pCurPoint = oSlice.m_arPoints[j]; - pCurPointType = oSlice.m_arPointsType[j]; - pCurPoint1 = oSlice.m_arPoints[j+1]; - pCurPointType1 = oSlice.m_arPointsType[j+1]; - - //длина сторон - m_lIndexSrc++; - ConvertSum(pCurPoint1.x, pCurPointType1.x, 0, ptValue, pCurPoint.x, pCurPointType.x, false, true, false, m_oGuidsRes); - ConvertSum(pCurPoint1.y, pCurPointType1.y, 0, ptValue, pCurPoint.y, pCurPointType.y, false, true, false, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //координаты центра - nIndex = m_arIndexDst[m_lIndexSrc]; - - m_lIndexSrc++; - ConvertProd(nIndex-1, ptFormula, 1, ptValue, 2, ptValue, true, true, true, m_oGuidsRes); //a=wR - ConvertProd(nIndex, ptFormula, 1, ptValue, 2, ptValue, true, true, true, m_oGuidsRes); //b=hR - - ConvertSum(pCurPoint.x, pCurPointType.x, m_lIndexDst-2, ptFormula, 0, ptValue, false, true, true, m_oGuidsRes); - ConvertSum(pCurPoint.y, pCurPointType.y, m_lIndexDst-2, ptFormula, 0, ptValue, false, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //рассчет для stAng--------------------------- - //расположение текущей точки по четвертям 3 4 - // 2 1 - - pCurPoint = oSlice.m_arPoints[j+2]; - pCurPointType = oSlice.m_arPointsType[j+2]; - nIndex = m_arIndexDst[m_lIndexSrc]; - - m_lIndexSrc++; - ConvertSum(pCurPoint.x, pCurPointType.x, 0, ptValue, nIndex-1, ptFormula, false, true, true, m_oGuidsRes); - ConvertSum(pCurPoint.y, pCurPointType.y, 0, ptValue, nIndex, ptFormula, false, true, true, m_oGuidsRes); - ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //угол между Ох и радиус-вектором к точке - nIndex = m_arIndexDst[m_lIndexSrc]; - - m_lIndexSrc++; - ConvertProd(nIndex-2, ptFormula, 1, ptValue, nIndex-3, ptFormula, true, true, true, m_oGuidsRes); - ConvertAt2(1, ptValue, m_lIndexDst-1, ptFormula, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //радиус к точке - nIndex = m_arIndexDst[m_lIndexSrc]; - nIndex1 = m_arIndexDst[m_lIndexSrc-2]; - - m_lIndexSrc++; - ConvertCos(1, ptValue, nIndex, ptFormula, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(nIndex1-2, ptFormula, nIndex1-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//(b*cos(u))^2 - - ConvertSin(1, ptValue, nIndex, ptFormula, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(nIndex1-3, ptFormula, nIndex1-3, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//(a*sin(u))^2 - - ConvertSum(m_lIndexDst-1, ptFormula, m_lIndexDst-5, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); - ConvertSqrt(m_lIndexDst-1, ptFormula, true, m_oGuidsRes); - ConvertProd(nIndex1-3, ptFormula, nIndex1-2, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//r - m_arIndexDst.push_back(m_lIndexDst-1); - //если точка во 2 и 3 четвертях, прибавляем по 180grad - nIndex = m_arIndexDst[m_lIndexSrc-2]; - - m_lIndexSrc++; - ConvertIf(nIndex-3, ptFormula, 0, ptValue, 10800000, ptValue, true, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //угол до 1 точки (stAngle) - nIndex = m_arIndexDst[m_lIndexSrc-2];//угол между ох и радиусом - nIndex1 = m_arIndexDst[m_lIndexSrc-3];//расположение точки по четвертям - nIndex2 = m_arIndexDst[m_lIndexSrc];//прибавка 180 или 0 - - m_lIndexSrc ++; - ConvertProd(nIndex1-1, ptFormula, nIndex1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//знак у угла - ConvertProd(nIndex, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(nIndex, ptFormula, nIndex, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//угол всегда положительный - - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-3, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//u с нужным знаком - - ConvertSum(m_lIndexDst-1, ptFormula, nIndex2, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //координаты стартовой точки - nIndex = m_arIndexDst[m_lIndexSrc-2]; - nIndex1 = m_arIndexDst[m_lIndexSrc-4]; - nIndex2 = m_arIndexDst[m_lIndexSrc-5]; - - m_lIndexSrc++; - ConvertProd(nIndex, ptFormula, nIndex-10, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//r*cos(a) - ConvertProd(nIndex1-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertSum(nIndex2-1, ptFormula, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); //x - - ConvertProd(nIndex-6, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(nIndex-6, ptFormula, nIndex-6, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//sin теперь всегда>0 - - ConvertProd(nIndex, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//r*sin - ConvertProd(nIndex1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertSum(nIndex2, ptFormula, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes);//y - m_arIndexDst.push_back(m_lIndexDst-1); - //рассчет для swAng--------------------------- - //расположение текущей точки по четвертям 3 4 - // 2 1 - - pCurPoint = oSlice.m_arPoints[j+3]; - pCurPointType = oSlice.m_arPointsType[j+3]; - - nIndex = m_arIndexDst[m_lIndexSrc-6]; - - m_lIndexSrc++; - ConvertSum(pCurPoint.x, pCurPointType.x, 0, ptValue, nIndex-1, ptFormula, false, true, true, m_oGuidsRes); - ConvertSum(pCurPoint.y, pCurPointType.y, 0, ptValue, nIndex, ptFormula, false, true, true, m_oGuidsRes); - ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //угол между Ох и радиус-вектором к точке - nIndex = m_arIndexDst[m_lIndexSrc]; - - m_lIndexSrc++; - ConvertProd(nIndex-2, ptFormula, 1, ptValue, nIndex-3, ptFormula, true, true, true, m_oGuidsRes); - ConvertAt2(1, ptValue, m_lIndexDst-1, ptFormula, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //радиус к точке - nIndex = m_arIndexDst[m_lIndexSrc]; - nIndex1 = m_arIndexDst[m_lIndexSrc-8]; - - m_lIndexSrc++; - ConvertCos(1, ptValue, nIndex, ptFormula, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(nIndex1-2, ptFormula, nIndex1-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - - ConvertSin(1, ptValue, nIndex, ptFormula, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(nIndex1-3, ptFormula, nIndex1-3, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - - ConvertSum(m_lIndexDst-1, ptFormula, m_lIndexDst-5, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); - ConvertSqrt(m_lIndexDst-1, ptFormula, true, m_oGuidsRes); - ConvertProd(nIndex1-3, ptFormula, nIndex1-2, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //если точка во 2 и 3 четвертях, прибавляем по 180grad - nIndex = m_arIndexDst[m_lIndexSrc-2]; - - m_lIndexSrc++; - ConvertIf(nIndex-3, ptFormula, 0, ptValue, 10800000, ptValue, true, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //угол до 2 точки - nIndex = m_arIndexDst[m_lIndexSrc-2];//угол между ох и радиусом - nIndex1 = m_arIndexDst[m_lIndexSrc-3];//расположение точки по четвертям - nIndex2 = m_arIndexDst[m_lIndexSrc];//прибавка 180 или 0 - - m_lIndexSrc++; - ConvertProd(nIndex1-1, ptFormula, nIndex1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//знак у угла - ConvertProd(nIndex, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(nIndex, ptFormula, nIndex, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//угол всегда положительный - - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-3, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//u с нужным знаком - - ConvertSum(m_lIndexDst-1, ptFormula, nIndex2, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //координаты конечной точки - nIndex = m_arIndexDst[m_lIndexSrc-2]; - nIndex1 = m_arIndexDst[m_lIndexSrc-4]; - nIndex2 = m_arIndexDst[m_lIndexSrc-11]; - - m_lIndexSrc++; - ConvertProd(nIndex, ptFormula, nIndex-10, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//r*cos(a) - ConvertProd(nIndex1-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertSum(nIndex2-1, ptFormula, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes);//x - - ConvertProd(nIndex-6, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(nIndex-6, ptFormula, nIndex-6, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//sin теперь всегда>0 - - ConvertProd(nIndex, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//r*sin(a) - ConvertProd(nIndex1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertSum(nIndex2, ptFormula, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes);//y - m_arIndexDst.push_back(m_lIndexDst-1); - //swAngle - nIndex = m_arIndexDst[m_lIndexSrc-1]; //2 угол - nIndex1 = m_arIndexDst[m_lIndexSrc-7]; //1 угол - - m_lIndexSrc++; - ConvertSum(nIndex1, ptFormula, 0, ptValue, nIndex, ptFormula, true, true, true, m_oGuidsRes); // (1)-(2), если отрицательный то берем его, иначе пересчитываем - ConvertProd(m_lIndexDst-1, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); - - ConvertSum(nIndex1, ptFormula, 21600000, ptValue, nIndex, ptFormula, true, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); // -1*((1)+360-(2)) - - ConvertIf(m_lIndexDst-4, ptFormula, m_lIndexDst-3, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes); - - m_arIndexDst.push_back(m_lIndexDst-1); - //wR,hR - nIndex = m_arIndexDst[m_lIndexSrc-14]; - m_lIndexSrc++; - ConvertProd(nIndex-1, ptFormula, 1, ptValue, 2, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(nIndex, ptFormula, 1, ptValue, 2, ptValue, true, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - - //--------------------------------------------------------- - nIndex = m_arIndexDst[m_lIndexSrc-8];//координаты стартовой точки - nIndex1 = m_arIndexDst[m_lIndexSrc-9];//stAng - nIndex2 = m_arIndexDst[m_lIndexSrc-1];//swAng - - if (oSlice.m_eRuler == rtArc && j == 0) - strFrmla = L"moveTo"; - else - strFrmla = L"lnTo"; - - if (oSlice.m_eRuler == rtArc && j == 0) - { - m_oPathRes.WriteString(L""); - } - else - { - m_oPathRes.WriteString(L""); - } - - //старт - /* - LONG nIndex3 = m_arIndexDst[m_lIndexSrc-14]; - strPathRes += L""); - */ - - //текущая точка - nIndex = m_arIndexDst[m_lIndexSrc-2]; - ConvertVal(nIndex-5, ptFormula, true, m_oGuidsRes); - ConvertVal(nIndex, ptFormula, true, m_oGuidsRes); - } - } - - void ConvertSlice_ClockwiseTo(const CSlicePath& oSlice) - { - LONG nIndex = 0; - LONG nIndex1 = 0; - LONG nIndex2 = 0; - - for (size_t j = 0; j < oSlice.m_arPoints.size(); j += 4) - { - pCurPoint = oSlice.m_arPoints[j]; - pCurPointType = oSlice.m_arPointsType[j]; - pCurPoint1 = oSlice.m_arPoints[j+1]; - pCurPointType1 = oSlice.m_arPointsType[j+1]; - - //длина сторон - m_lIndexSrc++; - ConvertSum(pCurPoint1.x, pCurPointType1.x, 0, ptValue, pCurPoint.x, pCurPointType.x, false, true, false, m_oGuidsRes); - ConvertSum(pCurPoint1.y, pCurPointType1.y, 0, ptValue, pCurPoint.y, pCurPointType.y, false, true, false, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //координаты центра - nIndex = m_arIndexDst[m_lIndexSrc]; - - m_lIndexSrc++; - ConvertProd(nIndex-1, ptFormula, 1, ptValue, 2, ptValue, true, true, true, m_oGuidsRes); //a=wR - ConvertProd(nIndex, ptFormula, 1, ptValue, 2, ptValue, true, true, true, m_oGuidsRes); //b=hR - - ConvertSum(pCurPoint.x, pCurPointType.x, m_lIndexDst-2, ptFormula, 0, ptValue, false, true, true, m_oGuidsRes); - ConvertSum(pCurPoint.y, pCurPointType.y, m_lIndexDst-2, ptFormula, 0, ptValue, false, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //рассчет для stAng--------------------------- - //расположение текущей точки по четвертям 3 4 - // 2 1 - - pCurPoint = oSlice.m_arPoints[j+2]; - pCurPointType = oSlice.m_arPointsType[j+2]; - nIndex = m_arIndexDst[m_lIndexSrc]; - - m_lIndexSrc++; - ConvertSum(pCurPoint.x, pCurPointType.x, 0, ptValue, nIndex-1, ptFormula, false, true, true, m_oGuidsRes); - ConvertSum(pCurPoint.y, pCurPointType.y, 0, ptValue, nIndex, ptFormula, false, true, true, m_oGuidsRes); - ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //угол между Ох и радиус-вектором к точке - nIndex = m_arIndexDst[m_lIndexSrc]; - - m_lIndexSrc++; - ConvertProd(nIndex-2, ptFormula, 1, ptValue, nIndex-3, ptFormula, true, true, true, m_oGuidsRes); - ConvertAt2(1, ptValue, m_lIndexDst-1, ptFormula, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //радиус к точке - nIndex = m_arIndexDst[m_lIndexSrc]; - nIndex1 = m_arIndexDst[m_lIndexSrc-2]; - - m_lIndexSrc++; - ConvertCos(1, ptValue, nIndex, ptFormula, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(nIndex1-2, ptFormula, nIndex1-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//(b*cos(u))^2 - - ConvertSin(1, ptValue, nIndex, ptFormula, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(nIndex1-3, ptFormula, nIndex1-3, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//(a*sin(u))^2 - - ConvertSum(m_lIndexDst-1, ptFormula, m_lIndexDst-5, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); - ConvertSqrt(m_lIndexDst-1, ptFormula, true, m_oGuidsRes); - ConvertProd(nIndex1-3, ptFormula, nIndex1-2, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//r - m_arIndexDst.push_back(m_lIndexDst-1); - //если точка во 2 и 3 четвертях, прибавляем по 180grad - nIndex = m_arIndexDst[m_lIndexSrc-2]; - - m_lIndexSrc++; - ConvertIf(nIndex-3, ptFormula, 0, ptValue, 10800000, ptValue, true, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //угол до 1 точки (stAngle) - nIndex = m_arIndexDst[m_lIndexSrc-2];//угол между ох и радиусом - nIndex1 = m_arIndexDst[m_lIndexSrc-3];//расположение точки по четвертям - nIndex2 = m_arIndexDst[m_lIndexSrc];//прибавка 180 или 0 - - m_lIndexSrc++; - ConvertProd(nIndex1-1, ptFormula, nIndex1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//знак у угла - ConvertProd(nIndex, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(nIndex, ptFormula, nIndex, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//угол всегда положительный - - ConvertProd ( m_lIndexDst-1, ptFormula, m_lIndexDst-3, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//u с нужным знаком - - ConvertSum ( m_lIndexDst-1, ptFormula, nIndex2, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //координаты стартовой точки - nIndex = m_arIndexDst[m_lIndexSrc-2]; - nIndex1 = m_arIndexDst[m_lIndexSrc-4]; - nIndex2 = m_arIndexDst[m_lIndexSrc-5]; - - m_lIndexSrc++; - ConvertProd(nIndex, ptFormula, nIndex-10, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//r*cos(a) - ConvertProd(nIndex1-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertSum(nIndex2-1, ptFormula, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); //x - - ConvertProd(nIndex-6, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(nIndex-6, ptFormula, nIndex-6, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//sin теперь всегда>0 - - ConvertProd(nIndex, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//r*sin - ConvertProd(nIndex1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertSum(nIndex2, ptFormula, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes);//y - m_arIndexDst.push_back(m_lIndexDst-1); - //рассчет для swAng--------------------------- - //расположение текущей точки по четвертям 3 4 - // 2 1 - - pCurPoint = oSlice.m_arPoints[j+3]; - pCurPointType = oSlice.m_arPointsType[j+3]; - - nIndex = m_arIndexDst[m_lIndexSrc-6]; - - m_lIndexSrc++; - ConvertSum(pCurPoint.x, pCurPointType.x, 0, ptValue, nIndex-1, ptFormula, false, true, true, m_oGuidsRes); - ConvertSum(pCurPoint.y, pCurPointType.y, 0, ptValue, nIndex, ptFormula, false, true, true, m_oGuidsRes); - ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(m_lIndexDst-2, ptFormula, 1, ptValue, -1, ptValue, true, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //угол между Ох и радиус-вектором к точке - nIndex = m_arIndexDst[m_lIndexSrc]; - - m_lIndexSrc++; - ConvertProd(nIndex-2, ptFormula, 1, ptValue, nIndex-3, ptFormula, true, true, true, m_oGuidsRes); - ConvertAt2(1, ptValue, m_lIndexDst-1, ptFormula, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //радиус к точке - nIndex = m_arIndexDst[m_lIndexSrc]; - nIndex1 = m_arIndexDst[m_lIndexSrc-8]; - - m_lIndexSrc++; - ConvertCos(1, ptValue, nIndex, ptFormula, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(nIndex1-2, ptFormula, nIndex1-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - - ConvertSin(1, ptValue, nIndex, ptFormula, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(nIndex1-3, ptFormula, nIndex1-3, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - - ConvertSum(m_lIndexDst-1, ptFormula, m_lIndexDst-5, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); - ConvertSqrt(m_lIndexDst-1, ptFormula, true, m_oGuidsRes); - ConvertProd(nIndex1-3, ptFormula, nIndex1-2, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //если точка во 2 и 3 четвертях, прибавляем по 180grad - nIndex = m_arIndexDst[m_lIndexSrc-2]; - - m_lIndexSrc++; - ConvertIf(nIndex-3, ptFormula, 0, ptValue, 10800000, ptValue, true, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //угол до 2 точки - nIndex = m_arIndexDst[m_lIndexSrc-2];//угол между ох и радиусом - nIndex1 = m_arIndexDst[m_lIndexSrc-3];//расположение точки по четвертям - nIndex2 = m_arIndexDst[m_lIndexSrc];//прибавка 180 или 0 - - m_lIndexSrc ++; - ConvertProd(nIndex1-1, ptFormula, nIndex1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//знак у угла - ConvertProd(nIndex, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(nIndex, ptFormula, nIndex, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//угол всегда положительный - - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-3, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//u с нужным знаком - - ConvertSum(m_lIndexDst-1, ptFormula, nIndex2, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - //координаты конечной точки - nIndex = m_arIndexDst[m_lIndexSrc-2]; - nIndex1 = m_arIndexDst[m_lIndexSrc-4]; - nIndex2 = m_arIndexDst[m_lIndexSrc-11]; - - m_lIndexSrc++; - ConvertProd(nIndex, ptFormula, nIndex-10, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//r*cos(a) - ConvertProd(nIndex1-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertSum(nIndex2-1, ptFormula, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes);//x - - ConvertProd(nIndex-6, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(nIndex-6, ptFormula, nIndex-6, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//sin теперь всегда>0 - - ConvertProd(nIndex, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//r*sin(a) - ConvertProd(nIndex1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertSum(nIndex2, ptFormula, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes);//y - m_arIndexDst.push_back(m_lIndexDst-1); - //swAngle - nIndex = m_arIndexDst[m_lIndexSrc-1]; - nIndex1 = m_arIndexDst[m_lIndexSrc-7]; - - m_lIndexSrc++; - ConvertSum(nIndex, ptFormula, 0, ptValue, nIndex1, ptFormula, true, true, true, m_oGuidsRes); - ConvertSum(21600000, ptValue, m_lIndexDst-1, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); - ConvertIf(m_lIndexDst-2, ptFormula, m_lIndexDst-2, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//swAng - - m_arIndexDst.push_back(m_lIndexDst-1); - //wR,hR - nIndex = m_arIndexDst[m_lIndexSrc-14]; - m_lIndexSrc++; - ConvertProd(nIndex-1, ptFormula, 1, ptValue, 2, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(nIndex, ptFormula, 1, ptValue, 2, ptValue, true, true, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - - //--------------------------------------------------------- - nIndex = m_arIndexDst[m_lIndexSrc-8];//координаты стартовой точки - nIndex1 = m_arIndexDst[m_lIndexSrc-9];//stAng - nIndex2 = m_arIndexDst[m_lIndexSrc-1];//swAng - - if (oSlice.m_eRuler == rtClockwiseArc && j == 0) - { - m_oPathRes.WriteString(L""); - } - else - { - m_oPathRes.WriteString(L""); - } - - //текущая точка - nIndex = m_arIndexDst[m_lIndexSrc-2]; - ConvertVal(nIndex-5, ptFormula, true, m_oGuidsRes); - ConvertVal(nIndex, ptFormula, true, m_oGuidsRes); - } - } - - void ConvertSlice_QuadrBesier(const CSlicePath& oSlice) - { - for (size_t j = 0; j < oSlice.m_arPoints.size(); j += 2) - { - int l = (int)(oSlice.m_arPoints.size() - j - 3); - if (l >= 0) - { - m_oPathRes.WriteString(L""); - for (int k = 0; k < 2; ++k) - { - pCurPoint = oSlice.m_arPoints[j+k]; - pCurPointType = oSlice.m_arPointsType[j+k]; - - m_oPathRes.WriteString(L""); - } - m_oPathRes.WriteString(L""); - } - else - { - for (size_t k = 0; k < oSlice.m_arPoints.size() - j; ++k) - { - pCurPoint = oSlice.m_arPoints[j+k]; - pCurPointType = oSlice.m_arPointsType[j+k]; - - m_oPathRes.WriteString(L""); - } - } - - m_lIndexSrc++; - ConvertVal(pCurPoint.x, pCurPointType.x, false, m_oGuidsRes); - ConvertVal(pCurPoint.y, pCurPointType.y, false, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - } - } - - void ConvertSlice_CurveTo(const CSlicePath& oSlice) - { - LONG nIndex = 0; - for (size_t j = 0; j < oSlice.m_arPoints.size(); j += 3) - { - int l = (int)(oSlice.m_arPoints.size() - j - 3); - if ( l >= 0 ) - { - m_oPathRes.WriteString(L""); - for (int k = 0; k < 3; ++k) - { - pCurPoint = oSlice.m_arPoints[j+k]; - pCurPointType = oSlice.m_arPointsType[j+k]; - - m_oPathRes.WriteString(L""); - } - m_oPathRes.WriteString(L""); - } - else - { - for (size_t k = 0; k < oSlice.m_arPoints.size() - j; ++k) - { - m_oPathRes.WriteString(L""); - } - } - - m_lIndexSrc++; - ConvertVal(pCurPoint.x, pCurPointType.x, false, m_oGuidsRes); - ConvertVal(pCurPoint.y, pCurPointType.y, false, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - } - } - - void ConvertSlice_RCurveTo(const CSlicePath& oSlice) - { - LONG nIndex = 0; - for (size_t j = 0; j < oSlice.m_arPoints.size(); j += 3) - { - nIndex = m_arIndexDst[m_lIndexSrc]; - - int l = (int)(oSlice.m_arPoints.size() - j - 3); - if (l >= 0) - { - m_oPathRes.WriteString(L""); - for (int k = 0; k < 3; ++k) - { - pCurPoint = oSlice.m_arPoints[j+k]; - pCurPointType = oSlice.m_arPointsType[j+k]; - - m_lIndexSrc++; - ConvertSum(nIndex-1, ptFormula, pCurPoint.x, pCurPointType.x, 0, ptValue, true, false, true, m_oGuidsRes); - ConvertSum(nIndex, ptFormula, pCurPoint.y, pCurPointType.y, 0, ptValue, true, false, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - - m_oPathRes.WriteString(L""); - } - m_oPathRes.WriteString(L""); - } - else - { - for (size_t k=0; k < oSlice.m_arPoints.size() - j; ++k) - { - pCurPoint = oSlice.m_arPoints[j+k]; - pCurPointType = oSlice.m_arPointsType[j+k]; - - m_lIndexSrc++; - ConvertSum(nIndex-1, ptFormula, pCurPoint.x, pCurPointType.x, 0, ptValue, true, false, true, m_oGuidsRes); - ConvertSum(nIndex, ptFormula, pCurPoint.y, pCurPointType.y, 0, ptValue, true, false, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - - m_oPathRes.WriteString(L""); - } - } - - nIndex = m_arIndexDst[m_lIndexSrc]; - - m_lIndexSrc++; - ConvertVal(nIndex-1, ptFormula, true, m_oGuidsRes); - ConvertVal(nIndex, ptFormula, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - } - } - - void ConvertSlice_AngleEllipse(const CSlicePath& oSlice) - { - LONG nIndex = 0; - LONG nIndex1 = 0; - LONG nIndex2 = 0; - - for (size_t j = 0; j < oSlice.m_arPoints.size(); j += 3) - { - pCurPoint = oSlice.m_arPoints[j+1]; - pCurPointType = oSlice.m_arPointsType[j+1]; - pCurPoint1 = oSlice.m_arPoints[j+2]; - pCurPointType1 = oSlice.m_arPointsType[j+2]; - - //конвертация углов в pptx формат - m_lIndexSrc++; - ConvertProd(pCurPoint1.x, pCurPointType1.x, pow3_16, ptValue, m_oParam.m_lParam, m_oParam.m_eType, false, true, true, m_oGuidsRes); //1 угол - ConvertProd(pCurPoint1.y, pCurPointType1.y, pow3_16, ptValue, m_oParam.m_lParam, m_oParam.m_eType, false, true, true, m_oGuidsRes); //2 угол - m_arIndexDst.push_back(m_lIndexDst-1); - - //wR и hR - nIndex = m_arIndexDst[m_lIndexSrc]; - - m_lIndexSrc++; - ConvertVal(pCurPoint.x, pCurPointType.x, false, m_oGuidsRes);//wr=a - ConvertVal(pCurPoint.y, pCurPointType.y, false, m_oGuidsRes);//hr=b - - m_arIndexDst.push_back(m_lIndexDst-1); - - //stAng и swAng - nIndex = m_arIndexDst[m_lIndexSrc-1]; - - m_lIndexSrc++; - ConvertProd(nIndex-1, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes); //stAng - ConvertSum(nIndex-1, ptFormula, nIndex, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(nIndex, ptFormula, -1, ptValue, 1, ptValue, true, true, true, m_oGuidsRes);//swAng - m_arIndexDst.push_back(m_lIndexDst-1); - - //радиус до стартовой точки - - nIndex = m_arIndexDst[m_lIndexSrc]; //stang - nIndex1 = m_arIndexDst[m_lIndexSrc-1]; //wr hr - - m_lIndexSrc++; - ConvertCos(1, ptValue, nIndex-2, ptFormula, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(nIndex1, ptFormula, nIndex1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//(b*cos(u))^2 - - ConvertSin(1, ptValue, nIndex-2, ptFormula, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(nIndex1-1, ptFormula, nIndex1-1, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); - ConvertProd(m_lIndexDst-1, ptFormula, m_lIndexDst-2, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);//(a*sin(u))^2 - - ConvertSum(m_lIndexDst-1, ptFormula, m_lIndexDst-5, ptFormula, 0, ptValue, true, true, true, m_oGuidsRes); - ConvertSqrt(m_lIndexDst-1, ptFormula, true, m_oGuidsRes); - ConvertProd(nIndex1, ptFormula, nIndex1-1, ptFormula, m_lIndexDst-1, ptFormula, true, true, true, m_oGuidsRes);//r - m_arIndexDst.push_back(m_lIndexDst-1); - - //координаты конечной точки (она же начальная для эллипса) - - pCurPoint1 = oSlice.m_arPoints[j];//коорд центра - pCurPointType1 = oSlice.m_arPointsType[j]; - - nIndex = m_arIndexDst[m_lIndexSrc-1]; //stang - nIndex1 = m_arIndexDst[m_lIndexSrc]; //r - - m_lIndexSrc++; - - ConvertProd(nIndex1, ptFormula, nIndex1-10, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes); //r*cos - ConvertSum(pCurPoint1.x, pCurPointType1.x, m_lIndexDst-1, ptFormula, 0, ptValue, false, true, true, m_oGuidsRes);//x - - ConvertProd(nIndex1, ptFormula, nIndex1-6, ptFormula, 1, ptValue, true, true, true, m_oGuidsRes);// r*sin - ConvertSum(pCurPoint1.y, pCurPointType1.y, m_lIndexDst-1, ptFormula, 0, ptValue, false, true, true, m_oGuidsRes);//y - m_arIndexDst.push_back(m_lIndexDst-1); - //--------------------- - - nIndex = m_arIndexDst[m_lIndexSrc];//текущая точка - nIndex1 = m_arIndexDst[m_lIndexSrc-2];//stAng и swAng - nIndex2 = m_arIndexDst[m_lIndexSrc-3];//wR и hR - - if (j == 0) - strFrmla = L"moveTo"; - else - strFrmla = L"lnTo"; - - if (j == 0) - { - m_oPathRes.WriteString(L""); - } - else - { - m_oPathRes.WriteString(L""); - } - - //текущая точка - - nIndex = m_arIndexDst[m_lIndexSrc]; - - m_lIndexSrc++; - ConvertVal(nIndex-2, ptFormula, true, m_oGuidsRes); - ConvertVal(nIndex, ptFormula, true, m_oGuidsRes); - m_arIndexDst.push_back(m_lIndexDst-1); - } - } - - void ConvertSlice_EllipticalQuadrX(const CSlicePath& oSlice) - { - for (size_t j = 0; j < oSlice.m_arPoints.size(); j += 2) - { - pCurPoint = oSlice.m_arPoints[j]; - pCurPointType = oSlice.m_arPointsType[j]; - - ConvertQuadrX(pCurPoint, pCurPointType); - - if (j + 1 < oSlice.m_arPoints.size()) - { - pCurPoint1 = oSlice.m_arPoints[j+1]; - pCurPointType1 = oSlice.m_arPointsType[j+1]; - ConvertQuadrY(pCurPoint1, pCurPointType1); - } - } - } - - void ConvertSlice_EllipticalQuadrY(const CSlicePath& oSlice) - { - for (size_t j = 0; j < oSlice.m_arPoints.size(); j += 2) - { - pCurPoint = oSlice.m_arPoints[j]; - pCurPointType = oSlice.m_arPointsType[j]; - ConvertQuadrY(pCurPoint, pCurPointType); - - if (j + 1 < oSlice.m_arPoints.size()) - { - pCurPoint1 = oSlice.m_arPoints[j+1]; - pCurPointType1 = oSlice.m_arPointsType[j+1]; - ConvertQuadrX(pCurPoint1, pCurPointType1); - } - } - } + void ConvertSlice_MoveTo(const CSlicePath& oSlice); + void ConvertSlice_RMoveTo(const CSlicePath& oSlice); + void ConvertSlice_LineTo(const CSlicePath& oSlice); + void ConvertSlice_RLineTo(const CSlicePath& oSlice); + void ConvertSlice_ArcTo(const CSlicePath& oSlice); + void ConvertSlice_ClockwiseTo(const CSlicePath& oSlice); + void ConvertSlice_QuadrBesier(const CSlicePath& oSlice); + void ConvertSlice_CurveTo(const CSlicePath& oSlice); + void ConvertSlice_RCurveTo(const CSlicePath& oSlice); + void ConvertSlice_AngleEllipse(const CSlicePath& oSlice); + void ConvertSlice_EllipticalQuadrX(const CSlicePath& oSlice); + void ConvertSlice_EllipticalQuadrY(const CSlicePath& oSlice); }; } diff --git a/MsBinaryFile/Common/Vml/PPTShape/PptFormula.cpp b/MsBinaryFile/Common/Vml/PPTShape/PptFormula.cpp index a105738290..b9d8471760 100644 --- a/MsBinaryFile/Common/Vml/PPTShape/PptFormula.cpp +++ b/MsBinaryFile/Common/Vml/PPTShape/PptFormula.cpp @@ -33,140 +33,282 @@ #include "PptFormula.h" -LONG NSGuidesVML::CFormula::Calculate(NSGuidesVML::CFormulasManager* pManager) +namespace NSGuidesVML { - if ((0 > m_lIndex) || (m_lIndex >= (int)pManager->m_arResults.size())) - return 0; - if (0xFFFFFFFF != pManager->m_arResults[m_lIndex]) + CFormula::CFormula() { - return pManager->m_arResults[m_lIndex]; - } - - LONG lResult = 0; + m_eFormulaType = ftSum; + m_lIndex = 0; + m_lParam1 = 0; m_eType1 = ptValue; + m_lParam2 = 0; m_eType2 = ptValue; + m_lParam3 = 0; m_eType3 = ptValue; - LONG lGuidesCount = (LONG)pManager->m_arFormulas.size(); - LONG lAdjCount = (LONG)pManager->m_pAdjustments->size(); - - LONG a1 = m_lParam1; - if (ptFormula == m_eType1 && !pManager->m_bCalc) - { - pManager->m_bCalc = true; - a1 = (m_lParam1 >= lGuidesCount) ? 0 : pManager->m_arFormulas[m_lParam1].Calculate(pManager); + m_lCountRecurs = 0; } - else if (ptAdjust == m_eType1) + CFormula::CFormula(int nIndex) { - a1 = (m_lParam1 >= lAdjCount) ? 0 : (*(pManager->m_pAdjustments))[m_lParam1]; - } - pManager->m_bCalc = false; + m_eFormulaType = ftSum; + m_lIndex = nIndex; + m_lParam1 = 0; m_eType1 = ptValue; + m_lParam2 = 0; m_eType2 = ptValue; + m_lParam3 = 0; m_eType3 = ptValue; - LONG b1 = m_lParam2; - if (ptFormula == m_eType2 && !pManager->m_bCalc) - { - pManager->m_bCalc = true; - b1 = (m_lParam2 >= lGuidesCount) ? 0 : pManager->m_arFormulas[m_lParam2].Calculate(pManager); + m_lCountRecurs = 0; } - else if (ptAdjust == m_eType2) + CFormula& CFormula::operator =(const CFormula& oSrc) { - b1 = (m_lParam2 >= lAdjCount) ? 0 : (*(pManager->m_pAdjustments))[m_lParam2]; + m_eFormulaType = oSrc.m_eFormulaType; + m_lIndex = oSrc.m_lIndex; + + m_lParam1 = oSrc.m_lParam1; + m_eType1 = oSrc.m_eType1; + + m_lParam2 = oSrc.m_lParam2; + m_eType2 = oSrc.m_eType2; + + m_lParam3 = oSrc.m_lParam3; + m_eType3 = oSrc.m_eType3; + + m_lCountRecurs = 0; + return (*this); } - pManager->m_bCalc = false; - - LONG c1 = m_lParam3; - if (ptFormula == m_eType3 && !pManager->m_bCalc) + void CFormula::FromString(std::wstring strFormula, long lShapeWidth, long lShapeHeight) { - pManager->m_bCalc = true; - c1 = (m_lParam3 >= lGuidesCount) ? 0 : pManager->m_arFormulas[m_lParam3].Calculate(pManager); - } - else if (ptAdjust == m_eType3) - { - c1 = (m_lParam3 >= lAdjCount) ? 0 : (*(pManager->m_pAdjustments))[m_lParam3]; - } - pManager->m_bCalc = false; + std::vector oArrayParams; + boost::algorithm::split(oArrayParams, strFormula, boost::algorithm::is_any_of(L" "), boost::algorithm::token_compress_on); - double a = (double)a1; - double b = (double)b1; - double c = (double)c1; + int nCount = (int)oArrayParams.size(); + if (0 >= nCount) + return; - double dRes = 0.0; + bool bRes = true; + m_eFormulaType = GetFormula(oArrayParams[0], bRes); - try - { - // теперь нужно просто посчитать - switch (m_eFormulaType) + ParamType ptType = ptValue; + if (1 < nCount) { - case ftSum: { dRes = a + b - c; break; } - case ftProduct: { - if (0 == c) - c = 1; - - dRes = a * b / c; - break; - } - case ftMid: { dRes = (a + b) / 2.0; break; } - case ftAbsolute: { dRes = abs(a); break; } - - case ftMin: { dRes = (std::min)(a, b); break; } - case ftMax: { dRes = (std::max)(a, b); break; } - case ftIf: { dRes = (a > 0) ? b : c; break; } - case ftSqrt: { dRes = sqrt(a); break; } - case ftMod: { dRes = sqrt(a*a + b*b + c*c); break; } - - case ftSin: { - //dRes = a * sin(b); - //dRes = a * sin(b / pow2_16); - dRes = a * sin(M_PI * b / (pow2_16 * 180)); - break; - } - case ftCos: { - //dRes = a * cos(b); - //dRes = a * cos(b / pow2_16); - dRes = a * cos(M_PI * b / (pow2_16 * 180)); - break; - } - case ftTan: { - //dRes = a * tan(b); - dRes = a * tan(M_PI * b / (pow2_16 * 180)); - break; - } - case ftAtan2: { - dRes = 180 * pow2_16 * atan2(b,a) / M_PI; - break; - } - - case ftSinatan2: { dRes = a * sin(atan2(c,b)); break; } - case ftCosatan2: { dRes = a * cos(atan2(c,b)); break; } - - case ftSumangle: { - //dRes = a + b - c; - dRes = a + b * pow2_16 - c * pow2_16; - - /*while (23592960 < dRes) - { - dRes -= 23592960; - } - while (-23592960 > dRes) - { - dRes += 23592960; - }*/ - - break; - } - case ftEllipse: { - if (0 == b) - b = 1; - dRes = c * sqrt(1-(a*a/(b*b))); - break; - } - case ftVal: { dRes = a; break; } - default: break; - }; + m_lParam1 = GetValue(oArrayParams[1], ptType, bRes, lShapeWidth, lShapeHeight); + m_eType1 = ptType; + } + if (2 < nCount) + { + m_lParam2 = GetValue(oArrayParams[2], ptType, bRes, lShapeWidth, lShapeHeight); + m_eType2 = ptType; + } + if (3 < nCount) + { + m_lParam3 = GetValue(oArrayParams[3], ptType, bRes, lShapeWidth, lShapeHeight); + m_eType3 = ptType; + } } - catch (...) + LONG CFormula::Calculate(NSGuidesVML::CFormulasManager* pManager) { - dRes = 0; + if ((0 > m_lIndex) || (m_lIndex >= (int)pManager->m_arResults.size())) + return 0; + if (0xFFFFFFFF != pManager->m_arResults[m_lIndex]) + { + return pManager->m_arResults[m_lIndex]; + } + + LONG lResult = 0; + + LONG lGuidesCount = (LONG)pManager->m_arFormulas.size(); + LONG lAdjCount = (LONG)pManager->m_pAdjustments->size(); + + LONG a1 = m_lParam1; + if (ptFormula == m_eType1 && !pManager->m_bCalc) + { + pManager->m_bCalc = true; + a1 = (m_lParam1 >= lGuidesCount) ? 0 : pManager->m_arFormulas[m_lParam1].Calculate(pManager); + } + else if (ptAdjust == m_eType1) + { + a1 = (m_lParam1 >= lAdjCount) ? 0 : (*(pManager->m_pAdjustments))[m_lParam1]; + } + pManager->m_bCalc = false; + + LONG b1 = m_lParam2; + if (ptFormula == m_eType2 && !pManager->m_bCalc) + { + pManager->m_bCalc = true; + b1 = (m_lParam2 >= lGuidesCount) ? 0 : pManager->m_arFormulas[m_lParam2].Calculate(pManager); + } + else if (ptAdjust == m_eType2) + { + b1 = (m_lParam2 >= lAdjCount) ? 0 : (*(pManager->m_pAdjustments))[m_lParam2]; + } + pManager->m_bCalc = false; + + LONG c1 = m_lParam3; + if (ptFormula == m_eType3 && !pManager->m_bCalc) + { + pManager->m_bCalc = true; + c1 = (m_lParam3 >= lGuidesCount) ? 0 : pManager->m_arFormulas[m_lParam3].Calculate(pManager); + } + else if (ptAdjust == m_eType3) + { + c1 = (m_lParam3 >= lAdjCount) ? 0 : (*(pManager->m_pAdjustments))[m_lParam3]; + } + pManager->m_bCalc = false; + + double a = (double)a1; + double b = (double)b1; + double c = (double)c1; + + double dRes = 0.0; + + try + { + // теперь нужно просто посчитать + switch (m_eFormulaType) + { + case ftSum: { dRes = a + b - c; break; } + case ftProduct: { + if (0 == c) + c = 1; + + dRes = a * b / c; + break; + } + case ftMid: { dRes = (a + b) / 2.0; break; } + case ftAbsolute: { dRes = abs(a); break; } + + case ftMin: { dRes = (std::min)(a, b); break; } + case ftMax: { dRes = (std::max)(a, b); break; } + case ftIf: { dRes = (a > 0) ? b : c; break; } + case ftSqrt: { dRes = sqrt(a); break; } + case ftMod: { dRes = sqrt(a*a + b*b + c*c); break; } + + case ftSin: { + //dRes = a * sin(b); + //dRes = a * sin(b / pow2_16); + dRes = a * sin(M_PI * b / (pow2_16 * 180)); + break; + } + case ftCos: { + //dRes = a * cos(b); + //dRes = a * cos(b / pow2_16); + dRes = a * cos(M_PI * b / (pow2_16 * 180)); + break; + } + case ftTan: { + //dRes = a * tan(b); + dRes = a * tan(M_PI * b / (pow2_16 * 180)); + break; + } + case ftAtan2: { + dRes = 180 * pow2_16 * atan2(b,a) / M_PI; + break; + } + + case ftSinatan2: { dRes = a * sin(atan2(c,b)); break; } + case ftCosatan2: { dRes = a * cos(atan2(c,b)); break; } + + case ftSumangle: { + //dRes = a + b - c; + dRes = a + b * pow2_16 - c * pow2_16; + + /*while (23592960 < dRes) + { + dRes -= 23592960; + } + while (-23592960 > dRes) + { + dRes += 23592960; + }*/ + + break; + } + case ftEllipse: { + if (0 == b) + b = 1; + dRes = c * sqrt(1-(a*a/(b*b))); + break; + } + case ftVal: { dRes = a; break; } + default: break; + }; + } + catch (...) + { + dRes = 0; + } + + lResult = (LONG)dRes; + pManager->m_arResults[m_lIndex] = lResult; + return lResult; } - lResult = (LONG)dRes; - pManager->m_arResults[m_lIndex] = lResult; - return lResult; + CFormulasManager::CFormulasManager() : m_bCalc(false) + { + m_pAdjustments = NULL; + m_lShapeWidth = ShapeSizeVML; + m_lShapeHeight = ShapeSizeVML; + } + CFormulasManager& CFormulasManager::operator =(const CFormulasManager& oSrc) + { + m_bCalc = oSrc.m_bCalc; + m_pAdjustments = oSrc.m_pAdjustments; + m_lShapeWidth = oSrc.m_lShapeWidth; + m_lShapeHeight = oSrc.m_lShapeHeight; + + m_arResults.clear(); + for (size_t nIndex = 0; nIndex < oSrc.m_arResults.size(); ++nIndex) + { + m_arResults.push_back(oSrc.m_arResults[nIndex]); + } + m_arFormulas.clear(); + for (size_t nIndex = 0; nIndex < oSrc.m_arFormulas.size(); ++nIndex) + { + m_arFormulas.push_back(oSrc.m_arFormulas[nIndex]); + } + + return (*this); + } + void CFormulasManager::Clear() + { + m_bCalc = false; + m_pAdjustments = NULL; + m_lShapeWidth = ShapeSizeVML; + m_lShapeHeight = ShapeSizeVML; + + m_arFormulas.clear(); + m_arResults.clear(); + } + void CFormulasManager::Clear(std::vector* pAdjusts) + { + m_pAdjustments = pAdjusts; + + //m_arFormulas.clear(); + //m_arResults.clear(); + for (size_t nIndex = 0; nIndex < m_arResults.size(); ++nIndex) + { + m_arResults[nIndex] = 0xFFFFFFFF; + } + } + void CFormulasManager::AddFormula(std::wstring strFormula) + { + CFormula oFormula((int)m_arFormulas.size()); + + oFormula.FromString(strFormula, m_lShapeWidth, m_lShapeHeight); + m_arFormulas.push_back(oFormula); + m_arResults.push_back(0xFFFFFFFF); + } + void CFormulasManager::AddFormula(CFormula oFormula) + { + oFormula.m_lIndex = (int)m_arFormulas.size(); + + m_arFormulas.push_back(oFormula); + m_arResults.push_back(0xFFFFFFFF); + } + void CFormulasManager::CalculateResults() + { + for (size_t index = 0; index < m_arFormulas.size(); ++index) + { + LONG lResult = m_arFormulas[index].Calculate(this); + } + + //m_pAdjustments = NULL; + //m_arFormulas.clear(); + } } diff --git a/MsBinaryFile/Common/Vml/PPTShape/PptFormula.h b/MsBinaryFile/Common/Vml/PPTShape/PptFormula.h index 9c190487cf..77a3fe6c4e 100644 --- a/MsBinaryFile/Common/Vml/PPTShape/PptFormula.h +++ b/MsBinaryFile/Common/Vml/PPTShape/PptFormula.h @@ -121,83 +121,84 @@ namespace NSGuidesVML }; static long GetValue(std::wstring strParam, ParamType& ptType, bool& bRes, - long lShapeWidth = ShapeSizeVML, long lShapeHeight = ShapeSizeVML) - { - ptType = ptValue; - bRes = true; - long val = 0; + long lShapeWidth = ShapeSizeVML, long lShapeHeight = ShapeSizeVML) + { + ptType = ptValue; + bRes = true; + long val = 0; - if ('#' == strParam[0]) - { - ptType = ptAdjust; - val = XmlUtils::GetInteger(strParam.substr(1)); - } - else if ('@' == strParam[0]) - { - ptType = ptFormula; - val = XmlUtils::GetInteger(strParam.substr(1)); - } - else if (!NSStringUtils::IsNumber(strParam)) - { - if (_T("width") == strParam) - { - val = lShapeWidth; - } - else if (_T("height") == strParam) - { - val = lShapeHeight; - } - else if (_T("pixelWidth") == strParam) - { - val = lShapeWidth; - } - else if (_T("pixelHeight") == strParam) - { - val = lShapeHeight; - } - else if (_T("pixelLineWidth") == strParam || _T("lineDrawn") == strParam) - { - val = 1; - } - else - { - bRes = false; - return 0; - } - } - else - { - ptType = ptValue; - val = XmlUtils::GetInteger(strParam); - } - return val; - } + if ('#' == strParam[0]) + { + ptType = ptAdjust; + val = XmlUtils::GetInteger(strParam.substr(1)); + } + else if ('@' == strParam[0]) + { + ptType = ptFormula; + val = XmlUtils::GetInteger(strParam.substr(1)); + } + else if (!NSStringUtils::IsNumber(strParam)) + { + if (_T("width") == strParam) + { + val = lShapeWidth; + } + else if (_T("height") == strParam) + { + val = lShapeHeight; + } + else if (_T("pixelWidth") == strParam) + { + val = lShapeWidth; + } + else if (_T("pixelHeight") == strParam) + { + val = lShapeHeight; + } + else if (_T("pixelLineWidth") == strParam || _T("lineDrawn") == strParam) + { + val = 1; + } + else + { + bRes = false; + return 0; + } + } + else + { + ptType = ptValue; + val = XmlUtils::GetInteger(strParam); + } + return val; + } - static FormulaType GetFormula(std::wstring strName, bool& bRes) - { - bRes = true; - if (_T("sum") == strName) return ftSum; - else if ((_T("prod") == strName) || (_T("product") == strName)) return ftProduct; - else if (_T("mid") == strName) return ftMid; - else if ((_T("absolute") == strName) || (_T("abs") == strName)) return ftAbsolute; - else if (_T("min") == strName) return ftMin; - else if (_T("max") == strName) return ftMax; - else if (_T("if") == strName) return ftIf; - else if (_T("sqrt") == strName) return ftSqrt; - else if (_T("mod") == strName) return ftMod; - else if (_T("sin") == strName) return ftSin; - else if (_T("cos") == strName) return ftCos; - else if (_T("tan") == strName) return ftTan; - else if (_T("atan2") == strName) return ftAtan2; - else if (_T("sinatan2") == strName) return ftSinatan2; - else if (_T("cosatan2") == strName) return ftCosatan2; - else if (_T("sumangle") == strName) return ftSumangle; - else if (_T("ellipse") == strName) return ftEllipse; - else if (_T("val") == strName) return ftVal; - else bRes = false; + static FormulaType GetFormula(std::wstring strName, bool& bRes) + { + bRes = true; + if (_T("sum") == strName) return ftSum; + else if ((_T("prod") == strName) || (_T("product") == strName)) return ftProduct; + else if (_T("mid") == strName) return ftMid; + else if ((_T("absolute") == strName) || (_T("abs") == strName)) return ftAbsolute; + else if (_T("min") == strName) return ftMin; + else if (_T("max") == strName) return ftMax; + else if (_T("if") == strName) return ftIf; + else if (_T("sqrt") == strName) return ftSqrt; + else if (_T("mod") == strName) return ftMod; + else if (_T("sin") == strName) return ftSin; + else if (_T("cos") == strName) return ftCos; + else if (_T("tan") == strName) return ftTan; + else if (_T("atan2") == strName) return ftAtan2; + else if (_T("sinatan2") == strName) return ftSinatan2; + else if (_T("cosatan2") == strName) return ftCosatan2; + else if (_T("sumangle") == strName) return ftSumangle; + else if (_T("ellipse") == strName) return ftEllipse; + else if (_T("val") == strName) return ftVal; + else bRes = false; + + return ftVal; + } - return ftVal; - } struct SPointType { ParamType x; @@ -238,9 +239,11 @@ namespace NSGuidesVML Aggplus::POINT PolarCentre; SPointType PolarCentreType; - }; + }; + class CFormulasManager; - class CFormula + + class CFormula { public: FormulaType m_eFormulaType; @@ -259,75 +262,12 @@ namespace NSGuidesVML long m_lCountRecurs; public: - CFormula() - { - m_eFormulaType = ftSum; - m_lIndex = 0; - m_lParam1 = 0; m_eType1 = ptValue; - m_lParam2 = 0; m_eType2 = ptValue; - m_lParam3 = 0; m_eType3 = ptValue; + CFormula(); + CFormula(int nIndex); - m_lCountRecurs = 0; - } + CFormula& operator =(const CFormula& oSrc); - CFormula(int nIndex) - { - m_eFormulaType = ftSum; - m_lIndex = nIndex; - m_lParam1 = 0; m_eType1 = ptValue; - m_lParam2 = 0; m_eType2 = ptValue; - m_lParam3 = 0; m_eType3 = ptValue; - - m_lCountRecurs = 0; - } - - CFormula& operator =(const CFormula& oSrc) - { - m_eFormulaType = oSrc.m_eFormulaType; - m_lIndex = oSrc.m_lIndex; - - m_lParam1 = oSrc.m_lParam1; - m_eType1 = oSrc.m_eType1; - - m_lParam2 = oSrc.m_lParam2; - m_eType2 = oSrc.m_eType2; - - m_lParam3 = oSrc.m_lParam3; - m_eType3 = oSrc.m_eType3; - - m_lCountRecurs = 0; - return (*this); - } - - void FromString(std::wstring strFormula, long lShapeWidth = ShapeSizeVML, long lShapeHeight = ShapeSizeVML) - { - std::vector oArrayParams; - boost::algorithm::split(oArrayParams, strFormula, boost::algorithm::is_any_of(L" "), boost::algorithm::token_compress_on); - - int nCount = (int)oArrayParams.size(); - if (0 >= nCount) - return; - - bool bRes = true; - m_eFormulaType = GetFormula(oArrayParams[0], bRes); - - ParamType ptType = ptValue; - if (1 < nCount) - { - m_lParam1 = GetValue(oArrayParams[1], ptType, bRes, lShapeWidth, lShapeHeight); - m_eType1 = ptType; - } - if (2 < nCount) - { - m_lParam2 = GetValue(oArrayParams[2], ptType, bRes, lShapeWidth, lShapeHeight); - m_eType2 = ptType; - } - if (3 < nCount) - { - m_lParam3 = GetValue(oArrayParams[3], ptType, bRes, lShapeWidth, lShapeHeight); - m_eType3 = ptType; - } - } + void FromString(std::wstring strFormula, long lShapeWidth = ShapeSizeVML, long lShapeHeight = ShapeSizeVML); LONG Calculate(CFormulasManager* pManager); }; @@ -344,79 +284,16 @@ namespace NSGuidesVML bool m_bCalc; //status - CFormulasManager() : m_bCalc(false) - { - m_pAdjustments = NULL; - m_lShapeWidth = ShapeSizeVML; - m_lShapeHeight = ShapeSizeVML; - } - CFormulasManager& operator =(const CFormulasManager& oSrc) - { - m_bCalc = oSrc.m_bCalc; - m_pAdjustments = oSrc.m_pAdjustments; - m_lShapeWidth = oSrc.m_lShapeWidth; - m_lShapeHeight = oSrc.m_lShapeHeight; + CFormulasManager(); - m_arResults.clear(); - for (size_t nIndex = 0; nIndex < oSrc.m_arResults.size(); ++nIndex) - { - m_arResults.push_back(oSrc.m_arResults[nIndex]); - } - m_arFormulas.clear(); - for (size_t nIndex = 0; nIndex < oSrc.m_arFormulas.size(); ++nIndex) - { - m_arFormulas.push_back(oSrc.m_arFormulas[nIndex]); - } + CFormulasManager& operator =(const CFormulasManager& oSrc); - return (*this); - } + void Clear(); + void Clear(std::vector* pAdjusts); - void Clear() - { - m_bCalc = false; - m_pAdjustments = NULL; - m_lShapeWidth = ShapeSizeVML; - m_lShapeHeight = ShapeSizeVML; + void AddFormula(std::wstring strFormula); + void AddFormula(CFormula oFormula); - m_arFormulas.clear(); - m_arResults.clear(); - } - - void Clear(std::vector* pAdjusts) - { - m_pAdjustments = pAdjusts; - - //m_arFormulas.clear(); - //m_arResults.clear(); - for (size_t nIndex = 0; nIndex < m_arResults.size(); ++nIndex) - { - m_arResults[nIndex] = 0xFFFFFFFF; - } - } - void AddFormula(std::wstring strFormula) - { - CFormula oFormula((int)m_arFormulas.size()); - - oFormula.FromString(strFormula, m_lShapeWidth, m_lShapeHeight); - m_arFormulas.push_back(oFormula); - m_arResults.push_back(0xFFFFFFFF); - } - void AddFormula(CFormula oFormula) - { - oFormula.m_lIndex = (int)m_arFormulas.size(); - - m_arFormulas.push_back(oFormula); - m_arResults.push_back(0xFFFFFFFF); - } - void CalculateResults() - { - for (size_t index = 0; index < m_arFormulas.size(); ++index) - { - LONG lResult = m_arFormulas[index].Calculate(this); - } - - //m_pAdjustments = NULL; - //m_arFormulas.clear(); - } + void CalculateResults(); }; } diff --git a/MsBinaryFile/Common/Vml/PPTXShape/Pptx2PptShapeConverter.cpp b/MsBinaryFile/Common/Vml/PPTXShape/Pptx2PptShapeConverter.cpp new file mode 100644 index 0000000000..84d54a8c04 --- /dev/null +++ b/MsBinaryFile/Common/Vml/PPTXShape/Pptx2PptShapeConverter.cpp @@ -0,0 +1,569 @@ +/* + * (c) Copyright Ascensio System SIA 2010-2019 + * + * 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 20A-12 Ernesta Birznieka-Upisha + * street, Riga, Latvia, EU, LV-1050. + * + * 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 "Pptx2PptShapeConverter.h" + +namespace NSGuidesVML +{ + CConverterPPTXPPT::CConverterPPTXPPT() + { + m_lPPTX2PPT = -1; + m_lPPT2PPTX = -1; + m_lIndexDst = -1; + m_lIndexAdj = -1; + pPPTShape = new CPPTShape(); + } + void CConverterPPTXPPT::Convert ( CPPTXShape* pPPTXShape ) + { + ConvertAdjastments ( pPPTXShape->m_arAdjustments, pPPTXShape->FManager.mapAdjustments ); + AddSizeGuides ((LONG)pPPTXShape->FManager.GetWidth(), (LONG)pPPTXShape->FManager.GetHeight()); + ConvertGuides ( pPPTXShape->FManager.strGuides, pPPTXShape->FManager.mapGuides); + ConvertPath( pPPTXShape->m_strPath, pPPTXShape->FManager.strGuides, pPPTXShape->FManager.mapGuides); + + //TODO текстовые поля + //ConvertTextRects ( pPPTXShape->m_arStringTextRects ); + ConvertHandles ( pPPTXShape->m_arHandles ); + + //ConvertType ( pPPTXShape->m_eType ); + //------------------------------------ + int i=0; + } + void CConverterPPTXPPT::ConvertHandles (std::vector& arHnd) + { + + for (size_t nIndex=0; nIndexm_arHandles.push_back(oHandle); + } + + return; + } + void CConverterPPTXPPT::ConvertAdjastments( std::vector &arAdj, std::map &mapAdj ) + { + int i=0; + for( std::map::iterator pPair = mapAdj.begin(); pPair != mapAdj.end(); i++, ++pPair) + { + m_arMapAdj.insert(std::pair(pPair->first, ++m_lIndexAdj)); + pPPTShape->m_arAdjustments.push_back(arAdj[i]); + } + //это аджасменты для перевода углов tan(angle, adj) + //тк все угла в формулах считаются в pptx + //pptx->ppt + pPPTShape->m_arAdjustments.push_back(3114601); + m_lPPTX2PPT = ++m_lIndexAdj; + //ppt->pptx + pPPTShape->m_arAdjustments.push_back(2783638); + m_lPPT2PPTX = ++m_lIndexAdj; + return; + } + void CConverterPPTXPPT::ConvertTextRects (std::vector &arTextRects) + { + pPPTShape->m_arStringTextRects.insert( pPPTShape->m_arStringTextRects.end(), arTextRects.begin(), arTextRects.end()); + return; + } + void CConverterPPTXPPT::ConvertType (OOXMLShapes::ShapeType eType) + { + switch (eType) + { + case OOXMLShapes::sptCRect: + pPPTShape->m_eType = PPTShapes::sptCRect; + break; + case OOXMLShapes::sptCArc: + pPPTShape->m_eType = PPTShapes::sptCRect; + break; + default: + pPPTShape->m_eType = PPTShapes::sptCustom; + } + return; + } + void CConverterPPTXPPT::AddSizeGuides (LONG lWidth, LONG lHeight) + { + //TODO прокинуть w и h в формулах + NSGuidesVML::CFormula pNewFmla3; + pNewFmla3.m_eFormulaType = ftVal; + pNewFmla3.m_lIndex = ++m_lIndexDst; + pNewFmla3.m_eType1 = ptValue; + pNewFmla3.m_lParam1 = 21600;// lWidth; + pPPTShape->m_oManager.m_arFormulas.push_back(pNewFmla3); + m_arMapFormula.insert(std::pair(_T("w"), m_lIndexDst)); + + pNewFmla3.m_lIndex = ++m_lIndexDst; + pNewFmla3.m_eType1 = ptValue; + pNewFmla3.m_lParam1 = 21600;//lHeight; + + pPPTShape->m_oManager.m_arFormulas.push_back(pNewFmla3); + + m_arMapFormula.insert(std::pair(_T("h"), m_lIndexDst)); + + return; + } + LONG CConverterPPTXPPT::ConvertFmlaParam (std::wstring strParam, NSGuidesVML::ParamType &eType, std::wstring strKey, std::vector &strGuides, std::map &mapGuides) + { + LONG lVal = 0; + + std::map::iterator NumFmla = m_arMapFormula.find(strParam); + std::map::iterator NumAdj = m_arMapAdj.find(strParam); + std::map::iterator NumGuides = mapGuides.find(strParam); + + if (NumAdj != m_arMapAdj.end()) + { + eType = ptAdjust; + lVal = NumAdj->second; + } + else if (NumFmla == m_arMapFormula.end()) + { + //пришло число + if (NumGuides == mapGuides.end()) + { + lVal = (LONG)XmlUtils::GetInteger(strParam); + if (lVal > 65535) + { + ConvertFmla( ftSumangle, lVal%65536, ptValue, (int)lVal/65536, ptValue, 0, ptValue); + eType = ptFormula; + lVal = m_lIndexDst; + } + else if (lVal < 0) + { + ConvertFmla( ftSum, 0, ptValue, 0, ptValue, abs(lVal), ptValue); + eType = ptFormula; + lVal = m_lIndexDst; + } + else + eType = ptValue; + } + else //пришла стандартная формула из набора, которую надо теперь добавить + { + LONG lNumGuides = NumGuides->second; + + NSGuidesOOXML::CFormula pFormula = strGuides[lNumGuides]; + + //strKey = mapGuides.GetKeyAt(lNumGuides); + int ind =0; + for (std::map::iterator p = mapGuides.begin(); p!= mapGuides.end(); ++p) + { + if (ind == lNumGuides) + { + strKey = p->first; + break; + } + } + + ConvertGuid(pFormula, strKey, strGuides, mapGuides); + eType = ptFormula; + lVal = m_lIndexDst; + } + } + else + { + eType = ptFormula; + std::map::iterator Val = m_arMapFormula.find(strParam); + lVal = Val->second; + } + return lVal; + } + void CConverterPPTXPPT::ConvertFmla ( FormulaType eFmlaType, LONG lParam1, ParamType eType1, LONG lParam2, ParamType eType2, LONG lParam3, ParamType eType3 ) + { + NSGuidesVML::CFormula pNewFmla; + pNewFmla.m_lIndex = ++m_lIndexDst; + pNewFmla.m_eFormulaType = eFmlaType; + + pNewFmla.m_eType1 = eType1; + pNewFmla.m_lParam1 = lParam1; + + pNewFmla.m_eType2 = eType2; + pNewFmla.m_lParam2 = lParam2; + + pNewFmla.m_eType3 = eType3; + pNewFmla.m_lParam3 = lParam3; + + pPPTShape->m_oManager.m_arFormulas.push_back(pNewFmla); + return; + } + void CConverterPPTXPPT::ConvertFmla ( FormulaType eFmlaType, LONG lParam1, ParamType eType1, LONG lParam2, ParamType eType2 ) + { + CFormula pNewFmla; + pNewFmla.m_lIndex = ++m_lIndexDst; + pNewFmla.m_eFormulaType = eFmlaType; + + pNewFmla.m_eType1 = eType1; + pNewFmla.m_lParam1 = lParam1; + + pNewFmla.m_eType2 = eType2; + pNewFmla.m_lParam2 = lParam2; + + pPPTShape->m_oManager.m_arFormulas.push_back(pNewFmla); + return; + } + void CConverterPPTXPPT::ConvertFmla ( FormulaType eFmlaType, LONG lParam1, ParamType eType1 ) + { + CFormula pNewFmla; + pNewFmla.m_lIndex = ++m_lIndexDst; + pNewFmla.m_eFormulaType = eFmlaType; + + pNewFmla.m_eType1 = eType1; + pNewFmla.m_lParam1 = lParam1; + + pPPTShape->m_oManager.m_arFormulas.push_back(pNewFmla); + return; + } + void CConverterPPTXPPT::ConvertGuid ( NSGuidesOOXML::CFormula pFormula, std::wstring strKey, std::vector &strGuides, std::map &mapGuides) + { + LONG lParam1, lParam2, lParam3; + NSGuidesVML::ParamType eType1, eType2, eType3; + + lParam1 = ConvertFmlaParam(pFormula.m_lParam1, eType1, strKey, strGuides, mapGuides); + lParam2 = ConvertFmlaParam(pFormula.m_lParam2, eType2, strKey, strGuides, mapGuides); + lParam3 = ConvertFmlaParam(pFormula.m_lParam3, eType3, strKey, strGuides, mapGuides); + + switch (pFormula.m_eFormulaType) + { + case NSGuidesOOXML::CFormula::ftOOXMLSum: + ConvertFmla( ftSum, lParam1, eType1, lParam2, eType2, lParam3, eType3); + break; + case NSGuidesOOXML::CFormula::ftOOXMLProduct: + ConvertFmla( ftProduct, lParam1, eType1, lParam2, eType2, lParam3, eType3); + break; + case NSGuidesOOXML::CFormula::ftOOXMLIf: + ConvertFmla( ftIf, lParam1, eType1, lParam2, eType2, lParam3, eType3); + break; + case NSGuidesOOXML::CFormula::ftOOXMLAbsolute: + ConvertFmla( ftAbsolute, lParam1, eType1); + break; + case NSGuidesOOXML::CFormula::ftOOXMLAtan2: + ConvertFmla( ftAtan2, lParam1, eType1, lParam2, eType2); + ConvertFmla( ftTan, m_lIndexDst, ptFormula, m_lPPT2PPTX, ptAdjust); + break; + case NSGuidesOOXML::CFormula::ftOOXMLCos: + ConvertFmla( ftCos, lParam1, eType1, lParam2, eType2); + ConvertFmla( ftTan, m_lIndexDst, ptFormula, m_lPPT2PPTX, ptAdjust); + break; + case NSGuidesOOXML::CFormula::ftOOXMLMax: + ConvertFmla( ftMax, lParam1, eType1, lParam2, eType2); + break; + case NSGuidesOOXML::CFormula::ftOOXMLMin: + ConvertFmla( ftMin, lParam1, eType1, lParam2, eType2); + break; + case NSGuidesOOXML::CFormula::ftOOXMLMod: + ConvertFmla( ftMod, lParam1, eType1, lParam2, eType2, lParam3, eType3); + break; + case NSGuidesOOXML::CFormula::ftOOXMLSinatan2: + ConvertFmla( ftSinatan2, lParam1, eType1, lParam2, eType2, lParam3, eType3); + ConvertFmla( ftTan, m_lIndexDst, ptFormula, m_lPPT2PPTX, ptAdjust); + break; + case NSGuidesOOXML::CFormula::ftOOXMLCosatan2: + ConvertFmla( ftCosatan2, lParam1, eType1, lParam2, eType2, lParam3, eType3); + ConvertFmla( ftTan, m_lIndexDst, ptFormula, m_lPPT2PPTX, ptAdjust); + break; + case NSGuidesOOXML::CFormula::ftOOXMLSin: + ConvertFmla( ftSin, lParam1, eType1, lParam2, eType2); + ConvertFmla( ftTan, m_lIndexDst, ptFormula, m_lPPT2PPTX, ptAdjust); + break; + case NSGuidesOOXML::CFormula::ftOOXMLSqrt: + ConvertFmla( ftSqrt, lParam1, eType1); + break; + case NSGuidesOOXML::CFormula::ftOOXMLTan: + ConvertFmla( ftTan, lParam1, eType1, lParam2, eType2); + break; + case NSGuidesOOXML::CFormula::ftOOXMLVal: + ConvertFmla( ftVal, lParam1, eType1); + break; + case NSGuidesOOXML::CFormula::ftOOXMLAddDivide: + ConvertFmla( ftSum, lParam1, eType1, lParam2, eType2, 0, ptValue); + ConvertFmla( ftProduct, m_lIndexDst, ptFormula, 1, ptValue, lParam3, eType3); + break; + case NSGuidesOOXML::CFormula::ftOOXMLPin: + ConvertFmla( ftSum, lParam1, eType1, 0, ptValue, lParam2, eType2); + ConvertFmla( ftSum, lParam2, eType2, 0, ptValue, lParam3, eType3); + ConvertFmla( ftIf, m_lIndexDst, ptFormula, lParam3, eType3, lParam2, eType2); + ConvertFmla( ftIf, m_lIndexDst-2, ptFormula, lParam1, eType1, m_lIndexDst, ptFormula); + break; + } + m_arMapFormula.insert(std::pair(strKey, m_lIndexDst)); + return; + } + void CConverterPPTXPPT::ConvertGuides ( std::vector &strGuides, std::map &mapGuides ) + { + //стандартные формулы для пптх будем добавлять, если только они встретятся + for (size_t nIndex=32; nIndex < strGuides.size(); ++nIndex) + { + NSGuidesOOXML::CFormula pFormula = strGuides[nIndex]; + + std::wstring strKey;// = mapGuides.GetKeyAt(nIndex); + int ind =0; + for (std::map::iterator p = mapGuides.begin(); p!= mapGuides.end(); ++p) + { + if (ind == nIndex) + { + strKey = p->first; + break; + } + } + ConvertGuid(pFormula, strKey, strGuides, mapGuides); + } + } + void CConverterPPTXPPT::ConvertPath(const std::wstring& xml, std::vector &strGuides, std::map &mapGuides) + { + XmlUtils::CXmlNode pathLst; + if(pathLst.FromXmlString(xml)) + { + XmlUtils::CXmlNodes list; + if (pathLst.GetNodes(_T("path"), list)) + { + int nPathCount = list.GetCount(); + for (int i=0; im_strPath += _T("m"); + else if (strName == _T("lnTo")) + pPPTShape->m_strPath += _T("l"); + else if (strName == _T("arcTo")) + pPPTShape->m_strPath += _T("ae"); + else if (strName == _T("cubicBezTo")) + pPPTShape->m_strPath += _T("c"); + else if (strName == _T("quadBezTo")) + pPPTShape->m_strPath += _T("qb"); + else + pPPTShape->m_strPath += _T("x"); + + if (strName == _T("arcTo")) + { + LONG lStartX = m_lIndexDst-1, lStartY = m_lIndexDst; + LONG lParam1, lParam2, lParam3, lParam4; + NSGuidesVML::ParamType eType1, eType2, eType3, eType4; + + lParam1 = ConvertFmlaParam(node.GetAttribute(_T("wR")), eType1, node.GetAttribute(_T("wR")), strGuides, mapGuides); + lParam2 = ConvertFmlaParam(node.GetAttribute(_T("hR")), eType2, node.GetAttribute(_T("hR")), strGuides, mapGuides); + lParam3 = ConvertFmlaParam(node.GetAttribute(_T("stAng")), eType3, node.GetAttribute(_T("stAng")), strGuides, mapGuides); + lParam4 = ConvertFmlaParam(node.GetAttribute(_T("swAng")), eType4, node.GetAttribute(_T("swAng")), strGuides, mapGuides); + + //stAng + ConvertFmla( ftTan, lParam3, eType3, m_lPPTX2PPT, ptAdjust); + //swAng + ConvertFmla( ftTan, lParam4, eType4, m_lPPTX2PPT, ptAdjust); + //a + ConvertFmla( ftVal, lParam1, eType1); + //b + ConvertFmla( ftVal, lParam2, eType2); + LONG lstAng = m_lIndexDst-3, lswAng = m_lIndexDst-2, la = m_lIndexDst-1, lb = m_lIndexDst; + //радиус эллипса в stAng-------------------- + //(b*cos)^2 + ConvertFmla( ftCos, m_lIndexDst, ptFormula, m_lIndexDst-3, ptFormula); + ConvertFmla( ftProduct, m_lIndexDst, ptFormula, m_lIndexDst, ptFormula, 1, ptValue); + //(a*sin)^2 + ConvertFmla( ftSin, m_lIndexDst-3, ptFormula, m_lIndexDst-5, ptFormula); + ConvertFmla( ftProduct, m_lIndexDst, ptFormula, m_lIndexDst, ptFormula, 1, ptValue); + ConvertFmla( ftSum, m_lIndexDst-2, ptFormula, m_lIndexDst, ptFormula, 0, ptValue); + ConvertFmla( ftSqrt, m_lIndexDst, ptFormula); + //r + ConvertFmla( ftProduct, la, ptFormula, lb, ptFormula, m_lIndexDst, ptFormula); + + //r*cos(stAng) + ConvertFmla( ftCos, m_lIndexDst, ptFormula, lstAng, ptFormula); + //xc + ConvertFmla( ftSum, lStartX, ptFormula, 0, ptValue, m_lIndexDst, ptFormula); + //r*sin(stAng) + ConvertFmla( ftSin, m_lIndexDst-2, ptFormula, lstAng, ptFormula); + //yc + ConvertFmla( ftSum, lStartY, ptFormula, 0, ptValue, m_lIndexDst, ptFormula); + //endAng + ConvertFmla( ftSum, lstAng, ptFormula, lswAng, ptFormula, 0, ptValue); + + //радиус эллипса в endAng-------------------- + //(b*cos)^2 + ConvertFmla( ftCos, lb, ptFormula, m_lIndexDst, ptFormula); + ConvertFmla( ftProduct, m_lIndexDst, ptFormula, m_lIndexDst, ptFormula, 1, ptValue); + //(a*sin)^2 + ConvertFmla( ftSin, la, ptFormula, m_lIndexDst-2, ptFormula); + ConvertFmla( ftProduct, m_lIndexDst, ptFormula, m_lIndexDst, ptFormula, 1, ptValue); + ConvertFmla( ftSum, m_lIndexDst-2, ptFormula, m_lIndexDst, ptFormula, 0, ptValue); + ConvertFmla( ftSqrt, m_lIndexDst, ptFormula); + //r + ConvertFmla( ftProduct, la, ptFormula, lb, ptFormula, m_lIndexDst, ptFormula); + + //r*cos(endAng) + ConvertFmla( ftCos, m_lIndexDst, ptFormula, m_lIndexDst-7, ptFormula); + //xEnd + ConvertFmla( ftSum, m_lIndexDst-11, ptFormula, m_lIndexDst, ptFormula, 0, ptValue); + //r*sin(endAng) + ConvertFmla( ftSin, m_lIndexDst-2, ptFormula, m_lIndexDst-9, ptFormula); + //yEnd + ConvertFmla( ftSum, m_lIndexDst-11, ptFormula, m_lIndexDst, ptFormula, 0, ptValue ); + + std::wstring xC = L"@" + std::to_wstring( m_lIndexDst-14); + std::wstring yC = L"@" + std::to_wstring( m_lIndexDst-12); + std::wstring wR = L"@" + std::to_wstring( la); + std::wstring hR = L"@" + std::to_wstring( lb); + + //360 + ConvertFmla( ftSumangle, 0, ptValue, 360, ptValue, 0, ptValue ); + //360-stAng + ConvertFmla( ftSum, m_lIndexDst, ptFormula, 0, ptValue, lstAng, ptFormula); + //-1 + ConvertFmla( ftSum, 0, ptValue, 0, ptValue, 1, ptValue); + //-1*swAng + ConvertFmla( ftProduct, lswAng, ptFormula, m_lIndexDst, ptFormula, 1, ptValue); + + std::wstring stAng = L"@" + std::to_wstring( m_lIndexDst-2); + std::wstring swAng = L"@" + std::to_wstring( m_lIndexDst); + //std::wstring xEnd = _T(""); xEnd.Format(_T("@%d"), m_lIndexDst-5); + //std::wstring yEnd = _T(""); yEnd.Format(_T("@%d"), m_lIndexDst-4); + + pPPTShape->m_strPath += xC + yC + wR + hR + stAng + swAng; + + ConvertFmla( ftVal, m_lIndexDst - 6, ptFormula); + ConvertFmla( ftVal, m_lIndexDst - 5, ptFormula); + + } + else + { + XmlUtils::CXmlNodes ptList; + node.GetNodes(_T("pt"), ptList); + int nPtCount = ptList.GetCount(); + + for (int k=0; km_strPath += ConvertPathPoint( ptX, ptY, bNum, strGuides, mapGuides, bLastPount); + } + } + } + } + } + if (!bFill) + pPPTShape->m_strPath += _T("nf"); + if (!bStroke) + pPPTShape->m_strPath += _T("ns"); + } + pPPTShape->m_strPath += _T("e"); + } + } + } + return; + } + LONG CConverterPPTXPPT::ConvertArcParam (std::wstring strParam, NSGuidesVML::ParamType &eType) + { + LONG lVal = 0; + + std::map::iterator NumFmla = m_arMapFormula.find(strParam); + std::map::iterator NumAdj = m_arMapAdj.find(strParam); + + if (NumAdj != m_arMapAdj.end()) + { + eType = ptAdjust; + lVal = NumAdj->second; //индекс в map ??? + } + else if (NumFmla == m_arMapFormula.end()) + { + eType = ptValue; + lVal = (LONG)XmlUtils::GetInteger(strParam); + + } + else + { + eType = ptFormula; + lVal = m_arMapFormula.find(strParam)->second; + } + return lVal; + } + std::wstring CConverterPPTXPPT::ConvertPathPoint (std::wstring strX, std::wstring strY, bool &bNum, std::vector &strGuides, std::map &mapGuides, bool bLPoint) + { + std::wstring strRes = _T(""); + ParamType eType1, eType2; + LONG lParam1, lParam2; + + if (bNum) + strRes += _T(","); + lParam1 = ConvertFmlaParam(strX, eType1, strX, strGuides, mapGuides); + strRes += ConvertPathParam (lParam1, eType1, bNum); + + if (bNum) + strRes += _T(","); + + lParam2 = ConvertFmlaParam(strY, eType2, strY, strGuides, mapGuides); + strRes += ConvertPathParam (lParam2, eType2, bNum); + + if (bLPoint) + { + ConvertFmla( ftVal, lParam1, eType1); + ConvertFmla( ftVal, lParam2, eType2); + } + return strRes; + } + std::wstring CConverterPPTXPPT::ConvertPathParam (LONG lParam, ParamType eType, bool &bNum) + { + std::wstring strRes; + + if (eType == ptAdjust) + strRes = L"#"; + else if (eType == ptValue) + { + bNum = true; + } + else + strRes = L"@"; + + strRes += std::to_wstring(lParam); + + return strRes; + } +} diff --git a/MsBinaryFile/Common/Vml/PPTXShape/Pptx2PptShapeConverter.h b/MsBinaryFile/Common/Vml/PPTXShape/Pptx2PptShapeConverter.h index dd69c55b32..ad68e7992c 100644 --- a/MsBinaryFile/Common/Vml/PPTXShape/Pptx2PptShapeConverter.h +++ b/MsBinaryFile/Common/Vml/PPTXShape/Pptx2PptShapeConverter.h @@ -30,14 +30,12 @@ * */ #pragma once + #include "PptxFormula.h" -#include "../Path.h" -#include "../PPTShape/PptFormula.h" -#include "../PPTShape/PptShape.h" -#include "../PPTXShape/PptxShape.h" +#include "../PPTShape/Ppt2PptxShapeConverter.h" + namespace NSGuidesVML { - class CConverterPPTXPPT { private: @@ -58,560 +56,39 @@ namespace NSGuidesVML LONG m_lPPT2PPTX; public: - - CConverterPPTXPPT () - { - m_lPPTX2PPT = -1; - m_lPPT2PPTX = -1; - m_lIndexDst = -1; - m_lIndexAdj = -1; - pPPTShape = new CPPTShape(); - } + CConverterPPTXPPT(); inline CPPTShape* GetConvertedShape() { return pPPTShape; } - void Convert ( CPPTXShape* pPPTXShape ) - { - ConvertAdjastments ( pPPTXShape->m_arAdjustments, pPPTXShape->FManager.mapAdjustments ); - AddSizeGuides ((LONG)pPPTXShape->FManager.GetWidth(), (LONG)pPPTXShape->FManager.GetHeight()); - ConvertGuides ( pPPTXShape->FManager.strGuides, pPPTXShape->FManager.mapGuides); - ConvertPath( pPPTXShape->m_strPath, pPPTXShape->FManager.strGuides, pPPTXShape->FManager.mapGuides); + void Convert ( CPPTXShape* pPPTXShape ); + void ConvertHandles (std::vector& arHnd); + void ConvertAdjastments( std::vector &arAdj, std::map &mapAdj ); + void ConvertTextRects (std::vector &arTextRects); + void ConvertType (OOXMLShapes::ShapeType eType); - //TODO текстовые поля - //ConvertTextRects ( pPPTXShape->m_arStringTextRects ); - ConvertHandles ( pPPTXShape->m_arHandles ); + void AddSizeGuides (LONG lWidth, LONG lHeight); - //ConvertType ( pPPTXShape->m_eType ); - //------------------------------------ - int i=0; - } + LONG ConvertFmlaParam (std::wstring strParam, NSGuidesVML::ParamType &eType, std::wstring strKey, std::vector &strGuides, std::map &mapGuides); - void ConvertHandles (std::vector& arHnd) - { + void ConvertFmla ( FormulaType eFmlaType, LONG lParam1, ParamType eType1, LONG lParam2, ParamType eType2, LONG lParam3, ParamType eType3 ); - for (size_t nIndex=0; nIndexm_arHandles.push_back(oHandle); - } + void ConvertFmla ( FormulaType eFmlaType, LONG lParam1, ParamType eType1 ); - return; - } + void ConvertGuid ( NSGuidesOOXML::CFormula pFormula, std::wstring strKey, std::vector &strGuides, std::map &mapGuides); - void ConvertAdjastments( std::vector &arAdj, std::map &mapAdj ) - { - int i=0; - for( std::map::iterator pPair = mapAdj.begin(); pPair != mapAdj.end(); i++, ++pPair) - { - m_arMapAdj.insert(std::pair(pPair->first, ++m_lIndexAdj)); - pPPTShape->m_arAdjustments.push_back(arAdj[i]); - } - //это аджасменты для перевода углов tan(angle, adj) - //тк все угла в формулах считаются в pptx - //pptx->ppt - pPPTShape->m_arAdjustments.push_back(3114601); - m_lPPTX2PPT = ++m_lIndexAdj; - //ppt->pptx - pPPTShape->m_arAdjustments.push_back(2783638); - m_lPPT2PPTX = ++m_lIndexAdj; - return; - } + void ConvertGuides ( std::vector &strGuides, std::map &mapGuides ); - void ConvertTextRects (std::vector &arTextRects) - { - pPPTShape->m_arStringTextRects.insert( pPPTShape->m_arStringTextRects.end(), arTextRects.begin(), arTextRects.end()); - return; - } + void ConvertPath(const std::wstring& xml, std::vector &strGuides, std::map &mapGuides); - void ConvertType (OOXMLShapes::ShapeType eType) - { - switch (eType) - { - case OOXMLShapes::sptCRect: - pPPTShape->m_eType = PPTShapes::sptCRect; - break; - case OOXMLShapes::sptCArc: - pPPTShape->m_eType = PPTShapes::sptCRect; - break; - default: - pPPTShape->m_eType = PPTShapes::sptCustom; - } - return; - } + LONG ConvertArcParam (std::wstring strParam, NSGuidesVML::ParamType &eType); - void AddSizeGuides (LONG lWidth, LONG lHeight) - { - //TODO прокинуть w и h в формулах - NSGuidesVML::CFormula pNewFmla3; - pNewFmla3.m_eFormulaType = ftVal; - pNewFmla3.m_lIndex = ++m_lIndexDst; - pNewFmla3.m_eType1 = ptValue; - pNewFmla3.m_lParam1 = 21600;// lWidth; - pPPTShape->m_oManager.m_arFormulas.push_back(pNewFmla3); - m_arMapFormula.insert(std::pair(_T("w"), m_lIndexDst)); + std::wstring ConvertPathPoint (std::wstring strX, std::wstring strY, bool &bNum, std::vector &strGuides, std::map &mapGuides, bool bLPoint); - pNewFmla3.m_lIndex = ++m_lIndexDst; - pNewFmla3.m_eType1 = ptValue; - pNewFmla3.m_lParam1 = 21600;//lHeight; - - pPPTShape->m_oManager.m_arFormulas.push_back(pNewFmla3); - - m_arMapFormula.insert(std::pair(_T("h"), m_lIndexDst)); - - return; - } - - LONG ConvertFmlaParam (std::wstring strParam, NSGuidesVML::ParamType &eType, std::wstring strKey, std::vector &strGuides, std::map &mapGuides) - { - LONG lVal = 0; - - std::map::iterator NumFmla = m_arMapFormula.find(strParam); - std::map::iterator NumAdj = m_arMapAdj.find(strParam); - std::map::iterator NumGuides = mapGuides.find(strParam); - - if (NumAdj != m_arMapAdj.end()) - { - eType = ptAdjust; - lVal = NumAdj->second; - } - else if (NumFmla == m_arMapFormula.end()) - { - //пришло число - if (NumGuides == mapGuides.end()) - { - lVal = (LONG)XmlUtils::GetInteger(strParam); - if (lVal > 65535) - { - ConvertFmla( ftSumangle, lVal%65536, ptValue, (int)lVal/65536, ptValue, 0, ptValue); - eType = ptFormula; - lVal = m_lIndexDst; - } - else if (lVal < 0) - { - ConvertFmla( ftSum, 0, ptValue, 0, ptValue, abs(lVal), ptValue); - eType = ptFormula; - lVal = m_lIndexDst; - } - else - eType = ptValue; - } - else //пришла стандартная формула из набора, которую надо теперь добавить - { - LONG lNumGuides = NumGuides->second; - - NSGuidesOOXML::CFormula pFormula = strGuides[lNumGuides]; - - //strKey = mapGuides.GetKeyAt(lNumGuides); - int ind =0; - for (std::map::iterator p = mapGuides.begin(); p!= mapGuides.end(); ++p) - { - if (ind == lNumGuides) - { - strKey = p->first; - break; - } - } - - ConvertGuid(pFormula, strKey, strGuides, mapGuides); - eType = ptFormula; - lVal = m_lIndexDst; - } - } - else - { - eType = ptFormula; - std::map::iterator Val = m_arMapFormula.find(strParam); - lVal = Val->second; - } - return lVal; - } - - void ConvertFmla ( FormulaType eFmlaType, LONG lParam1, ParamType eType1, LONG lParam2, ParamType eType2, LONG lParam3, ParamType eType3 ) - { - NSGuidesVML::CFormula pNewFmla; - pNewFmla.m_lIndex = ++m_lIndexDst; - pNewFmla.m_eFormulaType = eFmlaType; - - pNewFmla.m_eType1 = eType1; - pNewFmla.m_lParam1 = lParam1; - - pNewFmla.m_eType2 = eType2; - pNewFmla.m_lParam2 = lParam2; - - pNewFmla.m_eType3 = eType3; - pNewFmla.m_lParam3 = lParam3; - - pPPTShape->m_oManager.m_arFormulas.push_back(pNewFmla); - return; - } - - void ConvertFmla ( FormulaType eFmlaType, LONG lParam1, ParamType eType1, LONG lParam2, ParamType eType2 ) - { - CFormula pNewFmla; - pNewFmla.m_lIndex = ++m_lIndexDst; - pNewFmla.m_eFormulaType = eFmlaType; - - pNewFmla.m_eType1 = eType1; - pNewFmla.m_lParam1 = lParam1; - - pNewFmla.m_eType2 = eType2; - pNewFmla.m_lParam2 = lParam2; - - pPPTShape->m_oManager.m_arFormulas.push_back(pNewFmla); - return; - } - - void ConvertFmla ( FormulaType eFmlaType, LONG lParam1, ParamType eType1 ) - { - CFormula pNewFmla; - pNewFmla.m_lIndex = ++m_lIndexDst; - pNewFmla.m_eFormulaType = eFmlaType; - - pNewFmla.m_eType1 = eType1; - pNewFmla.m_lParam1 = lParam1; - - pPPTShape->m_oManager.m_arFormulas.push_back(pNewFmla); - return; - } - - void ConvertGuid ( NSGuidesOOXML::CFormula pFormula, std::wstring strKey, std::vector &strGuides, std::map &mapGuides) - { - LONG lParam1, lParam2, lParam3; - NSGuidesVML::ParamType eType1, eType2, eType3; - - lParam1 = ConvertFmlaParam(pFormula.m_lParam1, eType1, strKey, strGuides, mapGuides); - lParam2 = ConvertFmlaParam(pFormula.m_lParam2, eType2, strKey, strGuides, mapGuides); - lParam3 = ConvertFmlaParam(pFormula.m_lParam3, eType3, strKey, strGuides, mapGuides); - - switch (pFormula.m_eFormulaType) - { - case NSGuidesOOXML::CFormula::ftOOXMLSum: - ConvertFmla( ftSum, lParam1, eType1, lParam2, eType2, lParam3, eType3); - break; - case NSGuidesOOXML::CFormula::ftOOXMLProduct: - ConvertFmla( ftProduct, lParam1, eType1, lParam2, eType2, lParam3, eType3); - break; - case NSGuidesOOXML::CFormula::ftOOXMLIf: - ConvertFmla( ftIf, lParam1, eType1, lParam2, eType2, lParam3, eType3); - break; - case NSGuidesOOXML::CFormula::ftOOXMLAbsolute: - ConvertFmla( ftAbsolute, lParam1, eType1); - break; - case NSGuidesOOXML::CFormula::ftOOXMLAtan2: - ConvertFmla( ftAtan2, lParam1, eType1, lParam2, eType2); - ConvertFmla( ftTan, m_lIndexDst, ptFormula, m_lPPT2PPTX, ptAdjust); - break; - case NSGuidesOOXML::CFormula::ftOOXMLCos: - ConvertFmla( ftCos, lParam1, eType1, lParam2, eType2); - ConvertFmla( ftTan, m_lIndexDst, ptFormula, m_lPPT2PPTX, ptAdjust); - break; - case NSGuidesOOXML::CFormula::ftOOXMLMax: - ConvertFmla( ftMax, lParam1, eType1, lParam2, eType2); - break; - case NSGuidesOOXML::CFormula::ftOOXMLMin: - ConvertFmla( ftMin, lParam1, eType1, lParam2, eType2); - break; - case NSGuidesOOXML::CFormula::ftOOXMLMod: - ConvertFmla( ftMod, lParam1, eType1, lParam2, eType2, lParam3, eType3); - break; - case NSGuidesOOXML::CFormula::ftOOXMLSinatan2: - ConvertFmla( ftSinatan2, lParam1, eType1, lParam2, eType2, lParam3, eType3); - ConvertFmla( ftTan, m_lIndexDst, ptFormula, m_lPPT2PPTX, ptAdjust); - break; - case NSGuidesOOXML::CFormula::ftOOXMLCosatan2: - ConvertFmla( ftCosatan2, lParam1, eType1, lParam2, eType2, lParam3, eType3); - ConvertFmla( ftTan, m_lIndexDst, ptFormula, m_lPPT2PPTX, ptAdjust); - break; - case NSGuidesOOXML::CFormula::ftOOXMLSin: - ConvertFmla( ftSin, lParam1, eType1, lParam2, eType2); - ConvertFmla( ftTan, m_lIndexDst, ptFormula, m_lPPT2PPTX, ptAdjust); - break; - case NSGuidesOOXML::CFormula::ftOOXMLSqrt: - ConvertFmla( ftSqrt, lParam1, eType1); - break; - case NSGuidesOOXML::CFormula::ftOOXMLTan: - ConvertFmla( ftTan, lParam1, eType1, lParam2, eType2); - break; - case NSGuidesOOXML::CFormula::ftOOXMLVal: - ConvertFmla( ftVal, lParam1, eType1); - break; - case NSGuidesOOXML::CFormula::ftOOXMLAddDivide: - ConvertFmla( ftSum, lParam1, eType1, lParam2, eType2, 0, ptValue); - ConvertFmla( ftProduct, m_lIndexDst, ptFormula, 1, ptValue, lParam3, eType3); - break; - case NSGuidesOOXML::CFormula::ftOOXMLPin: - ConvertFmla( ftSum, lParam1, eType1, 0, ptValue, lParam2, eType2); - ConvertFmla( ftSum, lParam2, eType2, 0, ptValue, lParam3, eType3); - ConvertFmla( ftIf, m_lIndexDst, ptFormula, lParam3, eType3, lParam2, eType2); - ConvertFmla( ftIf, m_lIndexDst-2, ptFormula, lParam1, eType1, m_lIndexDst, ptFormula); - break; - } - m_arMapFormula.insert(std::pair(strKey, m_lIndexDst)); - return; - } - - - void ConvertGuides ( std::vector &strGuides, std::map &mapGuides ) - { - //стандартные формулы для пптх будем добавлять, если только они встретятся - for (size_t nIndex=32; nIndex < strGuides.size(); ++nIndex) - { - NSGuidesOOXML::CFormula pFormula = strGuides[nIndex]; - - std::wstring strKey;// = mapGuides.GetKeyAt(nIndex); - int ind =0; - for (std::map::iterator p = mapGuides.begin(); p!= mapGuides.end(); ++p) - { - if (ind == nIndex) - { - strKey = p->first; - break; - } - } - ConvertGuid(pFormula, strKey, strGuides, mapGuides); - } - } - - void ConvertPath(const std::wstring& xml, std::vector &strGuides, std::map &mapGuides) - { - XmlUtils::CXmlNode pathLst; - if(pathLst.FromXmlString(xml)) - { - XmlUtils::CXmlNodes list; - if (pathLst.GetNodes(_T("path"), list)) - { - int nPathCount = list.GetCount(); - for (int i=0; im_strPath += _T("m"); - else if (strName == _T("lnTo")) - pPPTShape->m_strPath += _T("l"); - else if (strName == _T("arcTo")) - pPPTShape->m_strPath += _T("ae"); - else if (strName == _T("cubicBezTo")) - pPPTShape->m_strPath += _T("c"); - else if (strName == _T("quadBezTo")) - pPPTShape->m_strPath += _T("qb"); - else - pPPTShape->m_strPath += _T("x"); - - if (strName == _T("arcTo")) - { - LONG lStartX = m_lIndexDst-1, lStartY = m_lIndexDst; - LONG lParam1, lParam2, lParam3, lParam4; - NSGuidesVML::ParamType eType1, eType2, eType3, eType4; - - lParam1 = ConvertFmlaParam(node.GetAttribute(_T("wR")), eType1, node.GetAttribute(_T("wR")), strGuides, mapGuides); - lParam2 = ConvertFmlaParam(node.GetAttribute(_T("hR")), eType2, node.GetAttribute(_T("hR")), strGuides, mapGuides); - lParam3 = ConvertFmlaParam(node.GetAttribute(_T("stAng")), eType3, node.GetAttribute(_T("stAng")), strGuides, mapGuides); - lParam4 = ConvertFmlaParam(node.GetAttribute(_T("swAng")), eType4, node.GetAttribute(_T("swAng")), strGuides, mapGuides); - - //stAng - ConvertFmla( ftTan, lParam3, eType3, m_lPPTX2PPT, ptAdjust); - //swAng - ConvertFmla( ftTan, lParam4, eType4, m_lPPTX2PPT, ptAdjust); - //a - ConvertFmla( ftVal, lParam1, eType1); - //b - ConvertFmla( ftVal, lParam2, eType2); - LONG lstAng = m_lIndexDst-3, lswAng = m_lIndexDst-2, la = m_lIndexDst-1, lb = m_lIndexDst; - //радиус эллипса в stAng-------------------- - //(b*cos)^2 - ConvertFmla( ftCos, m_lIndexDst, ptFormula, m_lIndexDst-3, ptFormula); - ConvertFmla( ftProduct, m_lIndexDst, ptFormula, m_lIndexDst, ptFormula, 1, ptValue); - //(a*sin)^2 - ConvertFmla( ftSin, m_lIndexDst-3, ptFormula, m_lIndexDst-5, ptFormula); - ConvertFmla( ftProduct, m_lIndexDst, ptFormula, m_lIndexDst, ptFormula, 1, ptValue); - ConvertFmla( ftSum, m_lIndexDst-2, ptFormula, m_lIndexDst, ptFormula, 0, ptValue); - ConvertFmla( ftSqrt, m_lIndexDst, ptFormula); - //r - ConvertFmla( ftProduct, la, ptFormula, lb, ptFormula, m_lIndexDst, ptFormula); - - //r*cos(stAng) - ConvertFmla( ftCos, m_lIndexDst, ptFormula, lstAng, ptFormula); - //xc - ConvertFmla( ftSum, lStartX, ptFormula, 0, ptValue, m_lIndexDst, ptFormula); - //r*sin(stAng) - ConvertFmla( ftSin, m_lIndexDst-2, ptFormula, lstAng, ptFormula); - //yc - ConvertFmla( ftSum, lStartY, ptFormula, 0, ptValue, m_lIndexDst, ptFormula); - //endAng - ConvertFmla( ftSum, lstAng, ptFormula, lswAng, ptFormula, 0, ptValue); - - //радиус эллипса в endAng-------------------- - //(b*cos)^2 - ConvertFmla( ftCos, lb, ptFormula, m_lIndexDst, ptFormula); - ConvertFmla( ftProduct, m_lIndexDst, ptFormula, m_lIndexDst, ptFormula, 1, ptValue); - //(a*sin)^2 - ConvertFmla( ftSin, la, ptFormula, m_lIndexDst-2, ptFormula); - ConvertFmla( ftProduct, m_lIndexDst, ptFormula, m_lIndexDst, ptFormula, 1, ptValue); - ConvertFmla( ftSum, m_lIndexDst-2, ptFormula, m_lIndexDst, ptFormula, 0, ptValue); - ConvertFmla( ftSqrt, m_lIndexDst, ptFormula); - //r - ConvertFmla( ftProduct, la, ptFormula, lb, ptFormula, m_lIndexDst, ptFormula); - - //r*cos(endAng) - ConvertFmla( ftCos, m_lIndexDst, ptFormula, m_lIndexDst-7, ptFormula); - //xEnd - ConvertFmla( ftSum, m_lIndexDst-11, ptFormula, m_lIndexDst, ptFormula, 0, ptValue); - //r*sin(endAng) - ConvertFmla( ftSin, m_lIndexDst-2, ptFormula, m_lIndexDst-9, ptFormula); - //yEnd - ConvertFmla( ftSum, m_lIndexDst-11, ptFormula, m_lIndexDst, ptFormula, 0, ptValue ); - - std::wstring xC = L"@" + std::to_wstring( m_lIndexDst-14); - std::wstring yC = L"@" + std::to_wstring( m_lIndexDst-12); - std::wstring wR = L"@" + std::to_wstring( la); - std::wstring hR = L"@" + std::to_wstring( lb); - - //360 - ConvertFmla( ftSumangle, 0, ptValue, 360, ptValue, 0, ptValue ); - //360-stAng - ConvertFmla( ftSum, m_lIndexDst, ptFormula, 0, ptValue, lstAng, ptFormula); - //-1 - ConvertFmla( ftSum, 0, ptValue, 0, ptValue, 1, ptValue); - //-1*swAng - ConvertFmla( ftProduct, lswAng, ptFormula, m_lIndexDst, ptFormula, 1, ptValue); - - std::wstring stAng = L"@" + std::to_wstring( m_lIndexDst-2); - std::wstring swAng = L"@" + std::to_wstring( m_lIndexDst); - //std::wstring xEnd = _T(""); xEnd.Format(_T("@%d"), m_lIndexDst-5); - //std::wstring yEnd = _T(""); yEnd.Format(_T("@%d"), m_lIndexDst-4); - - pPPTShape->m_strPath += xC + yC + wR + hR + stAng + swAng; - - ConvertFmla( ftVal, m_lIndexDst - 6, ptFormula); - ConvertFmla( ftVal, m_lIndexDst - 5, ptFormula); - - } - else - { - XmlUtils::CXmlNodes ptList; - node.GetNodes(_T("pt"), ptList); - int nPtCount = ptList.GetCount(); - - for (int k=0; km_strPath += ConvertPathPoint( ptX, ptY, bNum, strGuides, mapGuides, bLastPount); - } - } - } - } - } - if (!bFill) - pPPTShape->m_strPath += _T("nf"); - if (!bStroke) - pPPTShape->m_strPath += _T("ns"); - } - pPPTShape->m_strPath += _T("e"); - } - } - } - return; - } - - LONG ConvertArcParam (std::wstring strParam, NSGuidesVML::ParamType &eType) - { - LONG lVal = 0; - - std::map::iterator NumFmla = m_arMapFormula.find(strParam); - std::map::iterator NumAdj = m_arMapAdj.find(strParam); - - if (NumAdj != m_arMapAdj.end()) - { - eType = ptAdjust; - lVal = NumAdj->second; //индекс в map ??? - } - else if (NumFmla == m_arMapFormula.end()) - { - eType = ptValue; - lVal = (LONG)XmlUtils::GetInteger(strParam); - - } - else - { - eType = ptFormula; - lVal = m_arMapFormula.find(strParam)->second; - } - return lVal; - } - - std::wstring ConvertPathPoint (std::wstring strX, std::wstring strY, bool &bNum, std::vector &strGuides, std::map &mapGuides, bool bLPoint) - { - std::wstring strRes = _T(""); - ParamType eType1, eType2; - LONG lParam1, lParam2; - - if (bNum) - strRes += _T(","); - lParam1 = ConvertFmlaParam(strX, eType1, strX, strGuides, mapGuides); - strRes += ConvertPathParam (lParam1, eType1, bNum); - - if (bNum) - strRes += _T(","); - - lParam2 = ConvertFmlaParam(strY, eType2, strY, strGuides, mapGuides); - strRes += ConvertPathParam (lParam2, eType2, bNum); - - if (bLPoint) - { - ConvertFmla( ftVal, lParam1, eType1); - ConvertFmla( ftVal, lParam2, eType2); - } - return strRes; - } - - std::wstring ConvertPathParam (LONG lParam, ParamType eType, bool &bNum) - { - std::wstring strRes; - - if (eType == ptAdjust) - strRes = L"#"; - else if (eType == ptValue) - { - bNum = true; - } - else - strRes = L"@"; - - strRes += std::to_wstring(lParam); - - return strRes; - } + std::wstring ConvertPathParam (LONG lParam, ParamType eType, bool &bNum); }; } diff --git a/MsBinaryFile/Common/Vml/PPTXShape/PptxFormula.cpp b/MsBinaryFile/Common/Vml/PPTXShape/PptxFormula.cpp index 2c5dc37db2..bdb5cc3799 100644 --- a/MsBinaryFile/Common/Vml/PPTXShape/PptxFormula.cpp +++ b/MsBinaryFile/Common/Vml/PPTXShape/PptxFormula.cpp @@ -40,60 +40,331 @@ #define max(a,b) (((a)>(b))?(a):(b)) #endif -double NSGuidesOOXML::CFormula::Calculate(NSGuidesOOXML::CFormulaManager* pManager) +namespace NSGuidesOOXML { - if ((0 == m_lIndex) || (-m_lIndex > (int)pManager->Guides->size()) || (m_lIndex > (int)pManager->Adjustments->size())) - return 0.0; - if((m_lIndex < 0) && (dNonDefResult > (*pManager->Guides)[-m_lIndex-1])) - return (*pManager->Guides)[-m_lIndex-1]; - if((m_lIndex > 0) && (NonDefResult != (*pManager->Adjustments)[m_lIndex-1])) - return (*pManager->Adjustments)[m_lIndex-1]; - - double a = pManager->GetValue(m_lParam1); - double b = pManager->GetValue(m_lParam2); - double c = pManager->GetValue(m_lParam3); - //double c = (double)c1; - - double dRes = 0.0; - - try + CFormula::FormulaType CFormula::GetFormula(std::wstring strName, bool& bRes) { - // теперь нужно просто посчитать - switch (m_eFormulaType) + bRes = true; + if (_T("+-") == strName) return ftOOXMLSum; + else if (_T("*/") == strName) return ftOOXMLProduct; + else if (_T("+/") == strName) return ftOOXMLAddDivide; + else if (_T("abs") == strName) return ftOOXMLAbsolute; + else if (_T("min") == strName) return ftOOXMLMin; + else if (_T("max") == strName) return ftOOXMLMax; + else if (_T("?:") == strName) return ftOOXMLIf; + else if (_T("sqrt") == strName) return ftOOXMLSqrt; + else if (_T("mod") == strName) return ftOOXMLMod; + else if (_T("sin") == strName) return ftOOXMLSin; + else if (_T("cos") == strName) return ftOOXMLCos; + else if (_T("tan") == strName) return ftOOXMLTan; + else if (_T("at2") == strName) return ftOOXMLAtan2; + else if (_T("sat2") == strName) return ftOOXMLSinatan2; + else if (_T("cat2") == strName) return ftOOXMLCosatan2; + else if (_T("pin") == strName) return ftOOXMLPin; + else if (_T("val") == strName) return ftOOXMLVal; + else bRes = false; + + return ftOOXMLVal; + } + + CFormula::CFormula(long ind) + { + m_sName = _T(""); + m_eFormulaType = ftOOXMLSum; + m_lIndex = ind; + m_lParam1 = _T("0"); + m_lParam2 = _T("0"); + m_lParam3 = _T("0"); + } + CFormula& CFormula::operator =(const CFormula& src) + { + m_sName = src.m_sName; + m_eFormulaType = src.m_eFormulaType; + m_lIndex = src.m_lIndex; + m_lParam1 = src.m_lParam1; + m_lParam2 = src.m_lParam2; + m_lParam3 = src.m_lParam3; + + return *this; + } + void CFormula::FromString(std::wstring strFormula) + { + std::vector oArrayParams; + + boost::algorithm::split(oArrayParams, strFormula, boost::algorithm::is_any_of(L" "), boost::algorithm::token_compress_on); + + int nCount = (int)oArrayParams.size(); + if (0 >= nCount) + return; + + bool bRes = true; + m_eFormulaType = GetFormula(oArrayParams[0], bRes); + + // ParamType ptType = ptValue; + if (1 < nCount) + m_lParam1 = oArrayParams[1]; + if (2 < nCount) + m_lParam2 = oArrayParams[2]; + if (3 < nCount) + m_lParam3 = oArrayParams[3]; + } + double CFormula::Calculate(NSGuidesOOXML::CFormulaManager* pManager) + { + if ((0 == m_lIndex) || (-m_lIndex > (int)pManager->Guides->size()) || (m_lIndex > (int)pManager->Adjustments->size())) + return 0.0; + if((m_lIndex < 0) && (dNonDefResult > (*pManager->Guides)[-m_lIndex-1])) + return (*pManager->Guides)[-m_lIndex-1]; + if((m_lIndex > 0) && (NonDefResult != (*pManager->Adjustments)[m_lIndex-1])) + return (*pManager->Adjustments)[m_lIndex-1]; + + double a = pManager->GetValue(m_lParam1); + double b = pManager->GetValue(m_lParam2); + double c = pManager->GetValue(m_lParam3); + //double c = (double)c1; + + double dRes = 0.0; + + try { - case ftOOXMLSum: { dRes = a + b - c; break; } - case ftOOXMLProduct: {/*if(0==c1)c=1.0;*/ dRes = (a * b)/c; break; } - case ftOOXMLAddDivide: {/*if(0==c1)c=1.0;*/ dRes = (a + b)/c; break; } - case ftOOXMLAbsolute: { dRes = abs(a); break; } - case ftOOXMLMin: { dRes = min(a, b); break; } - case ftOOXMLMax: { dRes = max(a, b); break; } - case ftOOXMLIf: { dRes = (a > 0) ? b : c; break; } - case ftOOXMLSqrt: { dRes = sqrt(a); break; } - case ftOOXMLMod: { dRes = sqrt(a*a + b*b + c*c); break; } - case ftOOXMLSin: { dRes = a * sin(b * RadKoef); break; } - case ftOOXMLCos: { dRes = a * cos(b * RadKoef); break; } - case ftOOXMLTan: { dRes = a * tan(b * RadKoef); break; } - case ftOOXMLAtan2: { dRes = atan2(b,a)/RadKoef; break; } - case ftOOXMLSinatan2: { dRes = a * sin(atan2(c,b)); break; } - case ftOOXMLCosatan2: { dRes = a * cos(atan2(c,b)); break; } - case ftOOXMLPin: { dRes = (b < a) ? a :((b > c) ? c : b);break; } - case ftOOXMLVal: { dRes = a; break; } - default: break; - }; - } - catch (...) - { - dRes = 0.0; + // теперь нужно просто посчитать + switch (m_eFormulaType) + { + case ftOOXMLSum: { dRes = a + b - c; break; } + case ftOOXMLProduct: {/*if(0==c1)c=1.0;*/ dRes = (a * b)/c; break; } + case ftOOXMLAddDivide: {/*if(0==c1)c=1.0;*/ dRes = (a + b)/c; break; } + case ftOOXMLAbsolute: { dRes = abs(a); break; } + case ftOOXMLMin: { dRes = min(a, b); break; } + case ftOOXMLMax: { dRes = max(a, b); break; } + case ftOOXMLIf: { dRes = (a > 0) ? b : c; break; } + case ftOOXMLSqrt: { dRes = sqrt(a); break; } + case ftOOXMLMod: { dRes = sqrt(a*a + b*b + c*c); break; } + case ftOOXMLSin: { dRes = a * sin(b * RadKoef); break; } + case ftOOXMLCos: { dRes = a * cos(b * RadKoef); break; } + case ftOOXMLTan: { dRes = a * tan(b * RadKoef); break; } + case ftOOXMLAtan2: { dRes = atan2(b,a)/RadKoef; break; } + case ftOOXMLSinatan2: { dRes = a * sin(atan2(c,b)); break; } + case ftOOXMLCosatan2: { dRes = a * cos(atan2(c,b)); break; } + case ftOOXMLPin: { dRes = (b < a) ? a :((b > c) ? c : b);break; } + case ftOOXMLVal: { dRes = a; break; } + default: break; + }; + } + catch (...) + { + dRes = 0.0; + } + + //long lResult = (long)dRes; + if(m_lIndex < 0) + { + (*pManager->Guides)[-m_lIndex-1] = dRes; + // переопределим формулу + pManager->mapGuides.insert(std::pair(m_sName, -m_lIndex-1)); + } + else + (*pManager->Adjustments)[m_lIndex-1] = (long)dRes; + return dRes; } - //long lResult = (long)dRes; - if(m_lIndex < 0) + void CFormulaManager::SetWidthHeight(double w, double h) { - (*pManager->Guides)[-m_lIndex-1] = dRes; - // переопределим формулу - pManager->mapGuides.insert(std::pair(m_sName, -m_lIndex-1)); + if((w >= 0) && (h >= 0)) + { + Clear(); + if(w > h) + { + h = (h * ShapeSize)/w; + if(h < 1.0) h = 1.0; + w = ShapeSize; + } + else if(w < h) + { + w = (w * ShapeSize)/h; + if(w < 1.0) w = 1.0; + h = ShapeSize; + } + else + { + w = ShapeSize; + h = ShapeSize; + } + m_lShapeWidth = w; + m_lShapeHeight = h; + } + } + CFormulaManager::CFormulaManager(std::vector& a, std::vector& g) + { + Adjustments = &a; + Guides = &g; + + m_lShapeWidth = ShapeSize; + m_lShapeHeight = ShapeSize; + + AddGuide(_T("3cd4"), _T("val 16200000")); //The units here are in 60,000ths of a degree. This is equivalent to 270 degrees. + AddGuide(_T("3cd8"), _T("val 8100000")); //The units here are in 60,000ths of a degree. This is equivalent to 135 degrees. + AddGuide(_T("5cd8"), _T("val 13500000")); //The units here are in 60,000ths of a degree. This is equivalent to 225 degrees. + AddGuide(_T("7cd8"), _T("val 18900000")); //The units here are in 60,000ths of a degree. This is equivalent to 315 degrees. + AddGuide(_T("b"), _T("val h")); //This is the bottom edge of the shape and since the top edge of the shape is considered the 0 point, the + //bottom edge is thus the shape height. + AddGuide(_T("cd2"), _T("val 10800000")); //The units here are in 60,000ths of a degree. This is equivalent to 180 degrees. + AddGuide(_T("cd4"), _T("val 5400000")); //The units here are in 60,000ths of a degree. This is equivalent to 90 degrees. + AddGuide(_T("cd8"), _T("val 2700000")); //The units here are in 60,000ths of a degree. This is equivalent to 45 degrees. + AddGuide(_T("hc"), _T("*/ w 1 2")); //This is the horizontal center of the shape which is just the width divided by 2. + AddGuide(_T("hd2"), _T("*/ h 1 2")); //This is 1/2 the shape height. + AddGuide(_T("hd3"), _T("*/ h 1 3")); //This is 1/3 the shape height. + AddGuide(_T("hd4"), _T("*/ h 1 4")); //This is 1/4 the shape height. + AddGuide(_T("hd5"), _T("*/ h 1 5")); //This is 1/5 the shape height. + AddGuide(_T("hd6"), _T("*/ h 1 6")); //This is 1/6 the shape height. + AddGuide(_T("hd8"), _T("*/ h 1 8")); //This is 1/8 the shape height. + AddGuide(_T("l"), _T("val 0")); //This is the left edge of the shape and the left edge of the shape is considered the horizontal 0 point. + AddGuide(_T("ls"), _T("max w h")); //This is the longest side of the shape. This value is either the width or the height depending on which is greater. + AddGuide(_T("r"), _T("val w")); //This is the right edge of the shape and since the left edge of the shape is considered the 0 point, the right edge + //is thus the shape width. + AddGuide(_T("ss"), _T("min w h")); //This is the shortest side of the shape. This value is either the width or the height depending on which is + //smaller. + AddGuide(_T("ssd2"), _T("*/ ss 1 2")); //This is 1/2 the shortest side of the shape. + AddGuide(_T("ssd4"), _T("*/ ss 1 4")); //This is 1/4 the shortest side of the shape. + AddGuide(_T("ssd6"), _T("*/ ss 1 6")); //This is 1/6 the shortest side of the shape. + AddGuide(_T("ssd8"), _T("*/ ss 1 8")); //This is 1/8 the shortest side of the shape. + AddGuide(_T("t"), _T("val 0")); //This is the top edge of the shape and the top edge of the shape is considered the vertical 0 point. + AddGuide(_T("vc"), _T("*/ h 1 2")); //This is the vertical center of the shape which is just the height divided by 2. + AddGuide(_T("wd2"), _T("*/ w 1 2")); //This is 1/2 the shape width. + AddGuide(_T("wd4"), _T("*/ w 1 4")); //This is 1/4 the shape width. + AddGuide(_T("wd5"), _T("*/ w 1 5")); //This is 1/5 the shape width. + AddGuide(_T("wd6"), _T("*/ w 1 6")); //This is 1/6 the shape width. + AddGuide(_T("wd8"), _T("*/ w 1 8")); //This is 1/8 the shape width. + AddGuide(_T("wd10"), _T("*/ w 1 10")); //This is 1/10 the shape width. + AddGuide(_T("wd32"), _T("*/ w 1 32")); //This is 1/32 the shape width. + } + CFormulaManager::~CFormulaManager() + { + mapAdjustments.clear(); + mapGuides.clear(); + strAdjustments.clear(); + strGuides.clear(); + Adjustments->clear(); + Guides->clear(); + } + CFormulaManager& CFormulaManager::operator =(const CFormulaManager& manager) + { + m_lShapeWidth = manager.m_lShapeWidth; + m_lShapeHeight = manager.m_lShapeWidth; + + mapAdjustments.clear(); + for (std::map::const_iterator pPair = manager.mapAdjustments.begin(); pPair != manager.mapAdjustments.end(); ++pPair) + { + mapAdjustments.insert(std::pair(pPair->first, pPair->second)); + } + + mapGuides.clear(); + for (std::map::const_iterator pPair = manager.mapGuides.begin(); pPair != manager.mapGuides.end(); ++pPair) + { + mapGuides.insert(std::pair(pPair->first, pPair->second)); + } + + strAdjustments.clear(); + for(size_t i = 0; i < manager.strAdjustments.size(); i++) + { + strAdjustments.push_back(manager.strAdjustments[i]); + } + + strGuides.clear(); + for(size_t i = 0; i < manager.strGuides.size(); i++) + { + strGuides.push_back(manager.strGuides[i]); + } + + Adjustments->clear(); + for(size_t i = 0; i < manager.Adjustments->size(); i++) + { + Adjustments->push_back((*manager.Adjustments)[i]); + } + + Guides->clear(); + for(size_t i = 0; i < manager.Guides->size(); i++) + { + Guides->push_back((*manager.Guides)[i]); + } + + return *this; + } + void CFormulaManager::AddAdjustment(const std::wstring& name, const std::wstring& fmla) + { + std::map::const_iterator pPair = mapAdjustments.find(name); + + if(pPair != mapAdjustments.end()) + { + strAdjustments[pPair->second].FromString(fmla); + (*Adjustments)[pPair->second] = NonDefResult; + + return; + } + CFormula formula( (int)strAdjustments.size() + 1); + formula.m_sName = name; + formula.FromString(fmla); + + strAdjustments.push_back(formula); + Adjustments->push_back(NonDefResult); + + mapAdjustments.insert(std::pair(name, (long)strAdjustments.size() - 1)); + } + void CFormulaManager::AddGuide(const std::wstring& name, const std::wstring& fmla) + { + /* + long num = mapGuides.FindKey(name); + if(num >= 0) + { + strGuides[mapGuides.GetValueAt(num)].FromString(fmla); + (*Guides)[mapGuides.GetValueAt(num)] = dNonDefResult; + return; + } + */ + // формулы могут повторяться!!! + // тогда по мере расчитывания они перетирают друг друга + CFormula formula( -1 -(int)strGuides.size()); + formula.m_sName = name; + formula.FromString(fmla); + + strGuides.push_back(formula); + Guides->push_back(dNonDefResult); + + mapGuides.insert(std::pair(name, (long)strGuides.size() - 1)); + } + double CFormulaManager::GetValue(std::wstring str) + { + if(str == _T("w")) return m_lShapeWidth; + if(str == _T("h")) return m_lShapeHeight; + + std::map::iterator numGuide = mapGuides.find(str); + std::map::iterator numAdj = mapAdjustments.find(str); + + if(numGuide != mapGuides.end()) + { + double res = (*Guides)[numGuide->second]; + if(res < dNonDefResult) + return res; + return strGuides[numGuide->second].Calculate(this); + } + if(numAdj != mapAdjustments.end()) + { + long res = (*Adjustments)[numAdj->second]; + if(res != NonDefResult) + return res; + return strAdjustments[numAdj->second].Calculate(this); + } + return XmlUtils::GetInteger(str); + } + void CFormulaManager::Clear() + { + //for(long i = 0; i < Adjustments.size(); i++) + // Adjustments[i] = NonDefResult; + for(size_t i = 0; i < Guides->size(); i++) + (*Guides)[i] = dNonDefResult; + } + void CFormulaManager::ReCalculateGuides() + { + Clear(); + for(size_t i = 0; i < strGuides.size(); i++) + (*Guides)[i] = strGuides[i].Calculate(this); } - else - (*pManager->Adjustments)[m_lIndex-1] = (long)dRes; - return dRes; } diff --git a/MsBinaryFile/Common/Vml/PPTXShape/PptxFormula.h b/MsBinaryFile/Common/Vml/PPTXShape/PptxFormula.h index db2a9e0100..bbb094f669 100644 --- a/MsBinaryFile/Common/Vml/PPTXShape/PptxFormula.h +++ b/MsBinaryFile/Common/Vml/PPTXShape/PptxFormula.h @@ -72,30 +72,7 @@ namespace NSGuidesOOXML ftOOXMLVal = 16 // a }; - static FormulaType GetFormula(std::wstring strName, bool& bRes) - { - bRes = true; - if (_T("+-") == strName) return ftOOXMLSum; - else if (_T("*/") == strName) return ftOOXMLProduct; - else if (_T("+/") == strName) return ftOOXMLAddDivide; - else if (_T("abs") == strName) return ftOOXMLAbsolute; - else if (_T("min") == strName) return ftOOXMLMin; - else if (_T("max") == strName) return ftOOXMLMax; - else if (_T("?:") == strName) return ftOOXMLIf; - else if (_T("sqrt") == strName) return ftOOXMLSqrt; - else if (_T("mod") == strName) return ftOOXMLMod; - else if (_T("sin") == strName) return ftOOXMLSin; - else if (_T("cos") == strName) return ftOOXMLCos; - else if (_T("tan") == strName) return ftOOXMLTan; - else if (_T("at2") == strName) return ftOOXMLAtan2; - else if (_T("sat2") == strName) return ftOOXMLSinatan2; - else if (_T("cat2") == strName) return ftOOXMLCosatan2; - else if (_T("pin") == strName) return ftOOXMLPin; - else if (_T("val") == strName) return ftOOXMLVal; - else bRes = false; - - return ftOOXMLVal; - } + static FormulaType GetFormula(std::wstring strName, bool& bRes); public: FormulaType m_eFormulaType; @@ -105,55 +82,16 @@ namespace NSGuidesOOXML std::wstring m_lParam1; std::wstring m_lParam2; std::wstring m_lParam3; + public: - CFormula(long ind = 0) - { - m_sName = _T(""); - m_eFormulaType = ftOOXMLSum; - m_lIndex = ind; - m_lParam1 = _T("0"); - m_lParam2 = _T("0"); - m_lParam3 = _T("0"); - } - - CFormula& operator =(const CFormula& src) - { - m_sName = src.m_sName; - m_eFormulaType = src.m_eFormulaType; - m_lIndex = src.m_lIndex; - m_lParam1 = src.m_lParam1; - m_lParam2 = src.m_lParam2; - m_lParam3 = src.m_lParam3; - - return *this; - } - - void FromString(std::wstring strFormula) - { - std::vector oArrayParams; - - boost::algorithm::split(oArrayParams, strFormula, boost::algorithm::is_any_of(L" "), boost::algorithm::token_compress_on); - - int nCount = (int)oArrayParams.size(); - if (0 >= nCount) - return; - - bool bRes = true; - m_eFormulaType = GetFormula(oArrayParams[0], bRes); - - // ParamType ptType = ptValue; - if (1 < nCount) - m_lParam1 = oArrayParams[1]; - if (2 < nCount) - m_lParam2 = oArrayParams[2]; - if (3 < nCount) - m_lParam3 = oArrayParams[3]; - } + CFormula(long ind = 0); + CFormula& operator =(const CFormula& src); + void FromString(std::wstring strFormula); double Calculate(CFormulaManager* pManager); }; - class CFormulaManager +class CFormulaManager { private: double m_lShapeWidth; @@ -166,32 +104,8 @@ public: std::vector* Adjustments; std::vector* Guides; - void SetWidthHeight(double w, double h) - { - if((w >= 0) && (h >= 0)) - { - Clear(); - if(w > h) - { - h = (h * ShapeSize)/w; - if(h < 1.0) h = 1.0; - w = ShapeSize; - } - else if(w < h) - { - w = (w * ShapeSize)/h; - if(w < 1.0) w = 1.0; - h = ShapeSize; - } - else - { - w = ShapeSize; - h = ShapeSize; - } - m_lShapeWidth = w; - m_lShapeHeight = h; - } - } + void SetWidthHeight(double w, double h); + inline double GetWidth() { return m_lShapeWidth; @@ -202,187 +116,16 @@ public: } public: - CFormulaManager(std::vector& a, std::vector& g) - { - Adjustments = &a; - Guides = &g; - - m_lShapeWidth = ShapeSize; - m_lShapeHeight = ShapeSize; - - AddGuide(_T("3cd4"), _T("val 16200000")); //The units here are in 60,000ths of a degree. This is equivalent to 270 degrees. - AddGuide(_T("3cd8"), _T("val 8100000")); //The units here are in 60,000ths of a degree. This is equivalent to 135 degrees. - AddGuide(_T("5cd8"), _T("val 13500000")); //The units here are in 60,000ths of a degree. This is equivalent to 225 degrees. - AddGuide(_T("7cd8"), _T("val 18900000")); //The units here are in 60,000ths of a degree. This is equivalent to 315 degrees. - AddGuide(_T("b"), _T("val h")); //This is the bottom edge of the shape and since the top edge of the shape is considered the 0 point, the - //bottom edge is thus the shape height. - AddGuide(_T("cd2"), _T("val 10800000")); //The units here are in 60,000ths of a degree. This is equivalent to 180 degrees. - AddGuide(_T("cd4"), _T("val 5400000")); //The units here are in 60,000ths of a degree. This is equivalent to 90 degrees. - AddGuide(_T("cd8"), _T("val 2700000")); //The units here are in 60,000ths of a degree. This is equivalent to 45 degrees. - AddGuide(_T("hc"), _T("*/ w 1 2")); //This is the horizontal center of the shape which is just the width divided by 2. - AddGuide(_T("hd2"), _T("*/ h 1 2")); //This is 1/2 the shape height. - AddGuide(_T("hd3"), _T("*/ h 1 3")); //This is 1/3 the shape height. - AddGuide(_T("hd4"), _T("*/ h 1 4")); //This is 1/4 the shape height. - AddGuide(_T("hd5"), _T("*/ h 1 5")); //This is 1/5 the shape height. - AddGuide(_T("hd6"), _T("*/ h 1 6")); //This is 1/6 the shape height. - AddGuide(_T("hd8"), _T("*/ h 1 8")); //This is 1/8 the shape height. - AddGuide(_T("l"), _T("val 0")); //This is the left edge of the shape and the left edge of the shape is considered the horizontal 0 point. - AddGuide(_T("ls"), _T("max w h")); //This is the longest side of the shape. This value is either the width or the height depending on which is greater. - AddGuide(_T("r"), _T("val w")); //This is the right edge of the shape and since the left edge of the shape is considered the 0 point, the right edge - //is thus the shape width. - AddGuide(_T("ss"), _T("min w h")); //This is the shortest side of the shape. This value is either the width or the height depending on which is - //smaller. - AddGuide(_T("ssd2"), _T("*/ ss 1 2")); //This is 1/2 the shortest side of the shape. - AddGuide(_T("ssd4"), _T("*/ ss 1 4")); //This is 1/4 the shortest side of the shape. - AddGuide(_T("ssd6"), _T("*/ ss 1 6")); //This is 1/6 the shortest side of the shape. - AddGuide(_T("ssd8"), _T("*/ ss 1 8")); //This is 1/8 the shortest side of the shape. - AddGuide(_T("t"), _T("val 0")); //This is the top edge of the shape and the top edge of the shape is considered the vertical 0 point. - AddGuide(_T("vc"), _T("*/ h 1 2")); //This is the vertical center of the shape which is just the height divided by 2. - AddGuide(_T("wd2"), _T("*/ w 1 2")); //This is 1/2 the shape width. - AddGuide(_T("wd4"), _T("*/ w 1 4")); //This is 1/4 the shape width. - AddGuide(_T("wd5"), _T("*/ w 1 5")); //This is 1/5 the shape width. - AddGuide(_T("wd6"), _T("*/ w 1 6")); //This is 1/6 the shape width. - AddGuide(_T("wd8"), _T("*/ w 1 8")); //This is 1/8 the shape width. - AddGuide(_T("wd10"), _T("*/ w 1 10")); //This is 1/10 the shape width. - AddGuide(_T("wd32"), _T("*/ w 1 32")); //This is 1/32 the shape width. - } + CFormulaManager(std::vector& a, std::vector& g); + ~CFormulaManager(); - ~CFormulaManager() - { - mapAdjustments.clear(); - mapGuides.clear(); - strAdjustments.clear(); - strGuides.clear(); - Adjustments->clear(); - Guides->clear(); - } + CFormulaManager& operator =(const CFormulaManager& manager); - CFormulaManager& operator =(const CFormulaManager& manager) - { - m_lShapeWidth = manager.m_lShapeWidth; - m_lShapeHeight = manager.m_lShapeWidth; - - mapAdjustments.clear(); - for (std::map::const_iterator pPair = manager.mapAdjustments.begin(); pPair != manager.mapAdjustments.end(); ++pPair) - { - mapAdjustments.insert(std::pair(pPair->first, pPair->second)); - } + void AddAdjustment(const std::wstring& name, const std::wstring& fmla); + void AddGuide(const std::wstring& name, const std::wstring& fmla); - mapGuides.clear(); - for (std::map::const_iterator pPair = manager.mapGuides.begin(); pPair != manager.mapGuides.end(); ++pPair) - { - mapGuides.insert(std::pair(pPair->first, pPair->second)); - } - - strAdjustments.clear(); - for(size_t i = 0; i < manager.strAdjustments.size(); i++) - { - strAdjustments.push_back(manager.strAdjustments[i]); - } - - strGuides.clear(); - for(size_t i = 0; i < manager.strGuides.size(); i++) - { - strGuides.push_back(manager.strGuides[i]); - } - - Adjustments->clear(); - for(size_t i = 0; i < manager.Adjustments->size(); i++) - { - Adjustments->push_back((*manager.Adjustments)[i]); - } - - Guides->clear(); - for(size_t i = 0; i < manager.Guides->size(); i++) - { - Guides->push_back((*manager.Guides)[i]); - } - - return *this; - } - - void AddAdjustment(const std::wstring& name, const std::wstring& fmla) - { - std::map::const_iterator pPair = mapAdjustments.find(name); - - if(pPair != mapAdjustments.end()) - { - strAdjustments[pPair->second].FromString(fmla); - (*Adjustments)[pPair->second] = NonDefResult; - - return; - } - CFormula formula( (int)strAdjustments.size() + 1); - formula.m_sName = name; - formula.FromString(fmla); - - strAdjustments.push_back(formula); - Adjustments->push_back(NonDefResult); - - mapAdjustments.insert(std::pair(name, (long)strAdjustments.size() - 1)); - } - - void AddGuide(const std::wstring& name, const std::wstring& fmla) - { - /* - long num = mapGuides.FindKey(name); - if(num >= 0) - { - strGuides[mapGuides.GetValueAt(num)].FromString(fmla); - (*Guides)[mapGuides.GetValueAt(num)] = dNonDefResult; - return; - } - */ - // формулы могут повторяться!!! - // тогда по мере расчитывания они перетирают друг друга - CFormula formula( -1 -(int)strGuides.size()); - formula.m_sName = name; - formula.FromString(fmla); - - strGuides.push_back(formula); - Guides->push_back(dNonDefResult); - - mapGuides.insert(std::pair(name, (long)strGuides.size() - 1)); - } - - double GetValue(std::wstring str) - { - if(str == _T("w")) return m_lShapeWidth; - if(str == _T("h")) return m_lShapeHeight; - - std::map::iterator numGuide = mapGuides.find(str); - std::map::iterator numAdj = mapAdjustments.find(str); - - if(numGuide != mapGuides.end()) - { - double res = (*Guides)[numGuide->second]; - if(res < dNonDefResult) - return res; - return strGuides[numGuide->second].Calculate(this); - } - if(numAdj != mapAdjustments.end()) - { - long res = (*Adjustments)[numAdj->second]; - if(res != NonDefResult) - return res; - return strAdjustments[numAdj->second].Calculate(this); - } - return XmlUtils::GetInteger(str); - } - - void Clear() - { - //for(long i = 0; i < Adjustments.size(); i++) - // Adjustments[i] = NonDefResult; - for(size_t i = 0; i < Guides->size(); i++) - (*Guides)[i] = dNonDefResult; - } - - void ReCalculateGuides() - { - Clear(); - for(size_t i = 0; i < strGuides.size(); i++) - (*Guides)[i] = strGuides[i].Calculate(this); - } + double GetValue(std::wstring str); + void Clear(); + void ReCalculateGuides(); }; } diff --git a/MsBinaryFile/PptFile/Drawing/Elements.cpp b/MsBinaryFile/PptFile/Drawing/Elements.cpp index a5923d45fb..dc1749fcf5 100644 --- a/MsBinaryFile/PptFile/Drawing/Elements.cpp +++ b/MsBinaryFile/PptFile/Drawing/Elements.cpp @@ -276,8 +276,6 @@ namespace PPT return ConvertPPTtoPPTX(/*pPPTShape,*/ pParamCoef, bIsNamespace); } - - std::wstring CImageElement::ConvertPPTtoPPTX(/*CPPTShape* pPPTShape, */const NSGuidesVML::CFormParam& pCoef, bool bIsNamespace) { if (bIsNamespace) @@ -316,7 +314,6 @@ namespace PPT m_pShape = CShapePtr(new CShape(NSBaseShape::unknown, 0x1000)); } - CShapeElement::CShapeElement(const std::wstring& str) : CElement() { m_lShapeType = 0x1000; @@ -327,22 +324,21 @@ namespace PPT m_ClassType = m_pShape->getBaseShape()->GetClassType(); } - //virtual void NormalizeCoordsByMetric() - //{ - // CElement::NormalizeCoordsByMetric(); + //virtual void NormalizeCoordsByMetric() + //{ + // CElement::NormalizeCoordsByMetric(); - // double dScaleX = (double)m_oMetric.m_lUnitsHor / m_oMetric.m_lMillimetresHor; - // double dScaleY = (double)m_oMetric.m_lUnitsVer / m_oMetric.m_lMillimetresVer; + // double dScaleX = (double)m_oMetric.m_lUnitsHor / m_oMetric.m_lMillimetresHor; + // double dScaleY = (double)m_oMetric.m_lUnitsVer / m_oMetric.m_lMillimetresVer; - // m_pShape->m_oText.m_oBounds.left = (int)(dScaleX * m_pShape->m_oText.m_oBounds.left); - // m_pShape->m_oText.m_oBounds.right = (int)(dScaleX * m_pShape->m_oText.m_oBounds.right); - // m_pShape->m_oText.m_oBounds.top = (int)(dScaleY * m_pShape->m_oText.m_oBounds.top); - // m_pShape->m_oText.m_oBounds.bottom = (int)(dScaleY * m_pShape->m_oText.m_oBounds.bottom); - //} + // m_pShape->m_oText.m_oBounds.left = (int)(dScaleX * m_pShape->m_oText.m_oBounds.left); + // m_pShape->m_oText.m_oBounds.right = (int)(dScaleX * m_pShape->m_oText.m_oBounds.right); + // m_pShape->m_oText.m_oBounds.top = (int)(dScaleY * m_pShape->m_oText.m_oBounds.top); + // m_pShape->m_oText.m_oBounds.bottom = (int)(dScaleY * m_pShape->m_oText.m_oBounds.bottom); + //} CShapeElement::~CShapeElement() { } - CElementPtr CShapeElement::CreateDublicate() { CShapeElement* pShapeElement = new CShapeElement(m_ClassType, m_lShapeType); @@ -358,7 +354,6 @@ namespace PPT return pElement; } - void CShapeElement::SetupProperties(CSlide* pSlide, CTheme* pTheme, CLayout* pLayout) { m_pShape->m_oText.m_lPlaceholderType = m_lPlaceholderType; @@ -388,7 +383,6 @@ namespace PPT return ConvertPPTtoPPTX(pPPTShape, pParamCoef, bIsNamespace); } - std::wstring CShapeElement::ConvertPPTtoPPTX(CPPTShape* pPPTShape, const NSGuidesVML::CFormParam& pCoef, bool bIsNamespace) { if (pPPTShape->m_eType == PPTShapes::sptCRect || pPPTShape->m_eType == PPTShapes::sptCFrame || pPPTShape->m_eType == PPTShapes::sptCTextBox) @@ -510,11 +504,9 @@ namespace PPT m_dClipStartTime = 0.0; m_dClipEndTime = -1.0; } - CAudioElement::~CAudioElement() { } - CElementPtr CAudioElement::CreateDublicate() { CAudioElement* pAudioElement = new CAudioElement(); @@ -546,11 +538,9 @@ namespace PPT m_dClipEndTime = -1.0; m_bLoop = false; } - CVideoElement::~CVideoElement() { } - CElementPtr CVideoElement::CreateDublicate() { CVideoElement* pVideoElement = new CVideoElement(); diff --git a/MsBinaryFile/Projects/XlsFormatLib/Linux/XlsFormatLib.pro b/MsBinaryFile/Projects/XlsFormatLib/Linux/XlsFormatLib.pro index f930799fb6..24d82efd75 100644 --- a/MsBinaryFile/Projects/XlsFormatLib/Linux/XlsFormatLib.pro +++ b/MsBinaryFile/Projects/XlsFormatLib/Linux/XlsFormatLib.pro @@ -828,7 +828,12 @@ SOURCES += \ ../../../XlsFile/Format/Logging/Logger.cpp \ ../../../Common/ODraw/FormulaShape.cpp \ ../../../Common/ODraw/CustomShape.cpp \ - ../../../Common/ODraw/BaseShape_1.cpp \ + ../../../Common/ODraw/BaseShape.cpp \ + ../../../Common/ODraw/CustomGeomShape.cpp \ + ../../../Common/ODraw/CustomShapeConvert.cpp \ + ../../../Common/ODraw/GraphicsPath.cpp \ + ../../../Common/ODraw/PathShape.cpp \ + ../../../Common/ODraw/XmlWriter.cpp \ ../../../XlsFile/Converter/ConvertXls2Xlsx.cpp \ ../../../XlsFile/Converter/external_items.cpp \ ../../../XlsFile/Converter/mediaitems_utils.cpp \ diff --git a/OOXML/DocxFormat/WritingElement.h b/OOXML/DocxFormat/WritingElement.h index da09a91b2c..63eb13cecb 100644 --- a/OOXML/DocxFormat/WritingElement.h +++ b/OOXML/DocxFormat/WritingElement.h @@ -41,6 +41,7 @@ namespace NSBinPptxRW class CBinaryFileReader; class CXmlWriter; } + namespace OOX { #define WritingElement_AdditionConstructors(Class) \ diff --git a/OOXML/Projects/Linux/PPTXFormatLib/PPTXFormatLib.pro b/OOXML/Projects/Linux/PPTXFormatLib/PPTXFormatLib.pro index 9db0a779b3..8015f61e4e 100644 --- a/OOXML/Projects/Linux/PPTXFormatLib/PPTXFormatLib.pro +++ b/OOXML/Projects/Linux/PPTXFormatLib/PPTXFormatLib.pro @@ -328,11 +328,17 @@ SOURCES += \ \ ../../../../MsBinaryFile/Common/Vml/BaseShape.cpp \ ../../../../MsBinaryFile/Common/Vml/toVmlConvert.cpp \ + \ ../../../../MsBinaryFile/Common/Vml/PPTShape/PptShape.cpp \ ../../../../MsBinaryFile/Common/Vml/PPTShape/PptFormula.cpp \ ../../../../MsBinaryFile/Common/Vml/PPTShape/ElementSettings.cpp \ + ../../../../MsBinaryFile/Common/Vml/PPTShape/BinaryReader.cpp \ + ../../../../MsBinaryFile/Common/Vml/PPTShape/CustomGeomShape.cpp \ + ../../../../MsBinaryFile/Common/Vml/PPTShape/Ppt2PptxShapeConverter.cpp \ + \ ../../../../MsBinaryFile/Common/Vml/PPTXShape/PptxFormula.cpp \ ../../../../MsBinaryFile/Common/Vml/PPTXShape/PptxShape.cpp \ + ../../../../MsBinaryFile/Common/Vml/PPTXShape/Pptx2PptShapeConverter.cpp \ \ ../../../../MsBinaryFile/PptFile/Drawing/TextAttributesEx.cpp \ ../../../../MsBinaryFile/PptFile/Drawing/Elements.cpp \ @@ -393,6 +399,28 @@ SOURCES += \ HEADERS += \ pptx_format.h \ + \ + ../../../../MsBinaryFile/Common/Vml/BaseShape.h \ + ../../../../MsBinaryFile/Common/Vml/toVmlConvert.h \ + ../../../../MsBinaryFile/Common/Vml/Path.h \ + ../../../../MsBinaryFile/Common/Vml/GraphicsPath.h \ + ../../../../MsBinaryFile/Common/Vml/Common.h \ + \ + ../../../../MsBinaryFile/Common/Vml/PPTShape/PptShape.h \ + ../../../../MsBinaryFile/Common/Vml/PPTShape/PptFormula.h \ + ../../../../MsBinaryFile/Common/Vml/PPTShape/ElementSettings.h \ + ../../../../MsBinaryFile/Common/Vml/PPTShape/BinaryReader.h \ + ../../../../MsBinaryFile/Common/Vml/PPTShape/CustomGeomShape.h \ + ../../../../MsBinaryFile/Common/Vml/PPTShape/Ppt2PptxShapeConverter.h \ + ../../../../MsBinaryFile/Common/Vml/PPTShape/Enums.h \ + ../../../../MsBinaryFile/Common/Vml/PPTShape/PptShapeEnum.h \ + ../../../../MsBinaryFile/Common/Vml/PPTShape/PresetShapesHeader.h \ + \ + ../../../../MsBinaryFile/Common/Vml/PPTXShape/PptxFormula.h \ + ../../../../MsBinaryFile/Common/Vml/PPTXShape/PptxShape.h \ + ../../../../MsBinaryFile/Common/Vml/PPTXShape/PresetShapesHeader.h \ + ../../../../MsBinaryFile/Common/Vml/PPTXShape/Pptx2PptShapeConverter.h \ + \ ../../../PPTXFormat/DrawingConverter/ASCOfficeDrawingConverter.h \ ../../../PPTXFormat/DrawingConverter/ASCOfficePPTXFile.h \ ../../../PPTXFormat/FileTypes.h \