summaryrefslogtreecommitdiff
path: root/crates/typst-pdf
diff options
context:
space:
mode:
authorSébastien d'Herbais de Thun <sebastien.d.herbais@gmail.com>2023-11-20 18:20:26 +0100
committerGitHub <noreply@github.com>2023-11-20 18:20:26 +0100
commit96f02960a2d28bdfde23dec92d0a94058f78dd4f (patch)
treed2c2114b4f4f357e0024ed4e0499e82bc959d8c4 /crates/typst-pdf
parent9b5b3b2557008b28ba3e530fcf50942faa706ebe (diff)
Fix gradient colors (#2719)
Diffstat (limited to 'crates/typst-pdf')
-rw-r--r--crates/typst-pdf/src/color.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/crates/typst-pdf/src/color.rs b/crates/typst-pdf/src/color.rs
index a9ad0100..0899ff78 100644
--- a/crates/typst-pdf/src/color.rs
+++ b/crates/typst-pdf/src/color.rs
@@ -439,7 +439,15 @@ impl ColorSpaceExt for ColorSpace {
// The oklab color space is in the range -0.4..0.4
// Also map the angle range of HSV/HSL to 0..1 instead of 0..360
let [x, y, z] = match self {
- Self::Oklab => [x, y + 0.4, z + 0.4],
+ Self::Oklab => {
+ let [l, c, h, _] = color.to_oklch().to_vec4();
+ // Clamp on Oklch's chroma, not Oklab's a\* and b\* as to not distort hue.
+ let c = c.clamp(0.0, 0.5);
+ // Convert cylindrical coordinates back to rectangular ones.
+ let a = c * h.to_radians().cos();
+ let b = c * h.to_radians().sin();
+ [l, a + 0.5, b + 0.5]
+ }
Self::Hsv | Self::Hsl => [x / 360.0, y, z],
_ => [x, y, z],
};