bodoni / svg

Composer and parser for SVG
Other
302 stars 44 forks source link

How to add a filter #37

Closed konstare closed 3 years ago

konstare commented 3 years ago

Hey,

Could you help me please. I cannot understand how to add a filter to the svg Document. Is it possible with your library? For example, I want to add feGaussianBlur. As I understand i should start something like this:

let filter = Filter::new().add(What exactly I should put here??);
let definitions = Definitions::new().add(filter);
let document = Document::new()
    .set("viewBox", (0, 0, 70, 70))
    .add(definitions)
........
IvanUkhov commented 3 years ago

Hi, do you have a brief example in SVG?

konstare commented 3 years ago

Sure, I would like to write something like this:

 <svg height="110" width="110">
  <defs>
    <filter id="f1" x="0" y="0">
      <feGaussianBlur in="SourceGraphic" stdDeviation="15" />
    </filter>
  </defs>
  <rect width="90" height="90" filter="url(#f1)" />
</svg> 
IvanUkhov commented 3 years ago

You see you have to append an feGaussianBlur to a filter. There is no dedicated struct for feGaussianBlur:

https://docs.rs/svg/0.8.0/svg/node/element/index.html

What you can do instead is to append Element("feGaussianBlur").

konstare commented 3 years ago

Thank you. It works. I did not figure out that there is a structure Element by itself.