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:
Hermet Park 2023-09-14 15:44:24 +09:00 committed by Hermet Park
parent 00ab8c254d
commit d683d2e70d
2 changed files with 22 additions and 24 deletions

View file

@ -126,14 +126,18 @@ 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;
if (dash.curLen > 0) {
len -= dash.curLen;
_lineSplitAt(cur, dash.curLen, left, right);; _lineSplitAt(cur, dash.curLen, left, right);;
dash.curIdx = (dash.curIdx + 1) % dash.cnt; dash.curIdx = (dash.curIdx + 1) % dash.cnt;
if (!dash.curOpGap) { if (!dash.curOpGap) {
_outlineMoveTo(*dash.outline, &left.pt1, transform); _outlineMoveTo(*dash.outline, &left.pt1, transform);
_outlineLineTo(*dash.outline, &left.pt2, 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;
cur = right; cur = right;
@ -171,6 +175,7 @@ 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;
if (dash.curLen > 0) {
len -= dash.curLen; len -= dash.curLen;
bezSplitAt(cur, dash.curLen, left, right); bezSplitAt(cur, dash.curLen, left, right);
if (!dash.curOpGap) { if (!dash.curOpGap) {
@ -181,6 +186,9 @@ static void _dashCubicTo(SwDashStroke& dash, const Point* ctrl1, const Point* ct
} }
_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];
dash.curOpGap = !dash.curOpGap; dash.curOpGap = !dash.curOpGap;

View file

@ -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;