Ejemplo n.º 1
0
 public DeviceNColor(PdfDeviceNColor pdfDeviceNColor, float[] tints) : base(TYPE_DEVICEN) {
     if (pdfDeviceNColor.SpotColors.Length != tints.Length)
         throw new Exception(MessageLocalization.GetComposedMessage(
                 "devicen.color.shall.have.the.same.number.of.colorants.as.the.destination.DeviceN.color.space"));
     this.pdfDeviceNColor = pdfDeviceNColor;
     this.tints = tints;
 }
Ejemplo n.º 2
0
        public virtual void LabSpotBasedGradient() {
            // step 1
            Document document = new Document(PageSize.A3);
            // step 2
            String dest_file = DEST_FOLDER + "/lab_spot_based_gradient.pdf";
            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(dest_file, FileMode.Create));
            // step 3
            document.Open();
            // step 4
            PdfContentByte canvas = writer.DirectContent;
            PdfLabColor pdfLabColor = new PdfLabColor(new float[] {0.9505f, 1.0f, 1.0890f}, new float[] {0f, 0.5f, 1.5f},
                new float[] {-10, 100, -10, 100});
            PdfDeviceNColor pdfDeviceNNChannelColor =
                new PdfDeviceNColor(new PdfSpotColor[] {
                    new PdfSpotColor("lab3", pdfLabColor.Rgb2lab(new BaseColor(0, 217, 83))),
                    new PdfSpotColor("labBlue", pdfLabColor.Rgb2lab(new BaseColor(0, 0, 255)))
                });
            PdfSpotColor psc_lab3 = new PdfSpotColor("lab3", pdfLabColor.Rgb2lab(new BaseColor(0, 217, 83)));
            PdfSpotColor psc_lab2 = new PdfSpotColor("lab2", pdfLabColor.Rgb2lab(new BaseColor(70, 138, 96)));
            PdfSpotColor psc_lab1 = new PdfSpotColor("lab1", pdfLabColor.Rgb2lab(new BaseColor(255, 0, 0)));
            PdfSpotColor psc_lab_blue = new PdfSpotColor("labBlue", new BaseColor(0, 0, 100));

            PdfDeviceNColor pdfDeviceNNChannelColor2 = new PdfDeviceNColor(new PdfSpotColor[]{psc_lab_blue, psc_lab2, psc_lab1});

            ColorRectangle(canvas, pdfLabColor.Rgb2lab(new BaseColor(0, 0, 255)), 36, 878, 36, 36);
            ColorRectangle(canvas, pdfLabColor.Rgb2lab(new BaseColor(70, 138, 96)), 90, 878, 36, 36);
            ColorRectangle(canvas, pdfLabColor.Rgb2lab(new BaseColor(0, 217, 83)), 144, 878, 36, 36);
            ColorRectangle(canvas, pdfLabColor.Rgb2lab(new BaseColor(0, 50, 50)), 198, 878, 36, 36);

            ColorRectangle(canvas, pdfLabColor.Rgb2lab(new BaseColor(0, 0, 255)).ToRgb(), 36, 824, 36, 36);
            ColorRectangle(canvas, pdfLabColor.Rgb2lab(new BaseColor(70, 138, 96)).ToRgb(), 90, 824, 36, 36);
            ColorRectangle(canvas, pdfLabColor.Rgb2lab(new BaseColor(0, 217, 83)).ToRgb(), 144, 824, 36, 36);
            ColorRectangle(canvas, pdfLabColor.Rgb2lab(new BaseColor(0, 50, 50)).ToRgb(), 198, 824, 36, 36);


            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("lab1", pdfLabColor.Rgb2lab(new BaseColor(255, 0, 0))), 1f), 36, 986, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("lab1", pdfLabColor.Rgb2lab(new BaseColor(255, 0, 0))), 0.8f), 90, 986, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("lab1", pdfLabColor.Rgb2lab(new BaseColor(255, 0, 0))), 0.6f), 144, 986, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("lab1", pdfLabColor.Rgb2lab(new BaseColor(255, 0, 0))), 0.2f), 198, 986, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("lab2", pdfLabColor.Rgb2lab(new BaseColor(70, 138, 96))), 1f), 252, 986, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("lab2", pdfLabColor.Rgb2lab(new BaseColor(70, 138, 96))), 0.8f), 306, 986, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("lab2", pdfLabColor.Rgb2lab(new BaseColor(70, 138, 96))), 0.6f), 360, 986, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("lab2", pdfLabColor.Rgb2lab(new BaseColor(70, 138, 96))), 0.2f), 416, 986, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("lab3", pdfLabColor.Rgb2lab(new BaseColor(0, 217, 83))), 1.0f), 470, 986, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("lab3", pdfLabColor.Rgb2lab(new BaseColor(0, 217, 83))), 0.8f), 524, 986, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("lab3", pdfLabColor.Rgb2lab(new BaseColor(0, 217, 83))), 0.6f), 578, 986, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("lab3", pdfLabColor.Rgb2lab(new BaseColor(0, 217, 83))), 0.2f), 634, 986, 36, 36);

            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("rgb1", new BaseColor(255, 0, 0)), 1f), 36, 932, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("rgb1", new BaseColor(255, 0, 0)), 0.8f), 90, 932, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("rgb1", new BaseColor(255, 0, 0)), 0.6f), 144, 932, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("rgb1", new BaseColor(255, 0, 0)), 0.2f), 198, 932, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("rgb2", new BaseColor(70, 138, 96)), 1f), 252, 932, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("rgb2", new BaseColor(70, 138, 96)), 0.8f), 306, 932, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("rgb2", new BaseColor(70, 138, 96)), 0.6f), 360, 932, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("rgb2", new BaseColor(70, 138, 96)), 0.2f), 416, 932, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("rgb3", new BaseColor(0, 217, 83)), 1.0f), 470, 932, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("rgb3", new BaseColor(0, 217, 83)), 0.8f), 524, 932, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("rgb3", new BaseColor(0, 217, 83)), 0.6f), 578, 932, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("rgb3", new BaseColor(0, 217, 83)), 0.2f), 634, 932, 36, 36);

            ColorRectangle(canvas, new DeviceNColor(new PdfDeviceNColor(new PdfSpotColor[]{psc_lab2, psc_lab_blue, psc_lab1}), new float[]{0, 0.0f, 1}), 36, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(pdfDeviceNNChannelColor, new float[]{0.1f, 0.1f}), 90, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(pdfDeviceNNChannelColor, new float[]{0.2f, 0.2f}), 144, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(pdfDeviceNNChannelColor, new float[]{0.3f, 0.3f}), 198, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(pdfDeviceNNChannelColor, new float[]{0.4f, 0.4f}), 252, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(new PdfDeviceNColor(new PdfSpotColor[]{psc_lab2, psc_lab_blue, psc_lab1, psc_lab3}), new float[]{0.5f, 0.5f, 1, 0.5f}), 306, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(pdfDeviceNNChannelColor2, new float[]{0.6f, 0.1f, 0.5f}), 360, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(pdfDeviceNNChannelColor, new float[]{0.7f, 0.7f}), 416, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(pdfDeviceNNChannelColor, new float[]{0.8f, 0.8f}), 470, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(new PdfDeviceNColor(new PdfSpotColor[]{psc_lab2, psc_lab_blue, psc_lab1}), new float[]{0.9f, 0.9f, 1}), 524, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(pdfDeviceNNChannelColor, new float[]{1, 1}), 578, 770, 36, 36);

            canvas.SaveState();
            canvas.Rectangle(418, 412, -329, 189);
            canvas.Clip();
            canvas.NewPath();
            canvas.SaveState();
            canvas.ConcatCTM(329f, 0f, 0f, -329f, 89f, 506.5f);
            canvas.PaintShading(PdfShading.SimpleAxial(writer, 0, 0, 1, 0, new DeviceNColor(pdfDeviceNNChannelColor, new float[]{1, 0}), new DeviceNColor(pdfDeviceNNChannelColor, new float[]{ 0, 1})));
            canvas.RestoreState();
            canvas.RestoreState();
            canvas.SetColorStroke(new DeviceNColor(pdfDeviceNNChannelColor, new float[]{1, 1}));
            canvas.Rectangle(418, 412, -329, 189);
            canvas.Stroke();

            // step 5
            document.Close();

            CompareTool compareTool = new CompareTool();
            String error = compareTool.Compare(dest_file, TEST_RESOURCES_PATH +  "cmp_lab_spot_based_gradient.pdf", DEST_FOLDER, "diff");
            if (error != null) {
                Assert.Fail(error);
            }
        }
Ejemplo n.º 3
0
 public virtual void SetColorStroke(PdfDeviceNColor sp, float[] tints) {
     CheckWriter();
     state.colorDetails = writer.AddSimple(sp);
     PageResources prs = PageResources;
     PdfName name = state.colorDetails.ColorSpaceName;
     name = prs.AddColor(name, state.colorDetails.IndirectReference);
     SaveColor(new DeviceNColor(sp, tints), true);
     content.Append(name.GetBytes()).Append(" CS ");
     foreach (float tint in tints)
         content.Append(tint.ToString(NumberFormatInfo.InvariantInfo) + " ");
     content.Append("SCN").Append_i(separator);
 }
Ejemplo n.º 4
0
        public virtual void DeviceNSpotBasedGradient() {
            // step 1
            Document document = new Document(PageSize.A3);
            // step 2
            String dest_file = DEST_FOLDER + "/device_n_gradient_base.pdf";
            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(dest_file, FileMode.Create));
            // step 3
            document.Open();
            // step 4
            PdfContentByte canvas = writer.DirectContent;
            PdfSpotColor psc_gray = new PdfSpotColor("iTextGray", new GrayColor(0f));
            PdfSpotColor psc_cmyk_yell = new PdfSpotColor("iTextYellow", new CMYKColor(0f, 0f, 1f, 0f));
            PdfSpotColor psc_cmyk_magen = new PdfSpotColor("iTextMagenta", new CMYKColor(0f, 1f, 0f, 0f));
            PdfSpotColor psc_rgb_blue = new PdfSpotColor("iTextBlue", new BaseColor(0, 0, 255));

            PdfDeviceNColor pdfDeviceNNChannelColor =
                new PdfDeviceNColor(new PdfSpotColor[] {psc_cmyk_yell, psc_cmyk_magen, psc_rgb_blue});
            PdfDeviceNColor pdfDeviceNNChannelColor2 =
                new PdfDeviceNColor(new PdfSpotColor[] {psc_cmyk_magen, psc_cmyk_yell, psc_rgb_blue});

            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("iTextGray", new GrayColor(0f)), 0.8f), 36, 824, 36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("iTextYellow", new CMYKColor(0f, 0f, 1f, 0f)), 0.8f), 90, 824,
                36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("iTextMagenta", new CMYKColor(0f, 1f, 0f, 0f)), 0.4f), 144, 824,
                36, 36);
            ColorRectangle(canvas, new SpotColor(new PdfSpotColor("iTextBlue", new BaseColor(0, 0, 255)), 0.7f), 198, 824, 36, 36);

            ColorRectangle(canvas,
                new DeviceNColor(new PdfDeviceNColor(new PdfSpotColor[] {psc_cmyk_yell, psc_cmyk_magen, psc_rgb_blue}),
                    new float[] {0, 0.0f, 1}), 36, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(pdfDeviceNNChannelColor, new float[] {0.1f, 0.1f, 1}), 90, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(pdfDeviceNNChannelColor, new float[] {0.2f, 0.2f, 1}), 144, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(pdfDeviceNNChannelColor, new float[] {0.3f, 0.3f, 1}), 198, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(pdfDeviceNNChannelColor, new float[] {0.4f, 0.4f, 1}), 252, 770, 36, 36);
            ColorRectangle(canvas,
                new DeviceNColor(new PdfDeviceNColor(new PdfSpotColor[] {psc_cmyk_yell, psc_cmyk_magen, psc_rgb_blue, psc_gray}),
                    new float[] {0.5f, 0.5f, 1, 0.5f}), 306, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(pdfDeviceNNChannelColor2, new float[] {0.6f, 0.1f, 1}), 360, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(pdfDeviceNNChannelColor, new float[] {0.7f, 0.7f, 1}), 416, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(pdfDeviceNNChannelColor, new float[] {0.8f, 0.8f, 1}), 470, 770, 36, 36);
            ColorRectangle(canvas,
                new DeviceNColor(new PdfDeviceNColor(new PdfSpotColor[] {psc_cmyk_yell, psc_cmyk_magen, psc_rgb_blue}),
                    new float[] {0.9f, 0.9f, 1}), 524, 770, 36, 36);
            ColorRectangle(canvas, new DeviceNColor(pdfDeviceNNChannelColor, new float[] {1, 1, 1}), 578, 770, 36, 36);

            PdfDeviceNColor pdfDeviceNColor = new PdfDeviceNColor(new PdfSpotColor[] {psc_cmyk_yell, psc_cmyk_magen, psc_rgb_blue});
            canvas.SetColorFill(new DeviceNColor(pdfDeviceNColor, new float[] {0, 0, 1}));
            canvas.Rectangle(36, 716, 36, 36);
            canvas.FillStroke();
            canvas.SetColorFill(new DeviceNColor(pdfDeviceNColor, new float[] {0.1f, 0.1f, 1}));
            canvas.Rectangle(90, 716, 36, 36);
            canvas.FillStroke();
            canvas.SetColorFill(new DeviceNColor(pdfDeviceNColor, new float[] {0.2f, 0.2f, 1}));
            canvas.Rectangle(144, 716, 36, 36);
            canvas.FillStroke();
            canvas.SetColorFill(new DeviceNColor(pdfDeviceNColor, new float[] {0.3f, 0.3f, 1}));
            canvas.Rectangle(198, 716, 36, 36);
            canvas.FillStroke();
            canvas.SetColorFill(new DeviceNColor(pdfDeviceNColor, new float[] {0.4f, 0.4f, 1}));
            canvas.Rectangle(252, 716, 36, 36);
            canvas.FillStroke();
            canvas.SetColorFill(new DeviceNColor(pdfDeviceNColor, new float[] {0.5f, 0.5f, 1}));
            canvas.Rectangle(306, 716, 36, 36);
            canvas.FillStroke();
            canvas.SetColorFill(new DeviceNColor(pdfDeviceNColor, new float[] {0.6f, 0.1f, 1}));
            canvas.Rectangle(360, 716, 36, 36);
            canvas.FillStroke();
            canvas.SetColorFill(new DeviceNColor(pdfDeviceNColor, new float[] {0.7f, 0.7f, 1}));
            canvas.Rectangle(416, 716, 36, 36);
            canvas.FillStroke();
            canvas.SetColorFill(new DeviceNColor(pdfDeviceNColor, new float[] {0.8f, 0.8f, 1}));
            canvas.Rectangle(470, 716, 36, 36);
            canvas.FillStroke();
            canvas.SetColorFill(new DeviceNColor(pdfDeviceNColor, new float[] {0.9f, 0.9f, 1}));
            canvas.Rectangle(524, 716, 36, 36);
            canvas.FillStroke();
            canvas.SetColorFill(new DeviceNColor(pdfDeviceNColor, new float[] {1, 1, 1}));
            canvas.Rectangle(578, 716, 36, 36);
            canvas.FillStroke();

            canvas.SaveState();
            canvas.Rectangle(418, 412, -329, 189);
            canvas.Clip();
            canvas.NewPath();
            canvas.SaveState();
            canvas.ConcatCTM(329f, 0f, 0f, -329f, 89f, 506.5f);
            canvas.PaintShading(PdfShading.SimpleAxial(writer, 0, 0, 1, 0,
                new DeviceNColor(pdfDeviceNNChannelColor, new float[] {1, 1, 0}),
                new DeviceNColor(pdfDeviceNNChannelColor, new float[] {0, 0, 1})));
            canvas.RestoreState();
            canvas.RestoreState();
            canvas.SetColorStroke(new DeviceNColor(pdfDeviceNNChannelColor, new float[] {1, 1, 1}));
            canvas.Rectangle(418, 412, -329, 189);
            canvas.Stroke();

            // step 5
            document.Close();

            CompareTool compareTool = new CompareTool();
            String error = compareTool.Compare(dest_file, TEST_RESOURCES_PATH + "cmp_device_n_gradient_base.pdf", DEST_FOLDER, "diff_");
            if (error != null) {
                Assert.Fail(error);
            }
        }
