Exemplo n.º 1
0
        protected override Native.PDFObjectRef DoOutputToPDF(PDFRenderContext context, PDFWriter writer)
        {
            Scryber.Drawing.PDFPoint oldOffset = context.Offset;

            if (this.Region.PositionMode == Drawing.PositionMode.Absolute)
            {
                context.Offset = Scryber.Drawing.PDFPoint.Empty;
            }
            Native.PDFObjectRef oref = this.Region.OutputToPDF(context, writer);

            context.Offset = oldOffset;
            return(oref);
        }
Exemplo n.º 2
0
        protected override PDFObjectRef DoOutputToPDF(PDFRenderContext context, PDFWriter writer)
        {
            //Get the default font and size required for the DA (default Appearance value)
            var xObject = this._states[FormFieldAppearanceState.Normal];

            if (null == xObject)
            {
                return(null);
            }

            PDFObjectRef root = writer.BeginObject();

            var    font = this._style.CreateFont();
            var    rsrc = xObject.Document.GetResource(Scryber.Resources.PDFResource.FontDefnResourceType, font.FullName, true);
            string da   = rsrc.Name.ToString() + " " + font.Size.ToPoints().Value.ToString() + " Tf";

            writer.BeginDictionary();
            writer.WriteDictionaryNameEntry("Subtype", "Widget");
            writer.WriteDictionaryStringEntry("T", this.Name);

            if (!string.IsNullOrEmpty(this.Value))
            {
                writer.WriteDictionaryStringEntry("V", this.Value);
            }

            if (!string.IsNullOrEmpty(this.DefaultValue))
            {
                writer.WriteDictionaryStringEntry("DV", this.DefaultValue);
            }

            writer.WriteDictionaryNumberEntry("Ff", (int)this.FieldOptions + (int)this.FieldType);
            writer.WriteDictionaryStringEntry("DA", da);
            writer.WriteDictionaryNameEntry("FT", GetFieldTypeName(this.FieldType));
            if (null != this._page && null != this._page.PageObjectRef)
            {
                writer.WriteDictionaryObjectRefEntry("P", this._page.PageObjectRef);
            }

            //MK - appearance dictionary
            writer.BeginDictionaryEntry("MK");
            writer.BeginDictionary();

            if (this._style.IsValueDefined(Styles.StyleKeys.BorderColorKey))
            {
                WriteInputColor(context, writer, "BC", this._style.Border.Color);
            }
            if (this._style.IsValueDefined(Styles.StyleKeys.BgColorKey))
            {
                WriteInputColor(context, writer, "BG", this._style.Background.Color);
            }
            writer.EndDictionary();
            writer.EndDictionaryEntry();

            if (this._states.Count > 0)
            {
                _location = context.Offset;

                Drawing.PDFRect bounds = Drawing.PDFRect.Empty;
                writer.BeginDictionaryEntry("AP");
                writer.BeginDictionary();
                foreach (var kvp in _states)
                {
                    xObject = kvp.Value;
                    FormFieldAppearanceState state = kvp.Key;

                    PDFObjectRef oref = xObject.OutputToPDF(context, writer);

                    if (null != oref)
                    {
                        PDFSize sz = new Drawing.PDFSize(xObject.Width, xObject.Height);
                        if (_size == PDFSize.Empty)
                        {
                            _size = sz;
                        }
                        else
                        {
                            if (_size.Width < sz.Width)
                            {
                                _size.Width = sz.Width;
                            }
                            if (_size.Height < sz.Height)
                            {
                                _size.Height = sz.Height;
                            }
                        }
                        var name = GetFieldStateName(kvp.Key);
                        writer.WriteDictionaryObjectRefEntry(name, oref);

                        //We should have all states starting at the same location no matter what.
                        this._location = xObject.Location;
                    }
                }
                writer.EndDictionary();
                writer.EndDictionaryEntry();

                PDFReal left   = context.Graphics.GetXPosition(_location.X);
                PDFReal top    = context.Graphics.GetYPosition(_location.Y);
                PDFReal right  = left + context.Graphics.GetXOffset(_size.Width);
                PDFReal bottom = top + context.Graphics.GetYOffset(_size.Height);

                writer.BeginDictionaryEntry("Rect");
                writer.WriteArrayRealEntries(true, left.Value, bottom.Value, right.Value, top.Value);
                writer.EndDictionaryEntry();
            }
            writer.EndDictionary();
            writer.EndObject();
            //context.Offset = new PDFPoint(context.Offset.X, context.Offset.Y + _size.Height);
            return(root);
        }
Exemplo n.º 3
0
 public void DrawLine(PDFPoint start, PDFPoint end)
 {
     this.RenderMoveTo(start.X, start.Y);
     this.RenderLineTo(end.X, end.Y);
     this.RenderStrokePathOp();
 }
Exemplo n.º 4
0
 public void DrawElipse(PDFPen pen, PDFPoint pos, PDFSize size)
 {
     this.DrawElipse(pen, pos.X, pos.Y, size.Width, size.Height);
 }
Exemplo n.º 5
0
 public void DrawCurve(PDFPoint start, PDFPoint end, PDFPoint starthandle, PDFPoint endhandle)
 {
     this.RenderMoveTo(start.X, start.Y);
     this.RenderBezierCurveTo(end.X, end.Y, starthandle.X, starthandle.Y, endhandle.X, endhandle.Y);
 }
Exemplo n.º 6
0
 public void DrawContinuationCurve(PDFPoint end, PDFPoint starthandle, PDFPoint endhandle)
 {
     this.RenderBezierCurveTo(end.X, end.Y, starthandle.X, starthandle.Y, endhandle.X, endhandle.Y);
 }
Exemplo n.º 7
0
 public void FillQuadrants(PDFBrush brush, PDFPoint pos, PDFSize size, Quadrants sides)
 {
     this.FillQuadrants(brush, pos.X, pos.Y, size.Width, size.Height, sides);
 }
Exemplo n.º 8
0
 public void DrawQuadrants(PDFPen pen, PDFPoint pos, PDFSize size, Quadrants sides)
 {
     this.DrawQuadrants(pen, pos.X, pos.Y, size.Width, size.Height, sides);
 }
        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);
            }
        }
Exemplo n.º 10
0
 private PDFPoint ConvertDeltaToActual(PDFPoint delta)
 {
     return(new PDFPoint(this.Cursor.X + delta.X, this.Cursor.Y + delta.Y));
 }
Exemplo n.º 11
0
        internal void ArcFor(PDFUnit rx, PDFUnit ry, double ang, PathArcSize size, PathArcSweep sweep, PDFPoint enddelta)
        {
            PDFPoint    end = ConvertDeltaToActual(enddelta);
            PathArcData arc = new PathArcData()
            {
                RadiusX = rx, RadiusY = ry, XAxisRotation = ang, ArcSize = size, ArcSweep = sweep, EndPoint = end
            };

            CurrentPath.Add(arc);

            IEnumerable <PathBezierCurveData> curves = PathDataHelper.GetBezierCurvesForArc(this.Cursor, arc);

            foreach (PathBezierCurveData bez in curves)
            {
                IncludeInBounds(bez.EndPoint);
                if (bez.HasStartHandle)
                {
                    IncludeInBounds(bez.StartHandle);
                }
                if (bez.HasEndHandle)
                {
                    IncludeInBounds(bez.EndHandle);
                }
            }

            Cursor = end;
        }