private Color?GetNodeColor(ISvgElement targetNode, string property) { //StyleColor fillColor = new StyleColor(); //fillColor.FillType = ColorFillType.Solid; string szRGB = null; string szOpacity = null; string szNodeopacity = null; if (targetNode.RenderingHint == SvgRenderingHint.Text || targetNode.RenderingHint == SvgRenderingHint.Shape) { szRGB = (targetNode as SvgElement).GetComputedStyle("").GetPropertyValue(property); szOpacity = (targetNode as SvgElement).GetComputedStyle("").GetPropertyValue(property + @"-opacity"); szNodeopacity = (targetNode as SvgElement).GetComputedStyle("").GetPropertyValue("opacity"); if (string.IsNullOrEmpty(szRGB)) { return(null); } } //Get RGB Color SvgPaint paint = new SvgPaint(szRGB); if (paint.RgbColor == null) { return(null); } Color?solidColor = WpfConvert.ToColor(paint.RgbColor); if (solidColor == null) { return(null); } //Get Aplha Color result = solidColor.Value; if (szNodeopacity != null || szOpacity != null) { double opacityValue = 1; if (szNodeopacity != null && szNodeopacity.Length > 0) { opacityValue *= SvgNumber.ParseNumber(szNodeopacity); } else if (szOpacity != null && szOpacity.Length > 0) { opacityValue *= SvgNumber.ParseNumber(szOpacity); } opacityValue = Math.Min(opacityValue, 1); opacityValue = Math.Max(opacityValue, 0); result.A = Convert.ToByte(opacityValue * 255); } return(result); }
private Brush GetBrush(Geometry geometry, string propPrefix, bool setOpacity) { WpfSvgPaintContext paintContext = null; SvgPaintType paintType = this.PaintType; WpfSvgPaint fill; if (paintType == SvgPaintType.None) { return(null); } if (paintType == SvgPaintType.CurrentColor) { //TODO: Find a better way to support currentColor specified on parent element. var deferredFill = this.GetDeferredFill(); if (deferredFill == null) { fill = new WpfSvgPaint(_context, _element, "color"); } else { fill = deferredFill; } } else if (paintType == SvgPaintType.ContextFill) { paintContext = GetFillContext(); if (paintContext != null) { fill = paintContext.Fill; } else { fill = this; } } else if (paintType == SvgPaintType.ContextStroke) { paintContext = GetStrokeContext(); if (paintContext != null) { fill = paintContext.Stroke; } else { fill = this; } } else { fill = this; } SvgPaintType fillType = fill.PaintType; if (fillType == SvgPaintType.Uri || fillType == SvgPaintType.UriCurrentColor || fillType == SvgPaintType.UriNone || fillType == SvgPaintType.UriRgbColor || fillType == SvgPaintType.UriRgbColorIccColor) { _paintFill = GetPaintFill(fill.Uri); if (_paintFill != null) { Brush brush = null; if (geometry != null) { brush = _paintFill.GetBrush(geometry.Bounds, _context, geometry.Transform); } else { brush = _paintFill.GetBrush(Rect.Empty, _context, null); } if (brush != null) { brush.Opacity = GetOpacity(propPrefix); } return(brush); } if (paintType == SvgPaintType.UriNone || paintType == SvgPaintType.Uri) { return(null); } if (paintType == SvgPaintType.UriCurrentColor) { fill = new WpfSvgPaint(_context, _element, "color"); } else { fill = this; } } if (fill == null || fill.RgbColor == null) { return(null); } Color?solidColor = WpfConvert.ToColor(fill.RgbColor); if (solidColor == null) { return(null); } SolidColorBrush solidBrush = new SolidColorBrush(solidColor.Value); if (setOpacity) { solidBrush.Opacity = GetOpacity(propPrefix); } return(solidBrush); }
private Brush GetBrush(Geometry geometry, string propPrefix, bool setOpacity) { WpfSvgPaintContext paintContext = null; SvgPaintType paintType = this.PaintType; WpfSvgPaint fill; if (paintType == SvgPaintType.None) { return(null); } if (paintType == SvgPaintType.CurrentColor) { //TODO: Find a better way to support currentColor specified on parent element. var deferredFill = this.GetDeferredFill(); if (deferredFill == null) { fill = new WpfSvgPaint(_context, _element, CssConstants.PropColor); } else { fill = deferredFill; } } else if (paintType == SvgPaintType.ContextFill) { paintContext = GetFillContext(); if (paintContext != null) { fill = paintContext.Fill; } else { fill = this; } } else if (paintType == SvgPaintType.ContextStroke) { paintContext = GetStrokeContext(); if (paintContext != null) { fill = paintContext.Stroke; } else { fill = this; } } else { fill = this; } SvgPaintType fillType = fill.PaintType; if (fillType == SvgPaintType.Uri || fillType == SvgPaintType.UriCurrentColor || fillType == SvgPaintType.UriNone || fillType == SvgPaintType.UriRgbColor || fillType == SvgPaintType.UriRgbColorIccColor) { _paintFill = GetPaintFill(fill.Uri); if (_paintFill != null) { Brush brush = null; if (geometry != null) { brush = _paintFill.GetBrush(geometry.Bounds, _context, geometry.Transform); } else { brush = _paintFill.GetBrush(Rect.Empty, _context, null); } if (brush != null) { brush.Opacity = GetOpacity(propPrefix); } return(brush); } if (paintType == SvgPaintType.UriNone || paintType == SvgPaintType.Uri) { return(null); } if (paintType == SvgPaintType.UriCurrentColor) { fill = new WpfSvgPaint(_context, _element, CssConstants.PropColor); } else { fill = this; } } if (fill == null || fill.RgbColor == null) { return(null); } if (fill.RgbColor.IsVarColor) { var cssVar = this.GetVarsValue(fill); if (cssVar != null) { var cssVariables = _context.Settings.CssVariables; if (cssVariables != null && cssVariables.ContainsKey(cssVar.VarName)) { var cssColor = new CssColor(cssVariables[cssVar.VarName]); Color?varColor = WpfConvert.ToColor(cssColor); if (varColor != null) { var varBrush = new SolidColorBrush(varColor.Value); if (setOpacity) { varBrush.Opacity = GetOpacity(propPrefix); } return(varBrush); } } var cssValue = _element.GetComputedCssValue(cssVar.VarName, string.Empty) as CssAbsPrimitiveValue; if (cssValue != null) { Color?varColor = WpfConvert.ToColor(cssValue.GetRgbColorValue()); if (varColor != null) { var varBrush = new SolidColorBrush(varColor.Value); if (setOpacity) { varBrush.Opacity = GetOpacity(propPrefix); } return(varBrush); } } var fallbackValue = cssVar.VarValue; if (!string.IsNullOrWhiteSpace(fallbackValue)) { var cssColor = new CssColor(fallbackValue); Color?varColor = WpfConvert.ToColor(cssColor); if (varColor != null) { var varBrush = new SolidColorBrush(varColor.Value); if (setOpacity) { varBrush.Opacity = GetOpacity(propPrefix); } return(varBrush); } } } } Color?solidColor = WpfConvert.ToColor(fill.RgbColor); if (solidColor == null) { return(null); } SolidColorBrush solidBrush = new SolidColorBrush(solidColor.Value); if (setOpacity) { solidBrush.Opacity = GetOpacity(propPrefix); } return(solidBrush); }
private Brush GetBrush(Geometry geometry, string propPrefix, bool setOpacity) { SvgPaint fill; if (PaintType == SvgPaintType.None) { return(null); } else if (PaintType == SvgPaintType.CurrentColor) { fill = new WpfSvgPaint(_context, _element, "color"); } else { fill = this; } SvgPaintType paintType = fill.PaintType; if (paintType == SvgPaintType.Uri || paintType == SvgPaintType.UriCurrentColor || paintType == SvgPaintType.UriNone || paintType == SvgPaintType.UriRgbColor || paintType == SvgPaintType.UriRgbColorIccColor) { _paintFill = GetPaintFill(fill.Uri); if (_paintFill != null) { Brush brush = null; if (geometry != null) { brush = _paintFill.GetBrush(geometry.Bounds, _context); } else { brush = _paintFill.GetBrush(Rect.Empty, _context); } if (brush != null) { brush.Opacity = GetOpacity(propPrefix); } return(brush); } else { if (PaintType == SvgPaintType.UriNone || PaintType == SvgPaintType.Uri) { return(null); } else if (PaintType == SvgPaintType.UriCurrentColor) { fill = new WpfSvgPaint(_context, _element, "color"); } else { fill = this; } } } if (fill == null || fill.RgbColor == null) { return(null); } Color?solidColor = WpfConvert.ToColor(fill.RgbColor); if (solidColor == null) { return(null); } SolidColorBrush solidBrush = new SolidColorBrush(solidColor.Value); //int opacity = GetOpacity(propPrefix); //solidBrush.Color = Color.FromArgb(opacity, brush.Color); if (setOpacity) { solidBrush.Opacity = GetOpacity(propPrefix); } return(solidBrush); }