Ceci est une ancienne révision du document !
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 de trop s'enfoncer dans les Effets dynamiques de chemin (LPE - Live Path Effect), il vaut mieux montrer quelques détails d'implémentation. Le premier est que les LPE n'existent pas dans la spécification SVG. Il y a une version spécifique Inkscape et aucun navigateur ou autre éditeur SVG ne sait comment la rendre. Poursuivons, prenons un exemple. Créez une joli chaîne d'engrenages, ou un chemin Spiro, puis sauvez-le dans un fichier SVG. Ouvrez -le dans un navigateur Internet moderne voyez le résultat. Voici mon fichier, ouvert dans Firefox.
Bon, il ressemble à mon fichier Inkscape original, mais comment sera-t-il si mon navigateur n'y connaît rien en LPE ? 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 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 LPE visibles aient é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, 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 le LPE. Les autres applications utilisent l'attribut « d » pour rendre un instantané du chemin final, le LPE étant appliqué. Quand vous modifiez un LPE 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 voulu, même s'ils ne connaissent rien à propos ds LPE.
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 de LPE pendant que vous testez votre dessin, les vieilles définitions tendent à s'accumuler. Elle ne causent aucun dommage, mais elle font un peu augmenter la taille du fichier. Vous pouvez les effacer, avec les autres vieilles définitions, en utilisant Fichier > ___ (Fichier > Nettoyer les Defs dans la 0.48).
Parce que Inkscape calcule le chemin final à partir du chemin initial et des paramètres de LPE, l'utilisation des effets de chemin dynamiques charge plus le processeur, d'où une vitesse de rendu 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 du LPE, et que vous n'avez pas besoin de faire de nouveaux changements, vous pouvez « fixer » le chemin ; ainsi, il reste 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).
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.
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.
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.
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.
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.