Outils pour utilisateurs

Outils du site


issue103:tutoriel_5

Before we delve too much further into Live Path Effects, there are some implementation details that are worth pointing out. The first is that LPEs don't exist in the SVG specification. They're an Inkscape-specific thing, and no browser or other SVG editor knows how to render them. Go on, give it a try. Create a nice chain of gears, or a Spiro path, then save your SVG file. Open it in a modern web browser and see what you get. Here's my file, opened in Firefox. Well, it certainly looks like my original Inkscape file, but how can that be if the browser doesn't know anything about LPEs? The answer can be found by looking at the XML code for the file, either via Inkscape's XML editor (Edit > XML Editor, or CTRL-SHIFT-X), by viewing the page source in your browser (CTRL-U in Firefox), or simply by opening your SVG file in a text editor. You'll see that the main body of the image is made up of an SVG <path> element. The “d” attribute contains a series of letters and coordinates that tells an SVG-aware application how to draw the final path, after any visible LPEs have been applied. It's like a snapshot of the result, in a format that your browser understands. Notice that there are some other attributes, in the “inkscape” namespace. In particular you'll find “inkscape:original-d”, which holds the path definition of the original, skeleton path. There's also an “inkscape:path-effect” attribute, which holds a semicolon-separated list of XML IDs. These refer to <inkscape:path-effect> elements up in the <defs> section of the XML, which is where all the parameters for your effects are stored.

Avant d'aller plus loin dans les Effets de chemin (LPE - Live Path Effect), il vaut mieux montrer quelques détails d'implémentation. Le premier est que les effets de chemin n'existent pas dans la spécification SVG. Ce sont des choses spécifique à Inkscape et aucun navigateur ou autre éditeur SVG ne sait comment les rendre. Allez-y - essayez. Créez une jolie chaîne d'engrenages, ou un chemin Spiro, puis sauvez-le dans un fichier SVG. Ouvrez-le dans un navigateur Internet moderne et examinez le résultat. Voici mon fichier, ouvert dans Firefox.

Bon, il ressemble à mon fichier Inkscape original, mais comment cela peut-il être le cas si mon navigateur n'y connaît rien en effets de chemin ? La réponse peut être trouvée en regardant le code XML du fichier, soit via l'éditeur XML d'Inkscape (Éditer > Éditeur XML ou CTRL-MAJ-X), soit en regardant le code source dans votre navigateur (CTRL-U dans Firefox), ou simplement en ouvrant votre fichier SVG dans un éditeur de texte. Vous verrez que le corps principal de l'image est fait d'un élément SVG <path>. L'attribut « d » contient une série de lettres et de coordonnées qui indique à une application compatible SVG comment dessiner le chemin final, après que tous les effets de chemin visibles ont été appliqués. C'est comme un instantané du résultat, dans un format que le navigateur comprend.

Notez qu'il y a d'autres attributs, sous le nom d'espace « inkscape ». En particulier, vous trouverez « inkscape:original-d » qui contient la définition du chemin d'origine, le chemin squelette. Il y a aussi un attribut « inkscape:path-effect », qui contient une liste d'identifiants XML, séparés par des points-virgules. Ceux-ci font référence aux éléments <inkscape:path-effect> plus haut dans la section <defs> du XML, l'emplacement où tous les paramètres de vos effets sont stockés.

So, in summary, Inkscape uses the “original-d” attribute and <path-effect> elements to hold all the information it needs to draw the LPE. Other applications use the “d” attribute to render a snapshot of the final path, with the LPE applied. When you modify an LPE within Inkscape, it automatically updates the “d” attribute to match the rendered output, so other applications should always be able to display your drawing as intended, even though they don't know anything about LPEs. Inkscape doesn't always do a great job of clearing out unused elements in the <defs> section of a file, and path effect definitions are no exception. If you add and remove a number of LPEs whilst experimenting with your drawing, old definitions tend to build up there. They don't do any harm, but do slightly increase the size of the file. You can clear them out, together with other unused definitions, by using the File > Clean Up Document menu entry (File > Vacuum Defs on 0.48). Because Inkscape calculates the final path from the original path and LPE parameters, using live path effects places more of a burden on the processor, resulting in slower rendering speeds. Usually this isn't an issue, but when zooming into a very complex drawing it can become noticeable. If you're happy with the LPE output, and don't need to change it any further, you can “fix” the path so that it looks the same, but is no longer based on path effects. Essentially this process just removes the Inkscape-namespaced attributes from the path element, leaving it with just the same “d” attribute that any other application uses. To do this, simply use the Path > Object to Path menu entry (CTRL-SHIFT-C). It may seem odd to use Object to Path on something that's already a path, but think of it as converting an LPE path to a plain SVG path, and it makes more sense. Like any other Object to Path conversion this is a strictly one-way affair, so make sure you keep a backup of the file from just before the change, in case you subsequently find you need to modify your LPE parameters after all.

Donc, en résumé, Inkscape utilise l'attribut « original-d » et les éléments <path-effect> pour contenir toute l'information dont il a besoin pour tracer l'effet de chemin. Les autres applications utilisent l'attribut « d » pour restituer un instantané du chemin final, l'effet de chemin étant appliqué. Quand vous modifiez un effet de chemin dans Inkscape, l'attribut « d » est automatiquement mis à jour pour correspondre à la sortie rendue, de sorte que les autres applications pourront toujours afficher votre dessin comme il faut, même s'ils ne connaissent rien aux effets de chemin.

Inkscape ne fait pas toujours un bon travail de suppression des éléments inutilisés dans la section < defs > du fichier, et les définitions des effets de chemin ne font pas exception. Si vous ajoutez et supprimez pas mal d'effets de chemin pendant que vous testez votre dessin, les vieilles définitions ont tendance à s'accumuler. Elle ne causent aucun dommage, mais elle font augmenter légèrement la taille du fichier. Vous pouvez les effacer, avec les autres vieilles définitions, en utilisant Fichier > Nettoyer le document (Fichier > Nettoyer les Defs, dans la 0.48).

Parce que Inkscape calcule le chemin final à partir du chemin initial et des paramètres des effets de chemin, l'utilisation de ces derniers charge le processeur davantage, d'où une vitesse de restitution plus lente. En général, ce n'est pas un problème, mais en agrandissant un dessin très complexe, cela peut devenir visible. Si vous êtes content de la sortie de l'effet de chemin, et que vous n'avez plus besoin de faire de nouvelles modifications, vous pouvez « fixer » le chemin ; ainsi, il paraît identique, mais il n'est plus basé sur les effets de chemin. En gros, ce processus enlève juste les attributs du nom d'espace inkscape de l'élément de chemin, lui laissant seulement le même attribut « d » qu'utilisent les autres applications. Pour faire cela, utilisez simplement l'entrée de menu Chemin > Objet vers Chemin (CTRL-MAJ-C). L'utilisation d'Objet vers Chemin pour quelque chose qui est déjà un chemin peut paraître bizarre, mais dites-vous qu'il convertit un chemin LPE en chemin SVG brut, et cela aura plus de sens. Comme n'importe quelle autre conversion d'Objet en Chemin, c'est une opération sans retour ; assurez-vous de garder une copie de sauvegarde de votre fichier, faite juste avant l'opération, au cas où vous découvriez après coup que vous avez besoin de modifier les paramètres des effets de chemin.

That's enough behind-the-scenes detail for now, let's press on with another path effect! As usual we'll need a path to work on, so let's start by drawing a simple arrow shape. The path effect we'll look at this time is “Bend”, so add that to your path following the instructions from the previous instalment. As before, there's no immediate change to your image, but the LPE dialog has gained a few controls at the bottom. Of particular note is this quartet of buttons: This arrangement of buttons appears frequently in LPEs, whenever an extra path is required as part of the input parameters. In the case of the Bend effect, two paths are required: the original skeleton path (the arrow shape, in this case), and a bend path whose shape dictates how the skeleton path should be distorted. These buttons are for managing the bend path, as follows: • The first button allows you to edit the bend path directly on the canvas. This is the most commonly used of the four. • The second button lets you copy the bend path to the clipboard. From there you can paste it into another LPE, or even paste it directly into the canvas as a new path in its own right. These copies maintain no connection to the original bend path. • The third button is for pasting a path to use as the bend path. This could be one that you've copied from another LPE using button two, or it could be a path you've constructed elsewhere in your canvas. Again, there's no connection maintained to the original path. • The final button lets you link to an existing path, rather than create a new bend path. In this case there is a live connection to the original path, so any changes you make to that are immediately reflected in the LPE. I'll discuss this button in more detail a little later.

Pour le moment, c'est assez sur les détails de cuisine, poursuivons avec un nouvel effet de chemin ! Comme d'habitude, nous avons besoin d'un chemin pour travailler dessus ; aussi, commençons par dessiner une simple flèche.

Nous allons regarder l'effet de chemin « Courber » ; ajoutez donc cela à votre chemin en suivant les instructions de l'épisode précédent. Comme d'habitude, il n'y a pas de changement instantané de votre image, mais quelques contrôles supplémentaires ont été ajoutés en bas de la boîte de dialogue. Nous pouvons noter particulièrement les quatre boutons suivants :

Cette disposition de boutons apparaît fréquemment dans les effets de chemin, à chaque fois qu'un chemin supplémentaire est nécessaire comme partie des paramètres d'entrée. Dans le cas de l'effet Courber, il faut deux chemins : le chemin squelette d'origine (la flèche, ici) et un chemin de courbure dont la forme détermine la manière dont le chemin devrait être déformé. Ces boutons-ci gère le chemin courbé de la façon suivante :

• Le premier bouton vous permet de modifier le chemin « de courbure » directement sur le canevas. C'est le plus utilisé des quatre. • Le second bouton vous permet de copier le chemin de courbure dans le presse-papier. De là, vous pouvez le coller dans un autre effet de chemin, ou même le coller directement sur le canevas comme un autre chemin indépendant. Ces copies ne gardent aucune connexion avec le chemin de courbure d'origine. • Le troisième bouton est pour coller un chemin à utiliser en chemin de courbure. Ce peut en être un que vous avez copié d'un autre effet de chemin en utilisant le bouton deux, ou ce peut être un chemin que vous avez mis en place à un autre endroit du canevas. Là encore, aucune relation n'est conservée avec l'original. • Le dernier bouton vous permet de faire un lien avec un chemin existant, plutôt que de créer un nouveau chemin de courbure. Dans ce cas, il y a un connexione vivante avec l'original, ce qui fait que tout changement est reflété immédiatement dans l'effet de chemin. Je présenterai ce bouton plus en détail tout à l'heure.

If you press the first button you should find that a straight green path appears on the canvas, directly over your skeleton path. This is the bend path, and you can manipulate it in the same way as any other. Try dragging the path itself, or use the node handles, to distort its shape, noticing how the skeleton path is morphed in real-time to match your changes. You can also move the nodes themselves, in order to stretch, compress or rotate the skeleton path. If the bend path disappears – usually due to a mis-click causing the skeleton path to become selected – just click on the first button of the quartet in the LPE dialog to make it reappear. With barely any effort the Bend path effect can turn your straight arrow into a curved or sinuous shape that would take a lot more time and work to produce using normal path editing techniques: But there's more! Your bend path doesn't have to be limited to a pair of end nodes connected by a curve. You can add extra nodes, turn them into corners, mix straight and curved sections, have the path double-back on itself, or even split it into several sub-paths. Admittedly, getting too complex with your bend path can lead to a degree of contortion that's hard to control, but the options are there for you to explore. Using the second and third buttons you can copy and paste the bend path from one LPE to another, which can be handy if you want several skeleton paths all distorted in the same way. Each bend path will be an independent copy, though, so changes to one won't affect the others. Sometimes it's useful to have multiple bend paths all linked to a single “master” path, such that changes to the shape of the master are immediately reflected in each individual LPE. The fourth button allows you to achieve that effect, but it's not without its difficulties.

Si vous appuyez sur le premier bouton, vous devriez trouver qu'un chemin droit vert apparaît sur le canevas, directement sur le chemin squelette. C'est le chemin de courbure, que vous pouvez manipuler comme n'importe quel autre chemin. Essayez de le tirer, ou d'utiliser les poignées des nœuds, de distordre sa forme et notez comme le chemin squelette se déforme en temps réel pour se modifier de la même façon. Vous pouvez aussi déplacer les nœuds, de manière à étirer, comprimer ou tourner le chemin squelette. Si le chemin de courbure disparaît - en général suite à une erreur de clic qui sélectionne le chemin squelette - il suffit d'appuyer de nouveau sur le premier des quatre boutons de la boîte de dialogue des effets de chemin pour le faire réapparaître. Pratiquement sans effort, l'effet de chemin Courber peut tordre votre flèche droite dans une forme incurvée ou sinueuse et dont la réalisation demanderait beaucoup plus de temps et de travail en utilisant les techniques normales de modification des chemins :

Mais il y a plus ! Le chemin de courbure ne se limite pas aux deux nœuds terminaux reliés par une courbe. Vous pouvez ajouter des nœuds supplémentaires, les faire tourner en angles, mélanger des segments droits et courbes, faire rebrousser le chemin sur lui-même et même le couper en sous-chemins. Certes, une trop grande complexité de votre chemin de courbure peut conduire à un degré de distorsion difficile à contrôler, mais les options sont disponibles et vous pouvez les explorer.

Avec les second et troisième boutons, vous pouvez copier et coller le chemin de courbure d'un effet de chemin à un autre, ce qui peut être pratique si vous voulez que plusieurs squelettes soient déformés de la même manière. Cependant, chaque chemin de courbure sera une copie indépendante, de sorte que les modifications de l'un n'affecteront pas les autres. Parfois, il est utile d'avoir plusieurs chemins de courbure qui soient liés à un chemin « maître » unique, de sorte que les changements de la forme du maître soient immédiatement reflétés dans chaque effet de chemin individuel. Le quatrième bouton vous permet d'obtenir cet effet, mais ce n'est pas sans difficultés.

For this example I'm going to use two different kinds of arrow, and I want to apply the Bend LPE to both of them such that they follow the shape of the green path at the bottom of the image. The first step is to select the green path and copy it to the clipboard. As well as copying the path data itself, Inkscape also stores a reference to the original object. Next I need to select one of the arrows, add the Bend LPE, and click on the fourth button to use the stored reference to define the bend path. Clicking this button has two immediate effects: the arrow is distorted to match the bend path, as expected, and the arrow is moved to the same location as the bend path – which is not what I wanted! If I add a Bend LPE to the second arrow and link that to the bend path, that also gets moved. I've got all the right shapes, but not necessarily in the right locations. At first this might seem like a fairly trivial problem. Just drag the arrows back to where you want them, right? Unfortunately that doesn't work – drag them away and they'll spring right back to the location of the bend path. Drag the bend path away, and they both follow along after it. Being able to link to a common path seems a lot less useful if it means that your linked shapes all have to sit on top of each other. Fortunately there are a couple of ways around this problem. Inkscape has a setting hidden away in Edit > Preferences > Behaviour > Transforms labelled as “Store Transformation”, with options of Optimised or Preserved (it's in File > Inkscape Preferences > Transforms on 0.48). Use Optimised and you'll see the behaviour I've described above – LPE paths strongly bound to their linked bend path. Set it to Preserved, however, and you can move them around with impunity. Of course there's a trade-off: Optimised results in slightly smaller, more efficient files, whereas Preserved potentially stores additional data for any object that's been transformed, not just the ones that are causing us problems.

Pour cet exemple, je vais utiliser deux types de flèches différents et je veux appliquer l'effet de chemin de courbure aux deux de sorte qu'ils suivent la forme du chemin vert en bas de l'image. Tout d'abord, sélectionnez le chemin et copiez-le dans le presse-papier. Tout en copiant les données du chemin, Inkscape stocke aussi une référence à l'objet original. Ensuite, je dois sélectionner une des deux flèches, ajouter l'effet de chemin de courbure et cliquer sur le quatrième bouton pour utiliser la référence stockée comme définition du chemin de courbure. Le clic sur ce bouton a deux effets immédiats : la flèche est distordue pour correspondre au chemin de courbure, comme attendu, et la flèche est déplacée sur le même emplacement que le chemin de courbure - ce qui n'était pas ce que je voulais ! Si j'ajoute un effet de chemin de courbure à la seconde flèche et la lie à ce chemin de courbure, elle va aussi bouger. J'aurais obtenu les bonnes formes, mais pas vraiment à la bonne place.

De prime abord, ça peut paraître comme un problème plutôt anodin. Il n'y a qu'à ramener les flèches vers les positions souhaitées, n'est-ce pas ? Malheureusement, ça ne marche pas, écartez-les et elles vont revenir de suite à la position du chemin de courbure. Tirez le chemin de courbure et les deux flèches le suivent. Cette possibilité de lier à un chemin commun semble un peu moins utile si ça implique que les formes liées se superposent toutes.

Heureusement, Il y a des façons de régler ce problème. Inkscape a un réglage caché dans Éditer > Préférences > Comportement > Transformations, libellé « Enregistrement des transformations », avec les options Optimisé ou Préservé ((dans la 0.48, Fichier > Préférences d'Inkscape > Transformations). Avec Optimisé, vous obtenez le comportement décrit ci-dessus, les chemins LPE sont liés fortement à leur chemin de courbure. Choisissez Préservé et vous pouvez les bouger en toute impunité. Bien sûr, il y a des inconvénients : Optimisé induit des fichiers légèrement plus petits, plus performants, alors que Préservé stocke parfois des données supplémentaires pour chaque objet transformé, pas seulement ceux qui nous ont posé des problèmes.

If you want to leave the setting as Optimised, there is a second alternative which allows you to add extra data to just the problem paths. It's a little counter-intuitive, but it does the job perfectly: just select your path and add a second Bend effect to it. You don't even have to modify the bend path – just adding the effect is enough to let you drag your path around independently of the linked bend path once more. Whichever approach you take, you should now have two separate, independently positioned arrows, both of which are linked to the shape of the master bend path. Modify that path and you'll see the arrows shape change accordingly. If you don't want to see the bend path in your final design, simply hide it behind another object, set its opacity to 0 (use View > Display Mode > Outline to find it again) or just move it onto a hidden layer. The remaining controls for the Bend LPE are fairly simple. The Width spinbox lets you control the scaling of the skeleton path, perpendicular to the bend path. Play with it to see the effect. The “Width in units of length” checkbox has a slightly misleading title: “keep width proportional to length” would be a better name. Check this, and the width of the path is scaled as the length of the bend path changes; leave it unchecked to keep the width unchanged regardless of the shape of the bend path or the position of the end nodes. The final checkbox is quite self-explanatory: if you wish to bend a path that's more vertical than horizontal (e.g. an upwards facing arrow), then check this box, otherwise you'll be distorting along the width of the shape, rather than its length.

Si vous voulez laisser le réglage sur Optimisé, une deuxième alternative vous permet d'ajouter des données supplémentaires, juste aux chemins qui posent problème. Elle est tout sauf intuitive, mais elle fait bien son boulot : il suffit de sélectionner votre chemin et de lui ajouter un second effet de courbure. Vous n'avez même pas besoin de modifier le chemin de courbure - le simple fait d'ajouter l'effet est suffisant pour déplacer votre chemin indépendamment des chemins de courbure qui lui sont liés.

Quelle que soit l'approche choisie, vous devriez avoir maintenant deux flèches séparées, aux positions indépendantes, et liée chacune à la forme du chemin de courbure maître. Modifiez celui-ci et vous verrez les formes des deux flèches évoluer de même. Si vous ne voulez pas voir le chemin de courbure dans votre dessin final, cachez-le simplement derrière un autre objet, mettez son opacité à 0 (utilisez Affichage > Mode d'affichage > Contour pour le faire réapparaître) ou déplacez-le sur un calque caché.

Les contrôles restants de l'effet de courbure sont plutôt simples. Le champ numérique Largeur permet le contrôle de l'échelle du chemin squelette, perpendiculairement au chemin de courbure. Jouez-en pour voir l'effet. La case à cocher « Largeur en unités de longueur » a un titre un peu perturbant : « conserver une largeur proportionnelle à la longueur » aurait été un meilleur titre. Cochez-la et la largeur du chemin est à la même échelle que la longueur lors des modifications de celle-ci ; ne la cochez pas pour garder la largeur inchangée quelle que soit la forme du chemin de courbure ou la position des nœuds terminaux. La dernière case à cocher se comprend d'elle-même : si vous souhaitez courber un chemin qui est plus vertical qu'horizontal (par ex. un flèche vers le haut), cochez bien cette case, sinon vous déformeriez la largeur plutôt que la longueur de la forme.

The Bend LPE is one that's well suited for use with text, to produce the sort of “Word Art” effects so beloved of parish newsletters in the 1990s. Because LPEs won't work directly on a text object, you first have to perform the one-way conversion of your text into a complex path. Using Path > Object to Path will result in a group of individual paths, one for each letter. We really want a single path encompassing the whole text, so it's easier to use Path > Combine, which will convert your text into paths, and combine them into a single complex shape, all as one operation. The final result will be a group of one object, so you'll probably want to ungroup as well. From there you're free to add a Bend effect and distort your text as you would with any other path. Before you race off to convert your text into a path, however, it's worth considering the downside: the shape is no longer a text object, so you can't subsequently edit the content if you find a mistake. Often a similar result can be obtained by drawing a separate bend path, then selecting both your text and path before using Text > Put on Path. You may need to manually kern some of the characters to get the right result (see part 11), but it has the distinct advantage of keeping your text editable. In this image the red text was converted to a path and bent, the green is the same text put onto a copy of the bend path, and the blue is the same as the green, but with some manual kerning applied. One noticeable difference between the approaches is that the LPE distorts the shape of the letters, whereas text-on-a-path maintains their original shapes. Sometimes the distortion effect is desirable, in which case I can only recommend that you save a copy of the file just prior to converting to a path, in case you do need to edit it later. Next time we'll move beyond simple path bending and into the kind of full-on distortions that can turn some simple text into a 1970s album title, as we continue to look at Inkscape's live path effects.

L'effet de chemin Courber est un de ceux qui conviennent à des textes, pour réaliser une sorte d'effet d'« art du mot » tant apprécié par les bulletins paroissiaux des années 90. Comme les effets de chemin ne fonctionnent pas directement sur un objet texte, vous devez d'abord définitivement convertir votre texte en chemin complexe. Le résultat de l'utilisation de Objet > Objet vers Chemin sera un ensemble de chemins individuels, un par caractère. Nous souhaitons n'avoir qu'un seul chemin pour tout le texte ; aussi, il est plus facile d'utiliser Chemin > Combiner, qui convertira votre texte en chemins et les combinera en un seul chemin complexe, le tout en une opération. Le résultat final sera un groupe d'un seul objet ; vous voudrez aussi probablement le dégrouper. À partir de là, vous êtes libre d'ajouter l'effet Courber et de distordre votre texte comme vous le feriez avec n'importe quel autre chemin.

Cependant, avant de convertir définitivement votre texte en chemin, considérez cet inconvénient : la forme n'est plus du tout un objet texte ; ainsi, vous ne pourrez plus modifier le contenu si vous trouvez une erreur. Souvent un résultat similaire peut être obtenu en dessinant un chemin de courbure séparé, puis en sélectionnant à la fois votre texte et le chemin avant d'utiliser Texte > Mettre suivant un chemin. Vous aurez peut-être besoin de retoucher certaines lettres pour obtenir l'effet correct (voir la partie 11), mais avec l'avantage que votre texte reste modifiable. Dans cette image, le texte rouge a été converti en chemin puis courbé ; le même texte en vert a été placé sur un copie du chemin de courbure ; le texte en bleu est comme le vert, mais avec quelques retouches manuelles.

Une différence notable entre les deux approches est que l'effet distord la forme des lettres, alors que le texte-sur-chemin maintient les formes d'origine. Parfois, l'effet de distorsion est voulu ; dans ce cas, je ne peux que recommander de sauver une copie de votre fichier juste avant la conversion en chemin, au cas où vous auriez à y apporter une modification plus tard.

La prochaine fois, en continuant à étudier les effets de chemin d'Inkscape, nous irons plus loin que la courbure simple d'un chemin vers le genre de distorsions élaborées qui tourneraient un simple texte en titre d'album des années 70.

issue103/tutoriel_5.txt · Dernière modification : 2015/12/15 16:39 de erlevo