Merge pull request #11158 from janpe2/gradient-stops

Avoid floating point inaccuracy in gradient color stops
This commit is contained in:
Tim van der Meij 2019-09-19 13:15:11 +02:00 committed by GitHub
commit 3da680cdfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 6 deletions

View File

@ -143,12 +143,12 @@ Shadings.RadialAxial = (function RadialAxialClosure() {
// 10 samples seems good enough for now, but probably won't work // 10 samples seems good enough for now, but probably won't work
// if there are sharp color changes. Ideally, we would implement // if there are sharp color changes. Ideally, we would implement
// the spec faithfully and add lossless optimizations. // the spec faithfully and add lossless optimizations.
var diff = t1 - t0; const NUMBER_OF_SAMPLES = 10;
var step = diff / 10; const step = (t1 - t0) / NUMBER_OF_SAMPLES;
var colorStops = this.colorStops = []; var colorStops = this.colorStops = [];
// Protect against bad domains so we don't end up in an infinite loop below. // Protect against bad domains.
if (t0 >= t1 || step <= 0) { if (t0 >= t1 || step <= 0) {
// Acrobat doesn't seem to handle these cases so we'll ignore for // Acrobat doesn't seem to handle these cases so we'll ignore for
// now. // now.
@ -158,12 +158,12 @@ Shadings.RadialAxial = (function RadialAxialClosure() {
var color = new Float32Array(cs.numComps), ratio = new Float32Array(1); var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
var rgbColor; var rgbColor;
for (var i = t0; i <= t1; i += step) { for (let i = 0; i <= NUMBER_OF_SAMPLES; i++) {
ratio[0] = i; ratio[0] = t0 + i * step;
fn(ratio, 0, color, 0); fn(ratio, 0, color, 0);
rgbColor = cs.getRgb(color, 0); rgbColor = cs.getRgb(color, 0);
var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]); var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
colorStops.push([(i - t0) / diff, cssColor]); colorStops.push([i / NUMBER_OF_SAMPLES, cssColor]);
} }
var background = 'transparent'; var background = 'transparent';

View File

@ -161,6 +161,7 @@
!issue4402_reduced.pdf !issue4402_reduced.pdf
!issue845r.pdf !issue845r.pdf
!issue3405r.pdf !issue3405r.pdf
!issue7339_reduced.pdf
!issue3438.pdf !issue3438.pdf
!issue2074.pdf !issue2074.pdf
!scan-bad.pdf !scan-bad.pdf

Binary file not shown.

View File

@ -1872,6 +1872,12 @@
"link": true, "link": true,
"type": "load" "type": "load"
}, },
{ "id": "issue7339",
"file": "pdfs/issue7339_reduced.pdf",
"md5": "7092ab6a1acc31db9d1caaa0447334a0",
"rounds": 1,
"type": "eq"
},
{ "id": "bug1142033", { "id": "bug1142033",
"file": "pdfs/bug1142033.pdf", "file": "pdfs/bug1142033.pdf",
"md5": "1d9afd397e89a0f52c056f449ec93daa", "md5": "1d9afd397e89a0f52c056f449ec93daa",