mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +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);
|
||||
static WgPolyline dashed;
|
||||
dashed.clear();
|
||||
// append single point polyline
|
||||
if (polyline->pts.count == 1)
|
||||
appendStroke(polyline, stroke);
|
||||
// ignore singpe points polyline
|
||||
// append multy points dashed polyline
|
||||
else if (polyline->pts.count >= 2) {
|
||||
if (polyline->pts.count >= 2) {
|
||||
auto& pts = polyline->pts;
|
||||
auto& dist = polyline->dist;
|
||||
// starting state
|
||||
|
@ -357,21 +355,6 @@ void WgGeometryData::appendStroke(const WgPolyline* polyline, const RenderStroke
|
|||
assert(stroke);
|
||||
assert(polyline);
|
||||
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
|
||||
if (polyline->pts.count == 2) {
|
||||
|
@ -474,7 +457,7 @@ void WgGeometryData::appendStroke(const WgPolyline* polyline, const RenderStroke
|
|||
} else if (stroke->join == StrokeJoin::Miter) {
|
||||
WgPoint nrm = (nrm0 + nrm1).normal();
|
||||
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);
|
||||
} else {
|
||||
|
|
|
@ -321,16 +321,19 @@ void WgRenderDataShape::updateMeshes(WgContext& context, const WgPolyline* polyl
|
|||
updateBBox(pmin, pmax);
|
||||
}
|
||||
// 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 WgPolyline trimmed;
|
||||
// trim -> split -> stroke
|
||||
if ((rstroke->dashPattern) && ((rstroke->trim.begin != 0.0f) || (rstroke->trim.end != 1.0f))) {
|
||||
polyline->trim(&trimmed, rstroke->trim.begin, rstroke->trim.end);
|
||||
float trimBegin = rstroke->trim.begin < rstroke->trim.end ? 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);
|
||||
} else // trim -> stroke
|
||||
if ((rstroke->trim.begin != 0.0f) || (rstroke->trim.end != 1.0f)) {
|
||||
polyline->trim(&trimmed, rstroke->trim.begin, rstroke->trim.end);
|
||||
if ((trimBegin != 0.0f) || (trimEnd != 1.0f)) {
|
||||
polyline->trim(&trimmed, trimBegin, trimEnd);
|
||||
geometryData.appendStroke(&trimmed, rstroke);
|
||||
} else // split -> stroke
|
||||
if (rstroke->dashPattern) {
|
||||
|
@ -339,11 +342,13 @@ void WgRenderDataShape::updateMeshes(WgContext& context, const WgPolyline* polyl
|
|||
geometryData.appendStroke(polyline, rstroke);
|
||||
}
|
||||
// append render meshes and bboxes
|
||||
if(geometryData.positions.pts.count >= 3) {
|
||||
WgPoint pmin{}, pmax{};
|
||||
geometryData.positions.getBBox(pmin, pmax);
|
||||
meshGroupStrokes.append(context, &geometryData);
|
||||
meshGroupStrokesBBox.append(context, pmin, pmax);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue