Article View: comp.lang.postscript
Article #6148Re: Converting .ps to .eps
From: Gisle Aas
Date: Wed, 29 May 1991 15:37
Date: Wed, 29 May 1991 15:37
189 lines
5720 bytes
5720 bytes
In article <15708@adobe.UUCP> orthlieb@adobe.COM (Carl Orthlieb) writes:
> you should then have an EPS file (w/o a preview).
And if you want to have an EPS file WITH a preview, and you have
GhostScript, and you have perl, then you can try to filter the file
through the following program.
Enjoy!
------cut here-----
#!/usr/local/bin/perl
'di';
'ig00';
# EPSI file generator. Written by Gisle Aas, NR, 1991
# Converts all types of EPS-files to the EPSI format where a bitmap preview
# is included. You need GhostScript to render the bitmaps for you.
# $Log: eps2epsi,v $
# Revision 1.1 1991/05/28 09:18:04 aas
# Initial revision
#
$prog_name = substr($0,rindex($0,"/")+1);
require 'getopts.pl';
unless (&Getopts('w:')) {
print STDOUT "Usage: $prog_name [-w <preview width>] [<file>]\n";
exit 1;
}
die 'To many files' if ($#ARGV > 0);
@epsfile = <>; # slurp
die 'Not PostScript file' unless ($epsfile[0] =~ /^%!PS-Adobe-/);
# Get the dimensions of the picture
for (@epsfile) {
($llx, $lly, $urx, $ury) =
/^%%BoundingBox:\s*(-?\d+)\s+(-?\d+)\s+(-?\d+)\s+(-?\d+)/;
last if defined($llx);
}
die 'No %%BoundingBox found in file' unless defined($llx);
# Calculate
$preview_width = int(($opt_w || 79) / 2) * 8;
$width = $urx - $llx + 1;
$height = $ury - $lly + 1;
$scalefactor = $preview_width / $width;
$width = int($width * $scalefactor);
$height = int($height * $scalefactor);
# Produce GhostScript program
$gsfile = "/tmp/gs$$.tmp";
open(GSFILE, ">$gsfile") || die "Can't write to file $gsfile";
print GSFILE <<"---EndGhostScriptProgram---";
%!GhostScript
/BITIMAGE_WIDTH $width def
/BITIMAGE_HEIGHT $height def
/BITIMAGE_FILE (%stdout) def
%---- Setup a memory device --------
[1 0 0 -1 0 BITIMAGE_HEIGHT]
BITIMAGE_WIDTH BITIMAGE_HEIGHT
[1 1 1 rgbcolor 0 0 0 rgbcolor]
makeimagedevice
setdevice
%--- Some transformations
/showpage {} def
$scalefactor dup scale
$llx neg $lly neg translate
%--- The old EPS file
@epsfile
%---- Print bitmap on a file -------
/line BITIMAGE_WIDTH 8 idiv 1 add string def
/output BITIMAGE_FILE (w) file def
output (---------) writestring
output 10 write
0 1 BITIMAGE_HEIGHT 1 sub { %for
output (%) writestring
currentdevice exch
line copyscanlines
output exch writehexstring
output 10 write
} for
output flushfile
quit
---EndGhostScriptProgram---
close GSFILE;
close STDIN; # so that GhostScript can't read it.
@gsoutput = `gs -q -DNODISPLAY $gsfile`; # run GhostScript
die "Can't run GhostScript" unless $? == 0;
unlink $gsfile;
@preview = grep(/^-----/ .. 1, @gsoutput); # remove GhostScript garbage
shift(preview);
if ($#preview < 0) {
print STDERR "GhostScript gives no output for the specified file\n";
print STDERR @gsoutput;
exit 1;
}
print shift(epsfile);
$_ = shift(epsfile);
while (/^%%/) {
if (/^%%BoundingBox:/) {
print "%%BoundingBox: $llx $lly $urx $ury\n" if !defined($boundingbox);
$boundingbox = 1;
} elsif (/^%%EndComments/) {
last;
} else {
print;
}
$_ = shift(epsfile);
}
print "%%BoundingBox: $llx $lly $urx $ury\n" if !defined($boundingbox);
print "%%EndComments
%%BeginPreview: $width $height 1 $height\n";
print @preview;
print "%%EndPreview\n";
print grep(!(/^%%BeginPreview:/ .. /^%%EndPreview/) && !/^%%BoundingBox:/,
@epsfile);
###########################################################################
# These next few lines are legal in both Perl and nroff.
.00; # finish .ig
'di \" finish diversion--previous line must be blank
.nr nl 0-1 \" fake up transition to first page again
.nr % 0 \" start at page 1
';<<'.ex'; #__END__ #### From here on it's a standard manual page #########
.TH EPS2EPSI 1 "May 1991"
.SH NAME
eps2epsi \- Filter for inclusion of a preview in an EPS file
.SH SYNOPSIS
.B eps2epsi
[
.B \-w
.I preview_width
] [
.I filename
]
.SH DESCRIPTION
.B Eps2epsi
puts a preview section in a PostScript file (preferably EPSF).
The preview produced
is in the encapsulated PostScript interchange format (EPSI)
suitable for import by FrameMaker and other document composing
systems.
.B Eps2epsi
reads the file specified (or standard input) and sends the new file
with the preview included to standard output.
.PP
.B Esp2epsi
uses
.B GhostScript
to render the preview bitmap, which means that
.B GhostScript
must be installed at your system before you can use
.B eps2epsi.
.SH OPTIONS
.TP 5
.BI \-w " n"
Set the width (in characters) of the preview section. This also specifies the
resolution of the preview as
.I n
times 4 horizontally.
.SH SEE ALSO
.BR perl (1),
.BR gs(1)
.SH AUTHOR
Gisle Aas, Norwegian Computing Center (NR), Oslo, Norway.
<Gisle.Aas@nr.no>
.ex
--
Gisle Aas | snail: Boks 114 Blindern, N-0314 Oslo, Norway
Norsk Regnesentral | X.400: G=Gisle;S=Aas;O=nr;P=uninett;C=no
voice: +47-2-453561 | inet: Gisle.Aas@nr.no
Technical Details
Message-ID:
<AAS.91May29173725@aase.nr.no>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!ucbvax!bloom-beacon!eru!hagbard!sunic!ugle.unit.no!nuug!ulrik!aasReferences:
<BJORN.B.LARSEN.91May24114535@engels.delab.sintef.no> <15708@adobe.UUCP>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!ucbvax!bloom-beacon!eru!hagbard!sunic!ugle.unit.no!nuug!ulrik!aas From: aas@aase.nr.no (Gisle Aas) Newsgroups: comp.lang.postscript Subject: Re: Converting .ps to .eps Message-ID: <AAS.91May29173725@aase.nr.no> Date: 29 May 91 15:37:24 GMT References: <BJORN.B.LARSEN.91May24114535@engels.delab.sintef.no> <15708@adobe.UUCP> Sender: news@ulrik.uio.no (Mr News) Reply-To: Gisle.Aas@nr.no Distribution: comp Organization: Norwegian Computing Centre, Oslo, Norway Lines: 189 In-Reply-To: orthlieb@adobe.COM's message of 28 May 91 19:04:57 GMT Nntp-Posting-Host: aase.nr.no