mirror of
https://github.com/thorvg/thorvg.git
synced 2025-07-27 08:36:59 +00:00
tvg: support radial gradient focal properties
properly store/restore the radial gradient focal properties from the tvg loader and saver
This commit is contained in:
parent
ed23b432bb
commit
74b67919e0
3 changed files with 31 additions and 2 deletions
|
@ -32,6 +32,7 @@
|
||||||
|
|
||||||
#include "tvgTvgCommon.h"
|
#include "tvgTvgCommon.h"
|
||||||
#include "tvgShape.h"
|
#include "tvgShape.h"
|
||||||
|
#include "tvgFill.h"
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
@ -188,6 +189,25 @@ static unique_ptr<Fill> _parseShapeFill(const char *ptr, const char *end)
|
||||||
fillGrad = std::move(fillGradRadial);
|
fillGrad = std::move(fillGradRadial);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case TVG_TAG_FILL_RADIAL_GRADIENT_FOCAL: {
|
||||||
|
if (block.length != 3 * SIZE(float)) return nullptr;
|
||||||
|
|
||||||
|
auto ptr = block.data;
|
||||||
|
float x, y, radius;
|
||||||
|
|
||||||
|
READ_FLOAT(&x, ptr);
|
||||||
|
ptr += SIZE(float);
|
||||||
|
READ_FLOAT(&y, ptr);
|
||||||
|
ptr += SIZE(float);
|
||||||
|
READ_FLOAT(&radius, ptr);
|
||||||
|
|
||||||
|
if (auto fillGradRadial = static_cast<RadialGradient*>(fillGrad.get())) {
|
||||||
|
P(fillGradRadial)->fx = x;
|
||||||
|
P(fillGradRadial)->fy = y;
|
||||||
|
P(fillGradRadial)->fr = radius;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case TVG_TAG_FILL_LINEAR_GRADIENT: {
|
case TVG_TAG_FILL_LINEAR_GRADIENT: {
|
||||||
if (block.length != 4 * SIZE(float)) return nullptr;
|
if (block.length != 4 * SIZE(float)) return nullptr;
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,7 @@ using TvgBinFlag = TvgBinByte;
|
||||||
#define TVG_TAG_FILL_COLORSTOPS (TvgBinTag)0x62
|
#define TVG_TAG_FILL_COLORSTOPS (TvgBinTag)0x62
|
||||||
#define TVG_TAG_FILL_FILLSPREAD (TvgBinTag)0x63
|
#define TVG_TAG_FILL_FILLSPREAD (TvgBinTag)0x63
|
||||||
#define TVG_TAG_FILL_TRANSFORM (TvgBinTag)0x64
|
#define TVG_TAG_FILL_TRANSFORM (TvgBinTag)0x64
|
||||||
|
#define TVG_TAG_FILL_RADIAL_GRADIENT_FOCAL (TvgBinTag)0x65
|
||||||
|
|
||||||
//Picture
|
//Picture
|
||||||
#define TVG_TAG_PICTURE_RAW_IMAGE (TvgBinTag)0x70
|
#define TVG_TAG_PICTURE_RAW_IMAGE (TvgBinTag)0x70
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "tvgTvgSaver.h"
|
#include "tvgTvgSaver.h"
|
||||||
#include "tvgCompressor.h"
|
#include "tvgCompressor.h"
|
||||||
#include "tvgShape.h"
|
#include "tvgShape.h"
|
||||||
|
#include "tvgFill.h"
|
||||||
#include "tvgPicture.h"
|
#include "tvgPicture.h"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -411,9 +412,17 @@ TvgBinCounter TvgSaver::serializeFill(const Fill* fill, TvgBinTag tag, const Mat
|
||||||
|
|
||||||
//radial fill
|
//radial fill
|
||||||
if (fill->identifier() == TVG_CLASS_ID_RADIAL) {
|
if (fill->identifier() == TVG_CLASS_ID_RADIAL) {
|
||||||
|
const RadialGradient* radial = static_cast<const RadialGradient*>(fill);
|
||||||
float args[3];
|
float args[3];
|
||||||
static_cast<const RadialGradient*>(fill)->radial(args, args + 1, args + 2);
|
radial->radial(args, args + 1, args + 2);
|
||||||
cnt += writeTagProperty(TVG_TAG_FILL_RADIAL_GRADIENT, SIZE(args), args);
|
cnt += writeTagProperty(TVG_TAG_FILL_RADIAL_GRADIENT, SIZE(args), args);
|
||||||
|
//focal
|
||||||
|
if (!mathZero(P(radial)->fx)|| !mathZero(P(radial)->fy) || P(radial)->fr > 0.0f) {
|
||||||
|
args[0] = P(radial)->fx;
|
||||||
|
args[1] = P(radial)->fy;
|
||||||
|
args[2] = P(radial)->fr;
|
||||||
|
cnt += writeTagProperty(TVG_TAG_FILL_RADIAL_GRADIENT_FOCAL, SIZE(args), args);
|
||||||
|
}
|
||||||
//linear fill
|
//linear fill
|
||||||
} else {
|
} else {
|
||||||
float args[4];
|
float args[4];
|
||||||
|
|
Loading…
Add table
Reference in a new issue