Ejemplo n.º 1
0
 public PatternColor(PdfPattern.Tiling uncoloredPattern, PdfSpecialCs.UncoloredTilingPattern uncoloredTilingCS
                     , float[] colorValue)
     : base(uncoloredTilingCS, colorValue)
 {
     this.pattern         = uncoloredPattern;
     this.underlyingColor = MakeColor(uncoloredTilingCS.GetUnderlyingColorSpace(), colorValue);
 }
Ejemplo n.º 2
0
        private void SetColorSameColorSpacesTest(String pdfName, bool pattern)
        {
            String        cmpFile  = sourceFolder + "cmp_" + pdfName;
            String        destFile = destinationFolder + pdfName;
            PdfDocument   document = new PdfDocument(new PdfWriter(destFile));
            PdfPage       page     = document.AddNewPage();
            PdfCanvas     canvas   = new PdfCanvas(page);
            PdfColorSpace space    = pattern ? new PdfSpecialCs.Pattern() : PdfColorSpace.MakeColorSpace(PdfName.DeviceRGB
                                                                                                         );

            float[]    colorValue1 = pattern ? null : new float[] { 1.0f, 0.6f, 0.7f };
            float[]    colorValue2 = pattern ? null : new float[] { 0.1f, 0.9f, 0.9f };
            PdfPattern pattern1    = pattern ? new PdfPattern.Shading(new PdfShading.Axial(new PdfDeviceCs.Rgb(), 45, 750
                                                                                           , ColorConstants.PINK.GetColorValue(), 100, 760, ColorConstants.MAGENTA.GetColorValue())) : null;
            PdfPattern pattern2 = pattern ? new PdfPattern.Shading(new PdfShading.Axial(new PdfDeviceCs.Rgb(), 45, 690
                                                                                        , ColorConstants.BLUE.GetColorValue(), 100, 710, ColorConstants.CYAN.GetColorValue())) : null;

            canvas.SetColor(space, colorValue1, pattern1, true);
            canvas.SaveState();
            canvas.BeginText().MoveText(50, 750).SetFontAndSize(PdfFontFactory.CreateFont(), 16).ShowText("pinkish").EndText
                ();
            canvas.SaveState().BeginText().SetColor(space, colorValue2, pattern2, true).MoveText(50, 720).SetFontAndSize
                (PdfFontFactory.CreateFont(), 16).ShowText("bluish").EndText().RestoreState();
            canvas.RestoreState();
            canvas.SaveState().BeginText().MoveText(50, 690).SetColor(space, colorValue2, pattern2, true).SetFontAndSize
                (PdfFontFactory.CreateFont(), 16).ShowText("bluish").EndText().RestoreState();
            canvas.Release();
            document.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destFile, cmpFile, destinationFolder, "diff_"
                                                                             ));
        }
Ejemplo n.º 3
0
 public PatternColor(PdfPattern.Tiling uncoloredPattern, PdfColorSpace underlyingCS, float[] colorValue)
     : base(new PdfSpecialCs.UncoloredTilingPattern(underlyingCS), colorValue)
 {
     if (underlyingCS is PdfSpecialCs.Pattern)
     {
         throw new ArgumentException("underlyingCS");
     }
     this.pattern         = uncoloredPattern;
     this.underlyingColor = MakeColor(underlyingCS, colorValue);
 }
Ejemplo n.º 4
0
 public override void CheckColor(Color color, PdfDictionary currentColorSpaces, bool?fill, PdfStream stream
                                 )
 {
     CheckColorSpace(color.GetColorSpace(), currentColorSpaces, true, fill);
     if (color is PatternColor)
     {
         PdfPattern pattern = ((PatternColor)color).GetPattern();
         if (pattern is PdfPattern.Tiling)
         {
             CheckContentStream((PdfStream)pattern.GetPdfObject());
         }
     }
 }
Ejemplo n.º 5
0
        public static Color?GetColor(PdfPattern pattern, float alpha)
        {
            //not supported yet
            return(null);

            switch (pattern)
            {
            case PdfPattern.Shading shading:
                return(GetColor(shading, alpha));

            case PdfPattern.Tiling tiling:
                return(GetColor(tiling, alpha));

            default: throw new IndexOutOfRangeException();
            }
        }
Ejemplo n.º 6
0
        public void Start()
        {
            // Create the anchor for all pdf objects
            CompressionConfig cc = RdlEngineConfig.GetCompression();
            anchor = new PdfAnchor(cc != null);

            //Create a PdfCatalog
            string lang;
            if (r.ReportDefinition.Language != null)
                lang = r.ReportDefinition.Language.EvaluateString(this.r, null);
            else
                lang = null;
            catalog = new PdfCatalog(anchor, lang);

            //Create a Page Tree Dictionary
            pageTree = new PdfPageTree(anchor);

            //Create a Font Dictionary
            fonts = new PdfFonts(anchor);

            //Create a Pattern Dictionary
            patterns = new PdfPattern(anchor);

            //Create an Image Dictionary
            images = new PdfImages(anchor);

            //Create an Outline Dictionary
            outline = new PdfOutline(anchor);

            //Create the info Dictionary
            info = new PdfInfo(anchor);

            //Set the info Dictionary. 
            info.SetInfo(r.Name, r.Author, r.Description, "");	// title, author, subject, company

            //Create a utility object
            pdfUtility = new PdfUtility(anchor);

            //write out the header
            int size = 0;

            if (r.ItextPDF)
            {
                PdfWriter writer = PdfWriter.GetInstance(pdfdocument, ms);
                pdfdocument.Open();
                cb = writer.DirectContent;
                pdfdocument.AddAuthor(r.Author);
                pdfdocument.AddCreationDate();
                pdfdocument.AddCreator("Majorsilence Reporting");
                pdfdocument.AddSubject(r.Description);
                pdfdocument.AddTitle(r.Name);

            }
            else
            {
                tw.Write(pdfUtility.GetHeader("1.5", out size), 0, size);
            }

            //
            filesize = size;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Draw a pie
        /// </summary>
        /// <returns></returns>
        private void iAddPie(float x, float y, float height, float width, StyleInfo si, string url, PdfPattern patterns, string tooltip)
        {
            // Draw background rectangle if needed
            if (!si.BackgroundColor.IsEmpty && height > 0 && width > 0)
            {	// background color, height and width are specified
                iAddFillRect(x, y, width, height, si, patterns);
            }
            iAddBorder(si, x, y, height, width);			// add any required border

            //add url
            if (url != null)
                pdfdocument.Add(new Annotation(x, _pSize.yHeight - y, width + x, height, url));
            //add tooltip
            if (!string.IsNullOrEmpty(tooltip))
                pdfdocument.Add(new Annotation(x, _pSize.yHeight - y, width + x, height, tooltip));
            return;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Page Polygon
        /// </summary>
        /// <param name="pts"></param>
        /// <param name="si"></param>
        /// <param name="url"></param>
        /// <param name="patterns"></param>
        internal void iAddPolygon(PointF[] pts, StyleInfo si, string url, PdfPattern patterns)
        {
            if (si.BackgroundColor.IsEmpty)
                return;		 // nothing to do

            // Get the fill color - could be a gradient or pattern etc...
            System.Drawing.Color c = si.BackgroundColor;
            iAddPoints(pts);
            cb.SetRGBColorFill(c.R, c.G, c.B);
            cb.ClosePathFillStroke();

            //Not sure about iTextSharp Pattern => Need check
            if (si.PatternType != patternTypeEnum.None)
            {
                string p = patterns.GetPdfPattern(si.PatternType.ToString());
                StringBuilder elements = new StringBuilder();
                c = si.Color;
                double red = Math.Round((c.R / 255.0), 3);
                double green = Math.Round((c.G / 255.0), 3);
                double blue = Math.Round((c.B / 255.0), 3);
                elements.AppendFormat("\r\nq");
                elements.AppendFormat("\r\n /CS1 cs");
                elements.AppendFormat("\r\n {0} {1} {2} /{3} scn", red, green, blue, p);
                elements.AppendFormat("\r\n {0} {1} {2} RG", red, green, blue);
                elements.AppendFormat("\tQ");
                PdfPatternPainter pdfp = cb.CreatePattern(60f, 60f, 60f, 60f);
                pdfp.SetLiteral(elements.ToString());
                cb.SetPatternFill(pdfp);
                iAddPoints(pts);
                cb.ClosePathFillStroke();
            }
        }
Ejemplo n.º 9
0
        private void iAddFillRect(float x, float y, float width, float height, StyleInfo si, PdfPattern patterns)
        {
            System.Drawing.Color c;
            //Not sure about iTextSharp Pattern => Need check
            if (si.PatternType != patternTypeEnum.None)
            {
                string p = patterns.GetPdfPattern(si.PatternType.ToString());
                c = si.Color;
                double red = Math.Round((c.R / 255.0), 3);
                double green = Math.Round((c.G / 255.0), 3);
                double blue = Math.Round((c.B / 255.0), 3);
                StringBuilder elements = new StringBuilder();
                elements.AppendFormat("\r\nq");
                elements.AppendFormat("\r\n /CS1 cs");
                elements.AppendFormat("\r\n {0} {1} {2} /{3} scn", red, green, blue, p);
                elements.AppendFormat("\r\n {0} {1} {2} RG", red, green, blue);
                elements.AppendFormat("\r\n {0} {1} {2} {3} re\tf", x, _pSize.yHeight - y - height, width, height);
                elements.AppendFormat("\tQ");
                PdfPatternPainter pdfp = cb.CreatePattern(60f, 60f, 60f, 60f);
                pdfp.SetLiteral(elements.ToString());
                cb.SetPatternFill(pdfp);
            }
            // Get the fill color - could be a gradient or pattern etc...
            c = si.BackgroundColor;
            cb.SetRGBColorFill(c.R, c.G, c.B);
            cb.Rectangle(x, _pSize.yHeight - y - height, width, height);
            //cb.ClosePathFillStroke();
            cb.Fill();

        }
Ejemplo n.º 10
0
        public virtual PdfPattern GetPattern(PdfName name)
        {
            PdfObject pattern = GetResourceObject(PdfName.Pattern, name);

            return(pattern is PdfDictionary?PdfPattern.GetPatternInstance((PdfDictionary)pattern) : null);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Adds
 /// <see cref="iText.Kernel.Pdf.Colorspace.PdfPattern"/>
 /// object to the resources.
 /// </summary>
 /// <param name="pattern">
 /// the
 /// <see cref="iText.Kernel.Pdf.Colorspace.PdfPattern"/>
 /// to add.
 /// </param>
 /// <returns>added pattern resource name.</returns>
 public virtual PdfName AddPattern(PdfPattern pattern)
 {
     return(AddResource(pattern, patternNamesGen));
 }
Ejemplo n.º 12
0
 public PatternColor(PdfPattern coloredPattern)
     : base(new PdfSpecialCs.Pattern(), null)
 {
     // The underlying color for uncolored patterns. Will be null for colored ones.
     this.pattern = coloredPattern;
 }
Ejemplo n.º 13
0
 public virtual void SetPattern(PdfPattern pattern)
 {
     this.pattern = pattern;
 }
Ejemplo n.º 14
0
 public PatternColor(PdfPattern coloredPattern)
     : base(new PdfSpecialCs.Pattern(), null)
 {
     this.pattern = coloredPattern;
 }
 public override PdfCanvas SetColor(PdfColorSpace colorSpace, float[] colorValue, PdfPattern pattern, bool
                                    fill)
 {
     CheckNoColor();
     return(base.SetColor(colorSpace, colorValue, pattern, fill));
 }