GetClipGeometry() public method

public GetClipGeometry ( ) : System.Windows.Media.Geometry
return System.Windows.Media.Geometry
        //==========================================================================
        public virtual Geometry GetGeometry()
        {
            GeometryGroup geometry_group = new GeometryGroup();

            foreach (SvgBaseElement element in Children)
            {
                if (element is SvgDrawableBaseElement)
                {
                    geometry_group.Children.Add((element as SvgDrawableBaseElement).GetGeometry());
                }
                else if (element is SvgDrawableContainerBaseElement)
                {
                    geometry_group.Children.Add((element as SvgDrawableContainerBaseElement).GetGeometry());
                }
            }

            if (Transform != null)
            {
                geometry_group.Transform = Transform.ToTransform();
            }

            if (ClipPath != null)
            {
                SvgClipPathElement clip_path_element = Document.Elements[ClipPath.Id] as SvgClipPathElement;
                if (clip_path_element != null)
                {
                    return(Geometry.Combine(geometry_group, clip_path_element.GetClipGeometry(), GeometryCombineMode.Exclude, null));
                }
            }

            return(geometry_group);
        }
        //==========================================================================
        public virtual Drawing Draw()
        {
            DrawingGroup drawing_group = new DrawingGroup();

            drawing_group.Opacity = Opacity.ToDouble();
            if (Transform != null)
            {
                drawing_group.Transform = Transform.ToTransform();
            }

            if (ViewBox != null)
            {
                drawing_group.Children.Add(ViewBox.Process());
            }

            foreach (SvgBaseElement child_element in Children)
            {
                SvgBaseElement element = child_element;
                if (element is SvgUseElement)
                {
                    element = (element as SvgUseElement).GetElement();
                }

                Drawing drawing = null;

                if (element is SvgDrawableBaseElement)
                {
                    if ((element as SvgDrawableBaseElement).Display != SvgDisplay.None)
                    {
                        drawing = (element as SvgDrawableBaseElement).Draw();
                    }
                }
                else if (element is SvgDrawableContainerBaseElement)
                {
                    if ((element as SvgDrawableContainerBaseElement).Display != SvgDisplay.None)
                    {
                        drawing = (element as SvgDrawableContainerBaseElement).Draw();
                    }
                }

                if (drawing != null)
                {
                    drawing_group.Children.Add(drawing);
                }
            }

            if (Filter != null)
            {
                SvgFilterElement filter_element = Document.Elements[Filter.Id] as SvgFilterElement;
                if (filter_element != null)
                {
                    drawing_group.BitmapEffect = filter_element.ToBitmapEffect();
                }
            }

            if (ClipPath != null)
            {
                SvgClipPathElement clip_path_element = Document.Elements[ClipPath.Id] as SvgClipPathElement;
                if (clip_path_element != null)
                {
                    drawing_group.ClipGeometry = clip_path_element.GetClipGeometry();
                }
            }

            if (Mask != null)
            {
                SvgMaskElement mask_element = Document.Elements[Mask.Id] as SvgMaskElement;
                if (mask_element != null)
                {
                    DrawingBrush opacity_mask = mask_element.GetOpacityMask();

                    /*
                     * if(Transform != null)
                     * opacity_mask.Transform = Transform.ToTransform();
                     */
                    drawing_group.OpacityMask = opacity_mask;
                }
            }

            return(drawing_group);
        }
        //==========================================================================
        public override Drawing Draw()
        {
            DrawingGroup drawing_group = new DrawingGroup();

            drawing_group.Opacity = Opacity.ToDouble();
            if (Transform != null)
            {
                drawing_group.Transform = Transform.ToTransform();
            }

            foreach (SvgBaseElement element in Children)
            {
                Drawing drawing = null;

                if (element is SvgDrawableBaseElement)
                {
                    drawing = (element as SvgDrawableBaseElement).Draw();
                }
                else if (element is SvgDrawableContainerBaseElement)
                {
                    drawing = (element as SvgDrawableContainerBaseElement).Draw();
                }

                if (drawing != null)
                {
                    drawing_group.Children.Add(drawing);
                }
            }

            if (Filter != null)
            {
                SvgFilterElement filter_element = Document.Elements[Filter.Id] as SvgFilterElement;
                if (filter_element != null)
                {
                    drawing_group.BitmapEffect = filter_element.ToBitmapEffect();
                }
            }

            if (ClipPath != null)
            {
                SvgClipPathElement clip_path_element = Document.Elements[ClipPath.Id] as SvgClipPathElement;
                if (clip_path_element != null)
                {
                    drawing_group.ClipGeometry = clip_path_element.GetClipGeometry();
                }
            }

            if (Mask != null)
            {
                SvgMaskElement mask_element = Document.Elements[Mask.Id] as SvgMaskElement;
                if (mask_element != null)
                {
                    drawing_group.OpacityMask = mask_element.GetOpacityMask();

                    GeometryGroup geometry_group = new GeometryGroup();

                    if (drawing_group.ClipGeometry != null)
                    {
                        geometry_group.Children.Add(drawing_group.ClipGeometry);
                    }

                    geometry_group.Children.Add(mask_element.GetClipGeometry());
                    drawing_group.ClipGeometry = geometry_group;
                }
            }

            return(drawing_group);
        }
