FlatSVGIcon: some additions to PR #817:

- create new `LinearGradientPaint` only if color has changed
- preserve old `LinearGradientPaint.colorSpace` and `transform`
This commit is contained in:
Karl Tauber
2024-03-12 12:20:31 +01:00
parent 4be97b6ea6
commit 1f1ebc3c44
10 changed files with 142 additions and 10 deletions

View File

@@ -985,11 +985,12 @@ public class FlatSVGIcon
paint = filterColor( (Color) paint );
else if( paint instanceof LinearGradientPaint ) {
LinearGradientPaint oldPaint = (LinearGradientPaint) paint;
paint = new LinearGradientPaint( oldPaint.getStartPoint(),
oldPaint.getEndPoint(),
oldPaint.getFractions(),
filterColors( oldPaint.getColors() ),
oldPaint.getCycleMethod() );
Color[] newColors = filterColors( oldPaint.getColors() );
if( newColors != null ) {
paint = new LinearGradientPaint( oldPaint.getStartPoint(), oldPaint.getEndPoint(),
oldPaint.getFractions(), newColors, oldPaint.getCycleMethod(),
oldPaint.getColorSpace(), oldPaint.getTransform() );
}
}
super.setPaint( paint );
}
@@ -1013,9 +1014,12 @@ public class FlatSVGIcon
private Color[] filterColors( Color[] colors ) {
Color[] newColors = new Color[colors.length];
for( int i = 0; i < colors.length; i++ )
boolean changed = false;
for( int i = 0; i < colors.length; i++ ) {
newColors[i] = filterColor( colors[i] );
return newColors;
changed = (changed || newColors[i] != colors[i]);
}
return changed ? newColors : null;
}
}
}