mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
Fix linear gradient rendering
This commit is contained in:
@ -23,8 +23,33 @@ function LinearGradientContainer(imageData) {
|
||||
}
|
||||
}, this);
|
||||
|
||||
imageData.args.slice(1).forEach(function(colorStop) {
|
||||
// console.log(colorStop, colorStop.match(this.stepRegExp));
|
||||
this.colorStops = imageData.args.slice(1).map(function(colorStop) {
|
||||
var colorStopMatch = colorStop.match(this.stepRegExp);
|
||||
return {
|
||||
color: colorStopMatch[1],
|
||||
stop: colorStopMatch[3] === "%" ? colorStopMatch[2] / 100 : null
|
||||
};
|
||||
}, this);
|
||||
|
||||
if (this.colorStops[0].stop === null) {
|
||||
this.colorStops[0].stop = 0;
|
||||
}
|
||||
|
||||
if (this.colorStops[this.colorStops.length - 1].stop === null) {
|
||||
this.colorStops[this.colorStops.length - 1].stop = 1;
|
||||
}
|
||||
|
||||
this.colorStops.forEach(function(colorStop, index) {
|
||||
if (colorStop.stop === null) {
|
||||
this.colorStops.slice(index).some(function(find, count) {
|
||||
if (find.stop !== null) {
|
||||
colorStop.stop = ((find.stop - this.colorStops[index - 1].stop) / (count + 1)) + this.colorStops[index - 1].stop;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}, this);
|
||||
}
|
||||
}, this);
|
||||
}
|
||||
|
||||
|
@ -104,8 +104,15 @@ CanvasRenderer.prototype.renderBackgroundRepeat = function(imageContainer, backg
|
||||
|
||||
CanvasRenderer.prototype.renderBackgroundGradient = function(gradientImage, bounds) {
|
||||
if (gradientImage instanceof LinearGradientContainer) {
|
||||
var gradient = this.ctx.createLinearGradient(bounds.left, bounds.top, bounds.right, bounds.bottom);
|
||||
//console.log(gradientImage, bounds, gradient);
|
||||
var gradient = this.ctx.createLinearGradient(
|
||||
bounds.left + bounds.width * gradientImage.x0,
|
||||
bounds.top + bounds.height * gradientImage.y0,
|
||||
bounds.left + bounds.width * gradientImage.x1,
|
||||
bounds.top + bounds.height * gradientImage.y1);
|
||||
gradientImage.colorStops.forEach(function(colorStop) {
|
||||
gradient.addColorStop(colorStop.stop, colorStop.color);
|
||||
});
|
||||
this.rectangle(bounds.left, bounds.top, bounds.width, bounds.height, gradient);
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user