You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by lb...@apache.org on 2015/02/10 11:22:58 UTC

svn commit: r1658659 - in /xmlgraphics/fop/trunk/src/java/org/apache/fop: afp/ptoca/PtocaBuilder.java fo/expr/OCAColorFunction.java fo/expr/PropertyParser.java util/ColorUtil.java util/OCAColor.java util/OCAColorSpace.java

Author: lbernardo
Date: Tue Feb 10 10:22:58 2015
New Revision: 1658659

URL: http://svn.apache.org/r1658659
Log:
FOP-2367: Support for color space OCA; patch submitted by Seifeddine Dridi

Added:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/OCAColorFunction.java   (with props)
    xmlgraphics/fop/trunk/src/java/org/apache/fop/util/OCAColor.java   (with props)
    xmlgraphics/fop/trunk/src/java/org/apache/fop/util/OCAColorSpace.java   (with props)
Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/ptoca/PtocaBuilder.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/PropertyParser.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/util/ColorUtil.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/ptoca/PtocaBuilder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/ptoca/PtocaBuilder.java?rev=1658659&r1=1658658&r2=1658659&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/ptoca/PtocaBuilder.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/ptoca/PtocaBuilder.java Tue Feb 10 10:22:58 2015
@@ -33,6 +33,8 @@ import org.apache.xmlgraphics.java2d.col
 import org.apache.fop.afp.fonts.CharactersetEncoder.EncodedChars;
 import org.apache.fop.afp.modca.AxisOrientation;
 import org.apache.fop.afp.ptoca.TransparentDataControlSequence.TransparentData;
+import org.apache.fop.util.OCAColor;
+import org.apache.fop.util.OCAColorSpace;
 
 /**
  * Generator class for PTOCA data structures.
@@ -300,6 +302,12 @@ public abstract class PtocaBuilder imple
             int a = Math.round(colorComponents[1] * 255f) - 128;
             int b = Math.round(colorComponents[2] * 255f) - 128;
             writeBytes(l, a, b); // l*, a* and b*
+        } else if (cs instanceof OCAColorSpace) {
+            // Color space - 0x40 = OCA, all else are reserved and must be zero
+            writeBytes(0x00, 0x40, 0x00, 0x00, 0x00, 0x00);
+            writeBytes(16, 0, 0, 0); // Number of bits in each component
+            int ocaColor = ((OCAColor) col).getOCA();
+            writeBytes((ocaColor & 0xFF00) >> 8, ocaColor & 0xFF);
         } else {
             // Color space - 0x01 = RGB, all else are reserved and must be zero
             writeBytes(0x00, 0x01, 0x00, 0x00, 0x00, 0x00);

Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/OCAColorFunction.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/OCAColorFunction.java?rev=1658659&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/OCAColorFunction.java (added)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/OCAColorFunction.java Tue Feb 10 10:22:58 2015
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.fo.expr;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.fo.properties.ColorProperty;
+import org.apache.fop.fo.properties.Property;
+
+public class OCAColorFunction extends FunctionBase {
+
+    /** {@inheritDoc} */
+    public int getRequiredArgsCount() {
+        return 1;
+    }
+
+    /** {@inheritDoc} */
+    public Property eval(Property[] args, PropertyInfo pInfo) throws PropertyException {
+        StringBuffer sb = new StringBuffer();
+        sb.append("oca(" + args[0] + ")");
+        FOUserAgent ua = (pInfo == null)
+                ? null
+                : (pInfo.getFO() == null ? null : pInfo.getFO().getUserAgent());
+        return ColorProperty.getInstance(ua, sb.toString());
+    }
+
+}

Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/OCAColorFunction.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/PropertyParser.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/PropertyParser.java?rev=1658659&r1=1658658&r2=1658659&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/PropertyParser.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/PropertyParser.java Tue Feb 10 10:22:58 2015
@@ -68,6 +68,7 @@ public final class PropertyParser extend
         FUNCTION_TABLE.put("rgb-named-color", new RGBNamedColorFunction()); //since XSL-FO 2.0
         FUNCTION_TABLE.put("cie-lab-color", new CIELabColorFunction()); //since XSL-FO 2.0
         FUNCTION_TABLE.put("cmyk", new CMYKColorFunction()); //non-standard!!!
