csk157/paper.js — pull request #1 by mdiin (2014-04-26 14:20:43+00:00)
Title: Add SVG export of patterns.

# Additions

- In `src/style/Color.js` the functions `pattern-rgb` and `rgb-pattern` are dummies required for the color code, but otherwise do nothing (as patterns are not really colors).
- In `src/svg/SVGExport.js` the pervasive `options` map can have a `pattern` key, a boolean with value `true` when the item is used in a pattern, and `undefined` or `false` otherwise.

## `exportPattern`

Uses the same general shape as the rest of the `export*` functions, i.e. look up existing patterns using `getDefinition`, and otherwise create stuff. I decided on putting patterns in the `'color'` part of the definitions simply because they are most like colors (and the rest of the pattern code is implemented like a color as well).

To create the content of the SVG pattern node I use the created `exportSVG` function that delegates to the correct export functions for whatever elements are inside the pattern; thus, we can export both patterns created from other elements as well as from images using rasters.

### In the `attr` map

The size of the pattern is set to the bounds of the contained item to make sure that the entire pattern item is used.

The `patternUnits` is set to use a coordinate system based on the place where the pattern is inserted (I think, not quite sure I understand the specs here, but it does what I want it to do ;-) ).

# Changes

- `exportShape` function uses the `pattern` key in the `options` object.
- `exportRaster` function uses the `pattern` key in the `options` object.
- Extra spaces removed ;-)

## `exportShape`

I noticed that circle shapes exported as part of patterns would be shifted towards the top left corner. To show the entire shape in the pattern I am adding the radius of the circle to both the `x` and `y` axis, as that will shift the circle to the center of the generated SVG circle. This is why the `pattern` option is necessary for `exportShape`.

## `exportRaster`

For rasters I experienced the same as for shapes, i.e. the generated objects would be shifted away from the center. To fix this I conditionally remove the "take into account that rasters are centered" part of the code if the `options` object contains `pattern: true`.