Exemple #1
0
 public PatternColor(PdfPattern.Tiling uncoloredPattern, PdfSpecialCs.UncoloredTilingPattern uncoloredTilingCS
                     , float[] colorValue)
     : base(uncoloredTilingCS, colorValue)
 {
     this.pattern         = uncoloredPattern;
     this.underlyingColor = MakeColor(uncoloredTilingCS.GetUnderlyingColorSpace(), colorValue);
 }
        public virtual void PatternColorUncoloredSetTwiceTest()
        {
            String    name   = "patternColorUncoloredSetTwiceTest.pdf";
            PdfWriter writer = new PdfWriter(destinationFolder + name);

            writer.SetCompressionLevel(CompressionConstants.NO_COMPRESSION);
            PdfDocument document = new PdfDocument(writer);
            PdfPage     page     = document.AddNewPage();
            PdfCanvas   canvas   = new PdfCanvas(page);

            PdfPattern.Tiling circle = new PdfPattern.Tiling(15, 15, 10, 20, false);
            new PdfPatternCanvas(circle, document).Circle(7.5f, 7.5f, 2.5f).Fill().Release();
            PdfPattern.Tiling line = new PdfPattern.Tiling(5, 10, false);
            new PdfPatternCanvas(line, document).SetLineWidth(1).MoveTo(3, -1).LineTo(3, 11).Stroke().Release();
            PatternColor patternColorCircle = new PatternColor(circle, ColorConstants.RED);

            float[] cyan    = new float[] { 1, 0, 0, 0 };
            float[] magenta = new float[] { 0, 1, 0, 0 };
            PdfSpecialCs.UncoloredTilingPattern uncoloredTilingCmykCs = new PdfSpecialCs.UncoloredTilingPattern(new PdfDeviceCs.Cmyk
                                                                                                                    ());
            PatternColor patternColorLine = new PatternColor(line, uncoloredTilingCmykCs, magenta);

            canvas.SetFillColor(patternColorCircle);
            canvas.Rectangle(36, 696, 126, 126).Fill();
            canvas.SetFillColor(patternColorCircle);
            canvas.Rectangle(180, 696, 126, 126).Fill();
            canvas.SetFillColor(patternColorLine);
            canvas.Rectangle(36, 576, 126, 126).Fill();
            patternColorLine.SetColorValue(cyan);
            canvas.SetFillColor(patternColorLine);
            canvas.Rectangle(180, 576, 126, 126).Fill();
            // this case will be removed when deprecated method is removed
            patternColorLine.SetPattern(circle);
            canvas.SetFillColor(patternColorLine);
            canvas.Rectangle(360, 696, 126, 126).Fill();
            byte[] pageContentStreamBytes = canvas.GetContentStream().GetBytes();
            canvas.Release();
            document.Close();
            String contentStreamString = iText.IO.Util.JavaUtil.GetStringForBytes(pageContentStreamBytes, System.Text.Encoding
                                                                                  .ASCII);
            int p1Count = CountSubstringOccurrences(contentStreamString, "/P1 scn");
            int p2Count = CountSubstringOccurrences(contentStreamString, "/P2 scn");

            NUnit.Framework.Assert.AreEqual(3, p1Count);
            NUnit.Framework.Assert.AreEqual(2, p2Count);
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + name, sourceFolder +
                                                                             "cmp_" + name, destinationFolder));
        }
Exemple #3
0
        public virtual void MakePatternColorTest()
        {
            PdfWriter writer = new PdfWriter(DESTINATION_FOLDER + "makePatternColorTest.pdf");

            writer.SetCompressionLevel(CompressionConstants.NO_COMPRESSION);
            PdfDocument document = new PdfDocument(writer);
            PdfPage     page     = document.AddNewPage();
            PdfCanvas   canvas   = new PdfCanvas(page);

            PdfSpecialCs.Pattern pattern = new PdfSpecialCs.UncoloredTilingPattern(new PdfDeviceCs.Rgb());
            Color greenPattern           = Color.MakeColor(pattern, new float[] { 0, 1, 0 });

            PdfPattern.Tiling circle = new PdfPattern.Tiling(10, 10, 12, 12, false);
            new PdfPatternCanvas(circle, document).Circle(5f, 5f, 5f).Fill().Release();
            canvas.SetColor(greenPattern.GetColorSpace(), greenPattern.GetColorValue(), circle, true).Rectangle(50, 600
                                                                                                                , 50, 50).Fill();
            canvas.Release();
            document.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(DESTINATION_FOLDER + "makePatternColorTest.pdf"
                                                                             , SOURCE_FOLDER + "cmp_makePatternColorTest.pdf", DESTINATION_FOLDER, "diff_"));
        }
        public virtual void PatternColorUncoloredCircleRgbTest()
        {
            String    name   = "patternColorUncoloredCircleRgbTest.pdf";
            PdfWriter writer = new PdfWriter(destinationFolder + name);

            writer.SetCompressionLevel(CompressionConstants.NO_COMPRESSION);
            PdfDocument document = new PdfDocument(writer);
            PdfPage     page     = document.AddNewPage();
            PdfCanvas   canvas   = new PdfCanvas(page);

            PdfPattern.Tiling circle = new PdfPattern.Tiling(15, 15, 10, 20, false);
            new PdfPatternCanvas(circle, document).Circle(7.5f, 7.5f, 2.5f).Fill().Release();
            PdfSpecialCs.UncoloredTilingPattern uncoloredRgbCs = new PdfSpecialCs.UncoloredTilingPattern(new PdfDeviceCs.Rgb
                                                                                                             ());
            float[] green = new float[] { 0, 1, 0 };
            canvas.SetFillColor(new PatternColor(circle, uncoloredRgbCs, green));
            canvas.Rectangle(30, 300, 400, 400).Fill();
            canvas.Release();
            document.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + name, sourceFolder +
                                                                             "cmp_" + name, destinationFolder));
        }