Skip to content

color-rendering CSS property and SVG attribute was removed #134

@carlosame

Description

@carlosame

The color-rendering CSS property (and the corresponding SVG attribute) was removed from the SVG specification (w3c/svgwg#647).

Both EchoSVG and Batik are using it and I wondered if it would make sense to default to optimizeQuality here.


Experiment

I applied the following patch to CSSUtilities in the css module:

@@ -480,29 +480,28 @@ public abstract class CSSUtilities implements CSSConstants, ErrorConstants, XMLC
 	 * @param hints a RenderingHints to fill, or null.
 	 */
 	public static RenderingHints convertColorRendering(Element e, RenderingHints hints) {
 		Value v = getComputedStyle(e, SVGCSSEngine.COLOR_RENDERING_INDEX);
 		String s = v.getIdentifierValue();
-		int len = s.length();
-		if ((len == 4) && (s.charAt(0) == 'a')) // auto
-			return hints;
-		if (len < 13)
-			return hints; // Unknown.
 
-		if (hints == null)
+		if (hints == null) {
 			hints = new RenderingHints(null);
+		}
 
-		switch (s.charAt(8)) {
-		case 's': // optimizeSpeed
+		if (s.length() == 13 && s.charAt(8) == 's') { // optimizeSpeed
 			hints.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED);
-			hints.put(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED);
-			break;
-		case 'q': // optimizeQuality
-			hints.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
-			hints.put(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
-			break;
+			hints.put(RenderingHints.KEY_ALPHA_INTERPOLATION,
+					RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED);
+			return hints;
 		}
+		// auto, optimizeQuality or invalid
+
+		// In this implementation, optimizeQuality is equivalent to auto or invalid
+		hints.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
+		hints.put(RenderingHints.KEY_ALPHA_INTERPOLATION,
+				RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
+
 		return hints;
 	}
 
 	/////////////////////////////////////////////////////////////////////////
 	// 'display'

and then ran the tests.


Results

44 tests failed (rendering variations were detected), with many images looking better (e.g. radial gradients) while others don't. In the following images, left is the current rendering, right is with the patch:

gradientLimit
Image

linearGradientRepeat
Image

paintType
Image

radialGradient
Image

radialGradient2
Image


The gradientLimit rendering doesn't look good and I wonder if that could be considered a bug in the JDK; the left solid line in the paintType squares looks like a bug as well.

I have no plans to merge the patch but feedback would be appreciated, if anyone is familiar with the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    spec complianceSome behavior may not be spec-compliant

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions