Пример #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))
Пример #2
0
        public static ImageDrawable Create(SvgImage svgImage, Rect skOwnerBounds, DrawableBase?parent, IAssetLoader assetLoader, Attributes ignoreAttributes = Attributes.None)
        {
            var drawable = new ImageDrawable(assetLoader)
            {
                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, skOwnerBounds);
            var height   = svgImage.Height.ToDeviceValue(UnitRenderingType.Vertical, svgImage, skOwnerBounds);
            var x        = svgImage.Location.X.ToDeviceValue(UnitRenderingType.Horizontal, svgImage, skOwnerBounds);
            var y        = svgImage.Location.Y.ToDeviceValue(UnitRenderingType.Vertical, svgImage, skOwnerBounds);
            var location = new Point(x, y);

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

            // TODO: Check for image recursive references.
            //if (HasRecursiveReference(svgImage, (e) => e.Href))
            //{
            //    _canDraw = false;
            //    return;
            //}

            var image       = SvgModelExtensions.GetImage(svgImage.Href, svgImage.OwnerDocument, assetLoader);
            var skImage     = image as Image;
            var svgFragment = image as SvgFragment;

            if (skImage is null && svgFragment is null)
            {
                drawable.IsDrawable = false;
                return(drawable);
            }

            drawable.SrcRect = default;

            if (skImage is { })