The possibility of adding SVG support via a "svglib.c" extension

Added by Paul almost 5 years ago

This is mostly notes from a discussion with Christoph Moder who had hacked parts of gmt_plot.c and pslib.c to write svg instead of PostScript.

svg is vector graphics like PS, but made for the web (PS is for print). svg is an open specification and there are tools (e.g., the free inkscape) that can read and write svg and let you edit (similar to the commercial Adobe Illustrator).
There are some unanswered questions:

  1. Are there on-to-one equivalent svg commands to all ps commands used in pslib?
  2. svg simplifies grouping of objects. is there an equivalent PS comment?
  3. Can pstoedit be used to convert PS to svg, thus bypassing this idea entirely?

Some action items:

  1. We decided that first, pslib should issue the DSC comments %%BeginObject and %%EndObject to organize GMT layers. It is not clear yet if these are parsed and acted on by Illustrator or pstoedit but they should so this is a simple thing to do. This was implemented Nov 29, 2012.
  2. Find all PSL_command statements that write free-form PS and see if we can abstract these into general PSL commands; otherwise an SVG version would not be straightforward. I.e., we want to isolate all writing via the PSL library so that a replacement SVG library is possible in the future.
  3. Experiment with the limitations of pstoedit. Looks like it does not translate PS images to SVG, which was surprising. However, inkscape seems capable of parsing both PS and PDF so it is worth determining what the limitations are, perhaps give feedback to the pstoedit developer, before we embark on a SVG implementation in GMT.

If it seems worth doing we will make a branch for playing with this, requesting volunteers to help with the implementation of the svglib.c functionality.


Replies (2)

RE: The possibility of adding SVG support via a "svglib.c" extension - Added by Paul almost 5 years ago

As some further testing I tried to open Example 29 PostScript file in inkscape. That plot has a mix of images with clip masks, contours, symbols, text, in other words a fairly complicated plot representative of many GMT illustrations. The PS imported just fine. Using the ungroup menu (multiple times) I was able to get to any little detail one might wish to change, such as lines and points, text items etc. Looked pretty good to me, so I guess one would need to come up with a case where things don't work as well to justify having native SVG output in GMT. Whatever inkskape is doing, it clearly is able to parse the PS correctly. Interestingly, when I saved the original PS to plain svg, I found the following:

1. inkscape could read the svg back in, successfully, so everything is retained in the svg file.
2. Illustrator (CS4 version) read the svg, complained that clipping will be lost, then gave a garbled plot with lots of things missing, some lines with very thick pens, etc; basically useless. it is possible AI CS6 will do better but I have my doubts. Please provide feedback if you have CS6.
3. Safari and Firefox browsers read the svg but the images were scaled incorrectly, clipping did not work, and the psscale bars were blank. I guess it is the common webkit that has the bug.

So things don't look too mature or consistent across applications. If the basic viewers have trouble with anything complicated then people simply will not use this for figures. Perusing the W3C pages on SVG lists the same tools and viewers as above, so looks like there is very slow progress on accepting SVG. Given all of this it is hard to justify spending development time having GMT produce SVG natively at the present time.

RE: The possibility of adding SVG support via a "svglib.c" extension - Added by Paul over 3 years ago

Time for an update, June 2014: I have added SVG as a new output format in ps2raster, since gs has a svg driver. I experimented a bit with example 33 in this case. The SVG produced is viewable in the browser but label clipping along contours is deactivated. Using inkscape to convert the PDF to SVG keeps the clipping correct, but the SVG as written causes the image to be misrepresented in the browser. Finally, using Adobe Illustrator 6 to write out SVG form PDF yields a similar result. Importing the ps2raster-generated SVG into Illustrator results in fat pens (factor of 10?). So it continues to be non-prime-time for SVG, the W3C standard...

(1-2/2)