lottie/render: Use AlignCenter rule when the composition dosen't scale exactly to... 56/185256/2
authorsubhransu mohanty <sub.mohanty@samsung.com>
Fri, 27 Jul 2018 05:42:02 +0000 (14:42 +0900)
committersubhransu mohanty <sub.mohanty@samsung.com>
Fri, 27 Jul 2018 05:51:58 +0000 (14:51 +0900)
Change-Id: Ibd8aa929186104378287b65785afbc799cad0e04

src/lottie/lottieitem.cpp

index c0a9869..e516954 100644 (file)
@@ -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) {