/* * 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 "office_presentation.h" #include "draw_page.h" #include #include "odf_document.h" #include "odfcontext.h" #include "serialize_elements.h" namespace cpdoccore { namespace odf_reader { // office:presentation ////////////////////////////////////////////////////////////////////////////////////////////////// const wchar_t * office_presentation::ns = L"office"; const wchar_t * office_presentation::name = L"presentation"; void office_presentation::add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name) { if CP_CHECK_NAME(L"draw", L"page") { CP_CREATE_ELEMENT(pages_); } else if CP_CHECK_NAME(L"table", L"tracked-changes") { CP_CREATE_ELEMENT(tracked_changes_); } else if CP_CHECK_NAME(L"table", L"content-validations") { CP_CREATE_ELEMENT(content_validations_); } else if CP_CHECK_NAME(L"presentation", L"footer-decl") { CP_CREATE_ELEMENT(footer_decls_); } else if CP_CHECK_NAME(L"presentation", L"date-time-decl") { CP_CREATE_ELEMENT(date_time_decls_); } else if CP_CHECK_NAME(L"text", L"user-field-decls") { CP_CREATE_ELEMENT(user_fields_); } else if CP_CHECK_NAME(L"text", L"sequence-decls") { CP_CREATE_ELEMENT(sequences_); } else if CP_CHECK_NAME(L"text", L"variable-decls") { CP_CREATE_ELEMENT(variables_); } } void office_presentation::add_text(const std::wstring & Text) { } void office_presentation::add_attributes( const xml::attributes_wc_ptr & Attributes ) { } void office_presentation::collect_page_names(oox::pptx_conversion_context& Context) { for (size_t i = 0; i < pages_.size(); i++) { draw_page* page = dynamic_cast(pages_[i].get()); if (!page) continue; Context.add_page_name(page->get_draw_name()); } } void office_presentation::docx_convert(oox::docx_conversion_context & Context) { Context.start_office_text(); _CP_LOG << L"[info][docx] process pages (" << pages_.size() << L" elmements)" << std::endl; for (size_t i = 0; i < pages_.size(); i++) { pages_[i]->docx_convert(Context); } Context.end_office_text(); } void office_presentation::xlsx_convert(oox::xlsx_conversion_context & Context) { Context.start_office_spreadsheet(this); _CP_LOG << L"[info][xlsx] process pages (" << pages_.size() << L" elmements)" << std::endl; for (size_t i = 0; i < pages_.size(); i++) { pages_[i]->xlsx_convert(Context); } Context.end_office_spreadsheet(); } bool CheckPageLayout(std::vector>* vec_name_layout, draw_page* page, bool new_name) { if(vec_name_layout->empty() || !page) return true; for(size_t i = 0; i < vec_name_layout->size();i++) { if((*vec_name_layout)[i].first == page->attlist_.page_layout_name_.get_value_or(L"")) { if(new_name) page->attlist_.master_page_name_ = (*vec_name_layout)[i].second; return true; } } return false; } void office_presentation::pptx_convert(oox::pptx_conversion_context & Context) { Context.start_office_presentation(); _CP_LOG << L"[info][pptx] process pages(" << pages_.size() << L" elmements)" << std::endl; for (size_t i = 0; i < footer_decls_.size(); i++) { presentation_footer_decl * style = dynamic_cast(footer_decls_[i].get()); if (!style) continue; std::wstring style_name_ = L"footer:" + style->presentation_name_.get_value_or(L""); Context.root()->odf_context().drawStyles().add(style_name_, footer_decls_[i]); } for (size_t i = 0; i < date_time_decls_.size(); i++) { presentation_date_time_decl * style = dynamic_cast(date_time_decls_[i].get()); if (!style) continue; std::wstring style_name_ = L"datetime:" + style->presentation_name_.get_value_or(L""); Context.root()->odf_context().drawStyles().add(style_name_, date_time_decls_[i]); } if (user_fields_) user_fields_->pptx_convert(Context); if (variables_) variables_->pptx_convert(Context); if (sequences_) sequences_->pptx_convert(Context); collect_page_names(Context); std::vector>* vec_name_master_page = &(Context.root()->odf_context().styleContainer().get_vec_new_name()); unsigned int pos_in_vec = 0; if(!vec_name_master_page->empty()) { for (size_t i = 0; i < pages_.size(); i++) { if(i >= 1) { office_element_ptr & elm = pages_[i]; draw_page* page = dynamic_cast(elm.get()); if(CheckPageLayout(vec_name_master_page,page,true)) continue; for(size_t t = 0 ; t < i ; t++) { office_element_ptr & elm_prev_page = pages_[t]; draw_page* prev_page = dynamic_cast(elm_prev_page.get()); if(!prev_page) break; if(page->attlist_.master_page_name_.get_value_or(L"") == prev_page->attlist_.master_page_name_.get_value_or(L"") && page->attlist_.page_layout_name_.get_value_or(L"") != prev_page->attlist_.page_layout_name_.get_value_or(L"")) { page->attlist_.master_page_name_ = (*vec_name_master_page)[pos_in_vec].second; (*vec_name_master_page)[pos_in_vec].first = page->attlist_.page_layout_name_.get_value_or(L""); pos_in_vec++; break; } } } if(pos_in_vec == vec_name_master_page->size()) break; } } for (size_t i = 0; i < pages_.size(); i++) { office_element_ptr & elm = pages_[i]; draw_page* page = dynamic_cast(elm.get()); CheckPageLayout(vec_name_master_page,page,true); pages_[i]->pptx_convert(Context); } Context.end_office_presentation(); } } }