public virtual void ColorTest08() { PdfWriter writer = new PdfWriter(destinationFolder + "colorTest08.pdf"); writer.SetCompressionLevel(CompressionConstants.NO_COMPRESSION); PdfDocument document = new PdfDocument(writer); PdfPage page = document.AddNewPage(); PdfFunction.Type4 function = new PdfFunction.Type4(new PdfArray(new float[] { 0, 1, 0, 1 }), new PdfArray( new float[] { 0, 1, 0, 1, 0, 1 }), "{0}".GetBytes(iText.IO.Util.EncodingUtil.ISO_8859_1)); List <String> tmpArray = new List <String>(2); tmpArray.Add("MyRed"); tmpArray.Add("MyGreen"); PdfSpecialCs.DeviceN deviceN = new PdfSpecialCs.DeviceN(tmpArray, new PdfDeviceCs.Rgb(), function); PdfCanvas canvas = new PdfCanvas(page); canvas.SetFillColor(new DeviceN(deviceN, new float[] { 0, 0 })).Rectangle(50, 500, 50, 50).Fill(); canvas.SetFillColor(new DeviceN(deviceN, new float[] { 0, 1 })).Rectangle(150, 500, 50, 50).Fill(); canvas.SetFillColor(new DeviceN(deviceN, new float[] { 1, 0 })).Rectangle(250, 500, 50, 50).Fill(); canvas.Release(); document.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "colorTest08.pdf", sourceFolder + "cmp_colorTest08.pdf", destinationFolder, "diff_")); }
public override void CheckColorSpace(PdfColorSpace colorSpace, PdfDictionary currentColorSpaces, bool checkAlternate , bool?fill) { if (colorSpace is PdfSpecialCs.Separation) { colorSpace = ((PdfSpecialCs.Separation)colorSpace).GetBaseCs(); } else { if (colorSpace is PdfSpecialCs.DeviceN) { PdfSpecialCs.DeviceN deviceNColorspace = (PdfSpecialCs.DeviceN)colorSpace; if (deviceNColorspace.GetNumberOfComponents() > MAX_NUMBER_OF_DEVICEN_COLOR_COMPONENTS) { throw new PdfAConformanceException(PdfAConformanceException.THE_NUMBER_OF_COLOR_COMPONENTS_IN_DEVICE_N_COLORSPACE_SHOULD_NOT_EXCEED , MAX_NUMBER_OF_DEVICEN_COLOR_COMPONENTS); } colorSpace = deviceNColorspace.GetBaseCs(); } } if (colorSpace is PdfDeviceCs.Rgb) { if (cmykIsUsed) { throw new PdfAConformanceException(PdfAConformanceException.DEVICERGB_AND_DEVICECMYK_COLORSPACES_CANNOT_BE_USED_BOTH_IN_ONE_FILE ); } rgbIsUsed = true; } else { if (colorSpace is PdfDeviceCs.Cmyk) { if (rgbIsUsed) { throw new PdfAConformanceException(PdfAConformanceException.DEVICERGB_AND_DEVICECMYK_COLORSPACES_CANNOT_BE_USED_BOTH_IN_ONE_FILE ); } cmykIsUsed = true; } else { if (colorSpace is PdfDeviceCs.Gray) { grayIsUsed = true; } } } }
/// <summary>Makes a Color of certain color space and color value.</summary> /// <remarks> /// Makes a Color of certain color space and color value. /// If color value is set in null, all value components will be initialised with zeroes. /// </remarks> /// <param name="colorSpace">the color space to which the returned Color object relates</param> /// <param name="colorValue">the color value of the returned Color object</param> /// <returns>the created Color object.</returns> public static iText.Kernel.Colors.Color MakeColor(PdfColorSpace colorSpace, float[] colorValue) { iText.Kernel.Colors.Color c = null; bool unknownColorSpace = false; if (colorSpace is PdfDeviceCs) { if (colorSpace is PdfDeviceCs.Gray) { c = colorValue != null ? new DeviceGray(colorValue[0]) : new DeviceGray(); } else { if (colorSpace is PdfDeviceCs.Rgb) { c = colorValue != null ? new DeviceRgb(colorValue[0], colorValue[1], colorValue[2]) : new DeviceRgb(); } else { if (colorSpace is PdfDeviceCs.Cmyk) { c = colorValue != null ? new DeviceCmyk(colorValue[0], colorValue[1], colorValue[2], colorValue[3]) : new DeviceCmyk(); } else { unknownColorSpace = true; } } } } else { if (colorSpace is PdfCieBasedCs) { if (colorSpace is PdfCieBasedCs.CalGray) { PdfCieBasedCs.CalGray calGray = (PdfCieBasedCs.CalGray)colorSpace; c = colorValue != null ? new CalGray(calGray, colorValue[0]) : new CalGray(calGray); } else { if (colorSpace is PdfCieBasedCs.CalRgb) { PdfCieBasedCs.CalRgb calRgb = (PdfCieBasedCs.CalRgb)colorSpace; c = colorValue != null ? new CalRgb(calRgb, colorValue) : new CalRgb(calRgb); } else { if (colorSpace is PdfCieBasedCs.IccBased) { PdfCieBasedCs.IccBased iccBased = (PdfCieBasedCs.IccBased)colorSpace; c = colorValue != null ? new IccBased(iccBased, colorValue) : new IccBased(iccBased); } else { if (colorSpace is PdfCieBasedCs.Lab) { PdfCieBasedCs.Lab lab = (PdfCieBasedCs.Lab)colorSpace; c = colorValue != null ? new Lab(lab, colorValue) : new Lab(lab); } else { unknownColorSpace = true; } } } } } else { if (colorSpace is PdfSpecialCs) { if (colorSpace is PdfSpecialCs.Separation) { PdfSpecialCs.Separation separation = (PdfSpecialCs.Separation)colorSpace; c = colorValue != null ? new Separation(separation, colorValue[0]) : new Separation(separation); } else { if (colorSpace is PdfSpecialCs.DeviceN) { //NChannel goes here also PdfSpecialCs.DeviceN deviceN = (PdfSpecialCs.DeviceN)colorSpace; c = colorValue != null ? new DeviceN(deviceN, colorValue) : new DeviceN(deviceN); } else { if (colorSpace is PdfSpecialCs.Indexed) { c = colorValue != null ? new Indexed(colorSpace, (int)colorValue[0]) : new Indexed(colorSpace); } else { unknownColorSpace = true; } } } } else { if (colorSpace is PdfSpecialCs.Pattern) { c = new iText.Kernel.Colors.Color(colorSpace, colorValue); } else { // TODO review this. at least log a warning unknownColorSpace = true; } } } } if (unknownColorSpace) { throw new PdfException("Unknown color space."); } return(c); }
public DeviceN(PdfSpecialCs.DeviceN cs, float[] value) : base(cs, value) { }
public DeviceN(PdfSpecialCs.DeviceN cs) : this(cs, GetDefaultColorants(cs.GetNumberOfComponents())) { }