You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by tb...@apache.org on 2018/08/27 15:38:39 UTC
svn commit: r1839345 -
/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDExtendedGraphicsState.java
Author: tboehme
Date: Mon Aug 27 15:38:39 2018
New Revision: 1839345
URL: http://svn.apache.org/viewvc?rev=1839345&view=rev
Log:
PDFBOX-4301: check object type before casting to COSNumber in
PDExtendedGraphicsState.getFloatItem; plus additionall fix as
getFloatItem() might (now) 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/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDExtendedGraphicsState.java
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDExtendedGraphicsState.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDExtendedGraphicsState.java?rev=1839345&r1=1839344&r2=1839345&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDExtendedGraphicsState.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDExtendedGraphicsState.java Mon Aug 27 15:38:39 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.
@@ -588,9 +604,10 @@ public class PDExtendedGraphicsState imp
private Float getFloatItem( COSName key )
{
Float retval = null;
- COSNumber value = (COSNumber) dict.getDictionaryObject( key );
- if( value != null )
+ COSBase base = dict.getDictionaryObject(key);
+ if (base instanceof COSNumber)
{
+ COSNumber value = (COSNumber) base;
retval = value.floatValue();
}
return retval;