예제 #1
0
        /// <summary>
        /// 获取渲染
        /// </summary>
        /// <returns>渲染</returns>
        public virtual Drawing GetDrawing()
        {
            Drawing drawing = this.GetBaseDrawing();

            if (drawing == null)
            {
                return(null);
            }

            SVGMask mask = this.GetAttributeValue <SVGMask>("mask");

            if (mask != null && mask.Value != null)
            {
                SVGTransform transform = this.GetAttributeValue <SVGTransform>("transform");

                DrawingGroup group = new DrawingGroup();
                group.OpacityMask = mask.Value;

                if (transform != null && transform.Value != null && transform.Value.Count > 0)
                {
                    TransformGroup transform_group = this.GetTransformGroup(group.OpacityMask);

                    foreach (Transform item in transform.Value)
                    {
                        transform_group.Children.Add(item);
                    }
                }

                group.Children.Add(drawing);
                drawing = group;
            }

            return(drawing);
        }
        /// <summary>
        /// 获取基础渲染
        /// </summary>
        /// <returns>基础渲染</returns>
        protected override Drawing GetBaseDrawing()
        {
            double       opacity   = this.GetAttributeValue <SVGDouble>("opacity", false, SVGDouble.One).GetValue(1);
            SVGTransform transform = this.GetAttributeValue <SVGTransform>("transform");

            DrawingGroup result = new DrawingGroup();

            result.Opacity = opacity;

            if (transform != null && transform.Value != null && transform.Value.Count > 0)
            {
                TransformGroup group = new TransformGroup();

                foreach (Transform item in transform.Value)
                {
                    group.Children.Add(item);
                }

                result.Transform = group;
            }

            foreach (SVGElement element in this.Children)
            {
                Drawing drawing = null;

                if (element is SVGDrawingContainerElement)
                {
                    drawing = (element as SVGDrawingContainerElement).GetDrawing();
                }
                else if (element is SVGDrawingElement)
                {
                    drawing = (element as SVGDrawingElement).GetDrawing();
                }

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

            return(result);
        }
예제 #3
0
        /// <summary>
        /// 获取几何图形
        /// </summary>
        /// <returns>几何图形</returns>
        public virtual Geometry GetGeometry()
        {
            SVGDisplay display = this.GetAttributeValue <SVGDisplay>("display");

            if (display == SVGDisplay.None)
            {
                return(null);
            }

            Geometry geometry = this.GetBaseGeometry();

            if (geometry == null)
            {
                return(null);
            }

            SVGTransform transform = this.GetAttributeValue <SVGTransform>("transform");

            if (transform != null && transform.Value != null && transform.Value.Count > 0)
            {
                TransformGroup group = this.GetTransformGroup(geometry);

                foreach (Transform item in transform.Value)
                {
                    group.Children.Add(item);
                }

                geometry.Transform = group;
            }

            SVGClipPath clip_path = this.GetAttributeValue <SVGClipPath>("clip-path");

            if (clip_path != null && clip_path.Value != null)
            {
                geometry = Geometry.Combine(geometry, clip_path.Value, GeometryCombineMode.Intersect, null);
            }

            return(geometry);
        }
예제 #4
0
        /// <summary>
        /// 获取画刷
        /// </summary>
        /// <returns>画刷</returns>
        private Brush GetBrush()
        {
            double           x1            = this.GetAttributeValue <SVGDouble>("x1", false, SVGDouble.Zero).GetValue(1);
            double           y1            = this.GetAttributeValue <SVGDouble>("y1", false, SVGDouble.Zero).GetValue(1);
            double           x2            = this.GetAttributeValue <SVGDouble>("x2", false, SVGDouble.One).GetValue(1);
            double           y2            = this.GetAttributeValue <SVGDouble>("y2", false, SVGDouble.Zero).GetValue(1);
            SVGGradientUnits gradientUnits = this.GetAttributeValue <SVGGradientUnits>("gradientUnits");
            SVGTransform     transform     = this.GetAttributeValue <SVGTransform>("gradientTransform");
            SVGSpreadMethod  spreadMethod  = this.GetAttributeValue <SVGSpreadMethod>("spreadMethod");

            LinearGradientBrush brush = new LinearGradientBrush();

            brush.StartPoint = new System.Windows.Point(x1, y1);
            brush.EndPoint   = new System.Windows.Point(x2, y2);

            foreach (SVGElement item in this.Children)
            {
                Stop stop = item as Stop;
                if (stop == null)
                {
                    continue;
                }

                double   offset  = stop.GetAttributeValue <SVGDouble>("offset").GetValue(1);
                double   opacity = stop.GetAttributeValue <SVGDouble>("stop-opacity", false, SVGDouble.One).GetValue(1);
                SVGColor color   = stop.GetAttributeValue <SVGColor>("stop-color");

                GradientStop gs = new GradientStop();
                gs.Offset = offset;

                if (color != null)
                {
                    Color c = color.Value;
                    c.A = (byte)(opacity * 255);

                    gs.Color = c;
                }

                brush.GradientStops.Add(gs);
            }

            if (transform != null && transform.Value != null && transform.Value.Count > 0)
            {
                TransformGroup group = new TransformGroup();
                foreach (Transform item in transform.Value)
                {
                    group.Children.Add(item);
                }

                brush.Transform = group;
            }

            if (gradientUnits != null)
            {
                brush.MappingMode = gradientUnits.Value;
            }

            if (spreadMethod != null)
            {
                brush.SpreadMethod = spreadMethod.Value;
            }

            return(brush);
        }
예제 #5
0
        /// <summary>
        /// 获取画刷
        /// </summary>
        /// <returns>画刷</returns>
        private Brush GetBrush()
        {
            double           cx            = this.GetAttributeValue <SVGDouble>("cx", false, new SVGDouble(0.5)).GetValue(1);
            double           cy            = this.GetAttributeValue <SVGDouble>("cy", false, new SVGDouble(0.5)).GetValue(1);
            double           fx            = this.GetAttributeValue <SVGDouble>("fx", false, new SVGDouble(0.5)).GetValue(1);
            double           fy            = this.GetAttributeValue <SVGDouble>("fy", false, new SVGDouble(0.5)).GetValue(1);
            double           r             = this.GetAttributeValue <SVGDouble>("r", false, new SVGDouble(0.5)).GetValue(1);
            SVGGradientUnits gradientUnits = this.GetAttributeValue <SVGGradientUnits>("gradientUnits");
            SVGTransform     transform     = this.GetAttributeValue <SVGTransform>("gradientTransform");
            SVGSpreadMethod  spreadMethod  = this.GetAttributeValue <SVGSpreadMethod>("spreadMethod");

            RadialGradientBrush brush = new RadialGradientBrush();

            brush.Center         = new System.Windows.Point(cx, cy);
            brush.RadiusX        = r;
            brush.RadiusY        = r;
            brush.GradientOrigin = new System.Windows.Point(fx, fy);

            foreach (SVGElement item in this.Children)
            {
                Stop stop = item as Stop;
                if (stop == null)
                {
                    continue;
                }

                double   offset  = stop.GetAttributeValue <SVGDouble>("offset").GetValue(1);
                double   opacity = stop.GetAttributeValue <SVGDouble>("stop-opacity", false, SVGDouble.One).GetValue(1);
                SVGColor color   = stop.GetAttributeValue <SVGColor>("stop-color");

                GradientStop gs = new GradientStop();
                gs.Offset = offset;

                if (color != null)
                {
                    Color c = color.Value;
                    c.A = (byte)(opacity * 255);

                    gs.Color = c;
                }

                brush.GradientStops.Add(gs);
            }

            if (transform != null && transform.Value != null && transform.Value.Count > 0)
            {
                TransformGroup group = new TransformGroup();
                foreach (Transform item in transform.Value)
                {
                    group.Children.Add(item);
                }

                brush.Transform = group;
            }

            if (gradientUnits != null)
            {
                brush.MappingMode = gradientUnits.Value;
            }

            if (spreadMethod != null)
            {
                brush.SpreadMethod = spreadMethod.Value;
            }

            return(brush);
        }