Very Noisy

I'm Mark Kennedy. I'm part of the furniture at Eurogamer Network Ltd. and I do my best to lead the web development team there.

This website is mainly about food, though there's a few technical things here too.

Projects

Pals

Categories

Tip: filters in Inkscape

15 September 2011

Have been trying to get as comfortable working in http://inkscape.org/, the free SVG editor, as I used to be in Adobe Illustrator, which is the marvellous but prohibitively expensive king of vectors. When switching apps, you have to repeatedly remind yourself that different != rubbish, you just have to relearn everything and very complex apps are never going to be completely intuitive.

The first major-ish misunderstanding I've figured out out in version 0.48 concerns transforms and filters, or rather how to stop filters from transforming along with the artwork they're applied to. First some details about Inkscape's transformations.

When using the resize tool you are sometimes actually applying a distortion to an object, not modifying it's basic form. For example, if you draw a 10×10 box and leave it as a 'rect' primitive, and then stretch it to 20×10 (i.e. horizontally) Inkscape will modify the basic parameters of the box to really give you a 20×10 rect primitive.

<rect width="20" height="10" />

However, if you apply a slight rotation first, you don't end up with a 20×10 box, you get a 10×10 box with a rotation and 2× horizontal stretch on it. These things are subtly different. In the latter case, Inkscape is storing the transformation as a separate definition to the geometry of the object.

<rect width="10" height="10" transform="matrix(0.93834994,0.34568683,-0.59571192,0.80319817,0,0)" />

(Enjoy reading the matrix form of the transformation!)

If you expand the rect primitive to a path, then Inkscape will do a better job of applying your transformation to the base nodes of the path. So if you take a 10×10 box, expand to a 4 node path, then rotate 45°ree;, you will have a new 4 node path that traces a diamond.

<path d="M -5,-5 5,-5 5,5 -5,5 z" />

Becomes

<path d="M -7.0710678,0 0,-7.0710678 7.0710678,0 0,7.0710678 z" />

It may seem like Inkscape is being difficult here, but I suppose it's just trying to create the simplest SVG document at all times. And if this seems somewhat indeterministic then, er, perhaps it is. If you do somehow get stuck with a path primitive with a transform applied, you can force Inkscape to attempt to permanently apply the transformation to the underlying nodes by using 'Break apart' from the 'Path' menu. This is equivalent to 'Expand' in Illustrator.

So, back to filters. If you use the very nice (new) drop shadow or outer glow effect on an object, the resulting block becomes 'impenetrable' to Inkscape's transforms and all subsequent transformations apply to the entire group affected by the filter. This includes transforming the output of the filter. So if you apply a drop shadow simulating light from the top-left, and then rotate the whole lot, the light source will rotate with it. If you stretch the box, the drop shadow will stretch with it.

If you don't want this to happen, the solution is to group your geometry and apply the filter to the group. If you need to modify the filtered artwork, enter the group and apply your transforms there.

For example:

  1. Create a rect.
  2. Select and then create a group with just the box in it.
  3. Apply a drop shadow filter to the group.
  4. Enter the group (right click 'Enter group')
  5. Rotate the box.

Ta da!

Related tags: filters, Inkscape, transformations, vectors

Post a comment