コード例 #1
0
        /// <summary>
        /// Generates a new <see cref="GdiRendering">GdiRendering</see> that
        /// corresponds to the given Uri.
        /// </summary>
        /// <param name="baseUri">
        /// The base Uri.
        /// </param>
        /// <param name="url">
        /// The url.
        /// </param>
        /// <returns>
        /// The generated <see cref="GdiRendering">GdiRendering</see> that
        /// corresponds to the given Uri.
        /// </returns>
        public static GdiRendering CreateByUri(SvgDocument document, string baseUri, string url)
        {
            url = url.Trim().Trim(new char[] { '\"', '\'' });
            if (url.StartsWith("#", StringComparison.OrdinalIgnoreCase))
            {
                // do nothing
            }
            else if (!string.IsNullOrWhiteSpace(baseUri))
            {
                Uri absoluteUri = new Uri(new Uri(baseUri), url);
                url = absoluteUri.AbsoluteUri;
            }
            else
            {
                // TODO: Handle xml:base here?
                // Right now just skip this... it can't be resolved, must assume it is absolute
            }
            var elm = document.GetNodeByUri(url) as SvgElement;

            if (elm != null)
            {
                return(GdiRendering.Create(elm));
            }
            return(null);
        }
コード例 #2
0
        private void RenderElement(ISvgElement svgElement)
        {
            bool isNotRenderable = !svgElement.IsRenderable || string.Equals(svgElement.LocalName, "a");

            if (isNotRenderable)
            {
                return;
            }

            GdiRenderingBase renderingNode = GdiRendering.Create(svgElement);

            if (renderingNode == null)
            {
                return;
            }

            if (!renderingNode.NeedRender(_renderer))
            {
                renderingNode.Dispose();
                renderingNode = null;
                return;
            }

            bool shouldRender            = true;
            SvgStyleableElement stylable = svgElement as SvgStyleableElement;

            if (stylable != null)
            {
                string sVisibility = stylable.GetPropertyValue("visibility");
                string sDisplay    = stylable.GetPropertyValue("display");
                if (string.Equals(sVisibility, "hidden") || string.Equals(sDisplay, "none"))
                {
                    shouldRender = false;
                }
            }

            if (shouldRender)
            {
                //_rendererMap[svgElement] = renderingNode;
                _rendererMap.Push(renderingNode);
                renderingNode.BeforeRender(_renderer);

                renderingNode.Render(_renderer);

                if (!renderingNode.IsRecursive && svgElement.HasChildNodes)
                {
                    RenderChildren(svgElement);
                }

                //renderingNode = _rendererMap[svgElement];
                renderingNode = _rendererMap.Pop();
                Debug.Assert(renderingNode.Element == svgElement);
                renderingNode.AfterRender(_renderer);

                //_rendererMap.Remove(svgElement);
            }

            renderingNode.Dispose();
            renderingNode = null;
        }
コード例 #3
0
        public void DrawImage(GdiRendering grNode, Image image, Rectangle destRect,
                              float srcX, float srcY, float srcWidth, float srcHeight,
                              GraphicsUnit graphicsUnit, ImageAttributes imageAttributes)
        {
            if (_idMapGraphics != null)
            {
                // This handles pointer-events for visibleFill visibleStroke and visible

                /*Brush idBrush = new SolidBrush(grNode.UniqueColor);
                 * GraphicsPath gp = new GraphicsPath();
                 * gp.AddRectangle(destRect);
                 * _idMapGraphics.FillPath(idBrush, gp);*/
                Color       unique      = grNode.UniqueColor;
                float       r           = (float)unique.R / 255;
                float       g           = (float)unique.G / 255;
                float       b           = (float)unique.B / 255;
                ColorMatrix colorMatrix = new ColorMatrix(
                    new float[][] { new float[] { 0f, 0f, 0f, 0f, 0f },
                                    new float[] { 0f, 0f, 0f, 0f, 0f },
                                    new float[] { 0f, 0f, 0f, 0f, 0f },
                                    new float[] { 0f, 0f, 0f, 1f, 0f },
                                    new float[] { r, g, b, 0f, 1f } });
                ImageAttributes ia = new ImageAttributes();
                ia.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
                _idMapGraphics.DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, graphicsUnit, ia);
            }
            _graphics.DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, graphicsUnit, imageAttributes);
        }
