]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Added support for CMYK colors in PTOCA
authorVincent Hennebert <vhennebert@apache.org>
Tue, 28 Apr 2009 15:40:04 +0000 (15:40 +0000)
committerVincent Hennebert <vhennebert@apache.org>
Tue, 28 Apr 2009 15:40:04 +0000 (15:40 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@769437 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/afp/ptoca/PtocaBuilder.java

index 3a6507252c200b9035b5905fdb925f293ef5cd11..40adb5ed851226e167bc2bb8da0f95b06c0554eb 100644 (file)
@@ -20,6 +20,7 @@
 package org.apache.fop.afp.ptoca;
 
 import java.awt.Color;
+import java.awt.color.ColorSpace;
 import java.io.IOException;
 import java.io.OutputStream;
 
@@ -314,19 +315,38 @@ public abstract class PtocaBuilder implements PtocaConstants {
             return;
         }
         newControlSequence();
-        writeByte(0x00); // Reserved; must be zero
-        writeByte(0x01); // Color space - 0x01 = RGB
-        writeByte(0x00); // Reserved; must be zero
-        writeByte(0x00); // Reserved; must be zero
-        writeByte(0x00); // Reserved; must be zero
-        writeByte(0x00); // Reserved; must be zero
-        writeByte(8); // Number of bits in component 1
-        writeByte(8); // Number of bits in component 2
-        writeByte(8); // Number of bits in component 3
-        writeByte(0); // Number of bits in component 4
-        writeByte(col.getRed()); // Red intensity
-        writeByte(col.getGreen()); // Green intensity
-        writeByte(col.getBlue()); // Blue intensity
+        if (col.getColorSpace().getType() == ColorSpace.TYPE_CMYK) {
+            writeByte(0x00); // Reserved; must be zero
+            writeByte(0x04); // Color space - 0x04 = CMYK
+            writeByte(0x00); // Reserved; must be zero
+            writeByte(0x00); // Reserved; must be zero
+            writeByte(0x00); // Reserved; must be zero
+            writeByte(0x00); // Reserved; must be zero
+            writeByte(8); // Number of bits in component 1
+            writeByte(8); // Number of bits in component 2
+            writeByte(8); // Number of bits in component 3
+            writeByte(8); // Number of bits in component 4
+            float[] comps = col.getColorComponents(null);
+            assert comps.length == 4;
+            for (int i = 0; i < 4; i++) {
+                int component = Math.round(comps[i] * 256);
+                writeByte(component);
+            }
+        } else {
+            writeByte(0x00); // Reserved; must be zero
+            writeByte(0x01); // Color space - 0x01 = RGB
+            writeByte(0x00); // Reserved; must be zero
+            writeByte(0x00); // Reserved; must be zero
+            writeByte(0x00); // Reserved; must be zero
+            writeByte(0x00); // Reserved; must be zero
+            writeByte(8); // Number of bits in component 1
+            writeByte(8); // Number of bits in component 2
+            writeByte(8); // Number of bits in component 3
+            writeByte(0); // Number of bits in component 4
+            writeByte(col.getRed()); // Red intensity
+            writeByte(col.getGreen()); // Green intensity
+            writeByte(col.getBlue()); // Blue intensity
+        }
         commit(chained(SEC));
         this.currentColor = col;
     }