SVG Path Semantics

From Apache OpenOffice Wiki
Revision as of 13:21, 29 December 2005 by Haui (Talk | contribs)

Jump to: navigation, search
OOoSVG-110.png
SVG Import
(external impl.)
Overview
Download
Source code
Features
Restrictions
FAQ
TODO
OpenDocument
Gradients
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).

<img src="/test-non-closed-path1.png" />

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 shows two paths with the only difference that the left one is not closed but the right one is. The start and end point of the non-closed path on the left is the point surrounded with a green circle. Closing the path affects the line joining of its stroke.

<img src="/test-non-closed-path2.png" />      <img src="/test-closed-path3.png" />

Figure 2 Non-closed path with identical start and end position (left) vs. closed path (right).

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


Discussion

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



test-non-closed-path1.png Non-closed but filled SVG path.

test-non-closed-path2.png Non-closed path with identical start and end position.

test-closed-path3.png Closed path.

Personal tools