…my first approved bug report for an open source project. I am a little bit proud of it.🙂 So for the sake of documentation I want to write down what I’ve done.

The task was to add a feature to Librsvg which enbles developers to get the size of a SVG element. Robert Staudinger, the developer of the gtk-css-engine, wants to have this feature, so artists can provide a single SVG file instead of several files to describe their theme.

Librsvg had already a function but it only provides the size of the whole SVG file not of a single element. So the first thing I’ve done was to have a look on the already existing code. My hope was to get the feature implemented by adapting the already existing code. This worked only at the first sight. There have been several inaccuracies which became more obvious when I’ve used the function on elements which uses Bézier curves to define their shape.

So I had a further look on the code especially on the part where the function determines the size. It came out that the function applies the same function on lines and curves which is obviously the wrong way to determine the size of a curve.  So I wrote an email with possible solutions for the problem.

The maintainer of Librsvg preferred the mathematical approach and so far it was the only opinion I was aware of. So I started to find a mathematical formula which determines the height of a Bézier curve and implemented it. The problem with a mathematical approach is that you also have to keep the stroke width in mind because a mathematical formula assumes an infinitesimal small stroke width. So the new function worked well as long as your lines were not too thick.

Emmanuel Pacaud pointed out that it doesn’t make sense to reimplement all the functions to determine the bounding box when Cairo does these things already. Cairo is the backend used by Librsvg to draw the images. So I changed my code according to Emmanuels suggestion and my second solution I had pointed out in my mail.

Now the code passes a dummy surface to the drawing function of Librsvg. So every time one wants to have the size of an element of a SVG file Librsvg draws this specific element and returns the bounding box we get when we put the bounding boxes provided by Cairo together. Easy, isn’t it?😀

After bothering the maintainer for several weeks he applied the patch just yesterday.

With these few lines about my first patch I want to finish my post and wish you a good start into the following week!

Cheers!!! Hej då!!!