GithubHelp home page GithubHelp logo

linebender / vello_svg Goto Github PK

View Code? Open in Web Editor NEW
12.0 12.0 9.0 162 KB

An integration to render SVG files with Vello.

Home Page: http://linebender.org/vello_svg/

License: Apache License 2.0

Rust 100.00%

vello_svg's People

Contributors

daslixou avatar marijns95 avatar nixon-voxell avatar simbleau avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

vello_svg's Issues

Should the image `view_box_transform` actually be `view_box.to_transform(image_size)`?

vello_svg/src/lib.rs

Lines 217 to 237 in cf6fe55

let Some(size) =
usvg::Size::from_wh(image.width as f32, image.height as f32)
else {
error_handler(scene, node)?;
continue;
};
let view_box = img.view_box();
let new_size = view_box.rect.size();
let (tx, ty) = usvg::utils::aligned_pos(
view_box.aspect.align,
view_box.rect.x(),
view_box.rect.y(),
view_box.rect.width() - new_size.width(),
view_box.rect.height() - new_size.height(),
);
let (sx, sy) = (
new_size.width() / size.width(),
new_size.height() / size.height(),
);
let view_box_transform =
usvg::Transform::from_row(sx, 0.0, 0.0, sy, tx, ty);

Color/Brush override

Is there a way to set a color/brush override?

If not, would a PR for that be accepted?

Reduce boilerplate

I do this a lot in bevy_vello - It feels very verbose!

                // SVG -> Scene
                let svg_tree = bevy_vello::vello_svg::usvg::Tree::from_str(
                    &svg_contents,
                    &Default::default(),
                    &Default::default(),
                )
                .unwrap();
                let mut scene = bevy_vello::vello::Scene::new();
                bevy_vello::vello_svg::render_tree(&mut scene, &svg_tree);

This is pretty much the requirement for every SVG load, which feels pretty dumb.

We can surely do better, can't we? e.g. vello_svg::render_str(&str) -> Scene.

Proposal:

  • Introduce a usvg cargo feature.
    • Move vello_svg::render_tree behind this feature.
    • Move vello_svg::render_tree_with behind this feature.
    • Re-export vello_svg::usvg behind this feature.
  • Add a vello_svg::render_str(&str) -> Scene method (uses default usvg opts)
  • Add a vello_svg::render_str_to(&str, &mut Scene) method (uses default usvg opts)

Thoughts, @DJMcNab ?

Expose util functions

Right now, a lot of the useful functions in vello_svg is locked up inside a private util mod:

pub fn to_affine(ts: &usvg::Transform) -> Affine
pub fn to_stroke(stroke: &usvg::Stroke) -> Stroke
pub fn to_bez_path(path: &usvg::Path) -> BezPath
pub fn into_image(image: image::ImageBuffer<image::Rgba<u8>, Vec<u8>>) -> Image
pub fn to_brush(paint: &usvg::Paint, opacity: usvg::Opacity) -> Option<(Brush, Affine)>
pub fn decode_raw_raster_image(
    img: &usvg::ImageKind,
) -> Result<image::RgbaImage, image::ImageError>

As a user from the outside, it would be nice if I can access these functions and use it to transform an Svg into custom data struct that uses Vello types other than just Scene (maybe a collection of BezPaths).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.