You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlgraphics.apache.org by ss...@apache.org on 2024/06/18 07:41:10 UTC

(xmlgraphics-batik) branch main updated: BATIK-1285: Set offset to 0 if missing in stop tag

This is an automated email from the ASF dual-hosted git repository.

ssteiner pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/xmlgraphics-batik.git


The following commit(s) were added to refs/heads/main by this push:
     new 129129524 BATIK-1285: Set offset to 0 if missing in stop tag
129129524 is described below

commit 1291295244db1458d86cb67e3698db0536cffdd3
Author: Simon Steiner <ss...@apache.org>
AuthorDate: Tue Jun 18 08:40:47 2024 +0100

    BATIK-1285: Set offset to 0 if missing in stop tag
---
 .../bridge/AbstractSVGGradientElementBridge.java   |  4 +-
 ...radietElementBridgeOffsetAttributeTestCase.java | 53 ++++++++++++++++++++++
 .../org/apache/batik/bridge/unitTesting.xml        |  8 ++--
 3 files changed, 58 insertions(+), 7 deletions(-)

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 0d1fd1606..112323ccf 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,7 @@ public abstract class AbstractSVGGradientElementBridge
 
             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});
+                s = "0";
             }
             float offset;
             try {
diff --git a/batik-test-old/src/test/java/org/apache/batik/svg/SVGGradietElementBridgeOffsetAttributeTestCase.java b/batik-test-old/src/test/java/org/apache/batik/svg/SVGGradietElementBridgeOffsetAttributeTestCase.java
new file mode 100644
index 000000000..9656b66cf
--- /dev/null
+++ b/batik-test-old/src/test/java/org/apache/batik/svg/SVGGradietElementBridgeOffsetAttributeTestCase.java
@@ -0,0 +1,53 @@
+/*
+
+   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.svg;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import org.apache.batik.transcoder.TranscoderInput;
+import org.apache.batik.transcoder.TranscoderOutput;
+import org.apache.batik.transcoder.image.PNGTranscoder;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Test class for verifying correct handling of SVG gradient stops without an 'offset' attribute.
+ * *
+ * @version $Id$
+ */
+public class SVGGradietElementBridgeOffsetAttributeTestCase  {
+    @Test
+    public void testNoOffset() throws Exception {
+        String svgContent = "<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100'>" +
+                "<defs>" +
+                "<linearGradient id='gradient'>" +
+                "<stop stop-color='red'/>" + // No offset attribute
+                "<stop offset='100%' stop-color='blue'/>" +
+                "</linearGradient>" +
+                "</defs>" +
+                "<rect width='100%' height='100%' fill='url(#gradient)' />" +
+                "</svg>";
+        PNGTranscoder transcoder = new PNGTranscoder();
+        TranscoderInput input = new TranscoderInput(new ByteArrayInputStream(svgContent.getBytes()));
+        ByteArrayOutputStream ostream = new ByteArrayOutputStream();
+        TranscoderOutput output = new TranscoderOutput(ostream);
+        transcoder.transcode(input, output);
+        Assert.assertNotNull(ostream.toByteArray());
+    }
+}
diff --git a/test-resources/org/apache/batik/bridge/unitTesting.xml b/test-resources/org/apache/batik/bridge/unitTesting.xml
index 721a05380..66cd8cc43 100644
--- a/test-resources/org/apache/batik/bridge/unitTesting.xml
+++ b/test-resources/org/apache/batik/bridge/unitTesting.xml
@@ -418,12 +418,12 @@
             <property name="ExpectedErrorCode" class="java.lang.String"
                       value="attribute.malformed" />
         </test>
-        <test id="bridge/error/linearGradient-missing-offset">
+        <!--<test id="bridge/error/linearGradient-missing-offset">
             <property name="ExpectedExceptionClass" class="java.lang.String"
                       value="org.apache.batik.bridge.BridgeException" />
             <property name="ExpectedErrorCode" class="java.lang.String"
                       value="attribute.missing" />
-        </test>
+        </test>-->
         <test id="bridge/error/linearGradient-spreadMethod-invalid">
             <property name="ExpectedExceptionClass" class="java.lang.String"
                       value="org.apache.batik.bridge.BridgeException" />
@@ -515,12 +515,12 @@
             <property name="ExpectedErrorCode" class="java.lang.String"
                       value="attribute.malformed" />
         </test>
-        <test id="bridge/error/radialGradient-missing-offset">
+        <!--<test id="bridge/error/radialGradient-missing-offset">
             <property name="ExpectedExceptionClass" class="java.lang.String"
                       value="org.apache.batik.bridge.BridgeException" />
             <property name="ExpectedErrorCode" class="java.lang.String"
                       value="attribute.missing" />
-        </test>
+        </test>-->
         <test id="bridge/error/radialGradient-r-negative">
             <property name="ExpectedExceptionClass" class="java.lang.String"
                       value="org.apache.batik.bridge.BridgeException" />


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org