mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 05:33:36 +00:00
gl_engine: fix line join while dashing
While dashing, changing the path command each time caused a new 'move to' command to be added, even when dash segments across different path commands should have been connected. @Issue: https://github.com/thorvg/thorvg/issues/3231
This commit is contained in:
parent
9a2d1136de
commit
2c73da0e20
2 changed files with 37 additions and 10 deletions
|
@ -1960,6 +1960,7 @@ DashStroke::DashStroke(Array<PathCommand> *cmds, Array<Point> *pts, uint32_t das
|
||||||
mCurrLen(),
|
mCurrLen(),
|
||||||
mCurrIdx(),
|
mCurrIdx(),
|
||||||
mCurOpGap(false),
|
mCurOpGap(false),
|
||||||
|
mMove(true),
|
||||||
mPtStart(),
|
mPtStart(),
|
||||||
mPtCur()
|
mPtCur()
|
||||||
{
|
{
|
||||||
|
@ -1999,6 +2000,7 @@ void DashStroke::doStroke(const PathCommand *cmds, uint32_t cmd_count, const Poi
|
||||||
mCurrIdx = idx;
|
mCurrIdx = idx;
|
||||||
mCurrLen = mDashPattern[idx] - offset;
|
mCurrLen = mDashPattern[idx] - offset;
|
||||||
mCurOpGap = gap;
|
mCurOpGap = gap;
|
||||||
|
mMove = true;
|
||||||
mPtStart = mPtCur = *pts;
|
mPtStart = mPtCur = *pts;
|
||||||
pts++;
|
pts++;
|
||||||
break;
|
break;
|
||||||
|
@ -2024,23 +2026,31 @@ void DashStroke::dashLineTo(const Point& to)
|
||||||
{
|
{
|
||||||
auto len = length(mPtCur - to);
|
auto len = length(mPtCur - to);
|
||||||
|
|
||||||
if (len < mCurrLen) {
|
if (tvg::zero(len)) {
|
||||||
|
this->moveTo(mPtCur);
|
||||||
|
} else if (len <= mCurrLen) {
|
||||||
mCurrLen -= len;
|
mCurrLen -= len;
|
||||||
if (!mCurOpGap) {
|
if (!mCurOpGap) {
|
||||||
this->moveTo(mPtCur);
|
if (mMove) {
|
||||||
|
this->moveTo(mPtCur);
|
||||||
|
mMove = false;
|
||||||
|
}
|
||||||
this->lineTo(to);
|
this->lineTo(to);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Line curr = {mPtCur, to};
|
Line curr = {mPtCur, to};
|
||||||
|
|
||||||
while (len > mCurrLen) {
|
while (len - mCurrLen > 0.0001f) {
|
||||||
Line right;
|
Line right;
|
||||||
if (mCurrLen > 0.0f) {
|
if (mCurrLen > 0.0f) {
|
||||||
Line left;
|
Line left;
|
||||||
curr.split(mCurrLen, left, right);
|
curr.split(mCurrLen, left, right);
|
||||||
len -= mCurrLen;
|
len -= mCurrLen;
|
||||||
if (!mCurOpGap) {
|
if (!mCurOpGap) {
|
||||||
this->moveTo(left.pt1);
|
if (mMove || mDashPattern[mCurrIdx] - mCurrLen < FLOAT_EPSILON) {
|
||||||
|
this->moveTo(left.pt1);
|
||||||
|
mMove = false;
|
||||||
|
}
|
||||||
this->lineTo(left.pt2);
|
this->lineTo(left.pt2);
|
||||||
}
|
}
|
||||||
} else right = curr;
|
} else right = curr;
|
||||||
|
@ -2049,10 +2059,14 @@ void DashStroke::dashLineTo(const Point& to)
|
||||||
mCurOpGap = !mCurOpGap;
|
mCurOpGap = !mCurOpGap;
|
||||||
curr = right;
|
curr = right;
|
||||||
mPtCur = curr.pt1;
|
mPtCur = curr.pt1;
|
||||||
|
mMove = true;
|
||||||
}
|
}
|
||||||
mCurrLen -= len;
|
mCurrLen -= len;
|
||||||
if (!mCurOpGap) {
|
if (!mCurOpGap) {
|
||||||
this->moveTo(curr.pt1);
|
if (mMove) {
|
||||||
|
this->moveTo(curr.pt1);
|
||||||
|
mMove = false;
|
||||||
|
}
|
||||||
this->lineTo(curr.pt2);
|
this->lineTo(curr.pt2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2077,21 +2091,29 @@ void DashStroke::dashCubicTo(const Point& cnt1, const Point& cnt2, const Point&
|
||||||
|
|
||||||
auto len = cur.length();
|
auto len = cur.length();
|
||||||
|
|
||||||
if (len < mCurrLen) {
|
if (tvg::zero(len)) {
|
||||||
|
this->moveTo(mPtCur);
|
||||||
|
} else if (len <= mCurrLen) {
|
||||||
mCurrLen -= len;
|
mCurrLen -= len;
|
||||||
if (!mCurOpGap) {
|
if (!mCurOpGap) {
|
||||||
this->moveTo(mPtCur);
|
if (mMove) {
|
||||||
|
this->moveTo(mPtCur);
|
||||||
|
mMove = false;
|
||||||
|
}
|
||||||
this->cubicTo(cnt1, cnt2, end);
|
this->cubicTo(cnt1, cnt2, end);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
while (len > mCurrLen) {
|
while (len - mCurrLen > 0.0001f) {
|
||||||
Bezier right;
|
Bezier right;
|
||||||
if (mCurrLen > 0.0f) {
|
if (mCurrLen > 0.0f) {
|
||||||
Bezier left;
|
Bezier left;
|
||||||
cur.split(mCurrLen, left, right);
|
cur.split(mCurrLen, left, right);
|
||||||
len -= mCurrLen;
|
len -= mCurrLen;
|
||||||
if (!mCurOpGap) {
|
if (!mCurOpGap) {
|
||||||
this->moveTo(left.start);
|
if (mMove || mDashPattern[mCurrIdx] - mCurrLen < FLOAT_EPSILON) {
|
||||||
|
this->moveTo(left.start);
|
||||||
|
mMove = false;
|
||||||
|
}
|
||||||
this->cubicTo(left.ctrl1, left.ctrl2, left.end);
|
this->cubicTo(left.ctrl1, left.ctrl2, left.end);
|
||||||
}
|
}
|
||||||
} else right = cur;
|
} else right = cur;
|
||||||
|
@ -2100,11 +2122,15 @@ void DashStroke::dashCubicTo(const Point& cnt1, const Point& cnt2, const Point&
|
||||||
mCurOpGap = !mCurOpGap;
|
mCurOpGap = !mCurOpGap;
|
||||||
cur = right;
|
cur = right;
|
||||||
mPtCur = cur.start;
|
mPtCur = cur.start;
|
||||||
|
mMove = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
mCurrLen -= len;
|
mCurrLen -= len;
|
||||||
if (!mCurOpGap) {
|
if (!mCurOpGap) {
|
||||||
this->moveTo(cur.start);
|
if (mMove) {
|
||||||
|
this->moveTo(cur.start);
|
||||||
|
mMove = false;
|
||||||
|
}
|
||||||
this->cubicTo(cur.ctrl1, cur.ctrl2, cur.end);
|
this->cubicTo(cur.ctrl1, cur.ctrl2, cur.end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -139,6 +139,7 @@ private:
|
||||||
float mCurrLen;
|
float mCurrLen;
|
||||||
int32_t mCurrIdx;
|
int32_t mCurrIdx;
|
||||||
bool mCurOpGap;
|
bool mCurOpGap;
|
||||||
|
bool mMove;
|
||||||
Point mPtStart;
|
Point mPtStart;
|
||||||
Point mPtCur;
|
Point mPtCur;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue