From a74062d5f1e2d169ae1b0a7458b9840e12583d61 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Fri, 28 Jul 2023 13:09:25 +0900 Subject: [PATCH] loader tvg: add missing strokeFirst property. tvg binary missed the stroke order, this patch implements the missing condition. @Issue: https://github.com/thorvg/thorvg/issues/1499 --- src/lib/tvgBinaryDesc.h | 1 + src/lib/tvgShapeImpl.h | 7 +++++++ src/loaders/tvg/tvgTvgBinInterpreter.cpp | 8 ++++++++ src/savers/tvg/tvgTvgSaver.cpp | 14 +++++++++++--- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/lib/tvgBinaryDesc.h b/src/lib/tvgBinaryDesc.h index eb677d4f..3b9dbe89 100644 --- a/src/lib/tvgBinaryDesc.h +++ b/src/lib/tvgBinaryDesc.h @@ -81,6 +81,7 @@ using TvgBinFlag = TvgBinByte; #define TVG_TAG_SHAPE_STROKE_FILL (TvgBinTag)0x54 #define TVG_TAG_SHAPE_STROKE_DASHPTRN (TvgBinTag)0x55 #define TVG_TAG_SHAPE_STROKE_MITERLIMIT (TvgBinTag)0x56 +#define TVG_TAG_SHAPE_STROKE_ORDER (TvgBinTag)0x57 //Fill diff --git a/src/lib/tvgShapeImpl.h b/src/lib/tvgShapeImpl.h index 33666944..b05f85bf 100644 --- a/src/lib/tvgShapeImpl.h +++ b/src/lib/tvgShapeImpl.h @@ -24,6 +24,7 @@ #define _TVG_SHAPE_IMPL_H_ #include +#include "tvgMath.h" #include "tvgPaint.h" /************************************************************************/ @@ -294,6 +295,12 @@ struct Shape::Impl return true; } + bool strokeFirst() + { + if (!rs.stroke) return true; + return rs.stroke->strokeFirst; + } + bool strokeFirst(bool strokeFirst) { if (!rs.stroke) rs.stroke = new RenderStroke(); diff --git a/src/loaders/tvg/tvgTvgBinInterpreter.cpp b/src/loaders/tvg/tvgTvgBinInterpreter.cpp index 8389cf59..284c068b 100644 --- a/src/loaders/tvg/tvgTvgBinInterpreter.cpp +++ b/src/loaders/tvg/tvgTvgBinInterpreter.cpp @@ -31,8 +31,11 @@ #endif #include "tvgTvgCommon.h" +#include "tvgShapeImpl.h" +#define P(A) A->pImpl + /************************************************************************/ /* Internal Class Implementation */ /************************************************************************/ @@ -287,6 +290,11 @@ static bool _parseShapeStroke(const char *ptr, const char *end, Shape *shape) shape->stroke((StrokeJoin) *block.data); break; } + case TVG_TAG_SHAPE_STROKE_ORDER: { + if (block.length != SIZE(TvgBinFlag)) return false; + P(shape)->strokeFirst((bool) *block.data); + break; + } case TVG_TAG_SHAPE_STROKE_WIDTH: { if (block.length != SIZE(float)) return false; float width; diff --git a/src/savers/tvg/tvgTvgSaver.cpp b/src/savers/tvg/tvgTvgSaver.cpp index c1ceacae..b75ac0e3 100644 --- a/src/savers/tvg/tvgTvgSaver.cpp +++ b/src/savers/tvg/tvgTvgSaver.cpp @@ -20,12 +20,12 @@ * SOFTWARE. */ -#include "tvgMath.h" +#include + #include "tvgSaveModule.h" #include "tvgTvgSaver.h" #include "tvgLzw.h" - -#include +#include "tvgShapeImpl.h" #ifdef _WIN32 #include @@ -51,6 +51,8 @@ static FILE* _fopen(const char* filename, const char* mode) #define SIZE(A) sizeof(A) +#define P(A) A->pImpl + /************************************************************************/ /* Internal Class Implementation */ /************************************************************************/ @@ -98,6 +100,8 @@ static bool _merge(Shape* from, Shape* to) } //stroke + if (P(from)->strokeFirst() != P(to)->strokeFirst()) return false; + r = g = b = a = r2 = g2 = b2 = a2 = 0; from->strokeColor(&r, &g, &b, &a); @@ -455,6 +459,10 @@ TvgBinCounter TvgSaver::serializeStroke(const Shape* shape, const Matrix* pTrans if (auto flag = static_cast(shape->strokeJoin())) cnt += writeTagProperty(TVG_TAG_SHAPE_STROKE_JOIN, SIZE(TvgBinFlag), &flag); + //order + if (auto flag = static_cast(P(shape)->strokeFirst())) + writeTagProperty(TVG_TAG_SHAPE_STROKE_ORDER, SIZE(TvgBinFlag), &flag); + //fill if (auto fill = shape->strokeFill()) { cnt += serializeFill(fill, TVG_TAG_SHAPE_STROKE_FILL, (preTransform ? pTransform : nullptr));