Skip to content

Commit

Permalink
* 修复识别不了canvas.fillStyle("#ffff0000"); 这种四个字节的颜色格式的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
weolar committed Oct 14, 2020
1 parent b294b6e commit 0ae88cf
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions third_party/WebKit/Source/platform/graphics/Color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ RGBA32 makeRGBAFromCMYKA(float c, float m, float y, float k, float a)
template <typename CharacterType>
static inline bool parseHexColorInternal(const CharacterType* name, unsigned length, RGBA32& rgb)
{
if (length != 3 && length != 6)
if (length != 3 && length != 4 && length != 6 && length != 8)
return false;
unsigned value = 0;
for (unsigned i = 0; i < length; ++i) {
Expand All @@ -132,11 +132,23 @@ static inline bool parseHexColorInternal(const CharacterType* name, unsigned len
rgb = 0xFF000000 | value;
return true;
}
if (length == 8) {
// We parsed the values into RGBA order, but the RGBA32 type
// expects them to be in ARGB order, so we right rotate eight bits.
rgb = value << 24 | value >> 8;
return true;
}
if (length == 4) {
// #abcd converts to ddaabbcc in RGBA32.
rgb = (value & 0xF) << 28 | (value & 0xF) << 24 | (value & 0xF000) << 8 |
(value & 0xF000) << 4 | (value & 0xF00) << 4 | (value & 0xF00) |
(value & 0xF0) | (value & 0xF0) >> 4;
return true;
}
// #abc converts to #aabbcc
rgb = 0xFF000000
| (value & 0xF00) << 12 | (value & 0xF00) << 8
| (value & 0xF0) << 8 | (value & 0xF0) << 4
| (value & 0xF) << 4 | (value & 0xF);
rgb = 0xFF000000 | (value & 0xF00) << 12 | (value & 0xF00) << 8 |
(value & 0xF0) << 8 | (value & 0xF0) << 4 | (value & 0xF) << 4 |
(value & 0xF);
return true;
}

Expand Down

0 comments on commit 0ae88cf

Please sign in to comment.