Outils pour utilisateurs

Outils du site


issue162:inkscape

Ceci est une ancienne révision du document !


As you may have noticed in the News section of the previous edition of FCM, a new minor release of Inkscape is out. As is often the case with these things, the announcement came only a couple of days after the deadline for my previous article. As it turns out, version 1.0.1 doesn’t fix any of the issues I’ve raised in recent months, or change any of the features that I’ve described. Phew! No corrections required.

So what is new in the latest release? It’s mostly bug fixes and stability improvements, though there is a whole new “Selectors and CSS” dialog that is most likely to be of interest to web developers. I’ll cover it in due course, but it’s not the topic for this month’s instalment. Instead, I’ll cover some changes to the ‘Path > Stroke to Path’ function. To better understand this menu entry, however, I’m going to start with its sibling.

‘Path > Object to Path’ is a mainstay of any experienced Inkscape user. As the name suggests, it converts your object to a path, and is therefore commonly used when you want to break out of the design shackles imposed by an object’s native type. Whilst a rectangle can have only its width, height and corner radius modified, converting it into a path lets you move individual nodes, add more, or delete others. Since paths are so flexible, it can open up a world of design possibilities – albeit at the expense of losing access to the specialized editing tools for the original object type.

There’s nothing controversial about Object to Path. The end result maintains its fill and stroke properties, so there’s no visual change as a result of the operation. All that’s happened is that your native Inkscape object becomes a generic path of the same size, shape and appearance.

Despite the similar name, however, Path > Stroke to Path is an entirely different beast. At its core it converts any stroke that you may have on your object into a new filled path which matches the stroke’s original outline. If it sounds confusing, perhaps some examples will help. Let’s start with the simplest example possible: a straight line.

The top line is our original path, consisting of two nodes, no fill, and a thick, red stroke. As a rule it’s easiest to understand what Inkscape is doing when applied to thick strokes, but everything I describe can also be done with thinner strokes if that suits your requirements.

The bottom line is the result of the Stroke to Path operation. You can see that what we now have is a filled path consisting of four nodes arranged to match the original stroke’s outline. The fact that it’s a filled path is a really important point to grasp: the original shape had a stroke but no fill, whereas the new shape has a fill but no stroke. The fill color of the new shape is the same as that of the original’s stroke color in order to produce a result that is visually identical.

Why would you want to perform such a conversion? Consider trying to make a line that looks a little more hand-drawn. SVG has no support for variable width strokes, but you can fake it by converting your stroke to a path and then tweaking the shape.

These days Inkscape can simulate variable width strokes using Live Path Effects, but that wasn’t always the case. The LPE approach also supports varying the thickness only symmetrically, whereas this manual approach lets you achieve effects such as thickening the stroke on one side of the center line whilst thinning it on the other.

Let’s look at a more complicated example. This time we’ll jump straight to a multi-segment line with a dashed stroke applied. Once again the original line is at the top, and the bottom shows the effect of converting the stroke to a path.

Our converted line is starting to look a bit more interesting. Instead of a simple filled path, we now have a complex path, consisting of a number of filled sub-paths which match the visual appearance of the original line.

At first, this can be a little tricky to get your head around. Because the resultant shape still looks the same, it’s not obvious that it’s actually now a filled path that has no stroke. Like any other path, you can actually add a stroke to it; here’s the same result but with a thin, dashed, black stroke added to the converted line:

Hopefully it’s now pretty clear what Stroke to Path does when presented with the simple case of an object with just a stroke applied. But what happens when your object is a bit more complex? Here’s a line with a stroke applied, but also with markers at the start, end, and at each intermediate node.

What do you think should happen when Stroke to Path is applied to this object? To my mind there are three possible alternatives: • Remove the markers and convert the stroke as before. • Convert the stroke, but also turn the markers into filled paths. • Convert the stroke, but copy the markers to the new paths, so that each sub-path ends up with multiple markers.

Really old versions of Inkscape went with option 1. Stroke to Path converted the stroke to a path, and ignored everything else. But since version 0.44 (released in 2006), Inkscape uses the second option (no version uses the third option). This, however, is where not-so-subtle differences in behaviour for 1.0.x start to creep in.

