/* * Copyright (C) Ascensio System SIA, 2009-2026 * * This program is a free software product. You can redistribute it and/or * modify it under the terms of the GNU Affero General Public License (AGPL) * version 3 as published by the Free Software Foundation, together with the * additional terms provided in the LICENSE file. * * This program is distributed WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For * details, see the GNU AGPL at: https://www.gnu.org/licenses/agpl-3.0.html * * You can contact Ascensio System SIA by email at info@onlyoffice.com * or by postal mail at 20A-6 Ernesta Birznieka-Upisha Street, Riga, * LV-1050, Latvia, European Union. * * The interactive user interfaces in modified versions of the Program * are required to display Appropriate Legal Notices in accordance with * Section 5 of the GNU AGPL version 3. * * No trademark rights are granted under this License. * * All non-code elements of the Product, including illustrations, * icon sets, and technical writing content, are licensed under the * Creative Commons Attribution-ShareAlike 4.0 International License: * https://creativecommons.org/licenses/by-sa/4.0/legalcode * * This license applies only to such non-code elements and does not * modify or replace the licensing terms applicable to the Program's * source code, which remains licensed under the GNU Affero General * Public License v3. * * SPDX-License-Identifier: AGPL-3.0-only */ #include "OleConverter.h" #include "../../../DesktopEditor/common/File.h" #include "../../../DesktopEditor/common/Directory.h" #include "../../../DesktopEditor/common/StringBuilder.h" namespace HWP { COleConverter::COleConverter() : m_unCountCharts(0) {} void COleConverter::Clear() { m_unCountCharts = 0; m_wsTempDir.clear(); } unsigned int COleConverter::GetChartsCount() const { return m_unCountCharts; } void COleConverter::SetTempDir(const std::wstring& wsTempDir) { m_wsTempDir = wsTempDir; } void COleConverter::CreateChartData(const std::wstring& wsChartData) { const std::wstring wsPath = m_wsTempDir + FILE_SEPARATOR_STR + L"word" + FILE_SEPARATOR_STR + L"charts" + FILE_SEPARATOR_STR; NSFile::CFileBinary oChartFile; oChartFile.CreateFileW(wsPath + L"chart" + std::to_wstring(m_unCountCharts) + L".xml"); oChartFile.WriteStringUTF8(wsChartData); oChartFile.CloseFile(); NSStringUtils::CStringBuilder oColorData; oColorData.WriteString(L""); oColorData.WriteString(L""); oColorData.WriteString(L""); oColorData.WriteString(L""); oColorData.WriteString(L""); oColorData.WriteString(L""); oColorData.WriteString(L""); NSFile::CFileBinary oColorFile; oColorFile.CreateFileW(wsPath + L"colors" + std::to_wstring(m_unCountCharts) + L".xml"); oColorFile.WriteStringUTF8(oColorData.GetData()); oColorFile.CloseFile(); NSStringUtils::CStringBuilder oStyleData; oStyleData.WriteString(L""); oStyleData.WriteString(L""); oStyleData.WriteString(L""); oStyleData.WriteString(L""); oStyleData.WriteString(L""); oStyleData.WriteString(L""); oStyleData.WriteString(L""); oStyleData.WriteString(L""); oStyleData.WriteString(L""); oStyleData.WriteString(L""); oStyleData.WriteString(L""); oStyleData.WriteString(L""); oStyleData.WriteString(L""); oStyleData.WriteString(L""); oStyleData.WriteString(L""); oStyleData.WriteString(L""); oStyleData.WriteString(L""); oStyleData.WriteString(L""); oStyleData.WriteString(L""); oStyleData.WriteString(L""); oStyleData.WriteString(L""); oStyleData.WriteString(L""); oStyleData.WriteString(L""); oStyleData.WriteString(L""); oStyleData.WriteString(L""); oStyleData.WriteString(L""); oStyleData.WriteString(L""); oStyleData.WriteString(L""); oStyleData.WriteString(L""); oStyleData.WriteString(L""); oStyleData.WriteString(L""); oStyleData.WriteString(L""); oStyleData.WriteString(L""); NSFile::CFileBinary oStyleFile; oStyleFile.CreateFileW(wsPath + L"style" + std::to_wstring(m_unCountCharts) + L".xml"); oStyleFile.WriteStringUTF8(oStyleData.GetData()); oStyleFile.CloseFile(); } void COleConverter::CreateChart(CHWPStream& oOleStream) { std::string sData = std::string(oOleStream.GetCurPtr(), oOleStream.GetSize()); size_t unBegin = sData.find("", unBegin); if (std::string::npos == unEnd) return; const std::string sCharDataA = sData.substr(unBegin, unEnd - unBegin + 15); const std::wstring wsChartData = UTF8_TO_U(sCharDataA); const std::wstring wsPath = m_wsTempDir + FILE_SEPARATOR_STR + L"word" + FILE_SEPARATOR_STR + L"charts"; if (!NSDirectory::Exists(wsPath)) NSDirectory::CreateDirectory(wsPath); ++m_unCountCharts; CreateChartData(wsChartData); const std::wstring wsRelsPath = wsPath + FILE_SEPARATOR_STR + L"_rels"; if (!NSDirectory::Exists(wsRelsPath)) NSDirectory::CreateDirectory(wsRelsPath); NSStringUtils::CStringBuilder oRelsData; oRelsData.WriteString(L""); oRelsData.WriteString(L""); oRelsData.WriteString(L""); oRelsData.WriteString(L""); oRelsData.WriteString(L""); NSFile::CFileBinary oRelsFile; oRelsFile.CreateFileW(wsRelsPath + FILE_SEPARATOR_STR + L"chart" + std::to_wstring(m_unCountCharts) + L".xml.rels"); oRelsFile.WriteStringUTF8(oRelsData.GetData()); oRelsFile.CloseFile(); } }