Fix color export for SVG (#2610)

This commit is contained in:
frozolotl 2023-11-08 20:11:02 +10:00 committed by GitHub
parent cfb767346e
commit 7f1c38548a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1243,7 +1243,7 @@ impl ColorEncode for Color {
Color::LinearRgb(rgb) => { Color::LinearRgb(rgb) => {
if rgb.alpha != 1.0 { if rgb.alpha != 1.0 {
eco_format!( eco_format!(
"color(srgb-linear {:.3} {:.3} {:.3} / {:.3})", "color(srgb-linear {:.5} {:.5} {:.5} / {:.5})",
rgb.red, rgb.red,
rgb.green, rgb.green,
rgb.blue, rgb.blue,
@ -1251,7 +1251,7 @@ impl ColorEncode for Color {
) )
} else { } else {
eco_format!( eco_format!(
"color(srgb-linear {:.3} {:.3} {:.3})", "color(srgb-linear {:.5} {:.5} {:.5})",
rgb.red, rgb.red,
rgb.green, rgb.green,
rgb.blue, rgb.blue,
@ -1261,16 +1261,16 @@ impl ColorEncode for Color {
Color::Oklab(oklab) => { Color::Oklab(oklab) => {
if oklab.alpha != 1.0 { if oklab.alpha != 1.0 {
eco_format!( eco_format!(
"oklab({:?} {:.3} {:.3} / {:.3})", "oklab({:.3}% {:.5} {:.5} / {:.5})",
Ratio::new(oklab.l as f64), oklab.l * 100.0,
oklab.a, oklab.a,
oklab.b, oklab.b,
oklab.alpha oklab.alpha
) )
} else { } else {
eco_format!( eco_format!(
"oklab({:?} {:.3} {:.3})", "oklab({:.3}% {:.5} {:.5})",
Ratio::new(oklab.l as f64), oklab.l * 100.0,
oklab.a, oklab.a,
oklab.b, oklab.b,
) )
@ -1279,18 +1279,18 @@ impl ColorEncode for Color {
Color::Hsl(hsl) => { Color::Hsl(hsl) => {
if hsl.alpha != 1.0 { if hsl.alpha != 1.0 {
eco_format!( eco_format!(
"hsla({:?} {:?} {:?} / {:.3})", "hsla({:.3}deg {:.3}% {:.3}% / {:.5})",
Angle::deg(hsl.hue.into_degrees() as f64), hsl.hue.into_degrees(),
Ratio::new(hsl.saturation as f64), hsl.saturation * 100.0,
Ratio::new(hsl.lightness as f64), hsl.lightness * 100.0,
hsl.alpha, hsl.alpha,
) )
} else { } else {
eco_format!( eco_format!(
"hsl({:?} {:?} {:?})", "hsl({:.3}deg {:.3}% {:.3}%)",
Angle::deg(hsl.hue.into_degrees() as f64), hsl.hue.into_degrees(),
Ratio::new(hsl.saturation as f64), hsl.saturation * 100.0,
Ratio::new(hsl.lightness as f64), hsl.lightness * 100.0,
) )
} }
} }