MS RFC - SVG Symbol Support with AGG
Author: Kiran Anjaneya Varma Alluri
Contact: kiran.varma2k7 at gmail.com
Last Edited: 2009/07/12
Version: MapServer 6.0
Id: $Id: $
Popular tools such as Inkscape generate SVG graphics natively. So far MapServer has not supported
the SVG format, which leaves many users with the extra work of converting between formats. This RFC aims to introduce support for SVG graphics as an alternate method to de ne vector symbols in the MapServer symbolset.
The SVG parsing and rendering will be triggered by the following syntax:
SYMBOL TYPE VECTOR FILE / path / to / f i l e . svg END
The choice for using a SYMBOL for the task is to allow for the reuse of the SVG symbol easily within classes.
3 Technical Overview.
In order to support the SVG format, we make use of the AGG library. The reasons for going with the AGG library are:
- It has already been integrated into MapServer. While other popular libraries, such as Cairo, can be used, they would require effort to integrate into MapServer and would further introduce many dependencies into the MapServer code.
- It is a very lightweight library and delivers performance equal to, and sometimes higher than other popular libraries.
There are some disadvantages that emerge from using the AGG library. Foremost, the AGG library has an incomplete SVG specification. To avoid having to reimplement the missing subset of the specification (which would, without a doubt, be a non-trivial task, and would add to the complexity of this RFC), we stick by the following techniques:
- A modular design is used, where the generation of the intermediate pixmap is done by a single function so that it can be easily modified to adjust to a different library. Thus, using a pixmap will allow us to use any rendering library.
- The unimplemented subset of the SVG specification is clearly provided to users in the Documentation to prevent frustration on their side.
To implement this functionality, the following steps needs to be accomplished:
- Implement an SVG parser. For this, we directly make use of the SVG Viewer example provided along with the AGG sources.
- Write a single function to render a parsed SVG
file to a pixmap.The pixmap will be an intermediate form that can then be rendered.The pixmap will be stored in cache memory to prevent having to constantly be rasterized it every time a symbol is drawn.
- Render the pixmap into the final imagefile. This will be done using a mixture of the AGG and GD libraries.
4 Files Added.
Finally, the SVG parsing and pixmap generation functions will be stored in source files stored at
/ mapserver / r e n d e r e r s / agg / svg /
The files within the above directory include the files for:
- SVG Parsing.
- Trigger Function (based on Map
- SVG to Pixmap generation.
All files are within the C++ 'mapserver' namespace.
The following documentation needs to be prepared for this project:
- Missing SVG specification document.
- Basic usage tutorial with examples.