mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Fill a looped curve with the selected background color (#1315)
This commit is contained in:
parent
fe6f482e96
commit
57bbc9fe55
11 changed files with 240 additions and 32 deletions
|
@ -10,11 +10,12 @@ import {
|
|||
getElementAbsoluteCoords,
|
||||
} from "../element/bounds";
|
||||
import { RoughCanvas } from "roughjs/bin/canvas";
|
||||
import { Drawable } from "roughjs/bin/core";
|
||||
import { Drawable, Options } from "roughjs/bin/core";
|
||||
import { RoughSVG } from "roughjs/bin/svg";
|
||||
import { RoughGenerator } from "roughjs/bin/generator";
|
||||
import { SceneState } from "../scene/types";
|
||||
import { SVG_NS, distance } from "../utils";
|
||||
import { isPathALoop } from "../math";
|
||||
import rough from "roughjs/bin/rough";
|
||||
|
||||
const CANVAS_PADDING = 20;
|
||||
|
@ -226,16 +227,29 @@ function generateElement(
|
|||
break;
|
||||
case "line":
|
||||
case "arrow": {
|
||||
const options = {
|
||||
const options: Options = {
|
||||
stroke: element.strokeColor,
|
||||
strokeWidth: element.strokeWidth,
|
||||
roughness: element.roughness,
|
||||
seed: element.seed,
|
||||
};
|
||||
|
||||
// points array can be empty in the beginning, so it is important to add
|
||||
// initial position to it
|
||||
const points = element.points.length ? element.points : [[0, 0]];
|
||||
|
||||
// If shape is a line and is a closed shape,
|
||||
// fill the shape if a color is set.
|
||||
if (element.type === "line") {
|
||||
if (isPathALoop(element.points)) {
|
||||
options.fillStyle = element.fillStyle;
|
||||
options.fill =
|
||||
element.backgroundColor === "transparent"
|
||||
? undefined
|
||||
: element.backgroundColor;
|
||||
}
|
||||
}
|
||||
|
||||
// curve is always the first element
|
||||
// this simplifies finding the curve for an element
|
||||
shape = [generator.curve(points as [number, number][], options)];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue