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,13 +126,17 @@ static void _dashLineTo(SwDashStroke& dash, const Point* to, const Matrix* trans
}
} else {
while (len > dash.curLen) {
len -= dash.curLen;
Line left, right;
_lineSplitAt(cur, dash.curLen, left, right);;
dash.curIdx = (dash.curIdx + 1) % dash.cnt;
if (!dash.curOpGap) {
_outlineMoveTo(*dash.outline, &left.pt1, transform);
_outlineLineTo(*dash.outline, &left.pt2, transform);
if (dash.curLen > 0) {
len -= dash.curLen;
_lineSplitAt(cur, dash.curLen, left, right);;
dash.curIdx = (dash.curIdx + 1) % dash.cnt;
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.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
while (len > dash.curLen) {
Bezier left, right;
len -= dash.curLen;
bezSplitAt(cur, dash.curLen, left, right);
if (!dash.curOpGap) {
// leftovers from a previous command don't require moveTo
if (begin || dash.pattern[dash.curIdx] - dash.curLen < FLT_EPSILON) {
_outlineMoveTo(*dash.outline, &left.start, transform);
begin = false;
if (dash.curLen > 0) {
len -= dash.curLen;
bezSplitAt(cur, dash.curLen, left, right);
if (!dash.curOpGap) {
// leftovers from a previous command don't require moveTo
if (begin || dash.pattern[dash.curIdx] - dash.curLen < FLT_EPSILON) {
_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.curLen = dash.pattern[dash.curIdx];

View file

@ -373,10 +373,6 @@ void _firstSubPath(SwStroke& stroke, SwFixed startAngle, SwFixed lineLength)
static void _lineTo(SwStroke& stroke, const SwPoint& to)
{
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
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)
{
//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?
auto limit = bezStack + 32;
auto arc = bezStack;