Consider the shape above. Up to version 0.92 using Stroke to Path on this would have created a group containing five objects: the complex path generated by converting the stroke, and a separate path for each marker. In version 1.0.x the result is somewhat different. Now the output is a group containing two elements: the complex path, plus a nested group which contains four more deeply nested groups – one for each marker. Each of those marker groups contains two paths, one each for the fill and the stroke of the marker. Yes, I said the stroke of the marker. I know you probably weren’t even aware of markers having a separate stroke, but apparently they do and they’re now converted into a path of their own.

If this sounds a little confusing, perhaps an image of the structure will help. On the left we have the Objects dialog from 0.92, and on the right we have one from 1.0.1 (excuse the different themes – the 1.0.1 snap is still broken with the standard theme, so I’m using the symbolic theme):

As you can see, the structures are substantially different. If you do want to convert a 1.0 arrangement to the old structure, it’s quite simple: you just need to use Path > Union on each pair of marker paths (this is easier if you select them in the Objects dialog rather than on-canvas), then select the group that contains the markers (i.e. not the top-level group, but the one just inside that), then repeatedly ungroup until you’re left with a structure that looks like the one in the 0.92 dialog. Yes, “it’s quite simple” was sarcasm.

For most users, this may never present a problem. The sort of use-case that requires you to add markers to your path does not generally intersect much with the use-cases for converting the stroke to a path. So, let’s look at a far more common scenario: a path with both a stroke and a fill, but no markers. Here’s what happens in 0.92.x, again with the original shapes at the top, and the Stroke to Path conversions at the bottom:

The obvious take-away from this is that 0.92 removes the fill entirely before the stroke is converted to a path. I’ve shown both closed and open shapes to make it clear that the behaviour is the same in both cases. Structurally, you end up with a single filled path, just the same as you would if you’d performed the conversion on a shape with no fill or markers, the same as the first example I showed in this article.

Since version 1.0, however, performing a Stroke to Path operation on a shape with a fill results in a group that contains two filled paths: one is the usual path following the shape of the original stroke, whilst the other is a path representing the fill (i.e. it’s just a copy of the original path, but without the stroke). The end result is visually identical to the original object.

As I’m sure you’ve guessed by now, performing a Stroke to Path on a shape with the holy trinity of stroke, fill and markers, results in a group containing: • A path for the stroke • A path for the fill • A group containing an individual group for each marker, with each of those groups containing a path for the marker’s stroke and a path for the marker’s fill.

There are a few things to unpick from these changes. First of all, if you have an object with just a stroke then the behaviour is the same as it has always been: you end up with a single filled path, which will have sub-paths if the stroke was dashed.

If your path has a stroke and a fill, however, you’ll now end up with a group, rather than the fill being thrown away. This is particularly important to note if following an older tutorial. Many of them either rely on the fill being removed, or instruct you to duplicate the object before applying Stroke to Path so that you don’t lose the fill. To get the same result as earlier versions, you can do one of two things: • Remove the fill before using Stroke to Path. • After using Stroke to Path, ungroup the result and delete the new path containing the fill (or just keep it, if you need it for subsequent steps).

Despite the confusion this change has caused with some new users, I generally think it’s an improvement. Consider the case of drawing a simple cartoon character, with thick black outlines (strokes), and colored clothes and skin (fill). If you want to add some variety to the stroke thickness, the new behaviour makes it easier to do so without having to duplicate every object, then remove its stroke, just to keep a copy of the filled shape.

Markers are another matter, however. While dealing with an unwanted fill just requires a couple of extra steps, getting the 0.92 structure when markers are in play requires several steps – multiplied by the number of markers – with no easy shortcuts. Although the new functionality may technically be more flexible, in practice there are few use-cases for separating the fill and stroke on a marker. It would have been nice to either have the old method available as a preference, or to include a function or extension that would make it easy to union deeply nested paths and recursively pop them out of their groups.

The take-away from all this is that Object to Path still behaves the same way it always did, Stroke to Path may need an extra step or two if you have a fill, but if you have markers as well then good luck to you!

Next time, I’ll start to look at the changes to core drawing tools made with version 1.0.

issue162/inkscape.1604233816.txt.gz · Dernière modification : 2020/11/01 13:30 de auntiee