docs/feature-requests/svg-gradient-sax-parser.md
Is your feature request related to a problem? Please describe.
The current SAX SVG sprite parser supports linear gradients but only uses the first and last stops. Intermediate stops, offsets, and stop-opacity are ignored, and gradient direction is reduced to horizontal, vertical, or diagonal. This causes SVG gradients (including fades to transparent) to render incorrectly.
Current behavior example (SAX parser output):
Describe the solution you'd like Implement full SVG linear gradient support for sprite parsing so gradients behave like standard SVG:
stop-opacity.x1/y1/x2/y2 without reducing to PlantUML's four-direction policy.Describe alternatives you've considered
Additional context Relationship to PlantUML gradient syntax:
"You can also use color gradient for background colors, with the following syntax: two colors names separated either by: |, /, \, or
depending on the direction of the gradient."
Example:
#blue\9932CC
This request does not change that syntax. Instead, SVG sprite parsing would use full SVG gradient semantics when fill="url(#...)" is present.
Design summary:
Implementation sketch:
stop-opacity and offsets.Pseudo-code:
// During defs collection
if ("stop".equals(qName) && currentGradient != null) {
String offset = attrs.getValue("offset");
String stopColor = attrs.getValue("stop-color");
String stopOpacity = attrs.getValue("stop-opacity");
GradientStop stop = new GradientStop(
parseOffset(offset),
parseColor(stopColor),
parseOpacity(stopOpacity, 1.0)
);
currentGradient.stops.add(stop);
}
// During rendering
if (fill.startsWith("url(#")) {
GradientDef gradient = defs.get(gradientId);
if (gradient != null && gradient.isLinear()) {
MultiStopGradient g = new MultiStopGradient(
gradient.vector, // x1,y1,x2,y2
gradient.stops // offset, color, opacity
);
applyFillGradient(g);
} else {
applyFallbackColor();
}
}
Notes: