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
This commit is contained in:
Hermet Park 2023-07-28 13:09:25 +09:00 committed by Hermet Park
parent 1b7c882be4
commit a74062d5f1
4 changed files with 27 additions and 3 deletions

View file

@ -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

View file

@ -24,6 +24,7 @@
#define _TVG_SHAPE_IMPL_H_
#include <memory.h>
#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();

View file

@ -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;

View file

@ -20,12 +20,12 @@
* SOFTWARE.
*/
#include "tvgMath.h"
#include <cstring>
#include "tvgSaveModule.h"
#include "tvgTvgSaver.h"
#include "tvgLzw.h"
#include <cstring>
#include "tvgShapeImpl.h"
#ifdef _WIN32
#include <malloc.h>
@ -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<TvgBinFlag>(shape->strokeJoin()))
cnt += writeTagProperty(TVG_TAG_SHAPE_STROKE_JOIN, SIZE(TvgBinFlag), &flag);
//order
if (auto flag = static_cast<TvgBinFlag>(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));