summaryrefslogtreecommitdiff
path: root/crates/typst-render/src
diff options
context:
space:
mode:
authorEric Biedert <github@ericbiedert.de>2024-08-05 12:24:22 +0200
committerGitHub <noreply@github.com>2024-08-05 10:24:22 +0000
commited247797ac17e0975d6663d65b0976ab92130d80 (patch)
tree32e957ed0ce6da03a780fee0952452a8322d5cce /crates/typst-render/src
parentdfdcc197c019b4ca5bc09487ee5f36030704b334 (diff)
Fix alignment of gradients and patterns on strokes in PNG (#4634)
Diffstat (limited to 'crates/typst-render/src')
-rw-r--r--crates/typst-render/src/paint.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/crates/typst-render/src/paint.rs b/crates/typst-render/src/paint.rs
index 2b5c19c9..3a507ca4 100644
--- a/crates/typst-render/src/paint.rs
+++ b/crates/typst-render/src/paint.rs
@@ -185,6 +185,12 @@ pub fn to_sk_paint<'a>(
.container_transform
.post_concat(state.transform.invert().unwrap()),
};
+
+ let gradient_map = match relative {
+ RelativeTo::Self_ => gradient_map,
+ RelativeTo::Parent => None,
+ };
+
let width =
(container_size.x.to_f32().abs() * state.pixel_per_pt).ceil() as u32;
let height =
@@ -225,6 +231,13 @@ pub fn to_sk_paint<'a>(
let canvas = render_pattern_frame(&state, pattern);
*pixmap = Some(Arc::new(canvas));
+ let offset = match relative {
+ RelativeTo::Self_ => {
+ gradient_map.map(|(offset, _)| -offset).unwrap_or_default()
+ }
+ RelativeTo::Parent => Point::zero(),
+ };
+
// Create the shader
sk_paint.shader = sk::Pattern::new(
pixmap.as_ref().unwrap().as_ref().as_ref(),
@@ -232,7 +245,8 @@ pub fn to_sk_paint<'a>(
sk::FilterQuality::Nearest,
1.0,
fill_transform
- .pre_scale(1.0 / state.pixel_per_pt, 1.0 / state.pixel_per_pt),
+ .pre_scale(1.0 / state.pixel_per_pt, 1.0 / state.pixel_per_pt)
+ .pre_translate(offset.x.to_f32(), offset.y.to_f32()),
);
}
}