Outils pour utilisateurs

Outils du site


issue155:inkscape

This month and next, I’m going to cover a couple of Inkscape features that have fallen through the gaps in my previous coverage. The first of these, disgracefully, dates back to the 4th instalment of this series, way back in 2012! In FCM#64, when describing the options in the Fill and Stroke dialog, I wrote: “Also being put off for later articles are the Unset Paint button that looks like a question mark, and the two splodges on the right of the Fill tab.” The Unset Paint button was eventually described in part 30 (FCM issue #90), when I covered its use with clones. But what of the “two splodges on the right of the Fill tab”? For clarity, let’s first take a look at a screenshot of the Fill and Stroke dialog, in which I’ve circled the splodges.

Ce mois-ci et le prochain, je vais parler de quelques fonctionnalités d'Inkscape qui sont passées à travers les mailles de mes articles précédents. La première d'entre elles, et c'est déplorable, date du 4e numéro de cette série, en 2012 ! Dans le FCM n° 64, en décrivant les options de la boîte de dialogue Remplissage et contour, j'écrivais : « Également repoussés à des articles ultérieurs, le bouton Remplissage indéfini qui ressemble à un point d'interrogation et les deux taches informes à droite de l'onglet Remplissage. »

Le bouton Remplissage indéfini a été finalement décrit dans la partie 30 (FCM n° 90), quand j'ai parlé de son utilisation avec les clones. Mais que dire des « deux taches informes sur la droite de l'onglet Remplissage » ? Pour la clarté, commençons par regarder un instantané du dialogue Remplissage et contour, dans lequel j'ai entouré ces deux pâtés.

To understand what effect these splodges – which are actually a pair of mutually exclusive radio buttons – have on your objects, we’ll need a path to test with. Not just any path will do, however. These buttons have an effect only on paths that are either self-intersecting, or which contain sub-paths. Let’s deal with the former to start with: what exactly do I mean by ‘self-intersecting’? Consider the paths below. The one on the left is just a simple U-shaped filled path. Nothing special, no sneaky tricks. Just 10 nodes forming a shape with a couple of arms. The shape on the right is just a duplicate of the first one, with the end of the left arm moved to the right, and the end of the right arm moved to the left, so the arms cross each other. No nodes were added or removed, they were just moved around a little.

Pour comprendre l'effet de ces taches - qui sont en fait une paire de boutons radio mutuellement exclusifs - sur vos objets, nous aurons besoin d'un chemin pour les tester. Cependant, pas n'importe quel chemin. Ces boutons n'ont d'effet que sur les chemins qui, soit s'auto-croisent, soit contiennent des sous-chemins. Prenons le premier pour commencer : qu'est-ce que j'entends par « qui s'auto-croisent » ?

Prenez les chemins ci-dessous. Celui de gauche est un simple chemin rempli en forme de U. Rien de spécial, pas de truc insidieux. Juste 10 nœuds donnant une forme avec deux bras. La forme de droite n'est que la copie de la première, avec la terminaison gauche déplacée sur la droite et la fin du bras droit déplacé à gauche, de sorte que les bras se croisent. Aucun nœud n'a été ajouté ou enlevé ; ils ont juste été un peu déplacés.

The second shape is a self-intersecting path. It’s a closed path that is drawn such that it crosses itself, although the word ‘crosses’ carries a misleading implication in this case. Remember that Inkscape is a 2D drawing program, with no notion of the third dimension. So when making this shape I didn’t really move one arm ‘over’ the other, as you would do when making the same shape with a piece of string. Rather I moved it ‘through’ the other, in the same 2D plane. Neither arm is on top of the other. Neither arm ‘crosses’ the other. Instead the resultant shape simply intersects with itself. Turning on the stroke and reducing the fill opacity makes this a little clearer:

