Ceci est une ancienne révision du document !
With 69 previous instalments of this series behind us, it’s clear that Inkscape has a lot of features and functionality, despite being slightly shackled by the limitations of the SVG file format. But there are some tasks which don’t warrant inclusion in the main Inkscape application. To support these, the developers added a simple extension mechanism to Inkscape, which allows it to hand the document off to an external program for further manipulation, and receive the modified document back in response. The program that performs the modification could be anything from a small shell script to a fully blown, compiled C++ application. In practice, most take the form of simple Python scripts. Because the program just needs to manipulate a text document, just about any language could be used, but the output must still be a well-formed SVG file, so using a language with good XML libraries certainly makes the job of writing an extension easier.
Avec les 69 articles précédents de cette série derrière nous, il est évident qu'Inkscape a beaucoup de fonctions et de fonctionnalités, malgré qu'il soit légèrement entravé par les limitations du format de fichier SVG. Mais il y a certaines tâches qui ne méritent pas une inclusion dans l'application principale d'Inkscape. Pour accueillir celles-ci, les développeurs ont ajoutés un mécanisme simple d'extension, qui lui permet d'extraire le document vers un programme externe pour des manipulations supplémentaires et de réception le document modifié en retour.
Le programme qui réalise la modification peut être n'importe quoi du petit script shell à une application en C++ compilée à part entière. En pratique, la plupart prennent la forme d'un simple script Python. Comme le programme n'a besoin que de manipuler un document texte, à peu près n'importe quel langage peut être utilisé, mais la sortie doit encore être un fichier SVG bien formaté ; aussi, l'utilisation d'un langage avec de bonnes bibliothèques XML rend certainement le travail d'écriture de l'extension plus facile.
Because extensions are external programs, they can be shipped independently of Inkscape. If a manufacturer wants to create an extension to convert documents into the right format for their plotter or vinyl cutter, they can do so. With the right programming skills, users can even create their own extensions. But before considering third-party extensions, it’s worth looking at the ones that ship with Inkscape by default. Extensions can be found, unsurprisingly, under the Extensions menu. Here you’ll initially find a couple of shortcuts – the first to re-run the last used extension with the same settings you used previously, and the second to open the settings dialog for the last used extension, if it has one (otherwise it also just re-runs the extension). The rest of the menu is taken up with sub-menus, each of which holds menu items to launch the extensions themselves – and, in some cases, further sub-menus before you get to the actual launchers.
Comme les ectensions sont des programmes externes, ils peuvent être livrés indépendamment d'Inkscape. Si un fabricant veut créer une extension pour convertir les documents dans le bon format de leur traceur ou de leur graveur de vinyle, ils peuvent le faire. Avec les bonnes connaissances en programmation, les utilisateurs peuvent même créer leurs propres extensions. Mais avant de s'intéresser aux extensions tierces, ça vaut le coup de regarder celles qui sont livrées par défaut avec Inkscape.
Les extensions peuvent être trouvées, sans surprise, sous le menu Extensions. Ici, vous trouverez d'abord deux raccourcis - le premier relance la dernière extension utilisée avec les mêmes réglages que ceux utilisés précédemment, et le second ouvre le dialogue des paramètres de la dernière extension utilisée, s'il y en a une (autrement, lui aussi relance l'extension). Le reste du menu est organisé en sous-menus, chacun d'entre eux détenant des lignes qui lancent les extensions elles-mêmes - et, dans certains cas, avec d'autres sous-menus avant de tomber sur les vraies lignes de lancement.
If you take a couple of minutes to scroll through the available extensions, you’ll realise that there are a lot of them. Over 150 of them on my default installation of 0.92! That should keep this column full for the next few years, so let’s press on with the first one… …or maybe not. I’m not so cruel as to go through each and every extension in detail, but will pick out a few examples in order to show the common UI features that you’ll find. Since extensions are just normal programs, they can accept parameters, in the same way that running a tool on the command-line often requires additional arguments. The exact arguments that are needed are defined in a configuration file for the extension (this also includes other details, such as which sub-menu to put the launcher in). This file defines not only the names of any additional arguments, but also the type of value the argument expects. This allows Inkscape to generate a simple dialog, ensuring that the right type of UI widget is used for each parameter. You can tell in advance if an extension will prompt for additional parameters by looking at its name in the menu: as is the convention in computer programs, entries ending in an ellipsis (“…”) will display a dialog, while those without will have an immediate effect.
Si vous prenez quelques minutes pour naviguer dans les extensions disponibles, vous réaliserez qu'elles sont nombreuses. Plus de 150 dans mon installation par défaut de la 0.92 ! Ça devrait permettre de remplir cette série pendant les quelques prochaines années ; aussi, dépêchons-nous de passer au premier…
… ou peut-être pas. Je ne suis pas assez cruel pour vous faire passer pour chaque extension en détail, mais je vais prendre quelques exemples pour vous montrer les caractéristiques communes de l'interface utilisateur que vous trouverez. Comme les extensions sont des programmes classiques, ils peuvent accepter des paramètres, de la même manière que l'utilisation d'un outil en ligne de commande requiert souvent des arguments complémentaires. Les arguments exacts nécessaires sont définis dans un fichier de configuration de l'extension (celui-ci inclut aussi d'autres détails, tel que savoir dans quel sous-menu il faut mettre le lanceur). Ce fichier définit non seulement les noms de tous les arguments supplémentaires, mais le type de valeur attendu par l'argument. Ceci permet à Inkscape de générer un dialogue simple, en s'assurant que le bon type d'objet est utilisé de l'interface pour chaque paramètre. Vous pouvez dire à l'avance si une extension fera une demande à l'utilisateur pour des paramètres additionnels en regardant son nom dans le menu : comme c'est convenu dans les programmes informatiques, les entrées se terminant par trois points de suspension (« … ») demandent l'affichage d'un dialogue, alors que celles qui n'en n'ont pas auront un effet immédiat.
As an example of an extension with no UI, let’s consider the Color > Brighter extension. As you might expect this makes the selected objects brighter, which it does by altering their fill and stroke colors – albeit by only small amounts at a time. Here’s a before-and-after image, having applied this extension many, many times to the object on the right: Because this extension has no UI, its effect takes place immediately, so you might think that using the “Previous Extension” menu entry, or, better still, its keyboard shortcut (ALT-Q) would be a fast way to incrementally increase the brightness of an object. Unfortunately using an extension de-selects everything in your drawing, so repeatedly calling the same extension also involves an intermediate step of re-selecting the object you wish to operate on. In many cases, including the Brighter extension, failing to select an object results in the effect being applied to every element in the drawing. If you forget this, and just hammer ALT-Q a few times you’ll quickly find that everything gets brighter, not just the element you had selected when you first ran the extension.
Comme exemple d'extension sans interface utilisateur (UI), regardons l'extension Couleur > Plus clair. Comme vous pouvez y attendre, elle rend plus clairs les objets sélectionnés, ce qu'elle fait en altérant les couleurs de remplissage et de contour - mais qu'en petite quantité à chaque fois. Voici une image avant et après, ayant appliqué cette extension beaucoup, beaucoup de fois à l'objet de droite :
Parce que cette extension n'a pas d'UI, son effet agit immédiatement ; aussi, vous pourriez penser que l'entrée de menu « Extension précédente » ou, mieux encore, son raccourci clavier (ALT-Q), serait une façon rapide d'augmenter pas-à-pas la clarté d'un objet. Malheureusement, l'utilisation d'une extension désélectionne tout sur votre dessin et l'appel répétitif d'une même extension comprend aussi une étape intermédiaire de re-sélection de l'objet sur lequel vous voulez agir. Dans de nombreux cas, dans lesquels l'extension Plus clair, l'oubli de sélectionner un objet a pour effet d'appliquer l'effet à tous les éléments du dessin. Si vous l'oubliez, et que vous faites ALT-Q plusieurs fois, vous vous rendrez compte que tout devient plus clair, et pas seulement l'élément que vous aviez sélectionné la première fois que vous avez lancé l'extension.
A better approach to achieve a similar effect is to use the Color > HSL Adjust… extension. As the ellipsis indicates, this extension displays a user interface, so you can adjust the amount of brightening you wish to apply before the extension actually runs. Furthermore, recent versions of Inkscape add a “Live Preview” checkbox to the extension dialog, allowing you to see the effect of your changes before they’re finally applied. On the surface it might seem like the “Live Preview” option is a bit of a no-brainer. Why would you ever not want that checked? But consider that each extension is a separate program that needs to be launched, receive a copy of the entire Inkscape document, process it, return the entire document back to Inkscape, and then close. And this process will happen for every little change you make to the settings in the dialog. With a large document or a complex extension it can take several seconds, or even minutes, to preview the changes. Un-ticking the checkbox lets you change several settings at once without this overhead. If you already know the values you need to enter, or just want to preview after making a number of changes, being able to turn off this checkbox is vital.
Une meilleure approche pour réaliser un effet similaire est d'utiliser l'extension Couleur > Ajuster TSL… Comme ses points de suspension l'indiquent, cette extension affiche une interface utilisateur ; ainsi, vous pouvez ajuster la quantité d'éclaircissement que vous souhaitez appliquer avant que que l'extension soit réellement lancée. De plus, les versions récentes d'Inkscape comportent une case à cocher « Aperçu en direct » dans le dialogue de l'extension, vous permettant de voir l'effet de vos modifications avant qu'il soit appliqué définitivement.
À première vue, il pourrait sembler que l'option « Aperçu en direct » ne soit pas très futée. Pourquoi vous ne la voudriez-vous pas toujours cochée ? Mais chaque extension est un programme séparé qui doit être lancé, reçoit une copie de tout le document d'Inkscape, le traite, retourne le document en entier à Inkscape, puis se ferme. Et ce processus se produira à chaque petit changement que vous faites aux paramètres du dialogue. Avec un gros document ou un extension complexe, cela peut prendre plusieurs secondes, ou même des minutes, pour prévisualiser les modifications. La case décochée vous laisse changer plusieurs paramètres d'un coup sans cette surcharge. Si vous connaissez déjà les valeurs que vous voulez entrer, ou que vous voulez juste prévisualiser après avoir fait un certain nombre de changements, la possibilité de décocher cette case est vitale.
This dialog also shows a few other items worth noting. Inkscape has displayed the boolean parameters as checkboxes, and the numeric parameters as the GTK3 style hybrid spinbox and slider that is used elsewhere in the program. Furthermore, the sliders have different ranges – the Hue input runs from -360 to +360, whereas the Saturation and Lightness run from -100 to +100. By using the right field types, and limiting the possible values, well written extensions can ensure that users are protected from entering nonsense that the extension will then have to deal with. But Inkscape’s selection of UI widgets is limited to a few basic types, and doesn’t even allow the developer to specify a template or regular expression to validate free-text fields. For most extensions, this isn’t a problem, but some do have specific requirements for the data that you enter into their fields. For example, Render > Function Plotter… lets you draw mathematical curves by entering a function into a text field. Typing “sin(x*7)” and setting the checkbox to use polar coordinates, for example, renders this seven-lobed flower.
Type an invalid function into the input field, however, and you’re likely to see something like this instead: The problem is that Inkscape has no way to validate the input, and the extension has decided to send the whole Python error back to Inkscape, rather than a more friendly “The formula you entered is not valid”. When you are working with a free-text field that requires specifically formatted content, it’s worth disabling the live preview until you’ve finished editing your data. One other thing to look out for is a Help tab, or similar, which will often contain further information about what sort of values are valid in the fields. The Function Plotter, for example, has a “Functions” tab which details the Python mathematical functions that can be used in the text field: Whilst experimenting with different settings in an extension’s dialog, you’ll probably discover that you can’t zoom or pan the canvas, or change the selected objects. This is particularly frustrating when using something like the Function Plotter, as some combinations of parameters can lead to shapes being drawn that are too large or small for the current zoom level. The cause of this restriction is actually the preview mode – simply un-tick the Live Preview checkbox and you’ll be able to make changes on the canvas, before ticking it again to restore the preview.
Once you’ve finished playing with the Function Plotter, it’s worth exploring some of the other extensions in the Render sub-menu. Given the ubiquity of barcode scanning software on phones now, the Render > Barcode > QR Code… extension could be a useful tool when designing a poster, flyer or other promotional material. This menu also includes extensions to draw calendars, grids (including logarithmic and polar grids, which Inkscape can’t do natively), printer’s registration and color marks, and charts (though you’re probably better off using a spreadsheet or dedicated graphing program for anything other than the simplest of charts). On the more frivolous side of things, there are also extensions to create spirograph-style images, simple fractal trees, and fake 3D objects.
The last extension to look at this month is one that you’ll find either absolutely invaluable, or you’ll probably never need to use at all. It’s also one of the extensions with a less than descriptive name: Render > Hershey Text. What this extension does is to render some text using a so-called Hershey font. At first glance, this might not look terribly different from normal Inkscape text in a similar font: Zoom in, however, and things start to look a little different. Switch them both to a minimal stroke, and no fill, and the difference really becomes apparent:
As you can see, the normal text has a clean and simple outline with curves where needed. Conversely the Hershey text is made up of straight lines that sometimes overlap awkwardly – and just what is that little square doing in the dot on the i? The answer is that Hershey text is intended for use with pen plotters, laser engravers, and similar devices. Suppose you’re preparing a file for use with a laser engraver, but you want some solid text. Such devices really care only about outlines, not fills, so using a normal font would just result in an outline version of your text. If you wanted to fill it, you would need to draw a hatch pattern inside the text, resulting in the laser going over adjacent parts of your design repeatedly. At best, this might cost you more, as the job will take a lot longer. At worst you might find that these parts of the design become excessively scorched by keeping the beam in the same area for so long.
Hershey text, on the other hand, is not designed to be used with a fill. Rather the letters should be left as outlines, with the thickness of the beam or pen being used to provide any “fill” as the outline is drawn. With that knowledge, the little square makes a lot more sense. If you print your designs using only an inkjet, laser printer, or even a professional printing press, you’ll be fine using normal text. But if you decide to use one of the increasing number of laser cutting and engraving bureaus that accept Inkscape files, or if you purchase one of the hobbyist pen plotters that work with the program, this little extension could save you a lot of time, money or ink.