common picture: quick fix the broken bounds() interface.
authorHermet Park <chuneon.park@samsung.com>
Wed, 25 Aug 2021 06:17:25 +0000 (15:17 +0900)
committerJunsuChoi <jsuya.choi@samsung.com>
Fri, 27 Aug 2021 05:10:25 +0000 (14:10 +0900)
picture must return the boundary info - 0, 0, w, h
We assume that it has a designated picture size.

Aside from this issue,
bounds() api must be reviewed, its behavior is quite in a trouble...
unless the result is not transformed, its information is useless...

@Issue: https://github.com/Samsung/thorvg/issues/741

src/examples/PictureTvg.cpp
src/examples/TvgSaver.cpp
src/examples/images/test.tvg
src/lib/tvgPictureImpl.h

index a7593cf..7149e07 100644 (file)
@@ -42,6 +42,9 @@ void tvgDrawCmds(tvg::Canvas* canvas)
     picture->size(&w, &h);
     cout << "default tvg view size = " << w << " x " << h << endl;
 
+    picture->translate(w * 0.1f, h * 0.1f);
+    picture->size(w * 0.8f, h * 0.8f);
+
     canvas->push(move(picture));
 }
 
index 1274460..e2d3013 100644 (file)
@@ -108,15 +108,20 @@ void exportTvg()
     free(data);
 
     //nested paints
-    auto scene1 = tvg::Scene::gen();
+    auto scene2 = tvg::Scene::gen();
+    scene2->translate(100, 100);
+
+    auto scene3 = tvg::Scene::gen();
+    scene3->rotate(10);
+    scene3->scale(2);
+    scene3->translate(400,400);
 
     auto shape2 = tvg::Shape::gen();
     shape2->appendRect(50, 0, 50, 100, 10, 40);
     shape2->fill(0, 0, 255, 125);
-    scene1->push(move(shape2));
-    scene1->rotate(10);
-    scene1->scale(2);
-    scene1->translate(400,400);
+    scene3->push(move(shape2));
+
+    scene2->push(move(scene3));
 
     auto shape3 = tvg::Shape::gen();
     shape3->appendRect(0, 0, 50, 100, 10, 40);
@@ -127,11 +132,7 @@ void exportTvg()
     shape3->scale(2);
     shape3->opacity(200);
     shape3->translate(400, 400);
-
-    auto scene2 = tvg::Scene::gen();
-    scene2->push(move(scene1));
     scene2->push(move(shape3));
-    scene2->translate(100, 100);
 
     if (scene->push(move(scene2)) != tvg::Result::Success) return;
 
@@ -141,6 +142,7 @@ void exportTvg()
     svg->opacity(200);
     svg->scale(0.3);
     svg->translate(50, 450);
+
     auto svgMask = tvg::Shape::gen();
     tvgDrawStar(svgMask.get());
     svgMask->fill(0, 0, 0, 255);
index 36f5a1d..e68e57a 100644 (file)
Binary files a/src/examples/images/test.tvg and b/src/examples/images/test.tvg differ
index b5235a9..afa3acb 100644 (file)
@@ -169,9 +169,16 @@ struct Picture::Impl
 
     bool bounds(float* x, float* y, float* w, float* h) const
     {
-        if (paint) return paint->pImpl->bounds(x, y, w, h);
-        if (w) *w = this->w;
-        if (h) *h = this->h;
+        if (x) *x = 0;
+        if (y) *y = 0;
+        if (w) {
+            if (loader) *w = loader->w;
+            else *w = 0;
+        }
+        if (h) {
+            if (loader) *h = loader->h;
+            else *h = 0;
+        }
         return true;
     }