コード例 #1
0
        /// <summary>
        /// Renders the <see cref="SvgDocument">SvgDocument</see>.
        /// </summary>
        /// <param name="node">
        /// The <see cref="SvgDocument">SvgDocument</see> node to be
        /// rendered
        /// </param>
        /// <returns>
        /// The bitmap on which the rendering was performed.
        /// </returns>
        public void Render(ISvgDocument node)
        {
            SvgRectF updatedRect;

            if (invalidRect != SvgRectF.Empty)
            {
                updatedRect = new SvgRectF(invalidRect.X, invalidRect.Y,
                                           invalidRect.Width, invalidRect.Height);
            }
            else
            {
                updatedRect = SvgRectF.Empty;
            }

            RendererBeforeRender();

            if (graphics != null && graphics.Graphics != null)
            {
                _svgRenderer.Render(node);
            }

            RendererAfterRender();

            if (onRender != null)
            {
                OnRender(updatedRect);
            }
        }
コード例 #2
0
        public void OnRender(SvgRectF updatedRect)
        {
            //            using (var graphics = CreateGraphics())
            //            {
            //                this.UpdateGraphics(graphics);

            //                if (updatedRect == SvgRectF.Empty)
            //                {
            ////TODO:                    this.Draw(graphics);
            //                    this.DrawEx(graphics, this.ImageRectangle);
            //                }
            //                else
            //                {
            ////TODO:                    this.Draw(graphics, GdiConverter.ToRectangle(updatedRect));
            //                    this.DrawEx(graphics, this.ImageRectangle);
            //                }
            //            }

            this.Invalidate(new Rectangle((int)updatedRect.X, (int)updatedRect.Y,
                                          (int)updatedRect.Width, (int)updatedRect.Height));

            // Collect the rendering regions for later updates
            //SvgDocument doc = (window.Document as SvgDocument);
            //SvgElement root = (doc.RootElement as SvgElement);
            //root.CacheRenderingRegion(renderer);
        }
コード例 #3
0
        /// <summary>
        /// Renders the <see cref="SvgElement">SvgElement</see>.
        /// </summary>
        /// <param name="node">
        /// The <see cref="SvgElement">SvgElement</see> node to be
        /// rendered
        /// </param>
        /// <returns>
        /// The bitmap on which the rendering was performed.
        /// </returns>
        public void Render(ISvgElement node)
        {
            SvgRectF updatedRect;

            if (_invalidRect != SvgRectF.Empty)
            {
                updatedRect = new SvgRectF(_invalidRect.X, _invalidRect.Y,
                                           _invalidRect.Width, _invalidRect.Height);
            }
            else
            {
                updatedRect = SvgRectF.Empty;
            }

            OnBeforeRender();

            if (_graphics != null && _graphics.Graphics != null)
            {
                _svgRenderer.Render(node);
            }

            OnAfterRender();

            if (_onRender != null)
            {
                OnRender(updatedRect);
            }
        }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the GdiRenderer class.
 /// </summary>
 public GdiGraphicsRenderer(bool isStatic = false, bool disposeRaster = true)
 {
     _isStatic      = isStatic;
     _disposeRaster = disposeRaster;
     _invalidRect   = SvgRectF.Empty;
     _backColor     = Color.White;
     _hitTestHelper = GdiHitTestHelper.NoHit;
     _svgRenderer   = new GdiRenderingHelper(this);
 }
コード例 #5
0
 public void InvalidateRect(SvgRectF rect)
 {
     if (invalidRect == SvgRectF.Empty)
     {
         invalidRect = rect;
     }
     else
     {
         invalidRect.Intersect(rect);
     }
 }
コード例 #6
0
        public ISvgRect GetRenderedBounds(ISvgElement element, float margin)
        {
            SvgTransformableElement transElement = element as SvgTransformableElement;

            if (transElement != null)
            {
                SvgRectF rect = this.GetElementBounds(transElement, margin);

                return(new SvgRect(rect.X, rect.Y, rect.Width, rect.Height));
            }

            return(null);
        }
