Outils pour utilisateurs

Outils du site


issue101:inkscape_partie_41

Ceci est une ancienne révision du document !


After last month's special celebratory detour, we return to finish the subject of aligning and positioning objects in Inkscape. We've already seen a variety of approaches, from grids and snapping through to tiled clones and the Align and Distribute dialog, but we still have two dialogs to consider. They both live near the bottom of the Object menu: “Transform…”, and “Arrange…” (“Rows and Columns…” if you're still using 0.48.x).

The Transform dialog provides a more precise approach to moving, scaling, rotating and skewing objects when compared with simply dragging the selection handles using the mouse. In the world of SVG, every object can have a transformation applied to it. Rotate or skew an object, then look at it in the XML editor and you'll see that there's no obvious “rotate” or “skew” attribute, but rather a single “transform” attribute which holds a matrix that defines the cumulative effects of any transformations you may have applied. The details of this matrix are a little too mathematically intense for this series, but it's enough to know that each object can have its own matrix applied, and that a single matrix can combine the effects of moving, scaling, rotating and skewing into a single set of numbers. The Transform dialog is essentially a more user-friendly way of tweaking that matrix.

On opening the dialog from the menu, or using the CTRL-SHIFT-M shortcut, you'll be presented with a simple interface featuring a handful of tabs, each with just a few fields. This dialog has seen little change between 0.48 and 0.91.

The fields on the Move tab allow you to move your selected objects by a specific distance, when the “Relative move” checkbox is enabled. Disable this, and you can move your objects to absolute x and y coordinates. In addition, the current absolute coordinates are displayed in the fields. With 0.91, just about every spinbox in Inkscape lets you enter simple calculations, so there's a good argument for never enabling this checkbox in that version. Want to move your shape 50 pixels to the right? Just append “+50” to the number in the “Horizontal” box, then hit Return and watch the field update with the newly calculated value.

Positions and movements are based on Inkscape's own coordinate system which has the positive y axis running upwards from the bottom of the page (remember, this is the opposite of SVG's coordinate system, which has the origin at the top left, with the positive y-axis running downwards). Similarly, the selected objects are placed such that the bottom left corner of the bounding box is at the specified coordinates, with no option to use a different corner, or even the center of the box as the reference point.

The “Apply to each object separately” checkbox is effectively the opposite of the “Treat selection as group” checkbox in the Align and Distribute dialog. If you select multiple objects and leave this un-checked, then the transformation will be applied as though all the objects were grouped. With it checked, each object is individually transformed. When relatively moving things, there's little difference, but, for an absolute move, it results in all the items being placed at the same position on the page. It's also particularly relevant when using the other tabs, where the results can differ significantly due to the state of this checkbox. Consider the Rotate tab: there's a huge difference between rotating a group of separate objects and rotating each object individually.

The Scale, Rotate and Skew tabs in this dialog really need no additional explanation as the fields are all straightforward to understand. It's important to note, however, that only the current tab's values are used when the Apply button is clicked. You can't queue up a collection of movement, rotation and skewing to apply as a single operation, but instead have to press the button with the Move tab to the fore, then again with the Rotate tab selected, and so on.

On the subject of the Rotate tab, there has been a slight change with version 0.91: this release adds buttons to determine whether rotations should be clockwise or anti-clockwise. The corresponding field accepts both positive and negative values in either release of Inkscape, so the buttons just make the existing functionality more obvious, rather than adding anything new.

The last tab, Matrix, allows you to directly manipulate the six values in the SVG matrix transformation. With the “Edit current matrix” checkbox enabled, you can modify the transform that's currently being applied to the selected element, if there is one. With this unchecked, any changes you make in this tab will be mathematically combined with the existing matrix to produce a new, cumulative matrix. If you are mathematically inclined, and wish to play around with this tab, I recommend reading the SVG specification for coordinate systems and transformations: http://www.w3.org/TR/SVG/coords.html

It's worth noting that SVG's transform attribute does allow for a series of individual translate(), scale(), rotate(), skewX() and skewY() functions to be used, rather than just the matrix() operation that combines them all. From an authoring perspective, it would be far nicer to store a 45° rotation in the SVG file as rotate(45), rather than matrix(0.707,0.707,-0.707,0.707,0,0), but there's no option in Inkscape to do that, unfortunately.

The last feature we'll consider in this part of the series is the dialog that can be found via Object > Rows and Columns… (0.48) or Object > Arrange… (0.91). The latter lays the interface out a little more neatly and adds a second tab, so I'll describe that version. 0.48 users should be able to work out the differences in the first tab, but you'll just have to look on in envy when I describe the Polar Coordinates options in the second.

Let's start by creating a few objects to arrange. I've deliberately used different sizes, and semi-randomly placed them. I've numbered them from left to right, top to bottom, to make it easier to see which object moves where – once they're arranged using the dialog.

On selecting these nine objects and opening the dialog, it's possible to set various combinations of rows and columns, ranging from 1×9 to 9×1. These fields are dynamic: as items are added to, or removed from the selection, the rows and columns will change; similarly as each field is manually altered so the other will change to ensure that you don't end up with an impossible combination for the number of elements that are selected. In this example, I've set the arrangement to 3 rows by 3 columns.

