From 0eb5fdb5b978f43ae6cd87890637533f77c7addf Mon Sep 17 00:00:00 2001 From: Sahel LUCAS--SAOUDI Date: Wed, 7 Sep 2022 18:24:55 +0200 Subject: [PATCH 1/2] 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) From 3fbded248f4c8c7565c3ae2ee2f15b408f5daf0e Mon Sep 17 00:00:00 2001 From: Sahel LUCAS--SAOUDI Date: Wed, 7 Sep 2022 18:28:40 +0200 Subject: [PATCH 2/2] add line in CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 085dd412f..ece076034 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ project adheres to [Semantic Versioning](http://semver.org/). ### Added ### Fixed * Fix `actualBoundingBoxLeft` and `actualBoundingBoxRight` when `textAlign='center'` or `'right'` ([#1909](https://github.com/Automattic/node-canvas/issues/1909)) +* Fix `rgba(r,g,b,0)` with alpha to 0 should parse as transparent, not opaque. 2.10.0 ==================