Parcourir la source

FOP-2367: Support for color space OCA; patch submitted by Seifeddine Dridi

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1658659 13f79535-47bb-0310-9956-ffa450edef68
pull/2/head
Luis Bernardo il y a 9 ans
Parent
révision
1aa992c0e6

+ 8
- 0
src/java/org/apache/fop/afp/ptoca/PtocaBuilder.java Voir le fichier

@@ -33,6 +33,8 @@ import org.apache.xmlgraphics.java2d.color.ColorWithAlternatives;
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 implements PtocaConstants {
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);

+ 43
- 0
src/java/org/apache/fop/fo/expr/OCAColorFunction.java Voir le fichier

@@ -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());
}

}

+ 1
- 0
src/java/org/apache/fop/fo/expr/PropertyParser.java Voir le fichier

@@ -68,6 +68,7 @@ public final class PropertyParser extends PropertyTokenizer {
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!!!

+ 39
- 0
src/java/org/apache/fop/util/ColorUtil.java Voir le fichier

@@ -42,6 +42,7 @@ import org.apache.xmlgraphics.java2d.color.profile.NamedColorProfileParser;

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>

+ 75
- 0
src/java/org/apache/fop/util/OCAColor.java Voir le fichier

@@ -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;
}

}

+ 77
- 0
src/java/org/apache/fop/util/OCAColorSpace.java Voir le fichier

@@ -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;
}

}

Chargement…
Annuler
Enregistrer