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

  1. !/usr/bin/perl -i.old
  1. original source: https://en.wikipedia.org/wiki/Wikipedia:WikiProject_Chemistry/Structure_drawing_workgroup/Mysid%27s_script
  1. Note: "-i.old" means original file will be renamed to .old
  2. Modify svg file from BKchem to work with librsvg, for use on Wikimedia.

use warnings;

use strict;

my $font_size = 24;

while (<>) {

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

#on Helvetica.

s/helvetica/Sans/gi;

if(m#]+font-size="([0-9]+)pt"#){

$font_size = $1;

}

# Convert relative font sizes to absolute font sizes

s#(font-size=")([0-9]+)%(")#$1.($2*$font_size/100)."pt".$3#ge;

# Replace baseline-shift="super" with a numeric baseline-shift

if (/y="([\d\.]+)">.*

my $vy = $1;

my $oy = $1-4;

s/baseline-shift="super"/y="$oy"/g;

s#([^<]+)<#$1<#g;

}

# Replace baseline-shift="sub" with a numeric baseline-shift

if (/y="([\d\.]+)">.*

my $vy = $1;

my $oy = $1+3.25;

s/baseline-shift="sub"/y="$oy"/g;

s#([^<]+)<#$1<#g;

}

#write each line out after mangling it.

print $_;

}