mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 12:04:29 +00:00
tvg_saver: removing saving the default values
The default values (stroke cap/join, fill rule/spread or color with alpha = 0) were unnecessarily saved in the tvg format file.
This commit is contained in:
parent
82c7a96628
commit
18f4b96786
2 changed files with 24 additions and 18 deletions
|
@ -127,7 +127,7 @@ TvgBinCounter TvgSaver::writeTagProperty(TvgBinTag tag, TvgBinCounter cnt, const
|
||||||
return growCnt;
|
return growCnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TvgBinCounter TvgSaver::serializePaint(const Paint* paint)
|
TvgBinCounter TvgSaver::serializePaint(const Paint* paint)
|
||||||
{
|
{
|
||||||
TvgBinCounter cnt = 0;
|
TvgBinCounter cnt = 0;
|
||||||
|
@ -193,8 +193,8 @@ TvgBinCounter TvgSaver::serializeFill(const Fill* fill, TvgBinTag tag)
|
||||||
cnt += writeTagProperty(TVG_TAG_FILL_LINEAR_GRADIENT, sizeof(args), args);
|
cnt += writeTagProperty(TVG_TAG_FILL_LINEAR_GRADIENT, sizeof(args), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto flag = static_cast<TvgBinFlag>(fill->spread());
|
if (auto flag = static_cast<TvgBinFlag>(fill->spread()))
|
||||||
cnt += writeTagProperty(TVG_TAG_FILL_FILLSPREAD, SIZE(TvgBinFlag), &flag);
|
cnt += writeTagProperty(TVG_TAG_FILL_FILLSPREAD, SIZE(TvgBinFlag), &flag);
|
||||||
cnt += writeTagProperty(TVG_TAG_FILL_COLORSTOPS, stopsCnt * sizeof(stops), stops);
|
cnt += writeTagProperty(TVG_TAG_FILL_COLORSTOPS, stopsCnt * sizeof(stops), stops);
|
||||||
|
|
||||||
writeReservedCount(cnt);
|
writeReservedCount(cnt);
|
||||||
|
@ -208,17 +208,17 @@ TvgBinCounter TvgSaver::serializeStroke(const Shape* shape)
|
||||||
writeTag(TVG_TAG_SHAPE_STROKE);
|
writeTag(TVG_TAG_SHAPE_STROKE);
|
||||||
reserveCount();
|
reserveCount();
|
||||||
|
|
||||||
//cap
|
|
||||||
auto flag = static_cast<TvgBinFlag>(shape->strokeCap());
|
|
||||||
auto cnt = writeTagProperty(TVG_TAG_SHAPE_STROKE_CAP, SIZE(TvgBinFlag), &flag);
|
|
||||||
|
|
||||||
//join
|
|
||||||
flag = static_cast<TvgBinFlag>(shape->strokeJoin());
|
|
||||||
cnt += writeTagProperty(TVG_TAG_SHAPE_STROKE_JOIN, SIZE(TvgBinFlag), &flag);
|
|
||||||
|
|
||||||
//width
|
//width
|
||||||
auto width = shape->strokeWidth();
|
auto width = shape->strokeWidth();
|
||||||
cnt += writeTagProperty(TVG_TAG_SHAPE_STROKE_WIDTH, sizeof(width), &width);
|
auto cnt = writeTagProperty(TVG_TAG_SHAPE_STROKE_WIDTH, sizeof(width), &width);
|
||||||
|
|
||||||
|
//cap
|
||||||
|
if (auto flag = static_cast<TvgBinFlag>(shape->strokeCap()))
|
||||||
|
cnt += writeTagProperty(TVG_TAG_SHAPE_STROKE_CAP, SIZE(TvgBinFlag), &flag);
|
||||||
|
|
||||||
|
//join
|
||||||
|
if (auto flag = static_cast<TvgBinFlag>(shape->strokeJoin()))
|
||||||
|
cnt += writeTagProperty(TVG_TAG_SHAPE_STROKE_JOIN, SIZE(TvgBinFlag), &flag);
|
||||||
|
|
||||||
//fill
|
//fill
|
||||||
if (auto fill = shape->strokeFill()) {
|
if (auto fill = shape->strokeFill()) {
|
||||||
|
@ -276,13 +276,19 @@ TvgBinCounter TvgSaver::serializeShape(const Shape* shape)
|
||||||
{
|
{
|
||||||
writeTag(TVG_TAG_CLASS_SHAPE);
|
writeTag(TVG_TAG_CLASS_SHAPE);
|
||||||
reserveCount();
|
reserveCount();
|
||||||
|
TvgBinCounter cnt = 0;
|
||||||
|
|
||||||
//fill rule
|
//fill rule
|
||||||
auto flag = (shape->fillRule() == FillRule::EvenOdd) ? TVG_FLAG_SHAPE_FILLRULE_EVENODD : TVG_FLAG_SHAPE_FILLRULE_WINDING;
|
if (auto flag = static_cast<TvgBinFlag>(shape->fillRule()))
|
||||||
auto cnt = writeTagProperty(TVG_TAG_SHAPE_FILLRULE, SIZE(TvgBinFlag), &flag);
|
cnt = writeTagProperty(TVG_TAG_SHAPE_FILLRULE, SIZE(TvgBinFlag), &flag);
|
||||||
|
|
||||||
//stroke
|
//stroke
|
||||||
if (shape->strokeWidth() > 0) cnt += serializeStroke(shape);
|
if (shape->strokeWidth() > 0) {
|
||||||
|
uint8_t color[4] = {0, 0, 0, 0};
|
||||||
|
shape->strokeColor(color, color + 1, color + 2, color + 3);
|
||||||
|
auto fill = shape->strokeFill();
|
||||||
|
if (fill || color[3] > 0) cnt += serializeStroke(shape);
|
||||||
|
}
|
||||||
|
|
||||||
//fill
|
//fill
|
||||||
if (auto fill = shape->fill()) {
|
if (auto fill = shape->fill()) {
|
||||||
|
@ -290,7 +296,7 @@ TvgBinCounter TvgSaver::serializeShape(const Shape* shape)
|
||||||
} else {
|
} else {
|
||||||
uint8_t color[4] = {0, 0, 0, 0};
|
uint8_t color[4] = {0, 0, 0, 0};
|
||||||
shape->fillColor(color, color + 1, color + 2, color + 3);
|
shape->fillColor(color, color + 1, color + 2, color + 3);
|
||||||
cnt += writeTagProperty(TVG_TAG_SHAPE_COLOR, sizeof(color), color);
|
if (color[3] > 0) cnt += writeTagProperty(TVG_TAG_SHAPE_COLOR, sizeof(color), color);
|
||||||
}
|
}
|
||||||
|
|
||||||
cnt += serializePath(shape);
|
cnt += serializePath(shape);
|
||||||
|
@ -431,4 +437,4 @@ bool TvgSaver::save(Paint* paint, const string& path)
|
||||||
TaskScheduler::request(this);
|
TaskScheduler::request(this);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,4 +67,4 @@ public:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //_TVG_SAVE_MODULE_H_
|
#endif //_TVG_SAVE_MODULE_H_
|
||||||
|
|
Loading…
Add table
Reference in a new issue