From: subhransu mohanty Date: Fri, 17 Aug 2018 04:06:57 +0000 (+0900) Subject: lottie/parser: Added support for separate position attribute in transform object. X-Git-Tag: submit/tizen/20180917.042405~106 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=02404178e8b3fe3e65b7c6dbc9323b47a7fd7675;p=platform%2Fcore%2Fuifw%2Flottie-player.git lottie/parser: Added support for separate position attribute in transform object. Transform object can have separate x and y or a point object. Change-Id: I0ad0073b3cb958336539ad520434c3284894c6b9 --- diff --git a/src/lottie/lottiemodel.cpp b/src/lottie/lottiemodel.cpp index 934b6ce..c119950 100644 --- a/src/lottie/lottiemodel.cpp +++ b/src/lottie/lottiemodel.cpp @@ -76,7 +76,12 @@ void LOTTransformData::cacheMatrix() VMatrix LOTTransformData::computeMatrix(int frameNo) const { VMatrix m; - m.translate(mPosition.value(frameNo)) + VPointF position = mPosition.value(frameNo); + if (mSeparate) { + position.setX(mX.value(frameNo)); + position.setY(mY.value(frameNo)); + } + m.translate(position) .rotate(mRotation.value(frameNo)) .scale(mScale.value(frameNo) / 100.f) .translate(-mAnchor.value(frameNo)); diff --git a/src/lottie/lottiemodel.h b/src/lottie/lottiemodel.h index 69523b1..1321d92 100644 --- a/src/lottie/lottiemodel.h +++ b/src/lottie/lottiemodel.h @@ -392,11 +392,14 @@ public: LOTAnimatable mRotation{0}; /* "r" */ LOTAnimatable mScale; /* "s" */ LOTAnimatable mPosition; /* "p" */ + LOTAnimatable mX{0}; + LOTAnimatable mY{0}; LOTAnimatable mAnchor; /* "a" */ LOTAnimatable mOpacity{100}; /* "o" */ LOTAnimatable mSkew{0}; /* "sk" */ LOTAnimatable mSkewAxis{0}; /* "sa" */ bool mStaticMatrix{true}; + bool mSeparate{false}; VMatrix mCachedMatrix; }; diff --git a/src/lottie/lottieparser.cpp b/src/lottie/lottieparser.cpp index 39cad49..d4e6db3 100644 --- a/src/lottie/lottieparser.cpp +++ b/src/lottie/lottieparser.cpp @@ -233,6 +233,8 @@ public: void parseKeyFrame(LOTAnimInfo &obj); template void parseProperty(LOTAnimatable &obj); + template + void parsePropertyHelper(LOTAnimatable &obj); void parseShapeKeyFrame(LOTAnimInfo &obj); void parseShapeProperty(LOTAnimatable &obj); @@ -1164,7 +1166,20 @@ std::shared_ptr LottieParserImpl::parseTransformObject() if (0 == strcmp(key, "a")) { parseProperty(obj->mAnchor); } else if (0 == strcmp(key, "p")) { - parseProperty(obj->mPosition); + EnterObject(); + while (const char *key = NextObjectKey()) { + if (0 == strcmp(key, "k")) { + parsePropertyHelper(obj->mPosition); + } else if (0 == strcmp(key, "s")) { + obj->mSeparate = GetBool(); + } else if (obj->mSeparate && (0 == strcmp(key, "x"))) { + parseProperty(obj->mX); + } else if (obj->mSeparate && (0 == strcmp(key, "y"))) { + parseProperty(obj->mY); + }else { + Skip(key); + } + } } else if (0 == strcmp(key, "r")) { parseProperty(obj->mRotation); } else if (0 == strcmp(key, "s")) { @@ -1181,7 +1196,9 @@ std::shared_ptr LottieParserImpl::parseTransformObject() } obj->mStaticMatrix = obj->mAnchor.isStatic() && obj->mPosition.isStatic() && obj->mRotation.isStatic() && obj->mScale.isStatic() && - obj->mSkew.isStatic() && obj->mSkewAxis.isStatic(); + obj->mSkew.isStatic() && obj->mSkewAxis.isStatic() && + obj->mX.isStatic() && obj->mY.isStatic(); + obj->setStatic(obj->mStaticMatrix && obj->mOpacity.isStatic()); if (obj->mStaticMatrix) obj->cacheMatrix(); @@ -1785,6 +1802,38 @@ void LottieParserImpl::parseShapeProperty(LOTAnimatable &obj) } } +template +void LottieParserImpl::parsePropertyHelper(LOTAnimatable &obj) +{ + if (PeekType() == kNumberType) { + /*single value property with no animation*/ + getValue(obj.mValue); + } else { + RAPIDJSON_ASSERT(PeekType() == kArrayType); + EnterArray(); + while (NextArrayValue()) { + /* property with keyframe info*/ + if (PeekType() == kObjectType) { + if (!obj.mAnimInfo) + obj.mAnimInfo = std::make_unique>(); + parseKeyFrame(*obj.mAnimInfo.get()); + } else { + /* Read before modifying. + * as there is no way of knowing if the + * value of the array is either array of numbers + * or array of object without entering the array + * thats why this hack is there + */ + RAPIDJSON_ASSERT(PeekType() == kNumberType); + /*multi value property with no animation*/ + parseArrayValue(obj.mValue); + /*break here as we already reached end of array*/ + break; + } + } + } +} + /* * https://github.com/airbnb/lottie-web/tree/master/docs/json/properties */ @@ -1794,36 +1843,7 @@ void LottieParserImpl::parseProperty(LOTAnimatable &obj) EnterObject(); while (const char *key = NextObjectKey()) { if (0 == strcmp(key, "k")) { - if (PeekType() == kNumberType) { - /*single value property with no animation*/ - getValue(obj.mValue); - } else { - RAPIDJSON_ASSERT(PeekType() == kArrayType); - EnterArray(); - while (NextArrayValue()) { - /* property with keyframe info*/ - if (PeekType() == kObjectType) { - if (!obj.mAnimInfo) - obj.mAnimInfo = std::make_unique>(); - parseKeyFrame(*obj.mAnimInfo.get()); - } else { - /* Read before modifying. - * as there is no way of knowing if the - * value of the array is either array of numbers - * or array of object without entering the array - * thats why this hack is there - */ - RAPIDJSON_ASSERT(PeekType() == kNumberType); - /*multi value property with no animation*/ - parseArrayValue(obj.mValue); - /*break here as we already reached end of array*/ - break; - } - } - } - } else if (0 == strcmp(key, "ix")) { - RAPIDJSON_ASSERT(PeekType() == kNumberType); - obj.mPropertyIndex = GetInt(); + parsePropertyHelper(obj); } else { Skip(key); }