pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From msahy...@apache.org
Subject svn commit: r1793635 - in /pdfbox/branches/2.0/pdfbox/src: main/java/org/apache/pdfbox/pdmodel/interactive/form/PDDefaultAppearanceString.java test/java/org/apache/pdfbox/pdmodel/interactive/form/PDDefaultAppearanceStringTest.java
Date Wed, 03 May 2017 10:51:23 GMT
Author: msahyoun
Date: Wed May  3 10:51:22 2017
New Revision: 1793635

URL: http://svn.apache.org/viewvc?rev=1793635&view=rev
Log:
PDFBOX-3752: support DeviceGray and DeviceCMYK operator for setting the font color in default
appearance string

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDDefaultAppearanceString.java
    pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDDefaultAppearanceStringTest.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDDefaultAppearanceString.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDDefaultAppearanceString.java?rev=1793635&r1=1793634&r2=1793635&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDDefaultAppearanceString.java
(original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDDefaultAppearanceString.java
Wed May  3 10:51:22 2017
@@ -34,7 +34,8 @@ import org.apache.pdfbox.pdmodel.PDResou
 import org.apache.pdfbox.pdmodel.font.PDFont;
 import org.apache.pdfbox.pdmodel.graphics.color.PDColor;
 import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
-import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceColorSpace;
+import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceCMYK;
+import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceGray;
 import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceRGB;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceStream;
 
@@ -130,10 +131,18 @@ class PDDefaultAppearanceString
         {
             processSetFont(operands);
         }
+        else if ("g".equals(name))
+        {
+            processSetFontColor(operands);
+        }
         else if ("rg".equals(name))
         {
             processSetFontColor(operands);
         }
+        else if ("k".equals(name))
+        {
+            processSetFontColor(operands);
+        }
     }
     
     /**
@@ -184,9 +193,21 @@ class PDDefaultAppearanceString
      */
     private void processSetFontColor(List<COSBase> operands) throws IOException
     {
-        PDColorSpace colorSpace = PDDeviceRGB.INSTANCE;
-        if (colorSpace instanceof PDDeviceColorSpace &&
-            operands.size() < colorSpace.getNumberOfComponents())
+    	PDColorSpace colorSpace = null;
+        
+        if (operands.size() == 1)
+        {
+            colorSpace = PDDeviceGray.INSTANCE;
+        }
+        else if (operands.size() == 3)
+        {
+            colorSpace = PDDeviceRGB.INSTANCE;
+        }
+        else if (operands.size() == 4)
+        {
+            colorSpace = PDDeviceCMYK.INSTANCE;
+        }
+        else 
         {
             throw new IOException("Missing operands for set non stroking color operator "
+ Arrays.toString(operands.toArray()));
         }

Modified: pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDDefaultAppearanceStringTest.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDDefaultAppearanceStringTest.java?rev=1793635&r1=1793634&r2=1793635&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDDefaultAppearanceStringTest.java
(original)
+++ pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDDefaultAppearanceStringTest.java
Wed May  3 10:51:22 2017
@@ -46,7 +46,7 @@ public class PDDefaultAppearanceStringTe
     @Test
     public void testParseDAString() throws IOException
     {
-        COSString sampleString = new COSString("/" + fontResourceName.getName() + " 12 Tf
0.019 0.305 0.627 rg 0g");
+        COSString sampleString = new COSString("/" + fontResourceName.getName() + " 12 Tf
0.019 0.305 0.627 rg");
 
         PDDefaultAppearanceString defaultAppearanceString = new PDDefaultAppearanceString(sampleString,
resources);
 
@@ -61,14 +61,14 @@ public class PDDefaultAppearanceStringTe
     @Test(expected=IOException.class)
     public void testFontResourceUnavailable() throws IOException
     {
-        COSString sampleString = new COSString("/Helvetica 12 Tf 0.019 0.305 0.627 rg 0g");
+        COSString sampleString = new COSString("/Helvetica 12 Tf 0.019 0.305 0.627 rg");
         new PDDefaultAppearanceString(sampleString, resources);
     }
     
     @Test(expected=IOException.class)
     public void testWrongNumberOfColorArguments() throws IOException
     {
-        COSString sampleString = new COSString("/Helvetica 12 Tf 0.305 0.627 rg 0g");
+        COSString sampleString = new COSString("/Helvetica 12 Tf 0.305 0.627 rg");
         new PDDefaultAppearanceString(sampleString, resources);
     } 
 }



Mime
View raw message