#!/bin/bash # # Syntax: eps2fig [-h] [-a] [-f replacement_font] [-t] [-l] [-d] eps_file [...] # # Purpose: Uses pstoedit to transform an eps, ps, or pdf file into a fig file. # If the file eps_file does not exist, first the extension .eps # is tried, next the extension .ps, and finally the extension .pdf. # If the -a flag is specified, the plot-fig driver is used. The # default is to use the (x)fig driver. # The -f flag can be used to specify the default replacement default # font. The default is Times-Roman. Other valid values are xfig fonts # such as: Helvetica, Courier, ... # Use the -t or -l option to prevent merging of text or lines # respectively. For the fig driver -l is active by default. # Use the -d flag to select a different depth for each object. # The -h flag shows the help info for this command. # # Note: This program uses pstoedit. In case that program is not installed # on your system, you can find the source code at www.pstoedit.net # # See also: adjust_fig_lines # Created: Dec 31, 2006 by Bart De Schutter # Last revised: Dec 28, 2011 by Bart De Schutter # # See http://www.deschutter.info/util/scripts.html for the latest version of # this script. # Status: public # Category: xfig # # Define default options # l_option="-mergelines" t_option="-mergetext" repl_font="Times-Roman" driver="fig" start_depth=0 # # Process options # while getopts :hatldf: option do case "$option" in h) sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1;; a) driver="plot-fig";; t) t_option="";; l) l_option="";; f) repl_font=$OPTARG;; d) start_depth=999;; :) echo >&2 echo >&2 "Option -$OPTARG requires an argument." echo >&2 sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 echo >&2 exit 1;; \?) echo >&2 echo >&2 "Unknown option: $OPTARG" echo >&2 sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1;; esac done shift $(($OPTIND-1)) # # Check whether there is any output argument present. # if [ $# -eq 0 ] then echo >&2 echo >&2 "ERROR: ${0##*/} requires at least 1 input argument." echo >&2 sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1 fi # # Define temporary directory and template. # if [[ -d ~/tmp ]] then tmp=~/tmp elif [[ ( -n "$TMPDIR" ) || ( ! -d "$TMPDIR" ) ]] then tmp="$TMPDIR" elif [[ -d /tmp ]] then tmp=/tmp else tmp=`pwd` fi tmp_template="$tmp/${0##*/}__$(date '+%Y_%m_%d__%H_%M_%S')__XXXXXXXXXXXX" # # Enable extended pattern matching operators. # shopt -q -s extglob # # Define pstoedit options. # if [ $driver == "fig" ] then driver_option="-f \"fig:-startdepth $start_depth -metric\"" l_option="" # Necessary for (x)fig driver. else driver_option="-f plot-fig -pagesize a4" fi # # Process files. # for fil in "$@" do # # Check existence of $fil, $fil.eps or $fil.ps # convert_fil=1 if [ -f "$fil" ] then basename=${fil%.?(eps|ps|pdf)} eps_fil=$fil else basename=$fil if [ -f "$basename.eps" ] then eps_fil=$basename.eps else if [ -f "$basename.ps" ] then eps_fil=$basename.ps else if [ -f "$basename.pdf" ] then eps_fil=$basename.pdf else echo >&2 "WARNING: file $fil, $fil.(e)ps, or $fil.pdf not found." convert_fil=0 fi fi fi fi if [ "$convert_fil" == 1 ] then # # Convert file. # echo "Converting $eps_fil to fig file $basename.fig" tmp_fil=$(mktemp "${tmp_template}") || exit 1 eval pstoedit $driver_option $l_option $t_option \ -df $repl_font "$eps_fil" \ "$tmp_fil" # # Remove comments and redefine some initial options. # echo "#FIG 3.2" > "$basename.fig" if [ $driver == "fig" ] then cat "$tmp_fil" | grep -v '^#' | \ sed 's/^Letter$/A4/;s/^Flush left$/Center/;s/^0$/-2/' \ >> "$basename.fig" else cat "$tmp_fil" | grep -v '^#' | \ sed 's/^Flush Left$/Center/' >> "$basename.fig" fi \rm "$tmp_fil" fi done