Exemplo n.º 1
0
        /// <inheritdoc/>
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            var s   = (string)value;
            var uri = s.StartsWith("/")
                ? new Uri(s, UriKind.Relative)
                : new Uri(s, UriKind.RelativeOrAbsolute);
            var svg = new SvgSource();

            if (uri.IsAbsoluteUri && uri.IsFile)
            {
                svg.Load(uri.LocalPath);
                return(svg);
            }
            else
            {
                var assets = AvaloniaLocator.Current.GetService <IAssetLoader>();
                svg.Load(assets.Open(uri, context.GetContextBaseUri()));
            }
            return(svg);
        }
Exemplo n.º 2
0
        /// <inheritdoc/>
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            var s   = (string)value;
            var uri = s.StartsWith("/")
                ? new Uri(s, UriKind.Relative)
                : new Uri(s, UriKind.RelativeOrAbsolute);
            var svg = new SvgSource();

            if (uri.IsAbsoluteUri && uri.IsFile)
            {
#if USE_PICTURE
                var document = SKSvg.Open(uri.LocalPath);
                if (document != null)
                {
                    svg.Picture = SKSvg.ToModel(document);
                }
#else
                svg.Load(uri.LocalPath);
#endif
                return(svg);
            }
            else
            {
                var assets = AvaloniaLocator.Current.GetService <IAssetLoader>();
#if USE_PICTURE
                var document = SKSvg.Open(assets.Open(uri, context.GetContextBaseUri()));
                if (document != null)
                {
                    svg.Picture = SKSvg.ToModel(document);
                }
#else
                svg.Load(assets.Open(uri, context.GetContextBaseUri()));
#endif
            }
            return(svg);
        }
Exemplo n.º 3
0
 public SvgCustomDrawOperation(Rect bounds, SvgSource svg)
 {
     _svg   = svg;
     Bounds = bounds;
 }