-
Notifications
You must be signed in to change notification settings - Fork 3
/
bbox_clean.sh
executable file
·148 lines (111 loc) · 2.61 KB
/
bbox_clean.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/bash
G_SYNOPSIS="
NAME
bbox_clean.sh
SYNOPSIS
bbox_clean.sh [-v] <file1.[e]ps> ... <fileN.[e]ps>
DESCRIPTION
'bbox_clean.sh' cleans OpenOffice eps exports by reducing
the PostScript BoundingBox line to a box containing only
the image and no superfluous white space.
This is achieved in something of a round-about way. The original
input file is run through ps2epsi. The resultant file has the
correct BoundingBox parameter. This is extracted and copied
back into the original file.
TODO
PRECONDITIONS
o It is assumed that the OpenOffice.org generated eps files have
a bounding box of 0 0 575 755!!
HISTORY
14 April 2004
o Initial design and coding.
"
###\\\
# Global variables
###///
SELF=`basename $0`
# Actions
A_comargs="checking command line arguments"
# Error messages
EM_noPSFiles="no Postscript files specified!"
# Error codes
EC_noPSFiles=1
# Defaults
D_VERBOSE="NO"
###\\\
# Function definitions
###///
function shut_down
# $1: Exit code
{
if [ $D_VERBOSE = "YES" ] ; then
echo -e "\n$SELF:\n\tShutting down with code $1.\n"
fi
exit $1
}
function synopsis_show
{
echo "USAGE:"
echo -e "\t$SELF [-v] [-h] <file1.[e]ps> ... <fileN.[e]ps>"
echo -e ""
shut_down 1
}
function help_show
{
echo "$G_SYNOPSIS"
shut_down 1
}
function error
# $1: Action
# $2: Error string
# $3: Exit code
{
echo -e "\n$SELF:\n\tSorry, but there seems to be an error." >&2
echo -e "\tWhile $1," >&2
echo -e "\t$2\n" >&2
synopsis_show
shut_down $3
}
function warn
# $1: Action
# $2: Warn string
# $3: Default value
{
echo -e "\n$SELF: WARNING\n" >&2
echo -e "\tWhile $1," >&2
echo -e "\t$2\n" >&2
echo -e "\tSetting default to '$3'\n" >&2
}
###\\\
# Process command options
###///
while getopts "vh" option ; do
case "$option"
in
v ) D_VERBOSE="YES" ;;
h ) help_show;;
\? ) synopsis_show ;;
esac
done
shift $(($OPTIND - 1))
if [ "$#" = 0 ] ; then
error "$A_comargs" "$EM_noPSFiles" "$EC_noPSFiles"
fi
for FILEEXT in $*
do
if [ $FILEEXT != "-v" ]; then
FILE=`basename $FILEEXT .eps`
if [ $D_VERBOSE = "YES" ] ; then
echo -n "$FILEEXT --> ${FILE}.epsi"
fi
ps2epsi $FILEEXT ${FILE}.epsi
bbox=$(cat ${FILE}.epsi | grep Bounding)
cat $FILEEXT | sed "s/%%BoundingBox: 0 0 575 755/$bbox/" > ${FILE}.1.eps
if [ $D_VERBOSE = "YES" ] ; then
echo " --> ${FILE}.1.eps --> $FILEEXT"
fi
mv ${FILE}.1.eps $FILEEXT
rm ${FILE}.epsi
fi
done
shut_down 0