common picture: recover viewbox() api.
authorHermet Park <chuneon.park@samsung.com>
Mon, 9 Aug 2021 03:30:25 +0000 (12:30 +0900)
committerHermet Park <chuneon.park@samsung.com>
Mon, 9 Aug 2021 06:35:37 +0000 (15:35 +0900)
though picture has size() api, we have a regression issue in tizen,
we can't remove this api until we resolve any regression conditions.

inc/thorvg.h
src/bindings/capi/thorvg_capi.h
src/bindings/capi/tvgCapi.cpp
src/lib/tvgLoadModule.h
src/lib/tvgPicture.cpp
src/lib/tvgPictureImpl.h
src/loaders/svg/tvgSvgLoader.h

index 6c622c3..12316fa 100644 (file)
@@ -1091,6 +1091,15 @@ 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 SVG 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 d58249d..ea57c1a 100644 (file)
@@ -1696,6 +1696,14 @@ TVG_EXPORT Tvg_Result tvg_picture_load_data(Tvg_Paint* paint, const char *data,
 TVG_EXPORT Tvg_Result tvg_picture_get_size(const Tvg_Paint* paint, float* w, float* h);
 
 
+/*!
+* \brief Gets the position and 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);
+
+
 /** \} */   // end defgroup ThorVGCapi_Picture
 
 
index 19c52c7..ffbb9c3 100644 (file)
@@ -476,6 +476,13 @@ TVG_EXPORT Tvg_Result tvg_picture_get_size(const Tvg_Paint* paint, float* w, flo
     return (Tvg_Result) reinterpret_cast<Picture*>(CCP(paint))->size(w, h);
 }
 
+
+TVG_EXPORT Tvg_Result tvg_picture_get_viewbox(const Tvg_Paint* paint, float* x, float* y, float* w, float* h)
+{
+    if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
+    return (Tvg_Result) reinterpret_cast<Picture*>(CCP(paint))->viewbox(x, y, w, h);
+}
+
 /************************************************************************/
 /* Gradient API                                                         */
 /************************************************************************/
index 1025b73..70b95b7 100644 (file)
@@ -30,7 +30,13 @@ namespace tvg
 class LoadModule
 {
 public:
+    //default view box, if any.
+    float vx = 0;
+    float vy = 0;
+    float vw = 0;
+    float vh = 0;
     float w = 0, h = 0;         //default image size
+    bool preserveAspect = true; //keep aspect ratio by default.
 
     virtual ~LoadModule() {}
 
index 26df9f0..790ac97 100644 (file)
@@ -74,6 +74,13 @@ 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 4d329d3..8d4fd11 100644 (file)
@@ -137,6 +137,16 @@ 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 556a92c..01e90d4 100644 (file)
@@ -35,14 +35,7 @@ public:
     SvgLoaderData loaderData;
     unique_ptr<Scene> root;
 
-    //default view box, if any.
-    float vx = 0;
-    float vy = 0;
-    float vw = 0;
-    float vh = 0;
-
     bool copy = false;
-    bool preserveAspect = true;      //aspect ratio option
 
     SvgLoader();
     ~SvgLoader();