Skip to content

Commit a49c3a2

Browse files
committed
Correctly handle named colors in gradients
1 parent 4b80102 commit a49c3a2

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

dist/html2canvas.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2440,7 +2440,7 @@ function LinearGradientContainer(imageData) {
24402440
}
24412441

24422442
this.colorStops = imageData.args.slice(hasDirection ? 1 : 0).map(function(colorStop) {
2443-
var colorStopMatch = colorStop.replace(/transparent/g, 'rgba(0, 0, 0, 0.0)').match(this.stepRegExp);
2443+
var colorStopMatch = colorStop.match(/((?:rgb|rgba)\(\d{1,3},\s\d{1,3},\s\d{1,3}(?:,\s[0-9\.]+)?\)|\w+)\s*(\d{1,3})?(%|px)?/);
24442444
return {
24452445
color: new Color(colorStopMatch[1]),
24462446
stop: colorStopMatch[3] === "%" ? colorStopMatch[2] / 100 : null
@@ -2743,7 +2743,7 @@ NodeContainer.prototype.getValue = function() {
27432743
return value.length === 0 ? (this.node.placeholder || "") : value;
27442744
};
27452745

2746-
NodeContainer.prototype.MATRIX_PROPERTY = /(matrix)\((.+)\)/;
2746+
NodeContainer.prototype.MATRIX_PROPERTY = /(matrix|matrix3d)\((.+)\)/;
27472747
NodeContainer.prototype.TEXT_SHADOW_PROPERTY = /((rgba|rgb)\([^\)]+\)(\s-?\d+px){0,})/g;
27482748
NodeContainer.prototype.TEXT_SHADOW_VALUES = /(-?\d+px)|(#.+)|(rgb\(.+\))|(rgba\(.+\))/g;
27492749
NodeContainer.prototype.CLIP = /^rect\((\d+)px,? (\d+)px,? (\d+)px,? (\d+)px\)$/;
@@ -2758,6 +2758,11 @@ function parseMatrix(match) {
27582758
return match[2].split(",").map(function(s) {
27592759
return parseFloat(s.trim());
27602760
});
2761+
} else if (match && match[1] === "matrix3d") {
2762+
var matrix3d = match[2].split(",").map(function(s) {
2763+
return parseFloat(s.trim());
2764+
});
2765+
return [matrix3d[0], matrix3d[1], matrix3d[4], matrix3d[5], matrix3d[12], matrix3d[13]];
27612766
}
27622767
}
27632768

dist/html2canvas.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lineargradientcontainer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function LinearGradientContainer(imageData) {
4242
}
4343

4444
this.colorStops = imageData.args.slice(hasDirection ? 1 : 0).map(function(colorStop) {
45-
var colorStopMatch = colorStop.replace(/transparent/g, 'rgba(0, 0, 0, 0.0)').match(this.stepRegExp);
45+
var colorStopMatch = colorStop.match(/((?:rgb|rgba)\(\d{1,3},\s\d{1,3},\s\d{1,3}(?:,\s[0-9\.]+)?\)|\w+)\s*(\d{1,3})?(%|px)?/);
4646
return {
4747
color: new Color(colorStopMatch[1]),
4848
stop: colorStopMatch[3] === "%" ? colorStopMatch[2] / 100 : null

tests/cases/background/linear-gradient.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@
112112
.linearGradient8 {
113113
background: linear-gradient(to top left, #fff 0%, #00263c 100%);
114114
}
115+
116+
.linearGradient9 {
117+
background: linear-gradient(to top left, white 0%, black 100%);
118+
}
115119
</style>
116120

117121
</head>
@@ -125,6 +129,7 @@
125129
<div class="linearGradient6">&nbsp;</div>
126130
<div class="linearGradient7">&nbsp;</div>
127131
<div class="linearGradient8">&nbsp;</div>
132+
<div class="linearGradient9">&nbsp;</div>
128133
</div>
129134
</body>
130135
</html>

0 commit comments

Comments
 (0)