La seconde forme est un chemin qui s'auto-croise. C'est un chemin fermé qui a été dessiné de sorte qu'il se croise lui-même ; le mot « croise » porte un risque de mauvaise interprétation dans ce cas. Souvenez-vous qu'Inkscape est un programme de dessin en 2D, sans aucune notion de troisième dimension. Aussi, en faisant cette forme, je n'ai pas vraiment passé un bras au-dessus de l'autre, comme je l'aurais fait en créant cette forme avec un morceau de ficelle. J'ai plutôt fait un déplacement de l'un « à travers » l'autre, dans le même plan 2D. Aucun des bras n'est au-dessus de l'autre. Aucun ne « croise » l'autre. À l'inverse, la forme résultante se coupe avec elle-même.

En activant le contour et en diminuant l'opacité du remplissage, ça devient un peu plus clair.

Notice how the stroke is visible for both arms. If one crossed over the other you might expect the stroke of the arm on the bottom to be obscured by the one that’s on top, but that’s not how things work in the 2D graphics world. You’d also expect the colour of the fill to be a little darker where the two translucent arms cross over, but that’s not the case either. It’s also important to note that the arms don’t have to completely pass through each other in order to be a self intersecting shape, and that the shape could self-intersect multiple times, as demonstrated in these variations on the theme:

Notez que le contour est visible pour les deux bras. Si l'un d'eux avait croisé l'autre, vous vous seriez attendu à ce que le contour du bras du dessous disparaisse sous le bras du dessus, mais ce n'est pas comme ça que les choses fonctionnent dans le monde de l'affichage en 2D. Vous vous seriez aussi attendu à ce que la couleur de remplissage devienne plus sombre là où leurs deux bras translucides sont l'un sur l'autre, mais ce n'est pas le cas non plus.

Il est aussi important de noter que les bras ne sont pas obligés de passer complètement l'un à travers l'autre pour être une forme qui s'auto-croise, et que la forme peut s'auto-croiser plusieurs fois, comme le montrent les variations sur ce thème.

Now we’re all clear on what a self-intersecting path actually is, let’s look at how they’re affected by the splodgy radio buttons. The first thing to note is that the images so far have all been taken with the second button selected – the one that’s completely filled in. Switch to the first button, and we get this: The basic U-shaped path remains unaffected. It’s not a self-intersecting path, and it doesn’t contain any sub-paths, so the radio buttons have no effect. All the others, however, have no fill rendered in the intersecting parts. The stroke is still drawn, but the fill isn’t.

Maintenant que tout est clair sur ce qu'est un chemin qui s'auto-croise, regardons comment ils sont affectés par les boutons radio informes. La première chose à noter, c'est que les images jusqu'à maintenant ont toujours été prises avec le second bouton sélectionné, celui qui est complètement rempli. Appuyez sur le premier bouton et vous obtenez ceci :

La forme de base en U reste inchangée. Ce n'est pas un chemin qui s'auto-croise et il ne contient aucun sous-chemin ; les boutons radio n'ont donc aucun effet. Cependant, tous les autres n'ont plus de remplissage affiché dans les zones de croisement. Le contour est toujours dessiné, mais pas le remplissage.

This behaviour is a little confusing at first. Surely the intersecting parts are inside the shape, so they should still be filled, right? Unfortunately our intuitive idea of in-and-out doesn’t always apply in the world of computer graphics. Instead there are different rules or heuristics for determining whether a point is inside or outside a shape – and the splodgy buttons are used to switch between a couple of those rules. Let’s take a look at paths with sub-paths to try to explain why there’s a need for this choice. When you look at the self-intersecting shapes above, it’s pretty obvious that the fully-filled option (second button) is the right choice most of the time. Imagine trying to draw a figure-of-eight, only to find that the part where the shape crosses itself is unfilled. Definitely better to use the second option, so we’ll ensure that’s selected. Now we’re going to draw a circle with a hole in it. There are a few ways to achieve this but, to make a point, I’m going to use a very specific method: • Draw a circle for the outside. • Draw a smaller circle for the inside. • Path > Combine to create a complex path, made up of two sub-paths.

