Drawing with Inkscape – Part 160 By Mark Crutch The topic for this month is a feature that I never really use in Inkscape: color swatches. In theory, they could be a very useful tool for tackling some specific issues or requirements – but, in practice, I find Inkscape’s implementation to be a little too confusing, leading me to avoid them. But since the UI of the Swatches dialog has been overhauled in version 1.4, let’s revisit what they are, how you can use them, why you might want to – and why you might not. Sometimes the term ‘color swatch’ is used to generally refer to an entry in the color palette at the bottom of the Inkscape window, or for similar colored blocks elsewhere in the UI. But in this context we’re talking about something far more specific: an individual color block that appears in the Swatches dialog (View > Swatches, or Ctrl-Shift-W). Opening this dialog could, initially, lead to disappointment, as there may be no swatches visible at all – just a lonely red cross. If you see this view, it just means that there are no swatches defined in your document as yet. We’ll come on to how you create them shortly, but first it’s useful to understand the three main reasons why you might want to use swatches in the first place. To use a very specific (named) color To use a predefined collection of specific colors To easily change the color of multiple objects simultaneously In the old days of lithographic printing, that first reason was far more important than it is now. Most color printing is now done using CMYK colors – combining Cyan, Magenta, Yellow and blacK in different proportions to produce a wide range of colors. Other, similar systems may use more base colors, but they still combine them in different proportions to produce any given color on the page. On a modern digital press, which uses toners in a similar manner to a laser printer or photocopier, that’s likely to be the only option you have. But on a traditional press, with wet inks, it’s possible to use what are known as “spot” colors. These are very precisely controlled inks, made in small batches against very precise recipes to ensure that exactly the same color can be reproduced again and again. If a company has a very strong association with a specific color, they may well require that their logo is reproduced using a spot color ink, rather than risk it being slightly incorrect when C, M, Y and K are mixed. You may have heard of spot colors through the term ‘Pantone colors’. This is a reference to the largest vendor of these color recipes, used throughout the printing industry. When a company’s logo is defined as “Pantone Reflex Blue” or “Pantone PMS 803 C”, they can be sure that it will be reproduced in precisely the correct color – assuming they’re using lithographic printing, and a competent print supplier. The first use of swatches is therefore to define a very specific color. Except that the Pantone system is proprietary (and expensive) – and Inkscape, due to the web-based history of the SVG format, doesn’t really support anything other than RGB colors anyway. Try defining the color of an Inkscape swatch as “Pantone Reflex Blue” and you’ll get nowhere. While this does greatly limit the utility of Inkscape swatches for this purpose, it doesn’t render them completely useless. Okay, so you’re not going to be defining spot colors with Pantone references in your Inkscape documents, but most companies now have RGB equivalents (or approximations) of their corporate colors for use on websites and other purely digital media. You may not be able to use “Pantone Reflex Blue”, but your corporate style guide might let you swap it out for an RGB value of #011589 when used in a digital context. In this sense, swatches in Inkscape provide a way to define specific named colors. Let’s give that a try… In order to create a swatch in your document, you might expect to open the Swatches dialog and find a button to create and name a new entry. But that’s not how it works, unfortunately. Instead, swatches are created via the Fill & Stroke dialog, and the options you need are available only when an object is selected on the canvas. Our first step, therefore, is to create an object of some sort – just a plain ellipse or rectangle will do – and open the Fill & Stroke dialog. You can define a swatch on the fill or the stroke tab (or both). I usually set the fill color, as it’s a lot more obvious than a potentially thin stroke. Either way, in the collection of buttons at the top – where you might usually select a flat color or gradient – click on the penultimate button, which should have a tooltip of “Swatch”. This will display a list of the existing document swatches (possibly only one, if this is the first one you’re creating), with the usual selection of color pickers below. You can use any of these to define your color, whether by moving sliders, entering values directly, or showing the color wheel. In this example image, I pasted the RGB hex code from a couple of paragraphs above into the RGBA field at the bottom right – Inkscape automatically removed the hash (#) and added an extra ‘ff’ at the end for the Alpha (opacity) value. In the list at the top, your swatch will have been given a default name, such as “swatch1” – you can click on the name to change it, which I definitely recommend if you want to use swatch colors for very specific purposes. Here, I’ve changed mine to be called “Not Reflex Blue”. Now, back to the Swatches dialog, and you should see your new swatch in all its glory (assuming you’ve got the “Document swatches” option selected in the dropdown). You may see your swatch as a square, or stretched out into a rectangle, depending on the configuration you’ve got defined in the settings menu (the cog icon at the bottom-right of the dialog). Hovering over the swatch will show the name you defined in a tooltip. Alternatively, you might prefer to use the icons next to the cog to switch between the grid and list view. The latter is shown here, where you can see the swatch name is clearly displayed. Oddly, you can’t actually edit the name here. What you can do is to right-click on the swatch itself (though not on the name), to open a context menu. The “Edit…” option in the menu will open the Fill & Stroke dialog with the swatch already selected and ready to alter – allowing you to change the color, or the name. The other options in that menu are fairly self-explanatory. Setting the fill or stroke color is more easily done by clicking on the swatch (fill) or shift-clicking (stroke) – do the same on the red X swatch to remove the fill and/or stroke. The Pin Color option will, as its name suggests, pin the swatch to the top of the dialog, next to the X – which may be useful if you have a lot of swatches, but only a few that you frequently use. Note that pinning a color removes it from its position in the list rather than creating a ‘clone’ of the original, so if you’ve defined a specific series of colors (such as a stepped gradient) this might somewhat spoil your order. Unpinning will put it back into place though. Swatches appear in the dialog in reverse order of creation, with no way to sort them by name or color, which is another big omission in my opinion. Now you know how to create your own document swatches, it’s time to move onto my second reason for using swatches: to use a predefined collection of specific colors. At the top-left of the Swatches dialog is a pop-up which opens a menu listing all the palettes Inkscape knows about. These are the same ones you’ll see if you click the menu button at the end of the main palette below the canvas. Although it’s the same list, there’s no synchronisation here; the two selections are independent of each other. Selecting a palette for the main window won’t change the selection in the Swatches dialog, nor vice versa. Using the pop-up in the dialog to select a palette here will, as you might expect, show swatches for each of the colors in the palette as separate swatches. Depending on the palette you choose, the entries may have names, just hex values, or even a mixture of both. The lack of any sorting in the dialog means you’re at the mercy of the order in which the colors are specified in the underlying palette file. This can lead to quite jumbled swatches – as with the SVG palette in this image. Note in that screenshot that there are no pinned swatches next to the red X, despite me having pinned my “Not Reflex Blue” swatch previously. Pinned swatches remain specific to the selected palette, so the one I pinned when viewing “Document Swatches” doesn’t appear here, and a color pinned here won’t appear when any other palette is selected. For some situations this could be useful, to prevent you accidentally using an out-of-palette swatch that you pinned in another context. But it also prevents you from creating a ‘greatest hits’ collection of your favourite swatches across different sources. As you might have guessed, pinning colors here also does not affect the pinned colors in the main palette below the canvas, nor the other way round. Still, not having a way to pin a swatch across palettes is no great hardship, because as soon as you use a swatch from another palette, it will become available in the “Document Swatches” view, right? Alas, no. When you select a swatch from a predefined palette to apply it to the fill or stroke of an object, all it actually does is set the RGB color on that object – it doesn’t actually create or use a document swatch. This means that the “Swatches” dialog actually serves two different purposes: it shows Inkscape swatches (i.e. Document Swatches), and it displays palettes that just set RGB values, much like the palette at the bottom of the main window. But these are two separate notions of the word ‘swatch’, and there’s nothing in the UI to clearly indicate this difference if you don’t know about it. There is an awkward workaround. If you apply a fill or stroke color using a palette – either from the Swatches dialog or from the bottom of the main window – it will appear as a solid fill (or stroke) in the Fill & Stroke dialog. Simply switching to the Swatches section within this dialog will create a new document swatch with the selected color – in other words, it’s a mechanism to copy the RGB value of the palette color to a document swatch. You’ll have to set the swatch name manually, however, as that information does not get carried over. The Swatches dialog does offer one advantage over just using the palette on the main screen: at the bottom-left of the dialog is a button which allows you to dynamically load a palette from disk. The supported formats are ‘Gimp Color Palette’, ‘Adobe Color Book’ and ‘Adobe Swatch Exchange’ – so this feature might prove invaluable if you work in the sort of environment with a corporate color scheme available to download in one of these formats. This ability to load palettes is not, however, matched with a means to create your own. It would be great if you could create a collection of Document Swatches and save it out into a supported format to load later, but the Swatches dialog lacks any way to export. It may seem that all is not lost, as Inkscape offers “GIMP Palette” as a target filetype in the Save As… dialog (and yes, there’s some inconsistency in the capitalization of GIMP within Inkscape). But, again, minor issues prevent this being a truly useful solution as the resultant file takes the swatch names from the “id” attribute, not the “inskscape:label” attribute which gets set if you provide a custom name. In my example, therefore, my GIMP Palette file contained “swatch1” rather than “Not Reflex Blue”. So while you can export the colors of your swatches, you’ll have to manually modify the resultant file with a text editor if you want to preserve the names of the colors. Even worse than this, exporting a palette in this way fails to put an entry into the ‘Name:’ field of the file – without which the Swatches dialog refuses to load it. So even if you’re happy to lose or re-create your swatch names, you’ll still have to edit the exported file if you want to be able to load it again later. Thankfully the format of a GIMP palette file is pretty straightforward, so you should be able to work out how to edit it to add a palette name and swatch names, if you want to pursue this approach. The third way I suggested swatches might be useful is “to be able to change the color of multiple objects simultaneously”. What I mean by this is that document swatches effectively act as variables in an Inkscape document. If you change the color of a document swatch, then all objects using it will immediately update to the same color. Consider, for example, creating a mock-up of a user interface which has a specific accent color. By using a document swatch, you can quickly change the accent color for every element in the mock-up in order to produce differently themed examples of the UI. Or think of a “Congratulations” banner where the winning team is not yet known. You can create the entire design using a document swatch, and just update it to the right color once the results are in. There are lots of ways in which it can be useful to ensure that multiple objects all use the same color, and all update to a change in that color at once. But that brings me onto the disadvantages of swatches. Quite frankly they serve too many purposes, but do none of them particularly well. If you create your own document swatches, it can be really useful to be able to trivially change them and have every object update. But that can also be dangerous when you need to set a very specific color, and want to avoid the possibility of an accidental update. Yet there’s no way to lock a document swatch against further editing to help avoid this problem. One solution might be to create your own palette of fixed colors but, as we’ve seen, Inkscape doesn’t make that an easy task to achieve. And with no way to pin swatches across multiple palettes, you might end up having to ‘copy’ your colors back to Document Swatches, which brings back the same potential editing issues. Then there’s the limited way in which Document Swatches can be used. They can be set on the fill or stroke of an object, but that’s all. You can’t use them to create named stops in a gradient, or when picking the color of a pattern, grid or guideline. Realistically these may not be practical limitations, but they do reflect the fact that a swatch is not a “real” color in the sense that an RGB value is within Inkscape. Instead they’re a slightly confused way to create a named variable to use as a flat color, and really not much more. When looked at in that light, it’s not surprising that I don’t use them much. Mark uses Inkscape to create comics for the web (http://www.peppertop.com/) as well as for print. You can follow him on Twitter for more comic and Inkscape content: @PeppertopComics