SVG Path Semantics

From Apache OpenOffice Wiki
Jump to: navigation, search
SVG Import
(external impl.)
Source code
Group opacity
Elliptic arcs
Path semantics
Coordinate systems

The syntax of specifying paths in SVG and OpenDocument is identical. In both formats, a path can either be closed or non-closed. However, the semantics of closing a path differs in both specifications significantly.

Paths in SVG

Whether the area surrounded by a path is filled or not only depends on the value of the fill property on the path element. It does not matter, whether a path is closed or not (a closed path ends with the "close path" command). If the fill property has a value different from none, even a non-closed path is filled in SVG.

Closing a path only affects the stroking used to draw the border of the path. This makes it possible to specify a filled area, for which its border is only partially stroked (as shown in Figure 1).

Figure 1: A non-closed but filled and stroked path in SVG.

Only for stroking the path's border, it makes a difference, whether the path is closed or not (even, if the start and end positions of the path match). Figure 2 and Figure 3 show two paths with the only difference that the Figure 2 is not closed but the Figure 3 is. The start and end point of the non-closed path on Figure 2 is the point surrounded with a green circle. Closing the path affects the line joining of its stroke.

Figure 2: Non-closed path with identical start and end position.
Figure 3: Closed path.

On a non-closed path, the starting and ending strokes simply overlap without being joined. In contrast, the starting and ending stroke of a closed path are joined to give the impression of a closed curve.

Paths in OpenDocument

Section 15.14.1 of the OpenDocument specification states that only closed paths are filled, no matter what filling is defined in the current graphic style. Therefore, it is not possible to specify a shape as shown in Figure 1 and Figure 2 on the left with a single path in OpenDocument.

The only workaround is to draw two almost identical paths one over another: Firstly, a closed path with the corresponding fill style and without stroking, secondly, a non-closed path with the corresponding stroke style.

Consequences for SVG import

To mimic the SVG behavior exactly, non-closed but filled and stroked paths must be doubled during import. One path must be transformed into a closed path without stroke and one must be left as is. Of cause, this makes the resulting document larger and less editable, because of the two paths that represent a single shape.

Current status

With version r2009, the import filter has a path closing normalization built in. Without doubling the path, this normalization is executed on all paths that define a fill style. This may result in slightly differing results, but keeps the resulting document small and better suited for editing. The filter therefore does not distinguish between the three shapes in Figures 1 and 2. After import, all three shapes appear like the one shown in Figure 2 on the right.

-- BernhardHaumacher - 25 Aug 2005


I consider the OpenDocument behavior of not filling non-closed paths even if a fill style is defined as a bug in the specifications. Without strong reason, this makes some sort of shapes unnecessarily hard to create.

-- BernhardHaumacher - 25 Aug 2005

Personal tools