From 95cd0863eb594bca2c0abaa52ffce70e32bb5b1a Mon Sep 17 00:00:00 2001 From: Mira Grudzinska Date: Thu, 13 Feb 2025 23:42:02 +0100 Subject: [PATCH] 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 --- src/renderer/gl_engine/tvgGlTessellator.cpp | 41 +++++++++++---------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/renderer/gl_engine/tvgGlTessellator.cpp b/src/renderer/gl_engine/tvgGlTessellator.cpp index 54b6a572..200671f1 100644 --- a/src/renderer/gl_engine/tvgGlTessellator.cpp +++ b/src/renderer/gl_engine/tvgGlTessellator.cpp @@ -1999,7 +1999,7 @@ void DashStroke::doStroke(const PathCommand *cmds, uint32_t cmd_count, const Poi case PathCommand::MoveTo: { // reset the dash state mCurrIdx = 0; - mCurrLen = 0.f; + mCurrLen = mDashPattern[0]; mCurOpGap = false; mPtStart = mPtCur = *pts; pts++; @@ -2036,16 +2036,17 @@ void DashStroke::dashLineTo(const Point& to) Line curr = {mPtCur, to}; while (len > mCurrLen) { - len -= mCurrLen; - - Line left, right; - curr.split(mCurrLen, left, right); - + Line right; + if (mCurrLen > 0.0f) { + Line left; + curr.split(mCurrLen, left, right); + len -= mCurrLen; + if (!mCurOpGap) { + this->moveTo(left.pt1); + this->lineTo(left.pt2); + } + } else right = curr; mCurrIdx = (mCurrIdx + 1) % mDashCount; - if (!mCurOpGap) { - this->moveTo(left.pt1); - this->lineTo(left.pt2); - } mCurrLen = mDashPattern[mCurrIdx]; mCurOpGap = !mCurOpGap; curr = right; @@ -2086,16 +2087,16 @@ void DashStroke::dashCubicTo(const Point& cnt1, const Point& cnt2, const Point& } } else { while (len > mCurrLen) { - len -= mCurrLen; - - Bezier left, right; - cur.split(mCurrLen, left, right); - - if (mCurrIdx == 0) { - this->moveTo(left.start); - this->cubicTo(left.ctrl1, left.ctrl2, left.end); - } - + Bezier right; + if (mCurrLen > 0.0f) { + Bezier left; + cur.split(mCurrLen, left, right); + len -= mCurrLen; + if (!mCurOpGap) { + this->moveTo(left.start); + this->cubicTo(left.ctrl1, left.ctrl2, left.end); + } + } else right = cur; mCurrIdx = (mCurrIdx + 1) % mDashCount; mCurrLen = mDashPattern[mCurrIdx]; mCurOpGap = !mCurOpGap;