public static float[] getColorArray(Color color) { int type = ExtendedColor.getType(color); switch (type) { case ExtendedColor.TYPE_GRAY: { return(new float[] { ((GrayColor)color).Gray }); } case ExtendedColor.TYPE_CMYK: { CMYKColor cmyk = (CMYKColor)color; return(new float[] { cmyk.Cyan, cmyk.Magenta, cmyk.Yellow, cmyk.Black }); } case ExtendedColor.TYPE_SEPARATION: { return(new float[] { ((SpotColor)color).Tint }); } case ExtendedColor.TYPE_RGB: { return(new float[] { color.R / 255f, color.G / 255f, color.B / 255f }); } } throwColorSpaceError(); return(null); }
internal PdfArray getMKColor(Color color) { PdfArray array = new PdfArray(); int type = ExtendedColor.getType(color); switch (type) { case ExtendedColor.TYPE_GRAY: { array.Add(new PdfNumber(((GrayColor)color).Gray)); break; } case ExtendedColor.TYPE_CMYK: { CMYKColor cmyk = (CMYKColor)color; array.Add(new PdfNumber(cmyk.Cyan)); array.Add(new PdfNumber(cmyk.Magenta)); array.Add(new PdfNumber(cmyk.Yellow)); array.Add(new PdfNumber(cmyk.Black)); break; } case ExtendedColor.TYPE_SEPARATION: case ExtendedColor.TYPE_PATTERN: case ExtendedColor.TYPE_SHADING: throw new RuntimeException("Separations, patterns and shadings are not allowed in MK dictionary."); default: array.Add(new PdfNumber(color.R / 255f)); array.Add(new PdfNumber(color.G / 255f)); array.Add(new PdfNumber(color.B / 255f)); break; } return(array); }
public static void checkCompatibleColors(Color c1, Color c2) { int type1 = ExtendedColor.getType(c1); int type2 = ExtendedColor.getType(c2); if (type1 != type2) { throw new IllegalArgumentException("Both colors must be of the same type."); } if (type1 == ExtendedColor.TYPE_SEPARATION && ((SpotColor)c1).getPdfSpotColor() != ((SpotColor)c2).getPdfSpotColor()) { throw new IllegalArgumentException("The spot color must be the same, only the tint can vary."); } if (type1 == ExtendedColor.TYPE_PATTERN || type1 == ExtendedColor.TYPE_SHADING) { throwColorSpaceError(); } }
protected void setColorSpace(Color 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.IndirectReference; break; } case ExtendedColor.TYPE_PATTERN: case ExtendedColor.TYPE_SHADING: { throwColorSpaceError(); break; } default: colorSpace = PdfName.DEVICERGB; break; } shading.put(PdfName.COLORSPACE, colorSpace); }