コード例 #1
0
        public override bool SetUpGraphics(PDFGraphics graphics, PDFRect bounds)
        {
            var doc = graphics.Container.Document;
            var id  = doc.GetIncrementID(PDFObjectTypes.Pattern);

            bounds = ConvertToPageRect(graphics, bounds);

            var linear = this.GetLinearShadingPattern(graphics, id, this._descriptor, bounds);

            if (null != linear)
            {
                var name = graphics.Container.Register(linear);
                graphics.SetFillPattern(name);
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #2
0
        public override bool SetUpGraphics(PDFGraphics g, PDFRect bounds)
        {
            Scryber.Resources.PDFImageXObject imagex;

            string fullpath = _source; // g.Container.MapPath(_source); - Map Path is done in the document now
            //TODO: Add XStep, YStep etc.
            string resourcekey = GetImagePatternKey(fullpath);


            PDFResource rsrc = g.Container.Document.GetResource(PDFResource.PatternResourceType, resourcekey, false);

            if (null == rsrc)
            {
                //Create the image
                imagex = g.Container.Document.GetResource(Scryber.Resources.PDFResource.XObjectResourceType, fullpath, true) as PDFImageXObject;

                if (null == imagex)
                {
                    if (g.Context.Conformance == ParserConformanceMode.Lax)
                    {
                        g.Context.TraceLog.Add(TraceLevel.Error, "Drawing", "Could not set up the image brush as the graphic image was not found or returned for : " + fullpath);
                        return(false);
                    }
                    else
                    {
                        throw new PDFRenderException("Could not set up the image brush as the graphic image was not found or returned for : " + fullpath);
                    }
                }

                //The container of a pattern is the document as this is the scope
                PDFImageTilingPattern tile = new PDFImageTilingPattern(g.Container.Document, resourcekey, imagex);
                tile.Container  = g.Container;
                tile.Image      = imagex;
                tile.PaintType  = PatternPaintType.ColoredTile;
                tile.TilingType = PatternTilingType.NoDistortion;

                //Calculate the bounds of the pattern

                PDFUnit width;
                PDFUnit height;
                PDFSize imgsize = CalculateAppropriateImageSize(imagex.ImageData, bounds);
                width  = imgsize.Width;
                height = imgsize.Height;


                //Patterns are drawn from the bottom of the page so Y is the container height minus the vertical position and offset
                PDFUnit y = 0; // g.ContainerSize.Height - (bounds.Y);// g.ContainerSize.Height - (bounds.Y + height + this.YPostion);
                //X is simply the horizontal position plus offset
                PDFUnit x = 0; // bounds.X + this.XPostion;

                tile.ImageSize = imgsize;

                PDFSize step = new PDFSize();
                if (this.XStep == 0)
                {
                    step.Width = width;
                }
                else
                {
                    step.Width = this.XStep;
                }

                if (this.YStep == 0)
                {
                    step.Height = height;
                }
                else
                {
                    step.Height = this.YStep;
                }
                tile.Step = step;

                PDFPoint start = new PDFPoint(bounds.X + this.XPostion, bounds.Y + this.YPostion);

                if (g.Origin == DrawingOrigin.TopLeft)
                {
                    start.Y = g.ContainerSize.Height - start.Y;
                }
                tile.Start = start;

                PDFName name = g.Container.Register(tile);

                g.SetFillPattern(name);
                return(true);
            }
            else
            {
                return(false);
            }
        }