common picture: remove viewbox() api.
authorHermet Park <chuneon.park@samsung.com>
Mon, 26 Jul 2021 11:59:21 +0000 (20:59 +0900)
committerJunsuChoi <jsuya.choi@samsung.com>
Thu, 29 Jul 2021 01:14:54 +0000 (10:14 +0900)
picture provides size() interface to return the image size,
viewbox() is conceptually not correct with the Picture.

Remove it under the beta api.

inc/thorvg.h
src/bindings/capi/thorvg_capi.h
src/bindings/capi/tvgCapi.cpp
src/lib/sw_engine/tvgSwImage.cpp
src/lib/tvgPicture.cpp
src/lib/tvgPictureImpl.h
src/loaders/svg/tvgSvgSceneBuilder.cpp
test/capi/capiPicture.cpp

index 21a79d4..3edaeb5 100644 (file)
@@ -1067,15 +1067,6 @@ public:
     Result load(uint32_t* data, uint32_t w, uint32_t h, bool copy) noexcept;
 
     /**
-     * @brief Gets the position and the size of the loaded picture.
-     *
-     * @warning Please do not use it, this API is not official one. It could be modified in the next version.
-     *
-     * @BETA_API
-     */
-    Result viewbox(float* x, float* y, float* w, float* h) const noexcept;
-
-    /**
      * @brief Creates a new Picture object.
      *
      * @return A new Picture object.
index 6487d6b..cc37c8c 100644 (file)
@@ -1688,11 +1688,11 @@ TVG_EXPORT Tvg_Result tvg_picture_load_data(Tvg_Paint* paint, const char *data,
 
 
 /*!
-* \brief Gets the position and the size of the loaded picture. (BETA version)
+* \brief Gets the size of the loaded picture. (BETA version)
 *
 * \warning Please do not use it, this API is not official one. It can be modified in the next version.
 */
-TVG_EXPORT Tvg_Result tvg_picture_get_viewbox(const Tvg_Paint* paint, float* x, float* y, float* w, float* h);
+TVG_EXPORT Tvg_Result tvg_picture_get_size(const Tvg_Paint* paint, float* w, float* h);
 
 
 /** \} */   // end defgroup ThorVGCapi_Picture
index 40183ad..d9a50f6 100644 (file)
@@ -470,10 +470,10 @@ TVG_EXPORT Tvg_Result tvg_picture_load_data(Tvg_Paint* paint, const char *data,
 }
 
 
-TVG_EXPORT Tvg_Result tvg_picture_get_viewbox(const Tvg_Paint* paint, float* x, float* y, float* w, float* h)
+TVG_EXPORT Tvg_Result tvg_picture_get_size(const Tvg_Paint* paint, float* w, float* h)
 {
     if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
-    return (Tvg_Result) reinterpret_cast<Picture*>(CCP(paint))->viewbox(x, y, w, h);
+    return (Tvg_Result) reinterpret_cast<Picture*>(CCP(paint))->size(w, h);
 }
 
 /************************************************************************/
index 48b1e6c..b877591 100644 (file)
@@ -29,7 +29,7 @@
 static bool _genOutline(SwImage* image, const Picture* pdata, const Matrix* transform, SwMpool* mpool,  unsigned tid)
 {
     float w, h;
-    pdata->viewbox(nullptr, nullptr, &w, &h);
+    pdata->size(&w, &h);
     if (w == 0 || h == 0) return false;
 
     image->outline = mpoolReqOutline(mpool, tid);
index 7fda461..5a26e29 100644 (file)
@@ -75,13 +75,6 @@ Result Picture::load(uint32_t* data, uint32_t w, uint32_t h, bool copy) noexcept
 }
 
 
-Result Picture::viewbox(float* x, float* y, float* w, float* h) const noexcept
-{
-    if (pImpl->viewbox(x, y, w, h)) return Result::Success;
-    return Result::InsufficientCondition;
-}
-
-
 Result Picture::size(float w, float h) noexcept
 {
     if (pImpl->size(w, h)) return Result::Success;
index c47f371..c364868 100644 (file)
@@ -148,16 +148,6 @@ struct Picture::Impl
         return false;
     }
 