コード例 #4
0
        private void RenderElementAs(SvgElement svgElement)
        {
            GdiRenderingBase renderingNode = GdiRendering.Create(svgElement);

            if (renderingNode == null)
            {
                return;
            }

            if (!renderingNode.NeedRender(_renderer))
            {
                //renderingNode.Dispose();
                //renderingNode = null;
                return;
            }

            _rendererMap[svgElement.UniqueId] = renderingNode;
            renderingNode.BeforeRender(_renderer);

            renderingNode.Render(_renderer);

            if (!renderingNode.IsRecursive && svgElement.HasChildNodes)
            {
                RenderChildren(svgElement);
            }

            renderingNode = _rendererMap[svgElement.UniqueId];
            renderingNode.AfterRender(_renderer);

            _rendererMap.Remove(svgElement.UniqueId);

            //renderingNode.Dispose();
            //renderingNode = null;
        }
コード例 #5
0
        /// <summary>
        /// Generates a new <see cref="GdiRendering">GdiRendering</see> that
        /// corresponds to the given Uri.
        /// </summary>
        /// <param name="baseUri">
        /// The base Uri.
        /// </param>
        /// <param name="url">
        /// The url.
        /// </param>
        /// <returns>
        /// The generated <see cref="GdiRendering">GdiRendering</see> that
        /// corresponds to the given Uri.
        /// </returns>
        public static GdiRendering CreateByUri(SvgDocument document, string baseUri, string url)
        {
            if (url.StartsWith("#", StringComparison.OrdinalIgnoreCase))
            {
                // do nothing
            }
            else if (baseUri != "")
            {
                Uri absoluteUri = new Uri(new Uri(baseUri), url);
                url = absoluteUri.AbsoluteUri;
            }
            else
            {
                // TODO: Handle xml:base here?
                // Right now just skip this... it can't be resolved, must assume it is absolute
            }
            ISvgElement elm = document.GetNodeByUri(url) as ISvgElement;

            if (elm != null)
            {
                return(GdiRendering.Create(elm));
            }
            else
            {
                return(null);
            }
        }
コード例 #6
0
 public override void DrawPath(GdiRendering grNode, Pen pen, GraphicsPath path)
 {
     if (_listenerGraphics != null)
     {
         _listenerGraphics.DrawPath(grNode, pen, path);
     }
     _graphics.DrawPath(pen, path);
 }
コード例 #7
0
 public override void FillPath(GdiRendering grNode, Brush brush, GraphicsPath path)
 {
     if (_listenerGraphics != null)
     {
         _listenerGraphics.FillPath(grNode, brush, path);
     }
     _graphics.FillPath(brush, path);
 }
コード例 #8
0
 public override void DrawPath(GdiRendering grNode, Pen pen, GraphicsPath path)
 {
     if (_graphics != null)
     {
         Pen idPen = new Pen(grNode.UniqueColor, pen.Width);
         _graphics.DrawPath(idPen, path);
     }
 }
コード例 #9
0
 public override void DrawImage(GdiRendering grNode, Image image, Rectangle destRect,
                                float srcX, float srcY, float srcWidth, float srcHeight,
                                GraphicsUnit graphicsUnit, ImageAttributes imageAttributes)
 {
     if (_listenerGraphics != null)
     {
         _listenerGraphics.DrawImage(grNode, image, destRect, srcX, srcY, srcWidth,
                                     srcHeight, graphicsUnit, imageAttributes);
     }
     _graphics.DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, graphicsUnit, imageAttributes);
 }
コード例 #10
0
 public override void FillPath(GdiRendering grNode, Brush brush, GraphicsPath path)
 {
     if (_graphics != null)
     {
         Brush idBrush = new SolidBrush(grNode.UniqueColor);
         if (grNode.Element is SvgTextContentElement)
         {
             _graphics.FillRectangle(idBrush, path.GetBounds());
         }
         else
         {
             _graphics.FillPath(idBrush, path);
         }
     }
 }
