🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.postscript
Article #110

Re: EPS preview bitmap

#110
From: Jon White
Date: Mon, 02 Nov 1992 22:47
234 lines
7313 bytes
cherkaue@ee.rochester.edu (Brian Cherkauer) writes:
: I'm in need of a utility which can take an eps file which 
: does not contain a "preview bitmap" and generate the preview 
: bitmap so that graphics editors which contain no postscript 
: interpretors, yet allow for the inclusion of eps files, are 
: able to display the image on screen.

eps2epsi is a perl script written by Gisle Aas that converts 
all types of EPS files to the EPSI format with a preview bitmap.  
Enjoy...

--cut here--
#!/bin/sh
# This is a shell archive (produced by shar 3.49)
# To extract the files from this archive, save it to a file, remove
# everything above the "!/bin/sh" line above, and type "sh file_name".
#
# made 09/23/1992 11:04 UTC by aas@solnes
# Source directory /nr/boeygen/u2/aas/eps2epsi
#
# existing files will NOT be overwritten unless -c is specified
#
# This shar contains:
# length  mode       name
# ------ ---------- ------------------------------------------
#   5005 -rwxr-xr-x eps2epsi
#
# ============= eps2epsi ==============
if test -f 'eps2epsi' -a X"$1" != X"-c"; then
        echo 'x - skipping eps2epsi (File already exists)'
else
echo 'x - extracting eps2epsi (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'eps2epsi' &&
#!/usr/local/bin/perl
'di';
'ig00';
X
# 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.
X
# $Log: eps2epsi,v $
# Revision 1.4  1992/09/08  17:41:27  aas
# Some applications makes real (not integer) boundingbox coordinates, despite
# what the DSC says.  These applications should really be fixed.  But while we
# wait for that to happen....
#
# Revision 1.3  1992/08/25  14:56:05  aas
# Hvis kommentarene i begynnelsen ikke sluttet med %%EndComments, se spiste
# vi opp fxrste linje av postscript koden.
#
# Revision 1.2  1992/07/30  13:32:19  aas
# Oppdatert for GhostScript versjon 2.4.  Det var ny syntaks for
# makeimagedevice.
#
# Revision 1.1  1991/05/28  09:18:04  aas
# Initial revision
#
X
$prog_name = substr($0,rindex($0,"/")+1);
require 'getopts.pl';
unless (&Getopts('w:')) {
X  print STDOUT "Usage: $prog_name [-w <preview width>] [<file>]\n";
X  exit 1;
}
X
die 'To many files' if ($#ARGV > 0);
X
@epsfile = <>;                  # slurp
die 'Not PostScript file' unless ($epsfile[0] =~ /^%!PS-Adobe-/);
X
# Get the dimensions of the picture
for (@epsfile) {
X   ($llx, $lly, $urx, $ury) =
X      /^%%BoundingBox:\s*(-?[0-9\.]+)\s+(-?[0-9\.]+)\s+(-?[0-9\.]+)\s+(-?[0-9\.]+)/;
X   last if defined($llx);
}
die "No %%BoundingBox found in file" unless defined($llx);
X
# 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);
X
# 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
X
%---- 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
X
%--- Some transformations
/showpage {} def
$scalefactor dup scale
$llx neg $lly neg translate
X
%--- The old EPS file
@epsfile
X
%---- 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
X   output (%) writestring
X   currentdevice exch
X   line copyscanlines
X   output exch writehexstring
X   output 10 write
} for
output flushfile
quit
---EndGhostScriptProgram---
X
close GSFILE;
close STDIN;    # so that GhostScript can't read it.
X
@gsoutput = `gs -q -DNODISPLAY $gsfile`;   # run GhostScript
die "Can't run GhostScript" unless $? == 0;
unlink $gsfile;
X
@preview = grep(/^-----/ .. 1, @gsoutput);   # remove GhostScript garbage
shift(preview);
if ($#preview < 0) {
X  print STDERR "GhostScript gives no output for the specified file\n";
X  print STDERR @gsoutput;
X  exit 1;
}
X
print shift(epsfile);
$_ = shift(epsfile);
while (/^%%/) {
X  if (/^%%BoundingBox:/) {
X    print "%%BoundingBox: $llx $lly $urx $ury\n" if !defined($boundingbox);
X    $boundingbox = 1;
X  } elsif (/^%%EndComments/) {
X    last;
X  } else {
X    print;
X  }
X  $_ = 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";
X
print $_ unless /^%%/;
print grep(!(/^%%BeginPreview:/ .. /^%%EndPreview/) && !/^%%BoundingBox:/,
X          @epsfile);
X
X
X
X
X
###########################################################################
X       # These next few lines are legal in both Perl and nroff.
X
.00;                    # finish .ig
X 
'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
SHAR_EOF
chmod 0755 eps2epsi ||
echo 'restore of eps2epsi failed'
Wc_c="`wc -c < 'eps2epsi'`"
test 5005 -eq "$Wc_c" ||
        echo 'eps2epsi: original size 5005, current size' "$Wc_c"
fi
exit 0
Technical Details
Message-ID: <Bx41yH.LC4@unx.sas.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!ogicse!decwrl!concert!sas!mozart.unx.sas.com!sasjqw
References: <1992Nov2.202828.26752@ee.rochester.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!ogicse!decwrl!concert!sas!mozart.unx.sas.com!sasjqw
From: sasjqw@micro.unx.sas.com (Jon White)
Newsgroups: comp.lang.postscript
Subject: Re: EPS preview bitmap
Message-ID: <Bx41yH.LC4@unx.sas.com>
Date: 2 Nov 92 22:47:04 GMT
Article-I.D.: unx.Bx41yH.LC4
References: <1992Nov2.202828.26752@ee.rochester.edu>
Sender: news@unx.sas.com (Noter of Newsworthy Events)
Organization: SAS Institute Inc.
Lines: 234
Originator: sasjqw@micro.unx.sas.com
Nntp-Posting-Host: micro.unx.sas.com