mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
wg_engine: implement dash offset
Introduced dash offset param for stroke dashes Issue https://github.com/thorvg/thorvg/issues/2592
This commit is contained in:
parent
505ebe9fe6
commit
93ebd388c7
1 changed files with 16 additions and 2 deletions
|
@ -293,6 +293,21 @@ struct WgVertexBufferInd
|
||||||
// starting state
|
// starting state
|
||||||
uint32_t index_dash = 0;
|
uint32_t index_dash = 0;
|
||||||
float len_total = dashPattern[index_dash];
|
float len_total = dashPattern[index_dash];
|
||||||
|
// get dashes length
|
||||||
|
float dashes_lenth{};
|
||||||
|
for (uint32_t i = 0; i < dashCnt; i++)
|
||||||
|
dashes_lenth += dashPattern[i];
|
||||||
|
if (dashes_lenth == 0) return;
|
||||||
|
// normalize dash offset
|
||||||
|
float dashOffset = rstroke->dashOffset;
|
||||||
|
while(dashOffset < 0) dashOffset += dashes_lenth;
|
||||||
|
while(dashOffset > dashes_lenth) dashOffset -= dashes_lenth;
|
||||||
|
// scip dashes by offset
|
||||||
|
while(len_total < dashOffset) {
|
||||||
|
index_dash = (index_dash + 1) % dashCnt;
|
||||||
|
len_total += dashPattern[index_dash];
|
||||||
|
}
|
||||||
|
len_total -= dashOffset;
|
||||||
// iterate by polyline points
|
// iterate by polyline points
|
||||||
for (uint32_t i = 0; i < buff.vcount - 1; i++) {
|
for (uint32_t i = 0; i < buff.vcount - 1; i++) {
|
||||||
// append current polyline point
|
// append current polyline point
|
||||||
|
@ -301,8 +316,7 @@ struct WgVertexBufferInd
|
||||||
// move inside polyline segment
|
// move inside polyline segment
|
||||||
while(len_total < buff.vdist[i+1]) {
|
while(len_total < buff.vdist[i+1]) {
|
||||||
// get current point
|
// get current point
|
||||||
float t = len_total / buff.vdist[i+1];
|
dashed.append(tvg::lerp(buff.vbuff[i], buff.vbuff[i+1], len_total / buff.vdist[i+1]));
|
||||||
dashed.append(buff.vbuff[i] + (buff.vbuff[i+1] - buff.vbuff[i]) * t);
|
|
||||||
// update current state
|
// update current state
|
||||||
index_dash = (index_dash + 1) % dashCnt;
|
index_dash = (index_dash + 1) % dashCnt;
|
||||||
len_total += dashPattern[index_dash];
|
len_total += dashPattern[index_dash];
|
||||||
|
|
Loading…
Add table
Reference in a new issue