Ce comportement est, au début, un peu troublant. Il est sûr que les parties qui se croisent sont dans la forme, aussi elles devraient être remplies, non ? Malheureusement, notre idée intuitive de dedans-dehors ne s'applique pas toujours dans le monde du dessin informatique. Au lieu de ça, il y a plusieurs règles ou heuristiques pour déterminer si un point est dans ou hors d'une forme, et les boutons informes sont utilisés pour passer de l'une à l'autre des règles. Regardons les chemins avec des sous-chemins pour essayer d'expliquer pourquoi ce choix est nécessaire.

Quand nous regardons les formes auto-croisées ci-dessus, il est assez évident que l'option du remplissage complet (deuxième bouton) est le bon choix la plupart du temps. Imaginez que vous essayez de dessiner une forme de huit, pour découvrir que la partie où la forme s'auto-croise a un remplissage indéfini. Il est clairement mieux d'utiliser la seconde option, aussi nous nous assurerons qu'elle est sélectionnée. Maintenant, nous allons dessiner un cercle avec un trou dedans. Il y a plusieurs façons d'y arriver, mais je vais faire exprès d'utiliser une méthode très spéciale : ••Dessinez un cercle pour l'extérieur. ••Dessinez un cercle plus petit pour l'intérieur. ••Chemin > Combiner pour créer un chemin complexe, fait de deux sous-chemins.

In this image (above) you can see the two separate shapes on the left, and the result of combining them in the middle. The ‘hole’ in the shape is filled – not really what we were after. Switching to the first button, however, gives the expected result, as shown in the version on the right. Now we’ve got a simple rule-of-thumb: use the left-hand button for paths with sub-paths, and the right-hand button for self-intersecting paths. But what if we have a path that is both self-intersecting and has a sub-path describing a cut-out? Something like this odd piece of jewelry or alien symbol, shown as it appears with each of the two splodgy radio buttons selected: On the left we have the problem of no fill in the self-intersecting part, but the hole is fine. With the right-hand button we get a fill in the self-intersecting part, but no hole. Is there any way we can have the best of both options?

Dans l'image ci-dessus, vous pouvez voir deux formes séparées sur la gauche, et le résultat de leur combinaison au milieu. Le « trou » dans la forme est rempli - pas vraiment ce que nous recherchions. Cependant, l'appui sur le premier bouton nous donne le résultant attendu, comme nous le voyons sur la version de droite.

Maintenant, nous obtenons une règle empirique simple : utiliser le bouton de gauche pour les chemins avec des sous-chemins et le bouton de droite pour les chemins qui s'auto-croisent. Mais que se passe-t-il si nous avons un chemin avec à la fois un auto-croisement et un sous-chemin décrivant une découpe ? Quelque chose comme cette bizarre pièce de joaillerie ou symbole alien, montrée telle qu'elle apparaît en sélectionnant l'un ou l'autre des boutons :

Sur la gauche, le problème est l'absence de remplissage dans la partie de l'auto-croisement, mais le trou est correct. Avec le bouton de droite, nous obtenons un remplissage de la partie auto-croisée, mais pas de trou. Y a-t-il un moyen d'obtenir le meilleur des deux solutions ?

The answer is obviously ‘yes’, but to get there it helps to understand what the two heuristics are that we’ve been switching between. The first button has a tooltip that reads “any path self-intersections or subpaths create holes in the fill”, and is referred to as the “even-odd” rule. The heuristic for this is pretty simple: • Pick a point in the shape. • Draw an imaginary straight line from that point out of the shape in any direction. • Keep a ‘crossing’ count, which starts at zero. • Add one to the count each time the line crosses a path or sub-path boundary. • If the final count is even, the point was outside the shape. If the count is odd, the point was inside the shape. By performing this for a point in each region of the shape, Inkscape can determine which areas are inside, and therefore need to be filled, and which are outside. But it does result in self-intersections being counted as outside, and left unfilled.

