From 93749430f49f506d4917129ed6cc3d7939b946f1 Mon Sep 17 00:00:00 2001 From: Sahel LUCAS--SAOUDI Date: Wed, 7 Sep 2022 18:24:55 +0200 Subject: [PATCH] Parse rgba(r,g,b,0) correctly --- .gitignore | 2 ++ src/color.cc | 5 ++++- test/canvas.test.js | 5 ++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index e5e14d5b6..ff66b1103 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,5 @@ package-lock.json *.swp *.un~ npm-debug.log + +.idea diff --git a/src/color.cc b/src/color.cc index 1ea96e195..230fb8dbe 100644 --- a/src/color.cc +++ b/src/color.cc @@ -228,7 +228,10 @@ parse_clipped_percentage(const char** pStr, float *pFraction) { if (*str >= '1' && *str <= '9') { \ NAME = 1; \ } else { \ - if ('0' == *str) ++str; \ + if ('0' == *str) { \ + NAME = 0; \ + ++str; \ + } \ if ('.' == *str) { \ ++str; \ NAME = 0; \ diff --git a/test/canvas.test.js b/test/canvas.test.js index 5abd45cb8..670127783 100644 --- a/test/canvas.test.js +++ b/test/canvas.test.js @@ -210,6 +210,9 @@ describe('Canvas', function () { ctx.fillStyle = 'rgba(255, 250, 255)'; assert.equal('#fffaff', ctx.fillStyle); + ctx.fillStyle = 'rgba(124, 58, 26, 0)'; + assert.equal('rgba(124, 58, 26, 0.00)', ctx.fillStyle); + // hsl / hsla tests ctx.fillStyle = 'hsl(0, 0%, 0%)' @@ -985,7 +988,7 @@ describe('Canvas', function () { const cm = ctx.measureText('aaaa') assertApprox(cm.actualBoundingBoxLeft, 9, 6) assertApprox(cm.actualBoundingBoxRight, 11, 6) - + ctx.textAlign = 'right' const rm = ctx.measureText('aaaa') assertApprox(rm.actualBoundingBoxLeft, 19, 6)