mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
common: new api for a grad transformation
The new apii allows to transform the gradient fill.
This commit is contained in:
parent
fe35f69530
commit
e0aa007659
3 changed files with 48 additions and 3 deletions
28
inc/thorvg.h
28
inc/thorvg.h
|
@ -392,10 +392,23 @@ public:
|
|||
*/
|
||||
Result spread(FillSpread s) noexcept;
|
||||
|
||||
/**
|
||||
* @brief Sets the matrix of the affine transformation for the gradient fill.
|
||||
*
|
||||
* The augmented matrix of the transformation is expected to be given.
|
||||
*
|
||||
* @param[in] m The 3x3 augmented matrix.
|
||||
*
|
||||
* @return Result::Success when succeed, Result::FailedAllocation otherwise.
|
||||
*
|
||||
* @BETA_API
|
||||
*/
|
||||
Result transform(const Matrix& m) noexcept;
|
||||
|
||||
/**
|
||||
* @brief Gets the parameters of the colors of the gradient, their position and number.
|
||||
*
|
||||
* @param[in] colorStops A pointer to the memory location, where the array of the gradient's ColorStop is stored.
|
||||
* @param[out] colorStops A pointer to the memory location, where the array of the gradient's ColorStop is stored.
|
||||
*
|
||||
* @return The number of colors used in the gradient. This value corresponds to the length of the @p colorStops array.
|
||||
*/
|
||||
|
@ -408,6 +421,17 @@ public:
|
|||
*/
|
||||
FillSpread spread() const noexcept;
|
||||
|
||||
/**
|
||||
* @brief Gets the matrix of the affine transformation of the gradient fill.
|
||||
*
|
||||
* In case no transformation was applied, the identity matrix is returned.
|
||||
*
|
||||
* @retval The augmented transformation matrix.
|
||||
*
|
||||
* @BETA_API
|
||||
*/
|
||||
Matrix transform() const noexcept;
|
||||
|
||||
/**
|
||||
* @brief Creates a copy of the Fill object.
|
||||
*
|
||||
|
@ -1375,7 +1399,7 @@ public:
|
|||
* It's useful when you need to save the composed scene or image from a paint object and recreate it later.
|
||||
*
|
||||
* The file format is decided by the extension name(i.e. "*.tvg") while the supported formats depend on the TVG packaging environment.
|
||||
* If it doesn't support the file format, the save() method returns the @c NonSuppport result.
|
||||
* If it doesn't support the file format, the save() method returns the @c Result::NonSuppport result.
|
||||
*
|
||||
* Once you export a paint to the file successfully, you can recreate it using the Picture class.
|
||||
*
|
||||
|
|
|
@ -87,6 +87,22 @@ FillSpread Fill::spread() const noexcept
|
|||
}
|
||||
|
||||
|
||||
Result Fill::transform(const Matrix& m) noexcept
|
||||
{
|
||||
if (!pImpl->transform) pImpl->transform = new Matrix();
|
||||
if (!pImpl->transform) return Result::FailedAllocation;
|
||||
*pImpl->transform = m;
|
||||
return Result::Success;
|
||||
}
|
||||
|
||||
|
||||
Matrix Fill::transform() const noexcept
|
||||
{
|
||||
if (pImpl->transform) return *pImpl->transform;
|
||||
return {1, 0, 0, 0, 1, 0, 0, 0, 1};
|
||||
}
|
||||
|
||||
|
||||
Fill* Fill::duplicate() const noexcept
|
||||
{
|
||||
return pImpl->duplicate();
|
||||
|
|
|
@ -50,6 +50,7 @@ struct FillDup : DuplicateMethod<Fill>
|
|||
struct Fill::Impl
|
||||
{
|
||||
ColorStop* colorStops = nullptr;
|
||||
Matrix* transform = nullptr;
|
||||
uint32_t cnt = 0;
|
||||
FillSpread spread;
|
||||
DuplicateMethod<Fill>* dup = nullptr;
|
||||
|
@ -58,6 +59,7 @@ struct Fill::Impl
|
|||
{
|
||||
if (dup) delete(dup);
|
||||
if (colorStops) free(colorStops);
|
||||
if (transform) delete(transform);
|
||||
}
|
||||
|
||||
void method(DuplicateMethod<Fill>* dup)
|
||||
|
@ -74,7 +76,10 @@ struct Fill::Impl
|
|||
ret->pImpl->spread = spread;
|
||||
ret->pImpl->colorStops = static_cast<ColorStop*>(malloc(sizeof(ColorStop) * cnt));
|
||||
memcpy(ret->pImpl->colorStops, colorStops, sizeof(ColorStop) * cnt);
|
||||
|
||||
if (transform) {
|
||||
ret->pImpl->transform = new Matrix;
|
||||
if (ret->pImpl->transform) *ret->pImpl->transform = *transform;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue