Outils pour utilisateurs

Outils du site


issue223:inkscape

Ceci est une ancienne révision du document !


I’ve finally reached the last item on the list of new features in Inkscape 1.4 that I plan to cover in this column. Having written last month about the new Dash icon set, it’s time to look at another new option for customising the UI. Specifically, version 1.4 brings with it the ability to somewhat alter the on-canvas handles via a CSS file.

There are several steps to achieving this, which I’ve listed below to make the overall process a little clearer. It’s not particularly difficult, but different installation methods for Inkscape, across different operating systems and distributions means that it’s not possible to give a simple set of steps, with file paths and names, that will work for everyone. Instead, you’ll have to do a little detective work to find the relevant locations on your own system. Here’s what we’re going to do: • Find the User UI directory • Find the relevant System UI directory • Copy the template CSS file to the User UI directory • Edit the new file and watch the effect within Inkscape • Repeat step 4 until you’re happy with the result • Optionally delete the file from the User UI directory to return to the default styles

For reference, I’m using Ubuntu Mate 22.04 LTS with the Inkscape 1.4.2 AppImage file downloaded from the official Inkscape site.

One important note, though: if all you want to do is to make the handles a bit larger, you can skip all this nonsense. The ‘Interface’ pane of the Preferences dialog (Edit > Preferences) provides a slider for precisely this purpose. The canvas updates in real time as it’s adjusted, so make sure you’ve got some handles visible, then modify this to suit your taste and needs.

1. Find the User UI directory

Most users probably don’t realise that there’s a whole lot of user-specific configuration that can be done to Inkscape, outside of the options presented in the Preferences dialog. For example, you can create your own templates, symbols and palettes, dropping the relevant files into specific directories from which Inkscape will read them when it next starts. Typically these directories are inside your home directory, hidden inside ‘.config’ or ‘.local’ subdirectories on a Linux system. The dot at the start of these directory names causes them to be hidden from the default view of most file management tools.

To find these directories, the simplest approach is simply to let Inkscape tell you where it’s looking. Launch Inkscape, then go to Edit > Preferences, and select the System pane from the list on the left. You’ll be presented with a page full of the directories Inkscape looks in for various things, many of them likely disabled as the actual directory path isn’t something you are expected to edit as a user.

In this screenshot you can see that the majority of these subdirectories live inside ‘/home/xav/.config/inkscape’ on my machine. For this change we’re interested in the “User UI” path: ‘/home/xav/.config/inkscape/ui’. Unfortunately you can’t copy the paths from these read-only fields, but it’s not really required anyway: just click on the ‘Open’ button to the right of the User UI entry to open your default file browser directly at the right directory.

There’s a good chance this directory will be completely empty for you. In my case there are a couple of unused toolbar-related files kicking around, most likely as a result of the column in FCM #163, in which I looked at how to reorder the icons in the main toolbox.

Leave that file browser window open, and return to the Inkscape Preferences dialog to look for the next directory…

2. Find the relevant System UI directory

Next we’re on the hunt for the ‘node-handles.css’ file in Inkscape’s system UI directory. Unfortunately for us, this directory isn’t specifically listed with an ‘Open’ button, so we’ll need to do a little more detective work. First of all, scroll down in the Preferences dialog to find the likely candidate directories – those in the ‘Inkscape data’ and ‘System data’ fields (shown below).

Note that these fields are not read-only, so you should be able to copy their contents. Starting with the ‘Inkscape data’ entry, copy the path and paste it into the URL, Location or Path field in a new file browser window. In my case this brought me to a general ‘share’ directory in the AppImage, inside of which was an ‘inkscape’ directory. Depending on how you installed Inkscape this could equally be a system-level share directory for your operating system, or somewhere else entirely.

What we’re looking for is a ‘ui’ directory (shown above), which is most likely inside an ‘inkscape’ directory. In my case I navigated into the aforementioned ‘inkscape’ directory and, sure enough, the ‘ui’ directory I was seeking lay within. Drilling in further, I found the ‘node-handles.css’ file that is our ultimate goal. Note that it’s likely to be buried among a lot of other files, so sort alphabetically and look carefully to see if it’s present or not.

If you’re not so lucky with the ‘Inkscape data’ entry, try again with each separate entry in the ‘System data’ field. As a last resort, you could even do a search of your whole drive for the filename. Hopefully one of these methods will yield the file we’re looking for.

If you can’t find the file on your system – or just don’t want to go hunting – there is another alternative. Inkscape is, of course, FOSS software, so all its source files are publicly available in the project’s GitLab repo. This includes the ‘node-handles.css’ file, which you can download directly with this link: https://gitlab.com/inkscape/inkscape/-/raw/master/share/ui/node-handles.css

3. Copy the template CSS file to the User UI directory

This part shouldn’t be too tricky. Copy the ‘node-handles.css’ file you found from the System UI directory (or your download location) into the User UI directory window that we left open earlier.

IMPORTANT: Make sure to copy the file from the System UI directory, not move it. This ensures that there’s an unadulterated original available if you make a mistake when editing the file. It also means you can revert to the default configuration by simply deleting the copy from your User UI directory at any time.

4. Edit the new file

Open the file that’s now in your User UI directory using a text editor of your choice. If it supports syntax highlighting for CSS files, then so much the better, as common errors such as missing quotes or semicolons will be easier to spot. It’s also worth noting that editing this file will be a lot easier if you’re familiar with CSS syntax, but regardless of your level of competence I advise saving frequently and checking the changes you make in Inkscape as you go along. Remember, if you break things so badly that no amount of Ctrl-Z will save you, you always have the option of deleting the file to revert to Inkscape’s system settings. Then just copy a fresh file and try again.

