gl_engine: fix dashing

Incorrect condition for drawing segments in cubics;
missing checks.

@Issue: https://github.com/thorvg/thorvg/issues/2729
@Issue: https://github.com/thorvg/thorvg/issues/3222
This commit is contained in:
Mira Grudzinska 2025-02-13 23:42:02 +01:00 committed by Hermet Park
parent ac08a9d6e7
commit 95cd0863eb

View file

@ -1999,7 +1999,7 @@ void DashStroke::doStroke(const PathCommand *cmds, uint32_t cmd_count, const Poi
case PathCommand::MoveTo: { case PathCommand::MoveTo: {
// reset the dash state // reset the dash state
mCurrIdx = 0; mCurrIdx = 0;
mCurrLen = 0.f; mCurrLen = mDashPattern[0];
mCurOpGap = false; mCurOpGap = false;
mPtStart = mPtCur = *pts; mPtStart = mPtCur = *pts;
pts++; pts++;
@ -2036,16 +2036,17 @@ void DashStroke::dashLineTo(const Point& to)
Line curr = {mPtCur, to}; Line curr = {mPtCur, to};
while (len > mCurrLen) { while (len > mCurrLen) {
len -= mCurrLen; Line right;
if (mCurrLen > 0.0f) {
Line left, right; Line left;
curr.split(mCurrLen, left, right); curr.split(mCurrLen, left, right);
len -= mCurrLen;
mCurrIdx = (mCurrIdx + 1) % mDashCount;
if (!mCurOpGap) { if (!mCurOpGap) {
this->moveTo(left.pt1); this->moveTo(left.pt1);
this->lineTo(left.pt2); this->lineTo(left.pt2);
} }
} else right = curr;
mCurrIdx = (mCurrIdx + 1) % mDashCount;
mCurrLen = mDashPattern[mCurrIdx]; mCurrLen = mDashPattern[mCurrIdx];
mCurOpGap = !mCurOpGap; mCurOpGap = !mCurOpGap;
curr = right; curr = right;
@ -2086,16 +2087,16 @@ void DashStroke::dashCubicTo(const Point& cnt1, const Point& cnt2, const Point&
} }
} else { } else {
while (len > mCurrLen) { while (len > mCurrLen) {
len -= mCurrLen; Bezier right;
if (mCurrLen > 0.0f) {
Bezier left, right; Bezier left;
cur.split(mCurrLen, left, right); cur.split(mCurrLen, left, right);
len -= mCurrLen;
if (mCurrIdx == 0) { if (!mCurOpGap) {
this->moveTo(left.start); this->moveTo(left.start);
this->cubicTo(left.ctrl1, left.ctrl2, left.end); this->cubicTo(left.ctrl1, left.ctrl2, left.end);
} }
} else right = cur;
mCurrIdx = (mCurrIdx + 1) % mDashCount; mCurrIdx = (mCurrIdx + 1) % mDashCount;
mCurrLen = mDashPattern[mCurrIdx]; mCurrLen = mDashPattern[mCurrIdx];
mCurOpGap = !mCurOpGap; mCurOpGap = !mCurOpGap;