コード例 #11
0
        private void RenderElement(ISvgElement svgElement)
        {
            bool isNotRenderable = !svgElement.IsRenderable || String.Equals(svgElement.LocalName, "a");

            if (isNotRenderable)
            {
                return;
            }

            GdiRenderingBase renderingNode = GdiRendering.Create(svgElement);

            if (renderingNode == null)
            {
                return;
            }

            if (!renderingNode.NeedRender(_renderer))
            {
                renderingNode.Dispose();
                renderingNode = null;
                return;
            }

            //_rendererMap[svgElement] = renderingNode;
            _rendererMap.Push(renderingNode);
            renderingNode.BeforeRender(_renderer);

            renderingNode.Render(_renderer);

            if (!renderingNode.IsRecursive && svgElement.HasChildNodes)
            {
                RenderChildren(svgElement);
            }

            //renderingNode = _rendererMap[svgElement];
            renderingNode = _rendererMap.Pop();
            Debug.Assert(renderingNode.Element == svgElement);
            renderingNode.AfterRender(_renderer);

            //_rendererMap.Remove(svgElement);

            renderingNode.Dispose();
            renderingNode = null;
        }
コード例 #12
0
 public override void DrawImage(GdiRendering grNode, Image image, Rectangle destRect,
                                float srcX, float srcY, float srcWidth, float srcHeight,
                                GraphicsUnit graphicsUnit, ImageAttributes imageAttributes)
 {
     if (_graphics != null)
     {
         // This handles pointer-events for visibleFill visibleStroke and visible
         Color       unique      = grNode.UniqueColor;
         float       r           = (float)unique.R / 255;
         float       g           = (float)unique.G / 255;
         float       b           = (float)unique.B / 255;
         ColorMatrix colorMatrix = new ColorMatrix(new float[][] {
             new float[] { 0f, 0f, 0f, 0f, 0f },
             new float[] { 0f, 0f, 0f, 0f, 0f },
             new float[] { 0f, 0f, 0f, 0f, 0f },
             new float[] { 0f, 0f, 0f, 1f, 0f },
             new float[] { r, g, b, 0f, 1f }
         });
         ImageAttributes ia = new ImageAttributes();
         ia.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
         _graphics.DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, graphicsUnit, ia);
     }
 }
コード例 #13
0
ファイル: GdiGraphics.cs プロジェクト: zellus/SharpVectors
 public abstract void DrawPath(GdiRendering grNode, Pen pen, GraphicsPath path);
コード例 #14
0
 public void FillPath(GdiRendering grNode, Brush brush, GraphicsPath path)
 {
     if (_idMapGraphics != null)
     {
         Brush idBrush = new SolidBrush(grNode.UniqueColor);
         if (grNode.Element is SvgTextContentElement)
         {
             _idMapGraphics.FillRectangle(idBrush, path.GetBounds());
         }
         else
         {
             _idMapGraphics.FillPath(idBrush, path);
         }
     }
     _graphics.FillPath(brush, path);
 }
コード例 #15
0
ファイル: GdiGraphics.cs プロジェクト: zellus/SharpVectors
 public abstract void FillPath(GdiRendering grNode, Brush brush, GraphicsPath path);
コード例 #16
0
 public void DrawImage(GdiRendering grNode, Image image, Rectangle destRect, 
     float srcX, float srcY, float srcWidth, float srcHeight, 
     GraphicsUnit graphicsUnit, ImageAttributes imageAttributes)
 {
     if (_idMapGraphics != null)
     {
         // This handles pointer-events for visibleFill visibleStroke and visible
         /*Brush idBrush = new SolidBrush(grNode.UniqueColor);
         GraphicsPath gp = new GraphicsPath();
         gp.AddRectangle(destRect);
         _idMapGraphics.FillPath(idBrush, gp);*/
         Color unique = grNode.UniqueColor;
         float r = (float)unique.R / 255;
         float g = (float)unique.G / 255;
         float b = (float)unique.B / 255;
         ColorMatrix colorMatrix = new ColorMatrix(
           new float[][] { new float[] {0f, 0f, 0f, 0f, 0f},
                   new float[] {0f, 0f, 0f, 0f, 0f},
                   new float[] {0f, 0f, 0f, 0f, 0f},
                   new float[] {0f, 0f, 0f, 1f, 0f},
                   new float[] {r,  g,  b,  0f, 1f} });
         ImageAttributes ia = new ImageAttributes();
         ia.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
         _idMapGraphics.DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, graphicsUnit, ia);
     }
     _graphics.DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, graphicsUnit, imageAttributes);
 }
