summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-12-28 13:51:32 +0100
committerLaurenz <laurmaedje@gmail.com>2023-12-28 13:52:58 +0100
commit67ead94cc25d6663dc6afaebb6c7e781ba9c26bb (patch)
treebafdf207aeda1fa72d078ced5410ee31d5dc0e53
parente215f22965760bcc5df3204243597825e99b3fe7 (diff)
Fix naming inconsistency for strokes
-rw-r--r--crates/typst-pdf/src/page.rs22
-rw-r--r--crates/typst-render/src/lib.rs32
-rw-r--r--crates/typst-svg/src/lib.rs6
-rw-r--r--crates/typst/src/foundations/fields.rs6
-rw-r--r--crates/typst/src/math/matrix.rs2
-rw-r--r--crates/typst/src/visualize/shape.rs4
-rw-r--r--crates/typst/src/visualize/stroke.rs96
7 files changed, 65 insertions, 103 deletions
diff --git a/crates/typst-pdf/src/page.rs b/crates/typst-pdf/src/page.rs
index acf67014..89b0ba5f 100644
--- a/crates/typst-pdf/src/page.rs
+++ b/crates/typst-pdf/src/page.rs
@@ -516,26 +516,18 @@ impl PageContext<'_, '_> {
Some(Paint::Gradient(_))
)
{
- let FixedStroke {
- paint,
- thickness,
- line_cap,
- line_join,
- dash_pattern,
- miter_limit,
- } = stroke;
-
+ let FixedStroke { paint, thickness, cap, join, dash, miter_limit } = stroke;
paint.set_as_stroke(self, on_text, transforms);
self.content.set_line_width(thickness.to_f32());
- if self.state.stroke.as_ref().map(|s| &s.line_cap) != Some(line_cap) {
- self.content.set_line_cap(to_pdf_line_cap(*line_cap));
+ if self.state.stroke.as_ref().map(|s| &s.cap) != Some(cap) {
+ self.content.set_line_cap(to_pdf_line_cap(*cap));
}
- if self.state.stroke.as_ref().map(|s| &s.line_join) != Some(line_join) {
- self.content.set_line_join(to_pdf_line_join(*line_join));
+ if self.state.stroke.as_ref().map(|s| &s.join) != Some(join) {
+ self.content.set_line_join(to_pdf_line_join(*join));
}
- if self.state.stroke.as_ref().map(|s| &s.dash_pattern) != Some(dash_pattern) {
- if let Some(pattern) = dash_pattern {
+ if self.state.stroke.as_ref().map(|s| &s.dash) != Some(dash) {
+ if let Some(pattern) = dash {
self.content.set_dash_pattern(
pattern.array.iter().map(|l| l.to_f32()),
pattern.phase.to_f32(),
diff --git a/crates/typst-render/src/lib.rs b/crates/typst-render/src/lib.rs
index e8633f55..b906ac53 100644
--- a/crates/typst-render/src/lib.rs
+++ b/crates/typst-render/src/lib.rs
@@ -410,17 +410,11 @@ fn render_outline_glyph(
);
canvas.fill_path(&path, &paint, rule, ts, state.mask);
- if let Some(FixedStroke {
- paint,
- thickness,
- line_cap,
- line_join,
- dash_pattern,
- miter_limit,
- }) = &text.stroke
+ if let Some(FixedStroke { paint, thickness, cap, join, dash, miter_limit }) =
+ &text.stroke
{
if thickness.to_f32() > 0.0 {
- let dash = dash_pattern.as_ref().and_then(to_sk_dash_pattern);
+ let dash = dash.as_ref().and_then(to_sk_dash_pattern);
let paint = to_sk_paint(
paint,
@@ -433,8 +427,8 @@ fn render_outline_glyph(
);
let stroke = sk::Stroke {
width: thickness.to_f32() / scale, // When we scale the path, we need to scale the stroke width, too.
- line_cap: to_sk_line_cap(*line_cap),
- line_join: to_sk_line_join(*line_join),
+ line_cap: to_sk_line_cap(*cap),
+ line_join: to_sk_line_join(*join),
dash,
miter_limit: miter_limit.get() as f32,
};
@@ -607,20 +601,14 @@ fn render_shape(canvas: &mut sk::Pixmap, state: State, shape: &Shape) -> Option<
canvas.fill_path(&path, &paint, rule, ts, state.mask);
}
- if let Some(FixedStroke {
- paint,
- thickness,
- line_cap,
- line_join,
- dash_pattern,
- miter_limit,
- }) = &shape.stroke
+ if let Some(FixedStroke { paint, thickness, cap, join, dash, miter_limit }) =
+ &shape.stroke
{
let width = thickness.to_f32();
// Don't draw zero-pt stroke.
if width > 0.0 {
- let dash = dash_pattern.as_ref().and_then(to_sk_dash_pattern);
+ let dash = dash.as_ref().and_then(to_sk_dash_pattern);
let bbox = shape.geometry.bbox_size();
let offset_bbox = (!matches!(shape.geometry, Geometry::Line(..)))
@@ -661,8 +649,8 @@ fn render_shape(canvas: &mut sk::Pixmap, state: State, shape: &Shape) -> Option<
);
let stroke = sk::Stroke {
width,
- line_cap: to_sk_line_cap(*line_cap),
- line_join: to_sk_line_join(*line_join),
+ line_cap: to_sk_line_cap(*cap),
+ line_join: to_sk_line_join(*join),
dash,
miter_limit: miter_limit.get() as f32,
};
diff --git a/crates/typst-svg/src/lib.rs b/crates/typst-svg/src/lib.rs
index b8143122..62f217f5 100644
--- a/crates/typst-svg/src/lib.rs
+++ b/crates/typst-svg/src/lib.rs
@@ -657,7 +657,7 @@ impl SVGRenderer {
self.xml.write_attribute("stroke-width", &stroke.thickness.to_pt());
self.xml.write_attribute(
"stroke-linecap",
- match stroke.line_cap {
+ match stroke.cap {
LineCap::Butt => "butt",
LineCap::Round => "round",
LineCap::Square => "square",
@@ -665,7 +665,7 @@ impl SVGRenderer {
);
self.xml.write_attribute(
"stroke-linejoin",
- match stroke.line_join {
+ match stroke.join {
LineJoin::Miter => "miter",
LineJoin::Round => "round",
LineJoin::Bevel => "bevel",
@@ -673,7 +673,7 @@ impl SVGRenderer {
);
self.xml
.write_attribute("stroke-miterlimit", &stroke.miter_limit.get());
- if let Some(pattern) = &stroke.dash_pattern {
+ if let Some(pattern) = &stroke.dash {
self.xml.write_attribute("stroke-dashoffset", &pattern.phase.to_pt());
self.xml.write_attribute(
"stroke-dasharray",
diff --git a/crates/typst/src/foundations/fields.rs b/crates/typst/src/foundations/fields.rs
index 94b331e3..01f2348a 100644
--- a/crates/typst/src/foundations/fields.rs
+++ b/crates/typst/src/foundations/fields.rs
@@ -37,9 +37,9 @@ pub(crate) fn field(value: &Value, field: &str) -> StrResult<Value> {
match field {
"paint" => stroke.paint.clone().into_value(),
"thickness" => stroke.thickness.into_value(),
- "cap" => stroke.line_cap.into_value(),
- "join" => stroke.line_join.into_value(),
- "dash" => stroke.dash_pattern.clone().into_value(),
+ "cap" => stroke.cap.into_value(),
+ "join" => stroke.join.into_value(),
+ "dash" => stroke.dash.clone().into_value(),
"miter-limit" => {
stroke.miter_limit.map(|limit| limit.get()).into_value()
}
diff --git a/crates/typst/src/math/matrix.rs b/crates/typst/src/math/matrix.rs
index a6b30f3c..35a9ce55 100644
--- a/crates/typst/src/math/matrix.rs
+++ b/crates/typst/src/math/matrix.rs
@@ -412,7 +412,7 @@ fn layout_mat_body(
let default_stroke = FixedStroke {
thickness: default_stroke_thickness,
paint: TextElem::fill_in(ctx.styles()).as_decoration(),
- line_cap: LineCap::Square,
+ cap: LineCap::Square,
..Default::default()
};
diff --git a/crates/typst/src/visualize/shape.rs b/crates/typst/src/visualize/shape.rs
index fcdcfc31..b96507fb 100644
--- a/crates/typst/src/visualize/shape.rs
+++ b/crates/typst/src/visualize/shape.rs
@@ -709,7 +709,7 @@ fn corners_control_points(
strokes.get_ref(corner.side_ccw()),
strokes.get_ref(corner.side_cw()),
) {
- (Some(a), Some(b)) => a.paint == b.paint && a.dash_pattern == b.dash_pattern,
+ (Some(a), Some(b)) => a.paint == b.paint && a.dash == b.dash,
(None, None) => true,
_ => false,
},
@@ -870,7 +870,7 @@ fn segment(
}
let solid = stroke
- .dash_pattern
+ .dash
.as_ref()
.map(|pattern| pattern.array.is_empty())
.unwrap_or(true);
diff --git a/crates/typst/src/visualize/stroke.rs b/crates/typst/src/visualize/stroke.rs
index cc93cee7..1761d087 100644
--- a/crates/typst/src/visualize/stroke.rs
+++ b/crates/typst/src/visualize/stroke.rs
@@ -57,11 +57,11 @@ pub struct Stroke<T: Numeric = Length> {
/// The stroke's thickness.
pub thickness: Smart<T>,
/// The stroke's line cap.
- pub line_cap: Smart<LineCap>,
+ pub cap: Smart<LineCap>,
/// The stroke's line join.
- pub line_join: Smart<LineJoin>,
+ pub join: Smart<LineJoin>,
/// The stroke's line dash pattern.
- pub dash_pattern: Smart<Option<DashPattern<T>>>,
+ pub dash: Smart<Option<DashPattern<T>>>,
/// The miter limit.
pub miter_limit: Smart<Scalar>,
}
@@ -182,19 +182,12 @@ impl Stroke {
let paint = take::<Paint>(args, "paint")?;
let thickness = take::<Length>(args, "thickness")?;
- let line_cap = take::<LineCap>(args, "cap")?;
- let line_join = take::<LineJoin>(args, "join")?;
- let dash_pattern = take::<Option<DashPattern>>(args, "dash")?;
+ let cap = take::<LineCap>(args, "cap")?;
+ let join = take::<LineJoin>(args, "join")?;
+ let dash = take::<Option<DashPattern>>(args, "dash")?;
let miter_limit = take::<f64>(args, "miter-limit")?.map(Scalar::new);
- Ok(Self {
- paint,
- thickness,
- line_cap,
- line_join,
- dash_pattern,
- miter_limit,
- })
+ Ok(Self { paint, thickness, cap, join, dash, miter_limit })
}
}
@@ -207,9 +200,9 @@ impl<T: Numeric> Stroke<T> {
Stroke {
paint: self.paint,
thickness: self.thickness.map(&f),
- line_cap: self.line_cap,
- line_join: self.line_join,
- dash_pattern: self.dash_pattern.map(|pattern| {
+ cap: self.cap,
+ join: self.join,
+ dash: self.dash.map(|pattern| {
pattern.map(|pattern| DashPattern {
array: pattern
.array
@@ -231,8 +224,8 @@ impl Stroke<Abs> {
/// Unpack the stroke, filling missing fields from the `default`.
pub fn unwrap_or(self, default: FixedStroke) -> FixedStroke {
let thickness = self.thickness.unwrap_or(default.thickness);
- let dash_pattern = self
- .dash_pattern
+ let dash = self
+ .dash
.map(|pattern| {
pattern.map(|pattern| DashPattern {
array: pattern
@@ -243,14 +236,14 @@ impl Stroke<Abs> {
phase: pattern.phase,
})
})
- .unwrap_or(default.dash_pattern);
+ .unwrap_or(default.dash);
FixedStroke {
paint: self.paint.unwrap_or(default.paint),
thickness,
- line_cap: self.line_cap.unwrap_or(default.line_cap),
- line_join: self.line_join.unwrap_or(default.line_join),
- dash_pattern,
+ cap: self.cap.unwrap_or(default.cap),
+ join: self.join.unwrap_or(default.join),
+ dash,
miter_limit: self.miter_limit.unwrap_or(default.miter_limit),
}
}
@@ -266,19 +259,8 @@ impl Stroke<Abs> {
impl<T: Numeric + Repr> Repr for Stroke<T> {
fn repr(&self) -> EcoString {
let mut r = EcoString::new();
- let Self {
- paint,
- thickness,
- line_cap,
- line_join,
- dash_pattern,
- miter_limit,
- } = &self;
- if line_cap.is_auto()
- && line_join.is_auto()
- && dash_pattern.is_auto()
- && miter_limit.is_auto()
- {
+ let Self { paint, thickness, cap, join, dash, miter_limit } = &self;
+ if cap.is_auto() && join.is_auto() && dash.is_auto() && miter_limit.is_auto() {
match (&self.paint, &self.thickness) {
(Smart::Custom(paint), Smart::Custom(thickness)) => {
r.push_str(&thickness.repr());
@@ -304,19 +286,19 @@ impl<T: Numeric + Repr> Repr for Stroke<T> {
r.push_str(&thickness.repr());
sep = ", ";
}
- if let Smart::Custom(cap) = &line_cap {
+ if let Smart::Custom(cap) = &cap {
r.push_str(sep);
r.push_str("cap: ");
r.push_str(&cap.repr());
sep = ", ";
}
- if let Smart::Custom(join) = &line_join {
+ if let Smart::Custom(join) = &join {
r.push_str(sep);
r.push_str("join: ");
r.push_str(&join.repr());
sep = ", ";
}
- if let Smart::Custom(dash) = &dash_pattern {
+ if let Smart::Custom(dash) = &dash {
r.push_str(sep);
r.push_str("cap: ");
if let Some(dash) = dash {
@@ -344,9 +326,9 @@ impl Resolve for Stroke {
Stroke {
paint: self.paint,
thickness: self.thickness.resolve(styles),
- line_cap: self.line_cap,
- line_join: self.line_join,
- dash_pattern: self.dash_pattern.resolve(styles),
+ cap: self.cap,
+ join: self.join,
+ dash: self.dash.resolve(styles),
miter_limit: self.miter_limit,
}
}
@@ -359,9 +341,9 @@ impl Fold for Stroke<Abs> {
Self {
paint: self.paint.or(outer.paint),
thickness: self.thickness.or(outer.thickness),
- line_cap: self.line_cap.or(outer.line_cap),
- line_join: self.line_join.or(outer.line_join),
- dash_pattern: self.dash_pattern.or(outer.dash_pattern),
+ cap: self.cap.or(outer.cap),
+ join: self.join.or(outer.join),
+ dash: self.dash.or(outer.dash),
miter_limit: self.miter_limit.or(outer.miter_limit),
}
}
@@ -394,18 +376,18 @@ cast! {
let paint = take::<Paint>(&mut dict, "paint")?;
let thickness = take::<Length>(&mut dict, "thickness")?;
- let line_cap = take::<LineCap>(&mut dict, "cap")?;
- let line_join = take::<LineJoin>(&mut dict, "join")?;
- let dash_pattern = take::<Option<DashPattern>>(&mut dict, "dash")?;
+ let cap = take::<LineCap>(&mut dict, "cap")?;
+ let join = take::<LineJoin>(&mut dict, "join")?;
+ let dash = take::<Option<DashPattern>>(&mut dict, "dash")?;
let miter_limit = take::<f64>(&mut dict, "miter-limit")?;
dict.finish(&["paint", "thickness", "cap", "join", "dash", "miter-limit"])?;
Self {
paint,
thickness,
- line_cap,
- line_join,
- dash_pattern,
+ cap,
+ join,
+ dash,
miter_limit: miter_limit.map(Scalar::new),
}
},
@@ -592,11 +574,11 @@ pub struct FixedStroke {
/// The stroke's thickness.
pub thickness: Abs,
/// The stroke's line cap.
- pub line_cap: LineCap,
+ pub cap: LineCap,
/// The stroke's line join.
- pub line_join: LineJoin,
+ pub join: LineJoin,
/// The stroke's line dash pattern.
- pub dash_pattern: Option<DashPattern<Abs, Abs>>,
+ pub dash: Option<DashPattern<Abs, Abs>>,
/// The miter limit. Defaults to 4.0, same as `tiny-skia`.
pub miter_limit: Scalar,
}
@@ -606,9 +588,9 @@ impl Default for FixedStroke {
Self {
paint: Paint::Solid(Color::BLACK),
thickness: Abs::pt(1.0),
- line_cap: LineCap::Butt,
- line_join: LineJoin::Miter,
- dash_pattern: None,
+ cap: LineCap::Butt,
+ join: LineJoin::Miter,
+ dash: None,
miter_limit: Scalar::new(4.0),
}
}