#ifndef TextAnimator_hpp #define TextAnimator_hpp #include "Lottie/Public/Primitives/Vectors.hpp" #include "Lottie/Public/Primitives/Color.hpp" #include "Lottie/Private/Model/Keyframes/KeyframeGroup.hpp" #include "Lottie/Private/Parsing/JsonParsing.hpp" #include #include namespace lottie { class TextAnimator { public: TextAnimator( std::optional &name_, std::optional> anchor_, std::optional> position_, std::optional> scale_, std::optional> skew_, std::optional> skewAxis_, std::optional> rotation_, std::optional> opacity_, std::optional> strokeColor_, std::optional> fillColor_, std::optional> strokeWidth_, std::optional> tracking_ ) : name(name_), anchor(anchor_), position(position_), scale(scale_), skew(skew_), skewAxis(skewAxis_), rotation(rotation_), opacity(opacity_), strokeColor(strokeColor_), fillColor(fillColor_), strokeWidth(strokeWidth_), tracking(tracking_) { } explicit TextAnimator(json11::Json const &jsonAny) { if (!jsonAny.is_object()) { throw LottieParsingException(); } json11::Json::object const &json = jsonAny.object_items(); if (const auto nameData = getOptionalString(json, "nm")) { name = nameData.value(); } _extraS = getOptionalAny(json, "s"); json11::Json::object const &animatorContainer = getObject(json, "a"); if (const auto fillColorData = getOptionalObject(animatorContainer, "fc")) { fillColor = KeyframeGroup(fillColorData.value()); } if (const auto strokeColorData = getOptionalObject(animatorContainer, "sc")) { strokeColor = KeyframeGroup(strokeColorData.value()); } if (const auto strokeWidthData = getOptionalObject(animatorContainer, "sw")) { strokeWidth = KeyframeGroup(strokeWidthData.value()); } if (const auto trackingData = getOptionalObject(animatorContainer, "t")) { tracking = KeyframeGroup(trackingData.value()); } if (const auto anchorData = getOptionalObject(animatorContainer, "a")) { anchor = KeyframeGroup(anchorData.value()); } if (const auto positionData = getOptionalObject(animatorContainer, "p")) { position = KeyframeGroup(positionData.value()); } if (const auto scaleData = getOptionalObject(animatorContainer, "s")) { scale = KeyframeGroup(scaleData.value()); } if (const auto skewData = getOptionalObject(animatorContainer, "sk")) { skew = KeyframeGroup(skewData.value()); } if (const auto skewAxisData = getOptionalObject(animatorContainer, "sa")) { skewAxis = KeyframeGroup(skewAxisData.value()); } if (const auto rotationData = getOptionalObject(animatorContainer, "r")) { rotation = KeyframeGroup(rotationData.value()); } if (const auto opacityData = getOptionalObject(animatorContainer, "o")) { opacity = KeyframeGroup(opacityData.value()); } } json11::Json::object toJson() const { json11::Json::object animatorContainer; if (fillColor.has_value()) { animatorContainer.insert(std::make_pair("fc", fillColor->toJson())); } if (strokeColor.has_value()) { animatorContainer.insert(std::make_pair("sc", strokeColor->toJson())); } if (strokeWidth.has_value()) { animatorContainer.insert(std::make_pair("sw", strokeWidth->toJson())); } if (tracking.has_value()) { animatorContainer.insert(std::make_pair("t", tracking->toJson())); } if (anchor.has_value()) { animatorContainer.insert(std::make_pair("a", anchor->toJson())); } if (position.has_value()) { animatorContainer.insert(std::make_pair("p", position->toJson())); } if (scale.has_value()) { animatorContainer.insert(std::make_pair("s", scale->toJson())); } if (skew.has_value()) { animatorContainer.insert(std::make_pair("sk", skew->toJson())); } if (skewAxis.has_value()) { animatorContainer.insert(std::make_pair("sa", skewAxis->toJson())); } if (rotation.has_value()) { animatorContainer.insert(std::make_pair("r", rotation->toJson())); } if (opacity.has_value()) { animatorContainer.insert(std::make_pair("o", opacity->toJson())); } json11::Json::object result; result.insert(std::make_pair("a", animatorContainer)); if (name.has_value()) { result.insert(std::make_pair("nm", name.value())); } if (_extraS.has_value()) { result.insert(std::make_pair("s", _extraS.value())); } return result; } public: std::optional name; /// Anchor std::optional> anchor; /// Position std::optional> position; /// Scale std::optional> scale; /// Skew std::optional> skew; /// Skew Axis std::optional> skewAxis; /// Rotation std::optional> rotation; /// Opacity std::optional> opacity; /// Stroke Color std::optional> strokeColor; /// Fill Color std::optional> fillColor; /// Stroke Width std::optional> strokeWidth; /// Tracking std::optional> tracking; std::optional _extraS; }; } #endif /* TextAnimator_hpp */