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.
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.
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.
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.
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.
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.**