You can think of this dialog as creating a number of conceptual cells which are arranged in rows and columns, then your objects placed within them. They're “conceptual” in that they're never really created, or drawn, on the canvas, but serve as a tool to more easily describe how Inkscape arrives at its final layout. The height of each cell is determined by the height of the tallest object in the row, and the state of the Equal Height checkbox. If left unchecked, then the height of each row is free to change to suit the tallest object within it; if checked, all the rows will be the same height, equal to the tallest object in any of the rows. An analogous calculation is carried out to determine the width of each cell, too.

With the dimensions of each cell calculated, they are now distributed into their final positions. If the “Fit into selection box” radio button is active, they are evenly distributed to fit within the dimensions of the original selection's bounding box. This gives you the ability to distribute the objects within a specific area by carefully positioning two opposing corner objects.

Alternatively you can select the “Set spacing” option, and enter values for the X and Y fields. In this mode the cells will be arranged with the specified amount of space between the columns (X value) and rows (Y value). These numbers can be negative if you want to make the cells overlap. Note that 0.48 allows these numbers to be specified only in pixels whereas 0.91, as you can see from the screenshot, has a pop-up menu from which to choose different units.

With these imaginary cells conceptually placed on the canvas, it's finally time to move your objects into them. The “Alignment” buttons let you define how to place each object within its cell, allowing for any of nine relative positions (though you'll probably just use the center button most of the time). Note that 0.48 had the same nine possibilities available, but laid out as a pair of three-option radio buttons which specified the horizontal and vertical alignments separately.

Having distributed our virtual cells, and aligned the objects within them, the result is something like this: It's important to understand how Inkscape chooses the order for the arrangement. Whereas other parts of the application use an object's z-index or selection order, this dialog is only concerned with the placement of the objects on the canvas. They're ordered from left to right, top to bottom, and laid out in the same way. You can see this effect quite clearly if I move the blue “8” object up a little, leaving its z-index the same, then reapply the arrangement:

Because the objects are laid out from left to right, top to bottom, some arrangements can lead to an empty space in the bottom right corner. Here are the same nine objects in a 2×5 arrangement:

Note that there's no way to get the blank space to be anywhere other than the bottom right cell. If you want a different alignment you'll have to manually alter the results afterwards. It's also not possible to have more than one blank cell – the dynamic nature of the Rows and Columns fields will stymie any attempts. Trying to put these nine objects into a 2×6 arrangement, expecting six objects on the top row, and three on the bottom, just leads to the same result as before and the fields adjusting themselves to 2×5.

The second tab of this dialog allows you to place objects in a polar arrangement. You can either draw a circle, ellipse or arc as a guide on which to place your objects, or you can enter the parameters for such a shape within the dialog itself. The easiest way to do this is to draw a target shape (circle, ellipse or arc) that you wish to place your objects on. Send it to the bottom of the z-order, then select all the objects you wish to arrange plus the target itself. Ensuring that “First selected…” is active, click the Arrange button. With our previous selection of nine rounded rectangles, and a grey ellipse as the target, the result is something like this: As you can see, the objects have been arranged anti-clockwise, starting from the top right. To make them run clockwise from the top left, flip the ellipse horizontally first. For clockwise from the bottom right, flip it vertically. For anti-clockwise from the bottom left, flip it both horizontally and vertically before creating the arrangement.

If the target object is your only circle, ellipse or arc in the selection, it doesn't really matter whether you use the “First selected…” or “Last selected…” option. If you do have more than one, however, you should ensure that you select the target first, then add everything else to the selection (“First Selected…”) or select everything else, then add the target to the selection (“Last selected…”).

If you don't wish to create an additional object on the canvas to use as a target, the “Parameterized” option reveals additional fields (shown in the screenshot) to let you specify the details of the target arc to use. Realistically, it's almost always easier to draw an arc on the canvas to use as the target. You'll get visible feedback as to where your objects will be placed, and you can simply delete the arc once your arrangement is done, if you don't want it left in the drawing.

The specific position of each object on the target shape is set using the “Anchor point” section in the top half of the dialog. You can specify one of nine positions on the object's bounding box – so choosing the top-left button, for example, would position the objects such that the top-left corner of each individual bounding box is placed on the target. The center button is the most common choice here, and is the one I used for the previous image. An interesting alternative is to use the “Object's rotational center” option. This will position each object so that its rotational center is placed on the target, allowing you a finer degree of control over the placement of each individual object. The “Rotate objects” checkbox determines whether your objects will be rotated when they are arranged, or left with their original orientation. The previous image was made with this checked; had it been left un-checked, all of the positioned objects would have retained their original orientation, such that the numbers would all have been the right way up.

There's a small bug that you may have to work around: whilst writing this article, I found that the Polar mode would occasionally place all my objects on top of each other, rather than spacing them out around the target shape. I was able to reliably fix this by undoing the placement, then shifting the target object up (SHIFT-Up arrow), then back down to its previous position (SHIFT-Down arrow), before repeating my arrangement attempt.

That concludes our look at the myriad ways in which you can arrange and position objects within Inkscape. Amongst them there should be something to suit most artistic requirements. From snapping to grids, tiled clones to polar arrangements, Inkscape has far more ways to position your shapes than initially meets the eye.

issue101/inkscape_partie_41.1443477617.txt.gz · Dernière modification : 2015/09/29 00:00 de d52fr