Browse Source

Ensure stops have the correct keyframe associated.

Try to recover from unpatched svg icon with clearer error message.
pull/188/head
weisj 4 years ago
parent
commit
3b229953bf
  1. 22
      property-loader/src/main/java/com/github/weisj/darklaf/icons/DarkSVGIcon.java
  2. 24
      property-loader/src/main/java/com/github/weisj/darklaf/icons/IconColorMapper.java
  3. 1
      property-loader/src/main/java/com/github/weisj/darklaf/icons/ThemedSVGIcon.java

22
property-loader/src/main/java/com/github/weisj/darklaf/icons/DarkSVGIcon.java

@ -131,7 +131,27 @@ public class DarkSVGIcon implements DerivableIcon<DarkSVGIcon>, RotateIcon, Seri
public Image createImage(final Dimension size) {
ensureLoaded(false);
icon.setPreferredSize(size);
return icon.getImage();
try {
return icon.getImage();
} catch (RuntimeException e) {
if (!(this instanceof ThemedSVGIcon)) {
IconColorMapper.patchColors(icon);
Image img = icon.getImage();
/*
* If we get to here the issue was that the icon hasn't been patched because it isn't loaded as a themed
* svg icon.
*/
LOGGER.severe("Icon '" + getName() + "' that defines custom colors isn't loaded as themed icon.");
return img;
}
throw e;
}
}
private String getName() {
String name = uri.toASCIIString();
name = name.substring(Math.min(name.length() - 1, name.lastIndexOf('/') + 1));
return name;
}
protected void ensureImageLoaded(final Component c, final double rotation) {

24
property-loader/src/main/java/com/github/weisj/darklaf/icons/IconColorMapper.java

@ -158,15 +158,15 @@ public final class IconColorMapper {
final float opacity) throws SVGElementException {
LinearGradient grad = new LinearGradient();
grad.addAttribute("id", AnimationElement.AT_XML, name);
if (opacityKey != null) {
if (opacityKey != null && !opacityKey.isEmpty()) {
grad.addAttribute("opacity", AnimationElement.AT_XML, opacityKey);
}
if (fallbacks != null) {
if (fallbacks != null && !fallbacks.getStringValue().isEmpty()) {
grad.addAttribute(fallbacks.getName(), AnimationElement.AT_XML, fallbacks.getStringValue());
}
return new Pair<>(grad, () -> {
Stop stop1 = new Stop();
Stop stop2 = new Stop();
SolidStop stop1 = new SolidStop();
SolidStop stop2 = new SolidStop();
String color = toHexString(c);
try {
stop1.addAttribute("stop-color", AnimationElement.AT_XML, color);
@ -177,9 +177,11 @@ public final class IconColorMapper {
stop1.addAttribute("stop-opacity", AnimationElement.AT_XML, String.valueOf(opacity));
stop2.addAttribute("stop-opacity", AnimationElement.AT_XML, String.valueOf(opacity));
}
grad.loaderAddChild(null, stop1);
grad.loaderAddChild(null, stop2);
} catch (SVGElementException e) {
stop1.build();
stop2.build();
grad.appendStop(stop1);
grad.appendStop(stop2);
} catch (SVGException e) {
e.printStackTrace();
}
});
@ -188,4 +190,12 @@ public final class IconColorMapper {
private static String toHexString(final Color color) {
return "#" + ColorUtil.toHex(color);
}
private static class SolidStop extends Stop {
@Override
public void build() throws SVGException {
super.build();
}
}
}

1
property-loader/src/main/java/com/github/weisj/darklaf/icons/ThemedSVGIcon.java

@ -24,7 +24,6 @@
*/
package com.github.weisj.darklaf.icons;
import java.awt.*;
import java.net.URI;
/**

Loading…
Cancel
Save