Jump to content

Wikipedia talk:WikiProject Chemistry/Structure drawing workgroup/Mysid's script

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

This is a script originally written by User:Mysid and hacked by me (User:Slashme) to re-write the SVGs produced by BKchem for use by librsvg. It is still rough around the edges in the implementation, but I have used it for a few drawings already, and all of them have come out of the script in a form that is immediately uploadable and properly interpreted by librsvg. Sometimes the text is slightly misplaced, because BKchem can't know exactly what font will be used on the server, so you might have to adjust label positions with inkscape after drawing the structure.

What it does is:

  • Changes all text in "Helvetica" to "Sans", because that's a generic font that should work everywhere
  • Rounds off dimensions to save space (this can make a very noticeable difference to file-size and readability. It is easy to tweak the script to round off more or less if required.)
  • Changes subscripts and superscripts to <tspan> elements to work around a librsvg bug
  • Lumps some drawing elements into the same group where easily detectible to save space.

I removed the code that auto-crops the image, because there is a setting in BKchem that does that (under "File -> File properties")

The script should be phased out in the medium term, as the incompatibilities between BKchem and librsvg are purely due to librsvg's still incomplete implementation of the svg standard. --Slashme 08:25, 25 October 2007 (UTC)[reply]

Image::Magick module

[edit]

When I first tried to run this script (I'm on an XP box using ActivePerl) I got the following error:

Can't locate Image/Magick.pm in @INC (@INC contains: C:/Perl/site/lib C:/Perl/lib .) at chemistry\svg.pl line 3. BEGIN failed--compilation aborted at chemistry\svg.pl line 3.

To get this script to work, I had to comment out this line:

use Image::Magick;

Looking at the script, I'm not sure it was needed anyways. I was thinking of installing ImageMagick, but I don't see the point if it's unnecessary. Could someone weigh in? --JaGa (talk) 18:23, 14 July 2008 (UTC)[reply]

You're right; it doesn't use Imagemagick any more. I've removed the line. (PS. It's great to see this script finding use :) ›mysid () 03:22, 15 July 2008 (UTC)[reply]
Oh yeah, this is a great script. I use it after I draw a structure with BKChem and Inkscape and everything works without a hitch. Thanks for the help! --JaGa (talk) 04:15, 15 July 2008 (UTC)[reply]

Suggestion for script

[edit]

Hi, I use this script for every SVG I do (and I've done quite a few now) and I found I needed to make one addition. From time to time I would have to rotate objects to get them just right, and when I ran the script, those objects would be improperly located in the SVG. I was able to avoid the problem by adding the following

   if (/matrix/) {
     print OUTPUT $_;
     next;
   }

to the script right before this comment

   #Sans is the most general font definition we can use, and librsvg chokes
   #on Helvetica.

Could we add it to the online script? --JaGa (talk) 19:22, 10 August 2008 (UTC)[reply]

UPDATE: I was testing a complex drawing and found that the problem is rounding within the matrix() call. I've changed the script to only avoid matrix() lines. Sometimes this call occurred outside the <defs> block, leading to errors in object positioning. Also, simplified SVGs use <defs ... /> instead of a closing </defs>, which broke the script as well. This fix takes care of both problems. --JaGatalk 07:04, 28 August 2008 (UTC)[reply]

User guide?

[edit]

How do you use this script? Do I need to copy the text and run it via some program? --Rifleman 82 (talk) 02:35, 4 February 2009 (UTC)[reply]

You'll need to have Perl installed. Copy the text in a file and save it as svgscript.pl, for instance. In the command line, go to the directory containing your SVG file and type: perl svgscript.pl myfile.svg. The output file will be called myfile2.svg. ›mysid () 15:22, 4 February 2009 (UTC)[reply]

Still rolling

[edit]

Not bad for a script that "should be phased out"... changes to librsvg on wikimedia servers have been slow. I think it's hard for Windows users to get the script to run and IMO it's the best option, as it preserves fonts as fonts and also (at least in my limited tests) stays editable with bkchem. Even cairo export doesn't do that. So... good work, it's a simple solution and still usable after so much time (partly because there aren't too many changes to bkchem, I guess).

I think it would be useful to set this up behind a webinterface, so windows users can also use it. I will do that as a test on my server (which isn't ideal), perhaps it's something toolserver could do - or that could even be integrated into the upload to commons? Iridos (talk) 19:33, 24 September 2011 (UTC)[reply]

Wow, I haven't been watching this page, but this is really interesting - any updates? --Slashme (talk) 18:40, 8 June 2012 (UTC)[reply]