diff --git a/OdfFile/DataTypes/smil_attributename.cpp b/OdfFile/DataTypes/smil_attributename.cpp index 92c7e67d9f..bf819b228e 100644 --- a/OdfFile/DataTypes/smil_attributename.cpp +++ b/OdfFile/DataTypes/smil_attributename.cpp @@ -77,30 +77,31 @@ namespace cpdoccore { namespace odf_types { boost::algorithm::erase_all(tmp, L"-"); if (tmp == L"charcolor") return smil_attribute_name(charColor); - else if (Str == L"charfontname") return smil_attribute_name(charFontName); - else if (Str == L"charheight") return smil_attribute_name(charHeight); - else if (Str == L"charposture") return smil_attribute_name(charPosture); - else if (Str == L"charunderline") return smil_attribute_name(charUnderline); - else if (Str == L"charweight") return smil_attribute_name(charWeight); - else if (Str == L"color") return smil_attribute_name(color); - else if (Str == L"fillcolor") return smil_attribute_name(fillColor); - else if (Str == L"fillstyle") return smil_attribute_name(fillStyle); - else if (Str == L"fillon") return smil_attribute_name(fillOn); - else if (Str == L"height") return smil_attribute_name(height); - else if (Str == L"linecolor") return smil_attribute_name(lineColor); - else if (Str == L"linestyle") return smil_attribute_name(lineStyle); - else if (Str == L"opacity") return smil_attribute_name(opacity); - else if (Str == L"stroke") return smil_attribute_name(stroke); - else if (Str == L"strokecolor") return smil_attribute_name(strokeColor); - else if (Str == L"rotate") return smil_attribute_name(rotate); - else if (Str == L"skewx") return smil_attribute_name(skewX); - else if (Str == L"skewx") return smil_attribute_name(skewY); - else if (Str == L"transform") return smil_attribute_name(transform); - else if (Str == L"visibility") return smil_attribute_name(visibility); - else if (Str == L"width") return smil_attribute_name(width); - else if (Str == L"x") return smil_attribute_name(x); - else if (Str == L"y") return smil_attribute_name(y); - else if (Str == L"dim") return smil_attribute_name(dim); + else if (tmp == L"charfontname") return smil_attribute_name(charFontName); + else if (tmp == L"charheight") return smil_attribute_name(charHeight); + else if (tmp == L"charposture") return smil_attribute_name(charPosture); + else if (tmp == L"charunderline") return smil_attribute_name(charUnderline); + else if (tmp == L"charweight") return smil_attribute_name(charWeight); + else if (tmp == L"color") return smil_attribute_name(color); + else if (tmp == L"fill") return smil_attribute_name(fill); + else if (tmp == L"fillcolor") return smil_attribute_name(fillColor); + else if (tmp == L"fillstyle") return smil_attribute_name(fillStyle); + else if (tmp == L"fillon") return smil_attribute_name(fillOn); + else if (tmp == L"height") return smil_attribute_name(height); + else if (tmp == L"linecolor") return smil_attribute_name(lineColor); + else if (tmp == L"linestyle") return smil_attribute_name(lineStyle); + else if (tmp == L"opacity") return smil_attribute_name(opacity); + else if (tmp == L"stroke") return smil_attribute_name(stroke); + else if (tmp == L"strokecolor") return smil_attribute_name(strokeColor); + else if (tmp == L"rotate") return smil_attribute_name(rotate); + else if (tmp == L"skewx") return smil_attribute_name(skewX); + else if (tmp == L"skewx") return smil_attribute_name(skewY); + else if (tmp == L"transform") return smil_attribute_name(transform); + else if (tmp == L"visibility") return smil_attribute_name(visibility); + else if (tmp == L"width") return smil_attribute_name(width); + else if (tmp == L"x") return smil_attribute_name(x); + else if (tmp == L"y") return smil_attribute_name(y); + else if (tmp == L"dim") return smil_attribute_name(dim); return smil_attribute_name(none); } diff --git a/OdfFile/Reader/Converter/pptx_animation_context.cpp b/OdfFile/Reader/Converter/pptx_animation_context.cpp index c6e97b3298..d32a3aa749 100644 --- a/OdfFile/Reader/Converter/pptx_animation_context.cpp +++ b/OdfFile/Reader/Converter/pptx_animation_context.cpp @@ -33,6 +33,7 @@ #include "pptx_animation_context.h" #include +#include #include "../../DataTypes/clockvalue.h" @@ -263,6 +264,11 @@ namespace oox { impl_->set_description_->End = value; } + void pptx_animation_context::set_set_auto_rev(const std::wstring& value) + { + impl_->set_description_->AutoRev = value; + } + void pptx_animation_context::set_set_fill(const std::wstring& value) { impl_->set_description_->Fill = value; @@ -463,6 +469,11 @@ namespace oox { impl_->anim_clr_description_->ColorSpace = value; } + void pptx_animation_context::set_animate_color_dir(const std::wstring& value) + { + impl_->anim_clr_description_->Direction = value; + } + void pptx_animation_context::set_animate_color_duration(int value) { impl_->anim_clr_description_->Duration = value; @@ -473,6 +484,16 @@ namespace oox { impl_->anim_clr_description_->Delay = value; } + void pptx_animation_context::set_animate_color_fill(const std::wstring& value) + { + impl_->anim_clr_description_->Fill = value; + } + + void pptx_animation_context::set_animate_color_auto_rev(bool value) + { + impl_->anim_clr_description_->AutoRev = value; + } + void pptx_animation_context::set_animate_color_attribute_name(const std::wstring& value) { impl_->anim_clr_description_->AttributeName = value; @@ -483,6 +504,55 @@ namespace oox { impl_->anim_clr_description_->ToValue = value; } + void pptx_animation_context::set_animate_color_by_value(const std::wstring& value) + { + impl_->anim_clr_description_->ByValue = pptx_animation_context::Impl::_anim_clr::color(); + + if (boost::algorithm::starts_with(value, L"#")) + { + if (value.size() != std::wstring(L"#rrggbb").size()) + return; + + const std::wstring str = value.substr(1); // Remove # character + + int r = 0; + int g = 0; + int b = 0; + + std::wistringstream(str.substr(0, 2)) >> std::hex >> r; + std::wistringstream(str.substr(2, 2)) >> std::hex >> g; + std::wistringstream(str.substr(4, 2)) >> std::hex >> b; + + impl_->anim_clr_description_->ByValue->type_ = pptx_animation_context::Impl::_anim_clr::color::rgb; + impl_->anim_clr_description_->ByValue->v1 = r; + impl_->anim_clr_description_->ByValue->v2 = g; + impl_->anim_clr_description_->ByValue->v3 = b; + } + else if (boost::algorithm::starts_with(value, L"hsl")) + { + std::wstring str = value; + boost::algorithm::erase_all(str, L"hsl"); + boost::algorithm::erase_all(str, L"("); + boost::algorithm::erase_all(str, L")"); + boost::algorithm::erase_all(str, L"%"); + std::vector arr; + boost::algorithm::split(arr, str, boost::is_any_of(",")); + + int h = 0; + int s = 0; + int l = 0; + + std::wistringstream(arr[0]) >> h; + std::wistringstream(arr[1]) >> s; + std::wistringstream(arr[2]) >> l; + + impl_->anim_clr_description_->ByValue->type_ = pptx_animation_context::Impl::_anim_clr::color::hsl; + impl_->anim_clr_description_->ByValue->v1 = h * 60000; + impl_->anim_clr_description_->ByValue->v2 = s * 1000; + impl_->anim_clr_description_->ByValue->v3 = l * 1000; + } + } + void pptx_animation_context::set_animate_color_shape_id(size_t value) { impl_->anim_clr_description_->ShapeID = value; @@ -525,11 +595,21 @@ namespace oox { impl_->anim_scale_description_->To = Impl::_anim_scale::vec2(x, y); } + void pptx_animation_context::set_animate_scale_by(int x, int y) + { + impl_->anim_scale_description_->By = Impl::_anim_scale::vec2(x, y); + } + void pptx_animation_context::set_animate_scale_delay(const std::wstring& value) { impl_->anim_scale_description_->Delay = value; } + void pptx_animation_context::set_animate_scale_attribute_name(const std::wstring& value) + { + impl_->anim_scale_description_->AttributeName = value; + } + void pptx_animation_context::set_animate_scale_auto_reverse(bool value) { impl_->anim_scale_description_->AutoReverse = value; @@ -567,6 +647,11 @@ namespace oox { impl_->anim_rotate_description_->By = value; } + void pptx_animation_context::set_animate_rotate_attribute_name(const std::wstring& value) + { + impl_->anim_rotate_description_->AttributeName = value; + } + void pptx_animation_context::set_animate_rotate_delay(const std::wstring& value) { impl_->anim_rotate_description_->Delay = value; @@ -653,6 +738,21 @@ namespace oox { return impl_->root_animation_element_; } + static _CP_OPT(std::wstring) serialize_duration(const _CP_OPT(int) duration) + { + _CP_OPT(std::wstring) res = boost::none; + + if (duration) + { + if (*duration == -1) + res = L"indefinite"; + else + res = std::to_wstring(duration.value()); + } + + return res; + } + void pptx_animation_context::Impl::_par_animation::serialize(std::wostream& strm) { CP_XML_WRITER(strm) @@ -727,8 +827,10 @@ namespace oox { CP_XML_ATTR(L"nodeType", PresentationNodeType.value()); CP_XML_ATTR(L"dur", L"indefinite"); } - else if (Duration) - CP_XML_ATTR(L"dur", Duration.value()); + else + { + CP_XML_ATTR_OPT(L"dur", serialize_duration(Duration)); + } if (TargetEl) { @@ -796,9 +898,10 @@ namespace oox { { CP_XML_NODE(L"p:cTn") { - CP_XML_ATTR_OPT(L"dur" , Duration); - CP_XML_ATTR_OPT(L"fill" , Fill); - + CP_XML_ATTR_OPT(L"dur", serialize_duration(Duration)); + CP_XML_ATTR_OPT(L"fill", Fill); + CP_XML_ATTR_OPT(L"autoRev", AutoRev); + if (Delay) { CP_XML_NODE(L"p:stCondLst") @@ -820,9 +923,9 @@ namespace oox { } } - CP_XML_NODE(L"p:attrNameLst") + if (AttributeName) { - if (AttributeName) + CP_XML_NODE(L"p:attrNameLst") { CP_XML_NODE(L"p:attrName") { @@ -831,9 +934,9 @@ namespace oox { } } } - CP_XML_NODE(L"p:to") + if (ToValue) { - if (ToValue) + CP_XML_NODE(L"p:to") { CP_XML_NODE(L"p:strVal") { @@ -861,7 +964,7 @@ namespace oox { { CP_XML_NODE(L"p:cTn") { - CP_XML_ATTR(L"dur", Duration.value()); + CP_XML_ATTR_OPT(L"dur", serialize_duration(Duration)); } } if (ShapeID) @@ -926,8 +1029,7 @@ namespace oox { CP_XML_NODE(L"p:cTn") { - int duration = Duration ? Duration.value() : 1; - CP_XML_ATTR(L"dur", duration); + CP_XML_ATTR_OPT(L"dur", serialize_duration(Duration)); if (AutoReverse) { @@ -1001,19 +1103,20 @@ namespace oox { { CP_XML_NODE(L"p:animClr") { - if (ColorSpace) CP_XML_ATTR(L"clrSpc", ColorSpace.value()); + CP_XML_ATTR_OPT(L"clrSpc", ColorSpace); CP_XML_NODE(L"p:cBhvr") { CP_XML_NODE(L"p:cTn") { - int duration = Duration ? Duration.value() : 1; - CP_XML_ATTR(L"dur", duration); - CP_XML_ATTR(L"fill", L"hold"); + CP_XML_ATTR_OPT(L"dur", serialize_duration(Duration)); + CP_XML_ATTR_OPT(L"fill", Fill); + CP_XML_ATTR_OPT(L"autoRev", AutoRev); + CP_XML_ATTR_OPT(L"dir", Direction); - CP_XML_NODE(L"p:stCondLst") + if (Delay) { - if (Delay) + CP_XML_NODE(L"p:stCondLst") { CP_XML_NODE(L"p:cond") { @@ -1030,9 +1133,9 @@ namespace oox { CP_XML_ATTR(L"spid", shapeID); } } - CP_XML_NODE(L"p:attrNameLst") + if (AttributeName) { - if (AttributeName) + CP_XML_NODE(L"p:attrNameLst") { CP_XML_NODE(L"p:attrName") { @@ -1041,9 +1144,9 @@ namespace oox { } } } - CP_XML_NODE(L"p:to") + if (ToValue) { - if (ToValue) + CP_XML_NODE(L"p:to") { CP_XML_NODE(L"a:srgbClr") { @@ -1051,6 +1154,38 @@ namespace oox { } } } + + if (ByValue) + { + CP_XML_NODE(L"p:by") + { + switch (ByValue->type_) + { + case color::rgb: + { + CP_XML_NODE(L"a:srgbClr") + { + std::wstringstream ss; + ss << std::hex + << ByValue->v1 + << ByValue->v2 + << ByValue->v3; + + CP_XML_ATTR(L"val", ss.str()); + } + } break; + case color::hsl: + { + CP_XML_NODE(L"p:hsl") + { + CP_XML_ATTR(L"h", ByValue->v1); + CP_XML_ATTR(L"s", ByValue->v2); + CP_XML_ATTR(L"l", ByValue->v3); + } + } break; + } + } + } } } } @@ -1065,8 +1200,7 @@ namespace oox { { CP_XML_NODE(L"p:cTn") { - int duration = Duration ? Duration.value() : 1; - CP_XML_ATTR(L"dur", duration); + CP_XML_ATTR_OPT(L"dur", serialize_duration(Duration)); if (AutoReverse) CP_XML_ATTR(L"autoRev", AutoReverse.value()); if (Fill) CP_XML_ATTR(L"fill", Fill.value()); @@ -1088,6 +1222,17 @@ namespace oox { CP_XML_ATTR(L"spid", shapeID); } } + + if (AttributeName) + { + CP_XML_NODE(L"p:attrNameLst") + { + CP_XML_NODE(L"p:attrName") + { + CP_XML_STREAM() << AttributeName.value(); + } + } + } } if (From) @@ -1107,6 +1252,15 @@ namespace oox { CP_XML_ATTR(L"y", To->y); } } + + if (By) + { + CP_XML_NODE(L"p:by") + { + CP_XML_ATTR(L"x", By->x); + CP_XML_ATTR(L"y", By->y); + } + } } } } @@ -1123,8 +1277,7 @@ namespace oox { { CP_XML_NODE(L"p:cTn") { - int duration = Duration ? Duration.value() : 1; - CP_XML_ATTR(L"dur", duration); + CP_XML_ATTR_OPT(L"dur", serialize_duration(Duration)); if (AutoReverse) CP_XML_ATTR(L"autoRev", AutoReverse.value()); if (Fill) CP_XML_ATTR(L"fill", Fill.value()); @@ -1146,6 +1299,17 @@ namespace oox { CP_XML_ATTR(L"spid", shapeID); } } + + if (AttributeName) + { + CP_XML_NODE(L"p:attrNameLst") + { + CP_XML_NODE(L"p:attrName") + { + CP_XML_STREAM() << AttributeName.value(); + } + } + } } } } diff --git a/OdfFile/Reader/Converter/pptx_animation_context.h b/OdfFile/Reader/Converter/pptx_animation_context.h index 1b874274a3..d2a6897f57 100644 --- a/OdfFile/Reader/Converter/pptx_animation_context.h +++ b/OdfFile/Reader/Converter/pptx_animation_context.h @@ -106,6 +106,7 @@ namespace oox { _CP_OPT(int) Duration; // in ms _CP_OPT(std::wstring) Delay; _CP_OPT(std::wstring) End; + _CP_OPT(std::wstring) AutoRev; _CP_OPT(std::wstring) Fill; _CP_OPT(size_t) ShapeID; _CP_OPT(std::wstring) AttributeName; @@ -150,6 +151,18 @@ namespace oox { typedef shared_ptr<_anim_clr>::Type _anim_clr_ptr; struct _anim_clr : _animation_element { + struct color + { + enum type + { + rgb, + hsl + } type_; + + int v1, v2, v3; + }; + + _CP_OPT(std::wstring) PresentationNodeType; _CP_OPT(std::wstring) Direction; _CP_OPT(std::wstring) Restart; @@ -158,10 +171,12 @@ namespace oox { _CP_OPT(std::wstring) End; _CP_OPT(std::wstring) Fill; + _CP_OPT(bool) AutoRev; _CP_OPT(size_t) ShapeID; _CP_OPT(std::wstring) AttributeName; _CP_OPT(std::wstring) Delay; _CP_OPT(std::wstring) ToValue; + _CP_OPT(color) ByValue; _CP_OPT(std::wstring) ColorSpace; void serialize(std::wostream& strm) override; @@ -216,8 +231,9 @@ namespace oox { _CP_OPT(std::wstring) Fill; _CP_OPT(vec2) From; _CP_OPT(vec2) To; - //_CP_OPT(std::wstring) By; + _CP_OPT(vec2) By; _CP_OPT(std::wstring) Delay; + _CP_OPT(std::wstring) AttributeName; _CP_OPT(bool) AutoReverse; void serialize(std::wostream& strm) override; @@ -231,6 +247,7 @@ namespace oox { _CP_OPT(int) Duration; // in ms _CP_OPT(std::wstring) Fill; _CP_OPT(int) By; + _CP_OPT(std::wstring) AttributeName; _CP_OPT(std::wstring) Delay; _CP_OPT(bool) AutoReverse; @@ -299,6 +316,7 @@ namespace oox { void set_set_duration(int value); void set_set_delay(const std::wstring& value); void set_set_end(const std::wstring& value); + void set_set_auto_rev(const std::wstring& value); void set_set_fill(const std::wstring& value); void set_set_shape_id(size_t value); void set_set_attribute_name(const std::wstring& value); @@ -341,10 +359,14 @@ namespace oox { void start_animate_color(); void set_animate_color_color_space(const std::wstring& value); + void set_animate_color_dir(const std::wstring& value); void set_animate_color_duration(int value); void set_animate_color_delay(const std::wstring& value); + void set_animate_color_fill(const std::wstring& value); + void set_animate_color_auto_rev(bool value); void set_animate_color_attribute_name(const std::wstring& value); void set_animate_color_to_value(const std::wstring& value); + void set_animate_color_by_value(const std::wstring& value); void set_animate_color_shape_id(size_t value); void end_animate_color(); @@ -354,7 +376,9 @@ namespace oox { void set_animate_scale_fill(const std::wstring& value); void set_animate_scale_from(int x, int y); void set_animate_scale_to(int x, int y); + void set_animate_scale_by(int x, int y); void set_animate_scale_delay(const std::wstring& value); + void set_animate_scale_attribute_name(const std::wstring& value); void set_animate_scale_auto_reverse(bool value); void end_animate_scale(); @@ -363,6 +387,7 @@ namespace oox { void set_animate_rotate_duration(int value); void set_animate_rotate_fill(const std::wstring& value); void set_animate_rotate_by(int value); + void set_animate_rotate_attribute_name(const std::wstring& value); void set_animate_rotate_delay(const std::wstring& value); void set_animate_rotate_auto_reverse(bool value); void end_animate_rotate(); diff --git a/OdfFile/Reader/Format/anim_elements.cpp b/OdfFile/Reader/Format/anim_elements.cpp index 1a1b9dbb78..07839604e5 100644 --- a/OdfFile/Reader/Format/anim_elements.cpp +++ b/OdfFile/Reader/Format/anim_elements.cpp @@ -287,11 +287,14 @@ static std::wstring pptx_convert_smil_attribute_name(const odf_types::smil_attri case smil_attribute_name::fill: return L"fill.type"; case smil_attribute_name::fillColor: return L"fillcolor"; case smil_attribute_name::fillStyle: return L""; + case smil_attribute_name::fillOn: return L"fill.on"; case smil_attribute_name::height: return L"ppt_h"; case smil_attribute_name::lineColor: return L""; case smil_attribute_name::lineStyle: return L""; case smil_attribute_name::opacity: return L"style.opacity"; case smil_attribute_name::rotate: return L"r"; + case smil_attribute_name::stroke: return L"stroke.on"; + case smil_attribute_name::strokeColor: return L"stroke.color"; case smil_attribute_name::skewX: return L"xshear"; case smil_attribute_name::skewY: return L""; case smil_attribute_name::visibility: return L"style.visibility"; @@ -1125,7 +1128,7 @@ void anim_transitionFilter::pptx_convert(oox::pptx_conversion_context & Context) } std::wstring filter = convert_filter(); - std::wstring transition = L"in"; + _CP_OPT(std::wstring) transition; _CP_OPT(int) time; size_t shapeId = 0; @@ -1136,8 +1139,7 @@ void anim_transitionFilter::pptx_convert(oox::pptx_conversion_context & Context) if (filter_attlist_.smil_mode_) { - if (filter_attlist_.smil_mode_.value() == L"out") - transition = L"out"; + transition = filter_attlist_.smil_mode_.value(); } if (common_attlist_.smil_target_element_) @@ -1147,8 +1149,8 @@ void anim_transitionFilter::pptx_convert(oox::pptx_conversion_context & Context) animationContext.start_anim_effect(); animationContext.set_anim_effect_filter(filter); - animationContext.set_anim_effect_transition(transition); - if (time) animationContext.set_anim_effect_duration(time.value()); + if(transition) animationContext.set_anim_effect_transition(transition.value()); + if (time) animationContext.set_anim_effect_duration(time.value()); animationContext.set_anim_effect_shape_id(shapeId); animationContext.end_anim_effect(); } @@ -1229,6 +1231,7 @@ void anim_set::pptx_convert(oox::pptx_conversion_context& Context) _CP_OPT(std::wstring) delay; _CP_OPT(std::wstring) end; _CP_OPT(std::wstring) fill; + _CP_OPT(std::wstring) autoRev; _CP_OPT(std::wstring) attribute_name; _CP_OPT(std::wstring) to_value; size_t shapeID = 0; @@ -1237,6 +1240,9 @@ void anim_set::pptx_convert(oox::pptx_conversion_context& Context) { } + if (common_attlist_.smil_auto_reverse_) + autoRev = common_attlist_.smil_auto_reverse_->get() == true ? L"1" : L"0"; + if (common_attlist_.smil_restart_) { } @@ -1274,10 +1280,25 @@ void anim_set::pptx_convert(oox::pptx_conversion_context& Context) { if (set_attlist_.smil_to_.value() == L"visible") to_value = L"visible"; - else if(set_attlist_.smil_to_.value() == L"hidden") + else if (set_attlist_.smil_to_.value() == L"hidden") to_value = L"hidden"; else if (set_attlist_.smil_to_.value() == L"solid") to_value = L"solid"; + else if (set_attlist_.smil_to_.value() == L"false") + to_value = L"false"; + else if (set_attlist_.smil_to_.value() == L"true") + to_value = L"true"; + else + { + try + { + to_value = std::to_wstring(boost::lexical_cast(set_attlist_.smil_to_.value())); + } + catch (const boost::bad_lexical_cast& e) + { + // Ignore + } + } } oox::pptx_animation_context& animationContext = Context.get_slide_context().get_animation_context(); @@ -1288,6 +1309,7 @@ void anim_set::pptx_convert(oox::pptx_conversion_context& Context) if (duration) animationContext.set_set_duration(duration.value()); if (delay) animationContext.set_set_delay(delay.value()); if (end) animationContext.set_set_end(end.value()); + if (autoRev) animationContext.set_set_auto_rev(autoRev.value()); if (fill) animationContext.set_set_fill(fill.value()); if (attribute_name) animationContext.set_set_attribute_name(attribute_name.value()); if (to_value) animationContext.set_set_to_value(to_value.value()); @@ -1360,35 +1382,58 @@ const wchar_t* anim_animate_color::name = L"animateColor"; void anim_animate_color::pptx_convert(oox::pptx_conversion_context& Context) { - _CP_OPT(std::wstring) colorSpace; + _CP_OPT(std::wstring) colorSpace = L"rgb"; _CP_OPT(int) duration; _CP_OPT(std::wstring) delay; _CP_OPT(std::wstring) attributeName; _CP_OPT(std::wstring) toValue; + _CP_OPT(std::wstring) byValue; + _CP_OPT(std::wstring) fill = L"hold"; + _CP_OPT(bool) autoRev = false; + _CP_OPT(std::wstring) dir = L"cw"; // clockwise (cw) size_t shapeID = 0; - colorSpace = L"rgb"; + if (animate_color_attlist_.anim_color_interpolation_) + { + colorSpace = animate_color_attlist_.anim_color_interpolation_.value(); + } + + if (animate_color_attlist_.anim_color_interpolation_direction) + { + if (animate_color_attlist_.anim_color_interpolation_direction.value() == L"clockwise") + dir = L"cw"; + else if (animate_color_attlist_.anim_color_interpolation_direction.value() == L"counter-clockwise") + dir = L"ccw"; + } if (common_attlist_.smil_dur_) duration = common_attlist_.smil_dur_->get_value(); else duration = 1; - if (common_attlist_.smil_begin_) + if (common_attlist_.smil_fill_) { - delay = pptx_convert_smil_begin(common_attlist_.smil_begin_.value()); + bool durationSpecified = common_attlist_.smil_dur_.has_value() || common_attlist_.smil_end_.has_value(); + fill = pptx_convert_smil_fill(common_attlist_.smil_fill_.value(), durationSpecified); } + if (common_attlist_.smil_begin_) + delay = pptx_convert_smil_begin(common_attlist_.smil_begin_.value()); + if (common_attlist_.smil_attribute_name_) - { attributeName = pptx_convert_smil_attribute_name(common_attlist_.smil_attribute_name_.value()); - } if (animate_color_attlist_.smil_to_) { toValue = animate_color_attlist_.smil_to_.value(); - boost::algorithm::erase_all(toValue.value(), L"#"); + boost::erase_all(toValue.value(), L"#"); } + + if (common_attlist_.smil_auto_reverse_) + autoRev = common_attlist_.smil_auto_reverse_->get(); + + if (animate_color_attlist_.smil_by_) + byValue = animate_color_attlist_.smil_by_.value(); if (common_attlist_.smil_target_element_) shapeID = Context.get_slide_context().get_id(common_attlist_.smil_target_element_.value()); @@ -1401,6 +1446,10 @@ void anim_animate_color::pptx_convert(oox::pptx_conversion_context& Context) if (delay) animationContext.set_animate_color_delay(delay.value()); if (attributeName) animationContext.set_animate_color_attribute_name(attributeName.value()); if (toValue) animationContext.set_animate_color_to_value(toValue.value()); + if (byValue) animationContext.set_animate_color_by_value(byValue.value()); + if (autoRev) animationContext.set_animate_color_auto_rev(autoRev.value()); + if (dir) animationContext.set_animate_color_dir(dir.value()); + if (fill) animationContext.set_animate_color_fill(fill.value()); animationContext.set_animate_color_shape_id(shapeID); animationContext.end_animate_color(); } @@ -1532,6 +1581,28 @@ void anim_animate::add_attributes(const xml::attributes_wc_ptr& Attributes) const wchar_t* anim_animate_transform::ns = L"anim"; const wchar_t* anim_animate_transform::name = L"animateTransform"; +static std::vector smil_list_to_oox_vector(const std::wstring& list, int pptx_mulipier) +{ + std::vector oox_list; + std::vector list_str; + boost::split(list_str, list, boost::is_any_of(",")); + + for (const auto& el : list_str) + { + try + { + int num = boost::lexical_cast(el) * pptx_mulipier; + oox_list.push_back(num); + } + catch (boost::bad_lexical_cast e) + { + continue; + } + } + + return oox_list; +} + void anim_animate_transform::pptx_convert(oox::pptx_conversion_context& Context) { size_t shapeID = 0; @@ -1540,6 +1611,7 @@ void anim_animate_transform::pptx_convert(oox::pptx_conversion_context& Context) _CP_OPT(std::wstring) delay; _CP_OPT(bool) autoRev; _CP_OPT(int) by; + _CP_OPT(std::wstring) attributeName; if(common_attlist_.smil_target_element_) shapeID = Context.get_slide_context().get_id(common_attlist_.smil_target_element_.value()); @@ -1552,8 +1624,10 @@ void anim_animate_transform::pptx_convert(oox::pptx_conversion_context& Context) bool durationSpecified = common_attlist_.smil_dur_.has_value() || common_attlist_.smil_end_.has_value(); fill = pptx_convert_smil_fill(common_attlist_.smil_fill_.value(), durationSpecified); } - + if (common_attlist_.smil_attribute_name_) + attributeName = pptx_convert_smil_attribute_name(common_attlist_.smil_attribute_name_.value()); + if (common_attlist_.smil_begin_) delay = pptx_convert_smil_begin(common_attlist_.smil_begin_.value()); @@ -1575,34 +1649,40 @@ void anim_animate_transform::pptx_convert(oox::pptx_conversion_context& Context) if (duration) animationContext.set_animate_scale_duration(duration.value()); if (fill) animationContext.set_animate_scale_fill(fill.value()); if (delay) animationContext.set_animate_scale_delay(delay.value()); + if (attributeName) animationContext.set_animate_scale_attribute_name(attributeName.value()); if (autoRev) animationContext.set_animate_scale_auto_reverse(autoRev.value()); if (animate_transform_attlist_.smil_from_) { const int pptx_mulipier = 100000; - std::vector oox_from; - boost::split(oox_from, animate_transform_attlist_.smil_from_.value(), boost::is_any_of(",")); - if (oox_from.size() >= 2) - { - int x = boost::lexical_cast(oox_from[0]) * pptx_mulipier; - int y = boost::lexical_cast(oox_from[1]) * pptx_mulipier; + const std::vector oox_from = smil_list_to_oox_vector(animate_transform_attlist_.smil_from_.value(), pptx_mulipier); - animationContext.set_animate_scale_from(x, y); - } + if (oox_from.size() >= 2) + animationContext.set_animate_scale_from(oox_from[0], oox_from[1]); + else + _CP_LOG << "[ warning ] cannot convert scale smil:from"; } if (animate_transform_attlist_.smil_to_) { const int pptx_mulipier = 100000; - std::vector oox_to; - boost::split(oox_to, animate_transform_attlist_.smil_to_.value(), boost::is_any_of(",")); - if (oox_to.size() >= 2) - { - int x = boost::lexical_cast(oox_to[0]) * pptx_mulipier; - int y = boost::lexical_cast(oox_to[1]) * pptx_mulipier; + const std::vector oox_to = smil_list_to_oox_vector(animate_transform_attlist_.smil_to_.value(), pptx_mulipier); - animationContext.set_animate_scale_to(x, y); - } + if (oox_to.size() >= 2) + animationContext.set_animate_scale_to(oox_to[0], oox_to[1]); + else + _CP_LOG << "[ warning ] cannot convert scale smil:to"; + } + + if (animate_transform_attlist_.smil_by_) + { + const int pptx_mulipier = 100000; + const std::vector oox_by = smil_list_to_oox_vector(animate_transform_attlist_.smil_by_.value(), pptx_mulipier); + + if (oox_by.size() >= 2) + animationContext.set_animate_scale_by(oox_by[0] + pptx_mulipier, oox_by[1] + pptx_mulipier); + else + _CP_LOG << "[ warning ] cannot convert scale smil:by"; } animationContext.end_animate_scale(); @@ -1630,10 +1710,10 @@ void anim_animate_transform::pptx_convert(oox::pptx_conversion_context& Context) if (delay) animationContext.set_animate_rotate_delay(delay.value()); if (autoRev) animationContext.set_animate_rotate_auto_reverse(autoRev.value()); if (by) animationContext.set_animate_rotate_by(by.value()); + if (attributeName) animationContext.set_animate_rotate_attribute_name(attributeName.value()); animationContext.end_animate_rotate(); break; - break; } } } diff --git a/OdfFile/Writer/Converter/PptxConverter.cpp b/OdfFile/Writer/Converter/PptxConverter.cpp index f600b8b7b3..2db929d366 100644 --- a/OdfFile/Writer/Converter/PptxConverter.cpp +++ b/OdfFile/Writer/Converter/PptxConverter.cpp @@ -791,7 +791,7 @@ void PptxConverter::convert(PPTX::Logic::AnimEffect* oox_anim_effect) std::wstring filter = *oox_anim_effect->filter; std::wstring subtype = L""; - smil_transition_type odfType; + _CP_OPT(smil_transition_type) odfType = boost::none; std::wstring odfSubtype = L""; bool odfReversed = false; @@ -912,13 +912,19 @@ void PptxConverter::convert(PPTX::Logic::AnimEffect* oox_anim_effect) else if (subtype == L"down") { odfReversed = true; odfSubtype = L"fromBottom"; } else if (subtype == L"up") { odfReversed = false; odfSubtype = L"fromTop"; } } + else if (filter == L"image") + { + odfType = boost::none; + } else { odfType = smil_transition_type::fade; odfReversed = false; } - odp_context->current_slide().set_anim_transition_filter_type(odfType); + if(odfType) + odp_context->current_slide().set_anim_transition_filter_type(odfType.value()); + if(!odfSubtype.empty()) odp_context->current_slide().set_anim_transition_filter_subtype(odfSubtype); if(odfReversed)