Ejemplo n.º 1
0
        public static ImageDrawable Create(SvgImage svgImage, SKRect skViewport, DrawableBase?parent, IAssetLoader assetLoader, HashSet <Uri>?references, DrawAttributes ignoreAttributes = DrawAttributes.None)
        {
            var drawable = new ImageDrawable(assetLoader, references)
            {
                Element          = svgImage,
                Parent           = parent,
                IgnoreAttributes = ignoreAttributes
            };

            drawable.IsDrawable = drawable.CanDraw(svgImage, drawable.IgnoreAttributes) && drawable.HasFeatures(svgImage, drawable.IgnoreAttributes);

            if (!drawable.IsDrawable)
            {
                return(drawable);
            }

            var width    = svgImage.Width.ToDeviceValue(UnitRenderingType.Horizontal, svgImage, skViewport);
            var height   = svgImage.Height.ToDeviceValue(UnitRenderingType.Vertical, svgImage, skViewport);
            var x        = svgImage.Location.X.ToDeviceValue(UnitRenderingType.Horizontal, svgImage, skViewport);
            var y        = svgImage.Location.Y.ToDeviceValue(UnitRenderingType.Vertical, svgImage, skViewport);
            var location = new SKPoint(x, y);

            if (width <= 0f || height <= 0f || svgImage.Href is null)
            {
                drawable.IsDrawable = false;
                return(drawable);
            }

            var uri = SvgExtensions.GetImageUri(svgImage.Href, svgImage.OwnerDocument);

            if (references is { } && references.Contains(uri))