コード例 #7
0
        /// <summary>
        /// AfterRender - Dispose of Graphics object created for rendering.
        /// </summary>
        private void RendererAfterRender()
        {
            if (graphics != null)
            {
                // Check if we only invalidated a rect
                if (invalidRect != SvgRectF.Empty)
                {
                    // We actually drew everything on invalidatedRasterImage and now we
                    // need to copy that to rasterImage
                    Graphics tempGraphics = Graphics.FromImage(rasterImage);
                    tempGraphics.DrawImage(invalidatedRasterImage, invalidRect.X, invalidRect.Y,
                                           GdiConverter.ToRectangle(invalidRect), GraphicsUnit.Pixel);
                    tempGraphics.Dispose();
                    tempGraphics = null;

                    // If we currently have an idMapRaster here, then we need to create
                    // a temporary graphics object to draw the invalidated portion from
                    // our main graphics window onto it.
                    if (idMapRaster != null)
                    {
                        tempGraphics = Graphics.FromImage(idMapRaster);
                        tempGraphics.DrawImage(graphics.IdMapRaster, invalidRect.X, invalidRect.Y,
                                               GdiConverter.ToRectangle(invalidRect), GraphicsUnit.Pixel);
                        tempGraphics.Dispose();
                        tempGraphics = null;
                    }
                    else
                    {
                        idMapRaster = graphics.IdMapRaster;
                    }
                    // We have updated the invalid region
                    invalidRect = SvgRectF.Empty;
                }
                else
                {
                    if (idMapRaster != null && idMapRaster != graphics.IdMapRaster)
                    {
                        idMapRaster.Dispose();
                    }
                    idMapRaster = graphics.IdMapRaster;
                }

                graphics.Dispose();
                graphics = null;
            }
        }
コード例 #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SvgTransformF"/> class 
        /// to the geometric transform defined by the specified rectangle and 
        /// array of points.
        /// </summary>
        /// <param name="rect">
        /// A <see cref="SvgRectF"/> structure that represents the rectangle 
        /// to be transformed.
        /// </param>
        /// <param name="plgpts">
        /// An array of three <see cref="SvgPointF"/> structures that represents the 
        /// points of a parallelogram to which the upper-left, upper-right, and 
        /// lower-left corners of the rectangle is to be transformed. The 
        /// lower-right corner of the parallelogram is implied by the first three 
        /// corners.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If the <paramref name="plgpts"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// If the length of the <paramref name="plgpts"/> array is not equal
        /// to 3.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// If the width or height of the <paramref name="rect"/> is zero.
        /// </exception>
        public SvgTransformF(SvgRectF rect, SvgPointF[] plgpts)
        {
            if (plgpts == null)
            {
                throw new ArgumentNullException("plgpts");
            }
            if (plgpts.Length != 3)
            {
                throw new ArgumentException("plgpts");
            }

            if ((rect.Width == 0) || (rect.Height == 0))
            {
                throw new ArgumentOutOfRangeException("rect");
            }

            MapRectToRect(rect, plgpts);
        }
コード例 #9
0
ファイル: SvgPictureBox.cs プロジェクト: zellus/SharpVectors
        private void OnRender(SvgRectF updatedRect)
        {
            if (this.InvokeRequired)
            {
                MethodInvoker del = delegate
                {
                    OnRender(updatedRect);
                };
                this.Invoke(del);
                return;
            }

            this.Invalidate(new Rectangle((int)updatedRect.X, (int)updatedRect.Y,
                                          (int)updatedRect.Width, (int)updatedRect.Height));

            // Collect the rendering regions for later updates
            //SvgDocument doc = (window.Document as SvgDocument);
            //SvgElement root = (doc.RootElement as SvgElement);
            //root.CacheRenderingRegion(renderer);
        }
コード例 #10
0
        public void OnRender(SvgRectF updatedRect)
        {
            if (surface != null)
            {
                if (updatedRect == SvgRectF.Empty)
                {
                    Draw(surface);
                }
                else
                {
                    Draw(surface, GdiConverter.ToRectangle(updatedRect));
                }
            }
            else
            {
                surface = CreateGraphics();

                UpdateGraphics(surface);

                if (updatedRect == SvgRectF.Empty)
                {
                    Draw(surface);
                }
                else
                {
                    Draw(surface, GdiConverter.ToRectangle(updatedRect));
                }
                surface.Dispose();
                surface = null;
            }

            // Collect the rendering regions for later updates
            //SvgDocument doc = (window.Document as SvgDocument);
            //SvgElement root = (doc.RootElement as SvgElement);
            //root.CacheRenderingRegion(renderer);
        }
