🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.postscript
Article #351

Re: EPS files and preview bitmaps

#351
From: Gisle Aas
Date: Mon, 27 Jul 1992 13:24
221 lines
6665 bytes
In article <3151@peking.gdwb.oz.au> was@gdwb.oz.au (Warren Stokes) writes:

                                                If so, is there a way of
   generating this type of file from and EPS without a preview bitmap?

This simple perl-script does the job. You will need GhostScript to
make it run.

--Gisle

#!/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 07/27/1992 12:20 UTC by aas@solnes
# Source directory /nr/boeygen/u2/aas
#
# existing files will NOT be overwritten unless -c is specified
#
# This shar contains:
# length  mode       name
# ------ ---------- ------------------------------------------
#   4441 -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.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*(-?\d+)\s+(-?\d+)\s+(-?\d+)\s+(-?\d+)/;
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 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 4441 -eq "$Wc_c" ||
	echo 'eps2epsi: original size 4441, current size' "$Wc_c"
fi
exit 0
--
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.92Jul27142428@solnes.nr.no>
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!sunic!aun.uninett.no!nuug!nntp.uio.no!nntp.uio.no!aas
References: <3151@peking.gdwb.oz.au>

Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.postscript
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!sunic!aun.uninett.no!nuug!nntp.uio.no!nntp.uio.no!aas
From: aas@solnes.nr.no (Gisle Aas)
Subject: Re: EPS files and preview bitmaps
In-Reply-To: was@gdwb.oz.au's message of 27 Jul 92 05:59:49 GMT
Message-ID: <AAS.92Jul27142428@solnes.nr.no>
Sender: news@ulrik.uio.no (Mr News)
Nntp-Posting-Host: solnes.nr.no
Reply-To: Gisle.Aas@nr.no
Organization: Norwegian Computing Centre, Oslo, Norway
References: <3151@peking.gdwb.oz.au>
Date: Mon, 27 Jul 1992 13:24:28 GMT
Lines: 222