From db287518751e5e2cdd8fc839077a0d7bd8257349 Mon Sep 17 00:00:00 2001 From: Kamil Kerimov Date: Wed, 18 Sep 2024 22:02:21 +0500 Subject: [PATCH] Fix placeholder conversion --- OdfFile/DataTypes/presentationclass.cpp | 2 ++ OdfFile/DataTypes/presentationclass.h | 3 +- OdfFile/Reader/Converter/pptx_drawing.cpp | 21 +++++++++++++- OdfFile/Reader/Format/draw_frame.cpp | 1 - OdfFile/Reader/Format/draw_frame.h | 2 ++ OdfFile/Reader/Format/draw_frame_pptx.cpp | 29 ++++++++++++++++++- OdfFile/Writer/Converter/ConvertDrawing.cpp | 17 +++++++++-- OdfFile/Writer/Converter/PptxConverter.cpp | 2 +- OdfFile/Writer/Format/odf_drawing_context.cpp | 1 + 9 files changed, 70 insertions(+), 8 deletions(-) diff --git a/OdfFile/DataTypes/presentationclass.cpp b/OdfFile/DataTypes/presentationclass.cpp index c8239e863f..d57a34dad6 100644 --- a/OdfFile/DataTypes/presentationclass.cpp +++ b/OdfFile/DataTypes/presentationclass.cpp @@ -57,6 +57,7 @@ std::wostream & operator << (std::wostream & _Wostream, const presentation_class case presentation_class::handout: _Wostream << L"handout"; break; case presentation_class::outline: _Wostream << L"outline"; break; case presentation_class::text: _Wostream << L"text"; break; + case presentation_class::body: _Wostream << L"body"; break; } return _Wostream; } @@ -81,6 +82,7 @@ presentation_class presentation_class::parse(const std::wstring & Str) else if (tmp == L"footer") return presentation_class( footer ); else if (tmp == L"date-time") return presentation_class( date_time ); else if (tmp == L"page-number") return presentation_class( page_number ); + else if (tmp == L"body") return presentation_class( body ); else { return presentation_class( page ); diff --git a/OdfFile/DataTypes/presentationclass.h b/OdfFile/DataTypes/presentationclass.h index d91c067d63..7521aa695e 100644 --- a/OdfFile/DataTypes/presentationclass.h +++ b/OdfFile/DataTypes/presentationclass.h @@ -56,8 +56,9 @@ public: header, footer, date_time, - page_number + page_number, + body }; presentation_class() {} diff --git a/OdfFile/Reader/Converter/pptx_drawing.cpp b/OdfFile/Reader/Converter/pptx_drawing.cpp index 3a8563756d..eb2821d40d 100644 --- a/OdfFile/Reader/Converter/pptx_drawing.cpp +++ b/OdfFile/Reader/Converter/pptx_drawing.cpp @@ -58,7 +58,26 @@ void pptx_serialize_text(std::wostream & strm, _pptx_drawing & val) { CP_XML_NODE(L"a:p")//empty a:p { - CP_XML_NODE(L"a:endParaRPr"); + CP_XML_NODE(L"a:endParaRPr") + { + _CP_OPT(double) font_size; + odf_reader::GetProperty(val.additional, L"placeholder-font-size", font_size); + if (font_size) + CP_XML_ATTR(L"sz", *font_size * 100); + + _CP_OPT(std::wstring) text_color; + odf_reader::GetProperty(val.additional, L"placeholder-text-color", text_color); + if (text_color) + { + CP_XML_NODE(L"a:solidFill") + { + CP_XML_NODE(L"a:srgbClr") + { + CP_XML_ATTR_OPT(L"val", text_color); + } + } + } + } } } } diff --git a/OdfFile/Reader/Format/draw_frame.cpp b/OdfFile/Reader/Format/draw_frame.cpp index 53a0079c75..d595634c86 100644 --- a/OdfFile/Reader/Format/draw_frame.cpp +++ b/OdfFile/Reader/Format/draw_frame.cpp @@ -313,7 +313,6 @@ void draw_frame::add_child_element( xml::sax * Reader, const std::wstring & Ns, } } - /////////////////////// void draw_text_box_attlist::add_attributes( const xml::attributes_wc_ptr & Attributes ) diff --git a/OdfFile/Reader/Format/draw_frame.h b/OdfFile/Reader/Format/draw_frame.h index 6325d12a70..157e06d0d9 100644 --- a/OdfFile/Reader/Format/draw_frame.h +++ b/OdfFile/Reader/Format/draw_frame.h @@ -159,6 +159,8 @@ public: virtual void pptx_convert(oox::pptx_conversion_context & Context); virtual void pptx_convert_placeHolder(oox::pptx_conversion_context & Context); + void pptx_convert_placeHolder_styles(oox::pptx_conversion_context& Context, const paragraph_format_properties* paragraph_props, const text_format_properties* text_props); + virtual std::wostream & text_to_stream(std::wostream & _Wostream, bool bXmlEncode = true) const; int idx_in_owner ; diff --git a/OdfFile/Reader/Format/draw_frame_pptx.cpp b/OdfFile/Reader/Format/draw_frame_pptx.cpp index a4f43aeff6..1202f9063d 100644 --- a/OdfFile/Reader/Format/draw_frame_pptx.cpp +++ b/OdfFile/Reader/Format/draw_frame_pptx.cpp @@ -204,6 +204,17 @@ void draw_frame::pptx_convert(oox::pptx_conversion_context & Context) bool is_placeholder = common_presentation_attlist_.presentation_placeholder_.get_value_or(Bool(false)).get(); Context.get_slide_context().set_is_placeHolder(is_placeholder); } + + if (!textStyleName.empty()) + { + odf_reader::style_instance* textStyleInst = + Context.root()->odf_context().styleContainer().style_by_name(textStyleName, odf_types::style_family::Paragraph, Context.process_masters_); + + paragraph_format_properties paragraph_properties = calc_paragraph_properties_content(textStyleInst); + text_format_properties_ptr text_properties = calc_text_properties_content(textStyleInst); + + pptx_convert_placeHolder_styles(Context, ¶graph_properties, text_properties.get()); + } } if (common_draw_attlists_.shape_with_text_and_styles_.common_shape_draw_attlist_.drawooo_display_) @@ -251,6 +262,23 @@ void draw_frame::pptx_convert(oox::pptx_conversion_context & Context) Context.get_slide_context().end_frame(); } +void draw_frame::pptx_convert_placeHolder_styles(oox::pptx_conversion_context& Context, const paragraph_format_properties* paragraph_props, const text_format_properties* text_props) +{ + if (text_props) + { + if (text_props->fo_color_) + Context.get_slide_context().set_property(odf_reader::_property(L"placeholder-text-color", text_props->fo_color_->get_hex_value())); + if (text_props->fo_font_size_) + Context.get_slide_context().set_property( + odf_reader::_property(L"placeholder-font-size", text_props->fo_font_size_->get_length().get_value_unit(odf_types::length::pt))); + } + + if (paragraph_props) + { + //if(paragraph_props->fo_text_align_) + } +} + void draw_image::pptx_convert(oox::pptx_conversion_context & Context) { if (draw_frame_ptr) @@ -329,7 +357,6 @@ void draw_text_box::pptx_convert(oox::pptx_conversion_context & Context) frame->content_.push_back(elm); frame->pptx_convert(Context); - } return; } diff --git a/OdfFile/Writer/Converter/ConvertDrawing.cpp b/OdfFile/Writer/Converter/ConvertDrawing.cpp index 6c94c353cb..a9dec20018 100644 --- a/OdfFile/Writer/Converter/ConvertDrawing.cpp +++ b/OdfFile/Writer/Converter/ConvertDrawing.cpp @@ -874,7 +874,7 @@ void OoxConverter::convert(PPTX::Logic::Shape *oox_shape) //----------------------------------------------------------------------------- odf_context()->drawing_context()->start_shape(type); - if (odf_context()->drawing_context()->placeholder_replacing()) + if (oox_shape->nvSpPr.nvPr.ph.is_init()) { _CP_PTR(cpdoccore::odf_writer::paragraph_format_properties) paragraph_properties = boost::make_shared(); _CP_PTR(cpdoccore::odf_writer::text_format_properties) text_properties = boost::make_shared(); @@ -882,12 +882,23 @@ void OoxConverter::convert(PPTX::Logic::Shape *oox_shape) convert(oox_shape->txBody->lstStyle.GetPointer(), 0, paragraph_properties.get(), text_properties.get()); - graphic_properties->draw_textarea_horizontal_align_ = odf_types::text_align(odf_types::text_align::Left); - graphic_properties->draw_textarea_vertical_align_ = odf_types::vertical_align(odf_types::vertical_align::Top); + if (odf_context()->drawing_context()->placeholder_replacing()) + { + graphic_properties->draw_textarea_horizontal_align_ = odf_types::text_align(odf_types::text_align::Left); + graphic_properties->draw_textarea_vertical_align_ = odf_types::vertical_align(odf_types::vertical_align::Top); + } odf_context()->drawing_context()->set_text_properties(text_properties.get()); odf_context()->drawing_context()->set_paragraph_properties(paragraph_properties.get()); odf_context()->drawing_context()->set_graphic_properties(graphic_properties.get()); + + if (oox_shape->txBody.IsInit()) + { + odf_context()->start_text_context(); + convert(oox_shape->txBody->bodyPr.GetPointer()); + odf_context()->drawing_context()->set_text(odf_context()->text_context()); + odf_context()->end_text_context(); + } } convert(&oox_shape->spPr, oox_shape->style.GetPointer()); diff --git a/OdfFile/Writer/Converter/PptxConverter.cpp b/OdfFile/Writer/Converter/PptxConverter.cpp index a6f8187776..4bc2d877ef 100644 --- a/OdfFile/Writer/Converter/PptxConverter.cpp +++ b/OdfFile/Writer/Converter/PptxConverter.cpp @@ -2783,7 +2783,7 @@ void PptxConverter::convert_slide(PPTX::Logic::CSld *oox_slide, PPTX::Logic::TxS if (type == Slide && ph_type == 0) { placeholder_replacing = true; - ph_type = 13; // subtitle + ph_type = 16; // body } if (type == Layout && (ph_type == 5 || ph_type == 6 || ph_type == 7 || ph_type == 12)) diff --git a/OdfFile/Writer/Format/odf_drawing_context.cpp b/OdfFile/Writer/Format/odf_drawing_context.cpp index 74d64642ce..586c9da949 100644 --- a/OdfFile/Writer/Format/odf_drawing_context.cpp +++ b/OdfFile/Writer/Format/odf_drawing_context.cpp @@ -1519,6 +1519,7 @@ void odf_drawing_context::set_placeholder_type (int val) case 13: impl_->current_drawing_state_.presentation_class_ = presentation_class::subtitle; break; case 14: impl_->current_drawing_state_.presentation_class_ = presentation_class::table; break; case 15: impl_->current_drawing_state_.presentation_class_ = presentation_class::title; break; + case 16: impl_->current_drawing_state_.presentation_class_ = presentation_class::body; break; default: impl_->current_drawing_state_.presentation_class_ = presentation_class::outline; break; }