Пример #1
0
        private WpfFill GetPaintFill(string uri)
        {
            string absoluteUri = _element.ResolveUri(uri);

            if (_element.Imported && _element.ImportDocument != null && _element.ImportNode != null)
            {
                // We need to determine whether the provided URI refers to element in the
                // original document or in the current document...
                SvgStyleableElement styleElm = _element.ImportNode as SvgStyleableElement;
                if (styleElm != null)
                {
                    var cssDeclaration = styleElm.GetComputedStyle("");

                    string propertyValue = cssDeclaration.GetPropertyValue(_propertyName);

                    if (!string.IsNullOrWhiteSpace(propertyValue))
                    {
                        WpfSvgPaint importFill = new WpfSvgPaint(_context, styleElm, _propertyName);
                        if (string.Equals(uri, importFill.Uri, StringComparison.OrdinalIgnoreCase))
                        {
                            WpfFill fill = WpfFill.CreateFill(_element.ImportDocument, absoluteUri);
                            if (fill != null)
                            {
                                return(fill);
                            }
                        }
                    }
                }
            }

            return(WpfFill.CreateFill(_element.OwnerDocument, absoluteUri));
        }
Пример #2
0
 public WpfSvgPaint(WpfDrawingContext context, SvgStyleableElement elm, string propName)
     : base(elm.GetComputedStyle("").GetPropertyValue(propName))
 {
     _propertyName = propName;
     _element      = elm;
     _context      = context;
 }
Пример #3
0
        private CssPrimitiveVarsValue GetVarsValue(WpfSvgPaint fill)
        {
            if (fill == null || fill.RgbColor == null)
            {
                return(null);
            }
            if (!fill.RgbColor.IsVarColor)
            {
                return(null);
            }
            var cssDeclaration = _element.GetComputedStyle(string.Empty);

            if (cssDeclaration == null)
            {
                return(null);
            }
            var cssValue = cssDeclaration.GetPropertyCssValue(CssConstants.PropFill);

            if (cssValue == null)
            {
                return(null);
            }
            if (cssValue.IsAbsolute)
            {
                var cssAbs = cssValue as CssAbsPrimitiveValue;
                if (cssAbs != null && cssAbs.CssValue != null)
                {
                    return(cssAbs.CssValue as CssPrimitiveVarsValue);
                }
            }
            return(cssValue as CssPrimitiveVarsValue);
        }
 public GdiSvgColor(SvgStyleableElement elm, string propertyName) : base(elm.GetComputedStyle("").GetPropertyValue(propertyName))
 {
     _element      = elm;
     _propertyName = propertyName;
 }
Пример #5
0
        public static bool TryGetBrush(SvgStyleableElement element, string property, Rect bounds, Matrix transform, out Brush brush)
        {
            SvgPaint paint = new SvgPaint(element.GetComputedStyle(string.Empty).GetPropertyValue(property));
            SvgPaint svgBrush;

            if (paint.PaintType == SvgPaintType.None)
            {
                brush = null;
                return(false);
            }
            if (paint.PaintType == SvgPaintType.CurrentColor)
            {
                svgBrush = new SvgPaint(element.GetComputedStyle(string.Empty).GetPropertyValue(CssConstants.PropColor));
            }
            else
            {
                svgBrush = paint;
            }

            SvgPaintType paintType = svgBrush.PaintType;

            if (paintType == SvgPaintType.Uri || paintType == SvgPaintType.UriCurrentColor ||
                paintType == SvgPaintType.UriNone || paintType == SvgPaintType.UriRgbColor ||
                paintType == SvgPaintType.UriRgbColorIccColor)
            {
                SvgStyleableElement fillNode = null;
                string absoluteUri           = element.ResolveUri(svgBrush.Uri);

                if (element.Imported && element.ImportDocument != null &&
                    element.ImportNode != null)
                {
                    // We need to determine whether the provided URI refers to element in the
                    // original document or in the current document...
                    SvgStyleableElement styleElm = element.ImportNode as SvgStyleableElement;
                    if (styleElm != null)
                    {
                        string propertyValue = styleElm.GetComputedStyle(string.Empty).GetPropertyValue(property);

                        if (!string.IsNullOrWhiteSpace(propertyValue))
                        {
                            SvgPaint importFill = new SvgPaint(styleElm.GetComputedStyle(string.Empty).GetPropertyValue(property));
                            if (string.Equals(svgBrush.Uri, importFill.Uri, StringComparison.OrdinalIgnoreCase))
                            {
                                fillNode = element.ImportDocument.GetNodeByUri(absoluteUri) as SvgStyleableElement;
                            }
                        }
                    }
                }
                else
                {
                    fillNode = element.OwnerDocument.GetNodeByUri(absoluteUri) as SvgStyleableElement;
                }

                if (fillNode != null)
                {
                    SvgLinearGradientElement linearGradient;
                    SvgRadialGradientElement radialGradient;
                    SvgPatternElement        pattern;
                    if (TryCast.Cast(fillNode, out linearGradient))
                    {
                        brush = ConstructBrush(linearGradient, bounds, transform);
                        return(true);
                    }
                    if (TryCast.Cast(fillNode, out radialGradient))
                    {
                        brush = ConstructBrush(radialGradient, bounds, transform);
                        return(true);
                    }
                    if (TryCast.Cast(fillNode, out pattern))
                    {
                        brush = ConstructBrush(pattern, bounds, transform);
                        return(true);
                    }
                }
            }

            Color solidColor;

            if (svgBrush == null || svgBrush.RgbColor == null ||
                !TryConvertColor(svgBrush.RgbColor, out solidColor))
            {
                brush = null;
                return(false);
            }

            brush         = new SolidColorBrush(solidColor);
            brush.Opacity = GetOpacity(element, property);
            if (brush.CanFreeze)
            {
                brush.Freeze();
            }
            return(true);
        }
 public GdiSvgPaint(SvgStyleableElement elm, string propName)
     : base(elm.GetComputedStyle("").GetPropertyValue(propName))
 {
     _element = elm;
 }