From ceede2a1ad9174da593316c5758545c7a4fcbb68 Mon Sep 17 00:00:00 2001 From: Kamil Kerimov Date: Sat, 6 Jan 2024 02:47:02 +0500 Subject: [PATCH] Convert hidden slides pptx to odp --- OdfFile/DataTypes/presentationvisibility.cpp | 72 +++++++++++++++++++ OdfFile/DataTypes/presentationvisibility.h | 69 ++++++++++++++++++ OdfFile/Projects/Linux/OdfFormatLib.pro | 2 + OdfFile/Projects/Linux/odf_datatypes.cpp | 1 + OdfFile/Projects/Windows/cpcommon.vcxproj | 2 + OdfFile/Reader/Format/style_presentation.cpp | 4 ++ OdfFile/Reader/Format/style_presentation.h | 4 +- OdfFile/Writer/Converter/PptxConverter.cpp | 3 + .../Writer/Format/odp_conversion_context.cpp | 6 ++ .../Writer/Format/odp_conversion_context.h | 1 + OdfFile/Writer/Format/odp_page_state.cpp | 13 ++++ OdfFile/Writer/Format/odp_page_state.h | 2 + OdfFile/Writer/Format/odp_slide_context.cpp | 5 ++ OdfFile/Writer/Format/odp_slide_context.h | 1 + OdfFile/Writer/Format/style_presentation.cpp | 2 + OdfFile/Writer/Format/style_presentation.h | 4 +- OdfFile/Writer/Format/styles.cpp | 7 ++ OdfFile/Writer/Format/styles.h | 2 + 18 files changed, 198 insertions(+), 2 deletions(-) create mode 100644 OdfFile/DataTypes/presentationvisibility.cpp create mode 100644 OdfFile/DataTypes/presentationvisibility.h diff --git a/OdfFile/DataTypes/presentationvisibility.cpp b/OdfFile/DataTypes/presentationvisibility.cpp new file mode 100644 index 0000000000..a20d8d71b6 --- /dev/null +++ b/OdfFile/DataTypes/presentationvisibility.cpp @@ -0,0 +1,72 @@ +/* + * (c) Copyright Ascensio System SIA 2010-2023 + * + * 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-6 Ernesta Birznieka-Upish + * 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 "presentationvisibility.h" + +#include + +namespace cpdoccore { namespace odf_types { + + std::wostream& operator<<(std::wostream& _Wostream, const presentation_visibility& _Val) + { + switch (_Val.get_type()) + { + case presentation_visibility::hidden: + { + _Wostream << L"hidden"; + } break; + case presentation_visibility::visible: + { + _Wostream << L"visible"; + } break; + default: + break; + } + + return _Wostream; + } + + presentation_visibility presentation_visibility::parse(const std::wstring& Str) + { + std::wstring tmp = Str; + boost::algorithm::to_lower(tmp); + + if (tmp == L"hidden") + return presentation_visibility(hidden); + else if (tmp == L"visible") + return presentation_visibility(visible); + + return presentation_visibility(visible); + } + +} // namespace odf_types +} // namespace cpdoccore \ No newline at end of file diff --git a/OdfFile/DataTypes/presentationvisibility.h b/OdfFile/DataTypes/presentationvisibility.h new file mode 100644 index 0000000000..f90e77eb04 --- /dev/null +++ b/OdfFile/DataTypes/presentationvisibility.h @@ -0,0 +1,69 @@ +/* + * (c) Copyright Ascensio System SIA 2010-2023 + * + * 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-6 Ernesta Birznieka-Upish + * 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 +#include "odfattributes.h" + +namespace cpdoccore { namespace odf_types { + +class presentation_visibility +{ +public: + enum type + { + hidden, + visible + }; + + presentation_visibility() {} + presentation_visibility(type _Type) : type_(_Type) + {} + + type get_type() const + { + return type_; + } + + static presentation_visibility parse(const std::wstring & Str); + +private: + type type_; +}; + +std::wostream& operator << (std::wostream& _Wostream, const presentation_visibility& _Val); + +} // namespace odf_types + +APPLY_PARSE_XML_ATTRIBUTES(odf_types::presentation_visibility); + +} // namespace cpdoccore \ No newline at end of file diff --git a/OdfFile/Projects/Linux/OdfFormatLib.pro b/OdfFile/Projects/Linux/OdfFormatLib.pro index e821c9783d..45e696350e 100644 --- a/OdfFile/Projects/Linux/OdfFormatLib.pro +++ b/OdfFile/Projects/Linux/OdfFormatLib.pro @@ -97,6 +97,7 @@ SOURCES += \ ../../DataTypes/percentorscale.cpp \ ../../DataTypes/presentationclass.cpp \ ../../DataTypes/presentationnodetype.cpp \ + ../../DataTypes/presentationvisibility.cpp \ ../../DataTypes/presetclass.cpp \ ../../DataTypes/presetid.cpp \ ../../DataTypes/punctuationwrap.cpp \ @@ -502,6 +503,7 @@ HEADERS += \ ../../DataTypes/percentorscale.h \ ../../DataTypes/presentationclass.h \ ../../DataTypes/presentationnodetype.h \ + ../../DataTypes/presentationvisibility.h \ ../../DataTypes/presetclass.h \ ../../DataTypes/presetid.h \ ../../DataTypes/punctuationwrap.h \ diff --git a/OdfFile/Projects/Linux/odf_datatypes.cpp b/OdfFile/Projects/Linux/odf_datatypes.cpp index ccd39bb3f6..b13da53e57 100644 --- a/OdfFile/Projects/Linux/odf_datatypes.cpp +++ b/OdfFile/Projects/Linux/odf_datatypes.cpp @@ -86,6 +86,7 @@ #include "../../DataTypes/percentorscale.cpp" #include "../../DataTypes/presentationclass.cpp" #include "../../DataTypes/presentationnodetype.cpp" +#include "../../DataTypes/presentationvisibility.cpp" #include "../../DataTypes/presetclass.cpp" #include "../../DataTypes/presetid.cpp" #include "../../DataTypes/punctuationwrap.cpp" diff --git a/OdfFile/Projects/Windows/cpcommon.vcxproj b/OdfFile/Projects/Windows/cpcommon.vcxproj index ae7be3a897..55607999e5 100644 --- a/OdfFile/Projects/Windows/cpcommon.vcxproj +++ b/OdfFile/Projects/Windows/cpcommon.vcxproj @@ -249,6 +249,7 @@ + @@ -378,6 +379,7 @@ + diff --git a/OdfFile/Reader/Format/style_presentation.cpp b/OdfFile/Reader/Format/style_presentation.cpp index 805c6f1453..a11f5fecc4 100644 --- a/OdfFile/Reader/Format/style_presentation.cpp +++ b/OdfFile/Reader/Format/style_presentation.cpp @@ -151,6 +151,8 @@ void drawing_page_properties::add_attributes( const xml::attributes_wc_ptr & Att CP_APPLY_ATTR(L"presentation:display-date-time", presentation_display_date_time_); CP_APPLY_ATTR(L"presentation:display-header", presentation_display_header_); CP_APPLY_ATTR(L"presentation:page-duration", presentation_page_duration_); + + CP_APPLY_ATTR(L"presentation:visibility", presentation_visibility_); } void drawing_page_properties::apply_from(const drawing_page_properties & Other) { @@ -172,6 +174,8 @@ void drawing_page_properties::apply_from(const drawing_page_properties & Other) _CP_APPLY_PROP2(presentation_page_duration_); + _CP_APPLY_PROP2(presentation_visibility_); + } } } diff --git a/OdfFile/Reader/Format/style_presentation.h b/OdfFile/Reader/Format/style_presentation.h index c603cbde6f..0978abe2d7 100644 --- a/OdfFile/Reader/Format/style_presentation.h +++ b/OdfFile/Reader/Format/style_presentation.h @@ -38,6 +38,7 @@ #include "anim_elements.h" #include "../../DataTypes/presentationclass.h" +#include "../../DataTypes/presentationvisibility.h" #include "../../DataTypes/drawfill.h" @@ -119,12 +120,13 @@ public: _CP_OPT(bool) presentation_display_header_; _CP_OPT(std::wstring) presentation_page_duration_; + _CP_OPT(odf_types::presentation_visibility) presentation_visibility_; + office_element_ptr presentation_sound_; //presentation:background-objects-visible //presentation:background-visible //style:repeat - //presentation:visibility. //draw:background-size }; diff --git a/OdfFile/Writer/Converter/PptxConverter.cpp b/OdfFile/Writer/Converter/PptxConverter.cpp index c376c756cf..96407de5c9 100644 --- a/OdfFile/Writer/Converter/PptxConverter.cpp +++ b/OdfFile/Writer/Converter/PptxConverter.cpp @@ -1412,6 +1412,9 @@ void PptxConverter::convert_slides() convert (slide->transition.GetPointer()); convert (slide->timing.GetPointer()); + if (!bShow) + odp_context->hide_slide(); + odp_context->end_slide(); } diff --git a/OdfFile/Writer/Format/odp_conversion_context.cpp b/OdfFile/Writer/Format/odp_conversion_context.cpp index 4f9a53401b..c5e283ddc0 100644 --- a/OdfFile/Writer/Format/odp_conversion_context.cpp +++ b/OdfFile/Writer/Format/odp_conversion_context.cpp @@ -126,6 +126,12 @@ void odp_conversion_context::start_slide() drawing_context()->set_presentation(0); } + +void odp_conversion_context::hide_slide() +{ + slide_context_.hide_page(); +} + void odp_conversion_context::end_slide() { slide_context_.end_page(); diff --git a/OdfFile/Writer/Format/odp_conversion_context.h b/OdfFile/Writer/Format/odp_conversion_context.h index a30538b17a..4068241e00 100644 --- a/OdfFile/Writer/Format/odp_conversion_context.h +++ b/OdfFile/Writer/Format/odp_conversion_context.h @@ -59,6 +59,7 @@ public: virtual void end_document(); void start_slide(); + void hide_slide(); void end_slide(); size_t get_pages_count(); diff --git a/OdfFile/Writer/Format/odp_page_state.cpp b/OdfFile/Writer/Format/odp_page_state.cpp index 5c5efa4bd9..ed5a087603 100644 --- a/OdfFile/Writer/Format/odp_page_state.cpp +++ b/OdfFile/Writer/Format/odp_page_state.cpp @@ -92,6 +92,19 @@ void odp_page_state::set_page_duration(int id) page_properties_->content_.presentation_page_duration_ = id; } +void odp_page_state::hide_page() +{ + style* office_page_style_ = dynamic_cast(page_style_elm_.get()); + if (!office_page_style_) + return; + + drawing_page_properties* page_props = office_page_style_->content_.get_drawing_page_properties(); + if (!page_props) + return; + + page_props->presentation_visibility_ = presentation_visibility::hidden; +} + void odp_page_state::set_layout_page(std::wstring name) { if (name.empty())return; diff --git a/OdfFile/Writer/Format/odp_page_state.h b/OdfFile/Writer/Format/odp_page_state.h index 862a1e4528..ed76b701fb 100644 --- a/OdfFile/Writer/Format/odp_page_state.h +++ b/OdfFile/Writer/Format/odp_page_state.h @@ -83,6 +83,8 @@ public: void set_page_id (int id); void set_page_style (office_element_ptr & _style); void set_page_duration (int id); + + void hide_page(); void set_master_page(std::wstring name); void set_layout_page(std::wstring name); diff --git a/OdfFile/Writer/Format/odp_slide_context.cpp b/OdfFile/Writer/Format/odp_slide_context.cpp index 091945ee7b..209758e642 100644 --- a/OdfFile/Writer/Format/odp_slide_context.cpp +++ b/OdfFile/Writer/Format/odp_slide_context.cpp @@ -86,6 +86,11 @@ void odp_slide_context::start_page(office_element_ptr & elm) state().drawing_context()->set_styles_context(styles_context_); } +void odp_slide_context::hide_page() +{ + state().hide_page(); +} + void odp_slide_context::end_page() { state().drawing_context()->finalize(state().page_elm_); diff --git a/OdfFile/Writer/Format/odp_slide_context.h b/OdfFile/Writer/Format/odp_slide_context.h index 25f1177595..e41648b7b2 100644 --- a/OdfFile/Writer/Format/odp_slide_context.h +++ b/OdfFile/Writer/Format/odp_slide_context.h @@ -81,6 +81,7 @@ public: odp_slide_context(odp_conversion_context & Context); void start_page (office_element_ptr & elm); + void hide_page(); void end_page (); void remove_page(); diff --git a/OdfFile/Writer/Format/style_presentation.cpp b/OdfFile/Writer/Format/style_presentation.cpp index ae1311b095..e42d11826a 100644 --- a/OdfFile/Writer/Format/style_presentation.cpp +++ b/OdfFile/Writer/Format/style_presentation.cpp @@ -100,6 +100,8 @@ void drawing_page_properties::serialize(std::wostream & strm, const wchar_t * ns CP_XML_ATTR_OPT(L"presentation:display-date-time", presentation_display_date_time_); CP_XML_ATTR_OPT(L"presentation:display-header", presentation_display_header_); + CP_XML_ATTR_OPT(L"presentation:visibility", presentation_visibility_); + if (presentation_sound_) presentation_sound_->serialize(CP_XML_STREAM()); } diff --git a/OdfFile/Writer/Format/style_presentation.h b/OdfFile/Writer/Format/style_presentation.h index eccda39622..b3a791eede 100644 --- a/OdfFile/Writer/Format/style_presentation.h +++ b/OdfFile/Writer/Format/style_presentation.h @@ -42,6 +42,7 @@ #include "../../DataTypes/common_attlists.h" #include "../../DataTypes/animation_attlists.h" #include "../../DataTypes/presentationclass.h" +#include "../../DataTypes/presentationvisibility.h" #include "../../DataTypes/drawfill.h" namespace cpdoccore { @@ -118,12 +119,13 @@ public: _CP_OPT(bool) presentation_display_header_; _CP_OPT(odf_types::clockvalue) presentation_page_duration_; + _CP_OPT(odf_types::presentation_visibility) presentation_visibility_; + office_element_ptr presentation_sound_; //presentation:background-objects-visible //presentation:background-visible //style:repeat - //presentation:visibility //draw:background-size }; diff --git a/OdfFile/Writer/Format/styles.cpp b/OdfFile/Writer/Format/styles.cpp index 325b622354..555fe12e54 100644 --- a/OdfFile/Writer/Format/styles.cpp +++ b/OdfFile/Writer/Format/styles.cpp @@ -109,6 +109,13 @@ text_format_properties* style_content::get_text_properties() return &(style_text->content_); return NULL; } +drawing_page_properties* style_content::get_drawing_page_properties() +{ + style_drawing_page_properties* style_page = dynamic_cast(style_drawing_page_properties_.get()); + if (style_page) + return &(style_page->content_); + return NULL; +} graphic_format_properties * style_content::add_get_style_graphic_properties() { if (!style_graphic_properties_) diff --git a/OdfFile/Writer/Format/styles.h b/OdfFile/Writer/Format/styles.h index 48eee7b402..c0acce8f6e 100644 --- a/OdfFile/Writer/Format/styles.h +++ b/OdfFile/Writer/Format/styles.h @@ -94,6 +94,7 @@ class graphic_format_properties; class paragraph_format_properties; class chart_format_properties; class text_format_properties; +class drawing_page_properties; class style_content : noncopyable { @@ -108,6 +109,7 @@ public: paragraph_format_properties* get_paragraph_properties(); chart_format_properties* get_chart_properties(); text_format_properties* get_text_properties(); + drawing_page_properties* get_drawing_page_properties(); //add & get graphic_format_properties* add_get_style_graphic_properties(); text_format_properties* add_get_style_text_properties();