Outils pour utilisateurs

Outils du site


issue122:inkscape

Ceci est une ancienne révision du document !


One area of functionality that has received a huge boost in 0.91 and 0.92 is finding and selecting objects. There are many situations in which you may need to find similar, or identical objects in a busy drawing, perhaps to delete or change them all at once. In previous versions, this was a chore, especially if you had to make the same selection multiple times. So let’s look at the various ways in which recent releases make this easier. I’m going to use this contrived grid of objects to give you a feel for how the new tools operate: The first few items all live under the Edit > Select Same submenu, and offer several different ways to select all items which share a particular visual style. To use any of them, you must first select one or more objects whose close relatives you wish to also select. As a first example, if I select the teal square at the top left of my grid, then use Edit > Select Same > Object Type, all the other squares are selected. In my image I’ve given the selected items a gold colored background to make them stand out a little better, but you won’t see that in normal use. One important thing to note is that selecting the same “object type” purely refers to the type of underlying Inkscape object – so squares and rectangles, or circles and ellipses, are considered equivalent. You can see this effect if I select the green star on the top line, then use Select Same > Object Type. Not only are the stars selected, but so are the triangles, as they were all created using the ‘star’ tool. Frustratingly, the select by type option doesn’t work terribly well with multiple items selected. If every object in the selection is already the same type, it will work to select the other objects of that type; but if any one of them is of a different type then, rather than selecting all the objects of either type, everything is de-selected instead.

Une partie fonctionnelle qui a reçu une forte poussée dans les 0.91 et0.92 est la recherche et la sélection des objets. Il y a de nombreuses situations dans lesquelles vous pouvez avoir besoin de trouver des objets similaires ou identiques dans un dessin chargé, peut-être pour tous les effacer ou les modifier d'un coup. Dans les versions précédentes, c'était une corvée, spécialement si vous deviez faire la même sélection de nombreuses fois. Aussi, regardons les différentes façons qui rendent ceci plus facile dans les publications récentes. Je vais utiliser cette grille d'objets peu naturelle pour vous donner un aperçu du fonctionnement des nouveaux outils :

Les quelques premiers éléments sont tous situés sous le sous-menu Éditer > Sélectionner même, qui offre plusieurs façons différentes de sélectionner tous les éléments qui partagent un même style visuel particulier. Pour utiliser n'importe lequel d'entre eux, vous devez d'abord sélectionner un ou plusieurs objets dont vous voudrriez aussi sélectionner les voisins proches. Comme premier exemple, si je sélectionne le carré bleu sarcelle en haut à gauche de la grille, puis que j'utilise Éditer > Sélectionner même > Type d'objet, tous les autres carrés sont sélectionnés. Dans mon image, j'ai attribué une couleur or au fond de mes objets sélectionnés pour mieux les faire ressortir, mais vous ne verrez pas ça en usage normal.

Une chose importante à noter que sélectionner le même « type d'objet » fait référence précisément au type d'objet Inkscape sous-jacent - ainsi, des carrés et des rectangles, ou des cercles et des ellipses, sont équivalents. Vous pouvez voir cet effet si je sélectionne l'étoile verte sur la ligne du haut, puis utilise Sélectionner même > Type d'objet. Non seulement les étoiles sont sélectionnées, mais aussi les triangles, car ils sont créés en utilisant l'outil « Étoile ».

C'est frustrant ; l'option de sélection par type ne fonctionne pas terriblement bien avec de nombreux objets sélectionnés. Si chaque objet de la sélection est déjà du même type, ça marchera pour sélectionner les autres objets du même type ; mais, si l'un des objets est d'un type différent, alors, plutôt que de sélectionner tous les objets de l'un des types, à la place, tout est désélectionné.

