mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-09 06:04:03 +00:00
wg_engine: fix strokes failers and visual atrifacts
Ignoring rezo-width strokes, single point strokes. Fix visual artifacts in case of mitter joints.
This commit is contained in:
parent
43464ceba4
commit
419fa93989
2 changed files with 18 additions and 30 deletions
|
@ -310,11 +310,9 @@ void WgGeometryData::appendStrokeDashed(const WgPolyline* polyline, const Render
|
||||||
assert(polyline);
|
assert(polyline);
|
||||||
static WgPolyline dashed;
|
static WgPolyline dashed;
|
||||||
dashed.clear();
|
dashed.clear();
|
||||||
// append single point polyline
|
// ignore singpe points polyline
|
||||||
if (polyline->pts.count == 1)
|
|
||||||
appendStroke(polyline, stroke);
|
|
||||||
// append multy points dashed polyline
|
// append multy points dashed polyline
|
||||||
else if (polyline->pts.count >= 2) {
|
if (polyline->pts.count >= 2) {
|
||||||
auto& pts = polyline->pts;
|
auto& pts = polyline->pts;
|
||||||
auto& dist = polyline->dist;
|
auto& dist = polyline->dist;
|
||||||
// starting state
|
// starting state
|
||||||
|
@ -357,21 +355,6 @@ void WgGeometryData::appendStroke(const WgPolyline* polyline, const RenderStroke
|
||||||
assert(stroke);
|
assert(stroke);
|
||||||
assert(polyline);
|
assert(polyline);
|
||||||
float wdt = stroke->width / 2;
|
float wdt = stroke->width / 2;
|
||||||
// single point sub-path
|
|
||||||
if (polyline->pts.count == 1) {
|
|
||||||
if (stroke->cap == StrokeCap::Round) {
|
|
||||||
appendCircle(polyline->pts[0], wdt);
|
|
||||||
} else if (stroke->cap == StrokeCap::Butt) {
|
|
||||||
// for zero length sub-paths no stroke is rendered
|
|
||||||
} else if (stroke->cap == StrokeCap::Square) {
|
|
||||||
appendRect(
|
|
||||||
polyline->pts[0] + WgPoint(+wdt, +wdt),
|
|
||||||
polyline->pts[0] + WgPoint(+wdt, -wdt),
|
|
||||||
polyline->pts[0] + WgPoint(-wdt, +wdt),
|
|
||||||
polyline->pts[0] + WgPoint(-wdt, -wdt)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
|
|
||||||
// single line sub-path
|
// single line sub-path
|
||||||
if (polyline->pts.count == 2) {
|
if (polyline->pts.count == 2) {
|
||||||
|
@ -474,7 +457,7 @@ void WgGeometryData::appendStroke(const WgPolyline* polyline, const RenderStroke
|
||||||
} else if (stroke->join == StrokeJoin::Miter) {
|
} else if (stroke->join == StrokeJoin::Miter) {
|
||||||
WgPoint nrm = (nrm0 + nrm1).normal();
|
WgPoint nrm = (nrm0 + nrm1).normal();
|
||||||
float cosine = nrm.dot(nrm0);
|
float cosine = nrm.dot(nrm0);
|
||||||
if ((cosine != 0.0f) && (abs(cosine) != 1.0f) && (abs(wdt / cosine) <= stroke->miterlimit * 2)) {
|
if ((cosine != 0.0f) && (abs(cosine) < 1.0f) && (abs(wdt / cosine) <= stroke->miterlimit * 2)) {
|
||||||
appendRect(v1 + nrm * (wdt / cosine), v1 + offset0, v1 + offset1, v1);
|
appendRect(v1 + nrm * (wdt / cosine), v1 + offset0, v1 + offset1, v1);
|
||||||
appendRect(v1 - nrm * (wdt / cosine), v1 - offset0, v1 - offset1, v1);
|
appendRect(v1 - nrm * (wdt / cosine), v1 - offset0, v1 - offset1, v1);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -321,16 +321,19 @@ void WgRenderDataShape::updateMeshes(WgContext& context, const WgPolyline* polyl
|
||||||
updateBBox(pmin, pmax);
|
updateBBox(pmin, pmax);
|
||||||
}
|
}
|
||||||
// generate strokes geometry
|
// generate strokes geometry
|
||||||
if ((polyline->pts.count >= 1) && rstroke) {
|
if ((polyline->pts.count >= 1) && rstroke && (rstroke->width > 0.0f)) {
|
||||||
static WgGeometryData geometryData; geometryData.clear();
|
static WgGeometryData geometryData; geometryData.clear();
|
||||||
static WgPolyline trimmed;
|
static WgPolyline trimmed;
|
||||||
// trim -> split -> stroke
|
// trim -> split -> stroke
|
||||||
if ((rstroke->dashPattern) && ((rstroke->trim.begin != 0.0f) || (rstroke->trim.end != 1.0f))) {
|
float trimBegin = rstroke->trim.begin < rstroke->trim.end ? rstroke->trim.begin : rstroke->trim.end;
|
||||||
polyline->trim(&trimmed, rstroke->trim.begin, rstroke->trim.end);
|
float trimEnd = rstroke->trim.begin < rstroke->trim.end ? rstroke->trim.end : rstroke->trim.begin;
|
||||||
|
if (trimBegin == trimEnd) return;
|
||||||
|
if ((rstroke->dashPattern) && ((trimBegin != 0.0f) || (trimEnd != 1.0f))) {
|
||||||
|
polyline->trim(&trimmed, trimBegin, trimEnd);
|
||||||
geometryData.appendStrokeDashed(&trimmed, rstroke);
|
geometryData.appendStrokeDashed(&trimmed, rstroke);
|
||||||
} else // trim -> stroke
|
} else // trim -> stroke
|
||||||
if ((rstroke->trim.begin != 0.0f) || (rstroke->trim.end != 1.0f)) {
|
if ((trimBegin != 0.0f) || (trimEnd != 1.0f)) {
|
||||||
polyline->trim(&trimmed, rstroke->trim.begin, rstroke->trim.end);
|
polyline->trim(&trimmed, trimBegin, trimEnd);
|
||||||
geometryData.appendStroke(&trimmed, rstroke);
|
geometryData.appendStroke(&trimmed, rstroke);
|
||||||
} else // split -> stroke
|
} else // split -> stroke
|
||||||
if (rstroke->dashPattern) {
|
if (rstroke->dashPattern) {
|
||||||
|
@ -339,12 +342,14 @@ void WgRenderDataShape::updateMeshes(WgContext& context, const WgPolyline* polyl
|
||||||
geometryData.appendStroke(polyline, rstroke);
|
geometryData.appendStroke(polyline, rstroke);
|
||||||
}
|
}
|
||||||
// append render meshes and bboxes
|
// append render meshes and bboxes
|
||||||
|
if(geometryData.positions.pts.count >= 3) {
|
||||||
WgPoint pmin{}, pmax{};
|
WgPoint pmin{}, pmax{};
|
||||||
geometryData.positions.getBBox(pmin, pmax);
|
geometryData.positions.getBBox(pmin, pmax);
|
||||||
meshGroupStrokes.append(context, &geometryData);
|
meshGroupStrokes.append(context, &geometryData);
|
||||||
meshGroupStrokesBBox.append(context, pmin, pmax);
|
meshGroupStrokesBBox.append(context, pmin, pmax);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void WgRenderDataShape::releaseMeshes(WgContext &context)
|
void WgRenderDataShape::releaseMeshes(WgContext &context)
|
||||||
|
|
Loading…
Add table
Reference in a new issue