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.
/*!
-* \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
}
-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);
}
/************************************************************************/
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);
}
-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;
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;
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
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);
}
//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);
}
//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));
//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));
}
//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);
}