Files
core/MsBinaryFile/Common/Vml/PPTShape/Ppt2PptxShapeConverter.h
Alexander Trofimov 76ee07f61c [copyright] Update copyright header
Co-authored-by: Alexander Trofimov <alexander.trofimov@onlyoffice.com>
Co-committed-by: Alexander Trofimov <alexander.trofimov@onlyoffice.com>
2026-05-14 08:23:56 +00:00

298 lines
13 KiB
C++

/*
* Copyright (C) Ascensio System SIA, 2009-2026
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation, together with the
* additional terms provided in the LICENSE file.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: https://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA by email at info@onlyoffice.com
* or by postal mail at 20A-6 Ernesta Birznieka-Upisha Street, Riga,
* LV-1050, Latvia, European Union.
*
* The interactive user interfaces in modified versions of the Program
* are required to display Appropriate Legal Notices in accordance with
* Section 5 of the GNU AGPL version 3.
*
* No trademark rights are granted under this License.
*
* All non-code elements of the Product, including illustrations,
* icon sets, and technical writing content, are licensed under the
* Creative Commons Attribution-ShareAlike 4.0 International License:
* https://creativecommons.org/licenses/by-sa/4.0/legalcode
*
* This license applies only to such non-code elements and does not
* modify or replace the licensing terms applicable to the Program's
* source code, which remains licensed under the GNU Affero General
* Public License v3.
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
#pragma once
#include "PptFormula.h"
#include "../VmlPath.h"
#include "../PPTShape/PptShape.h"
#include "../PPTXShape/PptxShape.h"
#include "../../../../OOXML/Binary/Presentation/XmlWriter.h"
namespace PPTX2EditorAdvanced
{
OOXMLShapes::ShapeType GetShapeTypeFromStr(const std::wstring& str);
}
namespace NSGuidesVML
{
static int __wstrlen(const wchar_t* str)
{
const wchar_t* s = str;
for (; *s != 0; ++s);
return (LONG)(s - str);
}
static int g_guide_max_len = 80;
static wchar_t* g_guide_string1 = L"<a:gd name=\"gd";
static int g_guide_string1_len = __wstrlen(g_guide_string1);
static wchar_t* g_guide_string2 = L"\"/>";
static int g_guide_string2_len = __wstrlen(g_guide_string2);
static wchar_t* g_guide_string_val = L"\" fmla=\"val ";
static int g_guide_string_val_len = __wstrlen(g_guide_string_val);
static wchar_t* g_guide_string_sum = L"\" fmla=\"+- ";
static int g_guide_string_sum_len = __wstrlen(g_guide_string_sum);
static wchar_t* g_guide_string_prod = L"\" fmla=\"*/ ";
static int g_guide_string_prod_len = __wstrlen(g_guide_string_prod);
static wchar_t* g_guide_string_abs = L"\" fmla=\"abs ";
static int g_guide_string_abs_len = __wstrlen(g_guide_string_abs);
static wchar_t* g_guide_string_min = L"\" fmla=\"min ";
static int g_guide_string_min_len = __wstrlen(g_guide_string_min);
static wchar_t* g_guide_string_max = L"\" fmla=\"max ";
static int g_guide_string_max_len = __wstrlen(g_guide_string_max);
static wchar_t* g_guide_string__if = L"\" fmla=\"?: ";
static int g_guide_string__if_len = __wstrlen(g_guide_string__if);
static wchar_t* g_guide_string_sqrt = L"\" fmla=\"sqrt ";
static int g_guide_string_sqrt_len = __wstrlen(g_guide_string_sqrt);
static wchar_t* g_guide_string_at2 = L"\" fmla=\"at2 ";
static int g_guide_string_at2_len = __wstrlen(g_guide_string_at2);
static wchar_t* g_guide_string_sin = L"\" fmla=\"sin ";
static int g_guide_string_sin_len = __wstrlen(g_guide_string_sin);
static wchar_t* g_guide_string_cos = L"\" fmla=\"cos ";
static int g_guide_string_cos_len = __wstrlen(g_guide_string_cos);
static wchar_t* g_guide_string_cat2 = L"\" fmla=\"cat2 ";
static int g_guide_string_cat2_len = __wstrlen(g_guide_string_cat2);
static wchar_t* g_guide_string_sat2 = L"\" fmla=\"sat2 ";
static int g_guide_string_sat2_len = __wstrlen(g_guide_string_sat2);
static wchar_t* g_guide_string_mod = L"\" fmla=\"mod ";
static int g_guide_string_mod_len = __wstrlen(g_guide_string_mod);
static wchar_t* g_guide_string_tag = L"\" fmla=\"tag ";
static int g_guide_string_tag_len = __wstrlen(g_guide_string_tag);
#define GUIDE_PARAM_1(name) \
{ \
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_##name, g_guide_string_##name##_len); \
GetValue(lParam1, eType1, bExtShape1, oWriter); \
++m_lIndexDst; \
oWriter.m_oWriter.WriteStringNoSafe(g_guide_string2, g_guide_string2_len); \
}
#define GUIDE_PARAM_2(name) \
{ \
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_##name, g_guide_string_##name##_len); \
GetValue(lParam1, eType1, bExtShape1, oWriter); \
oWriter.m_oWriter.AddSpaceNoCheck(); \
GetValue(lParam2, eType2, bExtShape2, oWriter); \
++m_lIndexDst; \
oWriter.m_oWriter.WriteStringNoSafe(g_guide_string2, g_guide_string2_len); \
}
#define GUIDE_PARAM_3(name) \
{ \
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_##name, g_guide_string_##name##_len); \
GetValue(lParam1, eType1, bExtShape1, oWriter); \
oWriter.m_oWriter.AddSpaceNoCheck(); \
GetValue(lParam2, eType2, bExtShape2, oWriter); \
oWriter.m_oWriter.AddSpaceNoCheck(); \
GetValue(lParam3, eType3, bExtShape3, oWriter); \
++m_lIndexDst; \
oWriter.m_oWriter.WriteStringNoSafe(g_guide_string2, g_guide_string2_len); \
}
struct CFormParam
{
LONG m_lParam;
ParamType m_eType;
LONG m_lCoef;
};
class CSlicePath
{
private:
int m_nCountElementsPoint;
LONG m_lX;
LONG m_lY;
public:
RulesType m_eRuler;
std::vector<Aggplus::POINT> m_arPoints;
std::vector<SPointType> m_arPointsType;
CSlicePath(RulesType rule = rtMoveTo, LONG x = 0, LONG y = 0);
void AddParam(LONG lParam, ParamType eParType);
};
class CFormulaConverter
{
private:
int m_lIndexSrc;
int m_lIndexDst;
LONG m_lX;
LONG m_lY;
std::vector<LONG> m_arIndexDst;
std::vector<CSlicePath> m_arSlicesPath;
std::vector<CPartPath> m_arParts;
std::wstring strFmlaNum;
std::wstring strSign;
std::wstring strFrmla;
std::wstring strResult;
Aggplus::POINT pCurPoint;
SPointType pCurPointType;
Aggplus::POINT pCurPoint1;
SPointType pCurPointType1;
Aggplus::POINT pTmpPoint;
CFormParam m_oParam;
int m_lMaxAdjUse;
public:
LONG m_lWidth;
LONG m_lHeight;
// can't do everything in one, formulas also appear during path/adj conversion, etc.
NSBinPptxRW::CXmlWriter m_oGuidsRes;
NSBinPptxRW::CXmlWriter m_oPathRes;
NSBinPptxRW::CXmlWriter m_oHandleRes;
NSBinPptxRW::CXmlWriter m_oAdjRes;
NSBinPptxRW::CXmlWriter m_oTextRect;
NSBinPptxRW::CXmlWriter m_oCoef;
CFormulaConverter();
void ConvertCoef(NSGuidesVML::CFormParam pCoef);
void ConvertCoef2(NSGuidesVML::CFormParam pCoef);
void ConvertAdj(const std::vector<LONG>& arAdj);
void ConvertFormula(const std::vector<CFormula>& arFormulas);
void ConvertPath(std::wstring strPath, const ODRAW::CPath& oPath);
void ConvertHandle(const std::vector<CHandle_>& arHandles, std::vector<long>& arAdj, PPTShapes::ShapeType oSType);
void SetTextRectDefault();
void ConvertTextRect ( std::wstring strRect);
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);
//---------------------------------------
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);
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);
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);
void ConvertMax (const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2,
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);
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);
void ConvertSin (const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2,
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);
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);
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);
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);
void ConvertTag (const LONG& lParam1, const ParamType& eType1, const LONG& lParam2, const ParamType& eType2,
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);
//-------------------------------------
void FromXML(std::wstring strPath, bool &m_bFill, bool &m_bStroke);
void CreateHandle ( SHandle oHnd );
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);
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);
};
}