From 00596296c4116c42ef3cbb931f93513e8206c165 Mon Sep 17 00:00:00 2001 From: N00byEdge Date: Mon, 6 Jan 2020 19:29:49 +0100 Subject: [PATCH] LibDraw: Add support for parsing #RGBA colors This was the nicest way of making this happen, I think. Fitting it into the 4 length function ended up becoming too hard to read. Closes #1027 --- Libraries/LibDraw/Color.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Libraries/LibDraw/Color.cpp b/Libraries/LibDraw/Color.cpp index 1b1bf469d5..f6a976d94e 100644 --- a/Libraries/LibDraw/Color.cpp +++ b/Libraries/LibDraw/Color.cpp @@ -281,6 +281,16 @@ Optional Color::from_string(const StringView& string) return Color(r.value() * 17, g.value() * 17, b.value() * 17); } + if (string.length() == 5) { + Optional r = hex_nibble_to_u8(string[1]); + Optional g = hex_nibble_to_u8(string[2]); + Optional b = hex_nibble_to_u8(string[3]); + Optional a = hex_nibble_to_u8(string[4]); + if (!r.has_value() || !g.has_value() || !b.has_value() || !a.has_value()) + return {}; + return Color(r.value() * 17, g.value() * 17, b.value() * 17, a.value() * 17); + } + if (string.length() != 7 && string.length() != 9) return {};