mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-09 22:23:27 +00:00
tvg: support dash offset property
properly store/restore the dash offset property from the tvg loader and saver Issue: https://github.com/thorvg/thorvg/issues/1617
This commit is contained in:
parent
c7123a1547
commit
ed23b432bb
3 changed files with 15 additions and 1 deletions
|
@ -322,6 +322,13 @@ static bool _parseShapeStroke(const char *ptr, const char *end, Shape *shape)
|
|||
shape->strokeMiterlimit(miterlimit);
|
||||
break;
|
||||
}
|
||||
case TVG_TAG_SHAPE_STROKE_DASH_OFFSET: {
|
||||
if (block.length != SIZE(float)) return false;
|
||||
float offset;
|
||||
READ_FLOAT(&offset, block.data);
|
||||
P(shape)->rs.stroke->dashOffset = offset;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
TVGLOG("TVG", "Unsupported tag %d (0x%x) used as one of stroke properties, %d bytes skipped", block.type, block.type, block.length);
|
||||
break;
|
||||
|
|
|
@ -82,6 +82,7 @@ using TvgBinFlag = TvgBinByte;
|
|||
#define TVG_TAG_SHAPE_STROKE_DASHPTRN (TvgBinTag)0x55
|
||||
#define TVG_TAG_SHAPE_STROKE_MITERLIMIT (TvgBinTag)0x56
|
||||
#define TVG_TAG_SHAPE_STROKE_ORDER (TvgBinTag)0x57
|
||||
#define TVG_TAG_SHAPE_STROKE_DASH_OFFSET (TvgBinTag)0x58
|
||||
|
||||
|
||||
//Fill
|
||||
|
|
|
@ -469,7 +469,8 @@ TvgBinCounter TvgSaver::serializeStroke(const Shape* shape, const Matrix* pTrans
|
|||
|
||||
//dash
|
||||
const float* dashPattern = nullptr;
|
||||
auto dashCnt = shape->strokeDash(&dashPattern);
|
||||
float offset = 0.0f;
|
||||
auto dashCnt = P(shape)->rs.strokeDash(&dashPattern, &offset);
|
||||
if (dashPattern && dashCnt > 0) {
|
||||
TvgBinCounter dashCntSize = SIZE(dashCnt);
|
||||
TvgBinCounter dashPtrnSize = dashCnt * SIZE(dashPattern[0]);
|
||||
|
@ -487,6 +488,11 @@ TvgBinCounter TvgSaver::serializeStroke(const Shape* shape, const Matrix* pTrans
|
|||
cnt += writeTagProperty(TVG_TAG_SHAPE_STROKE_MITERLIMIT, SIZE(miterlimit), &miterlimit);
|
||||
}
|
||||
|
||||
//dash offset
|
||||
if (!mathZero(offset)) {
|
||||
cnt += writeTagProperty(TVG_TAG_SHAPE_STROKE_DASH_OFFSET, SIZE(offset), &offset);
|
||||
}
|
||||
|
||||
writeReservedCount(cnt);
|
||||
|
||||
return SERIAL_DONE(cnt);
|
||||
|
|
Loading…
Add table
Reference in a new issue