Beispiel #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));
        }
        private GdiFill GetPaintFill(string uri)
        {
            string absoluteUri = _element.ResolveUri(uri);

            return(GdiFill.CreateFill(_element.OwnerDocument, absoluteUri));
        }
Beispiel #3
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);
        }
        private PaintServer getPaintServer(string uri)
        {
            string absoluteUri = _element.ResolveUri(uri);

            return(PaintServer.CreatePaintServer(_element.OwnerDocument, absoluteUri));
        }