Skip to content

Issue rendering complex svgs. #439

@SaverinOnRails

Description

@SaverinOnRails

Im trying to render some svg in an avlaonia app like so:

 private void SvgImagePropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
    {
        if (sender is null) return;
        if (e.Property == Avalonia.Svg.Skia.Svg.BoundsProperty)
        {
            var parent = _svgImage.FindAncestorOfType<Panel>();
            if (parent is null) return;
            Console.WriteLine(parent.Bounds.Height);
            var height = parent.Bounds.Height;
            var width = parent.Bounds.Width;
            if (height > 0)
            {
                var ver = new Verovio();
                ver.LoadFile("/home/noble/Projects/Schubert_Lindenbaum.mei");
                ver.SetOption("pageHeight", height.ToString());
                ver.SetOption("pageWidth", width.ToString());
                var svg = ver.RenderToSvg();
                Console.WriteLine(Encoding.UTF8.GetString(svg));
                Dispatcher.UIThread.Post(() =>
                {
                    _svgImage.Source = Encoding.UTF8.GetString(svg);
                });
            }
        }
    }

This freezes the UI thread until the svg is "done" loading and it is still not rendered onto the control. The svg is quite complex but renders on web browsers fine. The control:

            <Svg HorizontalAlignment="Stretch" VerticalAlignment="Stretch" x:Name = "svgImage" />

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions