Skip to content

Commit

Permalink
fix solid fills for curves
Browse files Browse the repository at this point in the history
  • Loading branch information
pshihn committed Sep 23, 2023
1 parent 98034d3 commit e725f5f
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "roughjs",
"version": "4.6.0",
"version": "4.6.1",
"description": "Create graphics using HTML Canvas or SVG with a hand-drawn, sketchy, appearance.",
"main": "bundled/rough.cjs.js",
"module": "bundled/rough.esm.js",
Expand Down
6 changes: 5 additions & 1 deletion src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ export class RoughGenerator {
const bcurve = curveToBezier(points);
const polyPoints = pointsOnBezierCurves(bcurve, 10, (1 + o.roughness) / 2);
if (o.fillStyle === 'solid') {
paths.push(solidFillPolygon([polyPoints], o));
const shape: OpSet = {
type: 'fillPath',
ops: this._mergedShape(this._splicePath(outline.ops)),
};
paths.push(shape);
} else {
paths.push(patternFillPolygons([polyPoints], o));
}
Expand Down
74 changes: 74 additions & 0 deletions visual-tests/canvas/curve2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<!doctype html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes">
<title>RoughJS Curve</title>
</head>

<body>
<canvas width="800" height="800"></canvas>

<script type="module">
import rough from '../../bin/rough.js';
const canvas = document.querySelector('canvas');
const rc = rough.canvas(canvas);
const ctx = canvas.getContext('2d');

rc.curve([
[10, 10],
[200, 10],
[100, 100],
[100, 50],
[300, 100],
[60, 200]
], { stroke: 'black', strokeWidth: 2, fill: 'red', hachureGap: 10 });

ctx.translate(0, 210);
rc.curve([
[10, 10],
[200, 10],
[100, 100],
[100, 50],
[300, 100],
[60, 200]
], { fill: 'red', fillStyle: 'solid', roughness: 3 });

ctx.translate(0, 210);
rc.curve([
[10, 10],
[200, 10],
[100, 100],
[100, 50],
[300, 100],
[60, 200]
], { fill: 'red', fillStyle: 'cross-hatch', hachureGap: 8 });

ctx.translate(300, 0);


ctx.translate(0, -210);
rc.curve([
[10, 10],
[200, 10],
[100, 100],
[100, 50],
[300, 100],
[60, 200]
], { fill: 'red', fillStyle: 'solid', stroke: 'none', roughness: 3 });

ctx.translate(0, -210);
rc.curve([
[10, 10],
[200, 10],
[100, 100],
[100, 50],
[300, 100],
[60, 200]
], { stroke: 'black', strokeWidth: 2, fill: 'red', hachureGap: 10, stroke: 'none' });

</script>
</body>

</html>

0 comments on commit e725f5f

Please sign in to comment.