La réponse est évidemment « oui », mais pour y arriver, il est préférable de comprendre ce que sont les deux heuristiques entre lesquelles nous basculons. Le premier bouton a une info-bulle qui dit « Tout auto-croisement ou sous-chemin crée un trou dans le remplissage » et elle est nommée la règle « pair-impair ». L'heuristique de celle-ci est plutôt simple : ••Sélectionner un point de la forme. ••Dessiner une ligne droite imaginaire à partir de ce point de la forme dans une direction quelconque. ••Compter les points de croisement, en commençant à zéro. ••Ajouter un au compteur chaque fois que la ligne croise une limite de chemin ou de sous-chemin. ••Si le compte final est pair, le point était en dehors de la forme. Si le compte est impair, le point était à l'intérieur de la forme.

En réalisant cela pour un point de chaque zone de la forme, Inkscape peut déterminer quelles sont les zones intérieures, qui doivent donc être remplies, et celles qui sont dehors. Mais il en résulte forcément que les auto-croisements sont comptés comme extérieurs et laissés vides.

The second button has a tooltip that reads “fill is solid unless a subpath is counterdirectional”, and is referred to as the “non-zero” or “winding” rule. This heuristic relies on the fact that each sub-path has a direction associated with it, and works like this: • Pick a point in the shape. • Draw an imaginary straight line from that point out of the shape in any direction. • Keep a ‘winding count’ which starts at zero. • Each time the line crosses a path or sub-path, add one to the count if the path is crossing the line from left to right (clockwise from the perspective of the point) or subtract one if the path is crossing from right to left (counter-clockwise). • If the final count is zero the point is outside the shape, otherwise it is inside.

L'info-bulle du second bouton dit « le remplissage est solide sauf si un sous-chemin est en sens inverse » et elle s'appelle une règle du « non-zéro » ou de « l'enroulement ». L'heuristique se base sur le fait que chaque sous-chemin possède une direction propre, et fonctionne ainsi : ••Sélectionner un point dans la forme. ••Dessiner une ligne droite imaginaire à partir de ce point de la forme dans une direction queconque. ••Faire le compte des enroulements en commençant à zéro. ••Chaque fois que la ligne croise un chemin ou un sous-chemin, ajouter un au compteur si le chemin coupe la ligne de la gauche vers la droite (dans le sens horaire, vu du point) ou soustraire un si le chemin la coupe de la droite vers la gauche (anti-horaire). ••Si le résultat final est zéro, le point est en dehors de la forme ; autrement, il est interne.

From this algorithm and the mention of “counterdirectional” in the tooltip – you may have already worked out that using the second splodgy button (non-zero) lets us switch sub-paths between filled and unfilled by reversing the direction of the nodes. Fortunately for us, Inkscape makes this fairly easy: • Select the composite path and switch to the node tool (F2). • Select a node in the sub-path. • Use Path > Reverse to reverse the order of the nodes in the sub-path without changing the shape.

À partir de cet algorithme et de la mention « en sens inverse » de l'info-bulle, vous avez peut-être déjà déterminé que l'utilisation du deuxième bouton informe (non-zéro) vous permet de passer de sous-chemins remplis ou vides en inversant le sens des nœuds. Heureusement pour nous, Inkscape facilite cela : ••Sélectionnez le chemin composite et passez sur l'outil Nœuds (F2). ••Sélectionnez un nœud du sous-chemin. ••Utilisez Chemin > Inverser pour inverser l'ordre des nœuds du sous-chemin sans modifier la forme.

