wg_engine: handle properly odd numbers of dashes/gaps

If the provided list has an odd number of values, then it
should be repeated to yield an even number of values.

@Issue: https://github.com/thorvg/thorvg/issues/3205
This commit is contained in:
Mira Grudzinska 2025-02-13 15:47:39 +01:00 committed by Sergii Liebodkin
parent 391777091c
commit ddcbbf771f

View file

@ -309,10 +309,10 @@ struct WgVertexBufferInd
}
len_total -= dashOffset;
// iterate by polyline points
auto gap = false;
for (uint32_t i = 0; i < buff.vcount - 1; i++) {
// append current polyline point
if (index_dash % 2 == 0)
dashed.append(buff.vbuff[i]);
if (!gap) dashed.append(buff.vbuff[i]);
// move inside polyline segment
while(len_total < buff.vdist[i+1]) {
// get current point
@ -321,17 +321,18 @@ struct WgVertexBufferInd
index_dash = (index_dash + 1) % dashCnt;
len_total += dashPattern[index_dash];
// preceed stroke if dash
if (index_dash % 2 != 0) {
if (!gap) {
dashed.updateDistances();
appendStrokes(dashed, rstroke);
dashed.reset(tscale);
}
gap = !gap;
}
// update current subline length
len_total -= buff.vdist[i+1];
}
// draw last subline
if (index_dash % 2 == 0) {
if (!gap) {
dashed.append(buff.last());
dashed.updateDistances();
appendStrokes(dashed, rstroke);