Created
November 13, 2012 14:54
-
-
Save ssp/4066135 to your computer and use it in GitHub Desktop.
Convert Windows EMF to usable graphics files with a crazy chain of tools.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# Convert Windows EMF to usable graphics files with a crazy chain of tools. | |
# 2012 Sven-S. Porst, SUB Göttingen <porst@sub.uni-goettingen.de> | |
# Configuration | |
BASEPATH=/Users/ssp/SUB/edfu/emf | |
WINE=wine | |
METAFILE2EPS=$BASEPATH/metafile2eps-linux/metafile2eps.exe | |
PS2PDF=ps2pdf | |
INKSCAPE=/Applications/Graphik/Inkscape.app/Contents/Resources/bin/inkscape | |
XSLTPROC=xsltproc | |
XSLT=$BASEPATH/svg-stroke-width.xsl | |
# Variables | |
INPATH=$1 | |
OUTPATH=$2 | |
UUID=`uuidgen` | |
TMPPATH=/tmp/emf-converter-$UUID | |
mkdir $TMPPATH | |
# Step 1: EMF -> EPS | |
# Requires Wine and CUPS configured for this purpose. | |
# http://wiki.lyx.org/Windows/MetafileToEPSConverter | |
DOSINPATH=`winepath --windows "$INPATH"` | |
EPSPATH=$TMPPATH/file.eps | |
DOSEPSPATH=`winepath --windows "$EPSPATH"` | |
"$WINE" "$METAFILE2EPS" "$DOSINPATH" "$DOSEPSPATH" | |
# Step 2: EPS -> PDF | |
# Requires Ghostscript’s ps2pdf. | |
PDFPATH=$TMPPATH/file.pdf | |
"$PS2PDF" "$EPSPATH" "$PDFPATH" | |
# Step 3: PDF -> SVG | |
# Requires: Inkscape. | |
SVGPATH=$TMPPATH/file-temp.svg | |
"$INKSCAPE" --without-gui --export-plain-svg="$SVGPATH" "$PDFPATH" | |
# Step 4: SVG -> SVG | |
# Requires: libxml’s xsltproc. | |
# Apply XSL to set a line width which was lost in the preceding steps. | |
SVG2PATH=$TMPPATH/file.svg | |
"$XSLTPROC" "$XSLT" "$SVGPATH" > $SVG2PATH | |
rm "$SVGPATH" | |
# Step 5: SVG -> PNG | |
# Requires Inkscape. | |
PNGPATH=$TMPPATH/file.png | |
"$INKSCAPE" --without-gui --export-height=200 --export-area-drawing --export-png="$PNGPATH" "$SVG2PATH" | |
TARGETPATH=$INPATH-converted | |
mv "$TMPPATH" "$TARGETPATH" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!-- | |
Remove styles from SVG file and add a stroke width to its path. | |
2012 Sven-S. Porst, SUB Göttingen <porst@sub.uni-goettingen.de> | |
--> | |
<xsl:stylesheet | |
version="1.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:svg="http://www.w3.org/2000/svg" | |
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"> | |
<xsl:output indent="yes" method="xml" version="1.0" encoding="UTF-8"/> | |
<xsl:template match="@*|node()"> | |
<xsl:copy> | |
<xsl:apply-templates select="@*|node()"/> | |
</xsl:copy> | |
</xsl:template> | |
<xsl:template match="@style"> | |
<xsl:attribute name="style"> | |
<xsl:text>stroke:#000000;stroke-width:8;stroke-miterlimit:4;stroke-dasharray:none;fill:none;stroke-opacity:1</xsl:text> | |
</xsl:attribute> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment