Skip to content

Commit 8854bb6

Browse files
tcl3gmta
authored andcommitted
LibGfx: Use CSS sRGB serialization for canvas fill styles
1 parent ebd802f commit 8854bb6

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

Libraries/LibGfx/Color.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@ String Color::to_string(HTMLCompatibleSerialization html_compatible_serializatio
112112
}
113113

114114
// Otherwise, for sRGB the CSS serialization of sRGB values is used and for other color spaces, the relevant serialization of the <color> value.
115-
if (alpha() < 255)
116-
return MUST(String::formatted("rgba({}, {}, {}, {})", red(), green(), blue(), alpha() / 255.0));
117-
return MUST(String::formatted("rgb({}, {}, {})", red(), green(), blue()));
115+
return serialize_a_srgb_value();
118116
}
119117

120118
String Color::to_string_without_alpha() const
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Harness status: OK
2+
3+
Found 1 tests
4+
5+
1 Pass
6+
Pass Canvas test: 2d.fillStyle.get.halftransparent
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE html>
2+
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
3+
<meta charset="UTF-8">
4+
<title>Canvas test: 2d.fillStyle.get.halftransparent</title>
5+
<script src="../../../../resources/testharness.js"></script>
6+
<script src="../../../../resources/testharnessreport.js"></script>
7+
<script src="../../../../html/canvas/resources/canvas-tests.js"></script>
8+
<link rel="stylesheet" href="../../../../html/canvas/resources/canvas-tests.css">
9+
<body class="show_output">
10+
11+
<h1>2d.fillStyle.get.halftransparent</h1>
12+
<p class="desc"></p>
13+
14+
15+
<p class="output">Actual output:</p>
16+
<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
17+
18+
<ul id="d"></ul>
19+
<script>
20+
var t = async_test("");
21+
_addTest(function(canvas, ctx) {
22+
23+
ctx.fillStyle = 'rgba(255,255,255,0.5)';
24+
_assertSame(ctx.fillStyle, 'rgba(255, 255, 255, 0.5)', "ctx.fillStyle", "'rgba(255, 255, 255, 0.5)'");
25+
26+
});
27+
</script>
28+

0 commit comments

Comments
 (0)