User:Moyogo/SVG Maps

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Stripping the files from useless data[edit]

References maps[edit]

CIA World Factbook maps converted from PDF to SVG with Adobe Illustrator:

  • Stripping ns2: and ns1: tags
  • The other annoying thing is that many labels are split in two span, ex. <tspan>FRA</tspan><tspan>NCE</tspan>
  • removing useless whitespace lines
perl -0777 -pe 's/<ns[12]:.*?>//gsx; s/<\/ns[12]:.*?>//gsx; s/<foreignObject.*?\/foreignObject>//gsx; s/<\/tspan><tspan.*?>//gsx;' < INPUTFILE.svg| perl -pe 's/^\s*\n//g; s/^\t*</</g' > OUTPUTFILE.svg

World and Poles maps[edit]

These SVG have fonts encoded in them, they also have CDATA, I'm not sure what for.

perl -0777 -pe 's/<foreignObject.*?\/foreignObject>//gsx; s/<i:pgf.*?\/i:(pgf|pgfRef)>//gsx; s/<\/tspan><tspan.*?>//gsx; s/<font.*?\/font>//gsx;' < World_map_pol_2005_v02.svg| perl -pe 's/^\s*\n//g; s/^\t*</</g' > World_map_pol_2005_v02_out.svg

Changing the fonts[edit]

Changes all the font to DejaVu Sans and Serif:

cat South_america_fr.svg |perl -pe 's(Tiepolo-BookItalic)/DejaVu Sans Oblique/g; s/(Benguiat-Book|Sanvito-Roman|Tiepolo-Book)/DejaVu Sans/g; s/Helvetica-BoldOblique/DejaVu Serif BoldOblique/g; s/Helvetica-Oblique/DejaVu Serif Oblique/g; s/Tiepolo-BoldItalic/DejaVu Sans Bold Oblique/g; s/(Tiepolo-Black|Tiepolo-Bold)/DejaVu Sans Bold/g; s/Helvetica/DejaVu Serif/g;  s/font-size:([0-9]*)\.[0-9]*px/font-size:\1px/g' > South_america_fr_fonts.svg

Rounding font-size:

cat INPUTFILE.svg| perl -pe 's/font-size:([0-9]*)\.[0-9]*px/font-size:\1px/g' > OUTPUTFILE.svg

TODO[edit]

  • change fonts from uncommon ones to common ones like Bitstream or DejaVu ;-)
  • clean after Inkscape set sizes to float, set them to integers instead.
  • remove empty text or tspan elements - don't use spaces to make text wider but SVG properties