Wikipedia:WikiProject Chemistry/Structure drawing workgroup/Mysid's script
- !/usr/bin/perl -i.old
- original source: https://en.wikipedia.org/wiki/Wikipedia:WikiProject_Chemistry/Structure_drawing_workgroup/Mysid%27s_script
- Note: "-i.old" means original file will be renamed to
.old - 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 = $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#
}
# 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#
}
#write each line out after mangling it.
print $_;
}