Merge pull request #15 from LLK/fix-text-gradients

Fix gradients applied to text.
This commit is contained in:
DD Liu 2018-07-17 11:45:42 -04:00 committed by GitHub
commit 9043d1236f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -194,7 +194,7 @@ new function() {
return SvgElement.create('use', attrs, formatter);
}
function exportGradient(color) {
function exportGradient(color, item) {
// NOTE: As long as the fillTransform attribute is not implemented,
// we need to create a separate gradient object for each gradient,
// even when they share the same gradient definition.
@ -226,6 +226,13 @@ new function() {
y2: destination.y
};
}
// Scratch-specific: apply inverse of item transform for text elements
// because they use transform instead of x/y.
if (item instanceof paper.PointText) {
attrs.gradientTransform = getTransform(
item._matrix.clone().invert(), false, formatter).transform;
}
attrs.gradientUnits = 'userSpaceOnUse';
gradientNode = SvgElement.create((radial ? 'radial' : 'linear')
+ 'Gradient', attrs, formatter);
@ -298,7 +305,10 @@ new function() {
value = item[get]();
if (entry.exportFilter
? entry.exportFilter(item, value)
: !parent || !Base.equals(parent[get](), value)) {
: !parent || !Base.equals(parent[get](), value) ||
// Scratch-specific: always apply styles to text elements to
// because gradients must be specified to avoid transform problems.
item instanceof paper.PointText) {
if (type === 'color' && value != null) {
// Support for css-style rgba() values is not in SVG 1.1, so
// separate the alpha value of colors with alpha into the