Article View: comp.lang.postscript
Article #2044Re: EPSI?
From: Jon White
Date: Mon, 31 Aug 1992 18:58
Date: Mon, 31 Aug 1992 18:58
195 lines
6086 bytes
6086 bytes
In article <KFILES.92Aug31110335@virtual8.harvard.edu>, kfiles@virtual8.harvard.edu (Kirby Files) writes:
|> I have a variation on an FAQ. How can one generate an EPSI format
|> file? I can transform a PS file to EPS no problem, that's trivial.
|> But does anyone out there know where I can get my hands on a spec for
|> EPSI, which apparently has some for of text encoded bitmap preview,
|> and does anyone have any ideas for generating that preview. Perhaps
|> using Ghostscript to generate a bitmap, and then somehow properly
|> encoding that bitmap in correct EPSI format?
|>
|> I'm using FrameMaker on a Sun, and it's really particular about
|> importing PS; it will only accept EPSI. Any other ideas on getting
|> FM to accept a PS file as graphic, and not text would be appreciated.
Here's a perl script for generating EPSI files from EPS files:
--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] =~ /^%!/);
# 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] <-- 2.3 arguments
% <ff 00> <-- 2.4 arguments from ghost@aladdin.com
%
<ff 00>
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
Technical Details
Message-ID:
<Btv3D1.Gx2@unx.sas.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!olivea!decwrl!concert!sas!mozart.unx.sas.com!sasjqwReferences:
<KFILES.92Aug31110335@virtual8.harvard.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!olivea!decwrl!concert!sas!mozart.unx.sas.com!sasjqw From: sasjqw@donne.unx.sas.com (Jon White) Newsgroups: comp.lang.postscript Subject: Re: EPSI? Message-ID: <Btv3D1.Gx2@unx.sas.com> Date: 31 Aug 92 18:58:13 GMT References: <KFILES.92Aug31110335@virtual8.harvard.edu> Sender: news@unx.sas.com (Noter of Newsworthy Events) Distribution: comp Organization: SAS Institute Inc. Lines: 195 Originator: sasjqw@donne.unx.sas.com Nntp-Posting-Host: donne.unx.sas.com