/** * Indicates whether the color is a gray value. * @param col the color * @return true if it is a gray value */ public static boolean isGray(Color col) { return org.apache.xmlgraphics.java2d.color.ColorUtil.isGray(col); }
/** * Sets the text color. * @param color the new text color */ public void setTextColor(Color color) { if (!ColorUtil.isSameColor(color, this.textColor)) { this.fontChanged = true; } this.textColor = color; }
/** * Creates an uncalibrated CMYK color with the given gray value. * @param black the gray component (0 - 1) * @return the CMYK color */ public static Color toCMYKGrayColor(float black) { return org.apache.xmlgraphics.java2d.color.ColorUtil.toCMYKGrayColor(black); } }
private static Color getsRGBColor(Color c) { // Color space must be consistent, so convert to sRGB if necessary // TODO really? return c.getColorSpace().isCS_sRGB() ? c : ColorUtil.toSRGBColor(c); }
/** * Lightens up a color for groove, ridge, inset and outset border effects. * @param col the color to lighten up * @param factor factor by which to lighten up (negative values darken the color) * @return the modified color */ public static Color lightenColor(Color col, float factor) { return org.apache.xmlgraphics.java2d.color.ColorUtil.lightenColor(col, factor); }
this.color = ColorUtil.toSRGBColor(color); } else { this.color = color;
/** {@inheritDoc} */ @Override public boolean equals(Object o) { if (this == o) { return true; } if (o instanceof ColorProperty) { return org.apache.xmlgraphics.java2d.color.ColorUtil.isSameColor( ((ColorProperty) o).color, this.color); } return false; }
private void establishFallbackRGB(StringBuffer codeBuffer, Color color) { float[] comps; if (color.getColorSpace().isCS_sRGB()) { comps = color.getColorComponents(null); } else { if (log.isDebugEnabled()) { log.debug("Converting color to sRGB as a fallback: " + color); } ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB); comps = color.getColorComponents(sRGB, null); } assert comps.length == 3; boolean gray = ColorUtil.isGray(color); if (gray) { comps = new float[] {comps[0]}; } writeSetColor(codeBuffer, comps, gray ? "setgray" : "setrgbcolor"); }
/** * The color is converted to CMYK with just the K component. * {@inheritDoc} */ public Color convert(Color color) { float kValue = (RED_WEIGHT * color.getRed() + GREEN_WEIGTH * color.getGreen() + BLUE_WEIGHT * color.getBlue()) / 255.0f / 255.0f; return ColorUtil.toCMYKGrayColor(kValue); } }
/** * Establishes the specified color (RGB). * @param value color as defined by the setrgbcolor command * @return true if the color changed compared to the previous setting */ public boolean useColor(Color value) { if (!ColorUtil.isSameColor(color, value)) { color = value; return true; } else { return false; } }
private void establishDeviceRGB(StringBuffer codeBuffer, Color color, boolean fill) { float[] comps; if (color.getColorSpace().isCS_sRGB()) { comps = color.getColorComponents(null); } else { if (log.isDebugEnabled()) { log.debug("Converting color to sRGB as a fallback: " + color); } ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB); comps = color.getColorComponents(sRGB, null); } if (ColorUtil.isGray(color)) { comps = new float[] {comps[0]}; //assuming that all components are the same writeColor(codeBuffer, comps, 1, (fill ? "g" : "G")); } else { writeColor(codeBuffer, comps, 3, (fill ? "rg" : "RG")); } }
/** {@inheritDoc} */ @Override public boolean equals(Object obj) { if (obj == null) { return false; } else if (obj == this) { return true; } else { if (obj instanceof BorderProps) { BorderProps other = (BorderProps) obj; return (style == other.style) && org.apache.xmlgraphics.java2d.color.ColorUtil.isSameColor( color, other.color) && width == other.width && mode == other.mode && radiusStart == other.radiusStart && radiusEnd == other.radiusEnd; } } return false; }
/** * Set the current paint. * This checks if the paint will change and then sets the current paint. * * @param p the new paint * @return true if the new paint changes the current paint */ public boolean setPaint(Paint p) { PDFData data = getPDFData(); Paint currentPaint = data.paint; if (currentPaint == null) { if (p != null) { data.paint = p; return true; } } else if (p instanceof Color && currentPaint instanceof Color) { if (!ColorUtil.isSameColor((Color)p, (Color)currentPaint)) { data.paint = p; return true; } } else if (!currentPaint.equals(p)) { data.paint = p; return true; } return false; }
/** * Set the current background color. Check if the background color will * change and then set the new color. * * @param col the new color as a java.awt.Color * @return true if the background color has changed */ public boolean updateColor(Color col) { if (!ColorUtil.isSameColor(col, getGraph().getColor())) { getGraph().setColor(col); return true; } else { return false; } }
/** * Set the current background color. * Check if the new background color is a change and then set the current background color. * * @param col the background color to set * @return true if the color has changed */ public boolean setBackColor(Color col) { Color other = getData().backColor; if (!org.apache.xmlgraphics.java2d.color.ColorUtil.isSameColor(col, other)) { getData().backColor = col; return true; } return false; }
/** * Set the current color. * Check if the new color is a change and then set the current color. * * @param col the color to set * @return true if the color has changed */ public boolean setColor(Color col) { Color other = getData().color; if (!org.apache.xmlgraphics.java2d.color.ColorUtil.isSameColor(col, other)) { getData().color = col; return true; } return false; }
/** * Sets the current color * * @param color the active color to use */ public void setColor(Color color) { if (!ColorUtil.isSameColor(color, graphicsState.color)) { addObject(new GraphicsSetProcessColor(colorConverter.convert(color))); graphicsState.color = color; } }
/** * Set the current paint. This checks if the paint will change and then sets * the current paint. * * @param p the new paint * @return true if the new paint changes the current paint */ public boolean updatePaint(Paint p) { Paint currentPaint = getGraph().getPaint(); if (currentPaint == null) { if (p != null) { getGraph().setPaint(p); return true; } } else if (p instanceof Color && currentPaint instanceof Color) { if (!ColorUtil.isSameColor((Color)p, (Color)currentPaint)) { getGraph().setPaint(p); return true; } } else if (!p.equals(currentPaint)) { getGraph().setPaint(p); return true; } return false; }
/** * Indicates whether another instance has the same alternative colors. * @param col the color to compare the alternatives to * @return true if the same alternative colors are present */ public boolean hasSameAlternativeColors(ColorWithAlternatives col) { if (!hasAlternativeColors()) { return !col.hasAlternativeColors(); } // this.hasAlternativeColors() if (!col.hasAlternativeColors()) { return false; } // this.hasAlternativeColors() && col.hasAlternativeColors() Color[] alt1 = getAlternativeColors(); Color[] alt2 = col.getAlternativeColors(); if (alt1.length != alt2.length) { return false; } for (int i = 0, c = alt1.length; i < c; i++) { Color c1 = alt1[i]; Color c2 = alt2[i]; if (!ColorUtil.isSameColor(c1, c2)) { return false; } } return true; }
if (ColorUtil.isSameColor(col, currentColor)) { return;