From Inkscape .46, there is an ability to have stock patterns. This means that you can create your own patterns and make them available for use in any Inkscape drawing, not just the one the pattern was created in. Unfortunately, there is no way to construct these from the user interface, but there is a manual workaround.
The basic steps will be:
- create a new drawing
- make the pattern desired
- convert the drawing objects to a pattern
- save the drawing
- open the svg drawing in a text editor
- modify the pattern definition XML bounding box
- copy out the pattern definition XML paste it into the patterns.svg file.
- modify the definition to be recognized by Inkscape.
It is a good idea to make a backup of the original patterns.svg file, located in \share\patterns of the Inkscape installation directory (at least on windows) before modifying it.
Step 1: Create a new drawing.
It is worth a bit of planning at this time. Your pattern must be constrained in a rectangular shape. Mentally decide on a size up-front that your pattern will fit into. Because the pattern rendering engine can leave small hairline gaps between pattern repeats, it is best to provide slight overlaps in the drawing objects.
For this example, I have created a 40x40 drawing, and turned on the default rectangle grid. I have also enabled snapping to grids.
Step 2: Create the pattern.
Create your desired pattern, remembering to allow for overlap of shapes. Here I am creating a scallop effect with a 2 px line width. I have allowed for line endpoint overlaps.
At this time I realized that the smallest repeat would actually be a 20x20 portion of the image. To help visualize the pattern, draw a new rectangle over the desired pattern area, having no stroke and reduced opacity.
Erase the items that are not necessary, and keep one copy of items that would “wrap around” the pattern when tiled. Here is my final image, with the guide shape removed:
Step 3: Convert the objects to a pattern.
Select all of these objects, and convert them to a pattern (
Objects->Pattern->Objects to Pattern). The shapes will be replaced with a rectangle having a custom pattern fill. The rectangle completely bounds these shapes. If you enlarge the rectangle, you will see the created pattern….yuck! not what we ultimately it to look like, but it is all there, really! Checking the Fill tab of the fill and stroke dialog shows it is
“pattern3192”
Step 4: Save the drawing.
Save the drawing somewhere, and close Inkscape for now.
Step 5: open the svg drawing in a text editor
I use Notepad++, available from here:
http://notepad-plus.sourceforge.net/ which is a great little programming editor that supports XML nicely. Open up the file and search for
“pattern3192” (or whatever your pattern was named). Here is a screen grab with that definition highlighted.
Step 6: modify the pattern definition XML bounding box.
The first thing to change is the width and height parameters. You can see that it used the bounding box of all the shapes in the definition:
CODE:
width="32"
height="21.75"
but we had determined this was really a 20x20 repeat, so change these to 20 and 20 and save the file. Reload into Inkscape, and you should now see a nice repeating pattern fill:
Step 7: copy out the pattern definition XML paste it into the patterns.svg file.
Now that it has been verified, copy the whole pattern text definition (what was highlighted earlier). Open up the patterns.svg file, and paste your pattern in just before the first pattern definition in there.:
Step 8: Modify the definition to be recognized by Inkscape.
There are a few changes that should be made, (and one that must be made at this point). You must add a inkscape:stockid="Pattern name" attribute to the pattern before Inkscape will allow you to use it. I used “Scallops” as the pattern name. The other things you should do are:
- change the id to something unique that does not use the “patternXXXX” nomenclature to avoid name collisions.
- Change the pattern transform to "translate(0,0) scale(1,1)" (since we drew it full scale)
- Add a inkscape:collect="always" attribute (don’t know why but all the stock pattern have them)
- Delete the path id attributes from the objects that make up the pattern to avoid id collisions
Here is my final custom pattern:
CODE:
<pattern
inkscape:collect="always"
patternUnits="userSpaceOnUse"
width="20"
height="20"
patternTransform="translate(0,0) scale(1,1)"
id="RMA_Scallops"
inkscape:stockid="Scallops">
<path
style="opacity:1;fill:none;fill-opacity:1;
fill-rule:nonzero;stroke:#000000;
stroke-width:2;stroke-linecap:butt;
stroke-linejoin:miter;marker:none;
marker-start:none;marker-mid:none;
marker-end:none;stroke-miterlimit:4;
stroke-dasharray:none;stroke-dashoffset:0;
stroke-opacity:1;visibility:visible;display:inline;
overflow:visible;enable-background:accumulate"
d="M 11,11 C 11,24 31,24 31,11"
sodipodi:nodetypes="cc" />
<path
sodipodi:nodetypes="cc"
d="M 1,1 C 1,14 21,14 21,1"
style="opacity:1;fill:none;fill-opacity:1;
fill-rule:nonzero;stroke:#000000;
stroke-width:2;stroke-linecap:butt;
stroke-linejoin:miter;marker:none;
marker-start:none;marker-mid:none;
marker-end:none;stroke-miterlimit:4;
stroke-dasharray:none;stroke-dashoffset:0;
stroke-opacity:1;visibility:visible;display:inline;
overflow:visible;enable-background:accumulate" />
</pattern>
Save the patterns.svg file.
Now you can fire up Inkscape again (it has to restart to reload the patterns) and can now select the new pattern (Scallops) from the Fill and Stroke pattern fill drop-list. (They appear in the same order as in the patterns.svg file):
Warning! Updating Inkscape will overwrite your modified patterns.svg file, so make sure you keep a copy of it somewhere. I have filed a feature request at the Inkscape launchpad site requesting that Inkscape allow additional pattern definition files https://bugs.launchpad.net/inkscape/+bug/183535
A warm welcome to any of you coming here from the HeathenX Screencast Episode 63. Just follow this link to get to my Inkscape Custom Pattern Tutorial.
Tracked: Jun 24, 14:18