You can see the effect of this approach in the following image. In this case I’ve also added arrow markers to the paths, to clarify what’s happening. The first image is our starting path, created by combining an oval with a self-intersecting shape. You can see from the arrows that the sub-path is running counter-clockwise. In the second image I’ve reversed the direction of the sub-path, the arrows point the opposite way, and the shape has a hole for the sub-path but not for the self-intersection. Unfortunately this simple approach doesn’t appear to work in the beta of Inkscape v1.0, where the Path > Reverse operation reverses the entire path rather than the selected sub-path. The only option in this case is to use Path > Break Apart to split the shape down into its constituent parts, then use Path > Reverse on just one of those paths, then finally use Path > Combine to re-combine them back into your original complex path. This is a definite step backwards in the workflow, so I will be filing a bug about this on the Inkscape issue tracker.

Vous pouvez voir l'effet de cette approche dans l'image suivante. Dans ce cas, j'ai aussi ajouté des marques fléchées aux chemins, pour clarifier ce qui se passe. La première image est notre chemin initial, créé en combinant un ovale avec une forme auto-croisante. Vous pouvez voir grâce aux flèches que le sous-chemin circule dans le sens anti-horaire. Dans la seconde image, j'ai inversé la direction du sous-chemin ; les flèches sont dirigées dans le sens opposé, et la forme a un trou pour le sous-chemin et pas pour l'auto-croisement.

Malheureusement, cette approche simple ne semble pas fonctionner dans la bêta d'Inkscape 1.0 où l'opération Chemin > Inverser inverse tout le chemin plutôt que le sous-chemin sélectionné. Dans ce cas, la seule possibilité est d'utiliser Chemin > Séparer pour séparer les parties constituantes de la forme, puis Chemin > Inverser sur un seul de ces chemins et, enfin, Chemin > Combiner pour revenir au chemin complexe d'origine. C'est vraiment une régression dans l'enchaînement des tâches ; aussi, je remplirai un rapport de bogue à ce sujet sur le « tracker de problème » d'Inkscape.

This path-reversing approach works for simple shapes where the nesting of sub-paths isn’t very deep. For more complex arrangements you may need to reverse more than one path to get the effect you want. And if there are also intersections between sub-paths, or self-intersections within them, you may never be able to get just the fill you want, no matter what you try. In those cases you may find it easiest to use the first splodge (even-odd) to fill the entire shape, then create your complex hole arrangement by clipping with a suitably constructed path. It’s worth noting that you might never experience this problem. Punching a hole through a shape is more commonly done using Path > Difference than Path > Combine, and the former usually results in a sub-path going in the right direction. But it’s worth knowing about these splodgy buttons and how to work with them, just in case you ever find yourself presented with a path that contains inexplicable holes or fills where it shouldn’t.

Cette approche d'inverser le chemin fonctionne pour les formes simples où l'enfouissement des sous-chemins n'est pas trop profond. Pour les arrangements plus complexes, vous devrez peut-être inverser plus d'un chemin pour obtenir l'effet désiré. Et si d'autres intersections existent entre les sous-chemins, ou qu'ils aient leurs propres auto-croisements, vous pourriez ne jamais obtenir le remplissage que vous voulez, quelle que soit la façon de vous y prendre. Dans ces cas-là, vous pourriez trouver que le plus facile est d'utiliser le premier pâté (pair-impair) pour remplir toute la forme, puis de créer votre arrangement compliqué de trous par une découpe avec un chemin judicieusement placé.

Il est intéressant de noter que vous pourriez ne jamais tomber sur ce problème. Découper un trou dans une forme est une action plus classiquement faite avec Chemin > Différence qu'avec Chemin > Combiner, et la première a en général pour résultat un sous-chemin qui va dans la bonne direction. Mais il faut mieux connaître ses boutons informes et savoir comment ils fonctionnent, juste au cas où vous vous trouveriez devant un chemin qui contient des trous et ou des remplissages inexplicables là où ils ne devraient pas être.

issue155/inkscape.txt · Dernière modification : 2020/04/09 18:43 de andre_domenech