private static Color[] getAlternativeColors(Color color) { if (color instanceof ColorWithAlternatives) { ColorWithAlternatives cwa = (ColorWithAlternatives)color; if (cwa.hasAlternativeColors()) { return cwa.getAlternativeColors(); } } return null; }
ColorWithAlternatives colExt = (ColorWithAlternatives)color; Color[] alt = colExt.getAlternativeColors(); for (Color col : alt) { established = establishColorFromColor(codeBuffer, col);
/** * 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; }
/** * 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); } }
Color alt = color.getAlternativeColors()[0]; if (ColorSpaces.isDeviceColorSpace(alt.getColorSpace())) { cs = alt.getColorSpace();