Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
felipetesc opened this issue Feb 12, 2024 · 5 comments
Open

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

felipetesc opened this issue Feb 12, 2024 · 5 comments
Assignees
Labels
enhancement 🔥 New feature or request skia 🖌️

Comments

@felipetesc
Copy link

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 marc2332 self-assigned this Feb 12, 2024
@marc2332 marc2332 added the bug 😔 Something isn't working label Feb 12, 2024
@marc2332
Copy link
Owner

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

image

@felipetesc
Copy link
Author

felipetesc commented Feb 12, 2024

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

@marc2332
Copy link
Owner

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 marc2332 added enhancement 🔥 New feature or request and removed bug 😔 Something isn't working labels Feb 12, 2024
@marc2332 marc2332 changed the title Bug: Svg with image tag doesn't work always request: Support images encoded in base64 inside SVG elements Feb 12, 2024
@marc2332
Copy link
Owner

I wonder if something can be done at Freya level though

@felipetesc
Copy link
Author

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 :

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 🔥 New feature or request skia 🖌️
Projects
None yet
Development

No branches or pull requests

2 participants