Ejemplo n.º 5
0
        public virtual void DeviceNCmykRedRgbBlueGradient() {
            Document document = new Document();
            // step 2
            String dest_file = DEST_FOLDER + "/device_n_gradient_CmykRedRgbBlue.pdf";
            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(dest_file, FileMode.Create));
            // step 3
            document.Open();
            // step 4
            PdfContentByte canvas = writer.DirectContent;
            PdfSpotColor psc_red = new PdfSpotColor("Spot Red", new CMYKColor(0f, 1f, 1f, 0f));
            PdfSpotColor psc_blue = new PdfSpotColor("Spot Blue", new BaseColor(0, 0, 255));
            PdfDeviceNColor deviceNColor = new PdfDeviceNColor(new PdfSpotColor[] {psc_red, psc_blue});

            canvas.SaveState();
            canvas.Rectangle(418, 412, -329, 189);
            canvas.Clip();
            canvas.NewPath();
            canvas.SaveState();
            canvas.ConcatCTM(329f, 0f, 0f, -329f, 89f, 506.5f);
            canvas.PaintShading(PdfShading.SimpleAxial(writer, 0, 0, 1, 0, new DeviceNColor(deviceNColor, new float[] {1, 0}),
                new DeviceNColor(deviceNColor, new float[] {0, 1})));
            canvas.RestoreState();
            canvas.RestoreState();
            canvas.SetCMYKColorStroke(0, 0, 0, 0xFF);
            canvas.Rectangle(418, 412, -329, 189);
            canvas.Stroke();
            document.Close();

            CompareTool compareTool = new CompareTool();
            String error = compareTool.Compare(dest_file, TEST_RESOURCES_PATH + "cmp_device_n_gradient_CmykRedRgbBlue.pdf", DEST_FOLDER, "diff_");
            if (error != null) {
                Assert.Fail(error);
            }
        }