public static 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 Exception("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 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); }
public static void CheckCompatibleColors(Color c1, Color c2) { int type1 = ExtendedColor.GetType(c1); int type2 = ExtendedColor.GetType(c2); if (type1 != type2) { throw new ArgumentException("Both colors must be of the same type."); } if (type1 == ExtendedColor.TYPE_SEPARATION && ((SpotColor)c1).PdfSpotColor != ((SpotColor)c2).PdfSpotColor) { throw new ArgumentException("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) { 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.PdfSpotColor); colorSpace = colorDetails.IndirectReference; break; } case ExtendedColor.TYPE_PATTERN: case ExtendedColor.TYPE_SHADING: { ThrowColorSpaceError(); break; } default: colorSpace = PdfName.DEVICERGB; break; } shading.Put(PdfName.COLORSPACE, colorSpace); }