pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tboe...@apache.org
Subject svn commit: r1839325 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDExtendedGraphicsState.java
Date Mon, 27 Aug 2018 13:37:56 GMT
Author: tboehme
Date: Mon Aug 27 13:37:55 2018
New Revision: 1839325

URL: http://svn.apache.org/viewvc?rev=1839325&view=rev
Log:
PDFBOX-4301: follow up fix: now that getFloatItem() might return null with existing key we
also have to handle this case in copyIntoGraphicsState() where an implicit unboxing is done;
fix sets default values (from PDGraphicsState) in case the value from PDExtendedGraphicsState
is wrong (null)

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDExtendedGraphicsState.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDExtendedGraphicsState.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDExtendedGraphicsState.java?rev=1839325&r1=1839324&r2=1839325&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDExtendedGraphicsState.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDExtendedGraphicsState.java
Mon Aug 27 13:37:55 2018
@@ -70,7 +70,7 @@ public class PDExtendedGraphicsState imp
         {
             if( key.equals( COSName.LW ) )
             {
-                gs.setLineWidth( getLineWidth() );
+                gs.setLineWidth( defaultIfNull( getLineWidth(), 1 ) );
             }
             else if( key.equals( COSName.LC ) )
             {
@@ -82,7 +82,7 @@ public class PDExtendedGraphicsState imp
             }
             else if( key.equals( COSName.ML ) )
             {
-                gs.setMiterLimit( getMiterLimit() );
+                gs.setMiterLimit( defaultIfNull( getMiterLimit(), 10 ) );
             }
             else if( key.equals( COSName.D ) )
             {
@@ -94,7 +94,7 @@ public class PDExtendedGraphicsState imp
             }
             else if( key.equals( COSName.OPM ) )
             {
-                gs.setOverprintMode( getOverprintMode().doubleValue() );
+                gs.setOverprintMode( defaultIfNull( getOverprintMode(), 0 ) );
             }
             else if( key.equals( COSName.OP ) )
             {
@@ -115,11 +115,11 @@ public class PDExtendedGraphicsState imp
             }
             else if( key.equals( COSName.FL ) )
             {
-                gs.setFlatness( getFlatnessTolerance() );
+                gs.setFlatness( defaultIfNull( getFlatnessTolerance(), 1.0f ) );
             }
             else if( key.equals( COSName.SM ) )
             {
-                gs.setSmoothness( getSmoothnessTolerance() );
+                gs.setSmoothness( defaultIfNull( getSmoothnessTolerance(), 0 ) );
             }
             else if( key.equals( COSName.SA ) )
             {
@@ -127,11 +127,11 @@ public class PDExtendedGraphicsState imp
             }
             else if( key.equals( COSName.CA ) )
             {
-                gs.setAlphaConstant(getStrokingAlphaConstant());
+                gs.setAlphaConstant( defaultIfNull( getStrokingAlphaConstant(), 1.0f ) );
             }
             else if( key.equals( COSName.CA_NS ) )
             {
-                gs.setNonStrokeAlphaConstant(getNonStrokingAlphaConstant() );
+                gs.setNonStrokeAlphaConstant( defaultIfNull( getNonStrokingAlphaConstant(),
1.0f ) );
             }
             else if( key.equals( COSName.AIS ) )
             {
@@ -174,6 +174,22 @@ public class PDExtendedGraphicsState imp
     }
 
     /**
+     * Returns the provided default value in case 'standard' valu
+     * is <code>null</code>. To be used in cases unboxing may
+     * lead to a NPE.
+     *  
+     * @param _value  'standard' value
+     * @param _default  default value 
+     * 
+     * @return 'standard' value if not <code>null</code>
+     *         otherwise default value
+     */
+    private float defaultIfNull( Float _value, float _default ) 
+    {
+        return _value != null ? _value : _default;
+    }
+    
+    /**
      * This will get the underlying dictionary that this class acts on.
      *
      * @return The underlying dictionary for this class.



Mime
View raw message