At the top of the file are some instructions which describe exactly which CSS properties you can use in this context. This covers almost all the things you’re likely to want to change with handles – though it would have been nice to have ‘rotate’ available.

Following that is a list of the available shapes that each handle can have. There’s no option to draw your own custom handle shapes, I’m afraid. You’re strictly limited to the available list. This is perhaps the most limiting aspect of this feature, because swapping the standard shape for a particular handle is likely to encroach on that shape’s use elsewhere, potentially adding confusion. To avoid this, therefore, it’s probably best to limit your modifications to the fill color, stroke width and opacity of the handles, at least in the most part. Changing the scale globally is best done via the Preferences dialog, but this file can also be useful if you just want to change the scale of some specific handles, relative to the others.

Let’s take a look at some example changes. To make things clearer, I’ve used the Preferences dialog to scale the handles up to 15, the maximum value available on the slider. Here’s how the editing handles for a rectangle look by default, with the mouse pointer hovering over one of the sizing handles. Let’s focus first on the default rules that are used for all handles, unless specifically overridden later in the file. It’s the block that starts with a single asterisk – the universal selector in CSS:

* {

  fill: white;
  stroke: black;
  outline: white;
  stroke-width: 1.0px;
  outline-width: 1.0px;
  outline-opacity: 60%;
  scale: 2.0;
  size-extra: 1px;
  stroke-scale: 0.10;

}

Let’s see what happens when we edit some of these values. We’ll set the fill to yellow, the stroke to purple and the barely-visible outline to ‘hotPink’. Color names are case-insensitive, but other aspects of the file are not, so best to stick to lower case, in general. We’ll also make the stroke and outline thicker, and remove the transparency on the outline by setting the opacity to 100%.

* {

  fill: yellow;
  stroke: purple;
  outline: hotPink;
  stroke-width: 2.0px;
  outline-width: 5.0px;
  outline-opacity: 100%;
  ...

}

One extremely nice feature that the developers included is that Inkscape will detect changes to this file and immediately update its UI without any need to reload. This makes it very convenient to create a small test drawing like this, leave the handles visible, and just keep experimenting with edits to the file. Save after each edit, and Inkscape will reflect your changes straight away. After saving the tweaks above, we’re faced with this result.

It’s certainly a more… erm… distinct look. I’m not sure I’d want to work with it on a daily basis, but it serves to show some of the possibilities available to you. That blue on the hovered handle definitely clashes with the new theme though, so let’s see what we can do about that. A little further down the file we can find the CSS rule that applies by default to any hovered or clicked handles:

*:hover, *:click {

  fill: #0066ff;

}

This time the color has been defined as an RGB value using 6 hexadecimal digits. If you’ve been using Inkscape for a while then you’re probably familiar with this format. Suffice to say that you can use the Fill & Stroke dialog in Inkscape to find the color you want, then copy the color from the RGBA field at the bottom-right. Note, however, that the CSS file won’t work with an 8-digit RGBA value, so you’ll need to remove the last two digits (and ensure there’s a hash (#) character at the start), if you want to use this format.

Perhaps cyan would work better for this hover color?

*:hover, *:click {

  fill: #4ffff8;

}

It’s an improvement, of sorts, I guess.

Note that you can use either hexadecimal RGB values, or CSS color names. The latter cover the main “obvious” color names – so our highlight above could have just used ‘fill: cyan;’ – but there are also a wealth of oddities, such as the ‘hotPink’ we used in the first example. You can have ‘dodgerBlue’, ‘chocolate’, ‘honeydew’ and ‘lemonChiffon. But while ‘lightGreen’ and ‘lightBlue’ both exist, there’s no ‘lightRed’, so don’t assume that any color name will work. If you’re not already familiar with the weirdness of CSS color names, there are many sites online that will show you color swatches for each of them. Or just stick with RGB values if you want precise control.

The rest of the file is mostly overrides for specific handles. If you want to replace the odd shape that Inkscape uses for the center of rotation with a simple cross, for example, then poking around with the ‘.inkscape-adj-center’ CSS ruleset is the way to go.

.inkscape-adj-center {

  shape: "cross";
  stroke-width: 5px;

}

Before and after shown above.

Just bear in mind that not every handle in Inkscape is amenable to the full scope of the changes available, even in this limited subset of CSS. There’s a comment in the ‘.inkscape-guide-handle’ section that states that guide handles are deliberately small and unobtrusive. Personally I find them too small, so nudging the scale value here lets me increase their size without affecting the other handles. But trying to change the handle shape to a diamond (or any of the other supported shapes) doesn’t work in this case.

Most users will probably only ever use the default handle shapes and colors in Inkscape, perhaps adjusting their size in the Preferences dialog, but that’s all. As I’ve shown, if you really want to go overboard with a mish-mash of colors and stroke thicknesses, this custom CSS file lets you do that. But, more usefully, it can be used to make more subtle changes that might perhaps make your life with Inkscape just a little easier – whether that’s changing the size or shape of some specific handles, or globally changing colors the suit your taste and needs. It’s great that Inkscape offers this capability, even if it does require a little technical skill to achieve.

Just remember, if you manage to break things completely, simply throw the file away and start again. With that safety net in place, you can’t go far wrong.

issue223/inkscape.1764573454.txt.gz · Dernière modification : 2025/12/01 08:17 de d52fr