/* * 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 "../DocxFormat/Rels.h" #include "../DocxFormat/FileTypes.h" #include "FileTypes.h" #include "Folder.h" #include "FileMap.h" #include "Presentation.h" #include "Theme.h" #include "SlideMaster.h" #include "SlideLayout.h" #include "Slide.h" #include "NotesMaster.h" #include "NotesSlide.h" #include "HandoutMaster.h" #include namespace PPTX { Document::Document() : FileContainer(this) { } Document::Document(const OOX::CPath& path) : FileContainer(this) { read(path); } bool Document::read(const OOX::CPath& path) { OOX::CRels rels(path); PPTX::FileMap map; long files = CountFiles(path); if(files == 0) return false; m_sDocumentPath = path.GetPath(); FileContainer::read(rels, path, map); smart_ptr _presentation = FileContainer::Get(OOX::Presentation::FileTypes::Presentation).smart_dynamic_cast(); if (_presentation.is_init()) { _presentation->commentAuthors = _presentation->Get(OOX::Presentation::FileTypes::CommentAuthors).smart_dynamic_cast(); if (false == _presentation->commentAuthors.IsInit()) { _presentation->commentAuthors = _presentation->Get(OOX::Presentation::FileTypes::ModernCommentAuthors).smart_dynamic_cast(); } if (_presentation->IsExist(OOX::FileTypes::VbaProject)) { _presentation->m_bMacroEnabled = true; _presentation->m_pVbaProject = _presentation->Get(OOX::FileTypes::VbaProject).smart_dynamic_cast(); } if (_presentation->IsExist(OOX::FileTypes::JsaProject)) { _presentation->m_pJsaProject = _presentation->Get(OOX::FileTypes::JsaProject).smart_dynamic_cast(); } _presentation->comments = _presentation->Get(OOX::Presentation::FileTypes::SlideComments).smart_dynamic_cast(); } for (std::map>::const_iterator pPair = map.m_map.begin(); pPair != map.m_map.end(); ++pPair) { const OOX::FileType& curType = pPair->second->type(); if (OOX::FileTypes::Theme == curType) { smart_ptr pTheme = pPair->second.smart_dynamic_cast(); if (pTheme.IsInit()) pTheme->presentation = _presentation; } } for (std::map>::const_iterator pPair = map.m_map.begin(); pPair != map.m_map.end(); ++pPair) { const OOX::FileType& curType = pPair->second->type(); if (OOX::Presentation::FileTypes::SlideMaster == curType) { smart_ptr pointer = pPair->second.smart_dynamic_cast(); if (pointer.is_init()) pointer->ApplyRels(); } } for (std::map>::const_iterator pPair = map.m_map.begin(); pPair != map.m_map.end(); ++pPair) { const OOX::FileType& curType = pPair->second->type(); if (OOX::Presentation::FileTypes::SlideLayout == curType) { smart_ptr pointer = pPair->second.smart_dynamic_cast(); if (pointer.is_init()) pointer->ApplyRels(); } } for (std::map>::const_iterator pPair = map.m_map.begin(); pPair != map.m_map.end(); ++pPair) { const OOX::FileType& curType = pPair->second->type(); if (OOX::Presentation::FileTypes::Slide == curType) { smart_ptr pointer = pPair->second.smart_dynamic_cast(); if (pointer.is_init()) pointer->ApplyRels(); } } for (std::map>::const_iterator pPair = map.m_map.begin(); pPair != map.m_map.end(); ++pPair) { const OOX::FileType& curType = pPair->second->type(); if (OOX::Presentation::FileTypes::NotesMaster == curType) { smart_ptr pointer = pPair->second.smart_dynamic_cast(); if (pointer.is_init()) pointer->ApplyRels(); } } for (std::map>::const_iterator pPair = map.m_map.begin(); pPair != map.m_map.end(); ++pPair) { const OOX::FileType& curType = pPair->second->type(); if (OOX::Presentation::FileTypes::HandoutMaster == curType) { smart_ptr pointer = pPair->second.smart_dynamic_cast(); if (pointer.is_init()) pointer->ApplyRels(); } } for (std::map>::const_iterator pPair = map.m_map.begin(); pPair != map.m_map.end(); ++pPair) { const OOX::FileType& curType = pPair->second->type(); if (OOX::Presentation::FileTypes::NotesSlide == curType) { smart_ptr pointer = pPair->second.smart_dynamic_cast(); if (pointer.is_init()) pointer->ApplyRels(); } } return true; } void Document::write(const OOX::CPath& path) { OOX::CSystemUtility::CreateDirectories(path); OOX::CRels rels; OOX::CContentTypes content; OOX::CPath dir = path; FileContainer::write(rels, path, dir, content); rels.Write(path / FILE_SEPARATOR_STR); content.Write(path); FileContainer::WrittenSetFalse(); } void Document::createFromTemplate(const OOX::CPath& path) { //read(path); } const bool Document::isValid(const OOX::CPath& path) const { return true;//FileContainer::exist(OOX::Presentation::FileTypes::Presentation); } long Document::CountFiles(const OOX::CPath& path) { return OOX::CSystemUtility::GetFilesCount(path.GetDirectory(), true); } } // namespace PPTX