Beispiel #4
0
        //==========================================================================
        public virtual Drawing Draw()
        {
            DrawingGroup drawing_group = new DrawingGroup();

            drawing_group.Opacity = Opacity.ToDouble();
            if (Transform != null)
            {
                drawing_group.Transform = Transform.ToTransform();
            }

            //if (ViewBox != null)
            //    drawing_group.Children.Add(ViewBox.Process());

            foreach (SvgBaseElement child_element in Children)
            {
                SvgBaseElement element = child_element;
                if (element is SvgUseElement)
                {
                    element = (element as SvgUseElement).GetElement();
                }

                Drawing drawing = null;

                if (element is SvgDrawableBaseElement)
                {
                    if ((element as SvgDrawableBaseElement).Display != SvgDisplay.None)
                    {
                        drawing = (element as SvgDrawableBaseElement).Draw();
                    }
                }
                else if (element is SvgDrawableContainerBaseElement)
                {
                    if ((element as SvgDrawableContainerBaseElement).Display != SvgDisplay.None)
                    {
                        drawing = (element as SvgDrawableContainerBaseElement).Draw();
                    }
                }

                if (drawing != null)
                {
                    drawing_group.Children.Add(drawing);
                }
            }

            if (Filter != null)
            {
                SvgFilterElement filter_element = Document.Elements[Filter.Id] as SvgFilterElement;
                if (filter_element != null)
                {
                    drawing_group.BitmapEffect = filter_element.ToBitmapEffect();
                }
            }

            if (ClipPath != null)
            {
                SvgClipPathElement clip_path_element = Document.Elements[ClipPath.Id] as SvgClipPathElement;
                if (clip_path_element != null)
                {
                    drawing_group.ClipGeometry = clip_path_element.GetClipGeometry();
                }
            }

            if (Mask != null)
            {
                SvgMaskElement mask_element = Document.Elements[Mask.Id] as SvgMaskElement;
                if (mask_element != null)
                {
                    DrawingBrush opacity_mask = mask_element.GetOpacityMask();

                    /*
                     * if(Transform != null)
                     * opacity_mask.Transform = Transform.ToTransform();
                     */
                    drawing_group.OpacityMask = opacity_mask;
                }
            }

            // add base element size
            if (this is SvgSVGElement)
            {
                var svg = this as SvgSVGElement;

                DrawingVisual  visual = new DrawingVisual();
                DrawingContext dc     = visual.RenderOpen();

                Rect rect = new Rect(new System.Windows.Point(0, 0), new System.Windows.Size(svg.Width.Value, svg.Height.Value));
                dc.DrawRectangle(System.Windows.Media.Brushes.Transparent, (System.Windows.Media.Pen)null, rect);
                dc.Close();

                drawing_group.Children.Add(visual.Drawing);
            }

            return(drawing_group);
        }