Thread View: comp.lang.postscript
2 messages
2 total messages
Started by Rodney Mcduff
Sun, 30 Aug 1992 05:12
Preview Bitmaps for PS and EPS files?
Author: Rodney Mcduff
Date: Sun, 30 Aug 1992 05:12
Date: Sun, 30 Aug 1992 05:12
70 lines
3439 bytes
3439 bytes
It occurs to me that it would a 'good thing' to be able
to insert/append a preview bitmap into a arbitary postscript file.
With this facility one could for example import a postscript file
as a eps object into Xfig and see the bitmap displayed. (Thus one
can modify (or add to) a drawing or graph etc etc.)
So the question is "Is there some software out there that can achieve this?".
Now with the ghostscript package there exist a PS program (ps2image.ps) that
is atleast heading in the right direction. It converts a PS file
into a hex bitmap which it then reads and display. ie.
#!
# start of converted PS file
/readimage {gsave matrix setmatrix 1 matrix 3 index 7 add 8 idiv string currentfile exch
{2 copy 1 index token pop 2 index token pop getinterval readhexstring pop pop dup}
3 1 roll 7 2 roll image pop pop grestore showpage} bind def
568 736 readimage
0 71 fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
.
.
lots of hex stuff
.
.
# end of converted PS file
However what we want is something like this
%!PS-Adobe-2.0 EPSF-2.0
%%BoundingBox: 0 18 335 345
%%Title: logo.eps ( this is an example EPS file with a preview bitmap that comes with Xfig)
%%Creator: boyter
%%CreationDate: Wed Mar 27 09:22:54 1991
%%BeginPreview: 391 391 1 391
% 000000000000000000000000000000000000000000000003ffe00000000000000000000000000000000000000000000000
% 000000000000000000000000000000000000000000003ffffffffe00000000000000000000000000000000000000000000
.
.
lots of hex stuff
.
.
% 000000000000000000000000000000000000000000ffffffffffffff000000000000000000000000000000000000000000
% 000000000000000000000000000000000000000000007fffffffff00000000000000000000000000000000000000000000
%%EndPreview
.
.
Rest of original PS file
.
.
So it should be feasible that with ghostscript and an appropriate PS program one
can include/append a preview bitmap into an arbitary PS file.
--
+-------------------------+------------------------------------------+
| _ ^ _ | Rodney McDuff |
| |\ /|\ /| | Physics Department |
| \ | / | The University of Queensland |
| \ | / | St. Lucia, Brisbane |
| \|/ | Queensland, Australia. 4072. |
| <--------+--------> | |
| /|\ | TELEPHONE: +61 7 365 3424 |
| / | \ | INTERNET:mcduff@newton.physics.uq.oz.au |
| / | \ | FACSIMILE: +61 7 365 1242 |
| |/ \|/ \| | |
| - v - | |
+-------------------------+------------------------------------------+
Re: Preview Bitmaps for PS and EPS files?
Author: Gisle Aas
Date: Mon, 31 Aug 1992 12:47
Date: Mon, 31 Aug 1992 12:47
227 lines
6934 bytes
6934 bytes
In article <Bts6H4.HA3@bunyip.cc.uq.oz.au> mcduff@newton.physics.uq.oz.au (Rodney Mcduff) writes:
> So the question is "Is there some software out there that can achieve this?".
This is a perl/ghostscript solution:
#!/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 08/31/1992 11:47 UTC by aas@boeygen
# Source directory /nr/boeygen/u2/aas
#
# existing files will NOT be overwritten unless -c is specified
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 4755 -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.3 1992/08/25 14:56:05 aas
# Hvis kommentarene i begynnelsen ikke sluttet med %%EndComments, sรฅ spiste
# vi opp fรธrste 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*(-?\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 $_ 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 4755 -eq "$Wc_c" ||
echo 'eps2epsi: original size 4755, 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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads