marc2332 / freya

Cross-platform GUI library for 🦀 Rust powered by 🧬 Dioxus and 🎨 Skia.
https://freyaui.dev/
MIT License
1.44k stars 60 forks source link

request: Support images encoded in base64 inside SVG elements #504

Open felipetesc opened 7 months ago

felipetesc commented 7 months ago

Expected Behavior

I expect to load and render both svg files.

Current Behavior

Only the first svg file is loaded.

Possible Solution

Tell users about the render issues while loading a svg containing an image tag, or adapt svg render to allow rendering the image tag.

Steps to Reproduce

  1. Paste the provided svg file inside examples folder
  2. Create a file called svg.rs and paste the source code below inside project_name/examples folder :

#![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]

use freya::prelude::*;
use dioxus::core::Scope;

static PERSON_ICON: &[u8] = include_bytes!("./person.svg");
static PERSON2_ICON: &[u8] = include_bytes!("./person2.svg");

fn main() {
    launch(example_svg);
}

pub fn example_svg(cx: Scope) -> Element{

    //icons
    let svg1_data = bytes_to_data(cx, PERSON_ICON);
    let svg2_data = bytes_to_data(cx, PERSON2_ICON);

    render!{
        rect {
            height: "50",
            width: "100%",
            background: "black",
            color: "white",
            padding: "0",
            direction: "horizontal",
            //spacer
            rect{
                height: "100%",
                width: "5",
                background: "black",
            }
            //button account
            rect{
                height: "50",
                width: "50",
                //background: "red",
                color: "white",
                padding: "0",
                onclick:|_| {
                    println!("svg1");

                },
                svg {
                    svg_data: svg1_data,
                    width: "100%",
                    height: "100%",
                }
            }
            //spacer
            rect{
                height: "100%",
                width: "calc(100% - 110)",
                background: "black",
            }
            //button settings
            rect{
                height: "50",
                width: "50",
                //background: "blue",
                color: "white",
                padding: "0",
                onclick:|_| {

                    println!("svg2");

                },
                svg {
                    svg_data: svg2_data,
                    width: "100%",
                    height: "100%",
                }
            }
        }
    }

}
  1. from the terminal execute cargo run --example svg
  2. Wait and see the window showing a single image
  3. Read the messsage from the terminal: can't render image: load image failed

Context (Environment)

Windows 11 x64 rustc 1.73.0 (cc66ad468 2023-10-03)

PS: if we open both svg files we will see that one has the tag image (person2), and the other doesn't.

person person2

Thanks.

marc2332 commented 7 months ago

It seems to work just fine for me, can you send me your SVGs files?

image

felipetesc commented 7 months ago

person person2 You will need the svg files I provided I've sent the files atached at the bottom of the first message

marc2332 commented 7 months ago

My bad, my brain decided to ignore those for some reason.

Anyway, this is not a bug but more like Skia doesn't support rendering images encoded in base64 in the image tag.

image

marc2332 commented 7 months ago

I wonder if something can be done at Freya level though

felipetesc commented 7 months ago

I wonder if something can be done at Freya level though

Perhaps if the svg.rs is changed and something like ImageMagick bindings are added.

Some resources I found :