pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1832264 - in /pdfbox/trunk/pdfbox/src: main/java/org/apache/pdfbox/pdmodel/graphics/blend/BlendMode.java test/java/org/apache/pdfbox/pdmodel/graphics/blend/ test/java/org/apache/pdfbox/pdmodel/graphics/blend/BlendModeTest.java
Date Fri, 25 May 2018 18:36:15 GMT
Author: tilman
Date: Fri May 25 18:36:15 2018
New Revision: 1832264

URL: http://svn.apache.org/viewvc?rev=1832264&view=rev
Log:
PDFBOX-4071: add test to protect initialization sequence; move constructor to top for Sonar;
avoid COMPATIBLE returning blend mode that specification says "shouldn't be used"

Added:
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/blend/
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/blend/BlendModeTest.java
  (with props)
Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/blend/BlendMode.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/blend/BlendMode.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/blend/BlendMode.java?rev=1832264&r1=1832263&r2=1832264&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/blend/BlendMode.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/blend/BlendMode.java
Fri May 25 18:36:15 2018
@@ -60,7 +60,7 @@ public abstract class BlendMode
         {
             return result;
         }
-        return BlendMode.COMPATIBLE;
+        return BlendMode.NORMAL;
     }
     
     /**
@@ -251,6 +251,10 @@ public abstract class BlendMode
         }
     };
 
+    BlendMode()
+    {
+    }
+
     private static int get255Value(float val)
     {
         return (int) Math.floor(val >= 1.0 ? 255 : val * 255.0);
@@ -376,7 +380,7 @@ public abstract class BlendMode
         result[2] = b / 255.0f;
     }
     
-    // these maps *must* come after the declarations above, otherwise its values will be
null
+    // these maps *must* come after the BlendMode.* constant declarations, otherwise their
values would be null
     private static final Map<COSName, BlendMode> BLEND_MODES = createBlendModeMap();
     private static final Map<BlendMode, COSName> BLEND_MODE_NAMES = createBlendModeNamesMap();
 
@@ -384,7 +388,8 @@ public abstract class BlendMode
     {
         Map<COSName, BlendMode> map = new HashMap<>(13);
         map.put(COSName.NORMAL, BlendMode.NORMAL);
-        map.put(COSName.COMPATIBLE, BlendMode.COMPATIBLE);
+        // BlendMode.COMPATIBLE should not be used
+        map.put(COSName.COMPATIBLE, BlendMode.NORMAL);
         map.put(COSName.MULTIPLY, BlendMode.MULTIPLY);
         map.put(COSName.SCREEN, BlendMode.SCREEN);
         map.put(COSName.OVERLAY, BlendMode.OVERLAY);
@@ -407,7 +412,8 @@ public abstract class BlendMode
     {
         Map<BlendMode, COSName> map = new HashMap<>(13);
         map.put(BlendMode.NORMAL, COSName.NORMAL);
-        map.put(BlendMode.COMPATIBLE, COSName.COMPATIBLE);
+        // BlendMode.COMPATIBLE should not be used
+        map.put(BlendMode.COMPATIBLE, COSName.NORMAL);
         map.put(BlendMode.MULTIPLY, COSName.MULTIPLY);
         map.put(BlendMode.SCREEN, COSName.SCREEN);
         map.put(BlendMode.OVERLAY, COSName.OVERLAY);
@@ -425,8 +431,4 @@ public abstract class BlendMode
         map.put(BlendMode.COLOR, COSName.COLOR);
         return map;
     }
-
-    BlendMode()
-    {
-    }
 }

Added: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/blend/BlendModeTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/blend/BlendModeTest.java?rev=1832264&view=auto
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/blend/BlendModeTest.java
(added)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/blend/BlendModeTest.java
Fri May 25 18:36:15 2018
@@ -0,0 +1,84 @@
+/*
+ * 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.pdfbox.pdmodel.graphics.blend;
+
+import static junit.framework.TestCase.assertEquals;
+import org.apache.pdfbox.cos.COSName;
+import org.junit.Test;
+
+/**
+ *
+ * @author Tilman Hausherr
+ */
+public class BlendModeTest
+{
+    public BlendModeTest()
+    {
+    }
+
+    /**
+     * Check that BlendMode.* constant instances are not null. This could happen if the declaration
+     * sequence is changed.
+     */
+    @Test
+    public void testInstances()
+    {
+        assertEquals(BlendMode.NORMAL, BlendMode.getInstance(COSName.NORMAL));
+        assertEquals(BlendMode.NORMAL, BlendMode.getInstance(COSName.COMPATIBLE));
+        assertEquals(BlendMode.MULTIPLY, BlendMode.getInstance(COSName.MULTIPLY));
+        assertEquals(BlendMode.SCREEN, BlendMode.getInstance(COSName.SCREEN));
+        assertEquals(BlendMode.OVERLAY, BlendMode.getInstance(COSName.OVERLAY));
+        assertEquals(BlendMode.DARKEN, BlendMode.getInstance(COSName.DARKEN));
+        assertEquals(BlendMode.LIGHTEN, BlendMode.getInstance(COSName.LIGHTEN));
+        assertEquals(BlendMode.COLOR_DODGE, BlendMode.getInstance(COSName.COLOR_DODGE));
+        assertEquals(BlendMode.COLOR_BURN, BlendMode.getInstance(COSName.COLOR_BURN));
+        assertEquals(BlendMode.HARD_LIGHT, BlendMode.getInstance(COSName.HARD_LIGHT));
+        assertEquals(BlendMode.SOFT_LIGHT, BlendMode.getInstance(COSName.SOFT_LIGHT));
+        assertEquals(BlendMode.DIFFERENCE, BlendMode.getInstance(COSName.DIFFERENCE));
+        assertEquals(BlendMode.EXCLUSION, BlendMode.getInstance(COSName.EXCLUSION));
+        assertEquals(BlendMode.HUE, BlendMode.getInstance(COSName.HUE));
+        assertEquals(BlendMode.SATURATION, BlendMode.getInstance(COSName.SATURATION));
+        assertEquals(BlendMode.LUMINOSITY, BlendMode.getInstance(COSName.LUMINOSITY));
+        assertEquals(BlendMode.COLOR, BlendMode.getInstance(COSName.COLOR));
+    }
+
+    /**
+     * Check that COSName constants returned for BlendMode.* instances are not null. This
could
+     * happen if the declaration sequence is changed.
+     */
+    @Test
+    public void testCOSNames()
+    {
+        assertEquals(COSName.NORMAL, BlendMode.getCOSName(BlendMode.NORMAL));
+        assertEquals(COSName.NORMAL, BlendMode.getCOSName(BlendMode.COMPATIBLE));
+        assertEquals(COSName.MULTIPLY, BlendMode.getCOSName(BlendMode.MULTIPLY));
+        assertEquals(COSName.SCREEN, BlendMode.getCOSName(BlendMode.SCREEN));
+        assertEquals(COSName.OVERLAY, BlendMode.getCOSName(BlendMode.OVERLAY));
+        assertEquals(COSName.DARKEN, BlendMode.getCOSName(BlendMode.DARKEN));
+        assertEquals(COSName.LIGHTEN, BlendMode.getCOSName(BlendMode.LIGHTEN));
+        assertEquals(COSName.COLOR_DODGE, BlendMode.getCOSName(BlendMode.COLOR_DODGE));
+        assertEquals(COSName.COLOR_BURN, BlendMode.getCOSName(BlendMode.COLOR_BURN));
+        assertEquals(COSName.HARD_LIGHT, BlendMode.getCOSName(BlendMode.HARD_LIGHT));
+        assertEquals(COSName.SOFT_LIGHT, BlendMode.getCOSName(BlendMode.SOFT_LIGHT));
+        assertEquals(COSName.DIFFERENCE, BlendMode.getCOSName(BlendMode.DIFFERENCE));
+        assertEquals(COSName.EXCLUSION, BlendMode.getCOSName(BlendMode.EXCLUSION));
+        assertEquals(COSName.HUE, BlendMode.getCOSName(BlendMode.HUE));
+        assertEquals(COSName.SATURATION, BlendMode.getCOSName(BlendMode.SATURATION));
+        assertEquals(COSName.LUMINOSITY, BlendMode.getCOSName(BlendMode.LUMINOSITY));
+        assertEquals(COSName.COLOR, BlendMode.getCOSName(BlendMode.COLOR));
+    }
+}

Propchange: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/blend/BlendModeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message