summaryrefslogtreecommitdiff
path: root/crates/typst-render/src
diff options
context:
space:
mode:
authorEmmanuel Lesueur <48604057+Emm54321@users.noreply.github.com>2024-12-18 16:58:57 +0100
committerGitHub <noreply@github.com>2024-12-18 15:58:57 +0000
commit257764181e52332a00079b9e3af03823fde1a15d (patch)
tree203378b303f1969e684b26dbefb77f7a5979ec9f /crates/typst-render/src
parent24c08a7ec0aaf87d6dc2e1a2c47b7beb6d5ad2a4 (diff)
New `curve` element that supersedes `path` (#5323)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
Diffstat (limited to 'crates/typst-render/src')
-rw-r--r--crates/typst-render/src/lib.rs4
-rw-r--r--crates/typst-render/src/shape.rs20
2 files changed, 12 insertions, 12 deletions
diff --git a/crates/typst-render/src/lib.rs b/crates/typst-render/src/lib.rs
index 4cd32d39..f43cd019 100644
--- a/crates/typst-render/src/lib.rs
+++ b/crates/typst-render/src/lib.rs
@@ -193,8 +193,8 @@ fn render_group(canvas: &mut sk::Pixmap, state: State, pos: Point, group: &Group
let mut mask = state.mask;
let storage;
- if let Some(clip_path) = group.clip_path.as_ref() {
- if let Some(path) = shape::convert_path(clip_path)
+ if let Some(clip_curve) = group.clip.as_ref() {
+ if let Some(path) = shape::convert_curve(clip_curve)
.and_then(|path| path.transform(state.transform))
{
if let Some(mask) = mask {
diff --git a/crates/typst-render/src/shape.rs b/crates/typst-render/src/shape.rs
index 57d8ebc1..ba7ed6d8 100644
--- a/crates/typst-render/src/shape.rs
+++ b/crates/typst-render/src/shape.rs
@@ -1,7 +1,7 @@
use tiny_skia as sk;
use typst_library::layout::{Abs, Axes, Point, Ratio, Size};
use typst_library::visualize::{
- DashPattern, FillRule, FixedStroke, Geometry, LineCap, LineJoin, Path, PathItem,
+ Curve, CurveItem, DashPattern, FillRule, FixedStroke, Geometry, LineCap, LineJoin,
Shape,
};
@@ -10,7 +10,7 @@ use crate::{paint, AbsExt, State};
/// Render a geometrical shape into the canvas.
pub fn render_shape(canvas: &mut sk::Pixmap, state: State, shape: &Shape) -> Option<()> {
let ts = state.transform;
- let path = match shape.geometry {
+ let path = match &shape.geometry {
Geometry::Line(target) => {
let mut builder = sk::PathBuilder::new();
builder.line_to(target.x.to_f32(), target.y.to_f32());
@@ -33,7 +33,7 @@ pub fn render_shape(canvas: &mut sk::Pixmap, state: State, shape: &Shape) -> Opt
sk::PathBuilder::from_rect(rect)
}
- Geometry::Path(ref path) => convert_path(path)?,
+ Geometry::Curve(curve) => convert_curve(curve)?,
};
if let Some(fill) = &shape.fill {
@@ -119,18 +119,18 @@ pub fn render_shape(canvas: &mut sk::Pixmap, state: State, shape: &Shape) -> Opt
Some(())
}
-/// Convert a Typst path into a tiny-skia path.
-pub fn convert_path(path: &Path) -> Option<sk::Path> {
+/// Convert a Typst curve into a tiny-skia path.
+pub fn convert_curve(curve: &Curve) -> Option<sk::Path> {
let mut builder = sk::PathBuilder::new();
- for elem in &path.0 {
+ for elem in &curve.0 {
match elem {
- PathItem::MoveTo(p) => {
+ CurveItem::Move(p) => {
builder.move_to(p.x.to_f32(), p.y.to_f32());
}
- PathItem::LineTo(p) => {
+ CurveItem::Line(p) => {
builder.line_to(p.x.to_f32(), p.y.to_f32());
}
- PathItem::CubicTo(p1, p2, p3) => {
+ CurveItem::Cubic(p1, p2, p3) => {
builder.cubic_to(
p1.x.to_f32(),
p1.y.to_f32(),
@@ -140,7 +140,7 @@ pub fn convert_path(path: &Path) -> Option<sk::Path> {
p3.y.to_f32(),
);
}
- PathItem::ClosePath => {
+ CurveItem::Close => {
builder.close();
}
};