
Patterns
Inkscape comes with several patterns ready to be applied to either fill or stroke of an object. Most of them are vector based but there are also three bitmap patterns available.
It is often necessary to create your own pattern which can be quite easy with the Object to Pattern option.
This recipe will provide an overview of the basics of pattern editing in Inkscape.
Getting ready
Assigning patterns can only be done from the Fill and Stroke dialogue window (Shift + Ctrl + F) so it's useful to keep it open when dealing with patterns.
How to do it...
The following steps will outline how to create patterns:
- Select the Ellipse tool (F5) and draw a large ellipse to almost fill the page area.
- Under the Fill tab of the Fill and Stroke dialogue window choose the Pattern button:
- Choose Ermine from the Pattern fill drop-down list. Notice that three handles have now appeared on the top left of the page.
- Click and drag the square handle while holding Ctrl to scale the pattern without changing its aspect ratio. Drag it downwards and to the right to make it larger.
- Click and drag the round handle located on the top page border to rotate the pattern.
- Click and drag the cross handle located at the top-left corner of the page to adjust the pattern offset, this is what you end up with:

How it works...
All the patterns available for use on objects can be seen listed in the Fill and Stroke dialogue. User generated patterns will also appear on this list and will take precedence appearing at the top.
A pattern can be edited using the Node tool, all of the shapes, and the Paint Bucket tool. This is convenient because we don't have to switch between tools all the time to perform minor pattern tweaks.
As we have seen, there are three handles available for editing patterns:
- The cross handle that shifts (translates) the pattern inside the object
- The square handle that resizes the pattern
- The circle handle that rotates the pattern
Moving the cross handle also moves the square and circle handles so we can always expect them to appear together. Things do get a bit tricky when the pattern is scaled to a much larger size. In this case, the handles will end up far in between.
Moving the circle handle rotates the pattern, and it also rotates the handles positions. This is also something to be aware of when you have trouble locating the handles.
The editing handles are usually positioned at the top-left corner of the page. If a pattern was created from an object the handles will appear on that object.
Tip
What to do when handles are far away from the object
When working on an object that is far away from where the pattern handles appear it is useful to move the handles closer to the object by dragging the cross handle closer to the object. Circle and square pattern handles will move along with the cross handle.
There's more...
Probably the most fun we can have with patterns is creating our own. To illustrate this, we used an object from an example in the recipe with the radial gradients and converted it to a pattern by going to Object | Pattern | Objects (Alt + I):

The object on the left is the original one that got converted to a pattern. After that step the handles are positioned at the object's corners, cross at top left, circle at top right, and square handle at the bottom-right corner of the object. After applying the newly created pattern to a rectangle the pattern was the same size as the original object which seemed a little too large so we used the square handle to make it smaller. This is the result seen in the image above.
Moving patterns along with objects
Just like with gradients if we want to make the pattern move along with the object it is applied to, we have to make sure that the button Move patterns (in fill or stroke) along with the objects is enabled . This button is located on the right-hand side of the Selector toolbar, so you have to switch to the Selector tool to use it, or you can set this option in Inkscape Preferences (Shift + Ctrl + P) | Transforms | Transform patterns.
Pattern edges visible
Inkscape will smoothen object edges by applying an antialiasing effect to them. This can cause problems in patterns and clones where objects are placed one next to another; there is an unwanted thin but visible crack between the objects.
Although it is not currently possible to disable antialiasing, we can suppress it when we generate a bitmap image. The way to do it is to assure that all object edges are perfectly snapped to a 1x1 grid, then export our drawing at the default resolution of 90 DPI.
See the Inkscape FAQ for more information:
Clipping bitmaps using patterns
Even though clipping is a separate option in Inkscape and in most cases it's easier to use clipping than patterns. It isn't supported by all SVG viewers so sometimes you'll want to use patterns instead.
The procedure is the same as with any other pattern. First we must turn an imported bitmap image into a pattern, then apply that pattern to an object. The object shape will determine the "clipping" area, as in the following image:

See also
For more information, refer to the recipe on Creating a button to use with the CSS Sliding Doors technique in Chapter 10.