Skip to content

Commit b3ecff1

Browse files
pranav1344zbjornson
authored andcommitted
Add support for '/' in rgba
1 parent e6d55d8 commit b3ecff1

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/color.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ parse_clipped_percentage(const char** pStr, float *pFraction) {
210210
#define WHITESPACE_OR_COMMA \
211211
while (' ' == *str || ',' == *str) ++str;
212212

213+
#define WHITESPACE_OR_COMMA_OR_SLASH \
214+
while (' ' == *str || ',' == *str || '/' == *str) ++str;
215+
213216
#define CHANNEL(NAME) \
214217
if (!parse_rgb_channel(&str, &NAME)) \
215218
return 0; \
@@ -649,7 +652,7 @@ rgba_from_rgba_string(const char *str, short *ok) {
649652
CHANNEL(g);
650653
WHITESPACE_OR_COMMA;
651654
CHANNEL(b);
652-
WHITESPACE_OR_COMMA;
655+
WHITESPACE_OR_COMMA_OR_SLASH;
653656
ALPHA(a);
654657
WHITESPACE;
655658
return *ok = 1, rgba_from_rgba(r, g, b, (int) (a * 255));

test/canvas.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,25 @@ describe('Canvas', function () {
224224

225225
ctx.fillStyle = 'rgba( 255, 200, 90, 10 %)'
226226
assert.equal('rgba(255, 200, 90, 0.10)', ctx.fillStyle)
227+
228+
ctx.fillStyle = 'rgba( 255, 200, 90 / 40%)'
229+
assert.equal('rgba(255, 200, 90, 0.40)', ctx.fillStyle)
230+
231+
ctx.fillStyle = 'rgba( 255, 200, 90 / 0.5)'
232+
assert.equal('rgba(255, 200, 90, 0.50)', ctx.fillStyle)
233+
234+
ctx.fillStyle = 'rgba( 255, 200, 90 / 10%)'
235+
assert.equal('rgba(255, 200, 90, 0.10)', ctx.fillStyle)
236+
237+
ctx.fillStyle = 'rgba( 255, 200, 90 / 0.1)'
238+
assert.equal('rgba(255, 200, 90, 0.10)', ctx.fillStyle)
239+
240+
ctx.fillStyle = 'rgba( 255 200 90 / 10%)'
241+
assert.equal('rgba(255, 200, 90, 0.10)', ctx.fillStyle)
242+
243+
ctx.fillStyle = 'rgba( 255 200 90 0.1)'
244+
assert.equal('rgba(255, 200, 90, 0.10)', ctx.fillStyle)
245+
227246
// hsl / hsla tests
228247

229248
ctx.fillStyle = 'hsl(0, 0%, 0%)'

0 commit comments

Comments
 (0)