+        FUNCTION_TABLE.put("oca", new OCAColorFunction()); //non-standard!!!
 
         /**
          * * NOT YET IMPLEMENTED!!!

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/util/ColorUtil.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/util/ColorUtil.java?rev=1658659&r1=1658658&r2=1658659&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/util/ColorUtil.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/util/ColorUtil.java Tue Feb 10 10:22:58 2015
@@ -42,6 +42,7 @@ import org.apache.xmlgraphics.java2d.col
 
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.fo.expr.PropertyException;
+import org.apache.fop.util.OCAColor.OCAColorValue;
 
 /**
  * Generic Color helper class.
@@ -137,6 +138,8 @@ public final class ColorUtil {
                 parsedColor = parseAsCIELabColor(foUserAgent, value);
             } else if (value.startsWith("cmyk")) {
                 parsedColor = parseAsCMYK(value);
+            } else if (value.startsWith("oca")) {
+                parsedColor = parseAsOCA(value);
             }
 
             if (parsedColor == null) {
@@ -624,6 +627,42 @@ public final class ColorUtil {
         return parsedColor;
     }
 
+    private static Color parseAsOCA(String value) throws PropertyException {
+        int poss = value.indexOf("(");
+        int pose = value.indexOf(")");
+        if (poss != -1 && pose != -1) {
+            value = value.substring(poss + 1, pose);
+            OCAColorValue colorValue;
+            if (value.equals("blue")) {
+                colorValue = OCAColorValue.BLUE;
+            } else if (value.equals("red")) {
+                colorValue = OCAColorValue.RED;
+            } else if (value.equals("magenta")) {
+                colorValue = OCAColorValue.MAGENTA;
+            } else if (value.equals("green")) {
+                colorValue = OCAColorValue.GREEN;
+            } else if (value.equals("cyan")) {
+                colorValue = OCAColorValue.CYAN;
+            } else if (value.equals("yellow")) {
+                colorValue = OCAColorValue.YELLOW;
+            } else if (value.equals("black")) {
+                colorValue = OCAColorValue.BLACK;
+            } else if (value.equals("brown")) {
+                colorValue = OCAColorValue.BROWN;
+            } else if (value.equals("medium-color")) {
+                colorValue = OCAColorValue.MEDIUM_COLOR;
+            } else if (value.equals("device-default")) {
+                colorValue = OCAColorValue.DEVICE_DEFAULT;
+            } else {
+                throw new PropertyException("Unknwon OCA color: " + value);
+            }
+            return new OCAColor(colorValue);
+        } else {
+            throw new PropertyException("Unknown color format: " + value
+                    + ". Must be oca(color-name)");
+        }
+    }
+
     /**
      * Creates a re-parsable string representation of the given color.
      * <p>

Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/util/OCAColor.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/util/OCAColor.java?rev=1658659&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/util/OCAColor.java (added)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/util/OCAColor.java Tue Feb 10 10:22:58 2015
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.util;
+
+import java.awt.Color;
+import java.awt.color.ColorSpace;
+
+/**
+ * OCAColor is a single component color representation that is mostly used
+ * in AFP documents to represent text foreground color.
+ * See also {@link OCAColorSpace}.
+ *
+ */
+public class OCAColor extends Color {
+
+    private static final long serialVersionUID = 1L;
+
+    public enum OCAColorValue {
+        BLUE(0x1),
+        RED(0x2),
+        MAGENTA(0x3),
+        GREEN(0x4),
+        CYAN(0x5),
+        YELLOW(0x6),
+        BLACK(0x8),
+        BROWN(0x10),
+        DEVICE_DEFAULT(0xFF07),
+        MEDIUM_COLOR(0xFF08);
+
+        final int value;
+
+        OCAColorValue(int value) {
+            this.value = value;
+        }
+
+    }
+
+    public OCAColor(OCAColorValue oca) {
+        super(oca.value);
+    }
+
+    public int getOCA() {
+        return this.getRGB() & 0xFFFF;
+    }
+
+    public ColorSpace getColorSpace() {
+        return new OCAColorSpace();
+    }
+
+    public float[] getColorComponents(ColorSpace cspace, float[] compArray) {
+        if (cspace.isCS_sRGB()) {
+            ColorSpace oca = new OCAColorSpace();
+            return oca.toRGB(new float[]{getOCA()});
+        }
+        return null;
+    }
+
+}

Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/util/OCAColor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/util/OCAColorSpace.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/util/OCAColorSpace.java?rev=1658659&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/util/OCAColorSpace.java (added)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/util/OCAColorSpace.java Tue Feb 10 10:22:58 2015
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.util;
+
+import java.awt.color.ColorSpace;
+
+import org.apache.fop.util.OCAColor.OCAColorValue;
+
+/**
+ * The OCA color space is a subset of RGB that includes a limited set of colors.
+ * The color value is specified with one unsigned binary component that
+ * specifies a named color using a two-byte value from the Standard
+ * OCA Color Value table.
+ *
+ */
+public class OCAColorSpace extends ColorSpace {
+
+    private static final long serialVersionUID = 1L;
+
+    protected OCAColorSpace() {
+        super(ColorSpace.TYPE_RGB, 1);
+    }
+
+    public float[] fromCIEXYZ(float[] colorvalue) {
+        throw new UnsupportedOperationException("Color conversion from CIE XYZ to OCA is not possible");
+    }
+
+    public float[] fromRGB(float[] rgbvalue) {
+        throw new UnsupportedOperationException("Color conversion from RGB to OCA is not possible");
+    }
+
+    public float[] toCIEXYZ(float[] colorvalue) {
+        float[] rgb = toRGB(colorvalue);
+        ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB);
+        return sRGB.toCIEXYZ(rgb);
+    }
+
+    public float[] toRGB(float[] colorvalue) {
+        int oca = (int) colorvalue[0];
+        if (oca == OCAColorValue.BLACK.value) {
+            return new float[]{0, 0, 0};
+        } else if (oca == OCAColorValue.BLUE.value) {
+            return new float[]{0, 0, 1.0f};
+        } else if (oca == OCAColorValue.BROWN.value) {
+            return new float[]{0.565f, 0.188f, 0};
+        } else if (oca == OCAColorValue.CYAN.value) {
+            return new float[]{0, 1.0f, 1.0f};
+        } else if (oca == OCAColorValue.GREEN.value) {
+            return new float[]{0, 1.0f, 0};
+        } else if (oca == OCAColorValue.MAGENTA.value) {
+            return new float[]{1.0f, 0, 1.0f};
+        } else if (oca == OCAColorValue.RED.value) {
+            return new float[]{1.0f, 0, 0};
+        } else if (oca == OCAColorValue.YELLOW.value) {
+            return new float[]{1.0f, 1.0f, 0};
+        }
+        return null;
+    }
+
+}

Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/util/OCAColorSpace.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org