/// <summary> /// 获取蒙版 /// </summary> /// <returns>蒙版</returns> private DrawingBrush GetOpacityMask() { if (this.Children.Count == 0) { return(null); } DrawingGroup group = new DrawingGroup(); foreach (SVGElement item in this.Children) { Drawing drawing = null; if (item is SVGDrawingContainerElement) { drawing = (item as SVGDrawingContainerElement).GetDrawing(); } else if (item is SVGDrawingElement) { drawing = (item as SVGDrawingElement).GetDrawing(); } if (drawing != null) { group.Children.Add(drawing); } } if (group.Children.Count == 0) { return(null); } foreach (Drawing drawing in group.Children) { ConvertColors(drawing); } DrawingBrush result = new DrawingBrush(group); SVGGradientUnits mask_units = this.GetAttributeValue <SVGGradientUnits>("maskUnits"); if (mask_units != null && mask_units == SVGGradientUnits.UserSpaceOnUse) { result.ViewportUnits = mask_units.Value; result.Viewport = group.Bounds; } return(result); }
/// <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); }
/// <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); }