Skip to content

Commit 10cd6df

Browse files
committed
Cleanup
1 parent 01507ca commit 10cd6df

1 file changed

Lines changed: 5 additions & 28 deletions

File tree

editor/src/messages/portfolio/document/graph_operation/graph_operation_message_handler.rs

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -594,35 +594,12 @@ fn parse_stop_offset(s: &str) -> f64 {
594594

595595
fn parse_stop_color(value: &str, opacity: f32) -> Option<Color> {
596596
let value = value.trim();
597-
if let Some(hex) = value.strip_prefix('#') {
598-
return parse_hex_color(hex, opacity);
597+
if value.to_ascii_lowercase() == "transparent" {
598+
return Some(Color::from_rgbaf32_unchecked(0., 0., 0., 0.));
599599
}
600-
named_css_color(value).map(|(r, g, b, alpha)| Color::from_rgbaf32_unchecked(r as f32 / 255., g as f32 / 255., b as f32 / 255., alpha.unwrap_or(opacity)))
601-
}
602-
603-
fn parse_hex_color(hex: &str, opacity: f32) -> Option<Color> {
604-
let (r, g, b) = match hex.len() {
605-
6 => (
606-
u8::from_str_radix(&hex[0..2], 16).ok()?,
607-
u8::from_str_radix(&hex[2..4], 16).ok()?,
608-
u8::from_str_radix(&hex[4..6], 16).ok()?,
609-
),
610-
3 => {
611-
let r = u8::from_str_radix(&hex[0..1], 16).ok()?;
612-
let g = u8::from_str_radix(&hex[1..2], 16).ok()?;
613-
let b = u8::from_str_radix(&hex[2..3], 16).ok()?;
614-
(r * 17, g * 17, b * 17)
615-
}
616-
_ => return None,
617-
};
618-
Some(Color::from_rgbaf32_unchecked(r as f32 / 255., g as f32 / 255., b as f32 / 255., opacity))
619-
}
620-
621-
fn named_css_color(name: &str) -> Option<(u8, u8, u8, Option<f32>)> {
622-
if name.to_ascii_lowercase() == "transparent" {
623-
return Some((0, 0, 0, Some(0.)));
624-
}
625-
svgtypes::Color::from_str(name).ok().map(|c| (c.red, c.green, c.blue, None))
600+
svgtypes::Color::from_str(value).ok().map(|c| {
601+
Color::from_rgbaf32_unchecked(c.red as f32 / 255., c.green as f32 / 255., c.blue as f32 / 255., (c.alpha as f32 / 255.) * opacity)
602+
})
626603
}
627604

628605
/// Import a usvg node as the root of an SVG import operation.

0 commit comments

Comments
 (0)