-    bool viewbox(float* x, float* y, float* w, float* h) const
-    {
-        if (!loader) return false;
-        if (x) *x = loader->vx;
-        if (y) *y = loader->vy;
-        if (w) *w = loader->vw;
-        if (h) *h = loader->vh;
-        return true;
-    }
-
     bool size(uint32_t w, uint32_t h)
     {
         this->w = w;
index aeea6a5..bdfbaff 100644 (file)
@@ -457,7 +457,6 @@ static unique_ptr<Picture> _imageBuildHelper(SvgNode* node, float vx, float vy,
             string decoded = svgUtilURLDecode(href);
             if (picture->load(decoded.c_str(), decoded.size(), true) != Result::Success) return nullptr;
         }
-
     } else {
         if (!strncmp(href, "file://", sizeof("file://") - 1)) href += sizeof("file://") - 1;
         //TODO: protect against recursive svg image loading
@@ -467,17 +466,14 @@ static unique_ptr<Picture> _imageBuildHelper(SvgNode* node, float vx, float vy,
             TVGLOG("SVG", "Embedded svg file is disabled.");
             return nullptr;
         }
-
         if (picture->load(href) != Result::Success) return nullptr;
     }
 
-    float x, y, w, h;
-    if (picture->viewbox(&x, &y, &w, &h) == Result::Success && w && h) {
+    float w, h;
+    if (picture->size(&w, &h) == Result::Success && w  > 0 && h > 0) {
         auto sx = node->node.image.w / w;
         auto sy = node->node.image.h / h;
-        auto sxt = x * sx;
-        auto syt = y * sy;
-        Matrix m = {sx, 0, node->node.image.x - sxt, 0, sy, node->node.image.y - syt, 0, 0, 1};
+        Matrix m = {sx, 0, node->node.image.x, 0, sy, node->node.image.y, 0, 0, 1};
         picture->transform(m);
     }
 
index 3940624..24483a4 100644 (file)
@@ -39,8 +39,8 @@ TEST_CASE("Load Svg file in Picture", "[capiPicture]")
     //Load Svg file
     REQUIRE(tvg_picture_load(picture, TEST_DIR"/logo.svg") == TVG_RESULT_SUCCESS);
 
-    float x, y, w, h;
-    REQUIRE(tvg_picture_get_viewbox(picture, &x, &y, &w, &h) == TVG_RESULT_SUCCESS);
+    float w, h;
+    REQUIRE(tvg_picture_get_size(picture, &w, &h) == TVG_RESULT_SUCCESS);
 
     REQUIRE(tvg_paint_del(picture) == TVG_RESULT_SUCCESS);
 }
@@ -62,7 +62,7 @@ TEST_CASE("Load Svg Data in Picture", "[capiPicture]")
 
     //Verify Size
     float w, h;
-    REQUIRE(tvg_picture_get_viewbox(picture, nullptr, nullptr, &w, &h) == TVG_RESULT_SUCCESS);
+    REQUIRE(tvg_picture_get_size(picture, &w, &h) == TVG_RESULT_SUCCESS);
     REQUIRE(w == Approx(1000).epsilon(0.0000001));
     REQUIRE(h == Approx(1000).epsilon(0.0000001));
 
@@ -92,7 +92,7 @@ TEST_CASE("Load Raw file in Picture", "[capiPicture]")
 
         //Verify Size
         float w, h;
-        REQUIRE(tvg_picture_get_viewbox(picture, nullptr, nullptr, &w, &h) == TVG_RESULT_SUCCESS);
+        REQUIRE(tvg_picture_get_size(picture, &w, &h) == TVG_RESULT_SUCCESS);
         REQUIRE(w == Approx(200).epsilon(0.0000001));
         REQUIRE(h == Approx(300).epsilon(0.0000001));
     }
@@ -116,7 +116,7 @@ TEST_CASE("Load Png file in Picture", "[capiPicture]")
 
     //Verify Size
     float w, h;
-    REQUIRE(tvg_picture_get_viewbox(picture, nullptr, nullptr, &w, &h) == TVG_RESULT_SUCCESS);
+    REQUIRE(tvg_picture_get_size(picture, &w, &h) == TVG_RESULT_SUCCESS);
 
     REQUIRE(tvg_paint_del(picture) == TVG_RESULT_SUCCESS);
 }