コード例 #11
0
        private SvgRectF GetElementBounds(SvgTransformableElement element, float margin)
        {
            SvgRenderingHint hint = element.RenderingHint;

            if (hint == SvgRenderingHint.Shape || hint == SvgRenderingHint.Text)
            {
                GraphicsPath gp        = GdiRendering.CreatePath(element);
                ISvgMatrix   svgMatrix = element.GetScreenCTM();

                Matrix matrix = new Matrix((float)svgMatrix.A, (float)svgMatrix.B, (float)svgMatrix.C,
                                           (float)svgMatrix.D, (float)svgMatrix.E, (float)svgMatrix.F);
                SvgRectF bounds = SvgConverter.ToRect(gp.GetBounds(matrix));
                bounds = SvgRectF.Inflate(bounds, margin, margin);

                return(bounds);
            }

            SvgUseElement useElement = element as SvgUseElement;

            if (useElement != null)
            {
                SvgTransformableElement refEl = useElement.ReferencedElement as SvgTransformableElement;
                if (refEl == null)
                {
                    return(SvgRectF.Empty);
                }

                XmlElement refElParent = (XmlElement)refEl.ParentNode;
                element.OwnerDocument.Static = true;
                useElement.CopyToReferencedElement(refEl);
                element.AppendChild(refEl);

                SvgRectF bbox = this.GetElementBounds(refEl, margin);

                element.RemoveChild(refEl);
                useElement.RestoreReferencedElement(refEl);
                refElParent.AppendChild(refEl);
                element.OwnerDocument.Static = false;

                return(bbox);
            }

            SvgRectF union = SvgRectF.Empty;
            SvgTransformableElement transformChild;

            foreach (XmlNode childNode in element.ChildNodes)
            {
                if (childNode is SvgDefsElement)
                {
                    continue;
                }
                if (childNode is ISvgTransformable)
                {
                    transformChild = (SvgTransformableElement)childNode;
                    SvgRectF bbox = this.GetElementBounds(transformChild, margin);
                    if (bbox != SvgRectF.Empty)
                    {
                        if (union == SvgRectF.Empty)
                        {
                            union = bbox;
                        }
                        else
                        {
                            union = SvgRectF.Union(union, bbox);
                        }
                    }
                }
            }

            return(union);
        }
コード例 #12
0
        /// <summary>
        /// AfterRender - Dispose of Graphics object created for rendering.
        /// </summary>
        private void RendererAfterRender()
        {
            if (graphics != null)
            {
                // Check if we only invalidated a rect
                if (invalidRect != SvgRectF.Empty)
                {
                    // We actually drew everything on invalidatedRasterImage and now we
                    // need to copy that to rasterImage
                    Graphics tempGraphics = Graphics.FromImage(rasterImage);
                    tempGraphics.DrawImage(invalidatedRasterImage, invalidRect.X, invalidRect.Y,
                      GdiConverter.ToRectangle(invalidRect), GraphicsUnit.Pixel);
                    tempGraphics.Dispose();
                    tempGraphics = null;

                    // If we currently have an idMapRaster here, then we need to create
                    // a temporary graphics object to draw the invalidated portion from
                    // our main graphics window onto it.
                    if (idMapRaster != null)
                    {
                        tempGraphics = Graphics.FromImage(idMapRaster);
                        tempGraphics.DrawImage(graphics.IdMapRaster, invalidRect.X, invalidRect.Y,
                          GdiConverter.ToRectangle(invalidRect), GraphicsUnit.Pixel);
                        tempGraphics.Dispose();
                        tempGraphics = null;
                    }
                    else
                    {
                        idMapRaster = graphics.IdMapRaster;
                    }
                    // We have updated the invalid region
                    invalidRect = SvgRectF.Empty;
                }
                else
                {
                    if (idMapRaster != null && idMapRaster != graphics.IdMapRaster)
                        idMapRaster.Dispose();
                    idMapRaster = graphics.IdMapRaster;
                }

                graphics.Dispose();
                graphics = null;
            }
        }
コード例 #13
0
        /// <summary>
        /// Renders the <see cref="SvgDocument">SvgDocument</see>.
        /// </summary>
        /// <param name="node">
        /// The <see cref="SvgDocument">SvgDocument</see> node to be
        /// rendered
        /// </param>
        /// <returns>
        /// The bitmap on which the rendering was performed.
        /// </returns>
        public void Render(ISvgDocument node)
        {
            SvgRectF updatedRect;
            if (invalidRect != SvgRectF.Empty)
                updatedRect = new SvgRectF(invalidRect.X, invalidRect.Y,
                    invalidRect.Width, invalidRect.Height);
            else
                updatedRect = SvgRectF.Empty;

            RendererBeforeRender();

            if (graphics != null && graphics.Graphics != null)
            {
                _svgRenderer.Render(node);
            }

            RendererAfterRender();

            if (onRender != null)
                OnRender(updatedRect);
        }
コード例 #14
0
 /// <summary>
 /// This converts the specified <see cref="RectangleF"/> structure to a
 /// <see cref="SvgRectF"/> structure.
 /// </summary>
 /// <param name="rect">The <see cref="RectangleF"/> structure to convert.</param>
 /// <returns>
 /// The <see cref="SvgRectF"/> structure that is converted from the
 /// specified <see cref="RectangleF"/> structure.
 /// </returns>
 public static RectangleF ToRectangle(SvgRectF rect)
 {
     return(new RectangleF(rect.X, rect.Y, rect.Width, rect.Height));
 }