Select Same > Fill Color has no such problem: if I have both the teal square and the green star selected, then all the objects with a teal or green fill will be selected by the command. Note, however, that selecting by color is extremely specific: it will only select items whose fill color is absolutely identical to your starting object. There’s no way to set a threshold, in order to select all the items with approximately the same shade of green, for example. There’s also a Select Same > Stroke Color option, which does the same thing, with the same exacting requirements for a match, but based on the stroke color rather than the fill color. For example, selecting the teal square once again (before executing the command) will select all the shapes on the top and bottom rows; they all have a black stroke, even though the stroke thickness and dashes are different between them. Once again, starting with a multiple selection will result in a cumulative set of items whose stroke colors match any of the objects in your initial line-up. The counterpoint to selecting by stroke color is to select by Stroke Style. This matches objects only if they have the same stroke thickness and dashes – including the same dash offset, which seems a little strict, in my opinion. Stroke color, line caps, join type and markers don’t seem to have an effect, whereas the mitre limit does. The choice of what properties do and don’t contribute to a “matching” line style seem rather arbitrary and counter-intuitive, which may limit the usefulness of this option in many situations. Even more limiting, however, is the Select Same > Fill and Stroke menu entry. This will match items only with an identical stroke, but where both the fill and stroke colors also match. It’s the digital equivalent of a club doorman not only refusing entry for wearing sneakers, but actually only allowing entry to people with exactly the same shoes as him, in the same color and style – and only then if they’re also the same size.

The next tool we’ll look at this month is the recently souped-up Find/Replace dialog, which can be opened from the Edit menu or by pressing Ctrl-F. The key to working with this dialog effectively is to understand that all it’s really doing is a search (and possibly a replace) of text within the XML code that makes up an Inkscape document. So, first, a quick recap on XML using a heavily abridged snippet of code representing a text object in Inkscape: <text id=“text1178”> <tspan id=“tspan1180” style=“font-style:normal; font-weight:bold; font-family:Arial; -inkscape-font-specification:'Arial Bold'; fill:#000000;” x=“320.68646” y=“86.745667”> This is some text </tspan> </text> XML represents a tree structure in text. Here you can see that we have an opening <text …> element, which gets closed by the </text> line at the end. Inside of that is a single <tspan …> element, again being closed near the end. Inside that is the text itself, “This is some text”. This is between the opening and closing <tspan> tags, but is not a tag itself. This piece of literal text is what XML refers to as a ‘text node’, whereas <tspan> and <text> are ‘element nodes’. The element nodes also have name=value pairs of extra data, referred to as ‘attributes’. In the <text> node, for example, the id=“text1178” is an ‘id’ attribute, with a value of “text1178”. The ‘style’ attribute is a little special – it holds CSS style data, which itself takes the form of a list of ‘property:value;’ pairs. With that information in mind, let’s take a look at the Find/Replace dialog, with its Options section expanded:

As you might expect from a Find/Replace dialog, the first two fields allow you to type in text to be searched for and, optionally, text to replace it with. The search will match against substrings, unless the ‘Exact Match’ checkbox is ticked, so searching for “Fred” will match against Fred, Freda, Winifred and Alfred – although the latter two will match only if the ‘Case Sensitive’ checkbox is cleared. Interestingly, you can search with this field left blank. As you might guess, an empty string matches against everything, but the match is further restricted by the choices in the ‘Object types’ section at the bottom. Usually you would probably leave this set to ‘All types’, but, by setting specific checkboxes and leaving the search field blank, it provides a fast way to select all the objects of specific types – a workaround for the Select Same > Object Type’s restriction on finding only one type at a time. Assuming the more common case, where a search string is entered, the ‘Search in’ radio buttons determine whether the XML text nodes will be searched, or the attributes on the element nodes (though the latter is labelled as ‘Properties’ in the Inkscape UI). Use the former to search and replace text content – handy if you’re using Inkscape as a poor-man’s desktop publishing program (though I do recommend that you learn how to use Scribus if you need to do any significant text layout work). Use the ‘Scope’ buttons, and the checkboxes in the ‘General’ section to limit your search a little, if necessary. Switching the ‘Search in’ control to ‘Properties’ provides a great deal more power, if you’re comfortable enough with the insides of an SVG file to know what to look for. By ‘Properties’ it means attributes and attribute values, including CSS properties. Making a distinction between these terms might seem a little petty, but understanding them is key to making effective use of this section of the dialog. There you’ll find checkboxes to tell Inkscape which parts of the XML it should search: • ID – Only search the value of the ‘id’ attributes. • Style – Search for CSS properties and CSS values within the value part of ‘style’ attributes. • Font – Presumably this searches for only CSS font names, but I was unable to get it to work at all on my test file. Use a ‘Style’ search instead. • Attribute Value – Search within the values of attributes. This includes searching the values of id and style attributes, even if the earlier checkboxes are blank. • Attribute Name – Search for elements with a particular attribute name. Not as useful as searching for values.

