/** * Creates a color instance representing a device-specific CMYK color. An sRGB value * is calculated from the CMYK colors but it may not correctly represent the given CMYK * values. * @param cmykComponents the CMYK components * @return the device-specific color */ public static Color createCMYKColor(float[] cmykComponents) { DeviceCMYKColorSpace cmykCs = ColorSpaces.getDeviceCMYKColorSpace(); Color cmykColor = new ColorWithAlternatives(cmykCs, cmykComponents, 1.0f, null); return cmykColor; }
private static Color[] getAlternativeColors(Color color) { if (color instanceof ColorWithAlternatives) { ColorWithAlternatives cwa = (ColorWithAlternatives)color; if (cwa.hasAlternativeColors()) { return cwa.getAlternativeColors(); } } return null; }
@Override public boolean equals(Object obj) { if (obj == this) { return true; } else if (!super.equals(obj)) { return false; } else if (obj instanceof ColorWithFallback) { ColorWithFallback other = (ColorWithFallback) obj; return other.fallback.equals(fallback); } else { return false; } }
private static String toCIELabFunctionCall(ColorWithAlternatives color) { Color fallbackColor = getsRGBFallback(color); StringBuffer sb = new StringBuffer("cie-lab-color("); sb.append(fallbackColor.getRed()).append(','); sb.append(fallbackColor.getGreen()).append(','); sb.append(fallbackColor.getBlue()); CIELabColorSpace cs = (CIELabColorSpace)color.getColorSpace(); float[] lab = cs.toNativeComponents(color.getColorComponents(null)); for (int i = 0; i < 3; i++) { sb.append(',').append(lab[i]); } sb.append(')'); return sb.toString(); }
ColorSpace cs = color.getColorSpace(); if (cs.isCS_sRGB() && !color.hasAlternativeColors()) { return toRGBFunctionCall(color); if (color.hasAlternativeColors()) { Color alt = color.getAlternativeColors()[0]; if (ColorSpaces.isDeviceColorSpace(alt.getColorSpace())) { cs = alt.getColorSpace();
&& !((ColorWithAlternatives) col1).hasAlternativeColors()) { cl1 = Color.class; && !((ColorWithAlternatives) col2).hasAlternativeColors()) { cl2 = Color.class; ColorWithAlternatives ca1 = (ColorWithAlternatives) col1; ColorWithAlternatives ca2 = (ColorWithAlternatives) col2; return ca1.hasSameAlternativeColors(ca2);
ColorWithAlternatives colExt = (ColorWithAlternatives)color; Color[] alt = colExt.getAlternativeColors(); for (Color col : alt) { established = establishColorFromColor(codeBuffer, col);
/** * Returns the first alternative color found with the given color space type. * @param colorSpaceType the color space type ({@link ColorSpace}.TYPE_*). * @return the requested alternative color or null, if no match was found */ public Color getFirstAlternativeOfType(int colorSpaceType) { if (hasAlternativeColors()) { for (Color alternativeColor : this.alternativeColors) { if (alternativeColor.getColorSpace().getType() == colorSpaceType) { return alternativeColor; } } } return null; }
Color alt = cwa.getFirstAlternativeOfType(ColorSpace.TYPE_CMYK); if (alt != null) { col = alt;
/** * Generates code to select the given color and handles the registration of color spaces in * PDF where necessary. * @param codeBuffer the target buffer to receive the color selection code * @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 (Color col : alt) { boolean established = establishColorFromColor(codeBuffer, col, fill); if (established) { return; } } if (log.isDebugEnabled() && alt.length > 0) { log.debug("None of the alternative colors are supported. Using fallback: " + color); } } //Fallback boolean established = establishColorFromColor(codeBuffer, color, fill); if (!established) { establishDeviceRGB(codeBuffer, color, fill); } }
if (color instanceof ColorWithAlternatives) { ColorWithAlternatives cwa = (ColorWithAlternatives)color; Color alt = cwa.getFirstAlternativeOfType(ColorSpace.TYPE_CMYK); if (alt != null) { this.color = alt;
/** * Creates a {@link Color} instance from color values usually used by the L*a*b* color space * by scaling them to the 0.0..1.0 range expected by Color's constructor. * @param colorvalue the original color values * (native value range, i.e. not normalized to 0.0..1.0) * @param alpha the alpha component * @return the requested color instance */ public Color toColor(float[] colorvalue, float alpha) { int c = colorvalue.length; float[] normalized = new float[c]; for (int i = 0; i < c; i++) { normalized[i] = normalize(colorvalue[i], i); } //Using ColorWithAlternatives for better equals() functionality return new ColorWithAlternatives(this, normalized, alpha, null); }
/** * 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; }
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) {
parsedColor = new ColorWithAlternatives( rgbComps[0], rgbComps[1], rgbComps[2], new Color[] {deviceColor});
colorMap.put("yellow", createColor(255, 255, 0)); colorMap.put("yellowgreen", createColor(154, 205, 50)); colorMap.put("transparent", new ColorWithAlternatives(0, 0, 0, 0, null));
comps[i] = c.getColor(i); Color cmyk = new ColorWithAlternatives(cmykCs, comps, opacity, null); Color specColor = new ColorWithAlternatives(r, g, b, Math.round(opacity * 255f), new Color[] {cmyk}); return specColor;
comps[i] = c.getColor(i); Color cmyk = new ColorWithAlternatives(cmykCs, comps, opacity, null); Color specColor = new ColorWithAlternatives(r, g, b, Math.round(opacity * 255f), new Color[] {cmyk}); return specColor;
comps[i] = c.getColor(i); Color cmyk = new ColorWithAlternatives(cmykCs, comps, opacity, null); Color specColor = new ColorWithAlternatives(r, g, b, Math.round(opacity * 255f), new Color[] {cmyk}); return specColor;
if (ncs != null) { Color specColor = new ColorWithAlternatives(ncs, new float[] {1.0f}, opacity, null); return specColor; } else {