From bb4ac2cb7dfbe5c9c74e4e178e2715810c83e824 Mon Sep 17 00:00:00 2001 From: Mira Grudzinska Date: Sat, 11 Sep 2021 11:14:00 +0200 Subject: [PATCH] tvg_saver: proper serialization of a grad fill In the case when a gradinet fill is present, the transformation matrix can't be preapplied. Change-Id: I3346a351a488a7685443eae64c901f4cf185b005 --- src/savers/tvg/tvgTvgSaver.cpp | 42 ++++++++++++++---------------------------- src/savers/tvg/tvgTvgSaver.h | 2 +- 2 files changed, 15 insertions(+), 29 deletions(-) diff --git a/src/savers/tvg/tvgTvgSaver.cpp b/src/savers/tvg/tvgTvgSaver.cpp index 01d2bb7..a9e9b65 100644 --- a/src/savers/tvg/tvgTvgSaver.cpp +++ b/src/savers/tvg/tvgTvgSaver.cpp @@ -401,7 +401,7 @@ TvgBinCounter TvgSaver::serializeScene(const Scene* scene, const Matrix* pTransf } -TvgBinCounter TvgSaver::serializeFill(const Fill* fill, TvgBinTag tag, const Matrix* pTransform) +TvgBinCounter TvgSaver::serializeFill(const Fill* fill, TvgBinTag tag) { const Fill::ColorStop* stops = nullptr; auto stopsCnt = fill->colorStops(&stops); @@ -416,25 +416,11 @@ TvgBinCounter TvgSaver::serializeFill(const Fill* fill, TvgBinTag tag, const Mat if (fill->id() == TVG_CLASS_ID_RADIAL) { float args[3]; static_cast(fill)->radial(args, args + 1, args + 2); - if (pTransform) { - auto cx = args[0] * pTransform->e11 + args[1] * pTransform->e12 + pTransform->e13; - args[1] = args[0] * pTransform->e21 + args[1] * pTransform->e22 + pTransform->e23; - args[0] = cx; - args[2] *= sqrt(pow(pTransform->e11, 2) + pow(pTransform->e21, 2)); - } cnt += writeTagProperty(TVG_TAG_FILL_RADIAL_GRADIENT, SIZE(args), args); //linear fill } else { float args[4]; static_cast(fill)->linear(args, args + 1, args + 2, args + 3); - if (pTransform) { - auto x1 = args[0]; - args[0] = x1 * pTransform->e11 + args[1] * pTransform->e12 + pTransform->e13; - args[1] = x1 * pTransform->e21 + args[1] * pTransform->e22 + pTransform->e23; - auto x2 = args[2]; - args[2] = x2 * pTransform->e11 + args[3] * pTransform->e12 + pTransform->e13; - args[3] = x2 * pTransform->e21 + args[3] * pTransform->e22 + pTransform->e23; - } cnt += writeTagProperty(TVG_TAG_FILL_LINEAR_GRADIENT, SIZE(args), args); } @@ -468,7 +454,7 @@ TvgBinCounter TvgSaver::serializeStroke(const Shape* shape, const Matrix* pTrans //fill if (auto fill = shape->strokeFill()) { - cnt += serializeFill(fill, TVG_TAG_SHAPE_STROKE_FILL, pTransform); + cnt += serializeFill(fill, TVG_TAG_SHAPE_STROKE_FILL); } else { uint8_t color[4] = {0, 0, 0, 0}; shape->strokeColor(color, color + 1, color + 2, color + 3); @@ -550,30 +536,30 @@ TvgBinCounter TvgSaver::serializeShape(const Shape* shape, const Matrix* pTransf cnt = writeTagProperty(TVG_TAG_SHAPE_FILLRULE, SIZE(TvgBinFlag), &flag); } + //the pre-transformation can't be applied in the case where any fill is present or when the stroke is dashed or irregulary scaled bool preTransform = true; + //fill + if (auto fill = shape->fill()) { + preTransform = false; + cnt += serializeFill(fill, TVG_TAG_SHAPE_FILL); + } else { + uint8_t color[4] = {0, 0, 0, 0}; + shape->fillColor(color, color + 1, color + 2, color + 3); + if (color[3] > 0) cnt += writeTagProperty(TVG_TAG_SHAPE_COLOR, SIZE(color), color); + } + //stroke 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) { - //We can't apply pre-transformation if the stroke has the irregular scaling per directions or it has dash. - if (abs(transform.e11 - transform.e22) > FLT_EPSILON || shape->strokeDash(nullptr) > 0) preTransform = false; - + if (fill || abs(transform.e11 - transform.e22) > FLT_EPSILON || shape->strokeDash(nullptr) > 0) preTransform = false; cnt += serializeStroke(shape, &transform, preTransform); } } - //fill - if (auto fill = shape->fill()) { - cnt += serializeFill(fill, TVG_TAG_SHAPE_FILL, &transform); - } else { - uint8_t color[4] = {0, 0, 0, 0}; - shape->fillColor(color, color + 1, color + 2, color + 3); - if (color[3] > 0) cnt += writeTagProperty(TVG_TAG_SHAPE_COLOR, SIZE(color), color); - } - cnt += serializePath(shape, transform, preTransform); if (!preTransform) cnt += writeTransform(transform); diff --git a/src/savers/tvg/tvgTvgSaver.h b/src/savers/tvg/tvgTvgSaver.h index 8839f3c..db37c66 100644 --- a/src/savers/tvg/tvgTvgSaver.h +++ b/src/savers/tvg/tvgTvgSaver.h @@ -57,7 +57,7 @@ private: TvgBinCounter serializeShape(const Shape* shape, const Matrix* pTransform); TvgBinCounter serializePicture(const Picture* picture, const Matrix* pTransform); TvgBinCounter serializePaint(const Paint* paint, const Matrix* pTransform); - TvgBinCounter serializeFill(const Fill* fill, TvgBinTag tag, const Matrix* pTransform); + TvgBinCounter serializeFill(const Fill* fill, TvgBinTag tag); TvgBinCounter serializeStroke(const Shape* shape, const Matrix* pTransform, bool preTransform); TvgBinCounter serializePath(const Shape* shape, const Matrix& transform, bool preTransform); TvgBinCounter serializeComposite(const Paint* cmpTarget, CompositeMethod cmpMethod, const Matrix* pTransform); -- 2.7.4