コード例 #17
0
 public void DrawPath(GdiRendering grNode, Pen pen, GraphicsPath path)
 {
     if (_idMapGraphics != null)
     {
         Pen idPen = new Pen(grNode.UniqueColor, pen.Width);
         _idMapGraphics.DrawPath(idPen, path);
     }
     _graphics.DrawPath(pen, path);
 }
コード例 #18
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);
        }
コード例 #19
0
ファイル: GdiGraphics.cs プロジェクト: zellus/SharpVectors
 public abstract void DrawImage(GdiRendering grNode, Image image, Rectangle destRect,
                                float srcX, float srcY, float srcWidth, float srcHeight,
                                GraphicsUnit graphicsUnit, ImageAttributes imageAttributes);
コード例 #20
0
        private void RenderElement(ISvgElement svgElement)
        {
            bool isNotRenderable = !svgElement.IsRenderable || string.Equals(svgElement.LocalName, "a");

            if (isNotRenderable)
            {
                return;
            }
            SvgElement currentElement = (SvgElement)svgElement;

            GdiRenderingBase renderingNode = GdiRendering.Create(currentElement);

            if (renderingNode == null)
            {
                return;
            }

            if (!renderingNode.NeedRender(_renderer))
            {
                renderingNode.Dispose();
                renderingNode = null;
                return;
            }
            var comparer = StringComparison.OrdinalIgnoreCase;

            bool shouldRender            = true;
            SvgStyleableElement stylable = svgElement as SvgStyleableElement;

            if (stylable != null)
            {
                string sVisibility = stylable.GetPropertyValue(CssConstants.PropVisibility);
                string sDisplay    = stylable.GetPropertyValue(CssConstants.PropDisplay);
                if (string.Equals(sVisibility, CssConstants.ValHidden, comparer) ||
                    string.Equals(sDisplay, CssConstants.ValNone, comparer))
                {
                    shouldRender = false;
                }
            }

            if (shouldRender)
            {
                //_rendererMap[svgElement] = renderingNode;
                //                _rendererMap.Push(renderingNode);

                if (_rendererMap.ContainsKey(currentElement.UniqueId))
                {
                    // Might be circular rendering...
                    //                System.Diagnostics.Debug.WriteLine("Circular Object: " + currentElement.LocalName);
                    return;
                }

                _rendererMap[currentElement.UniqueId] = renderingNode;
                renderingNode.BeforeRender(_renderer);

                renderingNode.Render(_renderer);

                if (!renderingNode.IsRecursive && svgElement.HasChildNodes)
                {
                    RenderChildren(svgElement);
                }

                //renderingNode = _rendererMap[svgElement];
                renderingNode = _rendererMap[currentElement.UniqueId];
//                renderingNode = _rendererMap.Pop();
                Debug.Assert(renderingNode.Element == svgElement);
                renderingNode.AfterRender(_renderer);

                _rendererMap.Remove(currentElement.UniqueId);

                //_rendererMap.Remove(svgElement);
            }

            renderingNode.Dispose();
            renderingNode = null;
        }
コード例 #21
0
ファイル: GdiGraphics.cs プロジェクト: zellus/SharpVectors
 public void DrawImage(GdiRendering grNode, Image image, RectangleF destRect,
                       RectangleF srcRect, GraphicsUnit graphicsUnit, ImageAttributes imageAttributes)
 {
     this.DrawImage(grNode, image, destRect.Snap(),
                    srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, graphicsUnit, imageAttributes);
 }