mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-21 09:49:21 +00:00
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
This commit is contained in:
parent
123dcada05
commit
00596296c4
Notes:
sideshowbarker
2024-07-19 10:17:55 +09:00
Author: https://github.com/N00byEdge 🔰
Commit: 00596296c4
Pull-request: https://github.com/SerenityOS/serenity/pull/1030
1 changed files with 10 additions and 0 deletions
|
@ -281,6 +281,16 @@ Optional<Color> Color::from_string(const StringView& string)
|
|||
return Color(r.value() * 17, g.value() * 17, b.value() * 17);
|
||||
}
|
||||
|
||||
if (string.length() == 5) {
|
||||
Optional<u8> r = hex_nibble_to_u8(string[1]);
|
||||
Optional<u8> g = hex_nibble_to_u8(string[2]);
|
||||
Optional<u8> b = hex_nibble_to_u8(string[3]);
|
||||
Optional<u8> 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 {};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue