From 2809dac6a783318c1b07e237a0fba284c445fee2 Mon Sep 17 00:00:00 2001 From: Laurenz Stampfl <47084093+LaurenzV@users.noreply.github.com> Date: Mon, 4 Aug 2025 11:59:10 +0200 Subject: [PATCH] Apply aspect ratio correction for linear gradients in PDF export (#6689) --- crates/typst-pdf/src/paint.rs | 3 ++- ...680-gradient-linear-with-aspect-correction.png | Bin 0 -> 137 bytes tests/suite/visualize/gradient.typ | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 tests/ref/issue-6680-gradient-linear-with-aspect-correction.png diff --git a/crates/typst-pdf/src/paint.rs b/crates/typst-pdf/src/paint.rs index e03d0e94..c994e0e2 100644 --- a/crates/typst-pdf/src/paint.rs +++ b/crates/typst-pdf/src/paint.rs @@ -152,11 +152,12 @@ fn convert_gradient( RelativeTo::Parent => state.container_size(), }; - let angle = gradient.angle().unwrap_or_else(Angle::zero); + let mut angle = gradient.angle().unwrap_or_else(Angle::zero); let base_transform = correct_transform(state, gradient.unwrap_relative(on_text)); let stops = convert_gradient_stops(gradient); match &gradient { Gradient::Linear(_) => { + angle = Gradient::correct_aspect_ratio(angle, size.aspect_ratio()); let (x1, y1, x2, y2) = { let (mut sin, mut cos) = (angle.sin(), angle.cos()); diff --git a/tests/ref/issue-6680-gradient-linear-with-aspect-correction.png b/tests/ref/issue-6680-gradient-linear-with-aspect-correction.png new file mode 100644 index 0000000000000000000000000000000000000000..38769ed9d549717aee5c75b76bfbc086a10e8c13 GIT binary patch literal 137 zcmeAS@N?(olHy`uVBq!ia0vp^CxBRlkr_yS%6iZVq}T#{LR=Y2ZvJ;P%hJ5|7${=r z>Eaktacl1Rg@OzQ90wfS(oNhFSyY-9Z&gU@s1>c;Jn7;j7fuoTj)fXs6HL4os&p-u k=#q2skWvjy;(k~2H;*ae_RODBK$93eUHx3vIVCg!0B1-mhyVZp literal 0 HcmV?d00001 diff --git a/tests/suite/visualize/gradient.typ b/tests/suite/visualize/gradient.typ index 8446ca03..0071dd91 100644 --- a/tests/suite/visualize/gradient.typ +++ b/tests/suite/visualize/gradient.typ @@ -692,3 +692,6 @@ $ A = mat( (blue, 100%), ) ) + +--- issue-6680-gradient-linear-with-aspect-correction --- +#set page(width: 200pt, height: auto, margin: 10pt, fill: gradient.linear(red, blue, angle: 45deg).sharp(2))