Giter Club home page Giter Club logo

Comments (5)

simbleau avatar simbleau commented on August 22, 2024

No, there isn't currently.

This crate essentially exposes one method to translate an SVG into a Vello 'Scene'.

I think of a Scene as "write-only". There's no way to go back and recolor it.

I'm not sure what API would be suitable, how would you go about it?

from vello_svg.

jrmoulton avatar jrmoulton commented on August 22, 2024
        let brush_present = brush.is_some();

        let mut scene = Scene::new();
        if let Some(brush) = brush {
            let rect = Rect::from_origin_size(
                (0., 0.),
                (svg_size.width() as f64, svg_size.height() as f64),
            );
            scene.fill(Fill::NonZero, Affine::IDENTITY, brush, None, &rect);
            scene.push_layer(
                vello::peniko::BlendMode {
                    mix: Mix::Multiply,
                    compose: Compose::SrcOver,
                },
                1.,
                Affine::IDENTITY,
                &rect,
            );
        }
        vello_svg::render_tree(&mut scene, svg.tree);

        if brush_present {
            scene.pop_layer();
        }

I am trying to come up with a way to do this by drawing the override brush color to the background and then using the svg layer as an alpha mask for the background. But I can't figure it out / don't know if it is possible by using a layer with a blend mode.

from vello_svg.

jrmoulton avatar jrmoulton commented on August 22, 2024
  if let Some(brush) = brush {
      scene.push_layer(
          vello::peniko::BlendMode {
              mix: Mix::Normal,
              compose: Compose::SrcOver,
          },
          1.0,
          Affine::IDENTITY,
          &Rect::from_origin_size(
              (0., 0.),
              (svg_size.width() as f64, svg_size.height() as f64),
          ),
      );

      vello_svg::render_tree(&mut scene, svg.tree);

      scene.push_layer(
          vello::peniko::BlendMode {
              mix: Mix::Clip,
              compose: Compose::SrcIn,
          },
          1.0,
          Affine::IDENTITY,
          &Rect::from_origin_size(
              (0., 0.),
              (svg_size.width() as f64, svg_size.height() as f64),
          ),
      );

      scene.fill(Fill::NonZero, Affine::IDENTITY, brush.into(), None, &rect);
      scene.pop_layer();

      scene.pop_layer();
  } else {
      vello_svg::render_tree(&mut scene, svg.tree);
  }
Screenshot 2024-06-26 at 10 26 41 PM

I was finally able to figure it out. This will override the svg color, essentially using the svg as an alpha mask

from vello_svg.

simbleau avatar simbleau commented on August 22, 2024

Great! Does this need to be an addition to vello_svg then? You seem to have a workaround that uses vello_svg as intended.

from vello_svg.

jrmoulton avatar jrmoulton commented on August 22, 2024

Probably doesn't need to be an addition to vello_svg. I think this is better solved by adding some docs on how to create an alpha mask with Vello. I'll look into adding that

from vello_svg.

Related Issues (5)

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.