diff options
| author | Birk Tjelmeland <git@birktj.no> | 2023-04-13 16:05:56 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-13 16:05:56 +0200 |
| commit | d1cd814ef8149cbac6e59c81e074aa59c930eed3 (patch) | |
| tree | 02b9a8afed4d121b34d89669452f91cda19df8e2 /library | |
| parent | 46ce9c94e3f615751989d3cba5aa1599e0ba5913 (diff) | |
Add support for more complex strokes (#505)
Diffstat (limited to 'library')
| -rw-r--r-- | library/src/math/frac.rs | 1 | ||||
| -rw-r--r-- | library/src/math/root.rs | 7 | ||||
| -rw-r--r-- | library/src/text/deco.rs | 1 | ||||
| -rw-r--r-- | library/src/visualize/line.rs | 25 | ||||
| -rw-r--r-- | library/src/visualize/shape.rs | 18 |
5 files changed, 47 insertions, 5 deletions
diff --git a/library/src/math/frac.rs b/library/src/math/frac.rs index 1712a1fc..7520e10d 100644 --- a/library/src/math/frac.rs +++ b/library/src/math/frac.rs @@ -135,6 +135,7 @@ fn layout( Geometry::Line(Point::with_x(line_width)).stroked(Stroke { paint: TextElem::fill_in(ctx.styles()), thickness, + ..Stroke::default() }), span, ), diff --git a/library/src/math/root.rs b/library/src/math/root.rs index 037c6ce7..cc48cd74 100644 --- a/library/src/math/root.rs +++ b/library/src/math/root.rs @@ -121,8 +121,11 @@ fn layout( frame.push( line_pos, FrameItem::Shape( - Geometry::Line(Point::with_x(radicand.width())) - .stroked(Stroke { paint: TextElem::fill_in(ctx.styles()), thickness }), + Geometry::Line(Point::with_x(radicand.width())).stroked(Stroke { + paint: TextElem::fill_in(ctx.styles()), + thickness, + ..Stroke::default() + }), span, ), ); diff --git a/library/src/text/deco.rs b/library/src/text/deco.rs index 79917641..ab89e6b5 100644 --- a/library/src/text/deco.rs +++ b/library/src/text/deco.rs @@ -271,6 +271,7 @@ pub(super) fn decorate( let stroke = deco.stroke.clone().unwrap_or(Stroke { paint: text.fill.clone(), thickness: metrics.thickness.at(text.size), + ..Stroke::default() }); let gap_padding = 0.08 * text.size; diff --git a/library/src/visualize/line.rs b/library/src/visualize/line.rs index 0932a9f1..362f1a89 100644 --- a/library/src/visualize/line.rs +++ b/library/src/visualize/line.rs @@ -40,9 +40,32 @@ pub struct LineElem { /// to `{1pt}`. /// - A stroke combined from color and thickness using the `+` operator as /// in `{2pt + red}`. + /// - A stroke described by a dictionary with any of the following keys: + /// - `color`: the color to use for the stroke + /// - `thickness`: the stroke's thickness + /// - `cap`: one of `"butt"`, `"round"` or `"square"`, the line cap of the stroke + /// - `join`: one of `"miter"`, `"round"` or `"bevel"`, the line join of the stroke + /// - `miter-limit`: the miter limit to use if `join` is `"miter"`, defaults to 4.0 + /// - `dash`: the dash pattern to use. Can be any of the following: + /// - One of the strings `"solid"`, `"dotted"`, `"densely-dotted"`, `"loosely-dotted"`, + /// `"dashed"`, `"densely-dashed"`, `"loosely-dashed"`, `"dashdotted"`, + /// `"densely-dashdotted"` or `"loosely-dashdotted"` + /// - An array with elements that specify the lengths of dashes and gaps, alternating. + /// Elements can also be the string `"dot"` for a length equal to the line thickness. + /// - A dict with the keys `array`, same as the array above, and `phase`, the offset to + /// the start of the first dash. + /// /// /// ```example - /// #line(length: 100%, stroke: 2pt + red) + /// #stack( + /// line(length: 100%, stroke: 2pt + red), + /// v(1em), + /// line(length: 100%, stroke: (color: blue, thickness: 4pt, cap: "round")), + /// v(1em), + /// line(length: 100%, stroke: (color: blue, thickness: 1pt, dash: "dashed")), + /// v(1em), + /// line(length: 100%, stroke: (color: blue, thickness: 1pt, dash: ("dot", 2pt, 4pt, 2pt))), + /// ) /// ``` #[resolve] #[fold] diff --git a/library/src/visualize/shape.rs b/library/src/visualize/shape.rs index 51dbabd8..e0214f03 100644 --- a/library/src/visualize/shape.rs +++ b/library/src/visualize/shape.rs @@ -47,8 +47,22 @@ pub struct RectElem { /// to `{1pt}`. /// - A stroke combined from color and thickness using the `+` operator as /// in `{2pt + red}`. - /// - A dictionary: With a dictionary, the stroke for each side can be set - /// individually. The dictionary can contain the following keys in order + /// - A stroke described by a dictionary with any of the following keys: + /// - `color`: the color to use for the stroke + /// - `thickness`: the stroke's thickness + /// - `cap`: one of `"butt"`, `"round"` or `"square"`, the line cap of the stroke + /// - `join`: one of `"miter"`, `"round"` or `"bevel"`, the line join of the stroke + /// - `miter-limit`: the miter limit to use if `join` is `"miter"`, defaults to 4.0 + /// - `dash`: the dash pattern to use. Can be any of the following: + /// - One of the strings `"solid"`, `"dotted"`, `"densely-dotted"`, `"loosely-dotted"`, + /// `"dashed"`, `"densely-dashed"`, `"loosely-dashed"`, `"dashdotted"`, + /// `"densely-dashdotted"` or `"loosely-dashdotted"` + /// - An array with elements that specify the lengths of dashes and gaps, alternating. + /// Elements can also be the string `"dot"` for a length equal to the line thickness. + /// - A dict with the keys `array`, same as the array above, and `phase`, the offset to + /// the start of the first dash. + /// - Another dictionary describing the stroke for each side inidvidually. + /// The dictionary can contain the following keys in order /// of precedence: /// - `top`: The top stroke. /// - `right`: The right stroke. |
