Package org.apache.xmlgraphics.java2d.color

Examples of org.apache.xmlgraphics.java2d.color.ColorWithAlternatives


        //and the resulting RGB components are treated as DeviceRGB colors.
        //If all three RGB components are the same, DeviceGray is used.

        boolean established = false;
        if (color instanceof ColorWithAlternatives) {
            ColorWithAlternatives colExt = (ColorWithAlternatives)color;
            //Alternative colors have priority
            Color[] alt = colExt.getAlternativeColors();
            for (int i = 0, c = alt.length; i < c; i++) {
                Color col = alt[i];
                established = establishColorFromColor(codeBuffer, col);
                if (established) {
                    break;
View Full Code Here


        return comps[comps.length - 1]; //Alpha is on last component
    }

    private static Color[] getAlternativeColors(Color color) {
        if (color instanceof ColorWithAlternatives) {
            ColorWithAlternatives cwa = (ColorWithAlternatives)color;
            if (cwa.hasAlternativeColors()) {
                return cwa.getAlternativeColors();
            }
        }
        return null;
    }
View Full Code Here

     * Tests the cmyk() function.
     * @throws Exception if an error occurs
     */
    @Test
    public void testCMYK() throws Exception {
        ColorWithAlternatives colActual;
        String colSpec;

        colSpec = "cmyk(0.0, 0.0, 1.0, 0.0)";
        colActual = (ColorWithAlternatives)ColorUtil.parseColorString(null, colSpec);
        assertEquals(255, colActual.getRed());
        assertEquals(255, colActual.getGreen());
        assertEquals(0, colActual.getBlue());
        Color alt = colActual.getAlternativeColors()[0];
        assertEquals(ColorSpaces.getDeviceCMYKColorSpace(), alt.getColorSpace());
        float[] comps = alt.getColorComponents(null);
        assertEquals(4, comps.length);
        assertEquals(0f, comps[0], 0);
        assertEquals(0f, comps[1], 0);
        assertEquals(1f, comps[2], 0);
        assertEquals(0f, comps[3], 0);
        assertEquals("fop-rgb-icc(1.0,1.0,0.0,#CMYK,,0.0,0.0,1.0,0.0)",
                ColorUtil.colorToString(colActual));

        colSpec = "cmyk(0.0274, 0.2196, 0.3216, 0.0)";
        colActual = (ColorWithAlternatives)ColorUtil.parseColorString(null, colSpec);
        assertEquals(248, colActual.getRed(), 1);
        assertEquals(199, colActual.getGreen(), 1);
        assertEquals(172, colActual.getBlue(), 1);
        alt = colActual.getAlternativeColors()[0];
        assertEquals(ColorSpaces.getDeviceCMYKColorSpace(), alt.getColorSpace());
        comps = alt.getColorComponents(null);
        assertEquals(0.0274f, comps[0], 0.001);
        assertEquals(0.2196f, comps[1], 0.001);
        assertEquals(0.3216f, comps[2], 0.001);
        assertEquals(0f, comps[3], 0);
        assertEquals("fop-rgb-icc(0.9726,0.7804,0.67840004,#CMYK,,0.0274,0.2196,0.3216,0.0)",
                ColorUtil.colorToString(colActual));

        colSpec = "fop-rgb-icc(1.0,1.0,0.0,#CMYK,,0.0,0.0,1.0,0.0)";
        colActual = (ColorWithAlternatives)ColorUtil.parseColorString(null, colSpec);
        assertEquals(255, colActual.getRed());
        assertEquals(255, colActual.getGreen());
        assertEquals(0, colActual.getBlue());
        alt = colActual.getAlternativeColors()[0];
        assertEquals(ColorSpaces.getDeviceCMYKColorSpace(), alt.getColorSpace());
        comps = alt.getColorComponents(null);
        assertEquals(4, comps.length);
        assertEquals(0f, comps[0], 0);
        assertEquals(0f, comps[1], 0);
        assertEquals(1f, comps[2], 0);
        assertEquals(0f, comps[3], 0);
        assertEquals("fop-rgb-icc(1.0,1.0,0.0,#CMYK,,0.0,0.0,1.0,0.0)",
                ColorUtil.colorToString(colActual));

        colSpec = "fop-rgb-icc(0.5,0.5,0.5,#CMYK,,0.0,0.0,0.0,0.5)";
        colActual = (ColorWithAlternatives)ColorUtil.parseColorString(null, colSpec);
        assertEquals(127, colActual.getRed(), 1);
        assertEquals(127, colActual.getGreen(), 1);
        assertEquals(127, colActual.getBlue(), 1);
        alt = colActual.getAlternativeColors()[0];
        assertEquals(ColorSpaces.getDeviceCMYKColorSpace(), alt.getColorSpace());
        comps = alt.getColorComponents(null);
        assertEquals(4, comps.length);
        assertEquals(0f, comps[0], 0);
        assertEquals(0f, comps[1], 0);
        assertEquals(0f, comps[2], 0);
        assertEquals(0.5f, comps[3], 0);
        assertEquals("fop-rgb-icc(0.5,0.5,0.5,#CMYK,,0.0,0.0,0.0,0.5)",
                ColorUtil.colorToString(colActual));

        //Verify that the cmyk() and fop-rgb-icc(#CMYK) functions have the same results
        ColorWithAlternatives colCMYK = (ColorWithAlternatives)ColorUtil.parseColorString(
                null, "cmyk(0,0,0,0.5)");
        assertEquals(colCMYK.getAlternativeColors()[0], colActual.getAlternativeColors()[0]);
        //The following doesn't work:
        //assertEquals(colCMYK, colActual);
        //java.awt.Color does not consistenly calculate the int RGB values:
        //Color(ColorSpace cspace, float components[], float alpha): 0.5 --> 127
        //Color(float r, float g, float b): 0.5 --> 128
        if (!colCMYK.equals(colActual)) {
            System.out.println("Info: java.awt.Color does not consistently calculate"
                    + " int RGB values from float RGB values.");
        }
    }
View Full Code Here

                    if (ColorSpaces.isDeviceColorSpace(colorSpace)) {
                        //Device-specific colors are handled differently:
                        //sRGB is the primary color with the CMYK as the alternative
                        Color deviceColor = new Color(colorSpace, iccComponents, 1.0f);
                        float[] rgbComps = sRGB.getRGBColorComponents(null);
                        parsedColor = new ColorWithAlternatives(
                                rgbComps[0], rgbComps[1], rgbComps[2],
                                new Color[] {deviceColor});
                    } else {
                        parsedColor = new ColorWithFallback(
                                colorSpace, iccComponents, 1.0f, null, sRGB);
View Full Code Here

                float yellow = parseComponent1(args[2], value);
                float black = parseComponent1(args[3], value);
                float[] comps = new float[] {cyan, magenta, yellow, black};
                Color cmykColor = DeviceCMYKColorSpace.createCMYKColor(comps);
                float[] rgbComps = cmykColor.getRGBColorComponents(null);
                parsedColor = new ColorWithAlternatives(rgbComps[0], rgbComps[1], rgbComps[2],
                        new Color[] {cmykColor});
            } catch (RuntimeException re) {
                throw new PropertyException(re);
            }
        } else {
View Full Code Here

        colorMap.put("wheat", createColor(245, 222, 179));
        colorMap.put("white", createColor(255, 255, 255));
        colorMap.put("whitesmoke", createColor(245, 245, 245));
        colorMap.put("yellow", createColor(255, 255, 0));
        colorMap.put("yellowgreen", createColor(154, 205, 50));
        colorMap.put("transparent", new ColorWithAlternatives(0, 0, 0, 0, null));
    }
View Full Code Here

        float[] cmyk = new float[] {1.0f, 1.0f, 0.5f, 1.0f};
        col = DeviceCMYKColorSpace.createCMYKColor(cmyk);
        //Convert to sRGB with CMYK alternative as constructed by the cmyk() function
        float[] rgb = col.getRGBColorComponents(null);
        col = new ColorWithAlternatives(rgb[0], rgb[1], rgb[2], new Color[] {col});
        b1 = new BorderProps(Constants.EN_INSET, 9999,
                col, BorderProps.SEPARATE);
        ser = b1.toString();
        b2 = BorderProps.valueOf(null, ser);
        assertEquals(b1, b2);
View Full Code Here

    public void setExtendedTextColor(Color col) throws IOException {
        if (ColorUtil.isSameColor(col, currentColor)) {
            return;
        }
        if (col instanceof ColorWithAlternatives) {
            ColorWithAlternatives cwa = (ColorWithAlternatives)col;
            Color alt = cwa.getFirstAlternativeOfType(ColorSpace.TYPE_CMYK);
            if (alt != null) {
                col = alt;
            }
        }
        ColorSpace cs = col.getColorSpace();
View Full Code Here

     *
     * @param color the color to set
     */
    public GraphicsSetProcessColor(Color color) {
        if (color instanceof ColorWithAlternatives) {
            ColorWithAlternatives cwa = (ColorWithAlternatives)color;
            Color alt = cwa.getFirstAlternativeOfType(ColorSpace.TYPE_CMYK);
            if (alt != null) {
                this.color = alt;
                this.componentsSize = 4;
                return;
            }
View Full Code Here

     * @param color the color
     * @param fill true for fill color, false for stroke color
     */
    public void establishColor(StringBuffer codeBuffer, Color color, boolean fill) {
        if (color instanceof ColorWithAlternatives) {
            ColorWithAlternatives colExt = (ColorWithAlternatives)color;
            //Alternate colors have priority
            Color[] alt = colExt.getAlternativeColors();
            for (int i = 0, c = alt.length; i < c; i++) {
                Color col = alt[i];
                boolean established = establishColorFromColor(codeBuffer, col, fill);
                if (established) {
                    return;
View Full Code Here

TOP

Related Classes of org.apache.xmlgraphics.java2d.color.ColorWithAlternatives

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.