コード例 #15
0
 /// <summary>
 /// This converts the specified <see cref="RectangleF"/> structure to a 
 /// <see cref="SvgRectF"/> structure.
 /// </summary>
 /// <param name="rect">The <see cref="RectangleF"/> structure to convert.</param>
 /// <returns>
 /// The <see cref="SvgRectF"/> structure that is converted from the 
 /// specified <see cref="RectangleF"/> structure.
 /// </returns>
 public static RectangleF ToRectangle(SvgRectF rect)
 {
     return new RectangleF(rect.X, rect.Y, rect.Width, rect.Height);
 }
コード例 #16
0
 protected GdiRenderingBase(SvgElement element)
 {
     this.element      = element;
     this.screenRegion = SvgRectF.Empty;
 }
コード例 #17
0
 public void InvalidateRect(SvgRectF rect)
 {
 }
コード例 #18
0
 protected GdiRenderingBase(SvgElement element)
 {
     _svgElement   = element;
     _screenRegion = SvgRectF.Empty;
 }
コード例 #19
0
        private void MapRectToRect(SvgRectF rect, SvgPointF[] plgpts)
        {
            SvgPointF pt1 = new SvgPointF(plgpts[1].X - plgpts[0].X,
                            plgpts[1].Y - plgpts[0].Y);
            SvgPointF pt2 = new SvgPointF(plgpts[2].X - plgpts[0].X,
                            plgpts[2].Y - plgpts[0].Y);

            this.m11 = pt1.X / rect.Width;
            this.m12 = pt1.Y / rect.Width;
            this.m21 = pt2.X / rect.Height;
            this.m22 = pt2.Y / rect.Height;
            this.dx = plgpts[0].X - rect.X / rect.Width * pt1.X - rect.Y / rect.Height * pt2.X;
            this.dy = plgpts[0].Y - rect.X / rect.Width * pt1.Y - rect.Y / rect.Height * pt2.Y;
        }
コード例 #20
0
 public void InvalidateRect(SvgRectF rect)
 {
     if (invalidRect == SvgRectF.Empty)
         invalidRect = rect;
     else
         invalidRect.Intersect(rect);
 }
コード例 #21
0
 public void InvalidateRect(SvgRectF rect)
 {
     _invalidRect = rect;
 }
コード例 #22
0
 protected GdiRenderingBase(SvgElement element)
 {
     this.element      = element;
     this.screenRegion = SvgRectF.Empty;
 }
コード例 #23
0
 public void InvalidateRect(SvgRectF rect)
 {
 }
コード例 #24
0
 /// <summary>
 /// This converts the specified <see cref="Rect"/> structure to a
 /// <see cref="SvgRectF"/> structure.
 /// </summary>
 /// <param name="rect">The <see cref="Rect"/> structure to convert.</param>
 /// <returns>
 /// The <see cref="SvgRectF"/> structure that is converted from the
 /// specified <see cref="Rect"/> structure.
 /// </returns>
 public static Rect ToRect(SvgRectF rect)
 {
     return(new Rect(rect.X, rect.Y, rect.Width, rect.Height));
 }
コード例 #25
0
 /// <summary>
 /// This converts the specified <see cref="Rect"/> structure to a 
 /// <see cref="SvgRectF"/> structure.
 /// </summary>
 /// <param name="rect">The <see cref="Rect"/> structure to convert.</param>
 /// <returns>
 /// The <see cref="SvgRectF"/> structure that is converted from the 
 /// specified <see cref="Rect"/> structure.
 /// </returns>
 public static Rect ToRect(SvgRectF rect)
 {
     return new Rect(rect.X, rect.Y, rect.Width, rect.Height);
 }
コード例 #26
0
        public void OnRender(SvgRectF updatedRect)
        {
            if (surface != null)
            {
                if (updatedRect == SvgRectF.Empty)
                    Draw(surface);
                else
                    Draw(surface, GdiConverter.ToRectangle(updatedRect));
            }
            else
            {
                surface = CreateGraphics();

                UpdateGraphics(surface);

                if (updatedRect == SvgRectF.Empty)
                    Draw(surface);
                else
                    Draw(surface, GdiConverter.ToRectangle(updatedRect));
                surface.Dispose();
                surface = null;
            }

            // Collect the rendering regions for later updates
            //SvgDocument doc = (window.Document as SvgDocument);
            //SvgElement root = (doc.RootElement as SvgElement);
            //root.CacheRenderingRegion(renderer);
        }