From: subhransu mohanty Date: Fri, 27 Jul 2018 05:42:02 +0000 (+0900) Subject: lottie/render: Use AlignCenter rule when the composition dosen't scale exactly to... X-Git-Tag: submit/tizen/20180917.042405~182 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e62f74b624989c9dc7d42994e18ce324d56524ca;p=platform%2Fcore%2Fuifw%2Flottie-player.git lottie/render: Use AlignCenter rule when the composition dosen't scale exactly to the requested size. Change-Id: Ibd8aa929186104378287b65785afbc799cad0e04 --- diff --git a/src/lottie/lottieitem.cpp b/src/lottie/lottieitem.cpp index c0a9869..e516954 100644 --- a/src/lottie/lottieitem.cpp +++ b/src/lottie/lottieitem.cpp @@ -92,16 +92,25 @@ VSize LOTCompItem::size() const bool LOTCompItem::update(int frameNo) { - VMatrix m; - float sx, sy; - // check if cached frame is same as requested frame. if (!mUpdateViewBox && (mCurFrameNo == frameNo)) return false; - sx = mViewSize.width() / float(mCompData->size().width()); - sy = mViewSize.height() / float(mCompData->size().height()); + /* + * if viewbox dosen't scale exactly to the viewport + * we scale the viewbox keeping AspectRatioPreserved and then align the + * viewbox to the viewport using AlignCenter rule. + */ + VSize viewPort = mViewSize; + VSize viewBox = mCompData->size(); + + float sx = float(viewPort.width()) / viewBox.width(); + float sy = float(viewPort.height()) / viewBox.height(); float scale = fmin(sx, sy); - m.scale(scale, scale); + float tx = (viewPort.width() - viewBox.width() * scale) * 0.5; + float ty = (viewPort.height() - viewBox.height() * scale) * 0.5; + + VMatrix m; + m.scale(scale, scale).translate(tx, ty); // update the layer from back to front for (auto i = mLayers.rbegin(); i != mLayers.rend(); ++i) {