| 1 | MS RFC – SVG symbol Support with AGG |
| 2 | Kiran Anjaneya Varma Alluri |
| 3 | August 10, 2009 |
| 4 | 1 Overview |
| 5 | Popular tools such as Inkscape generate SVG graphics natively. So far MapServer has not supported the SVG format, which |
| 6 | leaves many users with the extra work of converting between formats. This RFC aims to introduce support for SVG graphics |
| 7 | as an alternate method to define vector symbols in the MapServer symbolset. |
| 8 | |
| 9 | 2 Method |
| 10 | The SVG parsing and rendering will be triggered by the following syntax: |
| 11 | SYMBOL |
| 12 | TYPE SVG |
| 13 | SVGPATH / p a t h / t o / f i l e . svg |
| 14 | END |
| 15 | The choice for using a SYMBOL for the task is to allow for the reuse of the SVG symbol easily within classes. |
| 16 | |
| 17 | 3 Technical Overview |
| 18 | In order to support the SVG format, we make use of the AGG library. The reasons for going with the AGG library are: |
| 19 | 1. It has already been integrated into MapServer. While other popular libraries, such as Cairo, can be used, they would |
| 20 | require effort to integrate into MapServer and would further introduce many dependencies into the MapServer code. |
| 21 | 2. It is a very lightweight library and delivers performance equal to, and sometimes higher than other popular libraries. |
| 22 | |
| 23 | There are some disadvantages that emerge from using the AGG library. Foremost, the AGG library has an incomplete SVG |
| 24 | specification. To avoid having to reimplement the missing subset of the specification (which would, without a doubt, be a |
| 25 | non-trivial task, and would add to the complexity of this RFC), we stick by the following techniques: |
| 26 | |
| 27 | 1. A modular design is used, where the generation of the intermediate pixmap is done by a single function so that it can be |
| 28 | easily modified to adjust to a diferent library. Thus, using a pixmap will allow us to use any rendering library. |
| 29 | 1 |
| 30 | 2. The unimplemented subset of the SVG specification is clearly provided to users in the documentation to prevent frustration |
| 31 | on their side. |
| 32 | |
| 33 | |
| 34 | To implement this functionality, the following steps needs to be accomplished: |
| 35 | 1. Implement an SVG parser. For this, we directly make use of the SVG Viewer example provided along with the AGG |
| 36 | sources. |
| 37 | 2. Modify the MapServer lexical analyzer and parser to recognize the new keywords (SVG and SVGPATH). |
| 38 | 3. Modify the symbolObj structure to store information about the SVG symbol requested (eg. File path). |
| 39 | 4. Write a single function to render a parsed SVG file to a pixmap. The pixmap will be an intermediate form that can then |
| 40 | be rendered. The pixmap will be stored in cache memory to prevent having to constantly be rasterized it every time a |
| 41 | symbol is drawn. |
| 42 | 5. Create a createBrushFromSVG() function that creates a GD image pixmap. Also modify the basic rendering functions |
| 43 | to support the new symbol type by using the createBrushFromSVG function. |
| 44 | 6. Render the pixmap into the final image file. This will be done using a mixture of the AGG and GD libraries. |
| 45 | |
| 46 | |
| 47 | 4 Files Added and Modified |
| 48 | 4.1 AGG/SVG Parser |
| 49 | The SVG parsing and pixmap generation functions will be stored in source files stored at |
| 50 | / maps e rve r / r e n d e r e r s / agg / svg / |
| 51 | The files within the above directory include the files for: |
| 52 | a. SVG Parsing |
| 53 | b. Trigger Function (based on Mapfile syntax) |
| 54 | c. SVG to Pixmap generation |
| 55 | All files are within the C++ ’mapserver’ namespace. |
| 56 | |
| 57 | 4.2 Rendering Functions |
| 58 | The rendering functions in mapgd.c will be modified to support the SVG type. These include all the basic shapes such as |
| 59 | points, lines, circles etc. These will make use of the createBrushFromSVG function to render to a GD pixmap. |
| 60 | |
| 61 | 4.3 Lexical Analyzer and Parser |
| 62 | The maplexer.l file will be modified to support two new keywords (SVG and SVGPATH). The mapsymbol.h file be modified |
| 63 | by adding SVG related data to the symbolObj structure along with basic enumerations and defines. The mapsymbol.c file’s |
| 64 | loadSymbol function will be modified to generate the required new fields in the symbolObj structure. |
| 65 | |
| 66 | |
| 67 | 5 Documentation |
| 68 | The following documentation needs to be prepared for this project: |
| 69 | 1. Missing SVG specification document. |
| 70 | 2. Basic usage tutorial of new functionality with examples. |