SVG: Optimize output of color alpha values

as suggested by drzed
This commit is contained in:
zzz
2024-07-27 10:04:57 -04:00
parent 5f748f7a55
commit 87a49e1abf

View File

@ -349,19 +349,12 @@ public class SimpleSVGMaker {
private void addStroke(String type, Color color, BasicStroke stroke) { private void addStroke(String type, Color color, BasicStroke stroke) {
buf.append(type); buf.append(type);
if (color != null) { if (color != null) {
// todo getRGB() #tohex & 0xffffff // Output RGB or RGBA. getRGB() is ARGB.
//buf.append("=\"rgb(").append(color.getRed()) buf.append("=\"#").append(String.format(Locale.US, "%06x", color.getRGB() & 0xffffff));
// .append(',').append(color.getGreen())
// .append(',').append(color.getBlue())
// .append(")\" ");
buf.append("=\"#").append(String.format(Locale.US, "%06x", color.getRGB() & 0xffffff))
.append("\" ");
int alpha = color.getAlpha(); int alpha = color.getAlpha();
if (alpha < 255) { if (alpha < 255)
buf.append(type).append("-opacity=\"") buf.append(String.format(Locale.US, "%02x", alpha));
.append(String.format(Locale.US, "%.2f", alpha / 255f)) buf.append("\" ");
.append("\" ");
}
} else { } else {
// default is black opaque, so fixup for none // default is black opaque, so fixup for none
buf.append("=\"none\" "); buf.append("=\"none\" ");