pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1655459 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation: PDAnnotation.java PDAnnotationLine.java PDAnnotationSquareCircle.java PDAppearanceCharacteristicsDictionary.java
Date Wed, 28 Jan 2015 20:36:51 GMT
Author: tilman
Date: Wed Jan 28 20:36:50 2015
New Revision: 1655459

URL: http://svn.apache.org/r1655459
Log:
PDFBOX-2636: return correct colorspace for annotations according to array size

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotation.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationLine.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationSquareCircle.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAppearanceCharacteristicsDictionary.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotation.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotation.java?rev=1655459&r1=1655458&r2=1655459&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotation.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotation.java
Wed Jan 28 20:36:50 2015
@@ -28,6 +28,9 @@ import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.pdmodel.common.COSObjectable;
 import org.apache.pdfbox.pdmodel.common.PDRectangle;
 import org.apache.pdfbox.pdmodel.graphics.color.PDColor;
+import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
+import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceCMYK;
+import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceGray;
 import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceRGB;
 
 /**
@@ -631,25 +634,36 @@ public abstract class PDAnnotation imple
     }
 
     /**
-     * This will retrieve the color used in drawing various elements. As of PDF 1.6 these
are : Background of icon when
-     * closed Title bar of popup window Border of a link annotation
-     * 
-     * Colour is in DeviceRGB colourspace
-     * 
-     * @return PDGamma object representing the colour
+     * This will retrieve the color used in drawing various elements. As of PDF
+     * 1.6 these are :
+     * <ul>
+     * <li>Background of icon when closed</li>
+     * <li>Title bar of popup window</li>
+     * <li>Border of a link annotation</li></ul>
+     *
+     * @return Color object representing the colour
      * 
      */
     public PDColor getColor()
     {
-        COSBase obj = getDictionary().getDictionaryObject(COSName.C);
-        if (obj instanceof COSArray)
-        {
-            return new PDColor((COSArray) obj, PDDeviceRGB.INSTANCE);
-        }
-        else
+        return getColor(COSName.C);
+    }
+
+    protected PDColor getColor(COSName itemName)
+    {
+        COSBase c = this.getDictionary().getItem(itemName);
+        if (c instanceof COSArray)
         {
-            return null;
+            PDColorSpace colorSpace = null;
+            switch (((COSArray) c).size())
+            {
+                case 1: colorSpace = PDDeviceGray.INSTANCE; break;
+                case 3: colorSpace = PDDeviceRGB.INSTANCE; break;
+                case 4: colorSpace = PDDeviceCMYK.INSTANCE; break;
+            }
+            return new PDColor((COSArray) c, colorSpace);
         }
+        return null;
     }
 
     /**

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationLine.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationLine.java?rev=1655459&r1=1655458&r2=1655459&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationLine.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationLine.java
Wed Jan 28 20:36:50 2015
@@ -21,7 +21,6 @@ import org.apache.pdfbox.cos.COSDictiona
 import org.apache.pdfbox.cos.COSFloat;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.graphics.color.PDColor;
-import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceRGB;
 
 /**
  * This is the class that represents a line annotation.
@@ -118,7 +117,6 @@ public class PDAnnotationLine extends PD
         getDictionary().setItem( COSName.SUBTYPE, COSName.getPDFName( SUB_TYPE ) );
         // Dictionary value L is mandatory, fill in with arbitary value
         setLine( new float[] { 0, 0, 0, 0 } );
-
     }
 
     /**
@@ -268,16 +266,7 @@ public class PDAnnotationLine extends PD
      */
     public PDColor getInteriorColor()
     {
-
-        COSArray ic = (COSArray) getDictionary().getDictionaryObject(COSName.IC);
-        if (ic != null)
-        {
-            return new PDColor( ic, PDDeviceRGB.INSTANCE );
-        }
-        else
-        {
-            return null;
-        }
+        return getColor(COSName.IC);
     }
 
     /**

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationSquareCircle.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationSquareCircle.java?rev=1655459&r1=1655458&r2=1655459&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationSquareCircle.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationSquareCircle.java
Wed Jan 28 20:36:50 2015
@@ -21,7 +21,6 @@ import org.apache.pdfbox.cos.COSDictiona
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.common.PDRectangle;
 import org.apache.pdfbox.pdmodel.graphics.color.PDColor;
-import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceRGB;
 
 /**
  * This is the class that represents a rectangular or eliptical annotation
@@ -86,15 +85,7 @@ public class PDAnnotationSquareCircle ex
      */
     public PDColor getInteriorColor()
     {
-        COSArray ic = (COSArray) getDictionary().getItem(COSName.IC);
-        if (ic != null)
-        {
-            return new PDColor( ic, PDDeviceRGB.INSTANCE );
-        }
-        else
-        {
-            return null;
-        }
+        return getColor(COSName.IC);
     }
 
 
@@ -179,6 +170,7 @@ public class PDAnnotationSquareCircle ex
      *
      * @return The subtype of this annotation, see the SUB_TYPE_XXX constants.
      */
+    @Override
     public String getSubtype()
     {
         return getDictionary().getNameAsString( COSName.SUBTYPE);

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAppearanceCharacteristicsDictionary.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAppearanceCharacteristicsDictionary.java?rev=1655459&r1=1655458&r2=1655459&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAppearanceCharacteristicsDictionary.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAppearanceCharacteristicsDictionary.java
Wed Jan 28 20:36:50 2015
@@ -39,7 +39,7 @@ import org.apache.pdfbox.pdmodel.graphic
 public class PDAppearanceCharacteristicsDictionary implements COSObjectable
 {
 
-    private COSDictionary dictionary;
+    private final COSDictionary dictionary;
 
     /**
      * Constructor.



Mime
View raw message