OpenOffice arrows, .soe files and writing your own SVG

Creating your own arrows in OpenOffice (.org, 2.0) is a pain. There’s tutorials out there that claim to show how to create arrows from OOo diagrams, but I’ve not had much success with those. However, by taking apart an existing arrow, I’ve managed to work out the rather nasty syntax

OOo arrow libraries are suffixed .soe, and just contain plain-text XML for a full library (so multiple arrows are defined in one file, and only one library can be loaded at once). These libraries sit in your user-specific config directory: to find out where that is, right-click on a line and go to “Line…”, then click on the “Arrow Styles” tab and find the little folder icon for loading new libraries. Click on that, and see where your file explorer puts you.

Arguably it’s easier to either add to or replicate an existing .soe file: the structure is simple enough but there are a lot of namespaces to get right. So open a copy of one of the existing files and have a look inside. It should be structured something like the following:

<?xml version=”1.0″ ?>
<office:marker-table … xmlns declarations… >
  <draw:marker
    draw:name=”Arrow name”
    svg:viewBox=”x1 y1 x2 y2
    svg:d=”mess of semi-numerical data” />
  <draw:marker />
  <draw:marker />
</office:marker-table>

The mess of data up there is the kicker: it looks a bit like SVG path data, but not quite. The reason is that the spacing is often all over the place, so whilst SVG path commands are usually of the form XN, where X is a letter and N a cursor position or a length, OOo frequently seems to prefix commands with numbers. This is actually just an artifact of the format: put spaces in after any number that doesn’t have them, and it reads as a sane SVG path.

So the structure of the arrow can be constructed using the basic, etch-a-sketchy SVG commands, with the following provisos:

  • Whitespace is irrelevant (see above)
  • OpenOffice always deals with closed paths. If your path isn’t closed with a terminating z SVG command, OpenOffice will do so for you. It will then fill in this closed path with the line colour! The tutorial above gives you ways of avoiding this, but I think it’s a consequence of SVG not having a native understanding of line width.
  • OpenOffice has a creative understanding of the standard SVG directions “V” and “H”
  • The SVG viewbox parameter is probably best left alone: I think it’s similar to the bounding box on postscript files, creating a window for the vector graphic to sit in.

An example is worth a thousand words, even if that example is made up of a thousand hard-to-read SVG commands, so here we go. The image below is a schematic of a three-pronged many-to-one arrow I want to use. The arrow line continues up the page from the junction of the three prongs.

OpenOffice many-to-one arrow

As you can see, when the parent line is running horizontally (as it appears in the OOo configuration, H actually describes movement along the vertical. With this in mind, the entry for this arrow would read:

<draw:marker
  draw:name=”Arrow name”
  svg:viewBox=”x1 y1 x2 y2
  svg:d=”m1000 1162
    l 0 -125 -125 0 -859 859
    v-859
    h-176
    v859
    l -859-859 -125 0 0 125 859 859 213 213
    z” />

  1. [M]ove the cursor to an x/y position to start (this makes the arrow start at the end of the line)
  2. [L]ine: draw towards -v, -h, then along a diagonal
  3. [V]ertical line towards -v, [h]orizontal towards -h, [v]ertical towards +v
  4. [L]ine: draw a diagonal, then towards -h and +v, then two diagonals in the same direction
  5. Clo[z]e the drawing

And that’s it. Fairly simple, as long as you break down your design into SVG primitives first, and realise how OOo is working. There’s some refinements that, as I’ve reverse-engineered much of this, I’ve not been able to go into: the starting position seems to only partly affect the arrow, as it gets centred on the line regardless; the viewbox seems to get ignored. But if anyone can take this any further, than do let me know.