diff --git a/batik-bridge/src/main/java/org/apache/batik/bridge/AbstractSVGGradientElementBridge.java b/batik-bridge/src/main/java/org/apache/batik/bridge/AbstractSVGGradientElementBridge.java index 0d1fd1606f..2b587d41cb 100644 --- a/batik-bridge/src/main/java/org/apache/batik/bridge/AbstractSVGGradientElementBridge.java +++ b/batik-bridge/src/main/java/org/apache/batik/bridge/AbstractSVGGradientElementBridge.java @@ -313,9 +313,8 @@ public Stop createStop(BridgeContext ctx, String s = stopElement.getAttributeNS(null, SVG_OFFSET_ATTRIBUTE); if (s.length() == 0) { - throw new BridgeException - (ctx, stopElement, ERR_ATTRIBUTE_MISSING, - new Object[] {SVG_OFFSET_ATTRIBUTE}); + //use default value according to the specification + s = "0"; } float offset; try { diff --git a/batik-test-svg/src/main/java/org/apache/batik/test/svg/AbstractSVGGradietElementBridgeOffsetAttributeTest.java b/batik-test-svg/src/main/java/org/apache/batik/test/svg/AbstractSVGGradietElementBridgeOffsetAttributeTest.java new file mode 100644 index 0000000000..a842460ff8 --- /dev/null +++ b/batik-test-svg/src/main/java/org/apache/batik/test/svg/AbstractSVGGradietElementBridgeOffsetAttributeTest.java @@ -0,0 +1,67 @@ +/* + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ +package org.apache.batik.test.svg; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import org.apache.batik.test.AbstractTest; +import org.apache.batik.test.TestReport; +import org.apache.batik.transcoder.TranscoderInput; +import org.apache.batik.transcoder.TranscoderOutput; +import org.apache.batik.transcoder.image.PNGTranscoder; + +/** + * Test class for verifying correct handling of SVG gradient stops without an 'offset' attribute. + * * + * @version $Id$ + */ +public class AbstractSVGGradietElementBridgeOffsetAttributeTest extends AbstractTest { + + public static final String ERROR_PNG_RENDERING_NOT_ACCURATE + = "SVGRenderingAccuracyTest.error.svg.rendering.not.accurate"; + + public TestReport runImpl() throws Exception{ + String svgContent = "" + + "" + + "" + + "" + // No offset attribute + "" + + "" + + "" + + "" + + ""; + + // Set up the PNGTranscoder and input/output streams + PNGTranscoder transcoder = new PNGTranscoder(); + TranscoderInput input = new TranscoderInput(new ByteArrayInputStream(svgContent.getBytes())); + ByteArrayOutputStream ostream = new ByteArrayOutputStream(); + TranscoderOutput output = new TranscoderOutput(ostream); + + // Perform the transcoding process + transcoder.transcode(input, output); + + // Verify the output is not null, indicating transcoding occurred without exception + if(ostream.toByteArray() == null){ + error(ERROR_PNG_RENDERING_NOT_ACCURATE); + } + + System.out.println("Test completed successfully - SVG without explicit stop offset was handled."); + return reportSuccess(); + } +}