示例#1
0
        //==========================================================================
        public DrawingBrush?GetOpacityMask()
        {
            var drawing_group = new DrawingGroup();

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

                var drawing = element switch
                {
                    SvgDrawableBaseElement drawable_base_element => drawable_base_element.Draw(),
                    SvgDrawableContainerBaseElement base_element => base_element.Draw(),
                    _ => null
                };

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

            if (drawing_group.Children.Count == 0)
            {
                return(null);
            }

            foreach (var drawing in drawing_group.Children)
            {
                ConvertColors(drawing);
            }


            var brush = new DrawingBrush(drawing_group);

            if (MaskUnits != SvgMaskUnits.UserSpaceOnUse)
            {
                return(brush);
            }
            brush.ViewportUnits = BrushMappingMode.Absolute;
            brush.Viewport      = drawing_group.Bounds;

            return(brush);
        }
    } // class SvgMaskElement
示例#2
0
        //==========================================================================
        public override Drawing Draw()
        {
            var drawing_group = new DrawingGroup {
                Opacity = Opacity.ToDouble()
            };

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

            foreach (var element in Children)
            {
                var drawing = element switch
                {
                    SvgDrawableBaseElement base_element => base_element.Draw(),
                    SvgDrawableContainerBaseElement base_element => base_element.Draw(),
                         _ => null
                };

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

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

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

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

                    var 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);
        }
    } // class SvgFlowRootElement