Exemplo n.º 1
0
        public override void BeforeRender(WpfDrawingRenderer renderer)
        {
            base.BeforeRender(renderer);

            _isAggregated = false;

            if (_svgElement.FirstChild == _svgElement.LastChild)
            {
                SvgGElement gElement = _svgElement.FirstChild as SvgGElement;
                if (gElement != null)
                {
                    string elementId = gElement.GetAttribute("id");
                    if (!string.IsNullOrWhiteSpace(elementId) &&
                        string.Equals(elementId, "IndicateLayer", StringComparison.OrdinalIgnoreCase))
                    {
                        WpfDrawingContext context = renderer.Context;

                        DrawingGroup animationGroup = context.Links;
                        if (animationGroup != null)
                        {
                            context.Push(animationGroup);
                        }

                        _isLayer = true;
                    }
                }
            }
        }
Exemplo n.º 2
0
        public override void Render(WpfDrawingRenderer renderer)
        {
            if (_drawGroup != null)
            {
                Geometry clipGeom = this.ClipGeometry;
                if (clipGeom != null)
                {
                    _drawGroup.ClipGeometry = clipGeom;
                }

                Transform transform = this.Transform;
                if (transform != null)
                {
                    _drawGroup.Transform = transform;
                }

                float opacityValue = -1;

                SvgGElement element = (SvgGElement)_svgElement;
                string      opacity = element.GetAttribute("opacity");
                if (opacity != null && opacity.Length > 0)
                {
                    opacityValue = (float)SvgNumber.ParseNumber(opacity);
                    opacityValue = Math.Min(opacityValue, 1);
                    opacityValue = Math.Max(opacityValue, 0);
                }

                if (opacityValue >= 0)
                {
                    _drawGroup.Opacity = opacityValue;
                }
            }

            base.Render(renderer);
        }
Exemplo n.º 3
0
        public override void VisitGElement(SvgGElement element)
        {
            var oldMatrix = activeMatrix;

            activeMatrix = CalulateUpdatedMatrix(element);
            base.VisitGElement(element);

            activeMatrix = oldMatrix;
        }
Exemplo n.º 4
0
 public void SetUp()
 {
     if (doc == null)
     {
         SvgWindow wnd = new SvgWindow(100, 100, null);
         doc = new SvgDocument(wnd);
         doc.Load("events_01.svg");
         rect = (SvgRectElement)doc.SelectSingleNode("//*[local-name()='rect']");
         g    = (SvgGElement)doc.SelectSingleNode("//*[local-name()='g']");
     }
     eventStatus = 0;
 }
        public override void Render(WpfDrawingRenderer renderer)
        {
            if (_drawGroup != null)
            {
                Geometry clipGeom = this.ClipGeometry;
                if (clipGeom != null)
                {
                    _drawGroup.ClipGeometry = clipGeom;
                }

                Transform transform = this.Transform;
                if (transform != null)
                {
                    _drawGroup.Transform = transform;
                }

                float opacityValue = -1;

                SvgGElement element = (SvgGElement)_svgElement;
                string      opacity = element.GetAttribute("opacity");
                if (string.IsNullOrWhiteSpace(opacity))
                {
                    opacity = element.GetPropertyValue("opacity");
                }
                if (!string.IsNullOrWhiteSpace(opacity))
                {
                    opacityValue = (float)SvgNumber.ParseNumber(opacity);
                    opacityValue = Math.Min(opacityValue, 1);
                    opacityValue = Math.Max(opacityValue, 0);
                }

                if (opacityValue >= 0 && opacityValue < 1)
                {
                    _drawGroup.Opacity = opacityValue;
                }

                string sVisibility = element.GetPropertyValue("visibility");
                string sDisplay    = element.GetPropertyValue("display");
                if (string.Equals(sVisibility, "hidden") || string.Equals(sDisplay, "none"))
                {
                    _drawGroup.Opacity = 0;
                }
            }

            // Register this drawing with the Drawing-Document...
            this.Rendered(_drawGroup);

            base.Render(renderer);
        }
Exemplo n.º 6
0
        public override PageElement VisitGElement(SvgGElement element)
        {
            if (!IsVisible(element))
            {
                return(null);
            }

            var ownOpacity = element.PresentationStyleData.FillOpacity;

            if (ownOpacity != null)
            {
                var oldGAlpha = _groupAlpha;
                _groupAlpha *= ownOpacity.Value;
                var result = new TransparencyGroup(_groupAlpha)
                {
                    VisitStructuralElement(element)
                };
                _groupAlpha = oldGAlpha;
                return(result);
            }

            return(VisitStructuralElement(element));
        }
