Back to Plantuml

PR: SVG Sprite Linear Gradient Multi-Stop + SpreadMethod

PR_LINEAR_GRADIENT_SPREAD.md

2017.114.9 KB
Original Source

PR: SVG Sprite Linear Gradient Multi-Stop + SpreadMethod

Summary

This PR expands SVG sprite rendering to preserve multi-stop linear gradients and honours SVG spreadMethod values across SVG and PNG outputs.

Key changes

  • SAX sprite parser now captures linearGradient multi-stop definitions and spreadMethod.
  • Gradient model extended to carry spread method for repeat/reflect behavior.
  • SVG output emits multi-stop <linearGradient> with optional spreadMethod.
  • PNG (G2D) output maps spreadMethod to LinearGradientPaint cycle methods.
  • Added visual verification sprite fixtures for pad/reflect/repeat.
  • Added a regression test for standard (non-sprite) gradient vectors in SVG output.

Files touched (high level)

Tests

  • ./gradlew test --tests net.sourceforge.plantuml.svg.parser.SvgSpriteImageGenerationTest
  • ./gradlew test --tests net.sourceforge.plantuml.svg.StandardGradientSvgTest

Notes

  • spreadMethod is preserved in SVG and mapped to PNG cycle methods; default remains pad when unspecified.
  • Visual fixtures allow manual verification of pad/reflect/repeat behavior.
  • Standard gradient regression coverage: StandardGradientSvgTest renders a simple diagram (non-sprite) and asserts SVG gradient vectors for |, -, /, and \\ policies.
  • Design note: gradient stop offsets are normalised to a strictly increasing sequence (ties are nudged by a tiny epsilon) to satisfy Java2D LinearGradientPaint requirements while preserving SVG semantics of non-decreasing offsets.

Why non-parser packages changed

The G2D change is intentionally small and scoped to recognising the new gradient type alongside the existing two-stop HColorGradient. Typical call sites look like this in src/main/java/net/sourceforge/plantuml/klimt/drawing/g2d/DriverPathG2d.java:

java
if (back instanceof HColorGradient || back instanceof HColorLinearGradient) {
	final Paint paint = DriverRectangleG2d.getPaintGradient(..., back);
	g2d.setPaint(paint);
	g2d.fill(path);
}

Regression risk scope

  • Changes are limited to rendering of linear gradients in SVG sprites and to generic gradient flattening behaviour for the new gradient type.
  • Non-gradient rendering paths are unchanged; tests focus on the sprite pipeline but a regression test for standard gradients has been added.