mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
sw_engine: Do not handle exceptions for zero line length.
While it may represent a dot with a stroke width, ignoring its length is not a good idea. this also eliminates 0 size dash dots caused by unexpected empty lengths.
This commit is contained in:
parent
00ab8c254d
commit
d683d2e70d
2 changed files with 22 additions and 24 deletions
|
@ -126,13 +126,17 @@ static void _dashLineTo(SwDashStroke& dash, const Point* to, const Matrix* trans
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
while (len > dash.curLen) {
|
while (len > dash.curLen) {
|
||||||
len -= dash.curLen;
|
|
||||||
Line left, right;
|
Line left, right;
|
||||||
_lineSplitAt(cur, dash.curLen, left, right);;
|
if (dash.curLen > 0) {
|
||||||
dash.curIdx = (dash.curIdx + 1) % dash.cnt;
|
len -= dash.curLen;
|
||||||
if (!dash.curOpGap) {
|
_lineSplitAt(cur, dash.curLen, left, right);;
|
||||||
_outlineMoveTo(*dash.outline, &left.pt1, transform);
|
dash.curIdx = (dash.curIdx + 1) % dash.cnt;
|
||||||
_outlineLineTo(*dash.outline, &left.pt2, transform);
|
if (!dash.curOpGap) {
|
||||||
|
_outlineMoveTo(*dash.outline, &left.pt1, transform);
|
||||||
|
_outlineLineTo(*dash.outline, &left.pt2, transform);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
right = cur;
|
||||||
}
|
}
|
||||||
dash.curLen = dash.pattern[dash.curIdx];
|
dash.curLen = dash.pattern[dash.curIdx];
|
||||||
dash.curOpGap = !dash.curOpGap;
|
dash.curOpGap = !dash.curOpGap;
|
||||||
|
@ -171,15 +175,19 @@ static void _dashCubicTo(SwDashStroke& dash, const Point* ctrl1, const Point* ct
|
||||||
bool begin = true; //starting with move_to
|
bool begin = true; //starting with move_to
|
||||||
while (len > dash.curLen) {
|
while (len > dash.curLen) {
|
||||||
Bezier left, right;
|
Bezier left, right;
|
||||||
len -= dash.curLen;
|
if (dash.curLen > 0) {
|
||||||
bezSplitAt(cur, dash.curLen, left, right);
|
len -= dash.curLen;
|
||||||
if (!dash.curOpGap) {
|
bezSplitAt(cur, dash.curLen, left, right);
|
||||||
// leftovers from a previous command don't require moveTo
|
if (!dash.curOpGap) {
|
||||||
if (begin || dash.pattern[dash.curIdx] - dash.curLen < FLT_EPSILON) {
|
// leftovers from a previous command don't require moveTo
|
||||||
_outlineMoveTo(*dash.outline, &left.start, transform);
|
if (begin || dash.pattern[dash.curIdx] - dash.curLen < FLT_EPSILON) {
|
||||||
begin = false;
|
_outlineMoveTo(*dash.outline, &left.start, transform);
|
||||||
|
begin = false;
|
||||||
|
}
|
||||||
|
_outlineCubicTo(*dash.outline, &left.ctrl1, &left.ctrl2, &left.end, transform);
|
||||||
}
|
}
|
||||||
_outlineCubicTo(*dash.outline, &left.ctrl1, &left.ctrl2, &left.end, transform);
|
} else {
|
||||||
|
right = cur;
|
||||||
}
|
}
|
||||||
dash.curIdx = (dash.curIdx + 1) % dash.cnt;
|
dash.curIdx = (dash.curIdx + 1) % dash.cnt;
|
||||||
dash.curLen = dash.pattern[dash.curIdx];
|
dash.curLen = dash.pattern[dash.curIdx];
|
||||||
|
|
|
@ -373,10 +373,6 @@ void _firstSubPath(SwStroke& stroke, SwFixed startAngle, SwFixed lineLength)
|
||||||
static void _lineTo(SwStroke& stroke, const SwPoint& to)
|
static void _lineTo(SwStroke& stroke, const SwPoint& to)
|
||||||
{
|
{
|
||||||
auto delta = to - stroke.center;
|
auto delta = to - stroke.center;
|
||||||
|
|
||||||
//a zero-length lineto is a no-op; avoid creating a spurious corner
|
|
||||||
if (delta.zero()) return;
|
|
||||||
|
|
||||||
//compute length of line
|
//compute length of line
|
||||||
auto angle = mathAtan(delta);
|
auto angle = mathAtan(delta);
|
||||||
|
|
||||||
|
@ -428,12 +424,6 @@ static void _lineTo(SwStroke& stroke, const SwPoint& to)
|
||||||
|
|
||||||
static void _cubicTo(SwStroke& stroke, const SwPoint& ctrl1, const SwPoint& ctrl2, const SwPoint& to)
|
static void _cubicTo(SwStroke& stroke, const SwPoint& ctrl1, const SwPoint& ctrl2, const SwPoint& to)
|
||||||
{
|
{
|
||||||
//if all control points are coincident, this is a no-op; avoid creating a spurious corner
|
|
||||||
if ((stroke.center - ctrl1).small() && (ctrl1 - ctrl2).small() && (ctrl2 - to).small()) {
|
|
||||||
stroke.center = to;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SwPoint bezStack[37]; //TODO: static?
|
SwPoint bezStack[37]; //TODO: static?
|
||||||
auto limit = bezStack + 32;
|
auto limit = bezStack + 32;
|
||||||
auto arc = bezStack;
|
auto arc = bezStack;
|
||||||
|
|
Loading…
Add table
Reference in a new issue