Ceci est une ancienne révision du document !
If you've been following this series from the start, you should now be quite comfortable with ellipses, rectangles and stars. You should be able to construct some quite complex paths using the Boolean operations, then manipulate them with the Node tool. You can give your objects colours, gradients and patterns, as well as apply markers, thickness and different end caps to their strokes. In short, you've got enough of a toolkit that you can create quite complex drawings, should you wish. In this instalment we will look at ways to manage that complexity.
As the number of objects in a drawing increases, it becomes less and less likely that manipulating them one at a time will be acceptable. If you want to scale or rotate our snowman's hat, for example, you will quickly become frustrated if you have to first manipulate the brim, then the side, then the top – and that's without considering the shadows and highlights we added last time. A far better approach is to select all of the parts and perform your operations on them simultaneously.
Last time you learnt how to select two objects at once by holding SHIFT as you click on the second one. If you continue to hold SHIFT while clicking on more objects, they will each be added to the selection. Holding it while clicking on an already selected object will remove it from the selection. This approach is useful when you want to select just a few objects, or if they're widely spaced with other objects in between.
In the case of our hat, however, there's a much better way. The objects are clustered closely together which makes it easy to simply drag a selection box around them, as follows: click and hold on a blank area of the canvas, then drag the mouse diagonally away from the starting point. You'll see a rectangle – the selection box – which follows the mouse pointer. When you release the button, anything inside the rectangle will be selected.
Unfortunately, there's not always a blank area of the canvas nearby. In the case of our hat, if it's in situ on the snowman, then you'll probably have the background rectangle in the way. If you try to drag a selection box by starting on another object you'll just end up moving that object instead. The answer is to hold SHIFT as you start dragging your mouse, which will prevent Inkscape from selecting the object you started on. Remember, SHIFT-CLICK will add to your selection (or remove from it), but SHIFT-DRAG will prevent the clicked object being added.
One limitation with a selection box is that it will select only objects that are entirely enclosed within the box. This can be a problem if you're zoomed right in, or your objects are too close together and you want to select only some of them. In these cases, you can use Inkscape's 'touch select' mode: just hold down the ALT key as you click and drag your mouse around, drawing a red line as you go. When you release the mouse button any objects that were touched by the red line will be selected. If you want to add to the existing selection, hold down SHIFT as well.
On many Linux systems you'll quickly discover a small issue if you try to use ALT-drag for the touch selection mode: often window managers use ALT-drag as a way to move the window around without having to drag the title bar, which prevents ALT-drag from working in Inkscape. There are three ways to deal with this limitation: • Disable the ALT-drag option in your window manager's preferences. This isn't always easy to do, and will usually have the side-effect of disabling it for all windows from all applications, not just Inkscape. • Hold down the SUPER key (that's what it's nominally called in the Linux world, but you probably know it better as the WINDOWS key) in addition to ALT or SHIFT-ALT. • Start dragging or SHIFT-dragging as though you are dragging a selection box, then press ALT to switch to touch select mode during the process. You can press and release ALT as often as you like during this process – it's only when the mouse button is released that Inkscape will check it to determine whether to use the selection box or touch select mode.
With several objects selected, it's time to combine them into a 'group' using the toolbox icon, the CTRL-G shortcut, or selecting the Object > Group menu item. Now you can move, scale, skew and rotate all the objects as though they were a single item. This makes it easy to combine the separate shapes that make up a single entity, such as our snowman's hat. You can even create a group that contains only one object, but usually grouping is used to make it easier to work with several objects that form a single part of your image.
Often you will want to modify an object that is in your group. One approach is to select the group, then use Object > Ungroup (CTRL-SHIFT-G) or the Ungroup toolbox button (shown left) in order to break the group apart into its constituent parts. After modifying your object you can re-group them again. It's usually beneficial to edit an object without the rigmarole of ungrouping and then re-grouping afterwards, so Inkscape lets you 'enter' a group in order to work with its contents directly. The fastest way to enter a group is simply to double-click on it, though there is an option at the bottom of the right-click context menu for 'Enter Group g#20'. Inkscape assigns a unique identifier to a group, so this menu entry will be slightly different for each of them. Once you have entered a group, you are free to edit its contents individually. The status bar will show you when you're inside a group by temporarily placing its ID into the layers pop-up, to the right of the fill, stroke and opacity settings (shown above).
Having entered a group, any objects that you paste from the clipboard will be added to the contents of that group, as will any new objects you create. There are various ways to exit a group, but the most common is simply to select an object that's outside the group. You can also double-click on a blank area of the canvas if you don't want to select something else, or select 'Go To Parent' from the context menu.
In addition to moving and transforming a group, you can also adjust its fill and stroke settings. Setting the fill or stroke will apply those values to every object in the group, as will a change to the stroke width. Unfortunately, none of the other line style attributes can be set like this, so if you want all the objects in your group to have a dashed stroke you'll need to enter the group and set each one individually.
Setting a flat color for a group's fill or stroke does exactly what you might expect. But try setting a gradient or a pattern to the whole group and you might be a little surprised by the results. Suppose you want to apply a gradient from white to black across a number of objects: you might be tempted to group them and then apply the gradient to the group. This is the actual result you would get:
As you can see, although the gradient stops cover the whole width of the group, Inkscape has actually just used a small portion of it – the amount covered by the first object – and then repeated that small amount for every other object in the group. So instead of white to black across four objects, we get white to grey across one object, which is then used for the other three as well. The same problem applies for patterns: each object has a copy of the first object's pattern applied, rather than there being one pattern that covers the whole group. There is an answer to both these problems in the form of clipping paths, but that's a more complex subject for another day.
The bottom section of the Fill and Stroke dialog does have an effect at the group level. If you set the opacity or blur for a group, it applies to the whole group as a single object. This is in addition to any opacity or blur that has been applied to individual objects, which lets you create complex combinations of effects. In this image, the top row shows two groups, one with no opacity on its objects, and one with the green circle set to 50% opacity. The bottom row shows what happens when you then also apply an opacity of 50% to the group itself.
Rather than the opacity being applied to each individual object – as a fill color would be – the circles retain their individual opacities and then the group opacity is applied to the whole. The same rules apply for blurs: the individual objects are blurred first, then the group-level blur is applied to the whole collection.
It may seem counter-intuitive to have fill and stroke affect groups in one way, while blur and opacity affect them in a different way. In practice, it's something you get used to very quickly, and the artistic benefits of having multiple levels of opacity and blur easily outweigh any short-term confusion.
Groups are invaluable for gathering related objects together into a single easily-managed entity – such as the case of the snowman's hat at the start of this article. You could also create another group for the snowman's head, and a third for his body and arms. Moving him around on your drawing is now a lot simpler as there are only three objects to select and move, rather than the dozens you had to contend with previously. But we can make things simpler still by creating a group that is made up of our three existing groups. Just select all three and create a group in the same way that we did earlier in the article.
With a single group containing all the parts of our snowman, it's trivial to move him around. If you need to adjust the position or angle of his hat, just enter the group and you can interact with the three groups inside it. Select one of those and you can enter it again to get down to the individual objects. Inkscape lets you nest your groups as deeply as you like.
To exit a deeply nested group, you can use the same techniques as for a single group. To step back out of your groups one level at a time, you can double-click on a blank area of the canvas, or use the context menu's Go To Parent option. To jump directly to a particular level, you only need to click on another object or group that's at that level. Alternatively, you can use the layers pop-up on the status bar to jump straight to any ancestor group, or even right back up to the page level.
Nested groups follow the same rules as any other groups when it comes to fill and stroke colors, opacity and blur. Set a fill color on a nested group and all the objects, no matter how deeply nested, will be set to that color, but opacity and blur is applied to each object and group separately.
Although groups are an invaluable tool for managing complex drawings, they're not without their limitations. In particular, a group occupies a single 'slot' in the z-order stack – so you can't interleave the objects from one group with those from another. In this image, I've drawn a series of interleaved squares on the left. The right-hand image shows the result of combining just the red squares into a group: the entire group takes up just a single slot in the z-order, occupying the same slot as the topmost object in the group.
If you imagine these objects as a stack of paper sheets, it's a bit more obvious what's happened. The following image shows the interleaved sheets stacked on top of each other, followed by the rearrangement of the z-order once the red sheets are grouped together.
If you enter a group, you can rearrange the z-order of the objects, but only relative to one another. The group as a whole will always just take up a single slot. In this case, it means that the three red sheets are indivisible – you can't move one of the orange sheets between them without either ungrouping the red sheets, or moving the orange sheet inside the group as well. This limitation will prevent you from creating some groups that might otherwise be useful – a rope that snakes around both the front and back of another object couldn't be grouped as a single object – but in many other cases groups will simplify your use of Inkscape significantly.