public static void checkCompatibleColors(BaseColor c1, BaseColor c2) { int type1 = ExtendedColor.getType(c1); int type2 = ExtendedColor.getType(c2); if (type1 != type2) throw new IllegalArgumentException( MessageLocalization.getComposedMessage("both.colors.must.be.of.the.same.type")); if (type1 == ExtendedColor.TYPE_SEPARATION && ((SpotColor) c1).getPdfSpotColor() != ((SpotColor) c2).getPdfSpotColor()) throw new IllegalArgumentException( MessageLocalization.getComposedMessage( "the.spot.color.must.be.the.same.only.the.tint.can.vary")); if (type1 == ExtendedColor.TYPE_PATTERN || type1 == ExtendedColor.TYPE_SHADING) throwColorSpaceError(); }
public static float[] getColorArray(BaseColor color) { int type = ExtendedColor.getType(color); switch (type) { case ExtendedColor.TYPE_GRAY: { return new float[] {((GrayColor) color).getGray()}; } case ExtendedColor.TYPE_CMYK: { CMYKColor cmyk = (CMYKColor) color; return new float[] {cmyk.getCyan(), cmyk.getMagenta(), cmyk.getYellow(), cmyk.getBlack()}; } case ExtendedColor.TYPE_SEPARATION: { return new float[] {((SpotColor) color).getTint()}; } case ExtendedColor.TYPE_DEVICEN: { return ((DeviceNColor) color).getTints(); } case ExtendedColor.TYPE_RGB: { return new float[] { color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f }; } } throwColorSpaceError(); return null; }
protected void setColorSpace(BaseColor color) { cspace = color; int type = ExtendedColor.getType(color); PdfObject colorSpace = null; switch (type) { case ExtendedColor.TYPE_GRAY: { colorSpace = PdfName.DEVICEGRAY; break; } case ExtendedColor.TYPE_CMYK: { colorSpace = PdfName.DEVICECMYK; break; } case ExtendedColor.TYPE_SEPARATION: { SpotColor spot = (SpotColor) color; colorDetails = writer.addSimple(spot.getPdfSpotColor()); colorSpace = colorDetails.getIndirectReference(); break; } case ExtendedColor.TYPE_DEVICEN: { DeviceNColor deviceNColor = (DeviceNColor) color; colorDetails = writer.addSimple(deviceNColor.getPdfDeviceNColor()); colorSpace = colorDetails.getIndirectReference(); break; } case ExtendedColor.TYPE_PATTERN: case ExtendedColor.TYPE_SHADING: { throwColorSpaceError(); } default: colorSpace = PdfName.DEVICERGB; break; } shading.put(PdfName.COLORSPACE, colorSpace); }