Usually, searching for an attribute value is sufficient. It will find matching IDs, styles and font names, without you having to understand how they’re stored in the XML. Only if it finds too much, is it worth switching to search only IDs or styles. Searching for attribute names is never really necessary for normal users, but might have its place if you’re using Inkscape to work on graphics for a web application that carry additional custom metadata. There are a couple of things to beware of when using this dialog in ‘Properties’ mode, however. Firstly, it can end up selecting objects you didn’t expect. Consider an element with a red stroke; later you change the stroke width to zero, so it isn’t visible any longer. If you search for “#ff0000” hoping to select all the elements with a red fill, you’ll also select the object with no stroke. Although it might not be visible, there will still be a color stored for the stroke in the style attribute, which is enough for it to become part of your selection. The second warning is with regard to the ‘replace’ field: performing a find and replace in text mode is generally safe; doing so in properties mode could have unforeseen results. Thankfully, Inkscape is sensible enough to stop you performing a replace operation if the ‘Attribute name’ checkbox is selected, but arbitrarily replacing strings within attribute values can be almost as destructive. It might seem safe enough to replace your black fills with white, by searching for “000000” and replacing it with “ffffff”, but a series of six zeroes could easily appear in the coordinates of your objects, where hexadecimal values are an error that could break your entire drawing. If in doubt, save a backup of your file first.

Having used the previous tools to make a selection, Inkscape now also provides a way to save that selection for later use. The Object > Selection Sets… menu item opens a rather empty dialog for managing stored collections of selections: The most important thing to note about this dialog is that the “+” button at the bottom does not create a set containing your current selection. Instead it creates a new, empty selection set which has another “+” button next to it. Only when you click this other button will your selection be stored in the set. The same button can be used later to add another selection to any existing items in the set. If you click on the triangle next to a set, hoping to view the elements within it, you’ll quickly find that there’s a rather useless intermediate level, labelled “Items”, that you also have to expand. If you click the triangle next to the “Items” entry to expand it, you’ll finally get to a list of the objects in your selection. Clicking on the cross next to an item in the list will remove it from the set. Clicking on a name in the list will select it, whereas clicking on the Set itself will select all the items in that set. Unfortunately, clicking on a Set doesn’t highlight all the items within it, so, if you want to re-select all the items except one, for example, you have to highlight each entry separately whilst holding the CTRL-key. You can even use the CTRL-key to select multiple Sets, or combinations of Sets and individual items. What you can’t do, however, is select something from this dialog, then add to (or remove from) the selection by CTRL-clicking on objects on the canvas, which is a pity as it effectively turns Selection Sets into a separate selection mechanism rather than something which integrates seamlessly into your normal Inkscape workflow. Selection sets are preserved when you save a document, however they do get cleared when the Edit > Clean Up Document menu is used. Nevertheless, they have their uses – for example, as another means to work around the restriction on Select By Type only working with a single type at a time. If you want to select, say, all the circles and rectangles, you could use the Select By Type option twice, adding each resultant selection to the same Set. The new and extended selection tools in 0.92 are a welcome addition, especially when working with complex documents. They do have their limitations and idiosyncrasies, but hopefully they’ll continue to mature in future releases to provide even more capabilities.

issue122/inkscape.1499582946.txt.gz · Dernière modification : 2017/07/09 08:49 de d52fr