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 PdfObject getSpotObject(PdfWriter writer) throws IOException { PdfArray array = new PdfArray(PdfName.SEPARATION); array.add(name); PdfFunction func = null; if (altcs instanceof ExtendedColor) { int type = ((ExtendedColor) altcs).type; // ssteward // having trouble with unreachable bytecode in switch default (per gcj 4.4) // so try a clumsier workaround boolean handled_b = false; switch (type) { case ExtendedColor.TYPE_GRAY: array.add(PdfName.DEVICEGRAY); func = PdfFunction.type2( writer, new float[] {0, 1}, null, new float[] {0}, new float[] {((GrayColor) altcs).getGray()}, 1); handled_b = true; break; case ExtendedColor.TYPE_CMYK: array.add(PdfName.DEVICECMYK); CMYKColor cmyk = (CMYKColor) altcs; func = PdfFunction.type2( writer, new float[] {0, 1}, null, new float[] {0, 0, 0, 0}, new float[] { cmyk.getCyan(), cmyk.getMagenta(), cmyk.getYellow(), cmyk.getBlack() }, 1); handled_b = true; break; // default: // throw new RuntimeException("Only RGB, Gray and CMYK are supported as // alternative color spaces."); } if (!handled_b) { throw new RuntimeException( "Only RGB, Gray and CMYK are supported as alternative color spaces."); } } else { array.add(PdfName.DEVICERGB); func = PdfFunction.type2( writer, new float[] {0, 1}, null, new float[] {1, 1, 1}, new float[] { (float) altcs.getRed() / 255, (float) altcs.getGreen() / 255, (float) altcs.getBlue() / 255 }, 1); } array.add(func.getReference()); return array; }