Exemplo n.º 7
0
        private void AggregateChildren(SvgAElement aElement, WpfDrawingContext context, float opacity)
        {
            _isAggregated = false;

            if (aElement == null || aElement.ChildNodes == null)
            {
                return;
            }

            string aggregatedFill = aElement.GetAttribute("fill");
            bool   isFillFound    = !String.IsNullOrEmpty(aggregatedFill);

            SvgStyleableElement paintElement = null;

            if (isFillFound)
            {
                paintElement = aElement;
            }

            XmlNode targetNode = aElement;

            // Check if the children of the link are wrapped in a Group Element...
            if (aElement.ChildNodes.Count == 1)
            {
                SvgGElement groupElement = aElement.ChildNodes[0] as SvgGElement;
                if (groupElement != null)
                {
                    targetNode = groupElement;
                }
            }

            WpfDrawingSettings settings = context.Settings;

            GeometryCollection geomColl = new GeometryCollection();

            foreach (XmlNode node in targetNode.ChildNodes)
            {
                if (node.NodeType != XmlNodeType.Element)
                {
                    continue;
                }

                // Handle a case where the clip element has "use" element as a child...
                if (String.Equals(node.LocalName, "use"))
                {
                    SvgUseElement useElement = (SvgUseElement)node;

                    XmlElement refEl = useElement.ReferencedElement;
                    if (refEl != null)
                    {
                        XmlElement refElParent = (XmlElement)refEl.ParentNode;
                        useElement.OwnerDocument.Static = true;
                        useElement.CopyToReferencedElement(refEl);
                        refElParent.RemoveChild(refEl);
                        useElement.AppendChild(refEl);

                        foreach (XmlNode useChild in useElement.ChildNodes)
                        {
                            if (useChild.NodeType != XmlNodeType.Element)
                            {
                                continue;
                            }

                            SvgStyleableElement element = useChild as SvgStyleableElement;
                            if (element != null && element.RenderingHint == SvgRenderingHint.Shape)
                            {
                                Geometry childPath = WpfRendering.CreateGeometry(element,
                                                                                 settings.OptimizePath);

                                if (childPath != null)
                                {
                                    if (isFillFound)
                                    {
                                        string elementFill = element.GetAttribute("fill");
                                        if (!String.IsNullOrEmpty(elementFill) &&
                                            !String.Equals(elementFill, aggregatedFill, StringComparison.OrdinalIgnoreCase))
                                        {
                                            return;
                                        }
                                    }
                                    else
                                    {
                                        aggregatedFill = element.GetAttribute("fill");
                                        isFillFound    = !String.IsNullOrEmpty(aggregatedFill);
                                        if (isFillFound)
                                        {
                                            paintElement = element;
                                        }
                                    }

                                    geomColl.Add(childPath);
                                }
                            }
                        }

                        useElement.RemoveChild(refEl);
                        useElement.RestoreReferencedElement(refEl);
                        refElParent.AppendChild(refEl);
                        useElement.OwnerDocument.Static = false;
                    }
                }
                //else if (String.Equals(node.LocalName, "g"))
                //{
                //}
                else
                {
                    SvgStyleableElement element = node as SvgStyleableElement;
                    if (element != null && element.RenderingHint == SvgRenderingHint.Shape)
                    {
                        Geometry childPath = WpfRendering.CreateGeometry(element,
                                                                         settings.OptimizePath);

                        if (childPath != null)
                        {
                            if (isFillFound)
                            {
                                string elementFill = element.GetAttribute("fill");
                                if (!String.IsNullOrEmpty(elementFill) &&
                                    !String.Equals(elementFill, aggregatedFill, StringComparison.OrdinalIgnoreCase))
                                {
                                    return;
                                }
                            }
                            else
                            {
                                aggregatedFill = element.GetAttribute("fill");
                                isFillFound    = !String.IsNullOrEmpty(aggregatedFill);
                                if (isFillFound)
                                {
                                    paintElement = element;
                                }
                            }

                            geomColl.Add(childPath);
                        }
                    }
                }
            }

            if (geomColl.Count == 0 || paintElement == null)
            {
                return;
            }

            _aggregatedFill = paintElement;
            _aggregatedGeom = geomColl;

            _isAggregated = true;
        }
Exemplo n.º 8
0
 public virtual void VisitGElement(SvgGElement element)
 => DefaultVisit(element);
Exemplo n.º 9
0
        public override void Render(WpfDrawingRenderer renderer)
        {
            if (_drawGroup != null)
            {
                Geometry clipGeom = this.ClipGeometry;
                if (clipGeom != null)
                {
                    _drawGroup.ClipGeometry = clipGeom;
                }

                Transform transform = this.Transform;
                if (transform != null)
                {
                    _drawGroup.Transform = transform;
                }

                float opacityValue = -1;

                SvgGElement element = (SvgGElement)_svgElement;
                string      opacity = element.GetAttribute("opacity");
                if (string.IsNullOrWhiteSpace(opacity))
                {
                    opacity = element.GetPropertyValue("opacity");
                }
                if (!string.IsNullOrWhiteSpace(opacity))
                {
                    opacityValue = (float)SvgNumber.ParseNumber(opacity);
                    opacityValue = Math.Min(opacityValue, 1);
                    opacityValue = Math.Max(opacityValue, 0);
                }

                if (opacityValue >= 0 && opacityValue < 1)
                {
                    _drawGroup.Opacity = opacityValue;
                }

                string sVisibility = element.GetPropertyValue("visibility");
                string sDisplay    = element.GetPropertyValue("display");
                if (string.Equals(sVisibility, "hidden", StringComparison.OrdinalIgnoreCase))
                {
                    var isOverriden = false;
                    foreach (XmlNode child in element.ChildNodes)
                    {
                        if (child.NodeType == XmlNodeType.Element)
                        {
                            var svgElem = child as SvgElement;
                            if (svgElem != null && string.Equals(svgElem.GetAttribute("visibility"),
                                                                 "visible", StringComparison.OrdinalIgnoreCase))
                            {
                                isOverriden = true;
                                break;
                            }
                        }
                    }

                    if (!isOverriden)
                    {
                        _drawGroup.Opacity = 0;
                    }
                }
                else if (string.Equals(sDisplay, "none", StringComparison.OrdinalIgnoreCase))
                {
                    _drawGroup.Opacity = 0;
                }
            }

            // Register this drawing with the Drawing-Document...
            this.Rendered(_drawGroup);

            base.Render(renderer);
        }
 public override void VisitGElement(SvgGElement element)
 => VisitStructuralElement(element);