From: Hermet Park Date: Mon, 9 Aug 2021 03:30:25 +0000 (+0900) Subject: common picture: recover viewbox() api. X-Git-Tag: accepted/tizen/unified/20210810.135318~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9bb1e2b65d2d009bbbbfb223f2ed438dff1b10db;p=platform%2Fcore%2Fgraphics%2Ftizenvg.git common picture: recover viewbox() api. though picture has size() api, we have a regression issue in tizen, we can't remove this api until we resolve any regression conditions. --- diff --git a/inc/thorvg.h b/inc/thorvg.h index 6c622c3..12316fa 100644 --- a/inc/thorvg.h +++ b/inc/thorvg.h @@ -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. diff --git a/src/bindings/capi/thorvg_capi.h b/src/bindings/capi/thorvg_capi.h index d58249d..ea57c1a 100644 --- a/src/bindings/capi/thorvg_capi.h +++ b/src/bindings/capi/thorvg_capi.h @@ -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 diff --git a/src/bindings/capi/tvgCapi.cpp b/src/bindings/capi/tvgCapi.cpp index 19c52c7..ffbb9c3 100644 --- a/src/bindings/capi/tvgCapi.cpp +++ b/src/bindings/capi/tvgCapi.cpp @@ -476,6 +476,13 @@ TVG_EXPORT Tvg_Result tvg_picture_get_size(const Tvg_Paint* paint, float* w, flo return (Tvg_Result) reinterpret_cast(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(CCP(paint))->viewbox(x, y, w, h); +} + /************************************************************************/ /* Gradient API */ /************************************************************************/ diff --git a/src/lib/tvgLoadModule.h b/src/lib/tvgLoadModule.h index 1025b73..70b95b7 100644 --- a/src/lib/tvgLoadModule.h +++ b/src/lib/tvgLoadModule.h @@ -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() {} diff --git a/src/lib/tvgPicture.cpp b/src/lib/tvgPicture.cpp index 26df9f0..790ac97 100644 --- a/src/lib/tvgPicture.cpp +++ b/src/lib/tvgPicture.cpp @@ -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; diff --git a/src/lib/tvgPictureImpl.h b/src/lib/tvgPictureImpl.h index 4d329d3..8d4fd11 100644 --- a/src/lib/tvgPictureImpl.h +++ b/src/lib/tvgPictureImpl.h @@ -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; diff --git a/src/loaders/svg/tvgSvgLoader.h b/src/loaders/svg/tvgSvgLoader.h index 556a92c..01e90d4 100644 --- a/src/loaders/svg/tvgSvgLoader.h +++ b/src/loaders/svg/tvgSvgLoader.h @@ -35,14 +35,7 @@ public: SvgLoaderData loaderData; unique_ptr 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();